Bug 1257532 - Toggle development prefs when installing the reload addon. r=jryans,bgrins
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 29 Mar 2016 06:28:17 -0700
changeset 290792 bc86e440410d9a6ce93c8f41f37fc4f94ee404da
parent 290791 c1f0341f9055edd241c8de6663aab14209a766b5
child 290793 e56e76ec40cb0e8f11278a5e61414972b771e9fd
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans, bgrins
bugs1257532
milestone48.0a1
Bug 1257532 - Toggle development prefs when installing the reload addon. r=jryans,bgrins
devtools/bootstrap.js
--- a/devtools/bootstrap.js
+++ b/devtools/bootstrap.js
@@ -156,25 +156,57 @@ function reload(event) {
       let target = TargetFactory.forTab(top.gBrowser.selectedTab);
       gDevTools.showToolbox(target);
     }, 1000);
   }
 
   actionOccurred("reloadAddonReload");
 }
 
+let prefs = {
+  // Enable dump as some errors are only printed on the stdout
+  "browser.dom.window.dump.enabled": true,
+  // Enable the browser toolbox and various chrome-only features
+  "devtools.chrome.enabled": true,
+  "devtools.debugger.remote-enabled": true,
+  // Disable the prompt to ease usage of the browser toolbox
+  "devtools.debugger.prompt-connection": false,
+};
+let originalPrefValues = {};
+
 let listener;
 function startup() {
   dump("DevTools addon started.\n");
   listener = new MultiWindowKeyListener({
     keyCode: Ci.nsIDOMKeyEvent.DOM_VK_R, ctrlKey: true, altKey: true,
     callback: reload
   });
   listener.start();
+
+  // Toggle development prefs and save original values
+  originalPrefValues = {};
+  for (let name in prefs) {
+    let value = prefs[name];
+    let userValue = Services.prefs.getBoolPref(name);
+    // Only toggle if the pref isn't already set to the right value
+    if (userValue != value) {
+      Services.prefs.setBoolPref(name, value);
+      originalPrefValues[name] = userValue;
+    }
+  }
 }
 function shutdown() {
   listener.stop();
   listener = null;
+
+  // Restore preferences that used to be before the addon was installed
+  for (let name in originalPrefValues) {
+    let userValue = Services.prefs.getBoolPref(name);
+    // Only reset the pref if it hasn't changed
+    if (userValue == prefs[name]) {
+      Services.prefs.setBoolPref(name, originalPrefValues[name]);
+    }
+  }
 }
 function install() {
   actionOccurred("reloadAddonInstalled");
 }
 function uninstall() {}