OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 /** @suppress {duplicate} */ | 7 /** @suppress {duplicate} */ |
8 var remoting = remoting || {}; | 8 var remoting = remoting || {}; |
9 | 9 |
10 /** | 10 /** |
11 * @type {base.EventSource} An event source object for handling global events. | 11 * @type {base.EventSource} An event source object for handling global events. |
12 * This is an interim hack. Eventually, we should move functionalities | 12 * This is an interim hack. Eventually, we should move functionalities |
13 * away from the remoting namespace and into smaller objects. | 13 * away from the remoting namespace and into smaller objects. |
14 */ | 14 */ |
15 remoting.testEvents; | 15 remoting.testEvents; |
16 | 16 |
17 /** | 17 /** |
18 * Initialization tasks that are common to all remoting apps. | 18 * Initialization tasks that are common to all remoting apps. |
19 */ | 19 */ |
20 remoting.initGlobalObjects = function() { | 20 remoting.initGlobalObjects = function() { |
21 if (base.isAppsV2()) { | 21 if (base.isAppsV2()) { |
22 var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode); | 22 var htmlNode = /** @type {HTMLElement} */ (document.body.parentNode); |
23 htmlNode.classList.add('apps-v2'); | 23 htmlNode.classList.add('apps-v2'); |
24 } else { | |
25 migrateLocalToChromeStorage_(); | |
26 } | 24 } |
27 | 25 |
28 console.log(remoting.getExtensionInfo()); | 26 console.log(remoting.getExtensionInfo()); |
29 l10n.localize(); | 27 l10n.localize(); |
30 | 28 |
31 if (base.isAppsV2()) { | 29 if (base.isAppsV2()) { |
32 remoting.fullscreen = new remoting.FullscreenAppsV2(); | 30 remoting.fullscreen = new remoting.FullscreenAppsV2(); |
33 } else { | 31 } else { |
34 remoting.fullscreen = new remoting.FullscreenAppsV1(); | 32 remoting.fullscreen = new remoting.FullscreenAppsV1(); |
35 } | 33 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)"; | 80 var v2OrLegacy = base.isAppsV2() ? " (v2)" : " (legacy)"; |
83 var manifest = chrome.runtime.getManifest(); | 81 var manifest = chrome.runtime.getManifest(); |
84 if (manifest && manifest.version) { | 82 if (manifest && manifest.version) { |
85 var name = chrome.i18n.getMessage('PRODUCT_NAME'); | 83 var name = chrome.i18n.getMessage('PRODUCT_NAME'); |
86 return name + ' version: ' + manifest.version + v2OrLegacy; | 84 return name + ' version: ' + manifest.version + v2OrLegacy; |
87 } else { | 85 } else { |
88 return 'Failed to get product version. Corrupt manifest?'; | 86 return 'Failed to get product version. Corrupt manifest?'; |
89 } | 87 } |
90 }; | 88 }; |
91 | 89 |
90 remoting.onBeforeUnload = function() { | |
kelvinp
2015/01/13 23:05:47
The 'remoting-email' is not set when initGlobalObj
Jamie
2015/01/15 20:51:30
This code is all about moving settings from window
| |
91 migrateLocalToChromeStorage_(); | |
92 return remoting.promptClose(); | |
93 }; | |
94 | |
92 /** | 95 /** |
93 * If an IT2Me client or host is active then prompt the user before closing. | 96 * If an IT2Me client or host is active then prompt the user before closing. |
94 * If a Me2Me client is active then don't bother, since closing the window is | 97 * If a Me2Me client is active then don't bother, since closing the window is |
95 * the more intuitive way to end a Me2Me session, and re-connecting is easy. | 98 * the more intuitive way to end a Me2Me session, and re-connecting is easy. |
99 * @return {?string} | |
96 */ | 100 */ |
97 remoting.promptClose = function() { | 101 remoting.promptClose = function() { |
98 if (remoting.clientSession && | 102 if (remoting.clientSession && |
99 remoting.clientSession.getMode() == remoting.ClientSession.Mode.IT2ME) { | 103 remoting.clientSession.getMode() == remoting.ClientSession.Mode.IT2ME) { |
100 switch (remoting.currentMode) { | 104 switch (remoting.currentMode) { |
101 case remoting.AppMode.CLIENT_CONNECTING: | 105 case remoting.AppMode.CLIENT_CONNECTING: |
102 case remoting.AppMode.HOST_WAITING_FOR_CODE: | 106 case remoting.AppMode.HOST_WAITING_FOR_CODE: |
103 case remoting.AppMode.HOST_WAITING_FOR_CONNECTION: | 107 case remoting.AppMode.HOST_WAITING_FOR_CONNECTION: |
104 case remoting.AppMode.HOST_SHARED: | 108 case remoting.AppMode.HOST_SHARED: |
105 case remoting.AppMode.IN_SESSION: | 109 case remoting.AppMode.IN_SESSION: |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
237 * Migrate settings in window.localStorage to chrome.storage.local so that | 241 * Migrate settings in window.localStorage to chrome.storage.local so that |
238 * users of older web-apps that used the former do not lose their settings. | 242 * users of older web-apps that used the former do not lose their settings. |
239 */ | 243 */ |
240 function migrateLocalToChromeStorage_() { | 244 function migrateLocalToChromeStorage_() { |
241 // The OAuth2 class still uses window.localStorage, so don't migrate any of | 245 // The OAuth2 class still uses window.localStorage, so don't migrate any of |
242 // those settings. | 246 // those settings. |
243 var oauthSettings = [ | 247 var oauthSettings = [ |
244 'oauth2-refresh-token', | 248 'oauth2-refresh-token', |
245 'oauth2-refresh-token-revokable', | 249 'oauth2-refresh-token-revokable', |
246 'oauth2-access-token', | 250 'oauth2-access-token', |
247 'oauth2-xsrf-token', | 251 'oauth2-xsrf-token' |
248 'remoting-email' | |
kelvinp
2015/01/13 23:05:47
We need to migrate 'remoting-email' as well.
Jamie
2015/01/15 20:51:30
See above; this is not about migrating settings fr
| |
249 ]; | 252 ]; |
250 for (var setting in window.localStorage) { | 253 for (var setting in window.localStorage) { |
251 if (oauthSettings.indexOf(setting) == -1) { | 254 if (oauthSettings.indexOf(setting) == -1) { |
252 var copy = {} | 255 var copy = {}; |
253 copy[setting] = window.localStorage.getItem(setting); | 256 copy[setting] = window.localStorage.getItem(setting); |
254 chrome.storage.local.set(copy); | 257 chrome.storage.local.set(copy); |
255 window.localStorage.removeItem(setting); | |
Jamie
2015/01/15 20:51:30
I don't think you wanted to remove this line.
| |
256 } | 258 } |
257 } | 259 } |
258 } | 260 } |
OLD | NEW |