Bug 1388552 - Work in progress - run with: `./mach run --setpref browser.dom.window.dump.enabled=true` draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Tue, 08 Aug 2017 15:45:24 -0700
changeset 642887 4c2edc67a175eaccda84c2f99525e79cb9e15bfe
parent 642886 d677241d3a24ea4dc45f79aff6daa03e28f2e001
child 725133 8808b33ad26cc6650e0515aa9f3a77af19478378
push id72903
push userbgrinstead@mozilla.com
push dateTue, 08 Aug 2017 22:46:02 +0000
bugs1388552
milestone57.0a1
Bug 1388552 - Work in progress - run with: `./mach run --setpref browser.dom.window.dump.enabled=true` There is a race here where the Browser Console window closes before the last call to SessionStore.getCurrentState MozReview-Commit-ID: D4vOGkpq8xH
browser/components/sessionstore/SessionStore.jsm
devtools/client/framework/devtools.js
devtools/client/webconsole/hudservice.js
devtools/shim/DevToolsShim.jsm
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -2760,18 +2760,21 @@ var SessionStoreInternal = {
 
     // Merge closed windows from this session with ones from last session
     if (lastSessionState._closedWindows) {
       this._closedWindows = this._closedWindows.concat(lastSessionState._closedWindows);
       this._capClosedWindows();
       this._closedObjectsChanged = true;
     }
 
-    if (lastSessionState.scratchpads) {
-      DevToolsShim.restoreScratchpadSession(lastSessionState.scratchpads);
+    if (lastSessionState.scratchpads || lastSessionState.browserConsole) {
+      DevToolsShim.restoreDevToolsSession({
+        scratchpads: lastSessionState.scratchpads,
+        browserConsole: lastSessionState.browserConsole,
+      });
     }
 
     // Set data that persists between sessions
     this._recentCrashes = lastSessionState.session &&
                           lastSessionState.session.recentCrashes || 0;
 
     // Update the session start time using the restored session state.
     this._updateSessionStartTime(lastSessionState);
@@ -3129,17 +3132,18 @@ var SessionStoreInternal = {
       _closedWindows: lastClosedWindowsCopy,
       session,
       global: this._globalState.getState()
     };
 
     // Collect and store session cookies.
     state.cookies = SessionCookies.collect();
 
-    let scratchpads = DevToolsShim.getOpenedScratchpads();
+    let {scratchpads, browserConsole} = DevToolsShim.getDevToolsSession();
+    state.browserConsole = browserConsole;
     if (scratchpads && scratchpads.length) {
       state.scratchpads = scratchpads;
     }
 
     // Persist the last session if we deferred restoring it
     if (LastSession.canRestore) {
       state.lastSessionState = LastSession.getState();
     }
@@ -3525,18 +3529,21 @@ var SessionStoreInternal = {
         if (w == root.selectedWindow - 1) {
           this.windowToFocus = window;
         }
       }
     }
 
     this.restoreWindow(aWindow, root.windows[0], aOptions);
 
-    if (aState.scratchpads) {
-      DevToolsShim.restoreScratchpadSession(aState.scratchpads);
+    if (aState.scratchpads || aState.browserConsole) {
+      DevToolsShim.restoreDevToolsSession({
+        scratchpads: aState.scratchpads,
+        browserConsole: aState.browserConsole,
+      });
     }
   },
 
   /**
    * Manage history restoration for a window
    * @param aWindow
    *        Window to restore the tabs into
    * @param aTabs
--- a/devtools/client/framework/devtools.js
+++ b/devtools/client/framework/devtools.js
@@ -9,16 +9,17 @@ const Services = require("Services");
 
 const {DevToolsShim} = Cu.import("chrome://devtools-shim/content/DevToolsShim.jsm", {});
 
 // Load gDevToolsBrowser toolbox lazily as they need gDevTools to be fully initialized
 loader.lazyRequireGetter(this, "TargetFactory", "devtools/client/framework/target", true);
 loader.lazyRequireGetter(this, "Toolbox", "devtools/client/framework/toolbox", true);
 loader.lazyRequireGetter(this, "ToolboxHostManager", "devtools/client/framework/toolbox-host-manager", true);
 loader.lazyRequireGetter(this, "gDevToolsBrowser", "devtools/client/framework/devtools-browser", true);
+loader.lazyRequireGetter(this, "HUDService", "devtools/client/webconsole/hudservice");
 loader.lazyImporter(this, "ScratchpadManager", "resource://devtools/client/scratchpad/scratchpad-manager.jsm");
 
 // Dependencies required for addon sdk compatibility layer.
 loader.lazyRequireGetter(this, "DebuggerServer", "devtools/server/main", true);
 loader.lazyRequireGetter(this, "DebuggerClient", "devtools/shared/client/main", true);
 loader.lazyImporter(this, "BrowserToolboxProcess", "resource://devtools/client/framework/ToolboxProcess.jsm");
 
 const {defaultTools: DefaultTools, defaultThemes: DefaultThemes} =
@@ -397,29 +398,41 @@ DevTools.prototype = {
   },
 
   /**
    * Get the array of currently opened scratchpad windows.
    *
    * @return {Array} array of currently opened scratchpad windows.
    *         Empty array if the scratchpad manager is not loaded.
    */
-  getOpenedScratchpads: function () {
+  getDevToolsSession: function () {
+    let browserConsole = !!HUDService.getBrowserConsole();
+    console.log("getDevToolsSession (after BC close)", browserConsole);
+    console.trace();
+
     // Check if the module is loaded to avoid loading ScratchpadManager for no reason.
-    if (!Cu.isModuleLoaded("resource://devtools/client/scratchpad/scratchpad-manager.jsm")) {
-      return [];
+    let scratchpads = [];
+    if (Cu.isModuleLoaded("resource://devtools/client/scratchpad/scratchpad-manager.jsm")) {
+      scratchpads = ScratchpadManager.getSessionState();
     }
-    return ScratchpadManager.getSessionState();
+
+    return { scratchpads, browserConsole };
   },
 
   /**
    * Restore the provided array of scratchpad window states.
    */
-  restoreScratchpadSession: function (scratchpads) {
-    ScratchpadManager.restoreSession(scratchpads);
+  restoreDevToolsSession: function ({scratchpads, browserConsole}) {
+    if (scratchpads) {
+      ScratchpadManager.restoreSession(scratchpads);
+    }
+
+    if (browserConsole && !HUDService.getBrowserConsole()) {
+      HUDService.toggleBrowserConsole();
+    }
   },
 
   /**
    * Show a Toolbox for a target (either by creating a new one, or if a toolbox
    * already exists for the target, by bring to the front the existing one)
    * If |toolId| is specified then the displayed toolbox will have the
    * specified tool selected.
    * If |hostType| is specified then the toolbox will be displayed using the
--- a/devtools/client/webconsole/hudservice.js
+++ b/devtools/client/webconsole/hudservice.js
@@ -547,16 +547,17 @@ WebConsole.prototype = {
    * Destroy the object. Call this method to avoid memory leaks when the Web
    * Console is closed.
    *
    * @return object
    *         A promise object that is resolved once the Web Console is closed.
    */
   destroy: function WC_destroy()
   {
+    console.trace();
     if (this._destroyer) {
       return this._destroyer.promise;
     }
 
     HUDService.consoles.delete(this.hudId);
 
     this._destroyer = promise.defer();
 
--- a/devtools/shim/DevToolsShim.jsm
+++ b/devtools/shim/DevToolsShim.jsm
@@ -184,37 +184,41 @@ this.DevToolsShim = {
     } else {
       removeItem(this.themes, t => t === theme);
     }
   },
 
   /**
    * Called from SessionStore.jsm in mozilla-central when saving the current state.
    *
-   * @return {Array} array of currently opened scratchpad windows. Empty array if devtools
-   *         are not installed
+   * @return {Object}
+   *          - scratchpads: array of currently opened scratchpad windows. Empty array if devtools
+   *                         are not installed.
+   *          - browserConsole: bool if Browser Console was opened
    */
-  getOpenedScratchpads: function () {
+  getDevToolsSession: function () {
     if (!this.isInitialized()) {
-      return [];
+      return {
+        scratchpads: [],
+        browserConsole: false,
+      }
     }
-
-    return this._gDevTools.getOpenedScratchpads();
+    return this._gDevTools.getDevToolsSession();
   },
 
   /**
    * Called from SessionStore.jsm in mozilla-central when restoring a state that contained
-   * opened scratchpad windows.
+   * opened scratchpad windows and browser console.
    */
-  restoreScratchpadSession: function (scratchpads) {
+  restoreDevToolsSession: function (session) {
     if (!this.isInstalled()) {
       return;
     }
 
-    this.gDevTools.restoreScratchpadSession(scratchpads);
+    this.gDevTools.restoreDevToolsSession(session);
   },
 
   /**
    * Called from nsContextMenu.js in mozilla-central when using the Inspect Element
    * context menu item.
    *
    * @param {XULTab} tab
    *        The browser tab on which inspect node was used.