Bug 1291737 - Changes to ExtensionParent JSM for the DevTools APIs. r=kmag
authorLuca Greco <lgreco@mozilla.com>
Fri, 02 Dec 2016 16:13:39 -0500
changeset 377490 0d88c3c271d2c771b0c2ea6adc22a1ef10cecd63
parent 377489 dc42f50d06e8de0945f1bc8e8efc03d597ddc715
child 377491 6b78221fc2ab459453ac6609f1cbb950af2e988e
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmag
bugs1291737
milestone53.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 1291737 - Changes to ExtensionParent JSM for the DevTools APIs. r=kmag This patch introduces the new DevToolsExtensionPageContextParent class, a class specialized for the devtools extension contexts needs, and other changes needed to support the DevTools Extension contexts (e.g. the devtools pages and devtools panels). MozReview-Commit-ID: dIeVpNJGN
toolkit/components/extensions/ExtensionParent.jsm
--- a/toolkit/components/extensions/ExtensionParent.jsm
+++ b/toolkit/components/extensions/ExtensionParent.jsm
@@ -227,32 +227,32 @@ GlobalManager = {
     this.extensionMap.delete(extension.id);
 
     if (this.extensionMap.size == 0 && this.initialized) {
       apiManager.off("extension-browser-inserted", this._onExtensionBrowser);
       this.initialized = false;
     }
   },
 
-  _onExtensionBrowser(type, browser) {
+  _onExtensionBrowser(type, browser, additionalData = {}) {
     browser.messageManager.loadFrameScript(`data:,
       Components.utils.import("resource://gre/modules/ExtensionContent.jsm");
       ExtensionContent.init(this);
       addEventListener("unload", function() {
         ExtensionContent.uninit(this);
       });
     `, false);
 
     let viewType = browser.getAttribute("webextension-view-type");
     if (viewType) {
       let data = {viewType};
 
       let {getBrowserInfo} = apiManager.global;
       if (getBrowserInfo) {
-        Object.assign(data, getBrowserInfo(browser));
+        Object.assign(data, getBrowserInfo(browser), additionalData);
       }
 
       browser.messageManager.sendAsyncMessage("Extension:InitExtensionView",
                                               data);
     }
   },
 
   getExtension(extensionId) {
@@ -378,16 +378,60 @@ class ExtensionPageContextParent extends
   }
 
   shutdown() {
     apiManager.emit("page-shutdown", this);
     super.shutdown();
   }
 }
 
+/**
+ * The parent side of proxied API context for devtools extension page, such as a
+ * devtools pages and panels running in ExtensionChild.jsm.
+ */
+class DevToolsExtensionPageContextParent extends ExtensionPageContextParent {
+  set devToolsToolbox(toolbox) {
+    if (this._devToolsToolbox) {
+      throw new Error("Cannot set the context DevTools toolbox twice");
+    }
+
+    this._devToolsToolbox = toolbox;
+
+    return toolbox;
+  }
+
+  get devToolsToolbox() {
+    return this._devToolsToolbox;
+  }
+
+  set devToolsTarget(contextDevToolsTarget) {
+    if (this._devToolsTarget) {
+      throw new Error("Cannot set the context DevTools target twice");
+    }
+
+    this._devToolsTarget = contextDevToolsTarget;
+
+    return contextDevToolsTarget;
+  }
+
+  get devToolsTarget() {
+    return this._devToolsTarget;
+  }
+
+  shutdown() {
+    if (!this._devToolsTarget) {
+      throw new Error("no DevTools target is set during DevTools Context shutdown");
+    }
+
+    this._devToolsTarget.destroy();
+    this._devToolsTarget = null;
+    this._devToolsToolbox = null;
+  }
+}
+
 ParentAPIManager = {
   proxyContexts: new Map(),
 
   init() {
     Services.obs.addObserver(this, "message-manager-close", false);
 
     Services.mm.addMessageListener("API:CreateProxyContext", this);
     Services.mm.addMessageListener("API:CloseProxyContext", this, true);
@@ -473,17 +517,21 @@ ParentAPIManager = {
           extension.parentMessageManager = processMessageManager;
         }
       }
 
       if (processMessageManager !== extension.parentMessageManager) {
         throw new Error("Attempt to create privileged extension parent from incorrect child process");
       }
 
-      context = new ExtensionPageContextParent(envType, extension, data, target);
+      if (envType == "addon_parent") {
+        context = new ExtensionPageContextParent(envType, extension, data, target);
+      } else if (envType == "devtools_parent") {
+        context = new DevToolsExtensionPageContextParent(envType, extension, data, target);
+      }
     } else if (envType == "content_parent") {
       context = new ContentScriptContextParent(envType, extension, data, target, principal);
     } else {
       throw new Error(`Invalid WebExtension context envType: ${envType}`);
     }
     this.proxyContexts.set(childId, context);
   },