| 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * Class handling creation and teardown of a remoting client session. | 7 * Class handling creation and teardown of a remoting client session. |
| 8 * | 8 * |
| 9 * The ClientSession class controls lifetime of the client plugin | 9 * The ClientSession class controls lifetime of the client plugin |
| 10 * object and provides the plugin with the functionality it needs to | 10 * object and provides the plugin with the functionality it needs to |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 * to the host. | 27 * to the host. |
| 28 * | 28 * |
| 29 * @const | 29 * @const |
| 30 * @type {number} | 30 * @type {number} |
| 31 */ | 31 */ |
| 32 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS = 15 * 60 * 1000; | 32 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS = 15 * 60 * 1000; |
| 33 | 33 |
| 34 /** | 34 /** |
| 35 * @param {remoting.Host} host The host to connect to. | 35 * @param {remoting.Host} host The host to connect to. |
| 36 * @param {remoting.SignalStrategy} signalStrategy Signal strategy. | 36 * @param {remoting.SignalStrategy} signalStrategy Signal strategy. |
| 37 * @param {remoting.CredentialsProvider} credentialsProvider |
| 38 * The credentialsProvider to authenticate the client with the host. |
| 37 * @param {HTMLElement} container Container element for the client view. | 39 * @param {HTMLElement} container Container element for the client view. |
| 38 * @param {string} accessCode The IT2Me access code. Blank for Me2Me. | |
| 39 * @param {function(boolean, function(string): void): void} fetchPin | |
| 40 * Called by Me2Me connections when a PIN needs to be obtained | |
| 41 * interactively. | |
| 42 * @param {function(string, string, string, | |
| 43 * function(string, string): void): void} | |
| 44 * fetchThirdPartyToken Called by Me2Me connections when a third party | |
| 45 * authentication token must be obtained. | |
| 46 * @param {string} authenticationMethods Comma-separated list of | |
| 47 * authentication methods the client should attempt to use. | |
| 48 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection. | 40 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection. |
| 49 * @param {string} clientPairingId For paired Me2Me connections, the | |
| 50 * pairing id for this client, as issued by the host. | |
| 51 * @param {string} clientPairedSecret For paired Me2Me connections, the | |
| 52 * paired secret for this client, as issued by the host. | |
| 53 * @param {string} defaultRemapKeys The default set of remap keys, to use | 41 * @param {string} defaultRemapKeys The default set of remap keys, to use |
| 54 * when the client doesn't define any. | 42 * when the client doesn't define any. |
| 55 * @constructor | 43 * @constructor |
| 56 * @extends {base.EventSourceImpl} | 44 * @extends {base.EventSourceImpl} |
| 57 */ | 45 */ |
| 58 remoting.ClientSession = function(host, signalStrategy, container, accessCode, | 46 remoting.ClientSession = function(host, signalStrategy, credentialsProvider, |
| 59 fetchPin, fetchThirdPartyToken, | 47 container, mode, defaultRemapKeys) { |
| 60 authenticationMethods, mode, clientPairingId, | |
| 61 clientPairedSecret, defaultRemapKeys) { | |
| 62 /** @private */ | 48 /** @private */ |
| 63 this.state_ = remoting.ClientSession.State.CREATED; | 49 this.state_ = remoting.ClientSession.State.CREATED; |
| 64 | 50 |
| 65 /** @private */ | 51 /** @private */ |
| 66 this.error_ = remoting.Error.NONE; | 52 this.error_ = remoting.Error.NONE; |
| 67 | 53 |
| 68 /** @private */ | 54 /** @private */ |
| 69 this.host_ = host; | 55 this.host_ = host; |
| 56 |
| 70 /** @private */ | 57 /** @private */ |
| 71 this.accessCode_ = accessCode; | 58 this.credentialsProvider_ = credentialsProvider; |
| 72 /** @private */ | |
| 73 this.fetchPin_ = fetchPin; | |
| 74 /** @private */ | |
| 75 this.fetchThirdPartyToken_ = fetchThirdPartyToken; | |
| 76 /** @private */ | |
| 77 this.authenticationMethods_ = authenticationMethods; | |
| 78 /** @private */ | |
| 79 this.clientPairingId_ = clientPairingId; | |
| 80 /** @private */ | |
| 81 this.clientPairedSecret_ = clientPairedSecret; | |
| 82 | 59 |
| 83 /** @private */ | 60 /** @private */ |
| 84 this.uiHandler_ = new remoting.DesktopConnectedView( | 61 this.uiHandler_ = new remoting.DesktopConnectedView( |
| 85 this, container, this.host_, mode, defaultRemapKeys, | 62 this, container, this.host_, mode, defaultRemapKeys, |
| 86 this.onPluginInitialized_.bind(this)); | 63 this.onPluginInitialized_.bind(this)); |
| 87 remoting.desktopConnectedView = this.uiHandler_; | 64 remoting.desktopConnectedView = this.uiHandler_; |
| 88 | 65 |
| 89 /** @private */ | 66 /** @private */ |
| 90 this.sessionId_ = ''; | 67 this.sessionId_ = ''; |
| 91 /** @type {remoting.ClientPlugin} | 68 /** @type {remoting.ClientPlugin} |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 plugin.setConnectionStatusUpdateHandler( | 280 plugin.setConnectionStatusUpdateHandler( |
| 304 this.onConnectionStatusUpdate_.bind(this)); | 281 this.onConnectionStatusUpdate_.bind(this)); |
| 305 plugin.setRouteChangedHandler(this.onRouteChanged_.bind(this)); | 282 plugin.setRouteChangedHandler(this.onRouteChanged_.bind(this)); |
| 306 plugin.setConnectionReadyHandler(this.onConnectionReady_.bind(this)); | 283 plugin.setConnectionReadyHandler(this.onConnectionReady_.bind(this)); |
| 307 plugin.setCapabilitiesHandler(this.onSetCapabilities_.bind(this)); | 284 plugin.setCapabilitiesHandler(this.onSetCapabilities_.bind(this)); |
| 308 plugin.setGnubbyAuthHandler( | 285 plugin.setGnubbyAuthHandler( |
| 309 this.processGnubbyAuthMessage_.bind(this)); | 286 this.processGnubbyAuthMessage_.bind(this)); |
| 310 plugin.setCastExtensionHandler( | 287 plugin.setCastExtensionHandler( |
| 311 this.processCastExtensionMessage_.bind(this)); | 288 this.processCastExtensionMessage_.bind(this)); |
| 312 | 289 |
| 313 this.initiateConnection_(); | 290 this.plugin_.connect( |
| 291 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_); |
| 314 }; | 292 }; |
| 315 | 293 |
| 316 /** | 294 /** |
| 317 * @param {remoting.Error} error | 295 * @param {remoting.Error} error |
| 318 */ | 296 */ |
| 319 remoting.ClientSession.prototype.resetWithError_ = function(error) { | 297 remoting.ClientSession.prototype.resetWithError_ = function(error) { |
| 320 this.signalStrategy_.setIncomingStanzaCallback(null); | 298 this.signalStrategy_.setIncomingStanzaCallback(null); |
| 321 this.removePlugin(); | 299 this.removePlugin(); |
| 322 this.error_ = error; | 300 this.error_ = error; |
| 323 this.setState_(remoting.ClientSession.State.FAILED); | 301 this.setState_(remoting.ClientSession.State.FAILED); |
| 324 } | 302 }; |
| 325 | 303 |
| 326 /** | 304 /** |
| 327 * Deletes the <embed> element from the container, without sending a | 305 * Deletes the <embed> element from the container, without sending a |
| 328 * session_terminate request. This is to be called when the session was | 306 * session_terminate request. This is to be called when the session was |
| 329 * disconnected by the Host. | 307 * disconnected by the Host. |
| 330 * | 308 * |
| 331 * @return {void} Nothing. | 309 * @return {void} Nothing. |
| 332 */ | 310 */ |
| 333 remoting.ClientSession.prototype.removePlugin = function() { | 311 remoting.ClientSession.prototype.removePlugin = function() { |
| 334 this.uiHandler_.removePlugin(); | 312 this.uiHandler_.removePlugin(); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 if (!this.plugin_) { | 431 if (!this.plugin_) { |
| 454 return; | 432 return; |
| 455 } | 433 } |
| 456 var formatted = new XMLSerializer().serializeToString(message); | 434 var formatted = new XMLSerializer().serializeToString(message); |
| 457 console.log(remoting.timestamp(), | 435 console.log(remoting.timestamp(), |
| 458 remoting.formatIq.prettifyReceiveIq(formatted)); | 436 remoting.formatIq.prettifyReceiveIq(formatted)); |
| 459 this.plugin_.onIncomingIq(formatted); | 437 this.plugin_.onIncomingIq(formatted); |
| 460 }; | 438 }; |
| 461 | 439 |
| 462 /** | 440 /** |
| 463 * @private | |
| 464 */ | |
| 465 remoting.ClientSession.prototype.initiateConnection_ = function() { | |
| 466 /** @type {remoting.ClientSession} */ | |
| 467 var that = this; | |
| 468 | |
| 469 /** @param {string} sharedSecret Shared secret. */ | |
| 470 function onSharedSecretReceived(sharedSecret) { | |
| 471 that.plugin_.connect(that.host_.jabberId, that.host_.publicKey, | |
| 472 that.signalStrategy_.getJid(), sharedSecret, | |
| 473 that.authenticationMethods_, that.host_.hostId, | |
| 474 that.clientPairingId_, that.clientPairedSecret_); | |
| 475 } | |
| 476 | |
| 477 this.getSharedSecret_(onSharedSecretReceived); | |
| 478 }; | |
| 479 | |
| 480 /** | |
| 481 * Gets shared secret to be used for connection. | |
| 482 * | |
| 483 * @param {function(string)} callback Callback called with the shared secret. | |
| 484 * @return {void} Nothing. | |
| 485 * @private | |
| 486 */ | |
| 487 remoting.ClientSession.prototype.getSharedSecret_ = function(callback) { | |
| 488 /** @type remoting.ClientSession */ | |
| 489 var that = this; | |
| 490 if (this.plugin_.hasFeature(remoting.ClientPlugin.Feature.THIRD_PARTY_AUTH)) { | |
| 491 /** @type{function(string, string, string): void} */ | |
| 492 var fetchThirdPartyToken = function(tokenUrl, hostPublicKey, scope) { | |
| 493 that.fetchThirdPartyToken_( | |
| 494 tokenUrl, hostPublicKey, scope, | |
| 495 that.plugin_.onThirdPartyTokenFetched.bind(that.plugin_)); | |
| 496 }; | |
| 497 this.plugin_.setFetchThirdPartyTokenHandler(fetchThirdPartyToken); | |
| 498 } | |
| 499 if (this.accessCode_) { | |
| 500 // Shared secret was already supplied before connecting (It2Me case). | |
| 501 callback(this.accessCode_); | |
| 502 } else if (this.plugin_.hasFeature( | |
| 503 remoting.ClientPlugin.Feature.ASYNC_PIN)) { | |
| 504 // Plugin supports asynchronously asking for the PIN. | |
| 505 this.plugin_.useAsyncPinDialog(); | |
| 506 /** @param {boolean} pairingSupported */ | |
| 507 var fetchPin = function(pairingSupported) { | |
| 508 that.fetchPin_(pairingSupported, | |
| 509 that.plugin_.onPinFetched.bind(that.plugin_)); | |
| 510 }; | |
| 511 this.plugin_.setFetchPinHandler(fetchPin); | |
| 512 callback(''); | |
| 513 } else { | |
| 514 // Clients that don't support asking for a PIN asynchronously also don't | |
| 515 // support pairing, so request the PIN now without offering to remember it. | |
| 516 this.fetchPin_(false, callback); | |
| 517 } | |
| 518 }; | |
| 519 | |
| 520 /** | |
| 521 * Callback that the plugin invokes to indicate that the connection | 441 * Callback that the plugin invokes to indicate that the connection |
| 522 * status has changed. | 442 * status has changed. |
| 523 * | 443 * |
| 524 * @param {number} status The plugin's status. | 444 * @param {number} status The plugin's status. |
| 525 * @param {number} error The plugin's error state, if any. | 445 * @param {number} error The plugin's error state, if any. |
| 526 * @private | 446 * @private |
| 527 */ | 447 */ |
| 528 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = | 448 remoting.ClientSession.prototype.onConnectionStatusUpdate_ = |
| 529 function(status, error) { | 449 function(status, error) { |
| 530 if (status == remoting.ClientSession.State.CONNECTED) { | 450 if (status == remoting.ClientSession.State.CONNECTED) { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 * @param {boolean} enable True to enable rendering. | 764 * @param {boolean} enable True to enable rendering. |
| 845 */ | 765 */ |
| 846 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { | 766 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { |
| 847 if (enable) { | 767 if (enable) { |
| 848 this.plugin_.setDebugDirtyRegionHandler( | 768 this.plugin_.setDebugDirtyRegionHandler( |
| 849 this.uiHandler_.handleDebugRegion.bind(this.uiHandler_)); | 769 this.uiHandler_.handleDebugRegion.bind(this.uiHandler_)); |
| 850 } else { | 770 } else { |
| 851 this.plugin_.setDebugDirtyRegionHandler(null); | 771 this.plugin_.setDebugDirtyRegionHandler(null); |
| 852 } | 772 } |
| 853 } | 773 } |
| OLD | NEW |