1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /** @type {chrome.app.window.AppWindow} */
9 * The main window cannot delete its context menu entries on close because it
10 * is being torn down at that point and doesn't have access to the necessary
11 * APIs. Instead, it notifies the background page of the entries it creates,
12 * and the background pages deletes them when the window is closed.
16 var contextMenuIds = {};
18 /** @param {chrome.app.runtime.LaunchData=} opt_launchData */
19 function createWindow(opt_launchData) {
20 // If there is already a window, give it focus.
26 var typed_screen = /** @type {{availWidth: number, availHeight: number}} */
29 var windowAttributes = {
31 frame: remoting.platformIsMac() ? 'chrome' : 'none',
33 width: typed_screen.availWidth,
34 height: typed_screen.availHeight,
42 var ids = Object.keys(contextMenuIds);
43 for (var i = 0; i < ids.length; ++i) {
44 chrome.contextMenus.remove(ids[i]);
49 /** @param {chrome.app.window.AppWindow} appWindow */
50 function onCreate(appWindow) {
51 // Set the global window.
52 mainWindow = appWindow;
54 // Clean up the windows sub-menu when the application quits.
55 appWindow.onClosed.addListener(onClosed);
58 chrome.app.window.create('main.html', windowAttributes, onCreate);
61 /** @param {Event} event */
62 function onWindowMessage(event) {
63 var method = /** @type {string} */ (event.data['method']);
64 var id = /** @type {string} */ (event.data['id']);
66 case 'addContextMenuId':
67 contextMenuIds[id] = true;
69 case 'removeContextMenuId':
70 delete contextMenuIds[id];
75 chrome.app.runtime.onLaunched.addListener(createWindow);
76 window.addEventListener('message', onWindowMessage, false);