Bug 1551407 - Move string utilities to the top-level of LoginAutoCompleteResult.jsm. r=sfoster
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 20 May 2019 18:21:36 +0000
changeset 474580 c74ca2406a0d4c550c998a5e911d7262351b75eb
parent 474579 00df22944d9abc5b26009738e4cfc4070ff2ed66
child 474581 a737c603ae331d23393d618aaf2292395799c3a6
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 - Move string utilities to the top-level of LoginAutoCompleteResult.jsm. r=sfoster Differential Revision: https://phabricator.services.mozilla.com/D31029
toolkit/components/passwordmgr/LoginAutoCompleteResult.jsm
--- a/toolkit/components/passwordmgr/LoginAutoCompleteResult.jsm
+++ b/toolkit/components/passwordmgr/LoginAutoCompleteResult.jsm
@@ -31,16 +31,19 @@ XPCOMUtils.defineLazyServiceGetter(this,
                                    "@mozilla.org/satchel/form-fill-controller;1",
                                    Ci.nsIFormFillController);
 XPCOMUtils.defineLazyPreferenceGetter(this, "SHOULD_SHOW_ORIGIN",
                                       "signon.showAutoCompleteOrigins");
 
 XPCOMUtils.defineLazyGetter(this, "log", () => {
   return LoginHelper.createLogger("LoginAutoCompleteResult");
 });
+XPCOMUtils.defineLazyGetter(this, "passwordMgrBundle", () => {
+  return Services.strings.createBundle("chrome://passwordmgr/locale/passwordmgr.properties");
+});
 
 function loginSort(a, b) {
   let userA = a.username.toLowerCase();
   let userB = b.username.toLowerCase();
 
   if (userA < userB) {
     return -1;
   }
@@ -59,16 +62,23 @@ function findDuplicates(loginList) {
     if (seen.has(login.username)) {
       duplicates.add(login.username);
     }
     seen.add(login.username);
   }
   return duplicates;
 }
 
+function getLocalizedString(key, formatArgs = null) {
+  if (formatArgs) {
+    return passwordMgrBundle.formatStringFromName(key, formatArgs, formatArgs.length);
+  }
+  return passwordMgrBundle.GetStringFromName(key);
+}
+
 // nsIAutoCompleteResult implementation
 function LoginAutoCompleteResult(aSearchString, matchingLogins, {
   isSecure,
   messageManager,
   isPasswordField,
   hostname,
 }) {
   let hidingFooterOnPWFieldAutoOpened = false;
@@ -97,17 +107,16 @@ function LoginAutoCompleteResult(aSearch
 
   this._showInsecureFieldWarning = (!isSecure && LoginHelper.showInsecureFieldWarning) ? 1 : 0;
   this._showAutoCompleteFooter = isFooterEnabled() ? 1 : 0;
   this._showOrigin = SHOULD_SHOW_ORIGIN ? 1 : 0;
   this.searchString = aSearchString;
   this.logins = matchingLogins.sort(loginSort);
   this.matchCount = matchingLogins.length + this._showInsecureFieldWarning + this._showAutoCompleteFooter;
   this._messageManager = messageManager;
-  this._stringBundle = Services.strings.createBundle("chrome://passwordmgr/locale/passwordmgr.properties");
   this._dateAndTimeFormatter = new Services.intl.DateTimeFormat(undefined, { dateStyle: "medium" });
 
   this._isPasswordField = isPasswordField;
   this._hostname = hostname;
 
   this._duplicateUsernames = findDuplicates(matchingLogins);
 
   if (this.matchCount > 0) {
@@ -159,23 +168,16 @@ LoginAutoCompleteResult.prototype = {
     return this._isPasswordField ? selectedLogin.password : selectedLogin.username;
   },
 
   getLabelAt(index) {
     if (index < 0 || index >= this.matchCount) {
       throw new Error("Index out of range.");
     }
 
-    let getLocalizedString = (key, formatArgs = null) => {
-      if (formatArgs) {
-        return this._stringBundle.formatStringFromName(key, formatArgs, formatArgs.length);
-      }
-      return this._stringBundle.GetStringFromName(key);
-    };
-
     if (this._showInsecureFieldWarning && index === 0) {
       let learnMoreString = getLocalizedString("insecureFieldWarningLearnMore");
       return getLocalizedString("insecureFieldWarningDescription2", [learnMoreString]);
     } else if (this._showAutoCompleteFooter && index === this.matchCount - 1) {
       return JSON.stringify({
         label: getLocalizedString("viewSavedLogins.label"),
         hostname: this._hostname,
       });