proposal: provide all the embedded webextension APIs to the legacy context. f?kmag,aswan
draft
proposal: provide all the embedded webextension APIs to the legacy context. f?kmag,aswan
MozReview-Commit-ID: GybbeI7NRHS
--- 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();