| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 * @constructor | 55 * @constructor |
| 56 * @extends {base.EventSourceImpl} | 56 * @extends {base.EventSourceImpl} |
| 57 */ | 57 */ |
| 58 remoting.ClientSession = function(host, signalStrategy, container, accessCode, | 58 remoting.ClientSession = function(host, signalStrategy, container, accessCode, |
| 59 fetchPin, fetchThirdPartyToken, | 59 fetchPin, fetchThirdPartyToken, |
| 60 authenticationMethods, mode, clientPairingId, | 60 authenticationMethods, mode, clientPairingId, |
| 61 clientPairedSecret, defaultRemapKeys) { | 61 clientPairedSecret, defaultRemapKeys) { |
| 62 /** @private */ | 62 /** @private */ |
| 63 this.state_ = remoting.ClientSession.State.CREATED; | 63 this.state_ = remoting.ClientSession.State.CREATED; |
| 64 | 64 |
| 65 /** @private */ | 65 /** @private {!remoting.Error} */ |
| 66 this.error_ = remoting.Error.NONE; | 66 this.error_ = remoting.Error.NONE; |
| 67 | 67 |
| 68 /** @private */ | 68 /** @private */ |
| 69 this.host_ = host; | 69 this.host_ = host; |
| 70 /** @private */ | 70 /** @private */ |
| 71 this.accessCode_ = accessCode; | 71 this.accessCode_ = accessCode; |
| 72 /** @private */ | 72 /** @private */ |
| 73 this.fetchPin_ = fetchPin; | 73 this.fetchPin_ = fetchPin; |
| 74 /** @private */ | 74 /** @private */ |
| 75 this.fetchThirdPartyToken_ = fetchThirdPartyToken; | 75 this.fetchThirdPartyToken_ = fetchThirdPartyToken; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 * @param {Array<string>} requiredCapabilities A list of capabilities | 280 * @param {Array<string>} requiredCapabilities A list of capabilities |
| 281 * required by this application. | 281 * required by this application. |
| 282 */ | 282 */ |
| 283 remoting.ClientSession.prototype.createPluginAndConnect = | 283 remoting.ClientSession.prototype.createPluginAndConnect = |
| 284 function(onExtensionMessage, requiredCapabilities) { | 284 function(onExtensionMessage, requiredCapabilities) { |
| 285 this.uiHandler_.createPluginAndConnect(onExtensionMessage, | 285 this.uiHandler_.createPluginAndConnect(onExtensionMessage, |
| 286 requiredCapabilities); | 286 requiredCapabilities); |
| 287 }; | 287 }; |
| 288 | 288 |
| 289 /** | 289 /** |
| 290 * @param {remoting.Error} error | 290 * @param {!remoting.Error} error |
| 291 * @param {remoting.ClientPlugin} plugin | 291 * @param {remoting.ClientPlugin} plugin |
| 292 */ | 292 */ |
| 293 remoting.ClientSession.prototype.onPluginInitialized_ = function( | 293 remoting.ClientSession.prototype.onPluginInitialized_ = function( |
| 294 error, plugin) { | 294 error, plugin) { |
| 295 if (error != remoting.Error.NONE) { | 295 if (error.tag != remoting.Error.Tag.NONE) { |
| 296 this.resetWithError_(error); | 296 this.resetWithError_(error); |
| 297 } | 297 } |
| 298 | 298 |
| 299 this.plugin_ = plugin; | 299 this.plugin_ = plugin; |
| 300 plugin.setOnOutgoingIqHandler(this.sendIq_.bind(this)); | 300 plugin.setOnOutgoingIqHandler(this.sendIq_.bind(this)); |
| 301 plugin.setOnDebugMessageHandler(this.onDebugMessage_.bind(this)); | 301 plugin.setOnDebugMessageHandler(this.onDebugMessage_.bind(this)); |
| 302 | 302 |
| 303 plugin.setConnectionStatusUpdateHandler( | 303 plugin.setConnectionStatusUpdateHandler( |
| 304 this.onConnectionStatusUpdate_.bind(this)); | 304 this.onConnectionStatusUpdate_.bind(this)); |
| 305 plugin.setRouteChangedHandler(this.onRouteChanged_.bind(this)); | 305 plugin.setRouteChangedHandler(this.onRouteChanged_.bind(this)); |
| 306 plugin.setConnectionReadyHandler(this.onConnectionReady_.bind(this)); | 306 plugin.setConnectionReadyHandler(this.onConnectionReady_.bind(this)); |
| 307 plugin.setCapabilitiesHandler(this.onSetCapabilities_.bind(this)); | 307 plugin.setCapabilitiesHandler(this.onSetCapabilities_.bind(this)); |
| 308 plugin.setGnubbyAuthHandler( | 308 plugin.setGnubbyAuthHandler( |
| 309 this.processGnubbyAuthMessage_.bind(this)); | 309 this.processGnubbyAuthMessage_.bind(this)); |
| 310 plugin.setCastExtensionHandler( | 310 plugin.setCastExtensionHandler( |
| 311 this.processCastExtensionMessage_.bind(this)); | 311 this.processCastExtensionMessage_.bind(this)); |
| 312 | 312 |
| 313 this.initiateConnection_(); | 313 this.initiateConnection_(); |
| 314 }; | 314 }; |
| 315 | 315 |
| 316 /** | 316 /** |
| 317 * @param {remoting.Error} error | 317 * @param {!remoting.Error} error |
| 318 */ | 318 */ |
| 319 remoting.ClientSession.prototype.resetWithError_ = function(error) { | 319 remoting.ClientSession.prototype.resetWithError_ = function(error) { |
| 320 this.signalStrategy_.setIncomingStanzaCallback(null); | 320 this.signalStrategy_.setIncomingStanzaCallback(null); |
| 321 this.removePlugin(); | 321 this.removePlugin(); |
| 322 this.error_ = error; | 322 this.error_ = error; |
| 323 this.setState_(remoting.ClientSession.State.FAILED); | 323 this.setState_(remoting.ClientSession.State.FAILED); |
| 324 } | 324 } |
| 325 | 325 |
| 326 /** | 326 /** |
| 327 * Deletes the <embed> element from the container, without sending a | 327 * Deletes the <embed> element from the container, without sending a |
| 328 * session_terminate request. This is to be called when the session was | 328 * session_terminate request. This is to be called when the session was |
| 329 * disconnected by the Host. | 329 * disconnected by the Host. |
| 330 * | 330 * |
| 331 * @return {void} Nothing. | 331 * @return {void} Nothing. |
| 332 */ | 332 */ |
| 333 remoting.ClientSession.prototype.removePlugin = function() { | 333 remoting.ClientSession.prototype.removePlugin = function() { |
| 334 this.uiHandler_.removePlugin(); | 334 this.uiHandler_.removePlugin(); |
| 335 this.plugin_ = null; | 335 this.plugin_ = null; |
| 336 }; | 336 }; |
| 337 | 337 |
| 338 /** | 338 /** |
| 339 * Disconnect the current session with a particular |error|. The session will | 339 * Disconnect the current session with a particular |error|. The session will |
| 340 * raise a |stateChanged| event in response to it. The caller should then call | 340 * raise a |stateChanged| event in response to it. The caller should then call |
| 341 * |cleanup| to remove and destroy the <embed> element. | 341 * |cleanup| to remove and destroy the <embed> element. |
| 342 * | 342 * |
| 343 * @param {remoting.Error} error The reason for the disconnection. Use | 343 * @param {!remoting.Error} error The reason for the disconnection. Use |
| 344 * remoting.Error.NONE if there is no error. | 344 * remoting.Error.NONE if there is no error. |
| 345 * @return {void} Nothing. | 345 * @return {void} Nothing. |
| 346 */ | 346 */ |
| 347 remoting.ClientSession.prototype.disconnect = function(error) { | 347 remoting.ClientSession.prototype.disconnect = function(error) { |
| 348 var state = (error == remoting.Error.NONE) ? | 348 var state = (error.tag == remoting.Error.Tag.NONE) ? |
| 349 remoting.ClientSession.State.CLOSED : | 349 remoting.ClientSession.State.CLOSED : |
| 350 remoting.ClientSession.State.FAILED; | 350 remoting.ClientSession.State.FAILED; |
| 351 | 351 |
| 352 // The plugin won't send a state change notification, so we explicitly log | 352 // The plugin won't send a state change notification, so we explicitly log |
| 353 // the fact that the connection has closed. | 353 // the fact that the connection has closed. |
| 354 this.logToServer.logClientSessionStateChange(state, error); | 354 this.logToServer.logClientSessionStateChange(state, error); |
| 355 this.error_ = error; | 355 this.error_ = error; |
| 356 this.setState_(state); | 356 this.setState_(state); |
| 357 }; | 357 }; |
| 358 | 358 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 379 }; | 379 }; |
| 380 | 380 |
| 381 /** | 381 /** |
| 382 * @return {remoting.ClientSession.State} The current state. | 382 * @return {remoting.ClientSession.State} The current state. |
| 383 */ | 383 */ |
| 384 remoting.ClientSession.prototype.getState = function() { | 384 remoting.ClientSession.prototype.getState = function() { |
| 385 return this.state_; | 385 return this.state_; |
| 386 }; | 386 }; |
| 387 | 387 |
| 388 /** | 388 /** |
| 389 * @return {remoting.Error} The current error code. | 389 * @return {!remoting.Error} The current error code. |
| 390 */ | 390 */ |
| 391 remoting.ClientSession.prototype.getError = function() { | 391 remoting.ClientSession.prototype.getError = function() { |
| 392 return this.error_; | 392 return this.error_; |
| 393 }; | 393 }; |
| 394 | 394 |
| 395 /** | 395 /** |
| 396 * Called when the client receives its first frame. | 396 * Called when the client receives its first frame. |
| 397 * | 397 * |
| 398 * @return {void} Nothing. | 398 * @return {void} Nothing. |
| 399 */ | 399 */ |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 * @private | 624 * @private |
| 625 */ | 625 */ |
| 626 remoting.ClientSession.prototype.setState_ = function(newState) { | 626 remoting.ClientSession.prototype.setState_ = function(newState) { |
| 627 var oldState = this.state_; | 627 var oldState = this.state_; |
| 628 this.state_ = newState; | 628 this.state_ = newState; |
| 629 var state = this.state_; | 629 var state = this.state_; |
| 630 if (oldState == remoting.ClientSession.State.CONNECTING) { | 630 if (oldState == remoting.ClientSession.State.CONNECTING) { |
| 631 if (this.state_ == remoting.ClientSession.State.CLOSED) { | 631 if (this.state_ == remoting.ClientSession.State.CLOSED) { |
| 632 state = remoting.ClientSession.State.CONNECTION_CANCELED; | 632 state = remoting.ClientSession.State.CONNECTION_CANCELED; |
| 633 } else if (this.state_ == remoting.ClientSession.State.FAILED && | 633 } else if (this.state_ == remoting.ClientSession.State.FAILED && |
| 634 this.error_ == remoting.Error.HOST_IS_OFFLINE && | 634 this.error_.tag == remoting.Error.Tag.HOST_IS_OFFLINE && |
| 635 !this.logHostOfflineErrors_) { | 635 !this.logHostOfflineErrors_) { |
| 636 // The application requested host-offline errors to be suppressed, for | 636 // The application requested host-offline errors to be suppressed, for |
| 637 // example, because this connection attempt is using a cached host JID. | 637 // example, because this connection attempt is using a cached host JID. |
| 638 console.log('Suppressing host-offline error.'); | 638 console.log('Suppressing host-offline error.'); |
| 639 state = remoting.ClientSession.State.CONNECTION_CANCELED; | 639 state = remoting.ClientSession.State.CONNECTION_CANCELED; |
| 640 } | 640 } |
| 641 } else if (oldState == remoting.ClientSession.State.CONNECTED && | 641 } else if (oldState == remoting.ClientSession.State.CONNECTED && |
| 642 this.state_ == remoting.ClientSession.State.FAILED) { | 642 this.state_ == remoting.ClientSession.State.FAILED) { |
| 643 state = remoting.ClientSession.State.CONNECTION_DROPPED; | 643 state = remoting.ClientSession.State.CONNECTION_DROPPED; |
| 644 } | 644 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 if (this.state_ != remoting.ClientSession.State.CONNECTED) { | 768 if (this.state_ != remoting.ClientSession.State.CONNECTED) { |
| 769 return; | 769 return; |
| 770 } | 770 } |
| 771 /** @type {remoting.ClientSession} */ | 771 /** @type {remoting.ClientSession} */ |
| 772 var that = this; | 772 var that = this; |
| 773 | 773 |
| 774 /** @param {string} token */ | 774 /** @param {string} token */ |
| 775 var sendToken = function(token) { | 775 var sendToken = function(token) { |
| 776 remoting.clientSession.sendClientMessage('accessToken', token); | 776 remoting.clientSession.sendClientMessage('accessToken', token); |
| 777 }; | 777 }; |
| 778 /** @param {remoting.Error} error */ | 778 /** @param {!remoting.Error} error */ |
| 779 var sendError = function(error) { | 779 var sendError = function(error) { |
| 780 console.log('Failed to refresh access token: ' + error); | 780 console.log('Failed to refresh access token: ' + error); |
| 781 }; | 781 }; |
| 782 remoting.identity.getNewToken(). | 782 remoting.identity.getNewToken(). |
| 783 then(sendToken). | 783 then(sendToken). |
| 784 catch(remoting.Error.handler(sendError)); | 784 catch(remoting.Error.handler(sendError)); |
| 785 window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this), | 785 window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this), |
| 786 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS); | 786 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS); |
| 787 }; | 787 }; |
| 788 | 788 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 * @param {boolean} enable True to enable rendering. | 844 * @param {boolean} enable True to enable rendering. |
| 845 */ | 845 */ |
| 846 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { | 846 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { |
| 847 if (enable) { | 847 if (enable) { |
| 848 this.plugin_.setDebugDirtyRegionHandler( | 848 this.plugin_.setDebugDirtyRegionHandler( |
| 849 this.uiHandler_.handleDebugRegion.bind(this.uiHandler_)); | 849 this.uiHandler_.handleDebugRegion.bind(this.uiHandler_)); |
| 850 } else { | 850 } else { |
| 851 this.plugin_.setDebugDirtyRegionHandler(null); | 851 this.plugin_.setDebugDirtyRegionHandler(null); |
| 852 } | 852 } |
| 853 } | 853 } |
| OLD | NEW |