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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/crd/js/session_connector_impl.js
diff --git a/remoting/webapp/crd/js/session_connector_impl.js b/remoting/webapp/crd/js/session_connector_impl.js
index fdbd6f0ccc6b1d7bf30f0ba261f301c90c2d4ac0..83851a521ddb99cba89d0a163a37c14794327bb2 100644
--- a/remoting/webapp/crd/js/session_connector_impl.js
+++ b/remoting/webapp/crd/js/session_connector_impl.js
@@ -108,14 +108,14 @@ remoting.SessionConnectorImpl = function(clientContainer, onConnected, onError,
};
// Initialize/declare per-connection state.
- this.reset();
+ this.reset_();
};
/**
* Reset the per-connection state so that the object can be re-used for a
* 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.
*/
-remoting.SessionConnectorImpl.prototype.reset = function() {
+remoting.SessionConnectorImpl.prototype.reset_ = function() {
/**
* @type {remoting.Host}
* @private
@@ -128,12 +128,18 @@ remoting.SessionConnectorImpl.prototype.reset = function() {
*/
this.logHostOfflineErrors_ = false;
+ /** @private {remoting.ClientPlugin} */
+ this.plugin_ = null;
+
/**
* @type {remoting.ClientSession}
* @private
*/
this.clientSession_ = null;
+ /** @private {remoting.DesktopConnectedView} */
+ this.connectedView_ = null;
+
/**
* @type {XMLHttpRequest}
* @private
@@ -288,15 +294,11 @@ remoting.SessionConnectorImpl.prototype.reconnect = function() {
* Cancel a connection-in-progress.
*/
remoting.SessionConnectorImpl.prototype.cancel = function() {
- if (this.clientSession_) {
- this.clientSession_.removePlugin();
- this.clientSession_ = null;
- }
if (this.pendingXhr_) {
this.pendingXhr_.abort();
this.pendingXhr_ = null;
}
- this.reset();
+ this.resetConnection();
};
/**
@@ -433,20 +435,89 @@ remoting.SessionConnectorImpl.prototype.createSession_ = function() {
// In some circumstances, the WCS <iframe> can get reloaded, which results
// in a new clientJid and a new callback. In this case, remove the old
// client plugin before instantiating a new one.
- if (this.clientSession_) {
- this.clientSession_.removePlugin();
- this.clientSession_ = null;
- }
+ this.removePlugin();
this.clientSession_ = new remoting.ClientSession(
this.host_, this.signalStrategy_, this.credentialsProvider_,
- this.clientContainer_, this.connectionMode_, this.defaultRemapKeys_);
+ this.connectionMode_);
+ remoting.clientSession = this.clientSession_;
+
+ 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.
+ this.clientSession_, this.clientContainer_, this.host_,
+ this.connectionMode_,
+ this.defaultRemapKeys_);
+ remoting.desktopConnectedView = this.connectedView_;
+
this.clientSession_.logHostOfflineErrors(this.logHostOfflineErrors_);
this.clientSession_.addEventListener(
remoting.ClientSession.Events.stateChanged,
this.bound_.onStateChange);
- this.clientSession_.createPluginAndConnect(this.onExtensionMessage_,
- this.requiredCapabilities_);
+
+ var pluginContainer = this.clientContainer_.querySelector(
+ '.client-plugin-container');
+
+ this.plugin_ = remoting.ClientPlugin.factory.createPlugin(
+ pluginContainer, this.onExtensionMessage_, this.requiredCapabilities_);
+
+ var that = this;
+ this.host_.options.load().then(function(){
+ that.plugin_.initialize(that.onPluginInitialized_.bind(that));
+ });
+};
+
+/**
+ * @param {boolean} initialized
+ */
+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.
+ initialized) {
+ if (!initialized) {
+ console.error('ERROR: remoting plugin not loaded');
+ this.pluginError(remoting.Error.MISSING_PLUGIN);
+ return;
+ }
+
+ if (!this.plugin_.isSupportedVersion()) {
+ console.error('ERROR: bad plugin version');
+ this.pluginError(remoting.Error.BAD_PLUGIN_VERSION);
+ return;
+ }
+
+ 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.
+ this.clientSession_.onPluginInitialized(this.plugin_);
+};
+
+/** @param {remoting.Error} error */
+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.
+ this.signalStrategy_.setIncomingStanzaCallback(null);
+ this.clientSession_.disconnect(error);
+ this.removePlugin();
+};
+
+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.
+ if (this.plugin_) {
+ this.clientSession_.removePlugin();
+ this.connectedView_.removePlugin();
+ this.plugin_.dispose();
+ }
+ this.plugin_ = null;
+
+ if (this.clientSession_) {
+ 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.
+ }
+ this.clientSession_ = null
+ remoting.clientSession = null;
+
+ this.connectedView_ = null;
+ remoting.desktopConnectedView = null;
+};
+
+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.
+ this.removePlugin();
+
+ this.host_ = null;
+ this.logHostOfflineErrors_ = false;
+ this.pendingXhr_ = null;
kelvinp 2015/03/06 02:58:38 This is already cleared in reset.
garykac 2015/03/06 23:38:33 Done.
+ 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.
};
/**

Powered by Google App Engine
This is Rietveld 408576698