Bug 1458840 - Allow restarting the browser with the keyboard shortcut in the Browser Console in all builds;r=jryans draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Thu, 03 May 2018 11:23:33 -0700
changeset 791197 360441312bcbbc086aa300e67ad97def4895d687
parent 791136 35165f43d0b97f500dafb4f0f7b9ca8d91416812
push id108728
push userbgrinstead@mozilla.com
push dateThu, 03 May 2018 18:24:16 +0000
reviewersjryans
bugs1458840
milestone61.0a1
Bug 1458840 - Allow restarting the browser with the keyboard shortcut in the Browser Console in all builds;r=jryans MozReview-Commit-ID: D7Hswr7IfvW
devtools/client/webconsole/new-webconsole.js
--- a/devtools/client/webconsole/new-webconsole.js
+++ b/devtools/client/webconsole/new-webconsole.js
@@ -235,35 +235,27 @@ NewWebConsoleFrame.prototype = {
 
     shortcuts.on(clearShortcut, () => this.jsterm.clearOutput(true));
 
     if (this.isBrowserConsole) {
       shortcuts.on(l10n.getStr("webconsole.close.key"),
                    this.window.top.close.bind(this.window.top));
 
       ZoomKeys.register(this.window);
-
-      if (!AppConstants.MOZILLA_OFFICIAL) {
-        // In local builds, inject the "quick restart" shortcut.
-        // This script expects to have Services on the global and we haven't yet imported
-        // it into the window, so assign it.
-        this.window.Services = Services;
-        Services.scriptloader.loadSubScript(
-          "chrome://browser/content/browser-development-helpers.js", this.window);
-        shortcuts.on("CmdOrCtrl+Alt+R", this.window.DevelopmentHelpers.quickRestart);
-      }
+      shortcuts.on("CmdOrCtrl+Alt+R", quickRestart);
     } else if (Services.prefs.getBoolPref(PREF_SIDEBAR_ENABLED)) {
       shortcuts.on("Esc", event => {
         if (!this.jsterm.autocompletePopup || !this.jsterm.autocompletePopup.isOpen) {
           this.newConsoleOutput.dispatchSidebarClose();
           this.jsterm.focus();
         }
       });
     }
   },
+
   /**
    * Handler for page location changes.
    *
    * @param string uri
    *        New page location.
    * @param string title
    *        New page title.
    */
@@ -337,9 +329,22 @@ NewWebConsoleFrame.prototype = {
     }
 
     if (packet.url) {
       this.onLocationChange(packet.url, packet.title);
     }
   }
 };
 
+/* This is the same as DevelopmentHelpers.quickRestart, but it runs in all
+ * builds (even official). This allows a user to do a restart + session restore
+ * with Ctrl+Shift+J (open Browser Console) and then Ctrl+Shift+R (restart).
+ */
+function quickRestart() {
+  const { Cc, Ci } = require("chrome");
+  Services.obs.notifyObservers(null, "startupcache-invalidate");
+  let env = Cc["@mozilla.org/process/environment;1"]
+            .getService(Ci.nsIEnvironment);
+  env.set("MOZ_DISABLE_SAFE_MODE_KEY", "1");
+  Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart);
+}
+
 exports.NewWebConsoleFrame = NewWebConsoleFrame;