Bug 1350152 - Don't rely on gBrowser in nsLoginManagerPrompter.js. r=mkaply a=IanN CLOSED TREE DONTBUILD SEAMONKEY_2_49_ESR_RELBRANCH
authorJohann Hofmann <jhofmann@mozilla.com>
Thu, 01 Jun 2017 21:41:11 +0200
branchSEAMONKEY_2_49_ESR_RELBRANCH
changeset 357499 7494af4354bc9e3fba6b3af962c420ca9da9772c
parent 357498 a5de6bf784e7235d66167bab9b764a349afd4080
child 357500 73a764862ae6919e7e0d5668d12cecf782ba39f4
push id7834
push userfrgrahl@gmx.net
push dateSun, 13 Jan 2019 12:17:02 +0000
treeherdermozilla-esr52@6e4ad8a8f2e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkaply, IanN
bugs1350152, 1266836
milestone52.9.1
Bug 1350152 - Don't rely on gBrowser in nsLoginManagerPrompter.js. r=mkaply a=IanN CLOSED TREE DONTBUILD mozilla-esr52 SEAMONKEY_2_49_ESR_RELBRANCH In bug 1266836 we fixed this code to properly work in e10s, but made the mistake of using gBrowser in toolkit code, breaking XUL apps that don't have a gBrowser. This solution implements a different code-path for non-e10s and returns a chrome window for consumers that don't offer a browser.
toolkit/components/passwordmgr/nsLoginManagerPrompter.js
--- a/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
+++ b/toolkit/components/passwordmgr/nsLoginManagerPrompter.js
@@ -803,16 +803,19 @@ LoginManagerPrompter.prototype = {
    *        Login to save or change. For changes, this login should contain the
    *        new password.
    * @param {string} type
    *        This is "password-save" or "password-change" depending on the
    *        original notification type. This is used for telemetry and tests.
    */
   _showLoginCaptureDoorhanger(login, type) {
     let { browser } = this._getNotifyWindow();
+    if (!browser) {
+      return;
+    }
 
     let saveMsgNames = {
       prompt: login.username === "" ? "rememberLoginMsgNoUser"
                                     : "rememberLoginMsg",
       buttonLabel: "rememberLoginButtonText",
       buttonAccessKey: "rememberLoginButtonAccessKey",
     };
 
@@ -1400,20 +1403,43 @@ LoginManagerPrompter.prototype = {
     propBag.setProperty("timesUsedIncrement", 1);
     this._pwmgr.modifyLogin(login, propBag);
   },
 
   /**
    * Given a content DOM window, returns the chrome window and browser it's in.
    */
   _getChromeWindow: function (aWindow) {
+    // Handle non-e10s toolkit consumers.
+    if (!Cu.isCrossProcessWrapper(aWindow)) {
+      let chromeWin = aWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIWebNavigation)
+                             .QueryInterface(Ci.nsIDocShell)
+                             .chromeEventHandler.ownerGlobal;
+      if (!chromeWin) {
+        return null;
+      }
+
+      // gBrowser only exists on some apps, like Firefox.
+      let tabbrowser = chromeWin.gBrowser || chromeWin.getBrowser();
+      // At least serve the chrome window if getBrowser()
+      // or getBrowserForContentWindow() are not supported.
+      if (!tabbrowser || typeof tabbrowser.getBrowserForContentWindow != "function") {
+        return { win: chromeWin };
+      }
+
+      let browser = tabbrowser.getBrowserForContentWindow(aWindow);
+      return { win: chromeWin, browser };
+    }
+
     let windows = Services.wm.getEnumerator(null);
     while (windows.hasMoreElements()) {
       let win = windows.getNext();
-      let browser = win.gBrowser.getBrowserForContentWindow(aWindow);
+      let tabbrowser = win.gBrowser || win.getBrowser();
+      let browser = tabbrowser.getBrowserForContentWindow(aWindow);
       if (browser) {
         return { win, browser };
       }
     }
     return null;
   },
 
   _getNotifyWindow: function () {