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 // TODO(garykac) Add code to switch between dev and prod shared modules.
59 chrome.app.window.create(
60 '_modules/koejkfhmphamcgafjmkellhnekdkopod/main.html',
61 windowAttributes, onCreate);
64 /** @param {Event} event */
65 function onWindowMessage(event) {
66 var method = /** @type {string} */ (event.data['method']);
67 var id = /** @type {string} */ (event.data['id']);
69 case 'addContextMenuId':
70 contextMenuIds[id] = true;
72 case 'removeContextMenuId':
73 delete contextMenuIds[id];
78 chrome.app.runtime.onLaunched.addListener(createWindow);
79 window.addEventListener('message', onWindowMessage, false);