summaryrefslogtreecommitdiffstats
path: root/remote/cdp/sessions/ContentProcessSession.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /remote/cdp/sessions/ContentProcessSession.sys.mjs
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/cdp/sessions/ContentProcessSession.sys.mjs')
-rw-r--r--remote/cdp/sessions/ContentProcessSession.sys.mjs104
1 files changed, 104 insertions, 0 deletions
diff --git a/remote/cdp/sessions/ContentProcessSession.sys.mjs b/remote/cdp/sessions/ContentProcessSession.sys.mjs
new file mode 100644
index 0000000000..d7aa3de57b
--- /dev/null
+++ b/remote/cdp/sessions/ContentProcessSession.sys.mjs
@@ -0,0 +1,104 @@
+/* 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/. */
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ ContentProcessDomains:
+ "chrome://remote/content/cdp/domains/ContentProcessDomains.sys.mjs",
+ ContextObserver:
+ "chrome://remote/content/cdp/observers/ContextObserver.sys.mjs",
+ DomainCache: "chrome://remote/content/cdp/domains/DomainCache.sys.mjs",
+});
+
+export class ContentProcessSession {
+ constructor(messageManager, browsingContext, content, docShell) {
+ this.messageManager = messageManager;
+ this.browsingContext = browsingContext;
+ this.content = content;
+ this.docShell = docShell;
+ // Most children or sibling classes are going to assume that docShell
+ // implements the following interface. So do the QI only once from here.
+ this.docShell.QueryInterface(Ci.nsIWebNavigation);
+
+ this.domains = new lazy.DomainCache(this, lazy.ContentProcessDomains);
+ this.messageManager.addMessageListener("remote:request", this);
+ this.messageManager.addMessageListener("remote:destroy", this);
+ }
+
+ destructor() {
+ this._contextObserver?.destructor();
+
+ this.messageManager.removeMessageListener("remote:request", this);
+ this.messageManager.removeMessageListener("remote:destroy", this);
+ this.domains.clear();
+ }
+
+ get contextObserver() {
+ if (!this._contextObserver) {
+ this._contextObserver = new lazy.ContextObserver(
+ this.docShell.chromeEventHandler
+ );
+ }
+ return this._contextObserver;
+ }
+
+ // Domain event listener
+
+ onEvent(eventName, params) {
+ this.messageManager.sendAsyncMessage("remote:event", {
+ browsingContextId: this.browsingContext.id,
+ event: {
+ eventName,
+ params,
+ },
+ });
+ }
+
+ // nsIMessageListener
+
+ async receiveMessage({ name, data }) {
+ const { browsingContextId } = data;
+
+ // We may have more than one tab loaded in the same process,
+ // and debug the two at the same time. We want to ensure not
+ // mixing up the requests made against two such tabs.
+ // Each tab is going to have its own frame script instance
+ // and two communication channels are going to be set up via
+ // the two message managers.
+ if (browsingContextId != this.browsingContext.id) {
+ return;
+ }
+
+ switch (name) {
+ case "remote:request":
+ try {
+ const { id, domain, command, params } = data.request;
+
+ const result = await this.domains.execute(domain, command, params);
+
+ this.messageManager.sendAsyncMessage("remote:result", {
+ browsingContextId,
+ id,
+ result,
+ });
+ } catch (e) {
+ this.messageManager.sendAsyncMessage("remote:error", {
+ browsingContextId,
+ id: data.request.id,
+ error: {
+ name: e.name || "exception",
+ message: e.message || String(e),
+ stack: e.stack,
+ },
+ });
+ }
+ break;
+
+ case "remote:destroy":
+ this.destructor();
+ break;
+ }
+ }
+}