diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /mobile/android/actors/GeckoViewPrompterChild.sys.mjs | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.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/GeckoViewPrompterChild.sys.mjs')
-rw-r--r-- | mobile/android/actors/GeckoViewPrompterChild.sys.mjs | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/mobile/android/actors/GeckoViewPrompterChild.sys.mjs b/mobile/android/actors/GeckoViewPrompterChild.sys.mjs new file mode 100644 index 0000000000..bb8c4fbcff --- /dev/null +++ b/mobile/android/actors/GeckoViewPrompterChild.sys.mjs @@ -0,0 +1,94 @@ +/* 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 { GeckoViewActorChild } from "resource://gre/modules/GeckoViewActorChild.sys.mjs"; + +export class GeckoViewPrompterChild extends GeckoViewActorChild { + constructor() { + super(); + this._prompts = new Map(); + } + + dismissPrompt(prompt) { + this.eventDispatcher.sendRequest({ + type: "GeckoView:Prompt:Dismiss", + id: prompt.id, + }); + this.unregisterPrompt(prompt); + } + + updatePrompt(message) { + this.eventDispatcher.sendRequest({ + type: "GeckoView:Prompt:Update", + prompt: message, + }); + } + + unregisterPrompt(prompt) { + this._prompts.delete(prompt.id); + this.sendAsyncMessage("UnregisterPrompt", { + id: prompt.id, + }); + } + + prompt(prompt, message) { + this._prompts.set(prompt.id, prompt); + this.sendAsyncMessage("RegisterPrompt", { + id: prompt.id, + promptType: prompt.getPromptType(), + }); + // We intentionally do not await here as we want to fire NotifyPromptShow + // immediately rather than waiting until the user accepts/dismisses the + // prompt. + const result = this.eventDispatcher.sendRequestForResult({ + type: "GeckoView:Prompt", + prompt: message, + }); + this.sendAsyncMessage("NotifyPromptShow", { + id: prompt.id, + }); + return result; + } + + /** + * Handles the message coming from GeckoViewPrompterParent. + * + * @param {string} message.name The subject of the message. + * @param {object} message.data The data of the message. + */ + async receiveMessage({ name, data }) { + const prompt = this._prompts.get(data.id); + if (!prompt) { + // Unknown prompt, probably for a different child actor. + return; + } + switch (name) { + case "GetPromptText": { + // eslint-disable-next-line consistent-return + return prompt.getPromptText(); + } + case "GetInputText": { + // eslint-disable-next-line consistent-return + return prompt.getInputText(); + } + case "SetInputText": { + prompt.setInputText(data.text); + break; + } + case "AcceptPrompt": { + prompt.accept(); + break; + } + case "DismissPrompt": { + prompt.dismiss(); + break; + } + default: { + break; + } + } + } +} + +const { debug, warn } = GeckoViewPrompterChild.initLogging("Prompter"); |