Index: remoting/webapp/host_it2me_dispatcher.js |
diff --git a/remoting/webapp/host_it2me_dispatcher.js b/remoting/webapp/host_it2me_dispatcher.js |
index bd75a4f88de70aff02057d47b6a081964d3558f9..3c2fce7762380181038c9bc5921a916ed42dfc74 100644 |
--- a/remoting/webapp/host_it2me_dispatcher.js |
+++ b/remoting/webapp/host_it2me_dispatcher.js |
@@ -5,9 +5,12 @@ |
/** |
* @fileoverview |
* This class provides an interface between the HostSession and either the |
- * NativeMessaging Host |
+ * NativeMessaging Host or the Host NPAPI plugin, depending on whether or not |
+ * NativeMessaging is supported. Since the test for NativeMessaging support is |
+ * asynchronous, the connection is attemped on either the the NativeMessaging |
+ * host or the NPAPI plugin once the test is complete. |
* |
- * TODO(sergeyu): Remove this class. |
+ * TODO(sergeyu): Remove this class once the NPAPI plugin is dropped. |
*/ |
'use strict'; |
@@ -25,12 +28,20 @@ |
this.nativeMessagingHost_ = null; |
/** |
+ * @type {remoting.HostPlugin} |
+ * @private */ |
+ this.npapiHost_ = null; |
+ |
+ /** |
* @param {remoting.Error} error |
* @private */ |
this.onErrorHandler_ = function(error) {} |
}; |
/** |
+ * @param {function():remoting.HostPlugin} createPluginCallback Callback to |
+ * instantiate the NPAPI plugin when NativeMessaging is determined to be |
+ * unsupported. |
* @param {function():void} onDispatcherInitialized Callback to be called after |
* initialization has finished successfully. |
* @param {function(remoting.Error):void} onDispatcherInitializationFailed |
@@ -38,18 +49,31 @@ |
* plugin works. |
*/ |
remoting.HostIt2MeDispatcher.prototype.initialize = |
- function(onDispatcherInitialized, |
+ function(createPluginCallback, onDispatcherInitialized, |
onDispatcherInitializationFailed) { |
/** @type {remoting.HostIt2MeDispatcher} */ |
var that = this; |
function onNativeMessagingStarted() { |
+ console.log('Native Messaging supported.'); |
+ |
+ that.npapiHost_ = null; |
onDispatcherInitialized(); |
} |
function onNativeMessagingInitFailed() { |
+ console.log('Native Messaging unsupported, falling back to NPAPI.'); |
+ |
that.nativeMessagingHost_ = null; |
- onDispatcherInitializationFailed(remoting.Error.MISSING_PLUGIN); |
+ that.npapiHost_ = createPluginCallback(); |
+ |
+ // TODO(weitaosu): is there a better way to check whether NPAPI plugin is |
+ // supported? |
+ if (that.npapiHost_) { |
+ onDispatcherInitialized(); |
+ } else { |
+ onDispatcherInitializationFailed(remoting.Error.MISSING_PLUGIN); |
+ } |
} |
this.nativeMessagingHost_ = new remoting.HostIt2MeNativeMessaging(); |
@@ -65,6 +89,20 @@ |
function(error) { |
this.nativeMessagingHost_ = null; |
this.onErrorHandler_(error); |
+} |
+ |
+/** |
+ * @return {boolean} |
+ */ |
+remoting.HostIt2MeDispatcher.prototype.usingNpapi = function() { |
+ return this.npapiHost_ != null; |
+} |
+ |
+/** |
+ * @return {remoting.HostPlugin} |
+ */ |
+remoting.HostIt2MeDispatcher.prototype.getNpapiHost = function() { |
+ return this.npapiHost_; |
} |
/** |
@@ -95,6 +133,15 @@ |
this.nativeMessagingHost_.connect( |
email, authServiceWithToken, onStateChanged, onNatPolicyChanged, |
xmppServerAddress, xmppServerUseTls, directoryBotJid); |
+ } else if (this.npapiHost_) { |
+ this.npapiHost_.xmppServerAddress = xmppServerAddress; |
+ this.npapiHost_.xmppServerUseTls = xmppServerUseTls; |
+ this.npapiHost_.directoryBotJid = directoryBotJid; |
+ this.npapiHost_.onStateChanged = onStateChanged; |
+ this.npapiHost_.onNatTraversalPolicyChanged = onNatPolicyChanged; |
+ this.npapiHost_.logDebugInfo = logDebugInfo; |
+ this.npapiHost_.localize(chrome.i18n.getMessage); |
+ this.npapiHost_.connect(email, authServiceWithToken); |
} else { |
console.error( |
'remoting.HostIt2MeDispatcher.connect() without initialization.'); |
@@ -106,26 +153,51 @@ |
* @return {void} |
*/ |
remoting.HostIt2MeDispatcher.prototype.disconnect = function() { |
- this.nativeMessagingHost_.disconnect(); |
+ if (this.npapiHost_) { |
+ this.npapiHost_.disconnect(); |
+ } else { |
+ this.nativeMessagingHost_.disconnect(); |
+ } |
}; |
/** |
* @return {string} The access code generated by the it2me host. |
*/ |
remoting.HostIt2MeDispatcher.prototype.getAccessCode = function() { |
- return this.nativeMessagingHost_.getAccessCode(); |
+ if (this.npapiHost_) { |
+ return this.npapiHost_.accessCode; |
+ } else { |
+ return this.nativeMessagingHost_.getAccessCode(); |
+ } |
}; |
/** |
* @return {number} The access code lifetime, in seconds. |
*/ |
remoting.HostIt2MeDispatcher.prototype.getAccessCodeLifetime = function() { |
- return this.nativeMessagingHost_.getAccessCodeLifetime(); |
+ if (this.npapiHost_) { |
+ return this.npapiHost_.accessCodeLifetime; |
+ } else { |
+ return this.nativeMessagingHost_.getAccessCodeLifetime(); |
+ } |
}; |
/** |
* @return {string} The client's email address. |
*/ |
remoting.HostIt2MeDispatcher.prototype.getClient = function() { |
- return this.nativeMessagingHost_.getClient(); |
-}; |
+ if (this.npapiHost_) { |
+ return this.npapiHost_.client; |
+ } else { |
+ return this.nativeMessagingHost_.getClient(); |
+ } |
+}; |
+ |
+/** |
+ * @return {void} |
+ */ |
+remoting.HostIt2MeDispatcher.prototype.cleanup = function() { |
+ if (this.npapiHost_) { |
+ this.npapiHost_.parentNode.removeChild(this.npapiHost_); |
+ } |
+}; |