Bug 1928510 - [devtools] Remove now-unused WebExtensionTargetActor. r=devtools-reviewers,devtools-backward-compat-reviewers,nchevobbe

WebExtensionTargetActor.getTarget is being removed and removes most of the now-useless
codebase involving connectToFrame and message manager.

This allows to simplify a bit the ParentProcessTargetActor which required
some tweaks to be subclassed correctly.

We can also remove the `consoleAPIListenerOptions` which was specific to
this special target actor retrieving all document's console messages.
Now each individual target actor, for each document will handle the messages distinctly.

Note that we weren't using WebExtensionDescriptorFront.connect.

Differential Revision: https://phabricator.services.mozilla.com/D220541
This commit is contained in:
Alexandre Poirot
2024-11-04 13:13:04 +00:00
parent f0b0147fcf
commit 015d569ad6
15 changed files with 55 additions and 676 deletions

View File

@@ -69,27 +69,6 @@ add_task(async function () {
await client.close();
});
// Test against Webextension targets
add_task(async function () {
const client = await setupDebuggerClient();
const mainRoot = client.mainRoot;
const addons = await mainRoot.listAddons();
await Promise.all(
// some extensions, such as themes, are not debuggable. Filter those out
// before trying to connect.
addons
.filter(a => a.debuggable)
.map(async addonDescriptorFront => {
const addonFront = await addonDescriptorFront.getTarget();
ok(addonFront, "Got the addon target");
})
);
await client.close();
});
// Test against worker targets on parent process
add_task(async function () {
const client = await setupDebuggerClient();

View File

@@ -14,12 +14,6 @@ const {
DescriptorMixin,
} = require("resource://devtools/client/fronts/descriptors/descriptor-mixin.js");
const DESCRIPTOR_TYPES = require("resource://devtools/client/fronts/descriptors/descriptor-types.js");
loader.lazyRequireGetter(
this,
"WindowGlobalTargetFront",
"resource://devtools/client/fronts/targets/window-global.js",
true
);
class WebExtensionDescriptorFront extends DescriptorMixin(
FrontClassWithSpec(webExtensionDescriptorSpec)
@@ -117,16 +111,9 @@ class WebExtensionDescriptorFront extends DescriptorMixin(
});
}
_createWebExtensionTarget(form) {
const front = new WindowGlobalTargetFront(this.conn, null, this);
front.form(form);
this.manage(front);
return front;
}
/**
* Retrieve the WindowGlobalTargetFront representing a
* WebExtensionTargetActor if this addon is a webextension.
* Retrieve the WindowGlobalTargetFront for the top level WindowGlobal
* currently active related to the Web Extension.
*
* WebExtensionDescriptors will be created for any type of addon type
* (webextension, search plugin, themes). Only webextensions can be targets.
@@ -147,25 +134,9 @@ class WebExtensionDescriptorFront extends DescriptorMixin(
return this._targetFront;
}
if (this._targetFrontPromise) {
return this._targetFrontPromise;
}
this._targetFrontPromise = (async () => {
let targetFront = null;
try {
const targetForm = await super.getTarget();
targetFront = this._createWebExtensionTarget(targetForm);
} catch (e) {
console.log(
`Request to connect to WebExtensionDescriptor "${this.id}" failed: ${e}`
);
}
this._targetFront = targetFront;
this._targetFrontPromise = null;
return targetFront;
})();
return this._targetFrontPromise;
throw new Error(
"Missing webextension target actor front. TargetCommand did not notify it (yet?) to the descriptor"
);
}
}

View File

@@ -17,9 +17,6 @@ const {
webExtensionDescriptorSpec,
} = require("resource://devtools/shared/specs/descriptors/webextension.js");
const {
connectToFrame,
} = require("resource://devtools/server/connectors/frame-connector.js");
const {
createWebExtensionSessionContext,
} = require("resource://devtools/server/actors/watcher/session-context.js");
@@ -55,9 +52,9 @@ const BGSCRIPT_STATUSES = {
};
/**
* Creates the actor that represents the addon in the parent process, which connects
* itself to a WebExtensionTargetActor counterpart which is created in the extension
* process (or in the main process if the WebExtensions OOP mode is disabled).
* Creates the actor that represents the addon in the parent process, which relies
* on its child Watcher Actor to expose all WindowGlobal target actors for all
* the active documents involved in the debugged addon.
*
* The WebExtensionDescriptorActor subscribes itself as an AddonListener on the AddonManager
* and forwards this events to child actor (e.g. on addon reload or when the addon is
@@ -83,10 +80,8 @@ class WebExtensionDescriptorActor extends Actor {
super(conn, webExtensionDescriptorSpec);
this.addon = addon;
this.addonId = addon.id;
this._childFormPromise = null;
this.destroy = this.destroy.bind(this);
this._onChildExit = this._onChildExit.bind(this);
lazy.AddonManager.addAddonListener(this);
}
@@ -102,7 +97,7 @@ class WebExtensionDescriptorActor extends Actor {
actor: this.actorID,
backgroundScriptStatus,
// Note that until the policy becomes active,
// getTarget/connectToFrame will fail attaching to the web extension:
// getWatcher will fail attaching to the web extension:
// https://searchfox.org/mozilla-central/rev/526a5089c61db85d4d43eb0e46edaf1f632e853a/toolkit/components/extensions/WebExtensionPolicy.cpp#551-553
debuggable: policy?.active && this.addon.isDebuggable,
hidden: this.addon.hidden,
@@ -211,63 +206,6 @@ class WebExtensionDescriptorActor extends Actor {
await onLocationChanged;
}
async getTarget() {
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,
name: this.addon.name,
});
}
getChildren() {
return [];
}
async _extensionFrameConnect() {
if (this._form) {
return this._form;
}
if (!this._browser) {
// The extension process browser will only be released on destroy and can
// be reused for subsequent targets.
this._browser =
await lazy.ExtensionParent.DebugUtils.getExtensionProcessBrowser(this);
}
const policy = lazy.ExtensionParent.WebExtensionPolicy.getByID(
this.addonId
);
this._form = await connectToFrame(this.conn, this._browser, this.destroy, {
addonId: this.addonId,
addonBrowsingContextGroupId: policy.browsingContextGroupId,
// Bug 1754452: This flag is passed by the client to getWatcher(), but the server
// doesn't support this anyway. So always pass false here and keep things simple.
// Once we enable this flag, we will stop using connectToFrame and instantiate
// the WebExtensionTargetActor from watcher code instead, so that shouldn't
// introduce an issue for the future.
isServerTargetSwitchingEnabled: false,
});
// connectToFrame may resolve to a null form,
// in case the browser element is destroyed before it is fully connected to it.
if (!this._form) {
throw new Error(
"browser element destroyed while connecting to it: " + this.addon.name
);
}
this._mm.addMessageListener("debug:webext_child_exit", this._onChildExit);
this._childActorID = this._form.actor;
return this._form;
}
/**
* Note that reloadDescriptor is the common API name for descriptors
* which support to be reloaded, while WebExtensionDescriptorActor::reload
@@ -344,27 +282,6 @@ class WebExtensionDescriptorActor extends Actor {
return isRunning ? BGSCRIPT_STATUSES.RUNNING : BGSCRIPT_STATUSES.STOPPED;
}
get _mm() {
return (
this._browser &&
(this._browser.messageManager || this._browser.frameLoader.messageManager)
);
}
/**
* Handle the child actor exit.
*/
_onChildExit(msg) {
if (msg.json.actor !== this._childActorID) {
return;
}
// Cleanup internal variables so that a new target will be recreated upon
// calling getTarget/getWatcher again.
delete this._form;
delete this._childActorID;
}
// AddonManagerListener callbacks.
onInstalled(addon) {
if (addon.id != this.addonId) {
@@ -387,25 +304,15 @@ class WebExtensionDescriptorActor extends Actor {
lazy.AddonManager.removeAddonListener(this);
this.addon = null;
if (this._mm) {
this._mm.removeMessageListener(
"debug:webext_child_exit",
this._onChildExit
);
this._mm.sendAsyncMessage("debug:webext_parent_exit", {
actor: this._childActorID,
});
lazy.ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(this);
}
if (this.watcher) {
this.watcher = null;
}
this._browser = null;
this._childActorID = null;
if (this._browser) {
lazy.ExtensionParent.DebugUtils.releaseExtensionProcessBrowser(this);
this._browser = null;
}
this.emit("descriptor-destroyed");

View File

@@ -55,13 +55,9 @@ class ConsoleMessageWatcher {
// But ParentProcess should be ignored as we want all messages emitted directly from
// that process (window and window-less).
// To do that we pass a null window and ConsoleAPIListener will catch everything.
// And also ignore WebExtension as we will filter out only by addonId, which is
// passed via consoleAPIListenerOptions. WebExtension may have multiple windows/documents
// but all of them will be flagged with the same addon ID.
const messagesShouldMatchWindow =
targetActor.targetType === Targets.TYPES.FRAME &&
targetActor.typeName != "parentProcessTarget" &&
targetActor.typeName != "webExtensionTarget";
targetActor.typeName != "parentProcessTarget";
const window = messagesShouldMatchWindow ? targetActor.window : null;
// If we should match messages for a given window but for some reason, targetActor.window
@@ -75,7 +71,6 @@ class ConsoleMessageWatcher {
const listener = new ConsoleAPIListener(window, onConsoleAPICall, {
excludeMessagesBoundToWindow: isTargetActorContentProcess,
matchExactWindow: targetActor.ignoreSubFrames,
...(targetActor.consoleAPIListenerOptions || {}),
});
this.listener = listener;
listener.init();

View File

@@ -14,7 +14,6 @@ DevToolsModules(
"index.js",
"parent-process.js",
"target-actor-registry.sys.mjs",
"webextension.js",
"window-global.js",
"worker.js",
)

View File

@@ -8,7 +8,6 @@
* Target actor for the entire parent process.
*
* This actor extends WindowGlobalTargetActor.
* This actor is extended by WebExtensionTargetActor.
*
* See devtools/docs/backend/actor-hierarchy.md for more details.
*/
@@ -34,26 +33,20 @@ class ParentProcessTargetActor extends WindowGlobalTargetActor {
* RootActor.getProcess request. ParentProcessTargetActor exposes all target-scoped actors
* via its form() request, like WindowGlobalTargetActor.
*
* @param conn DevToolsServerConnection
* @param {DevToolsServerConnection} conn
* The connection to the client.
* @param {Object} options
* - isTopLevelTarget: {Boolean} flag to indicate if this is the top
* level target of the DevTools session
* - sessionContext Object
* The Session Context to help know what is debugged.
* See devtools/server/actors/watcher/session-context.js
* - customSpec Object
* WebExtensionTargetActor inherits from ParentProcessTargetActor
* and has to use its own protocol.js specification object.
* @param {Boolean} options.isTopLevelTarget
* flag to indicate if this is the top
* level target of the DevTools session
* @param {Object} options.sessionContext
* The Session Context to help know what is debugged.
* See devtools/server/actors/watcher/session-context.js
*/
constructor(
conn,
{ isTopLevelTarget, sessionContext, customSpec = parentProcessTargetSpec }
) {
constructor(conn, { isTopLevelTarget, sessionContext }) {
super(conn, {
isTopLevelTarget,
sessionContext,
customSpec,
customSpec: parentProcessTargetSpec,
});
// This creates a Debugger instance for chrome debugging all globals.
@@ -72,17 +65,11 @@ class ParentProcessTargetActor extends WindowGlobalTargetActor {
Services.obs.addObserver(this, "chrome-webnavigation-create");
Services.obs.addObserver(this, "chrome-webnavigation-destroy");
// If we are the parent process target actor and not a subclass
// (i.e. if we aren't the webext target actor)
// set the parent process docshell:
if (customSpec == parentProcessTargetSpec) {
this.setDocShell(this._getInitialDocShell());
}
this.setDocShell(this._getInitialDocShell());
}
// Overload setDocShell in order to observe all the docshells.
// WindowGlobalTargetActor only observes the top level one,
// but we also need to observe all of them for WebExtensionTargetActor subclass.
// WindowGlobalTargetActor only observes the top level one.
setDocShell(initialDocShell) {
super.setDocShell(initialDocShell);

View File

@@ -1,380 +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";
/*
* Target actor for a WebExtension add-on.
*
* This actor extends ParentProcessTargetActor.
*
* See devtools/docs/backend/actor-hierarchy.md for more details.
*/
const {
ParentProcessTargetActor,
} = require("resource://devtools/server/actors/targets/parent-process.js");
const makeDebugger = require("resource://devtools/server/actors/utils/make-debugger.js");
const {
webExtensionTargetSpec,
} = require("resource://devtools/shared/specs/targets/webextension.js");
const {
getChildDocShells,
} = require("resource://devtools/server/actors/targets/window-global.js");
loader.lazyRequireGetter(
this,
"unwrapDebuggerObjectGlobal",
"resource://devtools/server/actors/thread.js",
true
);
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
getAddonIdForWindowGlobal:
"resource://devtools/server/actors/watcher/browsing-context-helpers.sys.mjs",
});
const FALLBACK_DOC_URL =
"chrome://devtools/content/shared/webextension-fallback.html";
class WebExtensionTargetActor extends ParentProcessTargetActor {
/**
* Creates a target actor for debugging all the contexts associated to a target
* WebExtensions add-on running in a child extension process. Most of the implementation
* is inherited from ParentProcessTargetActor (which inherits most of its implementation
* from WindowGlobalTargetActor).
*
* WebExtensionTargetActor is created by a WebExtensionActor counterpart, when its
* parent actor's `connect` method has been called (on the listAddons RDP package),
* it runs in the same process that the extension is running into (which can be the main
* process if the extension is running in non-oop mode, or the child extension process
* if the extension is running in oop-mode).
*
* A WebExtensionTargetActor contains all target-scoped actors, like a regular
* ParentProcessTargetActor or WindowGlobalTargetActor.
*
* History lecture:
* - The add-on actors used to not inherit WindowGlobalTargetActor because of the
* different way the add-on APIs where exposed to the add-on itself, and for this reason
* the Addon Debugger has only a sub-set of the feature available in the Tab or in the
* Browser Toolbox.
* - In a WebExtensions add-on all the provided contexts (background, popups etc.),
* besides the Content Scripts which run in the content process, hooked to an existent
* tab, by creating a new WebExtensionActor which inherits from
* ParentProcessTargetActor, we can provide a full features Addon Toolbox (which is
* basically like a BrowserToolbox which filters the visible sources and frames to the
* one that are related to the target add-on).
* - When the WebExtensions OOP mode has been introduced, this actor has been refactored
* and moved from the main process to the new child extension process.
*
* @param {DevToolsServerConnection} conn
* The connection to the client.
* @param {nsIMessageSender} chromeGlobal.
* The chromeGlobal where this actor has been injected by the
* frame-connector.js connectToFrame method.
* @param {Object} options
* - addonId: {String} the addonId of the target WebExtension.
* - addonBrowsingContextGroupId: {String} the BrowsingContextGroupId used by this addon.
* - chromeGlobal: {nsIMessageSender} The chromeGlobal where this actor
* has been injected by the frame-connector.js connectToFrame method.
* - isTopLevelTarget: {Boolean} flag to indicate if this is the top
* level target of the DevTools session
* - prefix: {String} the custom RDP prefix to use.
* - sessionContext Object
* The Session Context to help know what is debugged.
* See devtools/server/actors/watcher/session-context.js
*/
constructor(
conn,
{
addonId,
addonBrowsingContextGroupId,
chromeGlobal,
isTopLevelTarget,
prefix,
sessionContext,
}
) {
super(conn, {
isTopLevelTarget,
sessionContext,
customSpec: webExtensionTargetSpec,
});
this.addonId = addonId;
this.addonBrowsingContextGroupId = addonBrowsingContextGroupId;
this._chromeGlobal = chromeGlobal;
this._prefix = prefix;
// Expose the BrowsingContext of the fallback document,
// which is the one this target actor will always refer to via its form()
// and all resources should be related to this one as we currently spawn
// only just this one target actor to debug all webextension documents.
this.devtoolsSpawnedBrowsingContextForWebExtension =
chromeGlobal.browsingContext;
// Redefine the messageManager getter to return the chromeGlobal
// as the messageManager for this actor (which is the browser XUL
// element used by the parent actor running in the main process to
// connect to the extension process).
Object.defineProperty(this, "messageManager", {
enumerable: true,
configurable: true,
get: () => {
return this._chromeGlobal;
},
});
this._onParentExit = this._onParentExit.bind(this);
this._chromeGlobal.addMessageListener(
"debug:webext_parent_exit",
this._onParentExit
);
// Set the consoleAPIListener filtering options
// (retrieved and used in the related webconsole child actor).
this.consoleAPIListenerOptions = {
addonId: this.addonId,
};
// This creates a Debugger instance for debugging all the add-on globals.
this.makeDebugger = makeDebugger.bind(null, {
findDebuggees: dbg => {
return dbg
.findAllGlobals()
.filter(this._shouldAddNewGlobalAsDebuggee)
.map(g => g.unsafeDereference());
},
shouldAddNewGlobalAsDebuggee:
this._shouldAddNewGlobalAsDebuggee.bind(this),
});
// NOTE: This is needed to catch in the webextension webconsole all the
// errors raised by the WebExtension internals that are not currently
// associated with any window.
this.isRootActor = true;
// Try to discovery an existent extension page to attach (which will provide the initial
// URL shown in the window tittle when the addon debugger is opened).
const extensionWindow = this._searchForExtensionWindow();
this.setDocShell(extensionWindow.docShell);
// `setDocShell` will force the instantiation of the thread actor.
// We now have to initialize it in order to listen for new global
// which allows to properly detect addon reload via _shouldAddNewGlobalAsDebuggee
// which may call _onNewExtensionWindow.
this.threadActor.attach({});
}
// Override the ParentProcessTargetActor's override in order to only iterate
// over the docshells specific to this add-on
get docShells() {
// Iterate over all top-level windows and all their docshells.
let docShells = [];
for (const window of Services.ww.getWindowEnumerator(null)) {
docShells = docShells.concat(getChildDocShells(window.docShell));
}
// Then filter out the ones specific to the add-on
return docShells.filter(docShell => {
return this.isExtensionWindowDescendent(docShell.domWindow);
});
}
/**
* Called when the actor is removed from the connection.
*/
destroy() {
if (this._chromeGlobal) {
const chromeGlobal = this._chromeGlobal;
this._chromeGlobal = null;
chromeGlobal.removeMessageListener(
"debug:webext_parent_exit",
this._onParentExit
);
chromeGlobal.sendAsyncMessage("debug:webext_child_exit", {
actor: this.actorID,
});
}
if (this.fallbackWindow) {
this.fallbackWindow = null;
}
this.addon = null;
this.addonId = null;
return super.destroy();
}
// Private helpers.
_searchFallbackWindow() {
if (this.fallbackWindow) {
// Skip if there is already an existent fallback window.
return this.fallbackWindow;
}
// Set and initialize the fallbackWindow (which initially is a empty
// about:blank browser), this window is related to a XUL browser element
// specifically created for the devtools server and it is never used
// or navigated anywhere else.
this.fallbackWindow = this._chromeGlobal.content;
// Add the addonId in the URL to retrieve this information in other devtools
// helpers. The addonId is usually populated in the principal, but this will
// not be the case for the fallback window because it is loaded from chrome://
// instead of moz-extension://${addonId}
this.fallbackWindow.document.location.href = `${FALLBACK_DOC_URL}#${this.addonId}`;
return this.fallbackWindow;
}
// Discovery an extension page to use as a default target window.
// NOTE: This currently fail to discovery an extension page running in a
// windowless browser when running in non-oop mode, and the background page
// is set later using _onNewExtensionWindow.
_searchForExtensionWindow() {
// Looks if there is any top level add-on document:
// (we do not want to pass any nested add-on iframe)
const docShell = this.docShells.find(d =>
this.isTopLevelExtensionWindow(d.domWindow)
);
if (docShell) {
return docShell.domWindow;
}
return this._searchFallbackWindow();
}
// Customized ParentProcessTargetActor/WindowGlobalTargetActor hooks.
_onDocShellCreated(docShell) {
// Compare against the BrowsingContext's group ID as the document's principal addonId
// won't be set yet for freshly created docshells. It will be later set, when loading the addon URL.
// But right now, it is still on the initial about:blank document and the principal isn't related to the add-on.
if (docShell.browsingContext.group.id != this.addonBrowsingContextGroupId) {
return;
}
super._onDocShellCreated(docShell);
}
_onDocShellDestroy(docShell) {
if (docShell.browsingContext.group.id != this.addonBrowsingContextGroupId) {
return;
}
// Stop watching this docshell (the unwatch() method will check if we
// started watching it before).
this._unwatchDocShell(docShell);
// Let the _onDocShellDestroy notify that the docShell has been destroyed.
const webProgress = docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebProgress);
this._notifyDocShellDestroy(webProgress);
// If the destroyed docShell:
// * was the current docShell,
// * the actor is not destroyed,
// * isn't the background page, as it means the addon is being shutdown or reloaded
// and the target would be replaced by a new one to come, or everything is closing.
// => switch to the fallback window
if (
!this.isDestroyed() &&
docShell == this.docShell &&
!docShell.domWindow.location.href.includes(
"_generated_background_page.html"
)
) {
this._changeTopLevelDocument(this._searchForExtensionWindow());
}
}
_onNewExtensionWindow(window) {
if (!this.window || this.window === this.fallbackWindow) {
this._changeTopLevelDocument(window);
// For new extension windows, the BrowsingContext group id might have
// changed, for instance when reloading the addon.
this.addonBrowsingContextGroupId =
window.docShell.browsingContext.group.id;
}
}
isTopLevelExtensionWindow(window) {
const { docShell } = window;
const isTopLevel = docShell.sameTypeRootTreeItem == docShell;
// Note: We are not using getAddonIdForWindowGlobal here because the
// fallback window should not be considered as a top level extension window.
return isTopLevel && window.document.nodePrincipal.addonId == this.addonId;
}
isExtensionWindowDescendent(window) {
// Check if the source is coming from a descendant docShell of an extension window.
// We may have an iframe that loads http content which won't use the add-on principal.
const rootWin = window.docShell.sameTypeRootTreeItem.domWindow;
const addonId = lazy.getAddonIdForWindowGlobal(rootWin.windowGlobalChild);
return addonId == this.addonId;
}
/**
* Return true if the given global is associated with this addon and should be
* added as a debuggee, false otherwise.
*/
_shouldAddNewGlobalAsDebuggee(newGlobal) {
const global = unwrapDebuggerObjectGlobal(newGlobal);
if (global instanceof Ci.nsIDOMWindow) {
try {
global.document;
} catch (e) {
// The global might be a sandbox with a window object in its proto chain. If the
// window navigated away since the sandbox was created, it can throw a security
// exception during this property check as the sandbox no longer has access to
// its own proto.
return false;
}
// When `global` is a sandbox it may be a nsIDOMWindow object,
// but won't be the real Window object. Retrieve it via document's ownerGlobal.
const window = global.document.ownerGlobal;
if (!window) {
return false;
}
// Change top level document as a simulated frame switching.
if (this.isTopLevelExtensionWindow(window)) {
this._onNewExtensionWindow(window);
}
return this.isExtensionWindowDescendent(window);
}
try {
// This will fail for non-Sandbox objects, hence the try-catch block.
const metadata = Cu.getSandboxMetadata(global);
if (metadata) {
return metadata.addonID === this.addonId;
}
} catch (e) {
// Unable to retrieve the sandbox metadata.
}
return false;
}
// Handlers for the messages received from the parent actor.
_onParentExit(msg) {
if (msg.json.actor !== this.actorID) {
return;
}
this.destroy();
}
}
exports.WebExtensionTargetActor = WebExtensionTargetActor;

View File

@@ -12,7 +12,7 @@
* WindowGlobalTargetActor is an abstract class used by target actors that hold
* documents, such as frames, chrome windows, etc.
*
* This class is extended by ParentProcessTargetActor, itself being extented by WebExtensionTargetActor.
* This class is extended by ParentProcessTargetActor.
*
* See devtools/docs/backend/actor-hierarchy.md for more details.
*
@@ -366,7 +366,7 @@ class WindowGlobalTargetActor extends BaseTargetActor {
* Define the initial docshell.
*
* This is called from the constructor for WindowGlobalTargetActor,
* or from sub class constructors: WebExtensionTargetActor and ParentProcessTargetActor.
* or from sub class constructor of ParentProcessTargetActor.
*
* This is to circumvent the fact that sub classes need to call inner method
* to compute the initial docshell and we can't call inner methods before calling
@@ -425,10 +425,6 @@ class WindowGlobalTargetActor extends BaseTargetActor {
);
}
// Optional console API listener options (e.g. used by the WebExtensionActor to
// filter console messages by addonID), set to an empty (no options) object by default.
consoleAPIListenerOptions = {};
/*
* Return a Debugger instance or create one if there is none yet
*/

View File

@@ -501,7 +501,6 @@ class WebConsoleActor extends Actor {
this.onConsoleAPICall,
{
matchExactWindow: this.targetActor.ignoreSubFrames,
...(this.targetActor.consoleAPIListenerOptions || {}),
}
);
this.consoleAPIListener.init();

View File

@@ -40,12 +40,7 @@ loader.lazyRequireGetter(
* @return object
* A promise object that is resolved once the connection is established.
*/
function connectToFrame(
connection,
frame,
onDestroy,
{ addonId, addonBrowsingContextGroupId } = {}
) {
function connectToFrame(connection, frame, onDestroy) {
return new Promise(resolve => {
// Get messageManager from XUL browser (which might be a specialized tunnel for RDM)
// or else fallback to asking the frameLoader itself.
@@ -162,8 +157,6 @@ function connectToFrame(
mm.sendAsyncMessage("debug:connect", {
prefix,
addonId,
addonBrowsingContextGroupId,
});
});
}

View File

@@ -57,8 +57,6 @@ try {
const onConnect = DevToolsUtils.makeInfallible(function (msg) {
const mm = msg.target;
const prefix = msg.data.prefix;
const addonId = msg.data.addonId;
const addonBrowsingContextGroupId = msg.data.addonBrowsingContextGroupId;
// If we try to create several frame targets simultaneously, the frame script will be loaded several times.
// In this case a single "debug:connect" message might be received by all the already loaded frame scripts.
@@ -74,64 +72,34 @@ try {
const conn = DevToolsServer.connectToParent(prefix, mm);
connections.set(prefix, conn);
let actor;
const {
WindowGlobalTargetActor,
} = require("resource://devtools/server/actors/targets/window-global.js");
const {
createBrowserElementSessionContext,
} = require("resource://devtools/server/actors/watcher/session-context.js");
if (addonId) {
const {
WebExtensionTargetActor,
} = require("resource://devtools/server/actors/targets/webextension.js");
const {
createWebExtensionSessionContext,
} = require("resource://devtools/server/actors/watcher/session-context.js");
const { browsingContext } = docShell;
actor = new WebExtensionTargetActor(conn, {
addonId,
addonBrowsingContextGroupId,
chromeGlobal,
isTopLevelTarget: true,
prefix,
sessionContext: createWebExtensionSessionContext(
{
addonId,
browsingContextID: browsingContext.id,
innerWindowId: browsingContext.currentWindowContext.innerWindowId,
},
{
isServerTargetSwitchingEnabled:
msg.data.isServerTargetSwitchingEnabled,
}
),
});
} else {
const {
WindowGlobalTargetActor,
} = require("resource://devtools/server/actors/targets/window-global.js");
const {
createBrowserElementSessionContext,
} = require("resource://devtools/server/actors/watcher/session-context.js");
const { docShell } = chromeGlobal;
// For a script loaded via loadFrameScript, the global is the content
// message manager.
// All WindowGlobalTarget actors created via the framescript are top-level
// targets. Non top-level WindowGlobalTarget actors are all created by the
// DevToolsFrameChild actor.
//
// createBrowserElementSessionContext only reads browserId attribute
const fakeBrowserElement = {
browserId: docShell.browsingContext.browserId,
};
actor = new WindowGlobalTargetActor(conn, {
docShell,
isTopLevelTarget: true,
// This is only used when server target switching is off and we create
// the target from TabDescriptor. So all config attributes are false.
sessionContext: createBrowserElementSessionContext(
fakeBrowserElement,
{}
),
});
}
const { docShell } = chromeGlobal;
// For a script loaded via loadFrameScript, the global is the content
// message manager.
// All WindowGlobalTarget actors created via the framescript are top-level
// targets. Non top-level WindowGlobalTarget actors are all created by the
// DevToolsFrameChild actor.
//
// createBrowserElementSessionContext only reads browserId attribute
const fakeBrowserElement = {
browserId: docShell.browsingContext.browserId,
};
const actor = new WindowGlobalTargetActor(conn, {
docShell,
isTopLevelTarget: true,
// This is only used when server target switching is off and we create
// the target from TabDescriptor. So all config attributes are false.
sessionContext: createBrowserElementSessionContext(
fakeBrowserElement,
{}
),
});
actor.manage(actor);
sendAsyncMessage("debug:actor", { actor: actor.form(), prefix });

View File

@@ -23,17 +23,6 @@ const webExtensionDescriptorSpec = generateActorSpec({
response: {},
},
// @backward-compat { version 70 } The method is now called getTarget
connect: {
request: {},
response: { form: RetVal("json") },
},
getTarget: {
request: {},
response: { form: RetVal("json") },
},
reloadDescriptor: {
request: {
bypassCache: Option(0, "boolean"),

View File

@@ -283,11 +283,6 @@ const Types = (exports.__TypesForTests = [
spec: "devtools/shared/specs/targets/parent-process",
front: null,
},
{
types: ["webExtensionTarget"],
spec: "devtools/shared/specs/targets/webextension",
front: null,
},
{
types: ["windowGlobalTarget"],
spec: "devtools/shared/specs/targets/window-global",

View File

@@ -7,7 +7,6 @@
DevToolsModules(
"content-process.js",
"parent-process.js",
"webextension.js",
"window-global.js",
"worker.js",
)

View File

@@ -1,18 +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 { generateActorSpec } = require("resource://devtools/shared/protocol.js");
const { extend } = require("resource://devtools/shared/extend.js");
const {
parentProcessTargetSpecPrototype,
} = require("resource://devtools/shared/specs/targets/parent-process.js");
const webExtensionTargetSpec = generateActorSpec(
extend(parentProcessTargetSpecPrototype, {
typeName: "webExtensionTarget",
})
);
exports.webExtensionTargetSpec = webExtensionTargetSpec;