Bug 1551407 - Read login autocomplete comments from the AutocompleteItem instance. r=sfoster
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 20 May 2019 18:21:51 +0000
changeset 474584 801ff26b3c1de20fb8944eecd3899e49df76dd0e
parent 474583 dafc626c659054ce9feccae7632056cbe45a8751
child 474585 289880efd19336feedf4dc5c3d75c799446398bb
push id36042
push userdvarga@mozilla.com
push dateTue, 21 May 2019 04:19:40 +0000
treeherdermozilla-central@ca560ff55451 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs1551407
milestone69.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1551407 - Read login autocomplete comments from the AutocompleteItem instance. r=sfoster Differential Revision: https://phabricator.services.mozilla.com/D31033
toolkit/components/passwordmgr/LoginAutoCompleteResult.jsm
--- a/toolkit/components/passwordmgr/LoginAutoCompleteResult.jsm
+++ b/toolkit/components/passwordmgr/LoginAutoCompleteResult.jsm
@@ -72,16 +72,17 @@ function getLocalizedString(key, formatA
     return passwordMgrBundle.formatStringFromName(key, formatArgs, formatArgs.length);
   }
   return passwordMgrBundle.GetStringFromName(key);
 }
 
 
 class AutocompleteItem {
   constructor(style) {
+    this.comment = "";
     this.style = style;
     this.value = "";
   }
 }
 
 class InsecureLoginFormAutocompleteItem extends AutocompleteItem {
   constructor() {
     super("insecureWarning");
@@ -110,16 +111,22 @@ class LoginAutocompleteItem extends Auto
       }
 
       return username;
     });
 
     XPCOMUtils.defineLazyGetter(this, "value", () => {
       return isPasswordField ? login.password : login.username;
     });
+
+    XPCOMUtils.defineLazyGetter(this, "comment", () => {
+      return JSON.stringify({
+        loginOrigin: login.hostname,
+      });
+    });
   }
 }
 
 class LoginsFooterAutocompleteItem extends AutocompleteItem {
   constructor(hostname) {
     super("loginsFooter");
 
     XPCOMUtils.defineLazyGetter(this, "label", () => {
@@ -231,28 +238,20 @@ LoginAutoCompleteResult.prototype = {
   getLabelAt(index) {
     if (index < 0 || index >= this.matchCount) {
       throw new Error("Index out of range.");
     }
     return this.results[index].label;
   },
 
   getCommentAt(index) {
-    if (this._showInsecureFieldWarning && index === 0) {
-      return "";
+    if (index < 0 || index >= this.matchCount) {
+      throw new Error("Index out of range.");
     }
-
-    if (this._showAutoCompleteFooter && index === this.matchCount - 1) {
-      return "";
-    }
-
-    let login = this.logins[index - this._showInsecureFieldWarning];
-    return JSON.stringify({
-      loginOrigin: login.hostname,
-    });
+    return this.results[index].comment;
   },
 
   getStyleAt(index) {
     return this.results[index].style;
   },
 
   getImageAt(index) {
     return "";