зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1575557 - merge webextension-proxy with webextension; r=ochameau
Differential Revision: https://phabricator.services.mozilla.com/D42866 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
e7dd37593b
Коммит
207370a55c
|
@ -16,9 +16,7 @@ const protocol = require("devtools/shared/protocol");
|
|||
const {
|
||||
webExtensionSpec,
|
||||
} = require("devtools/shared/specs/addon/webextension");
|
||||
const {
|
||||
WebExtensionTargetActorProxy,
|
||||
} = require("devtools/server/actors/targets/webextension-proxy");
|
||||
const { DebuggerServer } = require("devtools/server/debugger-server");
|
||||
|
||||
loader.lazyImporter(
|
||||
this,
|
||||
|
@ -52,32 +50,17 @@ loader.lazyImporter(
|
|||
*/
|
||||
const WebExtensionActor = protocol.ActorClassWithSpec(webExtensionSpec, {
|
||||
initialize(conn, addon) {
|
||||
this.conn = conn;
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
this.addon = addon;
|
||||
this.addonId = addon.id;
|
||||
this._childFormPromise = null;
|
||||
|
||||
// Called when the debug browser element has been destroyed
|
||||
this._extensionFrameDisconnect = this._extensionFrameDisconnect.bind(this);
|
||||
this._onChildExit = this._onChildExit.bind(this);
|
||||
AddonManager.addAddonListener(this);
|
||||
},
|
||||
|
||||
destroy() {
|
||||
AddonManager.removeAddonListener(this);
|
||||
|
||||
this.addon = null;
|
||||
this._childFormPromise = null;
|
||||
|
||||
if (this._destroyProxy) {
|
||||
this._destroyProxy();
|
||||
delete this._destroyProxy;
|
||||
}
|
||||
},
|
||||
|
||||
reload() {
|
||||
return this.addon.reload().then(() => {
|
||||
return {};
|
||||
});
|
||||
},
|
||||
|
||||
form() {
|
||||
const policy = ExtensionParent.WebExtensionPolicy.getByID(this.addonId);
|
||||
return {
|
||||
|
@ -103,25 +86,57 @@ const WebExtensionActor = protocol.ActorClassWithSpec(webExtensionSpec, {
|
|||
},
|
||||
|
||||
connect() {
|
||||
if (this._childFormPormise) {
|
||||
return this._childFormPromise;
|
||||
if (this._childTargetPromise) {
|
||||
return this._childTargetPromise;
|
||||
}
|
||||
|
||||
const proxy = new WebExtensionTargetActorProxy(this.conn, this);
|
||||
this._childFormPromise = proxy.connect().then(form => {
|
||||
this._childTargetPromise = (async () => {
|
||||
const form = await this._extensionFrameConnect();
|
||||
// Merge into the child actor form, some addon metadata
|
||||
// (e.g. the addon name shown in the addon debugger window title).
|
||||
return Object.assign(form, {
|
||||
iconURL: this.addon.iconURL,
|
||||
id: this.addon.id,
|
||||
// Set the isOOP attribute on the connected child actor form.
|
||||
isOOP: proxy.isOOP,
|
||||
isOOP: this.isOOP,
|
||||
name: this.addon.name,
|
||||
});
|
||||
});
|
||||
this._destroyProxy = () => proxy.destroy();
|
||||
})();
|
||||
|
||||
return this._childFormPromise;
|
||||
return this._childTargetPromise;
|
||||
},
|
||||
|
||||
async _extensionFrameConnect() {
|
||||
if (this._browser) {
|
||||
throw new Error(
|
||||
"This actor is already connected to the extension process"
|
||||
);
|
||||
}
|
||||
|
||||
this._browser = await ExtensionParent.DebugUtils.getExtensionProcessBrowser(
|
||||
this
|
||||
);
|
||||
|
||||
this._form = await DebuggerServer.connectToFrame(
|
||||
this.conn,
|
||||
this._browser,
|
||||
this._extensionFrameDisconnect,
|
||||
{ addonId: this.addonId }
|
||||
);
|
||||
|
||||
this._childActorID = this._form.actor;
|
||||
|
||||
// Exit the proxy child actor if the child actor has been destroyed.
|
||||
this._mm.addMessageListener("debug:webext_child_exit", this._onChildExit);
|
||||
|
||||
return this._form;
|
||||
},
|
||||
|
||||
/** WebExtension Actor Methods **/
|
||||
reload() {
|
||||
return this.addon.reload().then(() => {
|
||||
return {};
|
||||
});
|
||||
},
|
||||
|
||||
// This function will be called from RootActor in case that the debugger client
|
||||
|
@ -163,17 +178,50 @@ const WebExtensionActor = protocol.ActorClassWithSpec(webExtensionSpec, {
|
|||
}
|
||||
},
|
||||
|
||||
// WebExtensionTargetActorProxy callbacks.
|
||||
// TODO: check if we need this, as it is only used in a test
|
||||
get isOOP() {
|
||||
return this._browser ? this._browser.isRemoteBrowser : undefined;
|
||||
},
|
||||
|
||||
onProxyDestroy() {
|
||||
// Invalidate the cached child actor and form Promise
|
||||
// if the child actor exits.
|
||||
this._childFormPromise = null;
|
||||
delete this._destroyProxy;
|
||||
// Private Methods
|
||||
get _mm() {
|
||||
return (
|
||||
this._browser &&
|
||||
(this._browser.messageManager || this._browser.frameLoader.messageManager)
|
||||
);
|
||||
},
|
||||
|
||||
_extensionFrameDisconnect() {
|
||||
this._childTargetPromise = null;
|
||||
|
||||
if (this._mm) {
|
||||
this._mm.removeMessageListener(
|
||||
"debug:webext_child_exit",
|
||||
this._onChildExit
|
||||
);
|
||||
|
||||
this._mm.sendAsyncMessage("debug:webext_parent_exit", {
|
||||
actor: this._childActorID,
|
||||
});
|
||||
|
||||
ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(this);
|
||||
}
|
||||
|
||||
this._browser = null;
|
||||
this._childActorID = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle the child actor exit.
|
||||
*/
|
||||
_onChildExit(msg) {
|
||||
if (msg.json.actor !== this._childActorID) {
|
||||
return;
|
||||
}
|
||||
this._extensionFrameDisconnect();
|
||||
},
|
||||
|
||||
// AddonManagerListener callbacks.
|
||||
|
||||
onInstalled(addon) {
|
||||
if (addon.id != this.addonId) {
|
||||
return;
|
||||
|
@ -188,7 +236,14 @@ const WebExtensionActor = protocol.ActorClassWithSpec(webExtensionSpec, {
|
|||
return;
|
||||
}
|
||||
|
||||
this.destroy();
|
||||
this._extensionFrameDisconnect();
|
||||
},
|
||||
|
||||
destroy() {
|
||||
AddonManager.removeAddonListener(this);
|
||||
this._extensionFrameDisconnect();
|
||||
this.addon = null;
|
||||
protocol.Actor.prototype.destroy.call(this);
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ DevToolsModules(
|
|||
'frame-proxy.js',
|
||||
'frame.js',
|
||||
'parent-process.js',
|
||||
'webextension-proxy.js',
|
||||
'webextension.js',
|
||||
'worker.js',
|
||||
)
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
/* 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";
|
||||
|
||||
const { DebuggerServer } = require("devtools/server/debugger-server");
|
||||
|
||||
loader.lazyImporter(
|
||||
this,
|
||||
"ExtensionParent",
|
||||
"resource://gre/modules/ExtensionParent.jsm"
|
||||
);
|
||||
|
||||
function WebExtensionTargetActorProxy(connection, parentActor) {
|
||||
this._conn = connection;
|
||||
this._parentActor = parentActor;
|
||||
this.addonId = parentActor.addonId;
|
||||
|
||||
this._onChildExit = this._onChildExit.bind(this);
|
||||
|
||||
this._form = null;
|
||||
this._browser = null;
|
||||
this._childActorID = null;
|
||||
}
|
||||
|
||||
WebExtensionTargetActorProxy.prototype = {
|
||||
/**
|
||||
* Connect the webextension child actor.
|
||||
*/
|
||||
async connect() {
|
||||
if (this._browser) {
|
||||
throw new Error(
|
||||
"This actor is already connected to the extension process"
|
||||
);
|
||||
}
|
||||
|
||||
// Called when the debug browser element has been destroyed
|
||||
// (no actor is using it anymore to connect the child extension process).
|
||||
const onDestroy = this.destroy.bind(this);
|
||||
|
||||
this._browser = await ExtensionParent.DebugUtils.getExtensionProcessBrowser(
|
||||
this
|
||||
);
|
||||
|
||||
this._form = await DebuggerServer.connectToFrame(
|
||||
this._conn,
|
||||
this._browser,
|
||||
onDestroy,
|
||||
{ addonId: this.addonId }
|
||||
);
|
||||
|
||||
this._childActorID = this._form.actor;
|
||||
|
||||
// Exit the proxy child actor if the child actor has been destroyed.
|
||||
this._mm.addMessageListener("debug:webext_child_exit", this._onChildExit);
|
||||
|
||||
return this._form;
|
||||
},
|
||||
|
||||
get isOOP() {
|
||||
return this._browser ? this._browser.isRemoteBrowser : undefined;
|
||||
},
|
||||
|
||||
get _mm() {
|
||||
return (
|
||||
this._browser &&
|
||||
(this._browser.messageManager || this._browser.frameLoader.messageManager)
|
||||
);
|
||||
},
|
||||
|
||||
destroy() {
|
||||
if (this._mm) {
|
||||
this._mm.removeMessageListener(
|
||||
"debug:webext_child_exit",
|
||||
this._onChildExit
|
||||
);
|
||||
|
||||
this._mm.sendAsyncMessage("debug:webext_parent_exit", {
|
||||
actor: this._childActorID,
|
||||
});
|
||||
|
||||
ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(this);
|
||||
}
|
||||
|
||||
if (this._parentActor) {
|
||||
this._parentActor.onProxyDestroy();
|
||||
}
|
||||
|
||||
this._parentActor = null;
|
||||
this._browser = null;
|
||||
this._childActorID = null;
|
||||
this._form = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Handle the child actor exit.
|
||||
*/
|
||||
_onChildExit(msg) {
|
||||
if (msg.json.actor !== this._childActorID) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.destroy();
|
||||
},
|
||||
};
|
||||
|
||||
exports.WebExtensionTargetActorProxy = WebExtensionTargetActorProxy;
|
|
@ -20,10 +20,7 @@ loader.lazyRequireGetter(
|
|||
class WebExtensionFront extends FrontClassWithSpec(webExtensionSpec) {
|
||||
constructor(client, targetFront, parentFront) {
|
||||
super(client, targetFront, parentFront);
|
||||
|
||||
this.client = client;
|
||||
|
||||
this.traits = {};
|
||||
}
|
||||
|
||||
form(json) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче