Bug 1268073 - Misleading error if you click "Debug" twice; r?janx draft
authorJoseph Yeh <jyeh@mozilla.com>
Mon, 23 May 2016 16:40:38 +0800
changeset 375984 531c35b81eea74f5a1a06d9e020ce4f8e193f70a
parent 375957 1828937da9493b2cd54862b9c520b2ba5c7db92b
child 523034 04557a30581db2652a737ded23f6f01fae278d56
push id20454
push userbmo:jyeh@mozilla.com
push dateTue, 07 Jun 2016 03:24:43 +0000
reviewersjanx
bugs1268073
milestone50.0a1
Bug 1268073 - Misleading error if you click "Debug" twice; r?janx MozReview-Commit-ID: DVW2ahqAO2Q
devtools/client/aboutdebugging/components/addons/target.js
devtools/client/aboutdebugging/modules/addon.js
devtools/client/aboutdebugging/modules/moz.build
--- a/devtools/client/aboutdebugging/components/addons/target.js
+++ b/devtools/client/aboutdebugging/components/addons/target.js
@@ -1,33 +1,30 @@
 /* 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/. */
 
 /* eslint-env browser */
-/* globals BrowserToolboxProcess */
 
 "use strict";
 
-loader.lazyImporter(this, "BrowserToolboxProcess",
-  "resource://devtools/client/framework/ToolboxProcess.jsm");
-
 const { createClass, DOM: dom } =
   require("devtools/client/shared/vendor/react");
+const { debugAddon } = require("../../modules/addon");
 const Services = require("Services");
 
 const Strings = Services.strings.createBundle(
   "chrome://devtools/locale/aboutdebugging.properties");
 
 module.exports = createClass({
   displayName: "AddonTarget",
 
   debug() {
     let { target } = this.props;
-    BrowserToolboxProcess.init({ addonID: target.addonID });
+    debugAddon(target.addonID);
   },
 
   reload() {
     let { client, target } = this.props;
     // This function sometimes returns a partial promise that only
     // implements then().
     client.request({
       to: target.addonActor,
new file mode 100644
--- /dev/null
+++ b/devtools/client/aboutdebugging/modules/addon.js
@@ -0,0 +1,23 @@
+/* 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/. */
+
+"use strict";
+
+loader.lazyImporter(this, "BrowserToolboxProcess",
+  "resource://devtools/client/framework/ToolboxProcess.jsm");
+
+let toolbox = null;
+
+exports.debugAddon = function (addonID) {
+  if (toolbox) {
+    toolbox.close();
+  }
+
+  toolbox = BrowserToolboxProcess.init({
+    addonID,
+    onClose: () => {
+      toolbox = null;
+    }
+  });
+};
--- a/devtools/client/aboutdebugging/modules/moz.build
+++ b/devtools/client/aboutdebugging/modules/moz.build
@@ -1,7 +1,8 @@
 # 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/.
 
 DevToolsModules(
+    'addon.js',
     'worker.js',
 )