Skip to content

Commit f0387db

Browse files
Refactor - auto update credential provider script
1 parent 75e9242 commit f0387db

15 files changed

+836
-798
lines changed

firefox-ios/Client/Assets/CC_Script/AddressRecord.sys.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { FormAutofillNameUtils } from "resource://gre/modules/shared/FormAutofil
77
import { FormAutofillUtils } from "resource://gre/modules/shared/FormAutofillUtils.sys.mjs";
88
import { PhoneNumber } from "resource://gre/modules/shared/PhoneNumber.sys.mjs";
99
import { FormAutofill } from "resource://autofill/FormAutofill.sys.mjs";
10+
import { AddressParser } from "resource://gre/modules/shared/AddressParser.sys.mjs";
1011

1112
/**
1213
* The AddressRecord class serves to handle and normalize internal address records.
@@ -32,6 +33,7 @@ export class AddressRecord {
3233
static computeFields(address) {
3334
this.#computeNameFields(address);
3435
this.#computeAddressLineFields(address);
36+
this.#computeStreetAndHouseNumberFields(address);
3537
this.#computeCountryFields(address);
3638
this.#computeTelFields(address);
3739
}
@@ -66,6 +68,17 @@ export class AddressRecord {
6668
}
6769
}
6870

71+
static #computeStreetAndHouseNumberFields(address) {
72+
if (!("address-housenumber" in address) && "street-address" in address) {
73+
let streetAddress = AddressParser.parseStreetAddress(
74+
address["street-address"]
75+
);
76+
if (streetAddress) {
77+
address["address-housenumber"] = streetAddress.street_number;
78+
}
79+
}
80+
}
81+
6982
static #computeCountryFields(address) {
7083
// Compute country name
7184
if (!("country-name" in address)) {

firefox-ios/Client/Assets/CC_Script/AutofillFormFactory.sys.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ export const AutofillFormFactory = {
3939
}
4040
return lazy.FormLikeFactory.createFromField(aField, { ignoreForm });
4141
},
42+
43+
createFromDocumentRoot(aDocRoot) {
44+
return lazy.FormLikeFactory.createFromDocumentRoot(aDocRoot);
45+
},
4246
};

firefox-ios/Client/Assets/CC_Script/AutofillTelemetry.sys.mjs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ class AutofillTelemetryBase {
1212
EVENT_CATEGORY = null;
1313
EVENT_OBJECT_FORM_INTERACTION = null;
1414

15-
HISTOGRAM_NUM_USES = null;
16-
HISTOGRAM_PROFILE_NUM_USES = null;
17-
HISTOGRAM_PROFILE_NUM_USES_KEY = null;
18-
1915
#initFormEventExtra(value) {
2016
let extra = {};
2117
for (const field of Object.values(this.SUPPORTED_FIELDS)) {
@@ -183,17 +179,6 @@ class AutofillTelemetryBase {
183179
throw new Error("Not implemented.");
184180
}
185181

186-
recordNumberOfUse(records) {
187-
let histogram = Services.telemetry.getKeyedHistogramById(
188-
this.HISTOGRAM_PROFILE_NUM_USES
189-
);
190-
histogram.clear();
191-
192-
for (let record of records) {
193-
histogram.add(this.HISTOGRAM_PROFILE_NUM_USES_KEY, record.timesUsed);
194-
}
195-
}
196-
197182
recordIframeLayoutDetection(flowId, fieldDetails) {
198183
const fieldsInMainFrame = [];
199184
const fieldsInIframe = [];
@@ -238,9 +223,6 @@ export class AddressTelemetry extends AutofillTelemetryBase {
238223
EVENT_OBJECT_FORM_INTERACTION = "AddressForm";
239224
EVENT_OBJECT_FORM_INTERACTION_EXT = "AddressFormExt";
240225

241-
HISTOGRAM_PROFILE_NUM_USES = "AUTOFILL_PROFILE_NUM_USES";
242-
HISTOGRAM_PROFILE_NUM_USES_KEY = "address";
243-
244226
// Fields that are recorded in `address_form` and `address_form_ext` telemetry
245227
SUPPORTED_FIELDS = {
246228
"street-address": "street_address",
@@ -316,10 +298,6 @@ class CreditCardTelemetry extends AutofillTelemetryBase {
316298
EVENT_CATEGORY = "creditcard";
317299
EVENT_OBJECT_FORM_INTERACTION = "CcFormV2";
318300

319-
HISTOGRAM_NUM_USES = "CREDITCARD_NUM_USES";
320-
HISTOGRAM_PROFILE_NUM_USES = "AUTOFILL_PROFILE_NUM_USES";
321-
HISTOGRAM_PROFILE_NUM_USES_KEY = "credit_card";
322-
323301
// Mapping of field name used in formautofill code to the field name
324302
// used in the telemetry.
325303
SUPPORTED_FIELDS = {
@@ -369,23 +347,6 @@ class CreditCardTelemetry extends AutofillTelemetryBase {
369347
}
370348
}
371349

372-
recordNumberOfUse(records) {
373-
super.recordNumberOfUse(records);
374-
375-
if (!this.HISTOGRAM_NUM_USES) {
376-
return;
377-
}
378-
379-
let histogram = Services.telemetry.getHistogramById(
380-
this.HISTOGRAM_NUM_USES
381-
);
382-
histogram.clear();
383-
384-
for (let record of records) {
385-
histogram.add(record.timesUsed);
386-
}
387-
}
388-
389350
recordAutofillProfileCount(count) {
390351
Glean.formautofillCreditcards.autofillProfilesCount.set(count);
391352
}
@@ -463,14 +424,6 @@ export class AutofillTelemetry {
463424
telemetry.recordAutofillProfileCount(count);
464425
}
465426

466-
/**
467-
* Utility functions for address/credit card number of use
468-
*/
469-
static recordNumberOfUse(type, records) {
470-
const telemetry = this.#getTelemetryByType(type);
471-
telemetry.recordNumberOfUse(records);
472-
}
473-
474427
static recordFormSubmissionHeuristicCount(label) {
475428
Glean.formautofill.formSubmissionHeuristic[label].add(1);
476429
}

firefox-ios/Client/Assets/CC_Script/Constants.ios.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
const IOS_DEFAULT_PREFERENCES = {
66
"extensions.formautofill.creditCards.heuristics.mode": 1,
77
"extensions.formautofill.creditCards.heuristics.fathom.confidenceThreshold": 0.5,
8-
"extensions.formautofill.creditCards.heuristics.fathom.highConfidenceThreshold": 0.95,
98
"extensions.formautofill.creditCards.heuristics.fathom.testConfidence": 0,
109
"extensions.formautofill.creditCards.heuristics.fathom.types":
1110
"cc-number,cc-name",
@@ -32,11 +31,11 @@ const IOS_DEFAULT_PREFERENCES = {
3231
"extensions.formautofill.heuristics.captureOnPageNavigation": false,
3332
"extensions.formautofill.heuristics.detectDynamicFormChanges": false,
3433
"extensions.formautofill.heuristics.fillOnDynamicFormChanges": false,
34+
"extensions.formautofill.heuristics.refillOnSiteClearingFields": false,
3535
"extensions.formautofill.focusOnAutofill": false,
3636
"extensions.formautofill.test.ignoreVisibilityCheck": false,
3737
"extensions.formautofill.heuristics.autofillSameOriginWithTop": false,
3838
"signon.generation.confidenceThreshold": 0.75,
39-
"extensions.formautofill.ml.experiment.enabled": false,
4039
};
4140

4241
// Used Mimic the behavior of .getAutocompleteInfo()

firefox-ios/Client/Assets/CC_Script/FieldScanner.sys.mjs

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44

55
const lazy = {};
66
ChromeUtils.defineESModuleGetters(lazy, {
7-
FormAutofill: "resource://autofill/FormAutofill.sys.mjs",
87
FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs",
9-
MLAutofill: "resource://autofill/MLAutofill.sys.mjs",
108
});
119

1210
/**
@@ -42,6 +40,10 @@ export class FieldDetail {
4240
// The possible values are "autocomplete", "fathom", and "regex-heuristic"
4341
reason = null;
4442

43+
// This field could be a lookup field, for example, one that could be used to
44+
// search for an address or postal code and fill in other fields.
45+
isLookup = false;
46+
4547
/*
4648
* The "section", "addressType", and "contactType" values are
4749
* used to identify the exact field when the serializable data is received
@@ -96,11 +98,9 @@ export class FieldDetail {
9698
fieldName = null,
9799
{
98100
autocompleteInfo = null,
99-
fathomLabel = null,
100101
fathomConfidence = null,
101102
isVisible = true,
102-
mlHeaderInput = null,
103-
mlButtonInput = null,
103+
isLookup = false,
104104
} = {}
105105
) {
106106
const fieldDetail = new FieldDetail(element);
@@ -133,23 +133,6 @@ export class FieldDetail {
133133
} else if (fathomConfidence) {
134134
fieldDetail.reason = "fathom";
135135
fieldDetail.confidence = fathomConfidence;
136-
137-
// TODO: This should be removed once we support reference field info across iframe.
138-
// Temporarily add an addtional "the field is the only visible input" constraint
139-
// when determining whether a form has only a high-confidence cc-* field a valid
140-
// credit card section. We can remove this restriction once we are confident
141-
// about only using fathom.
142-
fieldDetail.isOnlyVisibleFieldWithHighConfidence = false;
143-
if (
144-
fieldDetail.confidence >
145-
lazy.FormAutofillUtils.ccFathomHighConfidenceThreshold
146-
) {
147-
const root = element.form || element.ownerDocument;
148-
const inputs = root.querySelectorAll("input:not([type=hidden])");
149-
if (inputs.length == 1 && inputs[0] == element) {
150-
fieldDetail.isOnlyVisibleFieldWithHighConfidence = true;
151-
}
152-
}
153136
} else {
154137
fieldDetail.reason = "regex-heuristic";
155138
}
@@ -168,16 +151,7 @@ export class FieldDetail {
168151
// Info required by heuristics
169152
fieldDetail.maxLength = element.maxLength;
170153

171-
if (
172-
lazy.FormAutofill.isMLExperimentEnabled &&
173-
["input", "select"].includes(element.localName)
174-
) {
175-
fieldDetail.mlinput = lazy.MLAutofill.getMLMarkup(fieldDetail.element);
176-
fieldDetail.mlHeaderInput = mlHeaderInput;
177-
fieldDetail.mlButtonInput = mlButtonInput;
178-
fieldDetail.fathomLabel = fathomLabel;
179-
fieldDetail.fathomConfidence = fathomConfidence;
180-
}
154+
fieldDetail.isLookup = isLookup;
181155

182156
return fieldDetail;
183157
}
@@ -251,6 +225,43 @@ export class FieldScanner {
251225
return this.#fieldDetails[index];
252226
}
253227

228+
getFieldsMatching(matchFn, includeInvisible = false) {
229+
let fields = [];
230+
231+
for (let idx = 0; this.elementExisting(idx); idx++) {
232+
let field = this.#fieldDetails[idx];
233+
if ((includeInvisible || field.isVisible) && matchFn(field)) {
234+
fields.push(field);
235+
}
236+
}
237+
238+
return fields;
239+
}
240+
241+
/**
242+
* Return the index of the first visible field found with the given name.
243+
*
244+
* @param {string} fieldName
245+
* The field name to find.
246+
* @param {string} includeInvisible
247+
* Whether to find non-visible fields.
248+
* @returns {number}
249+
* The index of the element or -1 if not found.
250+
*/
251+
getFieldIndexByName(fieldName, includeInvisible = false) {
252+
for (let idx = 0; this.elementExisting(idx); idx++) {
253+
let field = this.#fieldDetails[idx];
254+
if (
255+
field.fieldName == fieldName &&
256+
(includeInvisible || field.isVisible)
257+
) {
258+
return idx;
259+
}
260+
}
261+
262+
return -1;
263+
}
264+
254265
/**
255266
* When a field detail should be changed its fieldName after parsing, use
256267
* this function to update the fieldName which is at a specific index.

firefox-ios/Client/Assets/CC_Script/FormAutofill.sys.mjs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const ENABLED_AUTOFILL_ADDRESSES_SUPPORTED_COUNTRIES_PREF =
2424
"extensions.formautofill.addresses.supportedCountries";
2525
const ENABLED_AUTOFILL_CREDITCARDS_PREF =
2626
"extensions.formautofill.creditCards.enabled";
27-
const AUTOFILL_CREDITCARDS_REAUTH_PREF =
28-
"extensions.formautofill.creditCards.reauth.optout";
27+
const AUTOFILL_CREDITCARDS_OS_AUTH_LOCKED_PREF =
28+
"extensions.formautofill.creditCards.os-auth.locked.enabled";
2929
const AUTOFILL_CREDITCARDS_HIDE_UI_PREF =
3030
"extensions.formautofill.creditCards.hideui";
3131
const FORM_AUTOFILL_SUPPORT_RTL_PREF = "extensions.formautofill.supportRTL";
@@ -45,6 +45,10 @@ const AUTOFILL_FILL_ON_DYNAMIC_FORM_CHANGES_TIMEOUT_PREF =
4545
"extensions.formautofill.heuristics.fillOnDynamicFormChanges.timeout";
4646
const AUTOFILL_FILL_ON_DYNAMIC_FORM_CHANGES_PREF =
4747
"extensions.formautofill.heuristics.fillOnDynamicFormChanges";
48+
const AUTOFILL_REFILL_ON_SITE_CLEARING_VALUE_PREF =
49+
"extensions.formautofill.heuristics.refillOnSiteClearingFields";
50+
const AUTOFILL_REFILL_ON_SITE_CLEARING_VALUE_TIMEOUT_PREF =
51+
"extensions.formautofill.heuristics.refillOnSiteClearingFields.timeout";
4852

4953
export const FormAutofill = {
5054
ENABLED_AUTOFILL_ADDRESSES_PREF,
@@ -54,11 +58,13 @@ export const FormAutofill = {
5458
ENABLED_AUTOFILL_SAME_ORIGIN_WITH_TOP,
5559
ENABLED_AUTOFILL_CREDITCARDS_PREF,
5660
ENABLED_AUTOFILL_DETECT_DYNAMIC_FORM_CHANGES_PREF,
57-
AUTOFILL_CREDITCARDS_REAUTH_PREF,
61+
AUTOFILL_CREDITCARDS_OS_AUTH_LOCKED_PREF,
5862
AUTOFILL_CREDITCARDS_AUTOCOMPLETE_OFF_PREF,
5963
AUTOFILL_ADDRESSES_AUTOCOMPLETE_OFF_PREF,
6064
AUTOFILL_FILL_ON_DYNAMIC_FORM_CHANGES_PREF,
6165
AUTOFILL_FILL_ON_DYNAMIC_FORM_CHANGES_TIMEOUT_PREF,
66+
AUTOFILL_REFILL_ON_SITE_CLEARING_VALUE_PREF,
67+
AUTOFILL_REFILL_ON_SITE_CLEARING_VALUE_TIMEOUT_PREF,
6268

6369
_region: null,
6470

@@ -212,10 +218,6 @@ export const FormAutofill = {
212218
prefix: logPrefix,
213219
});
214220
},
215-
216-
get isMLExperimentEnabled() {
217-
return FormAutofill._isMLEnabled && FormAutofill._isMLExperimentEnabled;
218-
},
219221
};
220222

221223
// TODO: Bug 1747284. Use Region.home instead of reading "browser.serach.region"
@@ -326,43 +328,36 @@ XPCOMUtils.defineLazyPreferenceGetter(
326328

327329
XPCOMUtils.defineLazyPreferenceGetter(
328330
FormAutofill,
329-
"_isMLEnabled",
330-
"browser.ml.enable",
331+
"detectDynamicFormChanges",
332+
"extensions.formautofill.heuristics.detectDynamicFormChanges",
331333
false
332334
);
333335

334336
XPCOMUtils.defineLazyPreferenceGetter(
335337
FormAutofill,
336-
"_isMLExperimentEnabled",
337-
"extensions.formautofill.ml.experiment.enabled",
338+
"fillOnDynamicFormChanges",
339+
"extensions.formautofill.heuristics.fillOnDynamicFormChanges",
338340
false
339341
);
340342

341343
XPCOMUtils.defineLazyPreferenceGetter(
342344
FormAutofill,
343-
"MLModelRevision",
344-
"extensions.formautofill.ml.experiment.modelRevision",
345-
null
346-
);
347-
348-
XPCOMUtils.defineLazyPreferenceGetter(
349-
FormAutofill,
350-
"detectDynamicFormChanges",
351-
"extensions.formautofill.heuristics.detectDynamicFormChanges",
352-
false
345+
"fillOnDynamicFormChangeTimeout",
346+
"extensions.formautofill.heuristics.fillOnDynamicFormChanges.timeout",
347+
0
353348
);
354349

355350
XPCOMUtils.defineLazyPreferenceGetter(
356351
FormAutofill,
357-
"fillOnDynamicFormChanges",
358-
"extensions.formautofill.heuristics.fillOnDynamicFormChanges",
352+
"refillOnSiteClearingFields",
353+
"extensions.formautofill.heuristics.refillOnSiteClearingFields",
359354
false
360355
);
361356

362357
XPCOMUtils.defineLazyPreferenceGetter(
363358
FormAutofill,
364-
"fillOnDynamicFormChangeTimeout",
365-
"extensions.formautofill.heuristics.fillOnDynamicFormChanges.timeout",
359+
"refillOnSiteClearingFieldsTimeout",
360+
"extensions.formautofill.heuristics.refillOnSiteClearingFields.timeout",
366361
0
367362
);
368363

0 commit comments

Comments
 (0)