summaryrefslogtreecommitdiffstats
path: root/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs')
-rw-r--r--toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs95
1 files changed, 27 insertions, 68 deletions
diff --git a/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs b/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs
index fc3f0454b0..7594fc8fcf 100644
--- a/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs
+++ b/toolkit/components/formautofill/AutofillProfileAutoComplete.sys.mjs
@@ -6,7 +6,10 @@
* Form Autofill content process module.
*/
-import { GenericAutocompleteItem } from "resource://gre/modules/FillHelpers.sys.mjs";
+import {
+ GenericAutocompleteItem,
+ sendFillRequestToParent,
+} from "resource://gre/modules/FillHelpers.sys.mjs";
/* eslint-disable no-use-before-define */
@@ -31,16 +34,6 @@ const autocompleteController = Cc[
ChromeUtils.defineLazyGetter(
lazy,
- "ADDRESSES_COLLECTION_NAME",
- () => lazy.FormAutofillUtils.ADDRESSES_COLLECTION_NAME
-);
-ChromeUtils.defineLazyGetter(
- lazy,
- "CREDITCARDS_COLLECTION_NAME",
- () => lazy.FormAutofillUtils.CREDITCARDS_COLLECTION_NAME
-);
-ChromeUtils.defineLazyGetter(
- lazy,
"FIELD_STATES",
() => lazy.FormAutofillUtils.FIELD_STATES
);
@@ -191,14 +184,8 @@ AutofillProfileAutoCompleteSearch.prototype = {
isInputAutofilled,
});
} else {
- let infoWithoutElement = { ...activeFieldDetail };
- delete infoWithoutElement.elementWeakRef;
-
- let data = {
- collectionName: isAddressField
- ? lazy.ADDRESSES_COLLECTION_NAME
- : lazy.CREDITCARDS_COLLECTION_NAME,
- info: infoWithoutElement,
+ const data = {
+ fieldName: activeFieldDetail.fieldName,
searchString,
};
@@ -284,12 +271,10 @@ AutofillProfileAutoCompleteSearch.prototype = {
* Input element for autocomplete.
* @param {object} data
* Parameters for querying the corresponding result.
- * @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.fieldName
+ * The identified field name for the input
* @returns {Promise}
* Promise that resolves when addresses returned from parent process.
*/
@@ -368,44 +353,6 @@ export const ProfileAutocomplete = {
}
},
- fillRequestId: 0,
-
- async sendFillRequestToFormAutofillParent(input, comment) {
- if (!comment) {
- return false;
- }
-
- if (!input || input != autocompleteController?.input.focusedInput) {
- return false;
- }
-
- const { fillMessageName, fillMessageData } = JSON.parse(comment ?? "{}");
- if (!fillMessageName) {
- return false;
- }
-
- this.fillRequestId++;
- const fillRequestId = this.fillRequestId;
- const actor = getActorFromWindow(input.ownerGlobal, "FormAutofill");
- const value = await actor.sendQuery(fillMessageName, fillMessageData ?? {});
-
- // skip fill if another fill operation started during await
- if (fillRequestId != this.fillRequestId) {
- return false;
- }
-
- if (typeof value !== "string") {
- return false;
- }
-
- // If AutoFillParent returned a string to fill, we must do it here because
- // nsAutoCompleteController.cpp already finished it's work before we finished await.
- input.setUserInput(value);
- input.select(value.length, value.length);
-
- return true;
- },
-
_getSelectedIndex(contentWindow) {
let actor = getActorFromWindow(contentWindow, "AutoComplete");
if (!actor) {
@@ -431,18 +378,31 @@ export const ProfileAutocomplete = {
? this.lastProfileAutoCompleteResult.getCommentAt(selectedIndex)
: null;
+ let profile = JSON.parse(comment);
if (
selectedIndex == -1 ||
!this.lastProfileAutoCompleteResult ||
- this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) !=
- "autofill-profile"
+ this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) != "autofill"
) {
- await this.sendFillRequestToFormAutofillParent(focusedInput, comment);
+ if (
+ focusedInput &&
+ focusedInput == autocompleteController?.input.focusedInput
+ ) {
+ if (profile?.fillMessageName == "FormAutofill:ClearForm") {
+ // The child can do this directly.
+ getActorFromWindow(focusedInput.ownerGlobal)?.clearForm();
+ } else {
+ // Pass focusedInput as both input arguments.
+ await sendFillRequestToParent(
+ "FormAutofill",
+ autocompleteController.input,
+ comment
+ );
+ }
+ }
return;
}
- let profile = JSON.parse(comment);
-
await lazy.FormAutofillContent.activeHandler.autofillFormFields(profile);
},
@@ -468,8 +428,7 @@ export const ProfileAutocomplete = {
if (
!this.lastProfileAutoCompleteResult ||
- this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) !=
- "autofill-profile"
+ this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) != "autofill"
) {
return;
}