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 10:45:48 -0700
changeset 791185 dbda0d5e557200fbba8210337f8a424a658836d5
parent 791136 35165f43d0b97f500dafb4f0f7b9ca8d91416812
push id108725
push userbgrinstead@mozilla.com
push dateThu, 03 May 2018 17:45:58 +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,40 @@ 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", this.quickRestart.bind(this));
     } 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();
         }
       });
     }
   },
+
+  /* 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).
+   */
+  quickRestart: function() {
+    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);
+  },
+
   /**
    * Handler for page location changes.
    *
    * @param string uri
    *        New page location.
    * @param string title
    *        New page title.
    */