1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { GeckoViewActorChild } from "resource://gre/modules/GeckoViewActorChild.sys.mjs";
7 export class GeckoViewPrompterChild extends GeckoViewActorChild {
10 this._prompts = new Map();
13 dismissPrompt(prompt) {
14 this.eventDispatcher.sendRequest({
15 type: "GeckoView:Prompt:Dismiss",
18 this.unregisterPrompt(prompt);
21 updatePrompt(message) {
22 this.eventDispatcher.sendRequest({
23 type: "GeckoView:Prompt:Update",
28 unregisterPrompt(prompt) {
29 this._prompts.delete(prompt.id);
30 this.sendAsyncMessage("UnregisterPrompt", {
35 prompt(prompt, message) {
36 this._prompts.set(prompt.id, prompt);
37 this.sendAsyncMessage("RegisterPrompt", {
39 promptType: prompt.getPromptType(),
41 // We intentionally do not await here as we want to fire NotifyPromptShow
42 // immediately rather than waiting until the user accepts/dismisses the
44 const result = this.eventDispatcher.sendRequestForResult({
45 type: "GeckoView:Prompt",
48 this.sendAsyncMessage("NotifyPromptShow", {
55 * Handles the message coming from GeckoViewPrompterParent.
57 * @param {string} message.name The subject of the message.
58 * @param {object} message.data The data of the message.
60 async receiveMessage({ name, data }) {
61 const prompt = this._prompts.get(data.id);
63 // Unknown prompt, probably for a different child actor.
67 case "GetPromptText": {
68 // eslint-disable-next-line consistent-return
69 return prompt.getPromptText();
71 case "GetInputText": {
72 // eslint-disable-next-line consistent-return
73 return prompt.getInputText();
75 case "SetInputText": {
76 prompt.setInputText(data.text);
79 case "AcceptPrompt": {
83 case "DismissPrompt": {
94 const { debug, warn } = GeckoViewPrompterChild.initLogging("Prompter");