Source code

Revision control

Other Tools

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/. */
5
"use strict";
6
7
var EXPORTED_SYMBOLS = ["ContextMenuParent"];
8
9
class ContextMenuParent extends JSWindowActorParent {
10
receiveMessage(message) {
11
let browser = this.manager.rootFrameLoader.ownerElement;
12
let win = browser.ownerGlobal;
13
// It's possible that the <xul:browser> associated with this
14
// ContextMenu message doesn't belong to a window that actually
15
// loads nsContextMenu.js. In that case, try to find the chromeEventHandler,
16
// since that'll likely be the "top" <xul:browser>, and then use its window's
17
// nsContextMenu instance instead.
18
if (!win.openContextMenu) {
19
let topBrowser = browser.ownerGlobal.docShell.chromeEventHandler;
20
win = topBrowser.ownerGlobal;
21
22
// If this context menu happens to be for a tabbed browser window,
23
// we need to check to see if we're in Responsive Design Mode. This is
24
// because we need to convince nsContextMenu to use the top-level browser
25
// for the tab, rather than the mozbrowser iframe actually showing the
26
// web content. This is a workaround until we can get bug 1559456 fixed.
27
if (win.gBrowser) {
28
let tab = win.gBrowser.getTabForBrowser(browser);
29
if (tab && tab.isResponsiveDesignMode) {
30
browser = topBrowser;
31
}
32
}
33
}
34
35
win.openContextMenu(message, browser, this);
36
}
37
38
hiding() {
39
try {
40
this.sendAsyncMessage("ContextMenu:Hiding", {});
41
} catch (e) {
42
// This will throw if the content goes away while the
43
// context menu is still open.
44
}
45
}
46
47
reloadFrame(targetIdentifier, forceReload) {
48
this.sendAsyncMessage("ContextMenu:ReloadFrame", {
49
targetIdentifier,
50
forceReload,
51
});
52
}
53
54
reloadImage(targetIdentifier) {
55
this.sendAsyncMessage("ContextMenu:ReloadImage", { targetIdentifier });
56
}
57
58
getFrameTitle(targetIdentifier) {
59
return this.sendQuery("ContextMenu:GetFrameTitle", { targetIdentifier });
60
}
61
62
mediaCommand(targetIdentifier, command, data) {
63
let windowGlobal = this.manager.browsingContext.currentWindowGlobal;
64
let browser = windowGlobal.rootFrameLoader.ownerElement;
65
let win = browser.ownerGlobal;
66
let windowUtils = win.windowUtils;
67
this.sendAsyncMessage("ContextMenu:MediaCommand", {
68
targetIdentifier,
69
command,
70
data,
71
handlingUserInput: windowUtils.isHandlingUserInput,
72
});
73
}
74
75
canvasToBlobURL(targetIdentifier) {
76
return this.sendQuery("ContextMenu:Canvas:ToBlobURL", { targetIdentifier });
77
}
78
79
saveVideoFrameAsImage(targetIdentifier) {
80
return this.sendQuery("ContextMenu:SaveVideoFrameAsImage", {
81
targetIdentifier,
82
});
83
}
84
85
setAsDesktopBackground(targetIdentifier) {
86
return this.sendQuery("ContextMenu:SetAsDesktopBackground", {
87
targetIdentifier,
88
});
89
}
90
91
getSearchFieldBookmarkData(targetIdentifier) {
92
return this.sendQuery("ContextMenu:SearchFieldBookmarkData", {
93
targetIdentifier,
94
});
95
}
96
97
doCustomCommand(generatedItemId, handlingUserInput) {
98
this.sendAsyncMessage("ContextMenu:DoCustomCommand", {
99
generatedItemId,
100
handlingUserInput,
101
});
102
}
103
}