Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 * Connect set-up state machine for Me2Me and IT2Me | 7 * Connect set-up state machine for Me2Me and IT2Me |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 'use strict'; | 10 'use strict'; |
| 11 | 11 |
| 12 /** @suppress {duplicate} */ | 12 /** @suppress {duplicate} */ |
| 13 var remoting = remoting || {}; | 13 var remoting = remoting || {}; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * @type {remoting.ClientSession} The client session object, set once the | |
| 17 * connector has invoked its onOk callback. | |
| 18 * TODO(garykac): Have this owned by someone instead of being global. | |
| 19 */ | |
| 20 remoting.clientSession = null; | |
| 21 | |
| 22 /** | |
| 23 * @type {remoting.DesktopConnectedView} The client session view object, set | |
| 24 * once the connector has invoked its onOk callback. | |
| 25 * TODO(garykac): Have this owned by someone instead of being global. | |
| 26 */ | |
| 27 remoting.desktopConnectedView = null; | |
| 28 | |
| 29 /** | |
| 16 * @param {HTMLElement} clientContainer Container element for the client view. | 30 * @param {HTMLElement} clientContainer Container element for the client view. |
| 17 * @param {function(remoting.ClientSession):void} onConnected Callback on | 31 * @param {function(remoting.ClientSession):void} onConnected Callback on |
| 18 * success. | 32 * success. |
| 19 * @param {function(remoting.Error):void} onError Callback on error. | 33 * @param {function(remoting.Error):void} onError Callback on error. |
| 20 * @param {function(string, string):boolean} onExtensionMessage The handler for | 34 * @param {function(string, string):boolean} onExtensionMessage The handler for |
| 21 * protocol extension messages. Returns true if a message is recognized; | 35 * protocol extension messages. Returns true if a message is recognized; |
| 22 * false otherwise. | 36 * false otherwise. |
| 23 * @param {function(remoting.Error):void} onConnectionFailed Callback for when | 37 * @param {function(remoting.Error):void} onConnectionFailed Callback for when |
| 24 * the connection fails. | 38 * the connection fails. |
| 25 * @param {Array<string>} requiredCapabilities Connector capabilities | 39 * @param {Array<string>} requiredCapabilities Connector capabilities |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 this.reconnector_ = null; | 115 this.reconnector_ = null; |
| 102 | 116 |
| 103 /** | 117 /** |
| 104 * @private | 118 * @private |
| 105 */ | 119 */ |
| 106 this.bound_ = { | 120 this.bound_ = { |
| 107 onStateChange : this.onStateChange_.bind(this) | 121 onStateChange : this.onStateChange_.bind(this) |
| 108 }; | 122 }; |
| 109 | 123 |
| 110 // Initialize/declare per-connection state. | 124 // Initialize/declare per-connection state. |
| 111 this.reset(); | 125 this.reset_(); |
| 112 }; | 126 }; |
| 113 | 127 |
| 114 /** | 128 /** |
| 115 * Reset the per-connection state so that the object can be re-used for a | 129 * Reset the per-connection state so that the object can be re-used for a |
| 116 * second connection. Note the none of the shared WCS state is reset. | 130 * second connection. Note the none of the shared WCS state is reset. |
| 131 * @private | |
| 117 */ | 132 */ |
| 118 remoting.SessionConnectorImpl.prototype.reset = function() { | 133 remoting.SessionConnectorImpl.prototype.reset_ = function() { |
| 119 /** | 134 /** |
| 120 * @type {remoting.Host} | 135 * @type {remoting.Host} |
| 121 * @private | 136 * @private |
| 122 */ | 137 */ |
| 123 this.host_ = null; | 138 this.host_ = null; |
| 124 | 139 |
| 125 /** | 140 /** |
| 126 * @type {boolean} | 141 * @type {boolean} |
| 127 * @private | 142 * @private |
| 128 */ | 143 */ |
| 129 this.logHostOfflineErrors_ = false; | 144 this.logHostOfflineErrors_ = false; |
| 130 | 145 |
| 146 /** @private {remoting.ClientPlugin} */ | |
| 147 this.plugin_ = null; | |
| 148 | |
| 131 /** | 149 /** |
| 132 * @type {remoting.ClientSession} | 150 * @type {remoting.ClientSession} |
| 133 * @private | 151 * @private |
| 134 */ | 152 */ |
| 135 this.clientSession_ = null; | 153 this.clientSession_ = null; |
| 136 | 154 |
| 155 /** @private {remoting.DesktopConnectedView} */ | |
| 156 this.connectedView_ = null; | |
| 157 | |
| 137 /** | 158 /** |
| 138 * @type {XMLHttpRequest} | 159 * @type {XMLHttpRequest} |
| 139 * @private | 160 * @private |
| 140 */ | 161 */ |
| 141 this.pendingXhr_ = null; | 162 this.pendingXhr_ = null; |
| 142 | 163 |
| 143 /** | 164 /** |
| 144 * @type {remoting.CredentialsProvider} | 165 * @type {remoting.CredentialsProvider} |
| 145 * @private | 166 * @private |
| 146 */ | 167 */ |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 281 return; | 302 return; |
| 282 } | 303 } |
| 283 this.logHostOfflineErrors_ = false; | 304 this.logHostOfflineErrors_ = false; |
| 284 this.connectInternal_(this.host_, this.credentialsProvider_); | 305 this.connectInternal_(this.host_, this.credentialsProvider_); |
| 285 }; | 306 }; |
| 286 | 307 |
| 287 /** | 308 /** |
| 288 * Cancel a connection-in-progress. | 309 * Cancel a connection-in-progress. |
| 289 */ | 310 */ |
| 290 remoting.SessionConnectorImpl.prototype.cancel = function() { | 311 remoting.SessionConnectorImpl.prototype.cancel = function() { |
| 291 if (this.clientSession_) { | |
| 292 this.clientSession_.removePlugin(); | |
| 293 this.clientSession_ = null; | |
| 294 } | |
| 295 if (this.pendingXhr_) { | 312 if (this.pendingXhr_) { |
| 296 this.pendingXhr_.abort(); | 313 this.pendingXhr_.abort(); |
| 297 this.pendingXhr_ = null; | 314 this.pendingXhr_ = null; |
| 298 } | 315 } |
| 299 this.reset(); | 316 this.resetConnection_(); |
| 300 }; | 317 }; |
| 301 | 318 |
| 302 /** | 319 /** |
| 303 * Get the connection mode (Me2Me or IT2Me) | 320 * Get the connection mode (Me2Me or IT2Me) |
| 304 * | 321 * |
| 305 * @return {remoting.DesktopConnectedView.Mode} | 322 * @return {remoting.DesktopConnectedView.Mode} |
| 306 */ | 323 */ |
| 307 remoting.SessionConnectorImpl.prototype.getConnectionMode = function() { | 324 remoting.SessionConnectorImpl.prototype.getConnectionMode = function() { |
| 308 return this.connectionMode_; | 325 return this.connectionMode_; |
| 309 }; | 326 }; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 } | 443 } |
| 427 }; | 444 }; |
| 428 | 445 |
| 429 /** | 446 /** |
| 430 * Creates ClientSession object. | 447 * Creates ClientSession object. |
| 431 */ | 448 */ |
| 432 remoting.SessionConnectorImpl.prototype.createSession_ = function() { | 449 remoting.SessionConnectorImpl.prototype.createSession_ = function() { |
| 433 // In some circumstances, the WCS <iframe> can get reloaded, which results | 450 // In some circumstances, the WCS <iframe> can get reloaded, which results |
| 434 // in a new clientJid and a new callback. In this case, remove the old | 451 // in a new clientJid and a new callback. In this case, remove the old |
| 435 // client plugin before instantiating a new one. | 452 // client plugin before instantiating a new one. |
| 436 if (this.clientSession_) { | 453 this.removePlugin_(); |
| 437 this.clientSession_.removePlugin(); | 454 |
| 438 this.clientSession_ = null; | 455 var pluginContainer = this.clientContainer_.querySelector( |
| 456 '.client-plugin-container'); | |
| 457 | |
| 458 this.plugin_ = remoting.ClientPlugin.factory.createPlugin( | |
| 459 pluginContainer, this.onExtensionMessage_, this.requiredCapabilities_); | |
| 460 | |
| 461 var that = this; | |
| 462 this.host_.options.load().then(function(){ | |
| 463 that.plugin_.initialize(that.onPluginInitialized_.bind(that)); | |
| 464 }); | |
| 465 }; | |
| 466 | |
| 467 /** | |
| 468 * @param {boolean} initialized | |
| 469 * @private | |
| 470 */ | |
| 471 remoting.SessionConnectorImpl.prototype.onPluginInitialized_ = function( | |
| 472 initialized) { | |
| 473 if (!initialized) { | |
| 474 console.error('ERROR: remoting plugin not loaded'); | |
| 475 this.pluginError_(remoting.Error.MISSING_PLUGIN); | |
| 476 return; | |
| 477 } | |
| 478 | |
| 479 if (!this.plugin_.isSupportedVersion()) { | |
| 480 console.error('ERROR: bad plugin version'); | |
| 481 this.pluginError_(remoting.Error.BAD_PLUGIN_VERSION); | |
| 482 return; | |
| 439 } | 483 } |
| 440 | 484 |
| 441 this.clientSession_ = new remoting.ClientSession( | 485 this.clientSession_ = new remoting.ClientSession( |
| 442 this.host_, this.signalStrategy_, this.credentialsProvider_, | 486 this.plugin_, this.host_, this.signalStrategy_, this.connectionMode_); |
| 443 this.clientContainer_, this.connectionMode_, this.defaultRemapKeys_); | 487 remoting.clientSession = this.clientSession_; |
| 488 | |
| 489 this.connectedView_ = new remoting.DesktopConnectedView( | |
| 490 this.plugin_, this.clientSession_, this.clientContainer_, this.host_, | |
| 491 this.connectionMode_, | |
| 492 this.defaultRemapKeys_); | |
| 493 remoting.desktopConnectedView = this.connectedView_; | |
| 494 | |
| 444 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); | 495 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); |
| 445 this.clientSession_.addEventListener( | 496 this.clientSession_.addEventListener( |
| 446 remoting.ClientSession.Events.stateChanged, | 497 remoting.ClientSession.Events.stateChanged, |
| 447 this.bound_.onStateChange); | 498 this.bound_.onStateChange); |
| 448 this.clientSession_.createPluginAndConnect(this.onExtensionMessage_, | 499 |
| 449 this.requiredCapabilities_); | 500 this.plugin_.connect( |
| 501 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_); | |
| 450 }; | 502 }; |
| 451 | 503 |
| 452 /** | 504 /** |
| 505 * @param {remoting.Error} error | |
| 506 * @private | |
| 507 */ | |
| 508 remoting.SessionConnectorImpl.prototype.pluginError_ = function(error) { | |
| 509 this.signalStrategy_.setIncomingStanzaCallback(null); | |
| 510 this.clientSession_.disconnect(error); | |
| 511 this.removePlugin_(); | |
| 512 }; | |
| 513 | |
| 514 /** @private */ | |
| 515 remoting.SessionConnectorImpl.prototype.removePlugin_ = function() { | |
| 516 if (this.plugin_) { | |
| 517 this.clientSession_.removePlugin(); | |
|
kelvinp
2015/03/07 00:09:28
Probably want to null check clientSession before r
garykac
2015/03/07 01:53:10
Done.
| |
| 518 this.connectedView_.removePlugin(); | |
| 519 this.plugin_.dispose(); | |
| 520 } | |
| 521 this.plugin_ = null; | |
| 522 | |
| 523 this.clientSession_ = null | |
| 524 remoting.clientSession = null; | |
| 525 | |
| 526 this.connectedView_ = null; | |
| 527 remoting.desktopConnectedView = null; | |
| 528 }; | |
| 529 | |
| 530 /** | |
| 531 * Reset the per-connection state so that the object can be re-used for a | |
| 532 * second connection. Note the none of the shared WCS state is reset. | |
| 533 * @private | |
| 534 */ | |
| 535 remoting.SessionConnectorImpl.prototype.resetConnection_ = function() { | |
| 536 this.removePlugin_(); | |
| 537 this.reset_(); | |
| 538 }; | |
| 539 | |
| 540 /** | |
| 453 * Handle a change in the state of the client session prior to successful | 541 * Handle a change in the state of the client session prior to successful |
| 454 * connection (after connection, this class no longer handles state change | 542 * connection (after connection, this class no longer handles state change |
| 455 * events). Errors that occur while connecting either trigger a reconnect | 543 * events). Errors that occur while connecting either trigger a reconnect |
| 456 * or notify the onError handler. | 544 * or notify the onError handler. |
| 457 * | 545 * |
| 458 * @param {remoting.ClientSession.StateEvent=} event | 546 * @param {remoting.ClientSession.StateEvent=} event |
| 459 * @return {void} Nothing. | 547 * @return {void} Nothing. |
| 460 * @private | 548 * @private |
| 461 */ | 549 */ |
| 462 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) { | 550 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 577 */ | 665 */ |
| 578 remoting.DefaultSessionConnectorFactory.prototype.createConnector = | 666 remoting.DefaultSessionConnectorFactory.prototype.createConnector = |
| 579 function(clientContainer, onConnected, onError, onExtensionMessage, | 667 function(clientContainer, onConnected, onError, onExtensionMessage, |
| 580 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { | 668 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { |
| 581 return new remoting.SessionConnectorImpl(clientContainer, onConnected, | 669 return new remoting.SessionConnectorImpl(clientContainer, onConnected, |
| 582 onError, onExtensionMessage, | 670 onError, onExtensionMessage, |
| 583 onConnectionFailed, | 671 onConnectionFailed, |
| 584 requiredCapabilities, | 672 requiredCapabilities, |
| 585 defaultRemapKeys); | 673 defaultRemapKeys); |
| 586 }; | 674 }; |
| OLD | NEW |