proposal: provide all the embedded webextension APIs to the legacy context. f?kmag,aswan draft
authorLuca Greco <lgreco@mozilla.com>
Fri, 05 Aug 2016 17:54:47 +0200
changeset 397388 fb8d23b86089ba01475140294adddc7e841eee8a
parent 397387 0c5c5ed7e8a5b7fdde505ab27dc38ac16f2a3f08
child 397389 c9bcb18e8fc86e587b1343188d280ef1ade3b055
push id25281
push userluca.greco@alcacoop.it
push dateFri, 05 Aug 2016 18:59:22 +0000
milestone51.0a1
proposal: provide all the embedded webextension APIs to the legacy context. f?kmag,aswan MozReview-Commit-ID: GybbeI7NRHS
toolkit/components/extensions/Extension.jsm
toolkit/components/extensions/LegacyExtensionsUtils.jsm
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -254,16 +254,22 @@ ExtensionContext = class extends BaseCon
     let filter = {extensionId: extension.id};
     this.messenger = new Messenger(this, [Services.mm, Services.ppmm], sender, filter, delegate);
 
     if (this.externallyVisible) {
       this.extension.views.add(this);
     }
   }
 
+// NOTE: used in ProxyContext and LegacyExtensionContext to inject the APIs in
+  // a custom object.
+  injectAPIsInObject(dest, namespaces = null, defaultCallback = () => {}) {
+    GlobalManager.injectInObject(this.extension, this, defaultCallback, dest, namespaces);
+  }
+
   get docShell() {
     return this.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                .getInterface(Ci.nsIDocShell);
   }
 
   get cloneScope() {
     return this.contentWindow;
   }
--- a/toolkit/components/extensions/LegacyExtensionsUtils.jsm
+++ b/toolkit/components/extensions/LegacyExtensionsUtils.jsm
@@ -68,25 +68,24 @@ var LegacyExtensionContext = class exten
     let cloneScope = Cu.Sandbox(this.principal, {});
     Cu.setSandboxMetadata(cloneScope, {addonId: targetExtension.id});
     Object.defineProperty(
       this, "cloneScope",
       {value: cloneScope, enumerable: true, configurable: true}
     );
 
     this.api = {
-      browser: {
-        runtime: {
-          onConnect: this.messenger.onConnect("runtime.onConnect"),
-          onMessage: this.messenger.onMessage("runtime.onMessage"),
-        },
-      },
+      browser: {},
+      chrome: {},
     };
 
-    this.api.chrome = this.api.browser;
+    // Provides to the legacy container add-on all the APIs available in the
+    // embedded webextension.
+    this.injectAPIsInObject(this.api.browser);
+    this.injectAPIsInObject(this.api.chrome, null, null);
   }
 
   /**
    * This method is called when the extension shuts down or is unloaded,
    * and it nukes the cloneScope sandbox, if any.
    */
   unload() {
     super.unload();