Backed out 7 changesets (bug 1839993) for causing build bustages on DecoderTemplate...
[gecko.git] / browser / actors / ContextMenuParent.sys.mjs
blob4c67bc75ef3ba92c89bc65fff3f6dfc6ccdc10af
1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 const lazy = {};
8 ChromeUtils.defineESModuleGetters(lazy, {
9   FirefoxRelay: "resource://gre/modules/FirefoxRelay.sys.mjs",
10 });
12 export class ContextMenuParent extends JSWindowActorParent {
13   receiveMessage(message) {
14     let browser = this.manager.rootFrameLoader.ownerElement;
15     let win = browser.ownerGlobal;
16     // It's possible that the <xul:browser> associated with this
17     // ContextMenu message doesn't belong to a window that actually
18     // loads nsContextMenu.js. In that case, try to find the chromeEventHandler,
19     // since that'll likely be the "top" <xul:browser>, and then use its window's
20     // nsContextMenu instance instead.
21     if (!win.openContextMenu) {
22       let topBrowser = browser.ownerGlobal.docShell.chromeEventHandler;
23       win = topBrowser.ownerGlobal;
24     }
26     message.data.context.showRelay &&= lazy.FirefoxRelay.isEnabled;
28     win.openContextMenu(message, browser, this);
29   }
31   hiding() {
32     try {
33       this.sendAsyncMessage("ContextMenu:Hiding", {});
34     } catch (e) {
35       // This will throw if the content goes away while the
36       // context menu is still open.
37     }
38   }
40   reloadFrame(targetIdentifier, forceReload) {
41     this.sendAsyncMessage("ContextMenu:ReloadFrame", {
42       targetIdentifier,
43       forceReload,
44     });
45   }
47   getImageText(targetIdentifier) {
48     return this.sendQuery("ContextMenu:GetImageText", {
49       targetIdentifier,
50     });
51   }
53   toggleRevealPassword(targetIdentifier) {
54     this.sendAsyncMessage("ContextMenu:ToggleRevealPassword", {
55       targetIdentifier,
56     });
57   }
59   async useRelayMask(targetIdentifier, origin) {
60     if (!origin) {
61       return;
62     }
64     const windowGlobal = this.manager.browsingContext.currentWindowGlobal;
65     const browser = windowGlobal.rootFrameLoader.ownerElement;
66     const emailMask = await lazy.FirefoxRelay.generateUsername(browser, origin);
67     if (emailMask) {
68       this.sendAsyncMessage("ContextMenu:UseRelayMask", {
69         targetIdentifier,
70         emailMask,
71       });
72     }
73   }
75   reloadImage(targetIdentifier) {
76     this.sendAsyncMessage("ContextMenu:ReloadImage", { targetIdentifier });
77   }
79   getFrameTitle(targetIdentifier) {
80     return this.sendQuery("ContextMenu:GetFrameTitle", { targetIdentifier });
81   }
83   mediaCommand(targetIdentifier, command, data) {
84     let windowGlobal = this.manager.browsingContext.currentWindowGlobal;
85     let browser = windowGlobal.rootFrameLoader.ownerElement;
86     let win = browser.ownerGlobal;
87     let windowUtils = win.windowUtils;
88     this.sendAsyncMessage("ContextMenu:MediaCommand", {
89       targetIdentifier,
90       command,
91       data,
92       handlingUserInput: windowUtils.isHandlingUserInput,
93     });
94   }
96   canvasToBlobURL(targetIdentifier) {
97     return this.sendQuery("ContextMenu:Canvas:ToBlobURL", { targetIdentifier });
98   }
100   saveVideoFrameAsImage(targetIdentifier) {
101     return this.sendQuery("ContextMenu:SaveVideoFrameAsImage", {
102       targetIdentifier,
103     });
104   }
106   setAsDesktopBackground(targetIdentifier) {
107     return this.sendQuery("ContextMenu:SetAsDesktopBackground", {
108       targetIdentifier,
109     });
110   }
112   getSearchFieldBookmarkData(targetIdentifier) {
113     return this.sendQuery("ContextMenu:SearchFieldBookmarkData", {
114       targetIdentifier,
115     });
116   }