Bug 1645334 - Handle parentProcessTargetActor in WatcherActor. r=jdescottes,ochameau.

In order to handle parentProcessTargetActor in the WatcherActor, we modify
TargetActorRegistry.getTargetActor to return the parent process target when
the passed browsing context id is null.

The comment explaining why we need to call getTargetActor in
WatcherActor#watchResources is modified to better summarize the situation.

We also take this as an opportunity to handle those targets in unwatchResources.

Differential Revision: https://phabricator.services.mozilla.com/D79424
This commit is contained in:
Nicolas Chevobbe 2020-06-16 16:37:09 +00:00
Родитель a54fa8e5b4
Коммит 49bb11a38e
2 изменённых файлов: 57 добавлений и 11 удалений

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

@ -185,16 +185,28 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
});
}
// If we are debugging the parent process, we will also have a target actor,
// still using the message manager, running in this process.
// Previous call to watchResources will only go through Browsing Context.
// So that it won't iterate over ParentProcessTargetActor, which:
// * doesn't relate to one Browsing Context
// * still uses process message manager
// * runs in the same process as this Watcher Actor.
const targetActor = TargetActorRegistry.getTargetActor(
this.browsingContextID
);
/*
* The Watcher actor doesn't support watching for targets other than frame targets yet:
* - process targets (bug 1620248)
* - worker targets (bug 1633712)
* - top level tab target (bug 1644397 and possibly some other followup).
*
* Because of that, we miss reaching these targets in the previous lines of this function.
* Since all BrowsingContext target actors register themselves to the TargetActorRegistry,
* we use it here in order to reach those missing targets, which are running in the
* parent process (where this WatcherActor lives as well):
* - the parent process target (which inherits from BrowsingContextTargetActor)
* - top level tab target for documents loaded in the parent process (e.g. about:robots).
* When the tab loads document in the content process, the FrameTargetHelper will
* reach it via the JSWindowActor API. Even if it uses MessageManager for anything
* else (RDP packet forwarding, creation and destruction).
*
* We will eventually get rid of this code once all targets are properly supported by
* the Watcher Actor and we have target helpers for all of them.
*/
const targetActor = this.browsingContextID
? TargetActorRegistry.getTargetActor(this.browsingContextID)
: TargetActorRegistry.getParentProcessTargetActor();
if (targetActor) {
await targetActor.watchTargetResources(resourceTypes);
}
@ -235,6 +247,14 @@ exports.WatcherActor = protocol.ActorClassWithSpec(watcherSpec, {
}
}
// See comment in watchResources.
const targetActor = this.browsingContextID
? TargetActorRegistry.getTargetActor(this.browsingContextID)
: TargetActorRegistry.getParentProcessTargetActor();
if (targetActor) {
targetActor.unwatchTargetResources(resourceTypes);
}
// Unregister the JS Window Actor if there is no more DevTools code observing any target/resource
WatcherRegistry.maybeUnregisteringJSWindowActor();
},

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

@ -23,12 +23,38 @@ var TargetActorRegistry = {
browsingContextTargetActors.delete(targetActor);
},
/**
* Return the target actor matching the passed browsing context id. Returns null if
* no matching target actors could be found.
*
* @param {Integer} browsingContextID
* @returns {TargetActor|null}
*/
getTargetActor(browsingContextID) {
for (const actor of browsingContextTargetActors) {
if (actor.browsingContextID == browsingContextID) {
if (
actor.browsingContextID == browsingContextID ||
(browsingContextID === null && actor.typeName === "parentProcessTarget")
) {
return actor;
}
}
return null;
},
/**
* Return the parent process target actor. Returns null if it couldn't be found.
*
* @param {Integer} browsingContextID
* @returns {TargetActor|null}
*/
getParentProcessTargetActor() {
for (const actor of browsingContextTargetActors) {
if (actor.typeName === "parentProcessTarget") {
return actor;
}
}
return null;
},
};