Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(587)

Unified Diff: remoting/webapp/background.js

Issue 23536033: Add 'New window' option to context menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/background.js
diff --git a/remoting/webapp/background.js b/remoting/webapp/background.js
index 290b43a0ee6929c268999f22f9a4494d3c049d8f..3809f0cea28fe49a02691a1a1bff0600ae149825 100644
--- a/remoting/webapp/background.js
+++ b/remoting/webapp/background.js
@@ -2,9 +2,37 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-chrome.app.runtime.onLaunched.addListener(function() {
+/** @type {string} */
+var kNewWindowId = 'new-window';
+
+function createWindow() {
chrome.app.window.create('main.html', {
'width': 800,
'height': 600
});
-});
+};
+
+/** @param {OnClickData} info */
+function onContextMenu(info) {
+ if (info.menuItemId == kNewWindowId) {
+ createWindow();
+ }
+};
+
+function initializeContextMenu() {
+ try {
+ chrome.contextMenus.remove(kNewWindowId);
+ } catch (ignore) {
+ // There is no way to detect if the context menu is already added, therefore
+ // try to recreate it every time.
Lambros 2013/09/06 22:16:14 This is the only place you're adding the context m
Jamie 2013/09/06 23:45:50 I added it because the sample I based it on did so
+ }
+ chrome.contextMenus.create({
+ id: kNewWindowId,
+ contexts: ['launcher'],
+ title: chrome.i18n.getMessage(/*i18n-content*/'NEW_WINDOW')
+ });
+}
+
+chrome.app.runtime.onLaunched.addListener(createWindow);
+chrome.contextMenus.onClicked.addListener(onContextMenu);
+initializeContextMenu();
Lambros 2013/09/06 22:16:14 Shouldn't we call this from remoting.init() (or th
Jamie 2013/09/06 23:45:50 This is the background page. It gets run when the

Powered by Google App Engine
This is Rietveld 408576698