From da4c7e7ed675c3bf405668739c3012d140856109 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:34:42 +0200 Subject: Adding upstream version 126.0. Signed-off-by: Daniel Baumann --- .../formautofill/shared/FormAutofillUtils.sys.mjs | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs') diff --git a/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs b/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs index e86f14975c..c2b48a53a3 100644 --- a/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs +++ b/toolkit/components/formautofill/shared/FormAutofillUtils.sys.mjs @@ -176,6 +176,12 @@ FormAutofillUtils = { return Array.from(categories); }, + getCollectionNameFromFieldName(fieldName) { + return this.isCreditCardField(fieldName) + ? CREDITCARDS_COLLECTION_NAME + : ADDRESSES_COLLECTION_NAME; + }, + getAddressSeparator() { // The separator should be based on the L10N address format, and using a // white space is a temporary solution. @@ -799,6 +805,42 @@ FormAutofillUtils = { return null; }, + /** + * Find the option element from xul menu popups, as used in address capture + * doorhanger. + * + * This is a proxy to `findAddressSelectOption`, which expects HTML select + * DOM nodes and operates on options instead of xul menuitems. + * + * NOTE: This is a temporary solution until Bug 1886949 is landed. This + * method will then be removed `findAddressSelectOption` will be used + * directly. + * + * @param {XULPopupElement} menupopup + * @param {object} address + * @param {string} fieldName + * @returns {XULElement} + */ + findAddressSelectOptionWithMenuPopup(menupopup, address, fieldName) { + class MenuitemProxy { + constructor(menuitem) { + this.menuitem = menuitem; + } + get text() { + return this.menuitem.label; + } + get value() { + return this.menuitem.value; + } + } + const selectEl = { + options: Array.from(menupopup.childNodes).map( + menuitem => new MenuitemProxy(menuitem) + ), + }; + return this.findAddressSelectOption(selectEl, address, fieldName)?.menuitem; + }, + findCreditCardSelectOption(selectEl, creditCard, fieldName) { let oneDigitMonth = creditCard["cc-exp-month"] ? creditCard["cc-exp-month"].toString() -- cgit v1.2.3