Bug 1745238 - [devtools] Rename WatcherActor and SessionData "context" to "sessionContext". r=nchevobbe

In prevision of a broader use of this existing "context" object,
I'm renaming it in order to make this important object clearer and more easily identifiable.

SessionContext object defines what we are debugging (everything, only one tab, an addon,...)
and so controls which platform data we should expose back to the client.

Differential Revision: https://phabricator.services.mozilla.com/D134411
This commit is contained in:
Alexandre Poirot 2021-12-22 13:17:11 +00:00
Родитель 4014400bc7
Коммит d7e364c932
14 изменённых файлов: 154 добавлений и 140 удалений

Просмотреть файл

@ -49,7 +49,10 @@ class NetworkEventWatcher {
// Boolean to know if we keep previous document network events or not.
this.persist = false;
this.listener = new NetworkObserver(
{ browserId: this.browserId, addonId: watcherActor.context.addonId },
{
browserId: this.browserId,
addonId: watcherActor.sessionContext.addonId,
},
{ onNetworkEvent: this.onNetworkEvent.bind(this) }
);
@ -62,7 +65,7 @@ class NetworkEventWatcher {
}
get browserId() {
return this.watcherActor.context.browserId;
return this.watcherActor.sessionContext.browserId;
}
/**
@ -155,13 +158,13 @@ class NetworkEventWatcher {
}
// If we persist, we will keep all requests allocated.
// For now, consider that the Browser console and toolbox persist all the requests.
if (this.persist || this.watcherActor.context.type == "all") {
if (this.persist || this.watcherActor.sessionContext.type == "all") {
return;
}
// If the watcher is bound to one browser element (i.e. a tab), ignore
// windowGlobals related to other browser elements
if (
this.watcherActor.context.type == "browser-element" &&
this.watcherActor.sessionContext.type == "browser-element" &&
windowGlobal.browsingContext.browserId != this.browserId
) {
return;

Просмотреть файл

@ -80,24 +80,25 @@ class ParentProcessDocumentEventWatcher {
}
getAllBrowsingContexts() {
if (this.watcherActor.context.type == "browser-element") {
if (this.watcherActor.sessionContext.type == "browser-element") {
const browsingContext = this.watcherActor.browserElement.browsingContext;
return browsingContext.getAllBrowsingContextsInSubtree();
}
if (this.watcherActor.context.type == "all") {
if (this.watcherActor.sessionContext.type == "all") {
return getAllRemoteBrowsingContexts();
}
if (this.watcherActor.context.type == "webextension") {
if (this.watcherActor.sessionContext.type == "webextension") {
return getAllRemoteBrowsingContexts().filter(
bc =>
bc.currentWindowGlobal.documentPrincipal.addonId ==
this.watcherActor.context.addonId
this.watcherActor.sessionContext.addonId
);
}
throw new Error(
"Unsupported context type=" + this.watcherActor.context.type
"Unsupported session context type=" +
this.watcherActor.sessionContext.type
);
}

Просмотреть файл

@ -67,20 +67,22 @@ class ParentProcessStorage {
({ windowGlobal }) => this._onNewWindowGlobal(windowGlobal, true)
);
if (watcherActor.context.type == "browser-element") {
if (watcherActor.sessionContext.type == "browser-element") {
const {
browsingContext,
innerWindowID: innerWindowId,
} = watcherActor.browserElement;
await this._spawnActor(browsingContext.id, innerWindowId);
} else if (watcherActor.context.type == "webextension") {
} else if (watcherActor.sessionContext.type == "webextension") {
const {
addonBrowsingContextID,
addonInnerWindowId,
} = watcherActor.context;
} = watcherActor.sessionContext;
await this._spawnActor(addonBrowsingContextID, addonInnerWindowId);
} else {
throw new Error("Unsupported context type=" + watcherActor.context.type);
throw new Error(
"Unsupported session context type=" + watcherActor.sessionContext.type
);
}
}
@ -202,9 +204,9 @@ class ParentProcessStorage {
// If the watcher is bound to one browser element (i.e. a tab), ignore
// windowGlobals related to other browser elements
if (
this.watcherActor.context.type == "browser-element" &&
this.watcherActor.sessionContext.type == "browser-element" &&
windowGlobal.browsingContext.browserId !=
this.watcherActor.context.browserId
this.watcherActor.sessionContext.browserId
) {
return;
}
@ -363,18 +365,21 @@ class StorageActorMock extends EventEmitter {
}
getAllBrowsingContexts() {
if (this.watcherActor.context.type == "browser-element") {
if (this.watcherActor.sessionContext.type == "browser-element") {
const browsingContext = this.watcherActor.browserElement.browsingContext;
return browsingContext
.getAllBrowsingContextsInSubtree()
.filter(x => !!x.currentWindowGlobal);
} else if (this.watcherActor.context.type == "webextension") {
} else if (this.watcherActor.sessionContext.type == "webextension") {
return [
BrowsingContext.get(this.watcherActor.context.addonBrowsingContextID),
BrowsingContext.get(
this.watcherActor.sessionContext.addonBrowsingContextID
),
];
}
throw new Error(
"Unsupported context type=" + this.watcherActor.context.type
"Unsupported session context type=" +
this.watcherActor.sessionContext.type
);
}
@ -398,7 +403,7 @@ class StorageActorMock extends EventEmitter {
}
get parentActor() {
return { isRootActor: this.watcherActor.context.type == "all" };
return { isRootActor: this.watcherActor.sessionContext.type == "all" };
}
/**
@ -409,8 +414,9 @@ class StorageActorMock extends EventEmitter {
// If the watcher is bound to one browser element (i.e. a tab), ignore
// updates related to other browser elements
if (
this.watcherActor.context.type == "browser-element" &&
subject.browsingContext.browserId != this.watcherActor.context.browserId
this.watcherActor.sessionContext.type == "browser-element" &&
subject.browsingContext.browserId !=
this.watcherActor.sessionContext.browserId
) {
return;
}

Просмотреть файл

@ -101,7 +101,7 @@ const TargetConfigurationActor = ActorClassWithSpec(targetConfigurationSpec, {
_shouldHandleConfigurationInParentProcess() {
// Only handle parent process configuration if the watcherActor is tied to a
// browser element (i.e. we're *not* in the Browser Toolbox)
return this.watcherActor.context.type == "browser-element";
return this.watcherActor.sessionContext.type == "browser-element";
},
/**
@ -123,8 +123,8 @@ const TargetConfigurationActor = ActorClassWithSpec(targetConfigurationSpec, {
// If the watcher is bound to one browser element (i.e. a tab), ignore
// updates related to other browser elements
if (
this.watcherActor.context.type == "browser-element" &&
browsingContext.browserId != this.watcherActor.context.browserId
this.watcherActor.sessionContext.type == "browser-element" &&
browsingContext.browserId != this.watcherActor.sessionContext.browserId
) {
return;
}

Просмотреть файл

@ -35,18 +35,18 @@ var TargetActorRegistry = {
},
/**
* Return the first target actor matching the passed watcher's context. Returns null if
* Return the first target actor matching the passed watcher's session context. Returns null if
* no matching target actors could be found.
*
* @param {Object} context: WatcherActor's context. To only retrieve targets related
* @param {Object} sessionContext: WatcherActor's session context. To only retrieve targets related
* to the scope of this watcher actor.
* See watcher actor constructor for more info.
* @param {String} connectionPrefix: DevToolsServerConnection's prefix, in order to select only actor
* related to the same connection. i.e. the same client.
* @returns {TargetActor|null}
*/
getTopLevelTargetActorForContext(context, connectionPrefix) {
if (context.type == "all") {
getTopLevelTargetActorForContext(sessionContext, connectionPrefix) {
if (sessionContext.type == "all") {
if (
Services.appinfo.processType === Services.appinfo.PROCESS_TYPE_DEFAULT
) {
@ -56,21 +56,21 @@ var TargetActorRegistry = {
return xpcShellTargetActor;
}
const actors = this.getTargetActors(context, connectionPrefix);
const actors = this.getTargetActors(sessionContext, connectionPrefix);
// In theory, there should be only one actor here.
return actors[0];
}
return null;
} else if (
context.type == "browser-element" ||
context.type == "webextension"
sessionContext.type == "browser-element" ||
sessionContext.type == "webextension"
) {
const actors = this.getTargetActors(context, connectionPrefix);
const actors = this.getTargetActors(sessionContext, connectionPrefix);
return actors.find(actor => {
return actor.isTopLevelTarget;
});
}
throw new Error("Unsupported context type: " + context.type);
throw new Error("Unsupported session context type: " + sessionContext.type);
},
/**
@ -78,22 +78,24 @@ var TargetActorRegistry = {
* In some scenarios, the registry can have multiple target actors for a given
* browserId (e.g. the regular DevTools content toolbox + DevTools WebExtensions targets).
*
* @param {Object} context: WatcherActor's context. To only retrieve targets related
* @param {Object} sessionContext: WatcherActor's session context. To only retrieve targets related
* to the scope of this watcher actor.
* See watcher actor constructor for more info.
* @param {String} connectionPrefix: DevToolsServerConnection's prefix, in order to select only actor
* related to the same connection. i.e. the same client.
* @returns {Array<TargetActor>}
*/
getTargetActors(context, connectionPrefix) {
getTargetActors(sessionContext, connectionPrefix) {
const actors = [];
for (const actor of windowGlobalTargetActors) {
const isMatchingPrefix = actor.actorID.startsWith(connectionPrefix);
const isMatchingContext =
(context.type == "all" && actor.typeName === "parentProcessTarget") ||
(context.type == "browser-element" &&
actor.browserId == context.browserId) ||
(context.type == "webextension" && actor.addonId == context.addonId);
(sessionContext.type == "all" &&
actor.typeName === "parentProcessTarget") ||
(sessionContext.type == "browser-element" &&
actor.browserId == sessionContext.browserId) ||
(sessionContext.type == "webextension" &&
actor.addonId == sessionContext.addonId);
if (isMatchingPrefix && isMatchingContext) {
actors.push(actor);
}

Просмотреть файл

@ -897,7 +897,7 @@ function hasStyleSheetWatcherSupportForTarget(targetActor) {
sessionDataByWatcherActor.values()
).find(sessionData => {
const actors = TargetActorRegistry.getTargetActors(
sessionData.context,
sessionData.sessionContext,
sessionData.connectionPrefix
);
return actors.includes(targetActor);

Просмотреть файл

@ -73,33 +73,33 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
*
* @param {DevToolsServerConnection} conn
* The connection to use in order to communicate back to the client.
* @param {Object} context
* @param {Object} sessionContext
* Mandatory argument to define the debugged context of this actor.
* Note that as this object is passed to other processes and thread,
* this should be a serializable object.
* @param {String} context.type: The type of debugged context.
* @param {String} sessionContext.type: The type of debugged context.
* Can be:
* - "all", to debug everything in the browser.
* - "browser-element", to focus on one given <browser> element
* and all its children resources (workers, iframes,...)
* @param {Number} context.browserId: If this is a "browser-element" context type,
* @param {Number} sessionContext.browserId: If this is a "browser-element" context type,
* the "browserId" of the <browser> element we would like to debug.
* @param {Object|null} config: Optional configuration object.
* @param {Boolean} config.isServerTargetSwitchingEnabled: Flag to to know if we should
* spawn new top level targets for the debugged context.
*/
initialize: function(conn, context, config = {}) {
initialize: function(conn, sessionContext, config = {}) {
protocol.Actor.prototype.initialize.call(this, conn);
this._context = context;
if (context.type == "browser-element") {
this._sessionContext = sessionContext;
if (sessionContext.type == "browser-element") {
// Retrieve the <browser> element for the given browser ID
const browsingContext = BrowsingContext.getCurrentTopByBrowserId(
context.browserId
sessionContext.browserId
);
if (!browsingContext) {
throw new Error(
"Unable to retrieve the <browser> element for browserId=" +
context.browserId
sessionContext.browserId
);
}
this._browserElement = browsingContext.embedderElement;
@ -129,8 +129,8 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
this.notifyResourceUpdated = this.notifyResourceUpdated.bind(this);
},
get context() {
return this._context;
get sessionContext() {
return this._sessionContext;
},
/**
@ -149,14 +149,16 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
* Helper to know if the context we are debugging has been already destroyed
*/
isContextDestroyed() {
if (this.context.type == "browser-element") {
if (this.sessionContext.type == "browser-element") {
return !this.browserElement.browsingContext;
} else if (this.context.type == "webextension") {
return !BrowsingContext.get(this.context.addonBrowsingContextID);
} else if (this.context.type == "all") {
} else if (this.sessionContext.type == "webextension") {
return !BrowsingContext.get(this.sessionContext.addonBrowsingContextID);
} else if (this.sessionContext.type == "all") {
return false;
}
throw new Error("Unsupported context type: " + this.context.type);
throw new Error(
"Unsupported session context type: " + this.sessionContext.type
);
},
get isServerTargetSwitchingEnabled() {
@ -189,14 +191,14 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
form() {
// All target types and all resources types are supported for tab debugging and web extensions.
// But worker target type and most watcher classes are still disabled for the browser toolbox (context.type=all).
// But worker target type and most watcher classes are still disabled for the browser toolbox (sessionContext.type=all).
// And they may also be disabled for workers once we start supporting them by the watcher.
//
// So keep the traits to false for all the resources that we don't support yet
// and keep using the legacy listeners.
const shouldEnableAllWatchers =
this.context.type == "browser-element" ||
this.context.type == "webextension";
this.sessionContext.type == "browser-element" ||
this.sessionContext.type == "webextension";
return {
actor: this.actorID,
@ -310,7 +312,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
this._currentWindowGlobalTargets.set(actor.innerWindowId, actor);
// The top-level is always the same for the browser-toolbox
if (this.context.type == "all") {
if (this.sessionContext.type == "all") {
this.emit("target-available-form", actor);
return;
}
@ -424,21 +426,21 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
* It may contain actor IDs, actor forms, to be manually marshalled by the client.
*/
notifyResourceAvailable(resources) {
if (this.context.type == "webextension") {
if (this.sessionContext.type == "webextension") {
this._overrideResourceBrowsingContextForWebExtension(resources);
}
this._emitResourcesForm("resource-available-form", resources);
},
notifyResourceDestroyed(resources) {
if (this.context.type == "webextension") {
if (this.sessionContext.type == "webextension") {
this._overrideResourceBrowsingContextForWebExtension(resources);
}
this._emitResourcesForm("resource-destroyed-form", resources);
},
notifyResourceUpdated(resources) {
if (this.context.type == "webextension") {
if (this.sessionContext.type == "webextension") {
this._overrideResourceBrowsingContextForWebExtension(resources);
}
this._emitResourcesForm("resource-updated-form", resources);
@ -466,7 +468,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
*/
_overrideResourceBrowsingContextForWebExtension(resources) {
resources.forEach(resource => {
resource.browsingContextID = this.context.addonBrowsingContextID;
resource.browsingContextID = this.sessionContext.addonBrowsingContextID;
});
},
@ -482,7 +484,7 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
// Note: For browser-element debugging, the WindowGlobalTargetActor returned here is created
// for a parent process page and lives in the parent process.
return TargetActorRegistry.getTopLevelTargetActorForContext(
this.context,
this.sessionContext,
this.conn.prefix
);
},

Просмотреть файл

@ -41,7 +41,7 @@ const { SUPPORTED_DATA } = SessionDataHelpers;
// It is keyed by WatcherActor ID and values contains following attributes:
// - targets: Set of strings, refering to target types to be listened to
// - resources: Set of strings, refering to resource types to be observed
// - context: WatcherActor's context. Describe what the watcher should be debugging.
// - sessionContext: WatcherActor's session context. Describe what the watcher should be debugging.
// See watcher actor constructor for more info.
// - connectionPrefix: The DevToolsConnection prefix of the watcher actor. Used to compute new actor ID in the content processes.
//
@ -109,9 +109,9 @@ const WatcherRegistry = {
let sessionData = sessionDataByWatcherActor.get(watcherActorID);
if (!sessionData && createData) {
sessionData = {
// The "context" object help understand what should be debugged and which target should be created.
// The "session context" object help understand what should be debugged and which target should be created.
// See WatcherActor constructor for more info.
context: watcher.context,
sessionContext: watcher.sessionContext,
// The DevToolsServerConnection prefix will be used to compute actor IDs created in the content process
connectionPrefix: watcher.conn.prefix,
// Expose watcher traits so we can retrieve them in content process.
@ -152,8 +152,8 @@ const WatcherRegistry = {
const watchers = [];
for (const watcherActor of watcherActors.values()) {
if (
watcherActor.context.type == "browser-element" &&
watcherActor.context.browserId === browserId
watcherActor.sessionContext.type == "browser-element" &&
watcherActor.sessionContext.browserId === browserId
) {
watchers.push(watcherActor);
}

Просмотреть файл

@ -39,7 +39,7 @@ async function createTargets(watcher) {
// TODO: We should also set the flag for the "parent process" browsing context when we're
// in the browser toolbox. This is blocked by Bug 1675763, and should be handled as part
// of Bug 1709529.
if (watcher.context.type == "browser-element") {
if (watcher.sessionContext.type == "browser-element") {
// The `watchedByDevTools` enables gecko behavior tied to this flag, such as:
// - reporting the contents of HTML loaded in the docshells
// - capturing stacks for the network monitor.
@ -49,7 +49,7 @@ async function createTargets(watcher) {
if (!browsingContextAttachedObserverByWatcher.has(watcher)) {
// We store the browserId here as watcher.browserElement.browserId can momentary be
// set to 0 when there's a navigation to a new browsing context.
const browserId = watcher.context.browserId;
const browserId = watcher.sessionContext.browserId;
const onBrowsingContextAttached = browsingContext => {
// We want to set watchedByDevTools on new top-level browsing contexts:
// - in the case of the BrowserToolbox/BrowserConsole, that would be the browsing
@ -59,7 +59,7 @@ async function createTargets(watcher) {
// Then BrowsingContext will propagate to all the tree of children BrowsingContext's.
if (
!browsingContext.parent &&
(watcher.context.type != "browser-element" ||
(watcher.sessionContext.type != "browser-element" ||
browserId === browsingContext.browserId)
) {
browsingContext.watchedByDevTools = true;
@ -134,7 +134,7 @@ async function createTargetForBrowsingContext({
.instantiateTarget({
watcherActorID: watcher.actorID,
connectionPrefix: watcher.conn.prefix,
context: watcher.context,
sessionContext: watcher.sessionContext,
sessionData: watcher.sessionData,
});
} catch (e) {
@ -170,7 +170,7 @@ function destroyTargets(watcher) {
);
if (
watcher.isServerTargetSwitchingEnabled &&
watcher.context.type == "browser-element"
watcher.sessionContext.type == "browser-element"
) {
// If server side target switching is enabled, we should also destroy the top level browsing context.
// If it is disabled, the top level target will be destroyed from the client instead.
@ -191,11 +191,11 @@ function destroyTargets(watcher) {
.getActor("DevToolsFrame")
.destroyTarget({
watcherActorID: watcher.actorID,
context: watcher.context,
sessionContext: watcher.sessionContext,
});
}
if (watcher.context.type == "browser-element") {
if (watcher.sessionContext.type == "browser-element") {
watcher.browserElement.browsingContext.watchedByDevTools = false;
}
@ -231,7 +231,7 @@ async function addSessionDataEntry({ watcher, type, entries }) {
.getActor("DevToolsFrame")
.addSessionDataEntry({
watcherActorID: watcher.actorID,
context: watcher.context,
sessionContext: watcher.sessionContext,
type,
entries,
});
@ -258,7 +258,7 @@ function removeSessionDataEntry({ watcher, type, entries }) {
.getActor("DevToolsFrame")
.removeSessionDataEntry({
watcherActorID: watcher.actorID,
context: watcher.context,
sessionContext: watcher.sessionContext,
type,
entries,
});
@ -294,15 +294,15 @@ function getWatchingBrowsingContexts(watcher) {
// Even if we aren't watching additional target, we want to process the top level target.
// The top level target isn't returned by getFilteredRemoteBrowsingContext, so add it in both cases.
if (
watcher.context.type == "browser-element" ||
watcher.context.type == "webextension"
watcher.sessionContext.type == "browser-element" ||
watcher.sessionContext.type == "webextension"
) {
let topBrowsingContext;
if (watcher.context.type == "browser-element") {
if (watcher.sessionContext.type == "browser-element") {
topBrowsingContext = watcher.browserElement.browsingContext;
} else if (watcher.context.type == "webextension") {
} else if (watcher.sessionContext.type == "webextension") {
topBrowsingContext = BrowsingContext.get(
watcher.context.addonBrowsingContextID
watcher.sessionContext.addonBrowsingContextID
);
}

Просмотреть файл

@ -29,7 +29,7 @@ async function createTargets(watcher) {
.instantiateWorkerTargets({
watcherActorID: watcher.actorID,
connectionPrefix: watcher.conn.prefix,
context: watcher.context,
sessionContext: watcher.sessionContext,
sessionData: watcher.sessionData,
});
promises.push(promise);
@ -61,7 +61,7 @@ async function destroyTargets(watcher) {
windowActor.destroyWorkerTargets({
watcherActorID: watcher.actorID,
context: watcher.context,
sessionContext: watcher.sessionContext,
});
}
}
@ -84,7 +84,7 @@ async function addSessionDataEntry({ watcher, type, entries }) {
.getActor(DEVTOOLS_WORKER_JS_WINDOW_ACTOR_NAME)
.addSessionDataEntry({
watcherActorID: watcher.actorID,
context: watcher.context,
sessionContext: watcher.sessionContext,
type,
entries,
});
@ -106,7 +106,7 @@ function removeSessionDataEntry({ watcher, type, entries }) {
.getActor(DEVTOOLS_WORKER_JS_WINDOW_ACTOR_NAME)
.removeSessionDataEntry({
watcherActorID: watcher.actorID,
context: watcher.context,
sessionContext: watcher.sessionContext,
type,
entries,
});

Просмотреть файл

@ -39,7 +39,7 @@ const SHARED_DATA_KEY_NAME = "DevTools:watchedPerWatcher";
*/
function shouldNotifyWindowGlobal(
windowGlobal,
context,
sessionContext,
{ acceptTopLevelTarget = false }
) {
const browsingContext = windowGlobal.browsingContext;
@ -72,8 +72,8 @@ function shouldNotifyWindowGlobal(
// If we are focusing only on a sub-tree of Browsing Element,
// Ignore the out of the sub tree elements.
if (
context.type == "browser-element" &&
browsingContext.browserId != context.browserId
sessionContext.type == "browser-element" &&
browsingContext.browserId != sessionContext.browserId
) {
return false;
}
@ -89,7 +89,7 @@ function shouldNotifyWindowGlobal(
// or when navigating to and from pages in the bfcache
if (
!acceptTopLevelTarget &&
context.type == "browser-element" &&
sessionContext.type == "browser-element" &&
!browsingContext.parent
) {
return false;
@ -179,7 +179,7 @@ class DevToolsFrameChild extends JSWindowActorChild {
for (const [watcherActorID, sessionData] of sessionDataByWatcherActor) {
const {
connectionPrefix,
context,
sessionContext,
isServerTargetSwitchingEnabled,
} = sessionData;
// Always create new targets when server targets are enabled as we create targets for all the WindowGlobal's,
@ -192,7 +192,7 @@ class DevToolsFrameChild extends JSWindowActorChild {
(isBFCache && this.isBfcacheInParentEnabled);
if (
sessionData.targets.includes("frame") &&
shouldNotifyWindowGlobal(this.manager, context, {
shouldNotifyWindowGlobal(this.manager, sessionContext, {
acceptTopLevelTarget,
})
) {
@ -208,7 +208,7 @@ class DevToolsFrameChild extends JSWindowActorChild {
// - in such case we weren't seeing the issue of Bug 1721398 (the old target can't access the new document)
const existingTarget = this._findTargetActor({
watcherActorID,
context,
sessionContext,
browsingContextId: this.manager.browsingContext.id,
});
@ -319,7 +319,7 @@ class DevToolsFrameChild extends JSWindowActorChild {
const browsingContext = this.manager.browsingContext;
const isTopLevelTarget =
!browsingContext.parent &&
browsingContext.browserId == sessionData.context.browserId;
browsingContext.browserId == sessionData.sessionContext.browserId;
const { connection, targetActor } = this._createConnectionAndActor(
forwardingPrefix,
@ -490,9 +490,9 @@ class DevToolsFrameChild extends JSWindowActorChild {
// and are expected to match shouldNotifyWindowGlobal result.
if (
message.name != "DevToolsFrameParent:packet" &&
message.data.context.type == "browser-element"
message.data.sessionContext.type == "browser-element"
) {
const { browserId } = message.data.context;
const { browserId } = message.data.sessionContext;
// Re-check here, just to ensure that both parent and content processes agree
// on what should or should not be watched.
if (
@ -525,19 +525,19 @@ class DevToolsFrameChild extends JSWindowActorChild {
return this._destroyTargetActor(watcherActorID);
}
case "DevToolsFrameParent:addSessionDataEntry": {
const { watcherActorID, context, type, entries } = message.data;
const { watcherActorID, sessionContext, type, entries } = message.data;
return this._addSessionDataEntry(
watcherActorID,
context,
sessionContext,
type,
entries
);
}
case "DevToolsFrameParent:removeSessionDataEntry": {
const { watcherActorID, context, type, entries } = message.data;
const { watcherActorID, sessionContext, type, entries } = message.data;
return this._removeSessionDataEntry(
watcherActorID,
context,
sessionContext,
type,
entries
);
@ -560,13 +560,13 @@ class DevToolsFrameChild extends JSWindowActorChild {
*
* @param {Object} options
* @param {Object} options.watcherActorID
* @param {Object} options.context
* @param {Object} options.sessionContext
* @param {Object} options.browsingContextId: Optional browsing context id to narrow the
* search to a specific browsing context.
*
* @returns {WindowGlobalTargetActor|null}
*/
_findTargetActor({ watcherActorID, context, browsingContextId }) {
_findTargetActor({ watcherActorID, sessionContext, browsingContextId }) {
// First let's check if a target was created for this watcher actor in this specific
// DevToolsFrameChild instance.
const connectionInfo = this._connections.get(watcherActorID);
@ -580,19 +580,19 @@ class DevToolsFrameChild extends JSWindowActorChild {
// This might be the case if we're navigating to a new page with server side target
// enabled and we want to retrieve the target of the page we're navigating from.
const isMatchingBrowserElement =
this.manager.browsingContext.browserId == context.browserId;
this.manager.browsingContext.browserId == sessionContext.browserId;
const isMatchingWebExtension =
this.document.nodePrincipal.addonId == context.addonId;
this.document.nodePrincipal.addonId == sessionContext.addonId;
if (
(context.type == "browser-element" && isMatchingBrowserElement) ||
(context.type == "webextension" && isMatchingWebExtension)
(sessionContext.type == "browser-element" && isMatchingBrowserElement) ||
(sessionContext.type == "webextension" && isMatchingWebExtension)
) {
// Ensure retrieving the one target actor related to this connection.
// This allows to distinguish actors created for various toolboxes.
// For ex, regular toolbox versus browser console versus browser toolbox
const connectionPrefix = watcherActorID.replace(/watcher\d+$/, "");
const targetActors = TargetActorRegistry.getTargetActors(
context,
sessionContext,
connectionPrefix
);
@ -606,30 +606,30 @@ class DevToolsFrameChild extends JSWindowActorChild {
return null;
}
_addSessionDataEntry(watcherActorID, context, type, entries) {
_addSessionDataEntry(watcherActorID, sessionContext, type, entries) {
// /!\ We may have an issue here as there could be multiple targets for a given
// (watcherActorID,browserId) pair.
// This should be clarified as part of Bug 1725623.
const targetActor = this._findTargetActor({
watcherActorID,
context,
sessionContext,
});
if (!targetActor) {
throw new Error(
`No target actor for this Watcher Actor ID:"${watcherActorID}" / BrowserId:${context.browserId}`
`No target actor for this Watcher Actor ID:"${watcherActorID}" / BrowserId:${sessionContext.browserId}`
);
}
return targetActor.addSessionDataEntry(type, entries);
}
_removeSessionDataEntry(watcherActorID, context, type, entries) {
_removeSessionDataEntry(watcherActorID, sessionContext, type, entries) {
// /!\ We may have an issue here as there could be multiple targets for a given
// (watcherActorID,browserId) pair.
// This should be clarified as part of Bug 1725623.
const targetActor = this._findTargetActor({
watcherActorID,
context,
sessionContext,
});
// By the time we are calling this, the target may already have been destroyed.
if (targetActor) {
@ -711,14 +711,14 @@ class DevToolsFrameChild extends JSWindowActorChild {
// It may not be the case if one Watcher isn't having server target switching enabled.
let allActorsAreDestroyed = true;
for (const [watcherActorID, sessionData] of sessionDataByWatcherActor) {
const { context, isServerTargetSwitchingEnabled } = sessionData;
const { sessionContext, isServerTargetSwitchingEnabled } = sessionData;
// /!\ We may have an issue here as there could be multiple targets for a given
// (watcherActorID,browserId) pair.
// This should be clarified as part of Bug 1725623.
const existingTarget = this._findTargetActor({
watcherActorID,
context,
sessionContext,
});
if (!existingTarget) {

Просмотреть файл

@ -57,32 +57,32 @@ class DevToolsFrameParent extends JSWindowActorParent {
async instantiateTarget({
watcherActorID,
connectionPrefix,
context,
sessionContext,
sessionData,
}) {
await this.sendQuery("DevToolsFrameParent:instantiate-already-available", {
watcherActorID,
connectionPrefix,
context,
sessionContext,
sessionData,
});
}
destroyTarget({ watcherActorID, context }) {
destroyTarget({ watcherActorID, sessionContext }) {
this.sendAsyncMessage("DevToolsFrameParent:destroy", {
watcherActorID,
context,
sessionContext,
});
}
/**
* Communicate to the content process that some data have been added.
*/
async addSessionDataEntry({ watcherActorID, context, type, entries }) {
async addSessionDataEntry({ watcherActorID, sessionContext, type, entries }) {
try {
await this.sendQuery("DevToolsFrameParent:addSessionDataEntry", {
watcherActorID,
context,
sessionContext,
type,
entries,
});
@ -98,10 +98,10 @@ class DevToolsFrameParent extends JSWindowActorParent {
/**
* Communicate to the content process that some data have been removed.
*/
removeSessionDataEntry({ watcherActorID, context, type, entries }) {
removeSessionDataEntry({ watcherActorID, sessionContext, type, entries }) {
this.sendAsyncMessage("DevToolsFrameParent:removeSessionDataEntry", {
watcherActorID,
context,
sessionContext,
type,
entries,
});

Просмотреть файл

@ -119,10 +119,10 @@ class DevToolsWorkerChild extends JSWindowActorChild {
// Create one Target actor for each prefix/client which listen to workers
for (const [watcherActorID, sessionData] of sessionDataByWatcherActor) {
const { targets, connectionPrefix, context } = sessionData;
const { targets, connectionPrefix, sessionContext } = sessionData;
if (
targets.includes("worker") &&
shouldNotifyWindowGlobal(this.manager, context)
shouldNotifyWindowGlobal(this.manager, sessionContext)
) {
this._watchWorkerTargets({
watcherActorID,
@ -141,15 +141,15 @@ class DevToolsWorkerChild extends JSWindowActorChild {
* @param {*} message.data
*/
receiveMessage(message) {
// All messages pass `context` (except packet) and are expected
// All messages pass `sessionContext` (except packet) and are expected
// to match shouldNotifyWindowGlobal result.
if (message.name != "DevToolsWorkerParent:packet") {
const { browserId } = message.data.context;
const { browserId } = message.data.sessionContext;
// Re-check here, just to ensure that both parent and content processes agree
// on what should or should not be watched.
if (
this.manager.browsingContext.browserId != browserId &&
!shouldNotifyWindowGlobal(this.manager, message.data.context)
!shouldNotifyWindowGlobal(this.manager, message.data.sessionContext)
) {
throw new Error(
"Mismatch between DevToolsWorkerParent and DevToolsWorkerChild " +
@ -527,14 +527,14 @@ class DevToolsWorkerChild extends JSWindowActorChild {
/**
* Helper function to know if we should watch for workers on a given windowGlobal
*/
function shouldNotifyWindowGlobal(windowGlobal, context) {
function shouldNotifyWindowGlobal(windowGlobal, sessionContext) {
const browsingContext = windowGlobal.browsingContext;
// If we are focusing only on a sub-tree of Browsing Element, ignore elements that are
// not part of it.
if (
context.type == "browser-element" &&
browsingContext.browserId != context.browserId
sessionContext.type == "browser-element" &&
browsingContext.browserId != sessionContext.browserId
) {
return false;
}

Просмотреть файл

@ -56,7 +56,7 @@ class DevToolsWorkerParent extends JSWindowActorParent {
async instantiateWorkerTargets({
watcherActorID,
connectionPrefix,
context,
sessionContext,
sessionData,
}) {
try {
@ -65,7 +65,7 @@ class DevToolsWorkerParent extends JSWindowActorParent {
{
watcherActorID,
connectionPrefix,
context,
sessionContext,
sessionData,
}
);
@ -80,21 +80,21 @@ class DevToolsWorkerParent extends JSWindowActorParent {
}
}
destroyWorkerTargets({ watcherActorID, context }) {
destroyWorkerTargets({ watcherActorID, sessionContext }) {
return this.sendAsyncMessage("DevToolsWorkerParent:destroy", {
watcherActorID: watcherActorID,
context,
sessionContext,
});
}
/**
* Communicate to the content process that some data have been added.
*/
async addSessionDataEntry({ watcherActorID, context, type, entries }) {
async addSessionDataEntry({ watcherActorID, sessionContext, type, entries }) {
try {
await this.sendQuery("DevToolsWorkerParent:addSessionDataEntry", {
watcherActorID,
context,
sessionContext,
type,
entries,
});
@ -112,10 +112,10 @@ class DevToolsWorkerParent extends JSWindowActorParent {
/**
* Communicate to the content process that some data have been removed.
*/
removeSessionDataEntry({ watcherActorID, context, type, entries }) {
removeSessionDataEntry({ watcherActorID, sessionContext, type, entries }) {
this.sendAsyncMessage("DevToolsWorkerParent:removeSessionDataEntry", {
watcherActorID,
context,
sessionContext,
type,
entries,
});