Bug 1104798 - Hide Disable JS checkbox when target.activeTab is undefined;r=mratcliffe
authorBrian Grinstead <bgrinstead@mozilla.com>
Tue, 25 Nov 2014 08:47:00 +0100
changeset 218285 932ee43b5e875a5a04ce940357b9c8e170cc6a47
parent 218284 68c805b2b5e366ea5a596ee7dfb3809f991e9fa1
child 218286 e16e9086a2457cbb6a2f7657589a1672188b4b3b
push id27926
push usercbook@mozilla.com
push dateWed, 03 Dec 2014 12:39:10 +0000
treeherdermozilla-central@a9fc46355661 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmratcliffe
bugs1104798
milestone37.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 1104798 - Hide Disable JS checkbox when target.activeTab is undefined;r=mratcliffe
browser/devtools/framework/toolbox-options.js
--- a/browser/devtools/framework/toolbox-options.js
+++ b/browser/devtools/framework/toolbox-options.js
@@ -76,16 +76,19 @@ function OptionsPanel(iframeWindow, tool
   this.panelWin = iframeWindow;
 
   this.toolbox = toolbox;
   this.isReady = false;
 
   this._prefChanged = this._prefChanged.bind(this);
   this._themeRegistered = this._themeRegistered.bind(this);
   this._themeUnregistered = this._themeUnregistered.bind(this);
+  this._disableJSClicked = this._disableJSClicked.bind(this);
+
+  this.disableJSNode = this.panelDoc.getElementById("devtools-disable-javascript");
 
   this._addListeners();
 
   Services.obs.addObserver(this, kDeveditionChangedNotification, false);
   const EventEmitter = require("devtools/toolkit/event-emitter");
   EventEmitter.decorate(this);
 }
 
@@ -107,21 +110,16 @@ OptionsPanel.prototype = {
 
     return targetPromise.then(() => {
       this.setupToolsList();
       this.setupToolbarButtonsList();
       this.setupThemeList();
       this.setupBrowserThemeButton();
       this.populatePreferences();
       this.updateDefaultTheme();
-
-      this._disableJSClicked = this._disableJSClicked.bind(this);
-
-      let disableJSNode = this.panelDoc.getElementById("devtools-disable-javascript");
-      disableJSNode.addEventListener("click", this._disableJSClicked, false);
     }).then(() => {
       this.isReady = true;
       this.emit("ready");
       return this;
     }).then(null, function onError(aReason) {
       Cu.reportError("OptionsPanel open failed. " +
                      aReason.error + ": " + aReason.message);
     });
@@ -364,21 +362,25 @@ OptionsPanel.prototype = {
           break;
         }
       }
       menulist.addEventListener("command", function() {
         setPrefAndEmit(this.getAttribute("data-pref"), this.value);
       }.bind(menulist));
     }
 
-    this.target.client.attachTab(this.target.activeTab._actor, (response) => {
-      this._origJavascriptEnabled = response.javascriptEnabled;
-
-      this._populateDisableJSCheckbox();
-    });
+    if (this.target.activeTab) {
+      this.target.client.attachTab(this.target.activeTab._actor, (response) => {
+        this._origJavascriptEnabled = response.javascriptEnabled;
+        this.disableJSNode.checked = !this._origJavascriptEnabled
+        this.disableJSNode.addEventListener("click", this._disableJSClicked, false);
+      });
+    } else {
+      this.disableJSNode.hidden = true;
+    }
   },
 
   updateDefaultTheme: function() {
     // Make sure a theme is set in case the previous one coming from
     // an extension isn't available anymore.
     let themeBox = this.panelDoc.getElementById("devtools-theme-box");
     if (themeBox.selectedIndex == -1) {
       themeBox.selectedItem = themeBox.querySelector("[value=light]");
@@ -390,21 +392,16 @@ OptionsPanel.prototype = {
     let themeBox = this.panelDoc.getElementById("devtools-theme-box");
     let themeOption = themeBox.querySelector("[value=" + currentTheme + "]");
 
     if (themeOption) {
       themeBox.selectedItem = themeOption;
     }
   },
 
-  _populateDisableJSCheckbox: function() {
-    let cbx = this.panelDoc.getElementById("devtools-disable-javascript");
-    cbx.checked = !this._origJavascriptEnabled;
-  },
-
   /**
    * Disables JavaScript for the currently loaded tab. We force a page refresh
    * here because setting docShell.allowJavascript to true fails to block JS
    * execution from event listeners added using addEventListener(), AJAX calls
    * and timers. The page refresh prevents these things from being added in the
    * first place.
    *
    * @param {Event} event
@@ -442,33 +439,31 @@ OptionsPanel.prototype = {
   destroy: function() {
     if (this.destroyPromise) {
       return this.destroyPromise;
     }
 
     let deferred = promise.defer();
 
     this.destroyPromise = deferred.promise;
-
-    let disableJSNode = this.panelDoc.getElementById("devtools-disable-javascript");
-    disableJSNode.removeEventListener("click", this._disableJSClicked, false);
-
     this._removeListeners();
 
-    this.panelWin = this.panelDoc = null;
-    this._disableJSClicked = null;
+    if (this.target.activeTab) {
+      this.disableJSNode.removeEventListener("click", this._disableJSClicked, false);
+      // If JavaScript is disabled we need to revert it to it's original value.
+      let options = {
+        "javascriptEnabled": this._origJavascriptEnabled
+      };
+      this.target.activeTab.reconfigure(options, () => {
+        this.toolbox = null;
+        deferred.resolve();
+      }, true);
+    }
 
-    // If JavaScript is disabled we need to revert it to it's original value.
-    let options = {
-      "javascriptEnabled": this._origJavascriptEnabled
-    };
-    this.target.activeTab.reconfigure(options, () => {
-      this.toolbox = null;
-      deferred.resolve();
-    }, true);
+    this.panelWin = this.panelDoc = this.disableJSNode = null;
 
     Services.obs.removeObserver(this, kDeveditionChangedNotification);
 
     return deferred.promise;
   }
 };
 
 /* Set a pref and emit the pref-changed event if needed. */