From 8e4a4d40123e5fac28bc4f0fc35ba79a26e2697a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 17 Sep 2024 14:41:36 -0400 Subject: [PATCH] Refactor - auto update credential provider script (#21975) Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../Assets/CC_Script/FormAutofillChild.ios.sys.mjs | 14 +++++++++++++- .../Assets/CC_Script/FormAutofillHandler.sys.mjs | 13 +++++++++---- .../Assets/CC_Script/HeuristicsRegExp.sys.mjs | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/firefox-ios/Client/Assets/CC_Script/FormAutofillChild.ios.sys.mjs b/firefox-ios/Client/Assets/CC_Script/FormAutofillChild.ios.sys.mjs index 5ac828ff41d3..053c65ffe1be 100644 --- a/firefox-ios/Client/Assets/CC_Script/FormAutofillChild.ios.sys.mjs +++ b/firefox-ios/Client/Assets/CC_Script/FormAutofillChild.ios.sys.mjs @@ -31,7 +31,10 @@ export class FormAutofillChild { this.callbacks = callbacks; - this.fieldDetailsManager = new FormStateManager(); + this.fieldDetailsManager = new FormStateManager(fieldDetail => + // Collect field_modified telemetry + this.activeSection?.onFilledModified(fieldDetail.elementId) + ); try { document.addEventListener("focusin", this.onFocusIn); @@ -70,6 +73,9 @@ export class FormAutofillChild { this.#sections = FormAutofillSection.classifySections( handler.fieldDetails ); + + // For telemetry + this.#sections.forEach(section => section.onDetected()); } } @@ -146,6 +152,8 @@ export class FormAutofillChild { } else { throw new Error("Unknown section type"); } + + section.onSubmitted(formFilledData); } if (creditCard.length) { @@ -174,6 +182,10 @@ export class FormAutofillChild { this.activeSection.fieldDetails.map(f => f.elementId), payload ); + + // For telemetry + const formFilledData = this.activeHandler.collectFormFilledData(); + this.activeSection.onFilled(formFilledData); } } diff --git a/firefox-ios/Client/Assets/CC_Script/FormAutofillHandler.sys.mjs b/firefox-ios/Client/Assets/CC_Script/FormAutofillHandler.sys.mjs index eebb965eac5b..b39f05d946d1 100644 --- a/firefox-ios/Client/Assets/CC_Script/FormAutofillHandler.sys.mjs +++ b/firefox-ios/Client/Assets/CC_Script/FormAutofillHandler.sys.mjs @@ -315,7 +315,7 @@ export class FormAutofillHandler { element.value == element.defaultValue || element.autofillState == FIELD_STATES.AUTO_FILLED ) { - this.fillFieldValue(element, value); + FormAutofillHandler.fillFieldValue(element, value); this.changeFieldState(fieldDetail, FIELD_STATES.AUTO_FILLED); } } else if (HTMLSelectElement.isInstance(element)) { @@ -328,7 +328,7 @@ export class FormAutofillHandler { // Use case for multiple select is not considered here. if (!option.selected) { option.selected = true; - this.fillFieldValue(element, option.value); + FormAutofillHandler.fillFieldValue(element, option.value); } // Autofill highlight appears regardless if value is changed or not this.changeFieldState(fieldDetail, FIELD_STATES.AUTO_FILLED); @@ -844,8 +844,13 @@ export class FormAutofillHandler { } return value; } - - fillFieldValue(element, value) { + /** + * Fills the provided element with the specified value. + * + * @param {HTMLInputElement| HTMLSelectElement} element - The form field element to be filled. + * @param {string} value - The value to be filled into the form field. + */ + static fillFieldValue(element, value) { if (FormAutofillUtils.focusOnAutofill) { element.focus({ preventScroll: true }); } diff --git a/firefox-ios/Client/Assets/CC_Script/HeuristicsRegExp.sys.mjs b/firefox-ios/Client/Assets/CC_Script/HeuristicsRegExp.sys.mjs index 1b7ff0d0b61f..359e9541108f 100644 --- a/firefox-ios/Client/Assets/CC_Script/HeuristicsRegExp.sys.mjs +++ b/firefox-ios/Client/Assets/CC_Script/HeuristicsRegExp.sys.mjs @@ -47,6 +47,7 @@ export const HeuristicsRegExp = { "address-line2": "addrline2|address_2|addl2", "address-line3": "addrline3|address_3|addl3", "address-level1": "land", // de-DE + "postal-code": "^PLZ(\\b|\\*)", // de-DE "additional-name": "apellido.?materno|lastlastname", "cc-name": "accountholdername" +