Bug 1385452 - Add a keyboard shortcut in local builds to restart the browser;r=mossop
authorBrian Grinstead <bgrinstead@mozilla.com>
Tue, 08 Aug 2017 11:35:47 -0700
changeset 425454 02bb58ce4347cb30287287fe7d0f3403f14f805a
parent 425453 dc0824a1c1755adeefd71b1375c893fc83c11f8c
child 425455 105f021802141dce47eecbe0e7f21b77b32eba88
push id1567
push userjlorenzo@mozilla.com
push dateThu, 02 Nov 2017 12:36:05 +0000
treeherdermozilla-release@e512c14a0406 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1385452
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1385452 - Add a keyboard shortcut in local builds to restart the browser;r=mossop MozReview-Commit-ID: Du4PTPawzhm
browser/base/content/browser-development-helpers.js
browser/base/content/browser.js
browser/base/content/global-scripts.inc
browser/base/jar.mn
new file mode 100644
--- /dev/null
+++ b/browser/base/content/browser-development-helpers.js
@@ -0,0 +1,48 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Extra features for local development. This file isn't loaded in
+ * non-local builds.
+ */
+
+var DevelopmentHelpers = {
+  init() {
+    this.quickRestart = this.quickRestart.bind(this);
+    this.addRestartShortcut();
+  },
+
+  quickRestart() {
+    Services.obs.notifyObservers(null, "startupcache-invalidate");
+
+    let env = Cc["@mozilla.org/process/environment;1"].
+              getService(Components.interfaces.nsIEnvironment);
+    env.set("MOZ_DISABLE_SAFE_MODE_KEY", "1");
+
+    Services.startup.quit(Ci.nsIAppStartup.eAttemptQuit | Ci.nsIAppStartup.eRestart);
+  },
+
+  addRestartShortcut() {
+    let command = document.createElement("command");
+    command.setAttribute("id", "cmd_quickRestart");
+    command.addEventListener("command", this.quickRestart, true);
+    command.setAttribute("oncommand", "void 0;"); // Needed - bug 371900
+    document.getElementById("mainCommandSet").prepend(command);
+
+    let key = document.createElement("key");
+    key.setAttribute("id", "key_quickRestart");
+    key.setAttribute("key", "r");
+    key.setAttribute("modifiers", "accel,alt");
+    key.setAttribute("command", "cmd_quickRestart");
+    key.setAttribute("oncommand", "void 0;"); // Needed - bug 371900
+    document.getElementById("mainKeyset").prepend(key);
+
+    let menuitem = document.createElement("menuitem");
+    menuitem.setAttribute("id", "menu_FileRestartItem");
+    menuitem.setAttribute("key", "key_quickRestart");
+    menuitem.setAttribute("label", "Restart (Developer)");
+    menuitem.addEventListener("command", this.quickRestart, true);
+    document.getElementById("menu_FilePopup").appendChild(menuitem);
+  },
+};
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1683,16 +1683,19 @@ var gBrowserInit = {
     // initialize the sync UI
     requestIdleCallback(() => {
       gSync.init();
     }, {timeout: 1000 * 5});
 
     if (AppConstants.MOZ_DATA_REPORTING)
       gDataNotificationInfoBar.init();
 
+    if (!AppConstants.MOZILLA_OFFICIAL)
+      DevelopmentHelpers.init();
+
     requestIdleCallback(() => {
       // setup simple gestures support
       gGestureSupport.init(true);
 
       // setup history swipe animation
       gHistorySwipeAnimation.init();
     });
 
--- a/browser/base/content/global-scripts.inc
+++ b/browser/base/content/global-scripts.inc
@@ -18,8 +18,12 @@
 <script type="application/javascript" src="chrome://browser/content/browser-plugins.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-sidebar.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-tabsintitlebar.js"/>
 <script type="application/javascript" src="chrome://browser/content/browser-trackingprotection.js"/>
 
 #ifdef MOZ_DATA_REPORTING
 <script type="application/javascript" src="chrome://browser/content/browser-data-submission-info-bar.js"/>
 #endif
+
+#ifndef MOZILLA_OFFICIAL
+<script type="application/javascript" src="chrome://browser/content/browser-development-helpers.js"/>
+#endif
--- a/browser/base/jar.mn
+++ b/browser/base/jar.mn
@@ -64,16 +64,19 @@ browser.jar:
         content/browser/browser.js                    (content/browser.js)
 *       content/browser/browser.xul                   (content/browser.xul)
         content/browser/browser-addons.js             (content/browser-addons.js)
         content/browser/browser-captivePortal.js      (content/browser-captivePortal.js)
         content/browser/browser-ctrlTab.js            (content/browser-ctrlTab.js)
         content/browser/browser-customization.js      (content/browser-customization.js)
         content/browser/browser-data-submission-info-bar.js (content/browser-data-submission-info-bar.js)
         content/browser/browser-compacttheme.js       (content/browser-compacttheme.js)
+#ifndef MOZILLA_OFFICIAL
+        content/browser/browser-development-helpers.js (content/browser-development-helpers.js)
+#endif
         content/browser/browser-feeds.js              (content/browser-feeds.js)
         content/browser/browser-fullScreenAndPointerLock.js  (content/browser-fullScreenAndPointerLock.js)
         content/browser/browser-fullZoom.js           (content/browser-fullZoom.js)
         content/browser/browser-gestureSupport.js     (content/browser-gestureSupport.js)
         content/browser/browser-media.js              (content/browser-media.js)
         content/browser/browser-pageActions.js        (content/browser-pageActions.js)
         content/browser/browser-places.js             (content/browser-places.js)
         content/browser/browser-plugins.js            (content/browser-plugins.js)