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/. */
8 ChromeUtils.defineESModuleGetters(lazy, {
9 FirefoxRelay: "resource://gre/modules/FirefoxRelay.sys.mjs",
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;
26 message.data.context.showRelay &&= lazy.FirefoxRelay.isEnabled;
28 win.openContextMenu(message, browser, this);
33 this.sendAsyncMessage("ContextMenu:Hiding", {});
35 // This will throw if the content goes away while the
36 // context menu is still open.
40 reloadFrame(targetIdentifier, forceReload) {
41 this.sendAsyncMessage("ContextMenu:ReloadFrame", {
47 getImageText(targetIdentifier) {
48 return this.sendQuery("ContextMenu:GetImageText", {
53 toggleRevealPassword(targetIdentifier) {
54 this.sendAsyncMessage("ContextMenu:ToggleRevealPassword", {
59 async useRelayMask(targetIdentifier, origin) {
64 const windowGlobal = this.manager.browsingContext.currentWindowGlobal;
65 const browser = windowGlobal.rootFrameLoader.ownerElement;
66 const emailMask = await lazy.FirefoxRelay.generateUsername(browser, origin);
68 this.sendAsyncMessage("ContextMenu:UseRelayMask", {
75 reloadImage(targetIdentifier) {
76 this.sendAsyncMessage("ContextMenu:ReloadImage", { targetIdentifier });
79 getFrameTitle(targetIdentifier) {
80 return this.sendQuery("ContextMenu:GetFrameTitle", { targetIdentifier });
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", {
92 handlingUserInput: windowUtils.isHandlingUserInput,
96 canvasToBlobURL(targetIdentifier) {
97 return this.sendQuery("ContextMenu:Canvas:ToBlobURL", { targetIdentifier });
100 saveVideoFrameAsImage(targetIdentifier) {
101 return this.sendQuery("ContextMenu:SaveVideoFrameAsImage", {
106 setAsDesktopBackground(targetIdentifier) {
107 return this.sendQuery("ContextMenu:SetAsDesktopBackground", {
112 getSearchFieldBookmarkData(targetIdentifier) {
113 return this.sendQuery("ContextMenu:SearchFieldBookmarkData", {