Bug 1318203 - Login manager autoCompleteSearchAsync helper to not complete canceled searches. r=timdream draft
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Fri, 23 Dec 2016 14:01:18 -0500
changeset 453510 3475a52bbcd358c8f8c2177e162fa50795d5b821
parent 452495 ab439ec85d1556fdeaf5aafb5261bfa452a69f4e
child 453511 2a4bc9552ef4e12c439b1e670d6dcf928b550cf6
push id39697
push usermozilla@noorenberghe.ca
push dateFri, 23 Dec 2016 19:05:15 +0000
reviewerstimdream
bugs1318203
milestone53.0a1
Bug 1318203 - Login manager autoCompleteSearchAsync helper to not complete canceled searches. r=timdream MozReview-Commit-ID: wBcORBANyS
toolkit/components/passwordmgr/nsLoginManager.js
--- 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]);