diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /remote/domains/content/Input.jsm | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/domains/content/Input.jsm')
-rw-r--r-- | remote/domains/content/Input.jsm | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/remote/domains/content/Input.jsm b/remote/domains/content/Input.jsm new file mode 100644 index 0000000000..17d88550e5 --- /dev/null +++ b/remote/domains/content/Input.jsm @@ -0,0 +1,71 @@ +/* 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"; + +var EXPORTED_SYMBOLS = ["Input"]; + +const { ContentProcessDomain } = ChromeUtils.import( + "chrome://remote/content/domains/ContentProcessDomain.jsm" +); + +class Input extends ContentProcessDomain { + constructor(session) { + super(session); + + // Internal id used to track existing event handlers. + this._eventId = 0; + + // Map of event id -> event handler promise. + this._eventPromises = new Map(); + } + + /** + * Internal methods: the following methods are not part of CDP; + * note the _ prefix. + */ + + /** + * Add an event listener in the content page for the provided eventName. + * This method will return a unique handler id that can be used to wait + * for the event. + * + * Example usage from a parent process domain: + * + * const id = await this.executeInChild("addContentEventListener", "click"); + * // do something that triggers a click in content + * await this.executeInChild("waitForContentEvent", id); + */ + _addContentEventListener(eventName) { + const eventPromise = new Promise(r => { + this.chromeEventHandler.addEventListener(eventName, r, { + mozSystemGroup: true, + once: true, + }); + }); + this._eventId++; + this._eventPromises.set(this._eventId, eventPromise); + return this._eventId; + } + + /** + * Wait for an event listener added via `addContentEventListener` to be fired. + */ + async _waitForContentEvent(eventId) { + const eventPromise = this._eventPromises.get(eventId); + if (!eventPromise) { + throw new Error("No event promise found for id " + eventId); + } + await eventPromise; + this._eventPromises.delete(eventId); + } + + /** + * Expose docShell.doCommand to parent domain. + * Used in temporary workaround for emulating certain native key bindings + */ + _doDocShellCommand(command) { + this.docShell.doCommand(command); + } +} |