--- a/toolkit/components/extensions/ExtensionChild.jsm
+++ b/toolkit/components/extensions/ExtensionChild.jsm
@@ -17,42 +17,36 @@ this.EXPORTED_SYMBOLS = ["ExtensionChild
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
-XPCOMUtils.defineLazyModuleGetter(this, "ExtensionParent",
- "resource://gre/modules/ExtensionParent.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "MessageChannel",
"resource://gre/modules/MessageChannel.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "NativeApp",
"resource://gre/modules/NativeMessaging.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PromiseUtils",
"resource://gre/modules/PromiseUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Schemas",
"resource://gre/modules/Schemas.jsm");
-XPCOMUtils.defineLazyGetter(this, "ParentAPIManager",
- () => ExtensionParent.ParentAPIManager);
-
const CATEGORY_EXTENSION_SCRIPTS_ADDON = "webextension-scripts-addon";
Cu.import("resource://gre/modules/ExtensionCommon.jsm");
Cu.import("resource://gre/modules/ExtensionUtils.jsm");
const {
DefaultMap,
EventManager,
SingletonEventManager,
SpreadArgs,
defineLazyGetter,
- findPathInObject,
getInnerWindowID,
getMessageManager,
injectAPI,
} = ExtensionUtils;
const {
BaseContext,
LocalAPIImplementation,
@@ -544,20 +538,21 @@ class ProxyAPIImplementation extends Sch
return map.listeners.has(listener);
}
}
// We create one instance of this class for every extension context that
// needs to use remote APIs. It uses the message manager to communicate
// with the ParentAPIManager singleton in ExtensionParent.jsm. It
// handles asynchronous function calls as well as event listeners.
-class ChildAPIManagerBase {
+class ChildAPIManager {
constructor(context, messageManager, localApis, contextData) {
this.context = context;
this.messageManager = messageManager;
+ this.url = contextData.url;
// The root namespace of all locally implemented APIs. If an extension calls
// an API that does not exist in this object, then the implementation is
// delegated to the ParentAPIManager.
this.localApis = localApis;
this.id = `${context.extension.id}.${context.contextId}`;
@@ -568,16 +563,25 @@ class ChildAPIManagerBase {
this.listeners = new DefaultMap(() => ({
ids: new Map(),
listeners: new Map(),
}));
// Map[callId -> Deferred]
this.callPromises = new Map();
+
+ let params = {
+ childId: this.id,
+ extensionId: context.extension.id,
+ principal: context.principal,
+ };
+ Object.assign(params, contextData);
+
+ this.messageManager.sendAsyncMessage("API:CreateProxyContext", params);
}
receiveMessage({name, messageName, data}) {
if (data.childId != this.id) {
return;
}
switch (name || messageName) {
@@ -709,90 +713,16 @@ class ChildAPIManagerBase {
return new ProxyAPIImplementation(namespace, name, this);
}
hasPermission(permission) {
return this.context.extension.hasPermission(permission);
}
}
-class ChildAPIManager extends ChildAPIManagerBase {
- constructor(context, messageManager, localApis, contextData) {
- super(context, messageManager, localApis, contextData);
-
- let params = {
- childId: this.id,
- extensionId: context.extension.id,
- principal: context.principal,
- };
- Object.assign(params, contextData);
-
- this.messageManager.sendAsyncMessage("API:CreateProxyContext", params);
- }
-}
-
-
-// A class that behaves identical to a ChildAPIManager, except
-// 1) creation of the ProxyContext in the parent is synchronous, and
-// 2) APIs without a local implementation and marked as incompatible with the
-// out-of-process model fall back to directly invoking the parent methods.
-// TODO(robwu): Remove this when all APIs have migrated.
-class PseudoChildAPIManager extends ChildAPIManagerBase {
- constructor(context, messageManager, localApis, contextData) {
- super(context, messageManager, localApis, contextData);
-
- let params = {
- childId: this.id,
- extensionId: context.extension.id,
- };
- Object.assign(params, contextData);
-
- // Structured clone the parameters to simulate cross-process messaging.
- params = Cu.cloneInto(params, {});
- // Principals can be structured cloned by message managers, but not
- // by cloneInto.
- params.principal = context.principal;
- params.cloneScope = this.cloneScope;
-
- this.url = params.url;
-
- let browserElement = this.context.docShell.chromeEventHandler;
- ParentAPIManager.receiveMessage({
- name: "API:CreateProxyContext",
- data: params,
- target: browserElement,
- });
-
- this.parentContext = ParentAPIManager.proxyContexts.get(this.id);
-
- // Synchronously unload the ProxyContext because we synchronously create it.
- this.context.callOnClose(this.parentContext);
- }
-
- getFallbackImplementation(namespace, name) {
- let useDirectParentAPI = (
- // Incompatible APIs are listed here.
- false
- );
-
- if (useDirectParentAPI) {
- let apiObj = findPathInObject(this.parentContext.apiObj, namespace, false);
-
- if (apiObj && name in apiObj) {
- return new LocalAPIImplementation(apiObj, name, this.context);
- }
- // If we got here, then it means that the JSON schema claimed that the API
- // will be available, but no actual implementation is given.
- // You should either provide an implementation or rewrite the JSON schema.
- }
-
- return super.getFallbackImplementation(namespace, name);
- }
-}
-
class ExtensionPageContextChild extends BaseContext {
/**
* This ExtensionPageContextChild represents a privileged addon
* execution environment that has full access to the WebExtensions
* APIs (provided that the correct permissions have been requested).
*
* This is the child side of the ExtensionPageContextParent class
* defined in ExtensionParent.jsm.
@@ -903,17 +833,17 @@ defineLazyGetter(ExtensionPageContextChi
defineLazyGetter(ExtensionPageContextChild.prototype, "childManager", function() {
let localApis = {};
apiManager.generateAPIs(this, localApis);
if (this.viewType == "background") {
apiManager.global.initializeBackgroundPage(this.contentWindow);
}
- let childManager = new PseudoChildAPIManager(this, this.messageManager, localApis, {
+ let childManager = new ChildAPIManager(this, this.messageManager, localApis, {
envType: "addon_parent",
viewType: this.viewType,
url: this.uri.spec,
incognito: this.incognito,
});
this.callOnClose(childManager);
--- a/toolkit/components/extensions/ExtensionParent.jsm
+++ b/toolkit/components/extensions/ExtensionParent.jsm
@@ -258,24 +258,16 @@ class ProxyContextParent extends BaseCon
// message manager object may change when `xulBrowser` swaps docshells, e.g.
// when a tab is moved to a different window.
this.messageManagerProxy = new MessageManagerProxy(xulBrowser);
Object.defineProperty(this, "principal", {
value: principal, enumerable: true, configurable: true,
});
- // TODO: Replace this with a Sandbox with our content principal when
- // we move to separate processes.
- if (params.cloneScope) {
- Object.defineProperty(this, "cloneScope", {
- value: params.cloneScope, enumerable: true, configurable: true,
- });
- }
-
this.listenerProxies = new Map();
apiManager.emit("proxy-context-load", this);
}
get cloneScope() {
return this.sandbox;
}