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

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

Issue 11769002: Apps v2 identity integration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reviewer comments. Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
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
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 consent UI and register a one-shot event handler to continue
Wez 2013/01/07 23:52:44 nit: consent -> authorization consent
Jamie 2013/01/08 22:09:10 Done.
33 * 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.
36 remoting.initMockStorage(); 57 remoting.initMockStorage();
37 58
38 remoting.logExtensionInfoAsync_(); 59 remoting.logExtensionInfoAsync_();
39 l10n.localize(); 60 l10n.localize();
40 // Create global objects. 61 // Create global objects.
41 remoting.oauth2 = new remoting.OAuth2(); 62 remoting.oauth2 = new remoting.OAuth2();
63 // TODO(jamiewalch): Reinstate this when we migrate to apps v2.
Wez 2013/01/07 23:52:44 nit: Reference the v2 app bug.
Jamie 2013/01/08 22:09:10 Done, here and elsewhere.
64 // remoting.identity = new remoting.Identity(consentRequired_);
65 remoting.identity = remoting.oauth2;
42 remoting.stats = new remoting.ConnectionStats( 66 remoting.stats = new remoting.ConnectionStats(
43 document.getElementById('statistics')); 67 document.getElementById('statistics'));
44 remoting.formatIq = new remoting.FormatIq(); 68 remoting.formatIq = new remoting.FormatIq();
45 remoting.hostList = new remoting.HostList( 69 remoting.hostList = new remoting.HostList(
46 document.getElementById('host-list'), 70 document.getElementById('host-list'),
47 document.getElementById('host-list-empty'), 71 document.getElementById('host-list-empty'),
48 document.getElementById('host-list-error-message'), 72 document.getElementById('host-list-error-message'),
49 document.getElementById('host-list-refresh-failed-button')); 73 document.getElementById('host-list-refresh-failed-button'));
50 remoting.toolbar = new remoting.Toolbar( 74 remoting.toolbar = new remoting.Toolbar(
51 document.getElementById('session-toolbar')); 75 document.getElementById('session-toolbar'));
52 remoting.clipboard = new remoting.Clipboard(); 76 remoting.clipboard = new remoting.Clipboard();
53 remoting.suspendMonitor = new remoting.SuspendMonitor( 77 remoting.suspendMonitor = new remoting.SuspendMonitor(
54 function() { 78 function() {
55 if (remoting.clientSession) { 79 if (remoting.clientSession) {
56 remoting.clientSession.logErrors(false); 80 remoting.clientSession.logErrors(false);
57 } 81 }
58 } 82 }
59 ); 83 );
60 84
61 remoting.oauth2.getEmail(remoting.onEmail, remoting.showErrorMessage); 85 remoting.identity.getEmail(remoting.onEmail, remoting.showErrorMessage);
62 86
63 remoting.showOrHideIt2MeUi(); 87 remoting.showOrHideIt2MeUi();
64 remoting.showOrHideMe2MeUi(); 88 remoting.showOrHideMe2MeUi();
65 89
66 // The plugin's onFocus handler sends a paste command to |window|, because 90 // The plugin's onFocus handler sends a paste command to |window|, because
67 // it can't send one to the plugin element itself. 91 // it can't send one to the plugin element itself.
68 window.addEventListener('paste', pluginGotPaste_, false); 92 window.addEventListener('paste', pluginGotPaste_, false);
69 window.addEventListener('copy', pluginGotCopy_, false); 93 window.addEventListener('copy', pluginGotCopy_, false);
70 94
71 remoting.initModalDialogs(); 95 remoting.initModalDialogs();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 document.getElementById('get-started-it2me').disabled = false; 130 document.getElementById('get-started-it2me').disabled = false;
107 document.getElementById('get-started-me2me').disabled = false; 131 document.getElementById('get-started-me2me').disabled = false;
108 }; 132 };
109 133
110 // initDaemonUi is called if the app is not starting up in session mode, and 134 // 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. 135 // also if the user cancels pin entry or the connection in session mode.
112 remoting.initDaemonUi = function () { 136 remoting.initDaemonUi = function () {
113 remoting.hostController = new remoting.HostController(); 137 remoting.hostController = new remoting.HostController();
114 document.getElementById('share-button').disabled = 138 document.getElementById('share-button').disabled =
115 !remoting.hostController.isPluginSupported(); 139 !remoting.hostController.isPluginSupported();
116 remoting.setMode(getAppStartupMode_()); 140 remoting.setMode(remoting.AppMode.HOME);
141 if (!remoting.oauth2.isAuthenticated()) {
142 document.getElementById('auth-dialog').hidden = false;
143 }
117 remoting.hostSetupDialog = 144 remoting.hostSetupDialog =
118 new remoting.HostSetupDialog(remoting.hostController); 145 new remoting.HostSetupDialog(remoting.hostController);
119 // Display the cached host list, then asynchronously update and re-display it. 146 // Display the cached host list, then asynchronously update and re-display it.
120 remoting.updateLocalHostState(); 147 remoting.updateLocalHostState();
121 remoting.hostList.refresh(remoting.updateLocalHostState); 148 remoting.hostList.refresh(remoting.updateLocalHostState);
122 }; 149 };
123 150
124 /** 151 /**
125 * Fetches local host state and updates host list accordingly. 152 * Fetches local host state and updates host list accordingly.
126 */ 153 */
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 } 208 }
182 }; 209 };
183 210
184 /** 211 /**
185 * Sign the user out of Chromoting by clearing (and revoking, if possible) the 212 * Sign the user out of Chromoting by clearing (and revoking, if possible) the
186 * OAuth refresh token. 213 * OAuth refresh token.
187 * 214 *
188 * Also clear all local storage, to avoid leaking information. 215 * Also clear all local storage, to avoid leaking information.
189 */ 216 */
190 remoting.signOut = function() { 217 remoting.signOut = function() {
191 remoting.oauth2.clear(); 218 remoting.oauth2.clear();
rmsousa 2013/01/05 05:21:11 What are we planning to do here for appsv2? experi
Wez 2013/01/07 23:52:44 Token revocation is much less critical in this cas
Jamie 2013/01/08 22:09:10 I think we'll eventually remove the option from th
192 chrome.storage.local.clear(); 219 chrome.storage.local.clear();
193 remoting.setMode(remoting.AppMode.UNAUTHENTICATED); 220 remoting.setMode(remoting.AppMode.HOME);
221 document.getElementById('auth-dialog').hidden = false;
194 }; 222 };
195 223
196 /** 224 /**
197 * Returns whether the app is running on ChromeOS. 225 * Returns whether the app is running on ChromeOS.
198 * 226 *
199 * @return {boolean} True if the app is running on ChromeOS. 227 * @return {boolean} True if the app is running on ChromeOS.
200 */ 228 */
201 remoting.runningOnChromeOS = function() { 229 remoting.runningOnChromeOS = function() {
202 return !!navigator.userAgent.match(/\bCrOS\b/); 230 return !!navigator.userAgent.match(/\bCrOS\b/);
203 } 231 }
(...skipping 21 matching lines...) Expand all
225 var event = /** @type {remoting.ClipboardEvent} */ eventUncast; 253 var event = /** @type {remoting.ClipboardEvent} */ eventUncast;
226 if (event && event.clipboardData) { 254 if (event && event.clipboardData) {
227 if (remoting.clipboard.toOs(event.clipboardData)) { 255 if (remoting.clipboard.toOs(event.clipboardData)) {
228 // The default action may overwrite items that we added to clipboardData. 256 // The default action may overwrite items that we added to clipboardData.
229 event.preventDefault(); 257 event.preventDefault();
230 } 258 }
231 } 259 }
232 } 260 }
233 261
234 /** 262 /**
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. 263 * Returns whether Host mode is supported on this platform.
248 * 264 *
249 * @return {boolean} True if Host mode is supported. 265 * @return {boolean} True if Host mode is supported.
250 */ 266 */
251 function isHostModeSupported_() { 267 function isHostModeSupported_() {
252 // Currently, sharing on Chromebooks is not supported. 268 // Currently, sharing on Chromebooks is not supported.
253 return !remoting.runningOnChromeOS(); 269 return !remoting.runningOnChromeOS();
254 } 270 }
255 271
256 /** 272 /**
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 */ 329 */
314 remoting.showErrorMessage = function(error) { 330 remoting.showErrorMessage = function(error) {
315 l10n.localizeElementFromTag( 331 l10n.localizeElementFromTag(
316 document.getElementById('token-refresh-error-message'), 332 document.getElementById('token-refresh-error-message'),
317 error); 333 error);
318 var auth_failed = (error == remoting.Error.AUTHENTICATION_FAILED); 334 var auth_failed = (error == remoting.Error.AUTHENTICATION_FAILED);
319 document.getElementById('token-refresh-auth-failed').hidden = !auth_failed; 335 document.getElementById('token-refresh-auth-failed').hidden = !auth_failed;
320 document.getElementById('token-refresh-other-error').hidden = auth_failed; 336 document.getElementById('token-refresh-other-error').hidden = auth_failed;
321 remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED); 337 remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED);
322 }; 338 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698