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 /** @type {remoting.HostSession} */ remoting.hostSession = null; | 10 /** @type {remoting.HostSession} */ remoting.hostSession = null; |
(...skipping 11 matching lines...) Expand all Loading... |
22 BAD_PLUGIN_VERSION: /*i18n-content*/'ERROR_BAD_PLUGIN_VERSION', | 22 BAD_PLUGIN_VERSION: /*i18n-content*/'ERROR_BAD_PLUGIN_VERSION', |
23 NETWORK_FAILURE: /*i18n-content*/'ERROR_NETWORK_FAILURE', | 23 NETWORK_FAILURE: /*i18n-content*/'ERROR_NETWORK_FAILURE', |
24 HOST_OVERLOAD: /*i18n-content*/'ERROR_HOST_OVERLOAD', | 24 HOST_OVERLOAD: /*i18n-content*/'ERROR_HOST_OVERLOAD', |
25 UNEXPECTED: /*i18n-content*/'ERROR_UNEXPECTED', | 25 UNEXPECTED: /*i18n-content*/'ERROR_UNEXPECTED', |
26 SERVICE_UNAVAILABLE: /*i18n-content*/'ERROR_SERVICE_UNAVAILABLE', | 26 SERVICE_UNAVAILABLE: /*i18n-content*/'ERROR_SERVICE_UNAVAILABLE', |
27 NOT_AUTHENTICATED: /*i18n-content*/'ERROR_NOT_AUTHENTICATED', | 27 NOT_AUTHENTICATED: /*i18n-content*/'ERROR_NOT_AUTHENTICATED', |
28 INVALID_HOST_DOMAIN: /*i18n-content*/'ERROR_INVALID_HOST_DOMAIN' | 28 INVALID_HOST_DOMAIN: /*i18n-content*/'ERROR_INVALID_HOST_DOMAIN' |
29 }; | 29 }; |
30 | 30 |
31 /** | 31 /** |
| 32 * Show the authorization consent UI and register a one-shot event handler to |
| 33 * continue the authorization process. |
| 34 * |
| 35 * @param {function():void} authContinue Callback to invoke when the user |
| 36 * clicks "Continue". |
| 37 */ |
| 38 function consentRequired_(authContinue) { |
| 39 /** @type {HTMLElement} */ |
| 40 var dialog = document.getElementById('auth-dialog'); |
| 41 /** @type {HTMLElement} */ |
| 42 var button = document.getElementById('auth-button'); |
| 43 var consentGranted = function(event) { |
| 44 dialog.hidden = true; |
| 45 button.removeEventListener('click', consentGranted, false); |
| 46 authContinue(); |
| 47 }; |
| 48 dialog.hidden = false; |
| 49 button.addEventListener('click', consentGranted, false); |
| 50 } |
| 51 |
| 52 /** |
32 * Entry point for app initialization. | 53 * Entry point for app initialization. |
33 */ | 54 */ |
34 remoting.init = function() { | 55 remoting.init = function() { |
35 // TODO(jamiewalch): Remove this when we migrate to apps v2. | 56 // TODO(jamiewalch): Remove this when we migrate to apps v2 |
| 57 // (http://crbug.com/ 134213). |
36 remoting.initMockStorage(); | 58 remoting.initMockStorage(); |
37 | 59 |
38 remoting.logExtensionInfoAsync_(); | 60 remoting.logExtensionInfoAsync_(); |
39 l10n.localize(); | 61 l10n.localize(); |
40 // Create global objects. | 62 // Create global objects. |
41 remoting.oauth2 = new remoting.OAuth2(); | 63 remoting.oauth2 = new remoting.OAuth2(); |
| 64 // TODO(jamiewalch): Reinstate this when we migrate to apps v2 |
| 65 // (http://crbug.com/ 134213). |
| 66 // remoting.identity = new remoting.Identity(consentRequired_); |
| 67 remoting.identity = remoting.oauth2; |
42 remoting.stats = new remoting.ConnectionStats( | 68 remoting.stats = new remoting.ConnectionStats( |
43 document.getElementById('statistics')); | 69 document.getElementById('statistics')); |
44 remoting.formatIq = new remoting.FormatIq(); | 70 remoting.formatIq = new remoting.FormatIq(); |
45 remoting.hostList = new remoting.HostList( | 71 remoting.hostList = new remoting.HostList( |
46 document.getElementById('host-list'), | 72 document.getElementById('host-list'), |
47 document.getElementById('host-list-empty'), | 73 document.getElementById('host-list-empty'), |
48 document.getElementById('host-list-error-message'), | 74 document.getElementById('host-list-error-message'), |
49 document.getElementById('host-list-refresh-failed-button')); | 75 document.getElementById('host-list-refresh-failed-button')); |
50 remoting.toolbar = new remoting.Toolbar( | 76 remoting.toolbar = new remoting.Toolbar( |
51 document.getElementById('session-toolbar')); | 77 document.getElementById('session-toolbar')); |
52 remoting.clipboard = new remoting.Clipboard(); | 78 remoting.clipboard = new remoting.Clipboard(); |
53 remoting.suspendMonitor = new remoting.SuspendMonitor( | 79 remoting.suspendMonitor = new remoting.SuspendMonitor( |
54 function() { | 80 function() { |
55 if (remoting.clientSession) { | 81 if (remoting.clientSession) { |
56 remoting.clientSession.logErrors(false); | 82 remoting.clientSession.logErrors(false); |
57 } | 83 } |
58 } | 84 } |
59 ); | 85 ); |
60 | 86 |
61 remoting.oauth2.getEmail(remoting.onEmail, remoting.showErrorMessage); | 87 remoting.identity.getEmail(remoting.onEmail, remoting.showErrorMessage); |
62 | 88 |
63 remoting.showOrHideIt2MeUi(); | 89 remoting.showOrHideIt2MeUi(); |
64 remoting.showOrHideMe2MeUi(); | 90 remoting.showOrHideMe2MeUi(); |
65 | 91 |
66 // The plugin's onFocus handler sends a paste command to |window|, because | 92 // The plugin's onFocus handler sends a paste command to |window|, because |
67 // it can't send one to the plugin element itself. | 93 // it can't send one to the plugin element itself. |
68 window.addEventListener('paste', pluginGotPaste_, false); | 94 window.addEventListener('paste', pluginGotPaste_, false); |
69 window.addEventListener('copy', pluginGotCopy_, false); | 95 window.addEventListener('copy', pluginGotCopy_, false); |
70 | 96 |
71 remoting.initModalDialogs(); | 97 remoting.initModalDialogs(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 document.getElementById('get-started-it2me').disabled = false; | 132 document.getElementById('get-started-it2me').disabled = false; |
107 document.getElementById('get-started-me2me').disabled = false; | 133 document.getElementById('get-started-me2me').disabled = false; |
108 }; | 134 }; |
109 | 135 |
110 // initDaemonUi is called if the app is not starting up in session mode, and | 136 // initDaemonUi is called if the app is not starting up in session mode, and |
111 // also if the user cancels pin entry or the connection in session mode. | 137 // also if the user cancels pin entry or the connection in session mode. |
112 remoting.initDaemonUi = function () { | 138 remoting.initDaemonUi = function () { |
113 remoting.hostController = new remoting.HostController(); | 139 remoting.hostController = new remoting.HostController(); |
114 document.getElementById('share-button').disabled = | 140 document.getElementById('share-button').disabled = |
115 !remoting.hostController.isPluginSupported(); | 141 !remoting.hostController.isPluginSupported(); |
116 remoting.setMode(getAppStartupMode_()); | 142 remoting.setMode(remoting.AppMode.HOME); |
| 143 if (!remoting.oauth2.isAuthenticated()) { |
| 144 document.getElementById('auth-dialog').hidden = false; |
| 145 } |
117 remoting.hostSetupDialog = | 146 remoting.hostSetupDialog = |
118 new remoting.HostSetupDialog(remoting.hostController); | 147 new remoting.HostSetupDialog(remoting.hostController); |
119 // Display the cached host list, then asynchronously update and re-display it. | 148 // Display the cached host list, then asynchronously update and re-display it. |
120 remoting.updateLocalHostState(); | 149 remoting.updateLocalHostState(); |
121 remoting.hostList.refresh(remoting.updateLocalHostState); | 150 remoting.hostList.refresh(remoting.updateLocalHostState); |
122 }; | 151 }; |
123 | 152 |
124 /** | 153 /** |
125 * Fetches local host state and updates host list accordingly. | 154 * Fetches local host state and updates host list accordingly. |
126 */ | 155 */ |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 212 |
184 /** | 213 /** |
185 * Sign the user out of Chromoting by clearing (and revoking, if possible) the | 214 * Sign the user out of Chromoting by clearing (and revoking, if possible) the |
186 * OAuth refresh token. | 215 * OAuth refresh token. |
187 * | 216 * |
188 * Also clear all local storage, to avoid leaking information. | 217 * Also clear all local storage, to avoid leaking information. |
189 */ | 218 */ |
190 remoting.signOut = function() { | 219 remoting.signOut = function() { |
191 remoting.oauth2.clear(); | 220 remoting.oauth2.clear(); |
192 chrome.storage.local.clear(); | 221 chrome.storage.local.clear(); |
193 remoting.setMode(remoting.AppMode.UNAUTHENTICATED); | 222 remoting.setMode(remoting.AppMode.HOME); |
| 223 document.getElementById('auth-dialog').hidden = false; |
194 }; | 224 }; |
195 | 225 |
196 /** | 226 /** |
197 * Returns whether the app is running on ChromeOS. | 227 * Returns whether the app is running on ChromeOS. |
198 * | 228 * |
199 * @return {boolean} True if the app is running on ChromeOS. | 229 * @return {boolean} True if the app is running on ChromeOS. |
200 */ | 230 */ |
201 remoting.runningOnChromeOS = function() { | 231 remoting.runningOnChromeOS = function() { |
202 return !!navigator.userAgent.match(/\bCrOS\b/); | 232 return !!navigator.userAgent.match(/\bCrOS\b/); |
203 } | 233 } |
(...skipping 21 matching lines...) Expand all Loading... |
225 var event = /** @type {remoting.ClipboardEvent} */ eventUncast; | 255 var event = /** @type {remoting.ClipboardEvent} */ eventUncast; |
226 if (event && event.clipboardData) { | 256 if (event && event.clipboardData) { |
227 if (remoting.clipboard.toOs(event.clipboardData)) { | 257 if (remoting.clipboard.toOs(event.clipboardData)) { |
228 // The default action may overwrite items that we added to clipboardData. | 258 // The default action may overwrite items that we added to clipboardData. |
229 event.preventDefault(); | 259 event.preventDefault(); |
230 } | 260 } |
231 } | 261 } |
232 } | 262 } |
233 | 263 |
234 /** | 264 /** |
235 * Gets the major-mode that this application should start up in. | |
236 * | |
237 * @return {remoting.AppMode} The mode to start in. | |
238 */ | |
239 function getAppStartupMode_() { | |
240 if (!remoting.oauth2.isAuthenticated()) { | |
241 return remoting.AppMode.UNAUTHENTICATED; | |
242 } | |
243 return remoting.AppMode.HOME; | |
244 } | |
245 | |
246 /** | |
247 * Returns whether Host mode is supported on this platform. | 265 * Returns whether Host mode is supported on this platform. |
248 * | 266 * |
249 * @return {boolean} True if Host mode is supported. | 267 * @return {boolean} True if Host mode is supported. |
250 */ | 268 */ |
251 function isHostModeSupported_() { | 269 function isHostModeSupported_() { |
252 // Currently, sharing on Chromebooks is not supported. | 270 // Currently, sharing on Chromebooks is not supported. |
253 return !remoting.runningOnChromeOS(); | 271 return !remoting.runningOnChromeOS(); |
254 } | 272 } |
255 | 273 |
256 /** | 274 /** |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 */ | 331 */ |
314 remoting.showErrorMessage = function(error) { | 332 remoting.showErrorMessage = function(error) { |
315 l10n.localizeElementFromTag( | 333 l10n.localizeElementFromTag( |
316 document.getElementById('token-refresh-error-message'), | 334 document.getElementById('token-refresh-error-message'), |
317 error); | 335 error); |
318 var auth_failed = (error == remoting.Error.AUTHENTICATION_FAILED); | 336 var auth_failed = (error == remoting.Error.AUTHENTICATION_FAILED); |
319 document.getElementById('token-refresh-auth-failed').hidden = !auth_failed; | 337 document.getElementById('token-refresh-auth-failed').hidden = !auth_failed; |
320 document.getElementById('token-refresh-other-error').hidden = auth_failed; | 338 document.getElementById('token-refresh-other-error').hidden = auth_failed; |
321 remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED); | 339 remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED); |
322 }; | 340 }; |
OLD | NEW |