Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions firefox-ios/Client/Assets/CC_Script/AddressRecord.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FormAutofillNameUtils } from "resource://gre/modules/shared/FormAutofil
import { FormAutofillUtils } from "resource://gre/modules/shared/FormAutofillUtils.sys.mjs";
import { PhoneNumber } from "resource://gre/modules/shared/PhoneNumber.sys.mjs";
import { FormAutofill } from "resource://autofill/FormAutofill.sys.mjs";
import { AddressParser } from "resource://gre/modules/shared/AddressParser.sys.mjs";

/**
* The AddressRecord class serves to handle and normalize internal address records.
Expand All @@ -32,6 +33,7 @@ export class AddressRecord {
static computeFields(address) {
this.#computeNameFields(address);
this.#computeAddressLineFields(address);
this.#computeStreetAndHouseNumberFields(address);
this.#computeCountryFields(address);
this.#computeTelFields(address);
}
Expand Down Expand Up @@ -66,6 +68,17 @@ export class AddressRecord {
}
}

static #computeStreetAndHouseNumberFields(address) {
if (!("address-housenumber" in address) && "street-address" in address) {
let streetAddress = AddressParser.parseStreetAddress(
address["street-address"]
);
if (streetAddress) {
address["address-housenumber"] = streetAddress.street_number;
}
}
}

static #computeCountryFields(address) {
// Compute country name
if (!("country-name" in address)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,8 @@ export const AutofillFormFactory = {
}
return lazy.FormLikeFactory.createFromField(aField, { ignoreForm });
},

createFromDocumentRoot(aDocRoot) {
return lazy.FormLikeFactory.createFromDocumentRoot(aDocRoot);
},
};
47 changes: 0 additions & 47 deletions firefox-ios/Client/Assets/CC_Script/AutofillTelemetry.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ class AutofillTelemetryBase {
EVENT_CATEGORY = null;
EVENT_OBJECT_FORM_INTERACTION = null;

HISTOGRAM_NUM_USES = null;
HISTOGRAM_PROFILE_NUM_USES = null;
HISTOGRAM_PROFILE_NUM_USES_KEY = null;

#initFormEventExtra(value) {
let extra = {};
for (const field of Object.values(this.SUPPORTED_FIELDS)) {
Expand Down Expand Up @@ -183,17 +179,6 @@ class AutofillTelemetryBase {
throw new Error("Not implemented.");
}

recordNumberOfUse(records) {
let histogram = Services.telemetry.getKeyedHistogramById(
this.HISTOGRAM_PROFILE_NUM_USES
);
histogram.clear();

for (let record of records) {
histogram.add(this.HISTOGRAM_PROFILE_NUM_USES_KEY, record.timesUsed);
}
}

recordIframeLayoutDetection(flowId, fieldDetails) {
const fieldsInMainFrame = [];
const fieldsInIframe = [];
Expand Down Expand Up @@ -238,9 +223,6 @@ export class AddressTelemetry extends AutofillTelemetryBase {
EVENT_OBJECT_FORM_INTERACTION = "AddressForm";
EVENT_OBJECT_FORM_INTERACTION_EXT = "AddressFormExt";

HISTOGRAM_PROFILE_NUM_USES = "AUTOFILL_PROFILE_NUM_USES";
HISTOGRAM_PROFILE_NUM_USES_KEY = "address";

// Fields that are recorded in `address_form` and `address_form_ext` telemetry
SUPPORTED_FIELDS = {
"street-address": "street_address",
Expand Down Expand Up @@ -316,10 +298,6 @@ class CreditCardTelemetry extends AutofillTelemetryBase {
EVENT_CATEGORY = "creditcard";
EVENT_OBJECT_FORM_INTERACTION = "CcFormV2";

HISTOGRAM_NUM_USES = "CREDITCARD_NUM_USES";
HISTOGRAM_PROFILE_NUM_USES = "AUTOFILL_PROFILE_NUM_USES";
HISTOGRAM_PROFILE_NUM_USES_KEY = "credit_card";

// Mapping of field name used in formautofill code to the field name
// used in the telemetry.
SUPPORTED_FIELDS = {
Expand Down Expand Up @@ -369,23 +347,6 @@ class CreditCardTelemetry extends AutofillTelemetryBase {
}
}

recordNumberOfUse(records) {
super.recordNumberOfUse(records);

if (!this.HISTOGRAM_NUM_USES) {
return;
}

let histogram = Services.telemetry.getHistogramById(
this.HISTOGRAM_NUM_USES
);
histogram.clear();

for (let record of records) {
histogram.add(record.timesUsed);
}
}

recordAutofillProfileCount(count) {
Glean.formautofillCreditcards.autofillProfilesCount.set(count);
}
Expand Down Expand Up @@ -463,14 +424,6 @@ export class AutofillTelemetry {
telemetry.recordAutofillProfileCount(count);
}

/**
* Utility functions for address/credit card number of use
*/
static recordNumberOfUse(type, records) {
const telemetry = this.#getTelemetryByType(type);
telemetry.recordNumberOfUse(records);
}

static recordFormSubmissionHeuristicCount(label) {
Glean.formautofill.formSubmissionHeuristic[label].add(1);
}
Expand Down
3 changes: 1 addition & 2 deletions firefox-ios/Client/Assets/CC_Script/Constants.ios.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
const IOS_DEFAULT_PREFERENCES = {
"extensions.formautofill.creditCards.heuristics.mode": 1,
"extensions.formautofill.creditCards.heuristics.fathom.confidenceThreshold": 0.5,
"extensions.formautofill.creditCards.heuristics.fathom.highConfidenceThreshold": 0.95,
"extensions.formautofill.creditCards.heuristics.fathom.testConfidence": 0,
"extensions.formautofill.creditCards.heuristics.fathom.types":
"cc-number,cc-name",
Expand All @@ -32,11 +31,11 @@ const IOS_DEFAULT_PREFERENCES = {
"extensions.formautofill.heuristics.captureOnPageNavigation": false,
"extensions.formautofill.heuristics.detectDynamicFormChanges": false,
"extensions.formautofill.heuristics.fillOnDynamicFormChanges": false,
"extensions.formautofill.heuristics.refillOnSiteClearingFields": false,
"extensions.formautofill.focusOnAutofill": false,
"extensions.formautofill.test.ignoreVisibilityCheck": false,
"extensions.formautofill.heuristics.autofillSameOriginWithTop": false,
"signon.generation.confidenceThreshold": 0.75,
"extensions.formautofill.ml.experiment.enabled": false,
};

// Used Mimic the behavior of .getAutocompleteInfo()
Expand Down
75 changes: 43 additions & 32 deletions firefox-ios/Client/Assets/CC_Script/FieldScanner.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
FormAutofill: "resource://autofill/FormAutofill.sys.mjs",
FormAutofillUtils: "resource://gre/modules/shared/FormAutofillUtils.sys.mjs",
MLAutofill: "resource://autofill/MLAutofill.sys.mjs",
});

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

// This field could be a lookup field, for example, one that could be used to
// search for an address or postal code and fill in other fields.
isLookup = false;

/*
* The "section", "addressType", and "contactType" values are
* used to identify the exact field when the serializable data is received
Expand Down Expand Up @@ -96,11 +98,9 @@ export class FieldDetail {
fieldName = null,
{
autocompleteInfo = null,
fathomLabel = null,
fathomConfidence = null,
isVisible = true,
mlHeaderInput = null,
mlButtonInput = null,
isLookup = false,
} = {}
) {
const fieldDetail = new FieldDetail(element);
Expand Down Expand Up @@ -133,23 +133,6 @@ export class FieldDetail {
} else if (fathomConfidence) {
fieldDetail.reason = "fathom";
fieldDetail.confidence = fathomConfidence;

// TODO: This should be removed once we support reference field info across iframe.
// Temporarily add an addtional "the field is the only visible input" constraint
// when determining whether a form has only a high-confidence cc-* field a valid
// credit card section. We can remove this restriction once we are confident
// about only using fathom.
fieldDetail.isOnlyVisibleFieldWithHighConfidence = false;
if (
fieldDetail.confidence >
lazy.FormAutofillUtils.ccFathomHighConfidenceThreshold
) {
const root = element.form || element.ownerDocument;
const inputs = root.querySelectorAll("input:not([type=hidden])");
if (inputs.length == 1 && inputs[0] == element) {
fieldDetail.isOnlyVisibleFieldWithHighConfidence = true;
}
}
} else {
fieldDetail.reason = "regex-heuristic";
}
Expand All @@ -168,16 +151,7 @@ export class FieldDetail {
// Info required by heuristics
fieldDetail.maxLength = element.maxLength;

if (
lazy.FormAutofill.isMLExperimentEnabled &&
["input", "select"].includes(element.localName)
) {
fieldDetail.mlinput = lazy.MLAutofill.getMLMarkup(fieldDetail.element);
fieldDetail.mlHeaderInput = mlHeaderInput;
fieldDetail.mlButtonInput = mlButtonInput;
fieldDetail.fathomLabel = fathomLabel;
fieldDetail.fathomConfidence = fathomConfidence;
}
fieldDetail.isLookup = isLookup;

return fieldDetail;
}
Expand Down Expand Up @@ -251,6 +225,43 @@ export class FieldScanner {
return this.#fieldDetails[index];
}

getFieldsMatching(matchFn, includeInvisible = false) {
let fields = [];

for (let idx = 0; this.elementExisting(idx); idx++) {
let field = this.#fieldDetails[idx];
if ((includeInvisible || field.isVisible) && matchFn(field)) {
fields.push(field);
}
}

return fields;
}

/**
* Return the index of the first visible field found with the given name.
*
* @param {string} fieldName
* The field name to find.
* @param {string} includeInvisible
* Whether to find non-visible fields.
* @returns {number}
* The index of the element or -1 if not found.
*/
getFieldIndexByName(fieldName, includeInvisible = false) {
for (let idx = 0; this.elementExisting(idx); idx++) {
let field = this.#fieldDetails[idx];
if (
field.fieldName == fieldName &&
(includeInvisible || field.isVisible)
) {
return idx;
}
}

return -1;
}

/**
* When a field detail should be changed its fieldName after parsing, use
* this function to update the fieldName which is at a specific index.
Expand Down
45 changes: 20 additions & 25 deletions firefox-ios/Client/Assets/CC_Script/FormAutofill.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const ENABLED_AUTOFILL_ADDRESSES_SUPPORTED_COUNTRIES_PREF =
"extensions.formautofill.addresses.supportedCountries";
const ENABLED_AUTOFILL_CREDITCARDS_PREF =
"extensions.formautofill.creditCards.enabled";
const AUTOFILL_CREDITCARDS_REAUTH_PREF =
"extensions.formautofill.creditCards.reauth.optout";
const AUTOFILL_CREDITCARDS_OS_AUTH_LOCKED_PREF =
"extensions.formautofill.creditCards.os-auth.locked.enabled";
const AUTOFILL_CREDITCARDS_HIDE_UI_PREF =
"extensions.formautofill.creditCards.hideui";
const FORM_AUTOFILL_SUPPORT_RTL_PREF = "extensions.formautofill.supportRTL";
Expand All @@ -45,6 +45,10 @@ const AUTOFILL_FILL_ON_DYNAMIC_FORM_CHANGES_TIMEOUT_PREF =
"extensions.formautofill.heuristics.fillOnDynamicFormChanges.timeout";
const AUTOFILL_FILL_ON_DYNAMIC_FORM_CHANGES_PREF =
"extensions.formautofill.heuristics.fillOnDynamicFormChanges";
const AUTOFILL_REFILL_ON_SITE_CLEARING_VALUE_PREF =
"extensions.formautofill.heuristics.refillOnSiteClearingFields";
const AUTOFILL_REFILL_ON_SITE_CLEARING_VALUE_TIMEOUT_PREF =
"extensions.formautofill.heuristics.refillOnSiteClearingFields.timeout";

export const FormAutofill = {
ENABLED_AUTOFILL_ADDRESSES_PREF,
Expand All @@ -54,11 +58,13 @@ export const FormAutofill = {
ENABLED_AUTOFILL_SAME_ORIGIN_WITH_TOP,
ENABLED_AUTOFILL_CREDITCARDS_PREF,
ENABLED_AUTOFILL_DETECT_DYNAMIC_FORM_CHANGES_PREF,
AUTOFILL_CREDITCARDS_REAUTH_PREF,
AUTOFILL_CREDITCARDS_OS_AUTH_LOCKED_PREF,
AUTOFILL_CREDITCARDS_AUTOCOMPLETE_OFF_PREF,
AUTOFILL_ADDRESSES_AUTOCOMPLETE_OFF_PREF,
AUTOFILL_FILL_ON_DYNAMIC_FORM_CHANGES_PREF,
AUTOFILL_FILL_ON_DYNAMIC_FORM_CHANGES_TIMEOUT_PREF,
AUTOFILL_REFILL_ON_SITE_CLEARING_VALUE_PREF,
AUTOFILL_REFILL_ON_SITE_CLEARING_VALUE_TIMEOUT_PREF,

_region: null,

Expand Down Expand Up @@ -212,10 +218,6 @@ export const FormAutofill = {
prefix: logPrefix,
});
},

get isMLExperimentEnabled() {
return FormAutofill._isMLEnabled && FormAutofill._isMLExperimentEnabled;
},
};

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

XPCOMUtils.defineLazyPreferenceGetter(
FormAutofill,
"_isMLEnabled",
"browser.ml.enable",
"detectDynamicFormChanges",
"extensions.formautofill.heuristics.detectDynamicFormChanges",
false
);

XPCOMUtils.defineLazyPreferenceGetter(
FormAutofill,
"_isMLExperimentEnabled",
"extensions.formautofill.ml.experiment.enabled",
"fillOnDynamicFormChanges",
"extensions.formautofill.heuristics.fillOnDynamicFormChanges",
false
);

XPCOMUtils.defineLazyPreferenceGetter(
FormAutofill,
"MLModelRevision",
"extensions.formautofill.ml.experiment.modelRevision",
null
);

XPCOMUtils.defineLazyPreferenceGetter(
FormAutofill,
"detectDynamicFormChanges",
"extensions.formautofill.heuristics.detectDynamicFormChanges",
false
"fillOnDynamicFormChangeTimeout",
"extensions.formautofill.heuristics.fillOnDynamicFormChanges.timeout",
0
);

XPCOMUtils.defineLazyPreferenceGetter(
FormAutofill,
"fillOnDynamicFormChanges",
"extensions.formautofill.heuristics.fillOnDynamicFormChanges",
"refillOnSiteClearingFields",
"extensions.formautofill.heuristics.refillOnSiteClearingFields",
false
);

XPCOMUtils.defineLazyPreferenceGetter(
FormAutofill,
"fillOnDynamicFormChangeTimeout",
"extensions.formautofill.heuristics.fillOnDynamicFormChanges.timeout",
"refillOnSiteClearingFieldsTimeout",
"extensions.formautofill.heuristics.refillOnSiteClearingFields.timeout",
0
);

Expand Down
Loading