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

Side by Side Diff: remoting/webapp/app_remoting/js/ar_background.js

Issue 1816653002: Remove app_remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 /** @type {chrome.app.window.AppWindow} */
6 var mainWindow = null;
7
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.
13 *
14 * @type {!Object}
15 */
16 var contextMenuIds = {};
17
18 /** @param {Object=} 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;
24 }
25
26 var typed_screen = /** @type {{availWidth: number, availHeight: number}} */
27 (screen);
28
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
37 }
38 };
39
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]);
45 }
46 contextMenuIds = {};
47 };
48
49 /** @param {chrome.app.window.AppWindow} appWindow */
50 function onCreate(appWindow) {
51 // Set the global window.
52 mainWindow = appWindow;
53
54 // Clean up the windows sub-menu when the application quits.
55 appWindow.onClosed.addListener(onClosed);
56 };
57
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);
62 };
63
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;
75 }
76 };
77
78 chrome.app.runtime.onLaunched.addListener(createWindow);
79 window.addEventListener('message', onWindowMessage, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698