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

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: Merge 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
« no previous file with comments | « remoting/webapp/crd/js/session_connector.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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';
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 77
64 /** @private {remoting.SmartReconnector} */ 78 /** @private {remoting.SmartReconnector} */
65 this.reconnector_ = null; 79 this.reconnector_ = null;
66 80
67 /** @private */ 81 /** @private */
68 this.bound_ = { 82 this.bound_ = {
69 onStateChange : this.onStateChange_.bind(this) 83 onStateChange : this.onStateChange_.bind(this)
70 }; 84 };
71 85
72 // Initialize/declare per-connection state. 86 // Initialize/declare per-connection state.
73 this.reset(); 87 this.resetConnection_();
74 }; 88 };
75 89
76 /** 90 /**
77 * Reset the per-connection state so that the object can be re-used for a 91 * Reset the per-connection state so that the object can be re-used for a
78 * second connection. Note the none of the shared WCS state is reset. 92 * second connection. Note the none of the shared WCS state is reset.
93 * @private
79 */ 94 */
80 remoting.SessionConnectorImpl.prototype.reset = function() { 95 remoting.SessionConnectorImpl.prototype.resetConnection_ = function() {
96 this.removePlugin_();
97
81 /** @private {remoting.Host} */ 98 /** @private {remoting.Host} */
82 this.host_ = null; 99 this.host_ = null;
83 100
84 /** @private {boolean} */ 101 /** @private {boolean} */
85 this.logHostOfflineErrors_ = false; 102 this.logHostOfflineErrors_ = false;
86 103
104 /** @private {remoting.ClientPlugin} */
105 this.plugin_ = null;
106
87 /** @private {remoting.ClientSession} */ 107 /** @private {remoting.ClientSession} */
88 this.clientSession_ = null; 108 this.clientSession_ = null;
89 109
110 /** @private {remoting.DesktopConnectedView} */
111 this.connectedView_ = null;
112
113 /** @private {XMLHttpRequest} */
114 this.pendingXhr_ = null;
115
90 /** @private {remoting.CredentialsProvider} */ 116 /** @private {remoting.CredentialsProvider} */
91 this.credentialsProvider_ = null; 117 this.credentialsProvider_ = null;
92 }; 118 };
93 119
94 /** 120 /**
95 * Initiate a Me2Me connection. 121 * Initiate a Me2Me connection.
96 * 122 *
97 * This doesn't report host-offline errors because the connection will 123 * This doesn't report host-offline errors because the connection will
98 * be retried and retryConnectMe2Me is responsible for reporting these errors. 124 * be retried and retryConnectMe2Me is responsible for reporting these errors.
99 * 125 *
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return; 225 return;
200 } 226 }
201 this.logHostOfflineErrors_ = false; 227 this.logHostOfflineErrors_ = false;
202 this.connect(this.connectionMode_, this.host_, this.credentialsProvider_); 228 this.connect(this.connectionMode_, this.host_, this.credentialsProvider_);
203 }; 229 };
204 230
205 /** 231 /**
206 * Cancel a connection-in-progress. 232 * Cancel a connection-in-progress.
207 */ 233 */
208 remoting.SessionConnectorImpl.prototype.cancel = function() { 234 remoting.SessionConnectorImpl.prototype.cancel = function() {
209 if (this.clientSession_) { 235 this.resetConnection_();
210 this.clientSession_.removePlugin();
211 this.clientSession_ = null;
212 }
213 this.reset();
214 }; 236 };
215 237
216 /** 238 /**
217 * Get the connection mode (Me2Me or IT2Me) 239 * Get the connection mode (Me2Me or IT2Me)
218 * 240 *
219 * @return {remoting.DesktopConnectedView.Mode} 241 * @return {remoting.DesktopConnectedView.Mode}
220 */ 242 */
221 remoting.SessionConnectorImpl.prototype.getConnectionMode = function() { 243 remoting.SessionConnectorImpl.prototype.getConnectionMode = function() {
222 return this.connectionMode_; 244 return this.connectionMode_;
223 }; 245 };
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 } 312 }
291 }; 313 };
292 314
293 /** 315 /**
294 * Creates ClientSession object. 316 * Creates ClientSession object.
295 */ 317 */
296 remoting.SessionConnectorImpl.prototype.createSession_ = function() { 318 remoting.SessionConnectorImpl.prototype.createSession_ = function() {
297 // In some circumstances, the WCS <iframe> can get reloaded, which results 319 // In some circumstances, the WCS <iframe> can get reloaded, which results
298 // in a new clientJid and a new callback. In this case, remove the old 320 // in a new clientJid and a new callback. In this case, remove the old
299 // client plugin before instantiating a new one. 321 // client plugin before instantiating a new one.
300 if (this.clientSession_) { 322 this.removePlugin_();
301 this.clientSession_.removePlugin(); 323
302 this.clientSession_ = null; 324 var pluginContainer = this.clientContainer_.querySelector(
325 '.client-plugin-container');
326
327 this.plugin_ = remoting.ClientPlugin.factory.createPlugin(
328 pluginContainer, this.onExtensionMessage_, this.requiredCapabilities_);
329
330 var that = this;
331 this.host_.options.load().then(function(){
332 that.plugin_.initialize(that.onPluginInitialized_.bind(that));
333 });
334 };
335
336 /**
337 * @param {boolean} initialized
338 * @private
339 */
340 remoting.SessionConnectorImpl.prototype.onPluginInitialized_ = function(
341 initialized) {
342 if (!initialized) {
343 console.error('ERROR: remoting plugin not loaded');
344 this.pluginError_(remoting.Error.MISSING_PLUGIN);
345 return;
346 }
347
348 if (!this.plugin_.isSupportedVersion()) {
349 console.error('ERROR: bad plugin version');
350 this.pluginError_(remoting.Error.BAD_PLUGIN_VERSION);
351 return;
303 } 352 }
304 353
305 this.clientSession_ = new remoting.ClientSession( 354 this.clientSession_ = new remoting.ClientSession(
306 this.host_, this.signalStrategy_, this.credentialsProvider_, 355 this.plugin_, this.host_, this.signalStrategy_, this.connectionMode_);
307 this.clientContainer_, this.connectionMode_, this.defaultRemapKeys_); 356 remoting.clientSession = this.clientSession_;
357
358 this.connectedView_ = new remoting.DesktopConnectedView(
359 this.plugin_, this.clientSession_, this.clientContainer_, this.host_,
360 this.connectionMode_,
361 this.defaultRemapKeys_);
362 remoting.desktopConnectedView = this.connectedView_;
363
308 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_); 364 this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_);
309 this.clientSession_.addEventListener( 365 this.clientSession_.addEventListener(
310 remoting.ClientSession.Events.stateChanged, 366 remoting.ClientSession.Events.stateChanged,
311 this.bound_.onStateChange); 367 this.bound_.onStateChange);
312 this.clientSession_.createPluginAndConnect(this.onExtensionMessage_, 368
313 this.requiredCapabilities_); 369 this.plugin_.connect(
370 this.host_, this.signalStrategy_.getJid(), this.credentialsProvider_);
314 }; 371 };
315 372
316 /** 373 /**
374 * @param {remoting.Error} error
375 * @private
376 */
377 remoting.SessionConnectorImpl.prototype.pluginError_ = function(error) {
378 this.signalStrategy_.setIncomingStanzaCallback(null);
379 this.clientSession_.disconnect(error);
380 this.removePlugin_();
381 };
382
383 /** @private */
384 remoting.SessionConnectorImpl.prototype.removePlugin_ = function() {
385 if (this.clientSession_) {
386 this.clientSession_.removePlugin();
387 }
388 this.clientSession_ = null;
389 remoting.clientSession = null;
390
391 if (this.connectedView_) {
392 this.connectedView_.removePlugin();
393 }
394 this.connectedView_ = null;
395 remoting.desktopConnectedView = null;
396
397 if (this.plugin_) {
398 this.plugin_.dispose();
399 }
400 this.plugin_ = null;
401 };
402
403 /**
317 * Handle a change in the state of the client session prior to successful 404 * Handle a change in the state of the client session prior to successful
318 * connection (after connection, this class no longer handles state change 405 * connection (after connection, this class no longer handles state change
319 * events). Errors that occur while connecting either trigger a reconnect 406 * events). Errors that occur while connecting either trigger a reconnect
320 * or notify the onError handler. 407 * or notify the onError handler.
321 * 408 *
322 * @param {remoting.ClientSession.StateEvent=} event 409 * @param {remoting.ClientSession.StateEvent=} event
323 * @return {void} Nothing. 410 * @return {void} Nothing.
324 * @private 411 * @private
325 */ 412 */
326 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) { 413 remoting.SessionConnectorImpl.prototype.onStateChange_ = function(event) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 */ 496 */
410 remoting.DefaultSessionConnectorFactory.prototype.createConnector = 497 remoting.DefaultSessionConnectorFactory.prototype.createConnector =
411 function(clientContainer, onConnected, onError, onExtensionMessage, 498 function(clientContainer, onConnected, onError, onExtensionMessage,
412 onConnectionFailed, requiredCapabilities, defaultRemapKeys) { 499 onConnectionFailed, requiredCapabilities, defaultRemapKeys) {
413 return new remoting.SessionConnectorImpl(clientContainer, onConnected, 500 return new remoting.SessionConnectorImpl(clientContainer, onConnected,
414 onError, onExtensionMessage, 501 onError, onExtensionMessage,
415 onConnectionFailed, 502 onConnectionFailed,
416 requiredCapabilities, 503 requiredCapabilities,
417 defaultRemapKeys); 504 defaultRemapKeys);
418 }; 505 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/session_connector.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698