Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Functions related to the 'client screen' for Chromoting. | 7 * Functions related to the 'client screen' for Chromoting. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 */ | 40 */ |
| 41 remoting.hostPublicKey = ''; | 41 remoting.hostPublicKey = ''; |
| 42 | 42 |
| 43 /** | 43 /** |
| 44 * @type {XMLHttpRequest} The XHR object corresponding to the current | 44 * @type {XMLHttpRequest} The XHR object corresponding to the current |
| 45 * support-hosts request, if there is one outstanding. | 45 * support-hosts request, if there is one outstanding. |
| 46 */ | 46 */ |
| 47 remoting.supportHostsXhr_ = null; | 47 remoting.supportHostsXhr_ = null; |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * @enum {string} | |
| 51 */ | |
| 52 remoting.ConnectionType = { | |
| 53 It2Me: 'It2Me', | |
| 54 Me2Me: 'Me2Me' | |
| 55 }; | |
| 56 | |
| 57 /** | |
| 58 * @type {remoting.ConnectionType?} | |
| 59 */ | |
| 60 remoting.currentConnectionType = null; | |
| 61 | |
| 62 /** | |
| 50 * Entry point for the 'connect' functionality. This function checks for the | 63 * Entry point for the 'connect' functionality. This function checks for the |
| 51 * existence of an OAuth2 token, and either requests one asynchronously, or | 64 * existence of an OAuth2 token, and either requests one asynchronously, or |
| 52 * calls through directly to tryConnectWithAccessToken_. | 65 * calls through directly to tryConnectWithAccessToken_. |
| 53 */ | 66 */ |
| 54 remoting.tryConnect = function() { | 67 remoting.tryConnect = function() { |
| 55 document.getElementById('cancel-button').disabled = false; | 68 document.getElementById('cancel-button').disabled = false; |
| 56 if (remoting.oauth2.needsNewAccessToken()) { | 69 if (remoting.oauth2.needsNewAccessToken()) { |
| 57 remoting.oauth2.refreshAccessToken(function(xhr) { | 70 remoting.oauth2.refreshAccessToken(function(xhr) { |
| 58 if (remoting.oauth2.needsNewAccessToken()) { | 71 if (remoting.oauth2.needsNewAccessToken()) { |
| 59 // Failed to get access token | 72 // Failed to get access token |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 /** | 129 /** |
| 117 * Disconnect the remoting client. | 130 * Disconnect the remoting client. |
| 118 * | 131 * |
| 119 * @return {void} Nothing. | 132 * @return {void} Nothing. |
| 120 */ | 133 */ |
| 121 remoting.disconnect = function() { | 134 remoting.disconnect = function() { |
| 122 if (remoting.clientSession) { | 135 if (remoting.clientSession) { |
| 123 remoting.clientSession.disconnect(); | 136 remoting.clientSession.disconnect(); |
| 124 remoting.clientSession = null; | 137 remoting.clientSession = null; |
| 125 remoting.debug.log('Disconnected.'); | 138 remoting.debug.log('Disconnected.'); |
| 126 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED); | 139 if (remoting.currentConnectionType == remoting.ConnectionType.It2Me) { |
| 140 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); | |
| 141 } else { | |
| 142 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); | |
| 143 } | |
| 127 } | 144 } |
| 128 } | 145 } |
| 129 | 146 |
| 130 /** | 147 /** |
| 131 * Second stage of the 'connect' functionality. Once an access token is | 148 * Second stage of the 'connect' functionality. Once an access token is |
| 132 * available, load the WCS widget asynchronously and call through to | 149 * available, load the WCS widget asynchronously and call through to |
| 133 * tryConnectWithWcs_ when ready. | 150 * tryConnectWithWcs_ when ready. |
| 134 */ | 151 */ |
| 135 function tryConnectWithAccessToken_() { | 152 function tryConnectWithAccessToken_() { |
| 136 if (!remoting.wcsLoader) { | 153 if (!remoting.wcsLoader) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 159 // At present, only 12-digit access codes are supported, of which the first | 176 // At present, only 12-digit access codes are supported, of which the first |
| 160 // 7 characters are the supportId. | 177 // 7 characters are the supportId. |
| 161 var kSupportIdLen = 7; | 178 var kSupportIdLen = 7; |
| 162 var kHostSecretLen = 5; | 179 var kHostSecretLen = 5; |
| 163 var kAccessCodeLen = kSupportIdLen + kHostSecretLen; | 180 var kAccessCodeLen = kSupportIdLen + kHostSecretLen; |
| 164 if (remoting.accessCode.length != kAccessCodeLen) { | 181 if (remoting.accessCode.length != kAccessCodeLen) { |
| 165 remoting.debug.log('Bad access code length'); | 182 remoting.debug.log('Bad access code length'); |
| 166 showConnectError_(remoting.Error.INVALID_ACCESS_CODE); | 183 showConnectError_(remoting.Error.INVALID_ACCESS_CODE); |
| 167 } else { | 184 } else { |
| 168 var supportId = remoting.accessCode.substring(0, kSupportIdLen); | 185 var supportId = remoting.accessCode.substring(0, kSupportIdLen); |
| 186 remoting.currentConnectionType = remoting.ConnectionType.It2Me; | |
| 169 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | 187 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); |
| 170 resolveSupportId(supportId); | 188 resolveSupportId(supportId); |
| 171 } | 189 } |
| 172 } else { | 190 } else { |
| 173 showConnectError_(remoting.Error.AUTHENTICATION_FAILED); | 191 showConnectError_(remoting.Error.AUTHENTICATION_FAILED); |
| 174 } | 192 } |
| 175 } | 193 } |
| 176 | 194 |
| 177 /** | 195 /** |
| 178 * Callback function called when the state of the client plugin changes. The | 196 * Callback function called when the state of the client plugin changes. The |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 207 recenterToolbar_(); | 225 recenterToolbar_(); |
| 208 showToolbarPreview_(); | 226 showToolbarPreview_(); |
| 209 updateStatistics_(); | 227 updateStatistics_(); |
| 210 } | 228 } |
| 211 | 229 |
| 212 } else if (newState == remoting.ClientSession.State.CLOSED) { | 230 } else if (newState == remoting.ClientSession.State.CLOSED) { |
| 213 if (oldState == remoting.ClientSession.State.CONNECTED) { | 231 if (oldState == remoting.ClientSession.State.CONNECTED) { |
| 214 remoting.clientSession.removePlugin(); | 232 remoting.clientSession.removePlugin(); |
| 215 remoting.clientSession = null; | 233 remoting.clientSession = null; |
| 216 remoting.debug.log('Connection closed by host'); | 234 remoting.debug.log('Connection closed by host'); |
| 217 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED); | 235 if (remoting.currentConnectionType == remoting.ConnectionType.It2Me) { |
| 236 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_IT2ME); | |
| 237 } else { | |
| 238 remoting.setMode(remoting.AppMode.CLIENT_SESSION_FINISHED_ME2ME); | |
| 239 } | |
| 218 } else { | 240 } else { |
| 219 // The transition from CONNECTING to CLOSED state may happen | 241 // The transition from CONNECTING to CLOSED state may happen |
| 220 // only with older client plugins. Current version should go the | 242 // only with older client plugins. Current version should go the |
| 221 // FAILED state when connection fails. | 243 // FAILED state when connection fails. |
| 222 showConnectError_(remoting.Error.INVALID_ACCESS_CODE); | 244 showConnectError_(remoting.Error.INVALID_ACCESS_CODE); |
| 223 } | 245 } |
| 224 | 246 |
| 225 } else if (newState == remoting.ClientSession.State.CONNECTION_FAILED) { | 247 } else if (newState == remoting.ClientSession.State.CONNECTION_FAILED) { |
| 226 remoting.debug.log('Client plugin reported connection failed: ' + | 248 remoting.debug.log('Client plugin reported connection failed: ' + |
| 227 remoting.clientSession.error); | 249 remoting.clientSession.error); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 */ | 304 */ |
| 283 function showConnectError_(errorTag) { | 305 function showConnectError_(errorTag) { |
| 284 remoting.debug.log('Connection failed: ' + errorTag); | 306 remoting.debug.log('Connection failed: ' + errorTag); |
| 285 var errorDiv = document.getElementById('connect-error-message'); | 307 var errorDiv = document.getElementById('connect-error-message'); |
| 286 l10n.localizeElementFromTag(errorDiv, /** @type {string} */ (errorTag)); | 308 l10n.localizeElementFromTag(errorDiv, /** @type {string} */ (errorTag)); |
| 287 remoting.accessCode = ''; | 309 remoting.accessCode = ''; |
| 288 if (remoting.clientSession) { | 310 if (remoting.clientSession) { |
| 289 remoting.clientSession.disconnect(); | 311 remoting.clientSession.disconnect(); |
| 290 remoting.clientSession = null; | 312 remoting.clientSession = null; |
| 291 } | 313 } |
| 292 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED); | 314 if (remoting.currentConnectionType == remoting.ConnectionType.It2Me) { |
| 315 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME); | |
| 316 } else { | |
| 317 remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED_ME2ME); | |
| 318 } | |
| 293 } | 319 } |
| 294 | 320 |
| 295 /** | 321 /** |
| 296 * Parse the response from the server to a request to resolve a support id. | 322 * Parse the response from the server to a request to resolve a support id. |
| 297 * | 323 * |
| 298 * @param {XMLHttpRequest} xhr The XMLHttpRequest object. | 324 * @param {XMLHttpRequest} xhr The XMLHttpRequest object. |
| 299 * @return {void} Nothing. | 325 * @return {void} Nothing. |
| 300 */ | 326 */ |
| 301 function parseServerResponse_(xhr) { | 327 function parseServerResponse_(xhr) { |
| 302 remoting.supportHostsXhr_ = null; | 328 remoting.supportHostsXhr_ = null; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 */ | 407 */ |
| 382 function recenterToolbar_() { | 408 function recenterToolbar_() { |
| 383 var toolbar = document.getElementById('session-toolbar'); | 409 var toolbar = document.getElementById('session-toolbar'); |
| 384 var toolbarX = (window.innerWidth - toolbar.clientWidth) / 2; | 410 var toolbarX = (window.innerWidth - toolbar.clientWidth) / 2; |
| 385 toolbar.style['left'] = toolbarX + 'px'; | 411 toolbar.style['left'] = toolbarX + 'px'; |
| 386 } | 412 } |
| 387 | 413 |
| 388 /** | 414 /** |
| 389 * Start a connection to the specified host, using the stored details. | 415 * Start a connection to the specified host, using the stored details. |
| 390 * | 416 * |
| 391 * @param {string} hostId The Id of the host to connect to. | 417 * @param {string} hostJid The jabber Id of the host. |
| 418 * @param {string} hostPublicKey The public key of the host. | |
| 419 * @param {string} hostName The name of the host. | |
| 392 * @return {void} Nothing. | 420 * @return {void} Nothing. |
| 393 */ | 421 */ |
| 394 remoting.connectHost = function(hostId) { | 422 remoting.connectHost = function(hostJid, hostPublicKey, hostName) { |
| 395 var hostTableEntry = remoting.hostList.getHostForId(hostId); | 423 // TODO(jamiewalch): Instead of passing the jid in the URL, cache it in local |
| 396 if (!hostTableEntry) { | 424 // storage so that host bookmarks can be implemented efficiently. |
| 397 console.error('connectHost: Unrecognised hostId: ' + hostId); | 425 remoting.hostJid = hostJid; |
| 398 return; | 426 remoting.hostPublicKey = hostPublicKey; |
| 399 } | 427 document.getElementById('connected-to').innerText = hostName; |
| 400 | 428 document.title = document.title + ': ' + hostName; |
| 401 remoting.hostJid = hostTableEntry.host.jabberId; | |
| 402 remoting.hostPublicKey = hostTableEntry.host.publicKey; | |
| 403 document.getElementById('connected-to').innerText = | |
| 404 hostTableEntry.host.hostName; | |
| 405 | 429 |
| 406 remoting.debug.log('Connecting to host...'); | 430 remoting.debug.log('Connecting to host...'); |
| 431 remoting.currentConnectionType = remoting.ConnectionType.Me2Me; | |
| 432 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | |
| 407 | 433 |
| 408 if (!remoting.wcsLoader) { | 434 if (!remoting.wcsLoader) { |
| 409 remoting.wcsLoader = new remoting.WcsLoader(); | 435 remoting.wcsLoader = new remoting.WcsLoader(); |
| 410 } | 436 } |
| 411 /** @param {function(string):void} setToken The callback function. */ | 437 /** @param {function(string):void} setToken The callback function. */ |
| 412 var callWithToken = function(setToken) { | 438 var callWithToken = function(setToken) { |
| 413 remoting.oauth2.callWithToken(setToken); | 439 remoting.oauth2.callWithToken(setToken); |
| 414 }; | 440 }; |
| 415 remoting.wcsLoader.start( | 441 remoting.wcsLoader.startAsync(callWithToken, remoting.connectHostWithWcs); |
|
Jamie
2011/11/30 21:23:43
The token might not be valid any more, especially
| |
| 416 remoting.oauth2.getAccessToken(), | |
| 417 callWithToken, | |
| 418 remoting.connectHostWithWcs); | |
| 419 } | 442 } |
| 420 | 443 |
| 421 /** | 444 /** |
| 422 * Continue making the connection to a host, once WCS has initialized. | 445 * Continue making the connection to a host, once WCS has initialized. |
| 423 * | 446 * |
| 424 * @return {void} Nothing. | 447 * @return {void} Nothing. |
| 425 */ | 448 */ |
| 426 remoting.connectHostWithWcs = function() { | 449 remoting.connectHostWithWcs = function() { |
| 427 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | |
|
Jamie
2011/11/30 21:23:43
I'm not sure why this was being done so late in th
| |
| 428 | |
| 429 remoting.clientSession = | 450 remoting.clientSession = |
| 430 new remoting.ClientSession( | 451 new remoting.ClientSession( |
| 431 remoting.hostJid, remoting.hostPublicKey, | 452 remoting.hostJid, remoting.hostPublicKey, |
| 432 '', /** @type {string} */ (remoting.oauth2.getCachedEmail()), | 453 '', /** @type {string} */ (remoting.oauth2.getCachedEmail()), |
| 433 onClientStateChange_); | 454 onClientStateChange_); |
| 434 /** @param {string} token The auth token. */ | 455 /** @param {string} token The auth token. */ |
| 435 var createPluginAndConnect = function(token) { | 456 var createPluginAndConnect = function(token) { |
| 436 remoting.clientSession.createPluginAndConnect( | 457 remoting.clientSession.createPluginAndConnect( |
| 437 document.getElementById('session-mode'), | 458 document.getElementById('session-mode'), |
| 438 token); | 459 token); |
| 439 }; | 460 }; |
| 440 | 461 |
| 441 remoting.setMode(remoting.AppMode.CLIENT_CONNECTING); | |
| 442 remoting.oauth2.callWithToken(createPluginAndConnect); | 462 remoting.oauth2.callWithToken(createPluginAndConnect); |
| 443 } | 463 } |
| 444 | 464 |
| 445 }()); | 465 }()); |
| OLD | NEW |