summaryrefslogtreecommitdiffstats
path: root/mobile/android/actors/GeckoViewPrompterParent.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:44:51 +0000
commit9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /mobile/android/actors/GeckoViewPrompterParent.sys.mjs
parentInitial commit. (diff)
downloadthunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.tar.xz
thunderbird-9e3c08db40b8916968b9f30096c7be3f00ce9647.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mobile/android/actors/GeckoViewPrompterParent.sys.mjs')
-rw-r--r--mobile/android/actors/GeckoViewPrompterParent.sys.mjs156
1 files changed, 156 insertions, 0 deletions
diff --git a/mobile/android/actors/GeckoViewPrompterParent.sys.mjs b/mobile/android/actors/GeckoViewPrompterParent.sys.mjs
new file mode 100644
index 0000000000..8e06b39744
--- /dev/null
+++ b/mobile/android/actors/GeckoViewPrompterParent.sys.mjs
@@ -0,0 +1,156 @@
+/* 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/. */
+
+import { GeckoViewActorParent } from "resource://gre/modules/GeckoViewActorParent.sys.mjs";
+
+const DIALOGS = [
+ "alert",
+ "alertCheck",
+ "confirm",
+ "confirmCheck",
+ "prompt",
+ "promptCheck",
+];
+
+export class GeckoViewPrompterParent extends GeckoViewActorParent {
+ constructor() {
+ super();
+ this._prompts = new Map();
+ }
+
+ get rootActor() {
+ return this.browsingContext.top.currentWindowGlobal.getActor(
+ "GeckoViewPrompter"
+ );
+ }
+
+ registerPrompt(promptId, promptType, actor) {
+ return this._prompts.set(
+ promptId,
+ new RemotePrompt(promptId, promptType, actor)
+ );
+ }
+
+ unregisterPrompt(promptId) {
+ this._prompts.delete(promptId);
+ }
+
+ notifyPromptShow(promptId) {
+ // ToDo: Bug 1761480 - GeckoView can send additional prompts to Marionette
+ if (this._prompts.get(promptId).isDialog) {
+ Services.obs.notifyObservers({ id: promptId }, "geckoview-prompt-show");
+ }
+ }
+
+ getPrompts() {
+ const self = this;
+ const prompts = [];
+ // Marionette expects this event to be fired from the parent
+ const dialogClosedEvent = new CustomEvent("DOMModalDialogClosed", {
+ cancelable: true,
+ bubbles: true,
+ });
+ for (const [, prompt] of this._prompts) {
+ // Adding only WebDriver compliant dialogs to the window
+ if (prompt.isDialog) {
+ prompts.push({
+ args: {
+ modalType: "GeckoViewPrompter",
+ promptType: prompt.type,
+ isDialog: prompt.isDialog,
+ },
+ setInputText(text) {
+ prompt.setInputText(text);
+ },
+ async getPromptText() {
+ return prompt.getPromptText();
+ },
+ async getInputText() {
+ return prompt.getInputText();
+ },
+ acceptPrompt() {
+ prompt.acceptPrompt();
+ self.window.dispatchEvent(dialogClosedEvent);
+ },
+ dismissPrompt() {
+ prompt.dismissPrompt();
+ self.window.dispatchEvent(dialogClosedEvent);
+ },
+ });
+ }
+ }
+ return prompts;
+ }
+
+ /**
+ * Handles the message coming from GeckoViewPrompterChild.
+ *
+ * @param {string} message.name The subject of the message.
+ * @param {object} message.data The data of the message.
+ */
+ // eslint-disable-next-line consistent-return
+ async receiveMessage({ name, data }) {
+ switch (name) {
+ case "RegisterPrompt": {
+ this.rootActor.registerPrompt(data.id, data.promptType, this);
+ break;
+ }
+ case "UnregisterPrompt": {
+ this.rootActor.unregisterPrompt(data.id);
+ break;
+ }
+ case "NotifyPromptShow": {
+ this.rootActor.notifyPromptShow(data.id);
+ break;
+ }
+ default: {
+ return super.receiveMessage({ name, data });
+ }
+ }
+ }
+}
+
+class RemotePrompt {
+ constructor(id, type, actor) {
+ this.id = id;
+ this.type = type;
+ this.actor = actor;
+ }
+
+ // Checks if the prompt conforms to a WebDriver simple dialog.
+ get isDialog() {
+ return DIALOGS.includes(this.type);
+ }
+
+ getPromptText() {
+ return this.actor.sendQuery("GetPromptText", {
+ id: this.id,
+ });
+ }
+
+ getInputText() {
+ return this.actor.sendQuery("GetInputText", {
+ id: this.id,
+ });
+ }
+
+ setInputText(inputText) {
+ this.actor.sendAsyncMessage("SetInputText", {
+ id: this.id,
+ text: inputText,
+ });
+ }
+
+ acceptPrompt() {
+ this.actor.sendAsyncMessage("AcceptPrompt", {
+ id: this.id,
+ });
+ }
+
+ dismissPrompt() {
+ this.actor.sendAsyncMessage("DismissPrompt", {
+ id: this.id,
+ });
+ }
+}