Bug 1838238 - [bidi] Fix responseCompleted for redirects with browsing context swaps r=webdriver-reviewers,whimboo

Differential Revision: https://phabricator.services.mozilla.com/D180854
This commit is contained in:
Julian Descottes 2023-06-15 20:57:24 +00:00
parent 652ca3486f
commit 91bda90b8a

View File

@ -19,6 +19,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
*/
export class NetworkEventRecord {
#channel;
#contextId;
#fromCache;
#networkListener;
#redirectCount;
@ -45,6 +46,10 @@ export class NetworkEventRecord {
this.#networkListener = networkListener;
// The context ids computed by TabManager have the lifecycle of a navigable
// and can be reused for all the events emitted from this record.
this.#contextId = this.#getContextId();
// The wrappedChannel id remains identical across redirects, whereas
// nsIChannel.channelId is different for each and every request.
this.#requestId = this.#wrappedChannel.id.toString();
@ -223,7 +228,7 @@ export class NetworkEventRecord {
this.#updateDataFromTimedChannel();
this.#networkListener.emit("before-request-sent", {
contextId: this.#getContextId(),
contextId: this.#contextId,
redirectCount: this.#redirectCount,
requestData: this.#requestData,
timestamp: Date.now(),
@ -234,7 +239,7 @@ export class NetworkEventRecord {
this.#updateDataFromTimedChannel();
this.#networkListener.emit("response-completed", {
contextId: this.#getContextId(),
contextId: this.#contextId,
redirectCount: this.#redirectCount,
requestData: this.#requestData,
responseData: this.#responseData,
@ -246,7 +251,7 @@ export class NetworkEventRecord {
this.#updateDataFromTimedChannel();
this.#networkListener.emit("response-started", {
contextId: this.#getContextId(),
contextId: this.#contextId,
redirectCount: this.#redirectCount,
requestData: this.#requestData,
responseData: this.#responseData,
@ -278,9 +283,12 @@ export class NetworkEventRecord {
}
/**
* Retrieve the context id corresponding to the current channel, this could
* change dynamically during a cross group navigation for an iframe, so this
* should always be retrieved dynamically.
* Retrieve the navigable id for the current browsing context associated to
* the requests' channel. Network events are recorded in the parent process
* so we always expect to be able to use TabManager.getIdForBrowsingContext.
*
* @returns {string}
* The navigable id corresponding to the given browsing context.
*/
#getContextId() {
const id = lazy.NetworkUtils.getChannelBrowsingContextID(this.#channel);