Bug 1266836 - Part 3 - Rename window to chromeWindow, clean up _getNotifyWindow in nsLoginManagerPrompter. r=MattN draft
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 30 Aug 2016 12:31:56 +0200
changeset 407419 6125f21f1e29039b0ca24714f783c8bba67ffd85
parent 407418 92be042e1d662242f751e450d910f27ecdc05b22
child 529882 131683df3e19ab351f5dfc00b5495482476e7a86
push id27972
push userbmo:jhofmann@mozilla.com
push dateTue, 30 Aug 2016 14:04:51 +0000
reviewersMattN
bugs1266836
milestone51.0a1
Bug 1266836 - Part 3 - Rename window to chromeWindow, clean up _getNotifyWindow in nsLoginManagerPrompter. r=MattN MozReview-Commit-ID: GetpnTlBtxg
toolkit/components/passwordmgr/nsLoginManagerPrompter.js
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -252,18 +252,18 @@ LoginManagerPrompter.prototype = {
       } catch (e) { }
     }
     return this.__ellipsis;
   },
 
 
   // Whether we are in private browsing mode
   get _inPrivateBrowsing() {
-    if (this._window) {
-      return PrivateBrowsingUtils.isContentWindowPrivate(this._window);
+    if (this._chromeWindow) {
+      return PrivateBrowsingUtils.isWindowPrivate(this._chromeWindow);
     }
     // If we don't that we're in private browsing mode if the caller did
     // not provide a window.  The callers which really care about this
     // will indeed pass down a window to us, and for those who don't,
     // we can just assume that we don't want to save the entered login
     // information.
     return true;
   },
@@ -285,17 +285,17 @@ LoginManagerPrompter.prototype = {
                                      Cr.NS_ERROR_NOT_IMPLEMENTED);
 
     this.log("===== prompt() called =====");
 
     if (aDefaultText) {
       aResult.value = aDefaultText;
     }
 
-    return this._promptService.prompt(this._window,
+    return this._promptService.prompt(this._chromeWindow,
            aDialogTitle, aText, aResult, null, {});
   },
 
 
   /**
    * Looks up a username and password in the database. Will prompt the user
    * with a dialog, even if a username and password are found.
    */
@@ -347,17 +347,17 @@ LoginManagerPrompter.prototype = {
           aUsername.value = selectedLogin.username;
           // If the caller provided a password, prefer it.
           if (!aPassword.value)
             aPassword.value = selectedLogin.password;
         }
       }
     }
 
-    var ok = this._promptService.promptUsernameAndPassword(this._window,
+    var ok = this._promptService.promptUsernameAndPassword(this._chromeWindow,
                 aDialogTitle, aText, aUsername, aPassword,
                 checkBoxLabel, checkBox);
 
     if (!ok || !checkBox.value || !hostname)
       return ok;
 
     if (!aPassword.value) {
       this.log("No password entered, so won't offer to save.");
@@ -438,17 +438,17 @@ LoginManagerPrompter.prototype = {
             aPassword.value = foundLogins[i].password;
             // wallet returned straight away, so this mimics that code
             return true;
           }
         }
       }
     }
 
-    var ok = this._promptService.promptPassword(this._window, aDialogTitle,
+    var ok = this._promptService.promptPassword(this._chromeWindow, aDialogTitle,
                                                 aText, aPassword,
                                                 checkBoxLabel, checkBox);
 
     if (ok && checkBox.value && hostname && aPassword.value) {
       var newLogin = Cc["@mozilla.org/login-manager/loginInfo;1"].
                      createInstance(Ci.nsILoginInfo);
       newLogin.init(hostname, null, realm, username,
                     aPassword.value, "", "");
@@ -558,19 +558,19 @@ LoginManagerPrompter.prototype = {
       // Ignore any errors and display the prompt anyway.
       epicfail = true;
       Components.utils.reportError("LoginManagerPrompter: " +
           "Epic fail in promptAuth: " + e + "\n");
     }
 
     var ok = canAutologin;
     if (!ok) {
-      if (this._window)
-        PromptUtils.fireDialogEvent(this._window, "DOMWillOpenModalDialog", this._browser);
-      ok = this._promptService.promptAuth(this._window,
+      if (this._chromeWindow)
+        PromptUtils.fireDialogEvent(this._chromeWindow, "DOMWillOpenModalDialog", this._browser);
+      ok = this._promptService.promptAuth(this._chromeWindow,
                                           aChannel, aLevel, aAuthInfo,
                                           checkboxLabel, checkbox);
     }
 
     // If there's a notification box, use it to allow the user to
     // determine if the login should be saved. If there isn't a
     // notification box, only save the login if the user set the
     // checkbox to do so.
@@ -676,22 +676,22 @@ LoginManagerPrompter.prototype = {
 
 
 
   /* ---------- nsILoginManagerPrompter prompts ---------- */
 
 
   init : function (aWindow, aFactory) {
     if (aWindow instanceof Ci.nsIDOMChromeWindow) {
-      this._window = aWindow;
+      this._chromeWindow = aWindow;
       // needs to be set explicitly using setBrowser
       this._browser = null;
     } else {
       let {win, browser} = this._getChromeWindow(aWindow);
-      this._window = win;
+      this._chromeWindow = win;
       this._browser = browser;
     }
     this._opener = null;
     this._factory = aFactory || null;
 
     this.log("===== initialized =====");
   },
 
@@ -1123,17 +1123,17 @@ LoginManagerPrompter.prototype = {
     var neverButtonText    = this._getLocalizedString(
                                     "neverForSiteButtonText");
     var rememberButtonText = this._getLocalizedString(
                                     "rememberButtonText");
     var notNowButtonText   = this._getLocalizedString(
                                     "notNowButtonText");
 
     this.log("Prompting user to save/ignore login");
-    var userChoice = this._promptService.confirmEx(this._window,
+    var userChoice = this._promptService.confirmEx(this._chromeWindow,
                                         dialogTitle, dialogText,
                                         buttonFlags, rememberButtonText,
                                         notNowButtonText, neverButtonText,
                                         null, {});
     //  Returns:
     //   0 - Save the login
     //   1 - Ignore the login this time
     //   2 - Never save logins for this site
@@ -1255,17 +1255,17 @@ LoginManagerPrompter.prototype = {
     else
       dialogText  = this._getLocalizedString(
                               "updatePasswordMsgNoUser");
 
     var dialogTitle = this._getLocalizedString(
                                 "passwordChangeTitle");
 
     // returns 0 for yes, 1 for no.
-    var ok = !this._promptService.confirmEx(this._window,
+    var ok = !this._promptService.confirmEx(this._chromeWindow,
                             dialogTitle, dialogText, buttonFlags,
                             null, null, null,
                             null, {});
     if (ok) {
       this.log("Updating password for user " + aOldLogin.username);
       this._updateLogin(aOldLogin, aNewLogin);
     }
   },
@@ -1288,17 +1288,17 @@ LoginManagerPrompter.prototype = {
 
     var usernames = logins.map(l => l.username);
     var dialogText  = this._getLocalizedString("userSelectText");
     var dialogTitle = this._getLocalizedString("passwordChangeTitle");
     var selectedIndex = { value: null };
 
     // If user selects ok, outparam.value is set to the index
     // of the selected username.
-    var ok = this._promptService.select(this._window,
+    var ok = this._promptService.select(this._chromeWindow,
                             dialogTitle, dialogText,
                             usernames.length, usernames,
                             selectedIndex);
     if (ok) {
       // Now that we know which login to use, modify its password.
       var selectedLogin = logins[selectedIndex.value];
       this.log("Updating password for user " + selectedLogin.username);
       var newLoginWithUsername = Cc["@mozilla.org/login-manager/loginInfo;1"].
@@ -1349,47 +1349,35 @@ LoginManagerPrompter.prototype = {
       if (browser) {
         return { win, browser };
       }
     }
     return null;
   },
 
   _getNotifyWindow: function () {
-    try {
-      // Get topmost window, in case we're in a frame.
-      let win = this._window;
-      let browser = this._browser;
-
-      // Some sites pop up a temporary login window, which disappears
-      // upon submission of credentials. We want to put the notification
-      // bar in the opener window if this seems to be happening.
-      if (this._opener) {
-        let chromeDoc = win.document.documentElement;
+    // Some sites pop up a temporary login window, which disappears
+    // upon submission of credentials. We want to put the notification
+    // bar in the opener window if this seems to be happening.
+    if (this._opener) {
+      let chromeDoc = this._chromeWindow.document.documentElement;
 
-        // Check to see if the current window was opened with chrome
-        // disabled, and if so use the opener window. But if the window
-        // has been used to visit other pages (ie, has a history),
-        // assume it'll stick around and *don't* use the opener.
-        if (chromeDoc.getAttribute("chromehidden") && !browser.canGoBack) {
-          this.log("Using opener window for notification bar.");
-          return this._getChromeWindow(this._opener);
-        }
+      // Check to see if the current window was opened with chrome
+      // disabled, and if so use the opener window. But if the window
+      // has been used to visit other pages (ie, has a history),
+      // assume it'll stick around and *don't* use the opener.
+      if (chromeDoc.getAttribute("chromehidden") && !this._browser.canGoBack) {
+        this.log("Using opener window for notification bar.");
+        return this._getChromeWindow(this._opener);
       }
+    }
 
-      return { win, browser };
-
-    } catch (e) {
-      // If any errors happen, just assume no notification box.
-      this.log("Unable to get notify window: " + e.fileName + ":" + e.lineNumber + ": " + e.message);
-      return null;
-    }
+    return { win: this._chromeWindow, browser: this._browser };
   },
 
-
   /**
    * Returns the popup notification to this prompter,
    * or null if there isn't one available.
    */
   _getPopupNote : function () {
     let popupNote = null;
 
     try {