| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 * when the client doesn't define any. | 42 * when the client doesn't define any. |
| 43 * @constructor | 43 * @constructor |
| 44 * @extends {base.EventSourceImpl} | 44 * @extends {base.EventSourceImpl} |
| 45 * @implements {base.Disposable} | 45 * @implements {base.Disposable} |
| 46 */ | 46 */ |
| 47 remoting.ClientSession = function(host, signalStrategy, credentialsProvider, | 47 remoting.ClientSession = function(host, signalStrategy, credentialsProvider, |
| 48 container, mode, defaultRemapKeys) { | 48 container, mode, defaultRemapKeys) { |
| 49 /** @private */ | 49 /** @private */ |
| 50 this.state_ = remoting.ClientSession.State.CREATED; | 50 this.state_ = remoting.ClientSession.State.CREATED; |
| 51 | 51 |
| 52 /** @private */ | 52 /** @private {!remoting.Error} */ |
| 53 this.error_ = remoting.Error.NONE; | 53 this.error_ = remoting.Error.NONE; |
| 54 | 54 |
| 55 /** @private */ | 55 /** @private */ |
| 56 this.host_ = host; | 56 this.host_ = host; |
| 57 | 57 |
| 58 /** @private */ | 58 /** @private */ |
| 59 this.credentialsProvider_ = credentialsProvider; | 59 this.credentialsProvider_ = credentialsProvider; |
| 60 | 60 |
| 61 /** @private */ | 61 /** @private */ |
| 62 this.uiHandler_ = new remoting.DesktopConnectedView( | 62 this.uiHandler_ = new remoting.DesktopConnectedView( |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 * @param {Array<string>} requiredCapabilities A list of capabilities | 257 * @param {Array<string>} requiredCapabilities A list of capabilities |
| 258 * required by this application. | 258 * required by this application. |
| 259 */ | 259 */ |
| 260 remoting.ClientSession.prototype.createPluginAndConnect = | 260 remoting.ClientSession.prototype.createPluginAndConnect = |
| 261 function(onExtensionMessage, requiredCapabilities) { | 261 function(onExtensionMessage, requiredCapabilities) { |
| 262 this.uiHandler_.createPluginAndConnect(onExtensionMessage, | 262 this.uiHandler_.createPluginAndConnect(onExtensionMessage, |
| 263 requiredCapabilities); | 263 requiredCapabilities); |
| 264 }; | 264 }; |
| 265 | 265 |
| 266 /** | 266 /** |
| 267 * @param {remoting.Error} error | 267 * @param {!remoting.Error} error |
| 268 * @param {remoting.ClientPlugin} plugin | 268 * @param {remoting.ClientPlugin} plugin |
| 269 */ | 269 */ |
| 270 remoting.ClientSession.prototype.onPluginInitialized_ = function( | 270 remoting.ClientSession.prototype.onPluginInitialized_ = function( |
| 271 error, plugin) { | 271 error, plugin) { |
| 272 if (error != remoting.Error.NONE) { | 272 if (error.tag != remoting.Error.Tag.NONE) { |
| 273 this.resetWithError_(error); | 273 this.resetWithError_(error); |
| 274 } | 274 } |
| 275 | 275 |
| 276 this.plugin_ = plugin; | 276 this.plugin_ = plugin; |
| 277 plugin.setOnOutgoingIqHandler(this.sendIq_.bind(this)); | 277 plugin.setOnOutgoingIqHandler(this.sendIq_.bind(this)); |
| 278 plugin.setOnDebugMessageHandler(this.onDebugMessage_.bind(this)); | 278 plugin.setOnDebugMessageHandler(this.onDebugMessage_.bind(this)); |
| 279 | 279 |
| 280 plugin.setConnectionStatusUpdateHandler( | 280 plugin.setConnectionStatusUpdateHandler( |
| 281 this.onConnectionStatusUpdate_.bind(this)); | 281 this.onConnectionStatusUpdate_.bind(this)); |
| 282 plugin.setRouteChangedHandler(this.onRouteChanged_.bind(this)); | 282 plugin.setRouteChangedHandler(this.onRouteChanged_.bind(this)); |
| 283 plugin.setConnectionReadyHandler(this.onConnectionReady_.bind(this)); | 283 plugin.setConnectionReadyHandler(this.onConnectionReady_.bind(this)); |
| 284 plugin.setCapabilitiesHandler(this.onSetCapabilities_.bind(this)); | 284 plugin.setCapabilitiesHandler(this.onSetCapabilities_.bind(this)); |
| 285 plugin.setGnubbyAuthHandler( | 285 plugin.setGnubbyAuthHandler( |
| 286 this.processGnubbyAuthMessage_.bind(this)); | 286 this.processGnubbyAuthMessage_.bind(this)); |
| 287 plugin.setCastExtensionHandler( | 287 plugin.setCastExtensionHandler( |
| 288 this.processCastExtensionMessage_.bind(this)); | 288 this.processCastExtensionMessage_.bind(this)); |
| 289 | 289 |
| 290 this.plugin_.connect( | 290 this.plugin_.connect( |
| 291 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_); | 291 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_); |
| 292 }; | 292 }; |
| 293 | 293 |
| 294 /** | 294 /** |
| 295 * @param {remoting.Error} error | 295 * @param {!remoting.Error} error |
| 296 */ | 296 */ |
| 297 remoting.ClientSession.prototype.resetWithError_ = function(error) { | 297 remoting.ClientSession.prototype.resetWithError_ = function(error) { |
| 298 this.signalStrategy_.setIncomingStanzaCallback(null); | 298 this.signalStrategy_.setIncomingStanzaCallback(null); |
| 299 this.removePlugin(); | 299 this.removePlugin(); |
| 300 this.error_ = error; | 300 this.error_ = error; |
| 301 this.setState_(remoting.ClientSession.State.FAILED); | 301 this.setState_(remoting.ClientSession.State.FAILED); |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 /** | 304 /** |
| 305 * Deletes the <embed> element from the container, without sending a | 305 * Deletes the <embed> element from the container, without sending a |
| 306 * 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 |
| 307 * disconnected by the Host. | 307 * disconnected by the Host. |
| 308 * | 308 * |
| 309 * @return {void} Nothing. | 309 * @return {void} Nothing. |
| 310 */ | 310 */ |
| 311 remoting.ClientSession.prototype.removePlugin = function() { | 311 remoting.ClientSession.prototype.removePlugin = function() { |
| 312 this.uiHandler_.removePlugin(); | 312 this.uiHandler_.removePlugin(); |
| 313 this.plugin_ = null; | 313 this.plugin_ = null; |
| 314 remoting.desktopConnectedView = null; | 314 remoting.desktopConnectedView = null; |
| 315 }; | 315 }; |
| 316 | 316 |
| 317 /** | 317 /** |
| 318 * Disconnect the current session with a particular |error|. The session will | 318 * Disconnect the current session with a particular |error|. The session will |
| 319 * raise a |stateChanged| event in response to it. The caller should then call | 319 * raise a |stateChanged| event in response to it. The caller should then call |
| 320 * dispose() to remove and destroy the <embed> element. | 320 * dispose() to remove and destroy the <embed> element. |
| 321 * | 321 * |
| 322 * @param {remoting.Error} error The reason for the disconnection. Use | 322 * @param {!remoting.Error} error The reason for the disconnection. Use |
| 323 * remoting.Error.NONE if there is no error. | 323 * remoting.Error.NONE if there is no error. |
| 324 * @return {void} Nothing. | 324 * @return {void} Nothing. |
| 325 */ | 325 */ |
| 326 remoting.ClientSession.prototype.disconnect = function(error) { | 326 remoting.ClientSession.prototype.disconnect = function(error) { |
| 327 var state = (error == remoting.Error.NONE) ? | 327 var state = (error.tag == remoting.Error.Tag.NONE) ? |
| 328 remoting.ClientSession.State.CLOSED : | 328 remoting.ClientSession.State.CLOSED : |
| 329 remoting.ClientSession.State.FAILED; | 329 remoting.ClientSession.State.FAILED; |
| 330 | 330 |
| 331 // The plugin won't send a state change notification, so we explicitly log | 331 // The plugin won't send a state change notification, so we explicitly log |
| 332 // the fact that the connection has closed. | 332 // the fact that the connection has closed. |
| 333 this.logToServer.logClientSessionStateChange(state, error); | 333 this.logToServer.logClientSessionStateChange(state, error); |
| 334 this.error_ = error; | 334 this.error_ = error; |
| 335 this.setState_(state); | 335 this.setState_(state); |
| 336 }; | 336 }; |
| 337 | 337 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 358 }; | 358 }; |
| 359 | 359 |
| 360 /** | 360 /** |
| 361 * @return {remoting.ClientSession.State} The current state. | 361 * @return {remoting.ClientSession.State} The current state. |
| 362 */ | 362 */ |
| 363 remoting.ClientSession.prototype.getState = function() { | 363 remoting.ClientSession.prototype.getState = function() { |
| 364 return this.state_; | 364 return this.state_; |
| 365 }; | 365 }; |
| 366 | 366 |
| 367 /** | 367 /** |
| 368 * @return {remoting.Error} The current error code. | 368 * @return {!remoting.Error} The current error code. |
| 369 */ | 369 */ |
| 370 remoting.ClientSession.prototype.getError = function() { | 370 remoting.ClientSession.prototype.getError = function() { |
| 371 return this.error_; | 371 return this.error_; |
| 372 }; | 372 }; |
| 373 | 373 |
| 374 /** | 374 /** |
| 375 * Called when the client receives its first frame. | 375 * Called when the client receives its first frame. |
| 376 * | 376 * |
| 377 * @return {void} Nothing. | 377 * @return {void} Nothing. |
| 378 */ | 378 */ |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 * @private | 545 * @private |
| 546 */ | 546 */ |
| 547 remoting.ClientSession.prototype.setState_ = function(newState) { | 547 remoting.ClientSession.prototype.setState_ = function(newState) { |
| 548 var oldState = this.state_; | 548 var oldState = this.state_; |
| 549 this.state_ = newState; | 549 this.state_ = newState; |
| 550 var state = this.state_; | 550 var state = this.state_; |
| 551 if (oldState == remoting.ClientSession.State.CONNECTING) { | 551 if (oldState == remoting.ClientSession.State.CONNECTING) { |
| 552 if (this.state_ == remoting.ClientSession.State.CLOSED) { | 552 if (this.state_ == remoting.ClientSession.State.CLOSED) { |
| 553 state = remoting.ClientSession.State.CONNECTION_CANCELED; | 553 state = remoting.ClientSession.State.CONNECTION_CANCELED; |
| 554 } else if (this.state_ == remoting.ClientSession.State.FAILED && | 554 } else if (this.state_ == remoting.ClientSession.State.FAILED && |
| 555 this.error_ == remoting.Error.HOST_IS_OFFLINE && | 555 this.error_.tag == remoting.Error.Tag.HOST_IS_OFFLINE && |
| 556 !this.logHostOfflineErrors_) { | 556 !this.logHostOfflineErrors_) { |
| 557 // The application requested host-offline errors to be suppressed, for | 557 // The application requested host-offline errors to be suppressed, for |
| 558 // example, because this connection attempt is using a cached host JID. | 558 // example, because this connection attempt is using a cached host JID. |
| 559 console.log('Suppressing host-offline error.'); | 559 console.log('Suppressing host-offline error.'); |
| 560 state = remoting.ClientSession.State.CONNECTION_CANCELED; | 560 state = remoting.ClientSession.State.CONNECTION_CANCELED; |
| 561 } | 561 } |
| 562 } else if (oldState == remoting.ClientSession.State.CONNECTED && | 562 } else if (oldState == remoting.ClientSession.State.CONNECTED && |
| 563 this.state_ == remoting.ClientSession.State.FAILED) { | 563 this.state_ == remoting.ClientSession.State.FAILED) { |
| 564 state = remoting.ClientSession.State.CONNECTION_DROPPED; | 564 state = remoting.ClientSession.State.CONNECTION_DROPPED; |
| 565 } | 565 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 if (this.state_ != remoting.ClientSession.State.CONNECTED) { | 689 if (this.state_ != remoting.ClientSession.State.CONNECTED) { |
| 690 return; | 690 return; |
| 691 } | 691 } |
| 692 /** @type {remoting.ClientSession} */ | 692 /** @type {remoting.ClientSession} */ |
| 693 var that = this; | 693 var that = this; |
| 694 | 694 |
| 695 /** @param {string} token */ | 695 /** @param {string} token */ |
| 696 var sendToken = function(token) { | 696 var sendToken = function(token) { |
| 697 remoting.clientSession.sendClientMessage('accessToken', token); | 697 remoting.clientSession.sendClientMessage('accessToken', token); |
| 698 }; | 698 }; |
| 699 /** @param {remoting.Error} error */ | 699 /** @param {!remoting.Error} error */ |
| 700 var sendError = function(error) { | 700 var sendError = function(error) { |
| 701 console.log('Failed to refresh access token: ' + error); | 701 console.log('Failed to refresh access token: ' + error); |
| 702 }; | 702 }; |
| 703 remoting.identity.getNewToken(). | 703 remoting.identity.getNewToken(). |
| 704 then(sendToken). | 704 then(sendToken). |
| 705 catch(remoting.Error.handler(sendError)); | 705 catch(remoting.Error.handler(sendError)); |
| 706 window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this), | 706 window.setTimeout(this.sendGoogleDriveAccessToken_.bind(this), |
| 707 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS); | 707 remoting.ACCESS_TOKEN_RESEND_INTERVAL_MS); |
| 708 }; | 708 }; |
| 709 | 709 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 * @param {boolean} enable True to enable rendering. | 765 * @param {boolean} enable True to enable rendering. |
| 766 */ | 766 */ |
| 767 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { | 767 remoting.ClientSession.prototype.enableDebugRegion = function(enable) { |
| 768 if (enable) { | 768 if (enable) { |
| 769 this.plugin_.setDebugDirtyRegionHandler( | 769 this.plugin_.setDebugDirtyRegionHandler( |
| 770 this.uiHandler_.handleDebugRegion.bind(this.uiHandler_)); | 770 this.uiHandler_.handleDebugRegion.bind(this.uiHandler_)); |
| 771 } else { | 771 } else { |
| 772 this.plugin_.setDebugDirtyRegionHandler(null); | 772 this.plugin_.setDebugDirtyRegionHandler(null); |
| 773 } | 773 } |
| 774 } | 774 } |
| OLD | NEW |