Bug 1318203 - Login manager autoCompleteSearchAsync helper to not complete canceled searches. r=mossop a=jcristau
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Tue, 03 Jan 2017 11:44:43 -0500
changeset 353318 98f702a24bea42d7e3f248cdaa74b66daf83a17e
parent 353317 218db8b47b80de47bf6fe624aea9c545a3e01e4e
child 353319 917b84b3b941b70c9cc29847f43bfe6b8731ec20
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop, jcristau
bugs1318203
milestone52.0a2
Bug 1318203 - Login manager autoCompleteSearchAsync helper to not complete canceled searches. r=mossop a=jcristau 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]);