Skip to content

Commit

Permalink
Refactor - auto update credential provider script (#21975)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Sep 17, 2024
1 parent 3c9362c commit 8e4a4d4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -70,6 +73,9 @@ export class FormAutofillChild {
this.#sections = FormAutofillSection.classifySections(
handler.fieldDetails
);

// For telemetry
this.#sections.forEach(section => section.onDetected());
}
}

Expand Down Expand Up @@ -146,6 +152,8 @@ export class FormAutofillChild {
} else {
throw new Error("Unknown section type");
}

section.onSubmitted(formFilledData);
}

if (creditCard.length) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
13 changes: 9 additions & 4 deletions firefox-ios/Client/Assets/CC_Script/FormAutofillHandler.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down

0 comments on commit 8e4a4d4

Please sign in to comment.