mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-07 18:04:46 +00:00
Bug 1756619 - [bidi] Implement "browsingContext.load" event. r=webdriver-reviewers,jdescottes,whimboo
Differential Revision: https://phabricator.services.mozilla.com/D155820
This commit is contained in:
parent
d94a74f52d
commit
c9433699f7
@ -32,7 +32,7 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
* ```
|
||||
*
|
||||
* @emits message
|
||||
* The LoadListener emits "DOMContentLoaded" events,
|
||||
* The LoadListener emits "DOMContentLoaded" and "load" events,
|
||||
* with the following object as payload:
|
||||
* - {Document} target
|
||||
* The target document.
|
||||
@ -72,6 +72,11 @@ class LoadListener {
|
||||
signal: this.#abortController.signal,
|
||||
}
|
||||
);
|
||||
|
||||
this.#window.addEventListener("load", this.#onLoad, {
|
||||
mozSystemGroup: true,
|
||||
signal: this.#abortController.signal,
|
||||
});
|
||||
}
|
||||
|
||||
stopListening() {
|
||||
@ -86,4 +91,8 @@ class LoadListener {
|
||||
#onDOMContentLoaded = event => {
|
||||
this.emit("DOMContentLoaded", { target: event.target });
|
||||
};
|
||||
|
||||
#onLoad = event => {
|
||||
this.emit("load", { target: event.target });
|
||||
};
|
||||
}
|
||||
|
@ -26,4 +26,5 @@ remote.jar:
|
||||
content/webdriver-bidi/modules/windowglobal/script.jsm (modules/windowglobal/script.jsm)
|
||||
|
||||
# WebDriver BiDi windowglobal-in-root modules
|
||||
content/webdriver-bidi/modules/windowglobal-in-root/browsingContext.jsm (modules/windowglobal-in-root/browsingContext.jsm)
|
||||
content/webdriver-bidi/modules/windowglobal-in-root/log.jsm (modules/windowglobal-in-root/log.jsm)
|
||||
|
@ -25,6 +25,8 @@ XPCOMUtils.defineLazyModuleGetters(modules.root, {
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(modules["windowglobal-in-root"], {
|
||||
browsingContext:
|
||||
"chrome://remote/content/webdriver-bidi/modules/windowglobal-in-root/browsingContext.jsm",
|
||||
log:
|
||||
"chrome://remote/content/webdriver-bidi/modules/windowglobal-in-root/log.jsm",
|
||||
});
|
||||
|
@ -564,7 +564,7 @@ class BrowsingContextModule extends Module {
|
||||
}
|
||||
|
||||
static get supportedEvents() {
|
||||
return ["browsingContext.contextCreated"];
|
||||
return ["browsingContext.contextCreated", "browsingContext.load"];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
"use strict";
|
||||
|
||||
const EXPORTED_SYMBOLS = ["browsingContext"];
|
||||
|
||||
const { XPCOMUtils } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/XPCOMUtils.sys.mjs"
|
||||
);
|
||||
|
||||
const { Module } = ChromeUtils.import(
|
||||
"chrome://remote/content/shared/messagehandler/Module.jsm"
|
||||
);
|
||||
|
||||
const lazy = {};
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
TabManager: "chrome://remote/content/shared/TabManager.jsm",
|
||||
});
|
||||
|
||||
class BrowsingContextModule extends Module {
|
||||
destroy() {}
|
||||
|
||||
interceptEvent(name, payload) {
|
||||
if (name == "browsingContext.load") {
|
||||
// Resolve browsing context to a TabManager id.
|
||||
payload.context = lazy.TabManager.getIdForBrowsingContext(
|
||||
payload.context
|
||||
);
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
}
|
||||
|
||||
const browsingContext = BrowsingContextModule;
|
@ -21,6 +21,8 @@ XPCOMUtils.defineLazyModuleGetters(lazy, {
|
||||
});
|
||||
|
||||
class BrowsingContextModule extends Module {
|
||||
#listeningToDOMContentLoaded;
|
||||
#listeningToLoad;
|
||||
#loadListener;
|
||||
|
||||
constructor(messageHandler) {
|
||||
@ -29,25 +31,49 @@ class BrowsingContextModule extends Module {
|
||||
// Setup the LoadListener as early as possible.
|
||||
this.#loadListener = new lazy.LoadListener(this.messageHandler.window);
|
||||
this.#loadListener.on("DOMContentLoaded", this.#onDOMContentLoaded);
|
||||
this.#loadListener.on("load", this.#onLoad);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
this.#loadListener.destroy();
|
||||
}
|
||||
|
||||
#subscribeEvent(event) {
|
||||
if (event === "browsingContext.DOMContentLoaded") {
|
||||
#startListening() {
|
||||
if (!this.#listeningToDOMContentLoaded && !this.#listeningToLoad) {
|
||||
this.#loadListener.startListening();
|
||||
}
|
||||
}
|
||||
|
||||
#subscribeEvent(event) {
|
||||
switch (event) {
|
||||
case "browsingContext.DOMContentLoaded":
|
||||
this.#startListening();
|
||||
this.#listeningToDOMContentLoaded = true;
|
||||
break;
|
||||
case "browsingContext.load":
|
||||
this.#startListening();
|
||||
this.#listeningToLoad = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#unsubscribeEvent(event) {
|
||||
if (event === "browsingContext.DOMContentLoaded") {
|
||||
switch (event) {
|
||||
case "browsingContext.DOMContentLoaded":
|
||||
this.#listeningToDOMContentLoaded = false;
|
||||
break;
|
||||
case "browsingContext.load":
|
||||
this.#listeningToLoad = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!this.#listeningToDOMContentLoaded && !this.#listeningToLoad) {
|
||||
this.#loadListener.stopListening();
|
||||
}
|
||||
}
|
||||
|
||||
#onDOMContentLoaded = (eventName, data) => {
|
||||
if (this.#listeningToDOMContentLoaded) {
|
||||
this.messageHandler.emitEvent("browsingContext.DOMContentLoaded", {
|
||||
baseURL: data.target.baseURI,
|
||||
contextId: this.messageHandler.contextId,
|
||||
@ -55,6 +81,19 @@ class BrowsingContextModule extends Module {
|
||||
innerWindowId: this.messageHandler.innerWindowId,
|
||||
readyState: data.target.readyState,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
#onLoad = (eventName, data) => {
|
||||
if (this.#listeningToLoad) {
|
||||
this.emitEvent("browsingContext.load", {
|
||||
context: this.messageHandler.context,
|
||||
// TODO: The navigation id should be a real id mapped to the navigation.
|
||||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=1763122
|
||||
navigation: null,
|
||||
url: data.target.baseURI,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user