Bug 1642470 - Use BrowsingContext ID instead of outerWindowID to filter out netmonitor requests. r=bomsy,Honza

OuterWindow ID is deprecated in a Fission world and we should rather use Browsing Context ID.
The outer window ID will change when navigating to another origin, loaded in a distinct process,
whereas Browsing Context ID will stay the same.

Differential Revision: https://phabricator.services.mozilla.com/D78253
This commit is contained in:
Alexandre Poirot 2020-06-04 15:01:47 +00:00
Родитель 9e9b45920a
Коммит 9812cc0c61
4 изменённых файлов: 15 добавлений и 18 удалений

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

@ -29,7 +29,7 @@ const NetworkMonitorActor = ActorClassWithSpec(networkMonitorSpec, {
* parent process. * parent process.
* *
* @param object filters * @param object filters
* Contains an `outerWindowID` attribute when this is used across processes. * Contains an `browsingContextID` attribute when this is used across processes.
* Or a `window` attribute when instanciated in the same process. * Or a `window` attribute when instanciated in the same process.
* @param number parentID (optional) * @param number parentID (optional)
* To be removed, specify the ID of the Web console actor. * To be removed, specify the ID of the Web console actor.

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

@ -69,7 +69,7 @@ const HTTP_TEMPORARY_REDIRECT = 307;
*/ */
function matchRequest(channel, filters) { function matchRequest(channel, filters) {
// Log everything if no filter is specified // Log everything if no filter is specified
if (!filters.outerWindowID && !filters.window) { if (!filters.browsingContextID && !filters.window) {
return true; return true;
} }
@ -109,24 +109,17 @@ function matchRequest(channel, filters) {
} }
} }
if (filters.outerWindowID) { if (filters.browsingContextID) {
const topFrame = NetworkHelper.getTopFrameForRequest(channel); const topFrame = NetworkHelper.getTopFrameForRequest(channel);
// topFrame is typically null for some chrome requests like favicons // topFrame is typically null for some chrome requests like favicons
if (topFrame) { if (topFrame && topFrame.browsingContext.id == filters.browsingContextID) {
try { return true;
if (topFrame.outerWindowID == filters.outerWindowID) {
return true;
}
} catch (e) {
// outerWindowID getter from browser.js (non-remote <xul:browser>) may
// throw when closing a tab while resources are still loading.
}
} else if ( } else if (
channel.loadInfo && channel.loadInfo &&
channel.loadInfo.topOuterWindowID == filters.outerWindowID channel.loadInfo.browsingContext.id == filters.browsingContextID
) { ) {
// If we couldn't get the top frame outerWindowID from the loadContext, // If we couldn't get the top frame BrowsingContext from the loadContext,
// look to the channel.loadInfo.topOuterWindowID instead. // look for it on channel.loadInfo instead.
return true; return true;
} }
} }
@ -146,7 +139,7 @@ exports.matchRequest = matchRequest;
* Object with the filters to use for network requests: * Object with the filters to use for network requests:
* - window (nsIDOMWindow): filter network requests by the associated * - window (nsIDOMWindow): filter network requests by the associated
* window object. * window object.
* - outerWindowID (number): filter requests by their top frame's outerWindowID. * - browsingContextID (number): filter requests by their top frame's BrowsingContext.
* Filters are optional. If any of these filters match the request is * Filters are optional. If any of these filters match the request is
* logged (OR is applied). If no filter is provided then all requests are * logged (OR is applied). If no filter is provided then all requests are
* logged. * logged.

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

@ -399,6 +399,10 @@ const browsingContextTargetPrototype = {
return null; return null;
}, },
get browsingContextID() {
return this.docShell && this.docShell.browsingContext.id;
},
/** /**
* Getter for the WebExtensions ContentScript globals related to the * Getter for the WebExtensions ContentScript globals related to the
* browsing context's current DOM window. * browsing context's current DOM window.
@ -505,7 +509,7 @@ const browsingContextTargetPrototype = {
const response = { const response = {
actor: this.actorID, actor: this.actorID,
browsingContextID: this.docShell.browsingContext.id, browsingContextID: this.browsingContextID,
traits: { traits: {
// FF64+ exposes a new trait to help identify BrowsingContextActor's inherited // FF64+ exposes a new trait to help identify BrowsingContextActor's inherited
// actorss from the client side. // actorss from the client side.

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

@ -701,7 +701,7 @@ const WebConsoleActor = ActorClassWithSpec(webconsoleSpec, {
"devtools/server/actors/network-monitor/network-monitor", "devtools/server/actors/network-monitor/network-monitor",
constructor: "NetworkMonitorActor", constructor: "NetworkMonitorActor",
args: [ args: [
{ outerWindowID: this.parentActor.outerWindowID }, { browsingContextID: this.parentActor.browsingContextID },
this.actorID, this.actorID,
], ],
}); });