Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / remoting / webapp / app_remoting / js / ar_background.js
blobd9ea8e51ddd57e44335837cd2ae143f8a21ff5d2
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} */
6 var mainWindow = null;
8 /**
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.
14 * @type {!Object}
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.
21 if (mainWindow) {
22 mainWindow.focus();
23 return;
26 var typed_screen = /** @type {{availWidth: number, availHeight: number}} */
27 (screen);
29 var windowAttributes = {
30 resizable: false,
31 frame: remoting.platformIsMac() ? 'chrome' : 'none',
32 bounds: {
33 width: typed_screen.availWidth,
34 height: typed_screen.availHeight,
35 left: undefined,
36 top: undefined
40 function onClosed() {
41 mainWindow = null;
42 var ids = Object.keys(contextMenuIds);
43 for (var i = 0; i < ids.length; ++i) {
44 chrome.contextMenus.remove(ids[i]);
46 contextMenuIds = {};
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']);
68 switch (method) {
69 case 'addContextMenuId':
70 contextMenuIds[id] = true;
71 break;
72 case 'removeContextMenuId':
73 delete contextMenuIds[id];
74 break;
78 chrome.app.runtime.onLaunched.addListener(createWindow);
79 window.addEventListener('message', onWindowMessage, false);