Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Side by Side Diff: remoting/webapp/crd/js/session_connector_impl.js

Issue 981083002: [Chromoting] Move ownership of ClientPlugin into SessionConnector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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';
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 this.reconnector_ = null; 101 this.reconnector_ = null;
102 102
103 /** 103 /**
104 * @private 104 * @private
105 */ 105 */
106 this.bound_ = { 106 this.bound_ = {
107 onStateChange : this.onStateChange_.bind(this) 107 onStateChange : this.onStateChange_.bind(this)
108 }; 108 };
109 109
110 // Initialize/declare per-connection state. 110 // Initialize/declare per-connection state.
111 this.reset(); 111 this.reset_();
112 }; 112 };
113 113
114 /** 114 /**
115 * Reset the per-connection state so that the object can be re-used for a 115 * 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. 116 * second connection. Note the none of the shared WCS state is reset.
kelvinp 2015/03/06 02:58:38 @private
garykac 2015/03/06 23:38:33 Done.
117 */ 117 */
118 remoting.SessionConnectorImpl.prototype.reset = function() { 118 remoting.SessionConnectorImpl.prototype.reset_ = function() {
119 /** 119 /**
120 * @type {remoting.Host} 120 * @type {remoting.Host}
121 * @private 121 * @private
122 */ 122 */
123 this.host_ = null; 123 this.host_ = null;
124 124
125 /** 125 /**
126 * @type {boolean} 126 * @type {boolean}
127 * @private 127 * @private
128 */ 128 */
129 this.logHostOfflineErrors_ = false; 129 this.logHostOfflineErrors_ = false;
130 130
131 /** @private {remoting.ClientPlugin} */
132 this.plugin_ = null;
133
131 /** 134 /**
132 * @type {remoting.ClientSession} 135 * @type {remoting.ClientSession}
133 * @private 136 * @private
134 */ 137 */
135 this.clientSession_ = null; 138 this.clientSession_ = null;
136 139
140 /** @private {remoting.DesktopConnectedView} */
141 this.connectedView_ = null;
142
137 /** 143 /**
138 * @type {XMLHttpRequest} 144 * @type {XMLHttpRequest}
139 * @private 145 * @private
140 */ 146 */
141 this.pendingXhr_ = null; 147 this.pendingXhr_ = null;
142 148
143 /** 149 /**
144 * @type {remoting.CredentialsProvider} 150 * @type {remoting.CredentialsProvider}
145 * @private 151 * @private
146 */ 152 */
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 return; 287 return;
282 } 288 }
283 this.logHostOfflineErrors_ = false; 289 this.logHostOfflineErrors_ = false;
284 this.connectInternal_(this.host_, this.credentialsProvider_); 290 this.connectInternal_(this.host_, this.credentialsProvider_);
285 }; 291 };
286 292
287 /** 293 /**
288 * Cancel a connection-in-progress. 294 * Cancel a connection-in-progress.
289 */ 295 */
290 remoting.SessionConnectorImpl.prototype.cancel = function() { 296 remoting.SessionConnectorImpl.prototype.cancel = function() {
291 if (this.clientSession_) {
292 this.clientSession_.removePlugin();
293 this.clientSession_ = null;
294 }
295 if (this.pendingXhr_) { 297 if (this.pendingXhr_) {
296 this.pendingXhr_.abort(); 298 this.pendingXhr_.abort();
297 this.pendingXhr_ = null; 299 this.pendingXhr_ = null;
298 } 300 }
299 this.reset(); 301 this.resetConnection();
300 }; 302 };
301 303
302 /** 304 /**
303 * Get the connection mode (Me2Me or IT2Me) 305 * Get the connection mode (Me2Me or IT2Me)
304 * 306 *
305 * @return {remoting.DesktopConnectedView.Mode} 307 * @return {remoting.DesktopConnectedView.Mode}
306 */ 308 */
307 remoting.SessionConnectorImpl.prototype.getConnectionMode = function() { 309 remoting.SessionConnectorImpl.prototype.getConnectionMode = function() {
308 return this.connectionMode_; 310 return this.connectionMode_;
309 }; 311 };
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } 428 }
427 }; 429 };
428 430
429 /** 431 /**
430 * Creates ClientSession object. 432 * Creates ClientSession object.
431 */ 433 */
432 remoting.SessionConnectorImpl.prototype.createSession_ = function() { 434 remoting.SessionConnectorImpl.prototype.createSession_ = function() {
433 // In some circumstances, the WCS <iframe> can get reloaded, which results 435 // 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 436 // in a new clientJid and a new callback. In this case, remove the old
435 // client plugin before instantiating a new one. 437 // client plugin before instantiating a new one.
436 if (this.clientSession_) { 438 this.removePlugin();
437 this.clientSession_.removePlugin();
438 this.clientSession_ = null;
439 }
440 439
441 this.clientSession_ = new remoting.ClientSession( 440 this.clientSession_ = new remoting.ClientSession(
442 this.host_, this.signalStrategy_, this.credentialsProvider_, 441 this.host_, this.signalStrategy_, this.credentialsProvider_,
443 this.clientContainer_, this.connectionMode_, this.defaultRemapKeys_); 442 this.connectionMode_);
443 remoting.clientSession = this.clientSession_;
444
445 this.connectedView_ = new remoting.DesktopConnectedView(
kelvinp 2015/03/06 02:58:38 This should be created when the session is connect
garykac 2015/03/06 23:38:33 Done.
446 this.clientSession_, this.clientContainer_, this.host_,
447 this.connectionMode_,
448 this.defaultRemapKeys_);
449 remoting.desktopConnectedView = this.connectedView_;
450
444 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); 451 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_);
445 this.clientSession_.addEventListener( 452 this.clientSession_.addEventListener(
446 remoting.ClientSession.Events.stateChanged, 453 remoting.ClientSession.Events.stateChanged,
447 this.bound_.onStateChange); 454 this.bound_.onStateChange);
448 this.clientSession_.createPluginAndConnect(this.onExtensionMessage_, 455
449 this.requiredCapabilities_); 456 var pluginContainer = this.clientContainer_.querySelector(
457 '.client-plugin-container');
458
459 this.plugin_ = remoting.ClientPlugin.factory.createPlugin(
460 pluginContainer, this.onExtensionMessage_, this.requiredCapabilities_);
461
462 var that = this;
463 this.host_.options.load().then(function(){
464 that.plugin_.initialize(that.onPluginInitialized_.bind(that));
465 });
450 }; 466 };
451 467
452 /** 468 /**
469 * @param {boolean} initialized
470 */
471 remoting.SessionConnectorImpl.prototype.onPluginInitialized_ = function(
kelvinp 2015/03/06 02:58:38 This should be private. Annotate and underscore
garykac 2015/03/06 23:38:33 Done.
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;
483 }
484
485 this.connectedView_.onPluginInitialized(this.plugin_);
kelvinp 2015/03/06 02:58:38 As mentioned, consider creating the DesktopConnect
garykac 2015/03/06 23:38:34 Done.
486 this.clientSession_.onPluginInitialized(this.plugin_);
487 };
488
489 /** @param {remoting.Error} error */
490 remoting.SessionConnectorImpl.prototype.pluginError = function(error) {
kelvinp 2015/03/06 02:58:38 This should be private. Annotate and underscore
garykac 2015/03/06 23:38:33 Done.
491 this.signalStrategy_.setIncomingStanzaCallback(null);
492 this.clientSession_.disconnect(error);
493 this.removePlugin();
494 };
495
496 remoting.SessionConnectorImpl.prototype.removePlugin = function() {
kelvinp 2015/03/06 02:58:37 This should be private. Annotate and underscore
garykac 2015/03/06 23:38:34 Done.
497 if (this.plugin_) {
498 this.clientSession_.removePlugin();
499 this.connectedView_.removePlugin();
500 this.plugin_.dispose();
501 }
502 this.plugin_ = null;
503
504 if (this.clientSession_) {
505 this.clientSession_.dispose();
kelvinp 2015/03/06 02:58:38 dispose() is currently poorly named (my apology) a
garykac 2015/03/06 23:38:33 Done.
506 }
507 this.clientSession_ = null
508 remoting.clientSession = null;
509
510 this.connectedView_ = null;
511 remoting.desktopConnectedView = null;
512 };
513
514 remoting.SessionConnectorImpl.prototype.resetConnection = function() {
kelvinp 2015/03/06 02:58:38 This should be private. Annotate and underscore
garykac 2015/03/06 23:38:33 Done.
515 this.removePlugin();
516
517 this.host_ = null;
518 this.logHostOfflineErrors_ = false;
519 this.pendingXhr_ = null;
kelvinp 2015/03/06 02:58:38 This is already cleared in reset.
garykac 2015/03/06 23:38:33 Done.
520 this.credentialsProvider_ = null;
kelvinp 2015/03/06 02:58:38 This is already cleared in reset. Do we need to c
garykac 2015/03/06 23:38:34 Done.
521 };
522
523 /**
453 * Handle a change in the state of the client session prior to successful 524 * Handle a change in the state of the client session prior to successful
454 * connection (after connection, this class no longer handles state change 525 * connection (after connection, this class no longer handles state change
455 * events). Errors that occur while connecting either trigger a reconnect 526 * events). Errors that occur while connecting either trigger a reconnect
456 * or notify the onError handler. 527 * or notify the onError handler.
457 * 528 *
458 * @param {remoting.ClientSession.StateEvent=} event 529 * @param {remoting.ClientSession.StateEvent=} event
459 * @return {void} Nothing. 530 * @return {void} Nothing.
460 * @private 531 * @private
461 */ 532 */
462 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) { 533 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 */ 648 */
578 remoting.DefaultSessionConnectorFactory.prototype.createConnector = 649 remoting.DefaultSessionConnectorFactory.prototype.createConnector =
579 function(clientContainer, onConnected, onError, onExtensionMessage, 650 function(clientContainer, onConnected, onError, onExtensionMessage,
580 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { 651 onConnectionFailed, requiredCapabilities, defaultRemapKeys) {
581 return new remoting.SessionConnectorImpl(clientContainer, onConnected, 652 return new remoting.SessionConnectorImpl(clientContainer, onConnected,
582 onError, onExtensionMessage, 653 onError, onExtensionMessage,
583 onConnectionFailed, 654 onConnectionFailed,
584 requiredCapabilities, 655 requiredCapabilities,
585 defaultRemapKeys); 656 defaultRemapKeys);
586 }; 657 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698