3
|
1 |
// This file contains the functions used to create the context menu for the browser's
|
|
2 |
// main content web view.
|
|
3 |
|
|
4 |
|
|
5 |
// Context menu spec:
|
|
6 |
// ------------------
|
|
7 |
//Images---Options to be shown under an "Links/Pictures" tab
|
|
8 |
// Save
|
|
9 |
// Share
|
|
10 |
//
|
|
11 |
//Images that are also links---Options to be shown under an "Links/Pictures" tab
|
|
12 |
// Open link in new window
|
|
13 |
// Save
|
|
14 |
// Share
|
|
15 |
//
|
|
16 |
//URLs-- Options to be shown under a "Links/Picture" tab
|
|
17 |
// Open link in new window
|
|
18 |
// Share
|
|
19 |
//
|
|
20 |
// Note: the options offered for a link or a picture or a combo
|
|
21 |
// link/picture are slightly different, but the right set should
|
|
22 |
// always be shown under a single tab contextual to what's been
|
|
23 |
// pressed.
|
|
24 |
//
|
|
25 |
// If no link or picture has been long-pressed and the user is in
|
|
26 |
// the CMB - say to see page options or the view switcher--the user
|
|
27 |
// can still press on the Links/Pictures tab. Because there is no
|
|
28 |
// known context to present options, we instead show menu items for
|
|
29 |
// the combined link/image object as grayed out with text on top
|
|
30 |
// approximating this: "Long-press on a web link or picture to use
|
|
31 |
// these actions."
|
|
32 |
|
|
33 |
function viewMenu_getImageItems(imageUrl) {
|
|
34 |
var items = new Array();
|
|
35 |
items =
|
|
36 |
[
|
|
37 |
{
|
|
38 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_image_save_image"), // "Save Image",
|
|
39 |
"onclick": function() {
|
|
40 |
if (window.downloads != null) {
|
|
41 |
window.downloads.downloadImage(imageUrl);
|
|
42 |
} else {
|
|
43 |
alert("Save " + imageUrl);
|
|
44 |
}
|
|
45 |
},
|
|
46 |
},
|
|
47 |
]
|
|
48 |
;
|
|
49 |
return items;
|
|
50 |
}
|
|
51 |
|
|
52 |
function viewMenu_getLinkItems(linkUrl) {
|
|
53 |
const maxWindowCount = 5;
|
|
54 |
var items = new Array();
|
|
55 |
items =
|
|
56 |
[
|
|
57 |
{
|
|
58 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_link_open_link"), // "Open Link In New Window",
|
|
59 |
"onclick": function() {
|
|
60 |
pageController.LoadInNewWindow(linkUrl);
|
|
61 |
},
|
|
62 |
"disabled": (pageController.pageCount() >= maxWindowCount) ? "true" : "false",
|
|
63 |
},
|
|
64 |
]
|
|
65 |
;
|
|
66 |
return items;
|
|
67 |
}
|
|
68 |
|
|
69 |
function viewMenu_getNavMenuData(current) {
|
|
70 |
return {
|
|
71 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_tab_navigation"), // "Navigation",
|
|
72 |
"iconHighlighted": "contextmenu.snippet/icons/nav_selected.png",
|
|
73 |
"icon": "contextmenu.snippet/icons/nav_deselected.png",
|
|
74 |
"current": current ? "true" : "false",
|
|
75 |
"menuItems":
|
|
76 |
[
|
|
77 |
{
|
|
78 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_nav_bookmarks"),
|
|
79 |
"onclick": chrome_showBookmarksView,
|
|
80 |
},
|
|
81 |
{
|
|
82 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_nav_history"),
|
|
83 |
"onclick": chrome_showHistoryView,
|
|
84 |
},
|
|
85 |
{
|
|
86 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_nav_windows"),
|
|
87 |
"onclick": chrome_showWindowsView,
|
|
88 |
},
|
|
89 |
{
|
|
90 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_nav_settings"),
|
|
91 |
"onclick": chrome_showSettingsView,
|
|
92 |
},
|
|
93 |
{
|
|
94 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_nav_exit"),
|
|
95 |
"onclick": window.app.quit,
|
|
96 |
},
|
|
97 |
],
|
|
98 |
};
|
|
99 |
}
|
|
100 |
|
|
101 |
function viewMenu_getPageMenuData(current) {
|
|
102 |
|
|
103 |
var popupsBlocked = pageController.getPopupSettings();
|
|
104 |
return {
|
|
105 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_tab_page"), // "Page",
|
|
106 |
"iconHighlighted": "contextmenu.snippet/icons/page_selected.png",
|
|
107 |
"icon": "contextmenu.snippet/icons/page_deselected.png",
|
|
108 |
"current": current ? "true" : "false",
|
|
109 |
"menuItems":
|
|
110 |
[
|
|
111 |
{
|
|
112 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_page_add_bookmark"), // "Add Bookmark",
|
|
113 |
"onclick": function() {
|
|
114 |
launchBookmarkDialog(pageController.currentDocTitle, pageController.currentDocUrl,0),
|
|
115 |
},
|
|
116 |
},
|
|
117 |
{
|
|
118 |
"text": (popupsBlocked ) ?
|
|
119 |
window.localeDelegate.translateText("txt_browser_content_view_menu_page_allow_popups"):
|
|
120 |
window.localeDelegate.translateText("txt_browser_content_view_menu_page_block_popups"), // "Block/Allow Pop-ups"
|
|
121 |
"onclick": function() {
|
|
122 |
pageController.savePopupSettings(!popupsBlocked);
|
|
123 |
},
|
|
124 |
},
|
|
125 |
{
|
|
126 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_page_share"), // "Share",
|
|
127 |
"onclick": function() {
|
|
128 |
var tempUrl = pageController.currentDocUrl;
|
|
129 |
pageController.share(tempUrl);
|
|
130 |
},
|
|
131 |
},
|
|
132 |
],
|
|
133 |
};
|
|
134 |
}
|
|
135 |
|
|
136 |
// Return a data structure representing the context menu for the main web view based
|
|
137 |
// on the information in contextEvent.
|
|
138 |
function viewMenu_getWebViewContextMenuData(contextEvent) {
|
|
139 |
var tabList = new Array;
|
|
140 |
var linkUrl = contextEvent != undefined ? contextEvent.linkUrl : "";
|
|
141 |
var imageUrl = contextEvent != undefined ? contextEvent.imageUrl : "";
|
|
142 |
var isLink = linkUrl != "";
|
|
143 |
var isImage = imageUrl != "";
|
|
144 |
var isLinkOrImage = isLink || isImage;
|
|
145 |
|
|
146 |
// Build Navigation tab and its menu.
|
|
147 |
if (contextEvent == undefined)
|
|
148 |
tabList = tabList.concat(viewMenu_getNavMenuData(true));
|
|
149 |
else
|
|
150 |
tabList = tabList.concat(viewMenu_getNavMenuData(false));
|
|
151 |
|
|
152 |
var linkMenuItems = new Array();
|
|
153 |
|
|
154 |
// Get image related menu items.
|
|
155 |
if (isImage || !isLinkOrImage)
|
|
156 |
linkMenuItems = linkMenuItems.concat(viewMenu_getImageItems(imageUrl));
|
|
157 |
|
|
158 |
// Get link related menu items.
|
|
159 |
if (isLink || !isLinkOrImage)
|
|
160 |
linkMenuItems = linkMenuItems.concat(viewMenu_getLinkItems(linkUrl));
|
|
161 |
|
|
162 |
linkMenuItems = linkMenuItems.concat(
|
|
163 |
[
|
|
164 |
{
|
|
165 |
"text": window.localeDelegate.translateText("txt_browser_content_view_menu_link_share_link"), // "Share"
|
|
166 |
"onclick": function() {
|
|
167 |
if ( isImage || !isLinkOrImage)
|
|
168 |
{
|
|
169 |
pageController.share(imageUrl);
|
|
170 |
}
|
|
171 |
else
|
|
172 |
{
|
|
173 |
pageController.share(linkUrl);
|
|
174 |
}
|
|
175 |
},
|
|
176 |
}
|
|
177 |
]);
|
|
178 |
|
|
179 |
// Build image/link tab and menu data.
|
|
180 |
tabList = tabList.concat( {
|
|
181 |
"text": (isLink && isImage || !isLink && !isImage)
|
|
182 |
? window.localeDelegate.translateText("txt_browser_content_view_menu_tab_link_image") // "Link/image"
|
|
183 |
: (isLink
|
|
184 |
? window.localeDelegate.translateText("txt_browser_content_view_menu_tab_link") // "Link"
|
|
185 |
: window.localeDelegate.translateText("txt_browser_content_view_menu_tab_image")), // "image"
|
|
186 |
"icon": "contextmenu.snippet/icons/links_deselected.png",
|
|
187 |
"iconHighlighted": "contextmenu.snippet/icons/links_selected.png",
|
|
188 |
"current": isLinkOrImage ? "true" : "false",
|
|
189 |
"disabled": isLinkOrImage ? "false" : "true",
|
|
190 |
"menuItems": linkMenuItems,
|
|
191 |
});
|
|
192 |
|
|
193 |
// Build Page tab and menu data.
|
|
194 |
if (contextEvent == undefined)
|
|
195 |
tabList = tabList.concat(viewMenu_getPageMenuData(false));
|
|
196 |
else
|
|
197 |
tabList = tabList.concat(viewMenu_getPageMenuData(!isLinkOrImage));
|
|
198 |
|
|
199 |
// Combine the tabs and return them.
|
|
200 |
return {
|
|
201 |
"tabs": tabList
|
|
202 |
};
|
|
203 |
}
|
|
204 |
|
|
205 |
// Initialize the WebView's context menu.
|
|
206 |
function viewMenu_initWebViewContextMenu() {
|
|
207 |
// Connect to the view's contextEvent signal.
|
|
208 |
views.WebView.contextEvent.connect(
|
|
209 |
function(contextEvent) {
|
|
210 |
//printProp(contextEvent);
|
|
211 |
cm_TheContextMenu.show(viewMenu_getWebViewContextMenuData(contextEvent));
|
|
212 |
}
|
|
213 |
);
|
|
214 |
}
|
|
215 |
|
|
216 |
chrome.chromeComplete.connect(viewMenu_initWebViewContextMenu);
|