fix bug 1297535 draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 20 Sep 2016 13:58:13 -0700
changeset 417584 e237d78245f0be3658cc7ac885d5b4bfea5ac604
parent 417583 e7bcdce8a595fb2e78a584d80433ac6d0c63f317
child 532123 ab89367d0b61cbc0001e120de1d63f67f58c0b3f
push id30437
push userbmo:poirot.alex@gmail.com
push dateMon, 26 Sep 2016 13:15:03 +0000
bugs1297535
milestone52.0a1
fix bug 1297535 MozReview-Commit-ID: 6bazA1Bl5Ph
devtools/client/framework/devtools-browser.js
--- a/devtools/client/framework/devtools-browser.js
+++ b/devtools/client/framework/devtools-browser.js
@@ -411,20 +411,23 @@ var gDevToolsBrowser = exports.gDevTools
    * is called after delayed-startup notification. This method should only do
    * what has to be done early. Otherwise devtools should be initialized lazily
    * to prevent overloading Firefox startup.
    *
    * @param {ChromeWindow} window
    *        The window to which devtools should be hooked to.
    */
   _onBrowserWindowLoaded: function (win) {
-    if (!win.gBrowser) {
+    // This method is called for all top level window, only consider firefox
+    // windows
+    if (!win.location.href.endsWith("browser.xul")) {
       return;
     }
     BrowserMenus.addMenus(win.document);
+    win.addEventListener("unload", this);
   },
 
   /**
    * Add this DevTools's presence to a browser window's document
    *
    * @param {ChromeWindow} win
    *        The window to which devtools should be hooked to.
    */
@@ -441,17 +444,16 @@ var gDevToolsBrowser = exports.gDevTools
     // Inject lazily DeveloperToolbar on the chrome window
     loader.lazyGetter(win, "DeveloperToolbar", function () {
       let { DeveloperToolbar } = require("devtools/client/shared/developer-toolbar");
       return new DeveloperToolbar(win);
     });
 
     this.updateCommandAvailability(win);
     this.ensurePrefObserver();
-    win.addEventListener("unload", this);
 
     let tabContainer = win.gBrowser.tabContainer;
     tabContainer.addEventListener("TabSelect", this, false);
     tabContainer.addEventListener("TabOpen", this, false);
     tabContainer.addEventListener("TabClose", this, false);
     tabContainer.addEventListener("TabPinned", this, false);
     tabContainer.addEventListener("TabUnpinned", this, false);
   },
@@ -638,23 +640,26 @@ var gDevToolsBrowser = exports.gDevTools
   /**
    * Called on browser unload to remove menu entries, toolboxes and event
    * listeners from the closed browser window.
    *
    * @param  {XULWindow} win
    *         The window containing the menu entry
    */
   _forgetBrowserWindow: function (win) {
+    // _forgetBrowserWindow can only be called once for each window, but
+    // _registerBrowserWindow may not have been called. Instead, only
+    // _onBrowserWindowLoaded was and we only need to revert that.
+    win.removeEventListener("unload", this);
+    BrowserMenus.removeMenus(win.document);
+
     if (!gDevToolsBrowser._trackedBrowserWindows.has(win)) {
       return;
     }
     gDevToolsBrowser._trackedBrowserWindows.delete(win);
-    win.removeEventListener("unload", this);
-
-    BrowserMenus.removeMenus(win.document);
 
     // Destroy toolboxes for closed window
     for (let [target, toolbox] of gDevTools._toolboxes) {
       if (toolbox.win.top == win) {
         toolbox.destroy();
       }
     }