Bug 1318203 - Login manager autoCompleteSearchAsync helper to not complete canceled searches. r=timdream
MozReview-Commit-ID: wBcORBANyS
--- a/toolkit/components/passwordmgr/nsLoginManager.js
+++ b/toolkit/components/passwordmgr/nsLoginManager.js
@@ -480,16 +480,33 @@ LoginManager.prototype = {
autoCompleteSearchAsync(aSearchString, aPreviousResult,
aElement, aCallback) {
// aPreviousResult is an nsIAutoCompleteResult, aElement is
// nsIDOMHTMLInputElement
let form = LoginFormFactory.createFromField(aElement);
let isSecure = InsecurePasswordUtils.isFormSecure(form);
let isPasswordField = aElement.type == "password";
+
+ let completeSearch = (autoCompleteLookupPromise, { logins, messageManager }) => {
+ // If the search was canceled before we got our
+ // results, don't bother reporting them.
+ if (this._autoCompleteLookupPromise !== autoCompleteLookupPromise) {
+ return;
+ }
+
+ this._autoCompleteLookupPromise = null;
+ let results = new UserAutoCompleteResult(aSearchString, logins, {
+ messageManager,
+ isSecure,
+ isPasswordField,
+ });
+ aCallback.onSearchCompletion(results);
+ };
+
if (isPasswordField) {
// The login items won't be filtered for password field.
aSearchString = "";
}
if (!this._remember) {
setTimeout(function() {
aCallback.onSearchCompletion(new UserAutoCompleteResult(aSearchString, [], {isSecure}));
@@ -506,33 +523,18 @@ LoginManager.prototype = {
} else {
previousResult = null;
}
let rect = BrowserUtils.getElementBoundingScreenRect(aElement);
let autoCompleteLookupPromise = this._autoCompleteLookupPromise =
LoginManagerContent._autoCompleteSearchAsync(aSearchString, previousResult,
aElement, rect);
- autoCompleteLookupPromise.then(({ logins, messageManager }) => {
- // If the search was canceled before we got our
- // results, don't bother reporting them.
- if (this._autoCompleteLookupPromise !== autoCompleteLookupPromise) {
- return;
- }
-
- this._autoCompleteLookupPromise = null;
- let results =
- new UserAutoCompleteResult(aSearchString, logins, {
- messageManager,
- isSecure,
- isPasswordField,
- });
- aCallback.onSearchCompletion(results);
- })
- .then(null, Cu.reportError);
+ autoCompleteLookupPromise.then(completeSearch.bind(this, autoCompleteLookupPromise))
+ .then(null, Cu.reportError);
},
stopSearch() {
this._autoCompleteLookupPromise = null;
},
}; // end of LoginManager implementation
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([LoginManager]);