diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /toolkit/components/formautofill/FormAutofillParent.sys.mjs | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/formautofill/FormAutofillParent.sys.mjs')
-rw-r--r-- | toolkit/components/formautofill/FormAutofillParent.sys.mjs | 103 |
1 files changed, 29 insertions, 74 deletions
diff --git a/toolkit/components/formautofill/FormAutofillParent.sys.mjs b/toolkit/components/formautofill/FormAutofillParent.sys.mjs index 61c4bd2943..34dac8ce15 100644 --- a/toolkit/components/formautofill/FormAutofillParent.sys.mjs +++ b/toolkit/components/formautofill/FormAutofillParent.sys.mjs @@ -84,21 +84,6 @@ export let FormAutofillStatus = { Services.prefs.addObserver(ENABLED_AUTOFILL_CREDITCARDS_PREF, this); } - // We have to use empty window type to get all opened windows here because the - // window type parameter may not be available during startup. - for (let win of Services.wm.getEnumerator("")) { - let { documentElement } = win.document; - if (documentElement?.getAttribute("windowtype") == "navigator:browser") { - this.injectElements(win.document); - } else { - // Manually call onOpenWindow for windows that are already opened but not - // yet have the window type set. This ensures we inject the elements we need - // when its docuemnt is ready. - this.onOpenWindow(win); - } - } - Services.wm.addListener(this); - Services.telemetry.setEventRecordingEnabled("creditcard", true); Services.telemetry.setEventRecordingEnabled("address", true); }, @@ -198,31 +183,6 @@ export let FormAutofillStatus = { this.updateStatus(); }, - injectElements(doc) { - Services.scriptloader.loadSubScript( - "chrome://formautofill/content/customElements.js", - doc.ownerGlobal - ); - }, - - onOpenWindow(xulWindow) { - const win = xulWindow.docShell.domWindow; - win.addEventListener( - "load", - () => { - if ( - win.document.documentElement.getAttribute("windowtype") == - "navigator:browser" - ) { - this.injectElements(win.document); - } - }, - { once: true } - ); - }, - - onCloseWindow() {}, - async observe(subject, topic, data) { lazy.log.debug("observe:", topic, "with data:", data); switch (topic) { @@ -312,7 +272,7 @@ export class FormAutofillParent extends JSWindowActorParent { scenarioName: data.scenarioName, hasInput: !!data.searchString?.length, }); - const recordsPromise = FormAutofillParent._getRecords(data); + const recordsPromise = FormAutofillParent.getRecords(data); const [records, externalEntries] = await Promise.all([ recordsPromise, relayPromise, @@ -448,42 +408,42 @@ export class FormAutofillParent extends JSWindowActorParent { * * This is static as a unit test calls this. * - * @private * @param {object} data - * @param {string} data.collectionName - * The name used to specify which collection to retrieve records. * @param {string} data.searchString * The typed string for filtering out the matched records. - * @param {string} data.info - * The input autocomplete property's information. + * @param {string} data.collectionName + * The name used to specify which collection to retrieve records. + * @param {string} data.fieldName + * The field name to search. If not specified, return all records in + * the collection */ - static async _getRecords({ collectionName, searchString, info }) { - let collection = lazy.gFormAutofillStorage[collectionName]; + static async getRecords({ searchString, collectionName, fieldName }) { + // Derive the collection name from field name if it doesn't exist + collectionName ||= + FormAutofillUtils.getCollectionNameFromFieldName(fieldName); + + const collection = lazy.gFormAutofillStorage[collectionName]; if (!collection) { return []; } - let recordsInCollection = await collection.getAll(); - if (!info || !info.fieldName || !recordsInCollection.length) { - return recordsInCollection; + const records = await collection.getAll(); + if (!fieldName || !records.length) { + return records; } - let isCC = collectionName == CREDITCARDS_COLLECTION_NAME; // We don't filter "cc-number" - if (isCC && info.fieldName == "cc-number") { - recordsInCollection = recordsInCollection.filter( - record => !!record["cc-number"] - ); - return recordsInCollection; + if (collectionName == CREDITCARDS_COLLECTION_NAME) { + if (fieldName == "cc-number") { + return records.filter(record => !!record["cc-number"]); + } } - let records = []; - let lcSearchString = searchString.toLowerCase(); - - for (let record of recordsInCollection) { - let fieldValue = record[info.fieldName]; + const lcSearchString = searchString.toLowerCase(); + return records.filter(record => { + const fieldValue = record[fieldName]; if (!fieldValue) { - continue; + return false; } if ( @@ -493,19 +453,14 @@ export class FormAutofillParent extends JSWindowActorParent { ) { // Address autofill isn't supported for the record's country so we don't // want to attempt to potentially incorrectly fill the address fields. - continue; - } - - if ( - lcSearchString && - !String(fieldValue).toLowerCase().startsWith(lcSearchString) - ) { - continue; + return false; } - records.push(record); - } - return records; + return ( + !lcSearchString || + String(fieldValue).toLowerCase().startsWith(lcSearchString) + ); + }); } async _onAddressSubmit(address, browser) { |