Bug 1413473 - Verify current focused input to determine whether the opening popup is for form autofill in order not to accidentally open new tab in wrong result types. r=lchang

MozReview-Commit-ID: JFvSxHsKC1P

--HG--
extra : rebase_source : 0c4a134632392f7f7e3c5d7c60a0b36c336996f9
This commit is contained in:
Ray Lin 2017-11-02 13:42:12 +08:00
parent abe0912713
commit 8d716cdae1
2 changed files with 23 additions and 25 deletions

View File

@ -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;
}

View File

@ -89,7 +89,7 @@ var FormAutofillFrameScript = {
break;
}
case "FormAutoComplete:PopupClosed": {
FormAutofillContent.previewProfile(doc);
FormAutofillContent.onPopupClosed();
chromeEventHandler.removeEventListener("keydown", FormAutofillContent._onKeyDown,
{capturing: true});
break;