Bug 1745238 - [devtools] Use context in NetworkEventActor to know if we are debugging a tab. r=nchevobbe

This is more reliable check and it feels more common type of check
we already do elsewhere.
It also helps expose less convoluted objects to NetworkEventActor and so simplify it.

Differential Revision: https://phabricator.services.mozilla.com/D133474
This commit is contained in:
Alexandre Poirot 2021-12-22 13:17:12 +00:00
Родитель 2435b208e5
Коммит f1d437953a
3 изменённых файлов: 26 добавлений и 28 удалений

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

@ -16,8 +16,11 @@ const { LongStringActor } = require("devtools/server/actors/string");
* Creates an actor for a network event.
*
* @constructor
* @param object networkEventWatcher
* The parent NetworkEventWatcher instance for this object.
* @param DevToolsServerConnection conn
* The connection into which this Actor will be added.
* @param object sessionContext
* WatcherActor's session context. This helps know what is the overall debugged scope.
* See watcher actor constructor for more info.
* @param object options
* Dictionary object with the following attributes:
* - onNetworkEventUpdate: optional function
@ -25,12 +28,13 @@ const { LongStringActor } = require("devtools/server/actors/string");
*/
const NetworkEventActor = protocol.ActorClassWithSpec(networkEventSpec, {
initialize(
networkEventWatcher,
conn,
sessionContext,
{ onNetworkEventUpdate, onNetworkEventDestroy },
networkEvent
) {
this._networkEventWatcher = networkEventWatcher;
this._conn = networkEventWatcher.conn;
this._sessionContext = sessionContext;
this._conn = conn;
this._onNetworkEventUpdate = onNetworkEventUpdate;
this._onNetworkEventDestroy = onNetworkEventDestroy;
@ -98,9 +102,9 @@ const NetworkEventActor = protocol.ActorClassWithSpec(networkEventSpec, {
* Returns a grip for this actor.
*/
asResource() {
// Ensure that we have a browsing context ID for all requests when debugging a tab (=`browserId` is defined).
// Only privileged requests debugged via the Browser Toolbox (=`browserId` null) can be unrelated to any browsing context.
if (!this._browsingContextID && this._networkEventWatcher.browserId) {
// Ensure that we have a browsing context ID for all requests.
// Only privileged requests debugged via the Browser Toolbox (sessionContext.type == "all") can be unrelated to any browsing context.
if (!this._browsingContextID && this._sessionContext.type != "all") {
throw new Error(
`Got a request ${this._request.url} without a browsingContextID set`
);
@ -109,11 +113,11 @@ const NetworkEventActor = protocol.ActorClassWithSpec(networkEventSpec, {
// The browsingContextID is used by the ResourceCommand on the client
// to find the related Target Front.
//
// For now in the browser toolbox (where watcher.browserId is undefined),
// do not relate requests to any WindowGlobalTargetActor
// For now in the browser and web extension toolboxes, requests
// do not relate to any specific WindowGlobalTargetActor
// as we are still using a unique target (ParentProcessTargetActor) for everything.
const browsingContextID =
this._browsingContextID && this._networkEventWatcher.browserId
this._browsingContextID && this._sessionContext.type == "browser-element"
? this._browsingContextID
: -1;
@ -148,13 +152,11 @@ const NetworkEventActor = protocol.ActorClassWithSpec(networkEventSpec, {
* Releases this actor from the pool.
*/
destroy(conn) {
if (!this._networkEventWatcher) {
if (!this._channelId) {
return;
}
if (this._channelId) {
this._onNetworkEventDestroy(this._channelId);
}
this._networkEventWatcher = null;
this._onNetworkEventDestroy(this._channelId);
this._channelId = null;
protocol.Actor.prototype.destroy.call(this, conn);
},

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

@ -62,10 +62,6 @@ class NetworkEventContentWatcher {
return this.targetActor.conn;
}
get browserId() {
return this.targetActor.browserId;
}
httpFailedOpeningRequest(subject, topic) {
const channel = subject.QueryInterface(Ci.nsIHttpChannel);
@ -89,7 +85,8 @@ class NetworkEventContentWatcher {
});
const actor = new NetworkEventActor(
this,
this.conn,
this.targetActor.sessionContext,
{
onNetworkEventUpdate: this.onNetworkEventUpdated.bind(this),
onNetworkEventDestroy: this.onNetworkEventDestroyed.bind(this),
@ -134,7 +131,8 @@ class NetworkEventContentWatcher {
});
const actor = new NetworkEventActor(
this,
this.conn,
this.targetActor.sessionContext,
{
onNetworkEventUpdate: this.onNetworkEventUpdatedForImageCache.bind(
this

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

@ -61,10 +61,6 @@ class NetworkEventWatcher {
return this.watcherActor.conn;
}
get browserId() {
return this.watcherActor.sessionContext.browserId;
}
/**
* Instruct to keep reference to previous document requests or not.
* If persist is disabled, we will clear all informations about previous document
@ -162,7 +158,8 @@ class NetworkEventWatcher {
// windowGlobals related to other browser elements
if (
this.watcherActor.sessionContext.type == "browser-element" &&
windowGlobal.browsingContext.browserId != this.browserId
windowGlobal.browsingContext.browserId !=
this.watcherActor.sessionContext.browserId
) {
return;
}
@ -212,7 +209,8 @@ class NetworkEventWatcher {
);
}
const actor = new NetworkEventActor(
this,
this.watcherActor.conn,
this.watcherActor.sessionContext,
{
onNetworkEventUpdate: this.onNetworkEventUpdate.bind(this),
onNetworkEventDestroy: this.onNetworkEventDestroy.bind(this),