diff --git a/browser/extensions/formautofill/FormAutofillContent.jsm b/browser/extensions/formautofill/FormAutofillContent.jsm index 33c990823669..f9dd5049814e 100644 --- a/browser/extensions/formautofill/FormAutofillContent.jsm +++ b/browser/extensions/formautofill/FormAutofillContent.jsm @@ -108,6 +108,7 @@ AutofillProfileAutoCompleteSearch.prototype = { FormAutofillUtils.isAutofillAddressesEnabled : FormAutofillUtils.isAutofillCreditCardsEnabled; + ProfileAutocomplete.lastProfileAutoCompleteFocusedInput = focusedInput; // Fallback to form-history if ... // - specified autofill feature is pref off. // - no profile can fill the currently-focused input. @@ -126,7 +127,7 @@ AutofillProfileAutoCompleteSearch.prototype = { formHistory.startSearch(searchString, searchParam, previousResult, { onSearchResult: (search, result) => { listener.onSearchResult(this, result); - ProfileAutocomplete.setProfileAutoCompleteResult(result); + ProfileAutocomplete.lastProfileAutoCompleteResult = result; }, }); return; @@ -166,7 +167,7 @@ AutofillProfileAutoCompleteSearch.prototype = { {isSecure}); } listener.onSearchResult(this, result); - ProfileAutocomplete.setProfileAutoCompleteResult(result); + ProfileAutocomplete.lastProfileAutoCompleteResult = result; }); }, @@ -174,7 +175,7 @@ AutofillProfileAutoCompleteSearch.prototype = { * Stops an asynchronous search that is in progress */ stopSearch() { - ProfileAutocomplete.setProfileAutoCompleteResult(null); + ProfileAutocomplete.lastProfileAutoCompleteResult = null; this.forceStop = true; }, @@ -211,8 +212,8 @@ this.NSGetFactory = XPCOMUtils.generateNSGetFactory([AutofillProfileAutoComplete let ProfileAutocomplete = { QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]), - _lastAutoCompleteResult: null, - _lastAutoCompleteFocusedInput: null, + lastProfileAutoCompleteResult: null, + lastProfileAutoCompleteFocusedInput: null, _registered: false, _factory: null, @@ -244,15 +245,6 @@ let ProfileAutocomplete = { Services.obs.removeObserver(this, "autocomplete-will-enter-text"); }, - getProfileAutoCompleteResult() { - return this._lastAutoCompleteResult; - }, - - setProfileAutoCompleteResult(result) { - this._lastAutoCompleteResult = result; - this._lastAutoCompleteFocusedInput = formFillController.focusedInput; - }, - observe(subject, topic, data) { switch (topic) { case "autocomplete-will-enter-text": { @@ -293,19 +285,19 @@ let ProfileAutocomplete = { let selectedIndex = this._getSelectedIndex(focusedInput.ownerGlobal); if (selectedIndex == -1 || - !this._lastAutoCompleteResult || - this._lastAutoCompleteResult.getStyleAt(selectedIndex) != "autofill-profile") { + !this.lastProfileAutoCompleteResult || + this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) != "autofill-profile") { return; } - let profile = JSON.parse(this._lastAutoCompleteResult.getCommentAt(selectedIndex)); + let profile = JSON.parse(this.lastProfileAutoCompleteResult.getCommentAt(selectedIndex)); let formHandler = FormAutofillContent.getFormHandler(focusedInput); formHandler.autofillFormFields(profile, focusedInput); }, _clearProfilePreview() { - let focusedInput = formFillController.focusedInput || this._lastAutoCompleteFocusedInput; + let focusedInput = formFillController.focusedInput || this.lastProfileAutoCompleteFocusedInput; if (!focusedInput || !FormAutofillContent.getFormDetails(focusedInput)) { return; } @@ -322,12 +314,12 @@ let ProfileAutocomplete = { return; } - if (!this._lastAutoCompleteResult || - this._lastAutoCompleteResult.getStyleAt(selectedIndex) != "autofill-profile") { + if (!this.lastProfileAutoCompleteResult || + this.lastProfileAutoCompleteResult.getStyleAt(selectedIndex) != "autofill-profile") { return; } - let profile = JSON.parse(this._lastAutoCompleteResult.getCommentAt(selectedIndex)); + let profile = JSON.parse(this.lastProfileAutoCompleteResult.getCommentAt(selectedIndex)); let formHandler = FormAutofillContent.getFormHandler(focusedInput); formHandler.previewFormFields(profile, focusedInput); @@ -522,7 +514,7 @@ var FormAutofillContent = { previewProfile(doc) { let docWin = doc.ownerGlobal; let selectedIndex = ProfileAutocomplete._getSelectedIndex(docWin); - let lastAutoCompleteResult = ProfileAutocomplete.getProfileAutoCompleteResult(); + let lastAutoCompleteResult = ProfileAutocomplete.lastProfileAutoCompleteResult; let focusedInput = formFillController.focusedInput; let mm = this._messageManagerFromWindow(docWin); @@ -550,6 +542,11 @@ var FormAutofillContent = { } }, + onPopupClosed() { + ProfileAutocomplete._clearProfilePreview(); + ProfileAutocomplete.lastProfileAutoCompleteResult = null; + }, + _markAsAutofillField(field) { // Since Form Autofill popup is only for input element, any non-Input // element should be excluded here. @@ -569,10 +566,11 @@ var FormAutofillContent = { }, _onKeyDown(e) { - let lastAutoCompleteResult = ProfileAutocomplete.getProfileAutoCompleteResult(); + let lastAutoCompleteResult = ProfileAutocomplete.lastProfileAutoCompleteResult; let focusedInput = formFillController.focusedInput; - if (e.keyCode != Ci.nsIDOMKeyEvent.DOM_VK_RETURN || !lastAutoCompleteResult || !focusedInput) { + if (e.keyCode != Ci.nsIDOMKeyEvent.DOM_VK_RETURN || !lastAutoCompleteResult || + !focusedInput || focusedInput != ProfileAutocomplete.lastProfileAutoCompleteFocusedInput) { return; } diff --git a/browser/extensions/formautofill/content/FormAutofillFrameScript.js b/browser/extensions/formautofill/content/FormAutofillFrameScript.js index e712bd34f1bc..201528c92bce 100644 --- a/browser/extensions/formautofill/content/FormAutofillFrameScript.js +++ b/browser/extensions/formautofill/content/FormAutofillFrameScript.js @@ -89,7 +89,7 @@ var FormAutofillFrameScript = { break; } case "FormAutoComplete:PopupClosed": { - FormAutofillContent.previewProfile(doc); + FormAutofillContent.onPopupClosed(); chromeEventHandler.removeEventListener("keydown", FormAutofillContent._onKeyDown, {capturing: true}); break;