Bug 1318203 - Don't show autocomplete UI on Password Field if it is already populated with text, r=MattN draft
authorTimothy Guan-tin Chien <timdream@gmail.com>
Fri, 23 Dec 2016 14:01:39 -0500
changeset 453511 2a4bc9552ef4e12c439b1e670d6dcf928b550cf6
parent 453510 3475a52bbcd358c8f8c2177e162fa50795d5b821
child 540491 36a14a62d3ea253820496d9ed14529e586bc4ade
push id39697
push usermozilla@noorenberghe.ca
push dateFri, 23 Dec 2016 19:05:15 +0000
reviewersMattN
bugs1318203
milestone53.0a1
Bug 1318203 - Don't show autocomplete UI on Password Field if it is already populated with text, r=MattN MozReview-Commit-ID: L3cUxHYIE5R
toolkit/components/passwordmgr/nsLoginManager.js
--- a/toolkit/components/passwordmgr/nsLoginManager.js
+++ b/toolkit/components/passwordmgr/nsLoginManager.js
@@ -497,43 +497,44 @@ LoginManager.prototype = {
       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 (isPasswordField && aSearchString) {
+      // Return empty result on password fields with password already filled.
+      let acLookupPromise = this._autoCompleteLookupPromise = Promise.resolve({ logins: [] });
+      acLookupPromise.then(completeSearch.bind(this, acLookupPromise));
+      return;
     }
 
     if (!this._remember) {
-      setTimeout(function() {
-        aCallback.onSearchCompletion(new UserAutoCompleteResult(aSearchString, [], {isSecure}));
-      }, 0);
+      let acLookupPromise = this._autoCompleteLookupPromise = Promise.resolve({ logins: [] });
+      acLookupPromise.then(completeSearch.bind(this, acLookupPromise));
       return;
     }
 
     log.debug("AutoCompleteSearch invoked. Search is:", aSearchString);
 
     let previousResult;
     if (aPreviousResult) {
       previousResult = { searchString: aPreviousResult.searchString,
                          logins: aPreviousResult.wrappedJSObject.logins };
     } else {
       previousResult = null;
     }
 
     let rect = BrowserUtils.getElementBoundingScreenRect(aElement);
-    let autoCompleteLookupPromise = this._autoCompleteLookupPromise =
+    let acLookupPromise = this._autoCompleteLookupPromise =
       LoginManagerContent._autoCompleteSearchAsync(aSearchString, previousResult,
                                                    aElement, rect);
-    autoCompleteLookupPromise.then(completeSearch.bind(this, autoCompleteLookupPromise))
+    acLookupPromise.then(completeSearch.bind(this, acLookupPromise))
                              .then(null, Cu.reportError);
   },
 
   stopSearch() {
     this._autoCompleteLookupPromise = null;
   },
 }; // end of LoginManager implementation