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 | 16 * @type {remoting.ClientSession} The client session object, set once the |
17 * connector has invoked its onOk callback. | 17 * connector has invoked its onOk callback. |
18 * TODO(garykac): Have this owned by someone instead of being global. | 18 * TODO(garykac): Have this owned by someone instead of being global. |
19 */ | 19 */ |
20 remoting.clientSession = null; | 20 remoting.clientSession = null; |
21 | 21 |
22 /** | 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 /** | |
30 * @param {HTMLElement} clientContainer Container element for the client view. | 23 * @param {HTMLElement} clientContainer Container element for the client view. |
31 * @param {function(remoting.ConnectionInfo):void} onConnected Callback on | 24 * @param {function(remoting.ConnectionInfo):void} onConnected Callback on |
32 * success. | 25 * success. |
33 * @param {function(!remoting.Error):void} onError Callback on error. | 26 * @param {function(!remoting.Error):void} onError Callback on error. |
34 * @param {function(!remoting.Error):void} onConnectionFailed Callback for when | 27 * @param {function(!remoting.Error):void} onConnectionFailed Callback for when |
35 * the connection fails. | 28 * the connection fails. |
36 * @param {Array<string>} requiredCapabilities Connector capabilities | 29 * @param {Array<string>} requiredCapabilities Connector capabilities |
37 * required by this application. | 30 * required by this application. |
38 * @param {string} defaultRemapKeys The default set of key mappings for the | 31 * @param {string} defaultRemapKeys The default set of key mappings for the |
39 * client session to use. | 32 * client session to use. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 86 |
94 /** @private {boolean} */ | 87 /** @private {boolean} */ |
95 this.logHostOfflineErrors_ = false; | 88 this.logHostOfflineErrors_ = false; |
96 | 89 |
97 /** @private {remoting.ClientPlugin} */ | 90 /** @private {remoting.ClientPlugin} */ |
98 this.plugin_ = null; | 91 this.plugin_ = null; |
99 | 92 |
100 /** @private {remoting.ClientSession} */ | 93 /** @private {remoting.ClientSession} */ |
101 this.clientSession_ = null; | 94 this.clientSession_ = null; |
102 | 95 |
103 /** @private {remoting.DesktopConnectedView} */ | |
104 this.connectedView_ = null; | |
105 | |
106 /** @private {XMLHttpRequest} */ | 96 /** @private {XMLHttpRequest} */ |
107 this.pendingXhr_ = null; | 97 this.pendingXhr_ = null; |
108 | 98 |
109 /** @private {remoting.CredentialsProvider} */ | 99 /** @private {remoting.CredentialsProvider} */ |
110 this.credentialsProvider_ = null; | 100 this.credentialsProvider_ = null; |
111 | 101 |
112 /** @private {Object<string,remoting.ProtocolExtension>} */ | 102 /** @private {Object<string,remoting.ProtocolExtension>} */ |
113 this.protocolExtensions_ = {}; | 103 this.protocolExtensions_ = {}; |
114 | 104 |
115 /** | 105 /** |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 this.pluginError_(new remoting.Error( | 344 this.pluginError_(new remoting.Error( |
355 remoting.Error.Tag.BAD_PLUGIN_VERSION)); | 345 remoting.Error.Tag.BAD_PLUGIN_VERSION)); |
356 return; | 346 return; |
357 } | 347 } |
358 | 348 |
359 this.clientSession_ = new remoting.ClientSession( | 349 this.clientSession_ = new remoting.ClientSession( |
360 this.plugin_, this.host_, this.signalStrategy_, this.connectionMode_, | 350 this.plugin_, this.host_, this.signalStrategy_, this.connectionMode_, |
361 this.onProtocolExtensionMessage_.bind(this)); | 351 this.onProtocolExtensionMessage_.bind(this)); |
362 remoting.clientSession = this.clientSession_; | 352 remoting.clientSession = this.clientSession_; |
363 | 353 |
364 this.connectedView_ = new remoting.DesktopConnectedView( | |
365 this.plugin_, this.clientContainer_, this.host_, | |
366 this.connectionMode_, this.defaultRemapKeys_); | |
367 remoting.desktopConnectedView = this.connectedView_; | |
368 | |
369 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); | 354 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); |
370 this.clientSession_.addEventListener( | 355 this.clientSession_.addEventListener( |
371 remoting.ClientSession.Events.stateChanged, | 356 remoting.ClientSession.Events.stateChanged, |
372 this.bound_.onStateChange); | 357 this.bound_.onStateChange); |
373 | 358 |
374 this.plugin_.connect( | 359 this.plugin_.connect( |
375 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_); | 360 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_); |
376 }; | 361 }; |
377 | 362 |
378 /** | 363 /** |
379 * @param {!remoting.Error} error | 364 * @param {!remoting.Error} error |
380 * @private | 365 * @private |
381 */ | 366 */ |
382 remoting.SessionConnectorImpl.prototype.pluginError_ = function(error) { | 367 remoting.SessionConnectorImpl.prototype.pluginError_ = function(error) { |
383 this.signalStrategy_.setIncomingStanzaCallback(null); | 368 this.signalStrategy_.setIncomingStanzaCallback(null); |
384 this.clientSession_.disconnect(error); | 369 this.clientSession_.disconnect(error); |
385 this.removePlugin_(); | 370 this.removePlugin_(); |
386 }; | 371 }; |
387 | 372 |
388 /** @private */ | 373 /** @private */ |
389 remoting.SessionConnectorImpl.prototype.removePlugin_ = function() { | 374 remoting.SessionConnectorImpl.prototype.removePlugin_ = function() { |
390 if (this.clientSession_) { | 375 if (this.clientSession_) { |
391 this.clientSession_.removePlugin(); | 376 this.clientSession_.removePlugin(); |
392 } | 377 } |
393 this.clientSession_ = null; | 378 this.clientSession_ = null; |
394 remoting.clientSession = null; | 379 remoting.clientSession = null; |
395 | 380 |
396 base.dispose(this.connectedView_); | |
397 this.connectedView_ = null; | |
398 remoting.desktopConnectedView = null; | |
399 | |
400 base.dispose(this.plugin_); | 381 base.dispose(this.plugin_); |
401 this.plugin_ = null; | 382 this.plugin_ = null; |
402 }; | 383 }; |
403 | 384 |
404 /** | 385 /** |
405 * @param {remoting.ProtocolExtension} extension | 386 * @param {remoting.ProtocolExtension} extension |
406 */ | 387 */ |
407 remoting.SessionConnectorImpl.prototype.registerProtocolExtension = | 388 remoting.SessionConnectorImpl.prototype.registerProtocolExtension = |
408 function(extension) { | 389 function(extension) { |
409 var types = extension.getExtensionTypes(); | 390 var types = extension.getExtensionTypes(); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 handled = extension.onExtensionMessage(type, message); | 455 handled = extension.onExtensionMessage(type, message); |
475 } catch (/** @type {*} */ err) { | 456 } catch (/** @type {*} */ err) { |
476 console.error('Failed to process protocol extension ' + type + | 457 console.error('Failed to process protocol extension ' + type + |
477 ' message: ' + err); | 458 ' message: ' + err); |
478 } | 459 } |
479 if (handled) { | 460 if (handled) { |
480 return true; | 461 return true; |
481 } | 462 } |
482 } | 463 } |
483 | 464 |
484 if (remoting.desktopConnectedView) { | |
485 return remoting.desktopConnectedView.handleExtensionMessage(type, message); | |
486 } | |
487 | |
488 return false; | 465 return false; |
489 }; | 466 }; |
490 | 467 |
491 /** | 468 /** |
492 * Handle a change in the state of the client session prior to successful | 469 * Handle a change in the state of the client session prior to successful |
493 * connection (after connection, this class no longer handles state change | 470 * connection (after connection, this class no longer handles state change |
494 * events). Errors that occur while connecting either trigger a reconnect | 471 * events). Errors that occur while connecting either trigger a reconnect |
495 * or notify the onError handler. | 472 * or notify the onError handler. |
496 * | 473 * |
497 * @param {remoting.ClientSession.StateEvent=} event | 474 * @param {remoting.ClientSession.StateEvent=} event |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 */ | 564 */ |
588 remoting.DefaultSessionConnectorFactory.prototype.createConnector = | 565 remoting.DefaultSessionConnectorFactory.prototype.createConnector = |
589 function(clientContainer, onConnected, onError, | 566 function(clientContainer, onConnected, onError, |
590 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { | 567 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { |
591 return new remoting.SessionConnectorImpl(clientContainer, onConnected, | 568 return new remoting.SessionConnectorImpl(clientContainer, onConnected, |
592 onError, | 569 onError, |
593 onConnectionFailed, | 570 onConnectionFailed, |
594 requiredCapabilities, | 571 requiredCapabilities, |
595 defaultRemapKeys); | 572 defaultRemapKeys); |
596 }; | 573 }; |
OLD | NEW |