diff options
Diffstat (limited to 'remoting/webapp')
-rw-r--r-- | remoting/webapp/all_js_load.gtestjs | 2 | ||||
-rw-r--r-- | remoting/webapp/host_controller.js | 4 | ||||
-rw-r--r-- | remoting/webapp/host_it2me_dispatcher.js | 136 | ||||
-rw-r--r-- | remoting/webapp/host_it2me_native_messaging.js | 349 | ||||
-rw-r--r-- | remoting/webapp/host_screen.js | 69 | ||||
-rw-r--r-- | remoting/webapp/host_session.js | 82 | ||||
-rw-r--r-- | remoting/webapp/main.html | 2 | ||||
-rw-r--r-- | remoting/webapp/remoting.js | 25 |
8 files changed, 68 insertions, 601 deletions
diff --git a/remoting/webapp/all_js_load.gtestjs b/remoting/webapp/all_js_load.gtestjs index 0ab7cf8..7c72946 100644 --- a/remoting/webapp/all_js_load.gtestjs +++ b/remoting/webapp/all_js_load.gtestjs @@ -35,8 +35,6 @@ AllJsLoadTest.prototype = { 'host.js', 'host_controller.js', 'host_dispatcher.js', - 'host_it2me_dispatcher.js', - 'host_it2me_native_messaging.js', 'host_list.js', 'host_native_messaging.js', //'host_plugin_proto.js', // Only used by jscompiler diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js index 21485b1..96a0bb0 100644 --- a/remoting/webapp/host_controller.js +++ b/remoting/webapp/host_controller.js @@ -10,7 +10,7 @@ var remoting = remoting || {}; /** @constructor */ remoting.HostController = function() { /** @return {remoting.HostPlugin} */ - var createPluginForMe2Me = function() { + var createNpapiPlugin = function() { var plugin = remoting.HostSession.createPlugin(); /** @type {HTMLElement} @private */ var container = document.getElementById('daemon-plugin-container'); @@ -19,7 +19,7 @@ remoting.HostController = function() { }; /** @type {remoting.HostDispatcher} @private */ - this.hostDispatcher_ = new remoting.HostDispatcher(createPluginForMe2Me); + this.hostDispatcher_ = new remoting.HostDispatcher(createNpapiPlugin); /** @param {string} version */ var printVersion = function(version) { diff --git a/remoting/webapp/host_it2me_dispatcher.js b/remoting/webapp/host_it2me_dispatcher.js deleted file mode 100644 index b018db6..0000000 --- a/remoting/webapp/host_it2me_dispatcher.js +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/** - * @fileoverview - * This class provides an interface between the HostSession and either the - * 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. - */ - -'use strict'; - -/** @suppress {duplicate} */ -var remoting = remoting || {}; - -/** - * @constructor - */ -remoting.HostIt2MeDispatcher = function() { - /** @type {remoting.HostIt2MeNativeMessaging} @private */ - this.nativeMessagingHost_ = new remoting.HostIt2MeNativeMessaging(); - - /** @type {remoting.HostPlugin} @private */ - this.npapiHost_ = null; -}; - -/** - * @param {function():remoting.HostPlugin} createPluginCallback Callback to - * instantiate the NPAPI plugin when NativeMessaging is determined to be - * unsupported. - * @param {string} email The user's email address. - * @param {string} authServiceWithToken Concatenation of the auth service - * (e.g. oauth2) and the access token. - * @param {function(remoting.HostSession.State):void} onStateChanged Callback to - * invoke when the host state changes. - * @param {function(boolean):void} onNatPolicyChanged Callback to invoke when - * the nat traversal policy changes. - * @param {string} xmppServerAddress XMPP server host name (or IP address) and - * port. - * @param {boolean} xmppServerUseTls Whether to use TLS on connections to the - * XMPP server - * @param {string} directoryBotJid XMPP JID for the remoting directory server - * bot. - * @param {function():void} onError Callback to invoke if neither the native - * messaging host nor the npapi plugin works. - */ -remoting.HostIt2MeDispatcher.prototype.initAndConnect = - function(createPluginCallback, email, authServiceWithToken, onStateChanged, - onNatPolicyChanged, xmppServerAddress, xmppServerUseTls, - directoryBotJid, onError) { - var that = this; - function onNativeMessagingStarted() { - console.log('Native Messaging supported.'); - that.nativeMessagingHost_.connect( - email, authServiceWithToken, onStateChanged, onNatPolicyChanged, - xmppServerAddress, xmppServerUseTls, directoryBotJid); - } - - function onNativeMessagingFailed() { - console.log('Native Messaging unsupported, falling back to NPAPI.'); - that.npapiHost_ = createPluginCallback(); - // TODO(weitaosu): is there a better way to check whether NPAPI plugin is - // supported? - if (that.npapiHost_.hasOwnProperty('REQUESTED_ACCESS_CODE')) { - that.npapiHost_.xmppServerAddress = xmppServerAddress; - that.npapiHost_.xmppServerUseTls = xmppServerUseTls; - that.npapiHost_.directoryBotJid = directoryBotJid; - that.npapiHost_.onStateChanged = onStateChanged; - that.npapiHost_.onNatTraversalPolicyChanged = onNatTraversalPolicyChanged; - that.npapiHost_.logDebugInfo = logDebugInfo; - that.npapiHost_.localize(chrome.i18n.getMessage); - that.npapiHost_.connect(email, authServiceWithToken); - } else { - onError(); - } - } - - this.nativeMessagingHost_.initialize( - onNativeMessagingStarted, onNativeMessagingFailed, onError); -}; - -/** - * @return {void} - */ -remoting.HostIt2MeDispatcher.prototype.disconnect = function() { - 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() { - 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() { - if (this.npapiHost_) { - return this.npapiHost_.accessCodeLifetime; - } else { - return this.nativeMessagingHost_.getAccessCodeLifetime(); - } -}; - -/** - * @return {string} The client's email address. - */ -remoting.HostIt2MeDispatcher.prototype.getClient = function() { - 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_); - } -}; diff --git a/remoting/webapp/host_it2me_native_messaging.js b/remoting/webapp/host_it2me_native_messaging.js deleted file mode 100644 index 567f2c5..0000000 --- a/remoting/webapp/host_it2me_native_messaging.js +++ /dev/null @@ -1,349 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/** - * @fileoverview - * Class to communicate with the It2me Host component via Native Messaging. - */ - -'use strict'; - -/** @suppress {duplicate} */ -var remoting = remoting || {}; - -/** - * @constructor - * @param {function(remoting.HostSession.State):void} onStateChanged Callback to - * invoke when the host state changes. - * @param {function(boolean):void} onNatPolicyChanged Callback to invoke when - * the nat traversal policy changes. - */ -remoting.HostIt2MeNativeMessaging = function() { - /** - * @type {number} - * @private - */ - this.nextId_ = 0; - - /** - * @type {?chrome.extension.Port} - * @private - */ - this.port_ = null; - - /** - * @type {string} - * @private - */ - this.accessCode_ = ''; - - /** - * @type {number} - * @private - */ - this.accessCodeLifetime_ = 0; - - /** - * @type {string} - * @private - */ - this.clientId_ = ''; - - /** - * @type {boolean} - * @private - */ - this.initialized_ = false; - - /** - * @type {function():void} - * @private - */ - this.onHostStarted_ = function() {}; - - /** - * @type {function():void} Called if Native Messaging is not supported or the - * It2Me Native Messaging host is not installed. - * @private - * */ - this.onHostInitFailed_ = function() {}; - - /** - * @type {function():void} Called if the It2Me Native Messaging host sends a - * malformed message: missing required attributes, attributes with - * incorrect types, etc. - * @private - */ - this.onError_ = function() {}; - - /** - * @type {function(remoting.HostSession.State):void} - * @private - */ - this.onStateChanged_ = function() {}; - - /** - * @type {function(boolean):void} - * @private - */ - this.onNatPolicyChanged_ = function() {}; -}; - -/** - * Sets up connection to the Native Messaging host process and exchanges - * 'hello' messages. If Native Messaging is not supported or if the it2me - * native messaging host is not installed, onHostInitFailed is invoked. - * Otherwise, onHostStarted is invoked. - * - * @param {function():void} onHostStarted Called after successful - * initialization. - * @param {function():void} onHostInitFailed Called if cannot connect to host. - * @param {function():void} onError Called on host error after successfully - * connecting to the host. - * @return {void} - */ -remoting.HostIt2MeNativeMessaging.prototype.initialize = - function(onHostStarted, onHostInitFailed, onError) { - this.onHostStarted_ = onHostStarted; - this.onHostInitFailed_ = onHostInitFailed; - this.onError_ = onError; - - try { - this.port_ = chrome.runtime.connectNative( - 'com.google.chrome.remote_assistance'); - this.port_.onMessage.addListener(this.onIncomingMessage_.bind(this)); - this.port_.onDisconnect.addListener(this.onHostDisconnect_.bind(this)); - this.postMessage_({type: 'hello'}); - } catch (err) { - console.log('Native Messaging initialization failed: ', - /** @type {*} */ (err)); - onHostInitFailed(); - return; - } -}; - -/** - * Attaches a new ID to the supplied message, and posts it to the Native - * Messaging port. - * |message| should have its 'type' field set, and any other fields set - * depending on the message type. - * - * @param {{type: string}} message The message to post. - * @return {void} - * @private - */ -remoting.HostIt2MeNativeMessaging.prototype.postMessage_ = - function(message) { - var id = this.nextId_++; - message['id'] = id; - this.port_.postMessage(message); -}; - -/** - * Handler for incoming Native Messages. - * - * @param {Object} message The received message. - * @return {void} - * @private - */ -remoting.HostIt2MeNativeMessaging.prototype.onIncomingMessage_ = - function(message) { - var type = message['type']; - if (!checkType_('type', type, 'string')) { - this.onError_(); - return; - } - - switch (type) { - case 'helloResponse': - /** @type {string} */ - var version = message['version']; - if (checkType_('version', version, 'string')) { - console.log('Host version: ', version); - this.initialized_ = true; - // A "hello" request is sent immediately after the native messaging host - // is started. We can proceed to the next task once we receive the - // "helloReponse". - this.onHostStarted_(); - } else { - this.onError_(); - } - break; - - case 'connectResponse': - console.log('connectResponse received'); - // Response to the "connect" request. No action is needed until we - // receive the corresponding "hostStateChagned" message. - break; - - case 'disconnectResponse': - console.log('disconnectResponse received'); - // Response to the "disconnect" request. No action is needed until we - // receive the corresponding "hostStateChagned" message. - break; - - case 'hostStateChanged': - /** @type {string} */ - var stateString = message['state']; - if (!checkType_('stateString', stateString, 'string')) { - this.onError_(); - break; - } - - console.log('hostStateChanged received: ', stateString); - - /** @type {remoting.HostSession.State} */ - var state = remoting.HostSession.stateFromString(stateString); - - switch (state) { - case remoting.HostSession.State.RECEIVED_ACCESS_CODE: - /** @type {string} */ - var accessCode = message['accessCode']; - if (!checkType_('accessCode', accessCode, 'string')) { - this.onError_(); - break; - } - - /** @type {number} */ - var accessCodeLifetime = message['accessCodeLifetime']; - if (!checkType_('accessCodeLifetime', accessCodeLifetime, 'number')) { - this.onError_(); - break; - } - - this.onReceivedAccessCode_(accessCode, accessCodeLifetime); - break; - - case remoting.HostSession.State.CONNECTED: - /** @type {string} */ - var client = message['client']; - if (checkType_('client', client, 'string')) { - this.onConnected_(client); - } else { - this.onError_(); - } - break; - } - this.onStateChanged_(state); - break; - - case 'natPolicyChanged': - /** @type {boolean} */ - var natTraversalEnabled = message['natTraversalEnabled']; - if (checkType_('natTraversalEnabled', natTraversalEnabled, 'boolean')) { - this.onNatPolicyChanged_(natTraversalEnabled); - } else { - this.onError_(); - } - break; - - case 'error': - /** @type {string} */ - var description = message['description']; - // Ignore the return value. - checkType_('description', description, 'string'); - this.onError_(); - break; - - default: - console.error('Unexpected native message: ', message); - this.onError_(); - } -}; - -/** - * @param {string} email The user's email address. - * @param {string} authServiceWithToken Concatenation of the auth service - * (e.g. oauth2) and the access token. - * @param {function(remoting.HostSession.State):void} onStateChanged Callback to - * invoke when the host state changes. - * @param {function(boolean):void} onNatPolicyChanged Callback to invoke when - * the nat traversal policy changes. - * @param {string} xmppServerAddress XMPP server host name (or IP address) and - * port. - * @param {boolean} xmppServerUseTls Whether to use TLS on connections to the - * XMPP server - * @param {string} directoryBotJid XMPP JID for the remoting directory server - * bot. - * @return {void} - */ -remoting.HostIt2MeNativeMessaging.prototype.connect = - function(email, authServiceWithToken, onStateChanged, onNatPolicyChanged, - xmppServerAddress, xmppServerUseTls, directoryBotJid) { - this.onStateChanged_ = onStateChanged; - this.onNatPolicyChanged_ = onNatPolicyChanged; - this.postMessage_({ - type: 'connect', - userName: email, - authServiceWithToken: authServiceWithToken, - xmppServerAddress: xmppServerAddress, - xmppServerUseTls: xmppServerUseTls, - directoryBotJid: directoryBotJid}); -}; - -/** - * @return {void} - */ -remoting.HostIt2MeNativeMessaging.prototype.disconnect = - function() { - this.postMessage_({ - type: 'disconnect'}); -}; - -/** - * @param {string} accessCode - * @param {number} accessCodeLifetime - * @return {void} - * @private - */ -remoting.HostIt2MeNativeMessaging.prototype.onReceivedAccessCode_ = - function(accessCode, accessCodeLifetime) { - this.accessCode_ = accessCode; - this.accessCodeLifetime_ = accessCodeLifetime; -}; - -/** - * @param {string} clientId - * @return {void} - * @private - */ -remoting.HostIt2MeNativeMessaging.prototype.onConnected_ = - function(clientId) { - this.clientId_ = clientId; -}; - -/** - * @return {void} - * @private - */ -remoting.HostIt2MeNativeMessaging.prototype.onHostDisconnect_ = function() { - if (!this.initialized_) { - console.error('Native Messaging initialization failed.'); - this.onHostInitFailed_(); - } else { - console.error('Native Messaging port disconnected.'); - this.onError_(); - } -} - -/** - * @return {string} - */ -remoting.HostIt2MeNativeMessaging.prototype.getAccessCode = function() { - return this.accessCode_ -}; - -/** - * @return {number} - */ -remoting.HostIt2MeNativeMessaging.prototype.getAccessCodeLifetime = function() { - return this.accessCodeLifetime_ -}; - -/** - * @return {string} - */ -remoting.HostIt2MeNativeMessaging.prototype.getClient = function() { - return this.clientId_; -}; diff --git a/remoting/webapp/host_screen.js b/remoting/webapp/host_screen.js index 39eb0c4..df4008b 100644 --- a/remoting/webapp/host_screen.js +++ b/remoting/webapp/host_screen.js @@ -14,7 +14,8 @@ var remoting = remoting || {}; /** * @type {boolean} Whether or not the last share was cancelled by the user. - * This controls what screen is shown when the host signals completion. + * This controls what screen is shown when the host plugin signals + * completion. * @private */ var lastShareWasCancelled_ = false; @@ -41,38 +42,31 @@ remoting.tryShareWithToken_ = function(token) { disableTimeoutCountdown_(); var div = document.getElementById('host-plugin-container'); - // TODO(weitaosu): Unlike the npapi plugin, the it2me native messaging host - // can be long-lived and will create an it2me host on demand. We should also - // keep the HostSession and HostIt2MeDispatcher object alive to avoid repeated - // creation of the native messaging host. remoting.hostSession = new remoting.HostSession(); - remoting.hostSession.createDispatcherAndConnect( + remoting.hostSession.createPluginAndConnect( document.getElementById('host-plugin-container'), /** @type {string} */(remoting.identity.getCachedEmail()), token, - onHostStateChanged_, onNatTraversalPolicyChanged_, - logDebugInfo_, - it2meConnectFailed_); + onHostStateChanged_, + logDebugInfo_); }; /** * Callback for the host plugin to notify the web app of state changes. * @param {remoting.HostSession.State} state The new state of the plugin. - * @return {void} Nothing. - * @private */ function onHostStateChanged_(state) { if (state == remoting.HostSession.State.STARTING) { // Nothing to do here. - console.log('Host state: STARTING'); + console.log('Host plugin state: STARTING'); } else if (state == remoting.HostSession.State.REQUESTED_ACCESS_CODE) { // Nothing to do here. - console.log('Host state: REQUESTED_ACCESS_CODE'); + console.log('Host plugin state: REQUESTED_ACCESS_CODE'); } else if (state == remoting.HostSession.State.RECEIVED_ACCESS_CODE) { - console.log('Host state: RECEIVED_ACCESS_CODE'); + console.log('Host plugin state: RECEIVED_ACCESS_CODE'); var accessCode = remoting.hostSession.getAccessCode(); var accessCodeDisplay = document.getElementById('access-code-display'); accessCodeDisplay.innerText = ''; @@ -86,7 +80,8 @@ function onHostStateChanged_(state) { } accessCodeExpiresIn_ = remoting.hostSession.getAccessCodeLifetime(); if (accessCodeExpiresIn_ > 0) { // Check it hasn't expired. - accessCodeTimerId_ = setInterval(decrementAccessCodeTimeout_, 1000); + accessCodeTimerId_ = setInterval( + remoting.decrementAccessCodeTimeout_, 1000); timerRunning_ = true; updateAccessCodeTimeoutElement_(); updateTimeoutStyles_(); @@ -99,7 +94,7 @@ function onHostStateChanged_(state) { } } else if (state == remoting.HostSession.State.CONNECTED) { - console.log('Host state: CONNECTED'); + console.log('Host plugin state: CONNECTED'); var element = document.getElementById('host-shared-message'); var client = remoting.hostSession.getClient(); l10n.localizeElement(element, client); @@ -107,10 +102,10 @@ function onHostStateChanged_(state) { disableTimeoutCountdown_(); } else if (state == remoting.HostSession.State.DISCONNECTING) { - console.log('Host state: DISCONNECTING'); + console.log('Host plugin state: DISCONNECTING'); } else if (state == remoting.HostSession.State.DISCONNECTED) { - console.log('Host state: DISCONNECTED'); + console.log('Host plugin state: DISCONNECTED'); if (remoting.currentMode != remoting.AppMode.HOST_SHARE_FAILED) { // If an error is being displayed, then the plugin should not be able to // hide it by setting the state. Errors must be dismissed by the user @@ -121,13 +116,13 @@ function onHostStateChanged_(state) { remoting.setMode(remoting.AppMode.HOST_SHARE_FINISHED); } } - remoting.hostSession.cleanup(); + remoting.hostSession.removePlugin(); } else if (state == remoting.HostSession.State.ERROR) { - console.error('Host state: ERROR'); + console.error('Host plugin state: ERROR'); showShareError_(remoting.Error.UNEXPECTED); } else if (state == remoting.HostSession.State.INVALID_DOMAIN_ERROR) { - console.error('Host state: INVALID_DOMAIN_ERROR'); + console.error('Host plugin state: INVALID_DOMAIN_ERROR'); showShareError_(remoting.Error.INVALID_HOST_DOMAIN); } else { console.error('Unknown state -> ' + state); @@ -138,7 +133,6 @@ function onHostStateChanged_(state) { * This is the callback that the host plugin invokes to indicate that there * is additional debug log info to display. * @param {string} msg The message (which will not be localized) to be logged. - * @private */ function logDebugInfo_(msg) { console.log('plugin: ' + msg); @@ -149,7 +143,6 @@ function logDebugInfo_(msg) { * * @param {string} errorTag The error message to be localized and displayed. * @return {void} Nothing. - * @private */ function showShareError_(errorTag) { var errorDiv = document.getElementById('host-plugin-error'); @@ -159,21 +152,7 @@ function showShareError_(errorTag) { } /** - * Show a sharing error with error code UNEXPECTED . - * - * @return {void} Nothing. - * @private - */ -function it2meConnectFailed_() { - // TODO (weitaosu): Instruct the user to install the native messaging host. - // We probably want to add a new error code (with the corresponding error - // message for sharing error. - console.error('Cannot share desktop.'); - showShareError_(remoting.Error.UNEXPECTED); -} - -/** - * Cancel an active or pending it2me share operation. + * Cancel an active or pending share operation. * * @return {void} Nothing. */ @@ -187,7 +166,7 @@ remoting.cancelShare = function() { // Hack to force JSCompiler type-safety. var errorTyped = /** @type {{description: string}} */ error; console.error('Error disconnecting: ' + errorTyped.description + - '. The host probably crashed.'); + '. The host plugin probably crashed.'); // TODO(jamiewalch): Clean this up. We should have a class representing // the host plugin, like we do for the client, which should handle crash // reporting and it should use a more detailed error message than the @@ -216,19 +195,17 @@ var accessCodeTimerId_ = 0; var accessCodeExpiresIn_ = 0; /** - * The timer callback function - * @return {void} Nothing. + * The timer callback function, which needs to be visible from the global + * namespace. * @private */ -function decrementAccessCodeTimeout_() { +remoting.decrementAccessCodeTimeout_ = function() { --accessCodeExpiresIn_; updateAccessCodeTimeoutElement_(); }; /** * Stop the access code timeout countdown if it is running. - * @return {void} Nothing. - * @private */ function disableTimeoutCountdown_() { if (timerRunning_) { @@ -251,7 +228,6 @@ var ACCESS_CODE_RED_THRESHOLD_ = 10; * * @return {boolean} True if the timeout is in progress, false if it has * expired. - * @private */ function updateTimeoutStyles_() { if (timerRunning_) { @@ -275,8 +251,6 @@ function updateTimeoutStyles_() { /** * Update the text and appearance of the access code timeout element to * reflect the time remaining. - * @return {void} Nothing. - * @private */ function updateAccessCodeTimeoutElement_() { var pad = (accessCodeExpiresIn_ < 10) ? '0:0' : '0:'; @@ -291,7 +265,6 @@ function updateAccessCodeTimeoutElement_() { * Callback to show or hide the NAT traversal warning when the policy changes. * @param {boolean} enabled True if NAT traversal is enabled. * @return {void} Nothing. - * @private */ function onNatTraversalPolicyChanged_(enabled) { var natBox = document.getElementById('nat-box'); diff --git a/remoting/webapp/host_session.js b/remoting/webapp/host_session.js index a2524ee..72007a3 100644 --- a/remoting/webapp/host_session.js +++ b/remoting/webapp/host_session.js @@ -20,10 +20,11 @@ var remoting = remoting || {}; * @constructor */ remoting.HostSession = function() { - /** @type {remoting.HostIt2MeDispatcher} @private */ - this.hostDispatcher_ = null; }; +/** @type {remoting.HostPlugin} */ +remoting.HostSession.prototype.plugin = null; + // Note that these values are copied directly from host_script_object.h and // must be kept in sync. /** @enum {number} */ @@ -40,19 +41,6 @@ remoting.HostSession.State = { }; /** - * @param {string} stateString The string representation of the host state. - * @return {remoting.HostSession.State} The HostSession.State enum value - * corresponding to stateString. - */ -remoting.HostSession.stateFromString = function(stateString) { - if (!remoting.HostSession.State.hasOwnProperty(stateString)) { - console.error('NativeMessaging: unexpected state string: ', stateString); - return remoting.HostSession.State.UNKNOWN; - } - return remoting.HostSession.State[stateString]; -} - -/** * Create an instance of the host plugin. * @return {remoting.HostPlugin} The new plugin instance. */ @@ -66,59 +54,48 @@ remoting.HostSession.createPlugin = function() { }; /** - * Create the host dispatcher and initiate a connection. + * Create the host plugin and initiate a connection. * @param {Element} container The parent element to which to add the plugin. * @param {string} email The user's email address. * @param {string} accessToken A valid OAuth2 access token. - * @param {function(remoting.HostSession.State):void} onStateChanged - * Callback for notifications of changes to the host plugin's state. * @param {function(boolean):void} onNatTraversalPolicyChanged Callback * for notification of changes to the NAT traversal policy. + * @param {function(remoting.HostSession.State):void} onStateChanged + * Callback for notifications of changes to the host plugin's state. * @param {function(string):void} logDebugInfo Callback allowing the plugin * to log messages to the debug log. - * @param {function():void} onError Callback to invoke if neither the native - * messaging host nor the npapi plugin works. - * @return {void} Nothing. */ -remoting.HostSession.prototype.createDispatcherAndConnect = - function(container, email, accessToken, onStateChanged, - onNatTraversalPolicyChanged, logDebugInfo, onError) { - /** @type {remoting.HostIt2MeDispatcher} @private */ - this.hostDispatcher_ = new remoting.HostIt2MeDispatcher(); - - /** @return {remoting.HostPlugin} */ - var createPluginForIt2Me = function() { - var plugin = remoting.HostSession.createPlugin(); - container.appendChild(plugin); - return plugin; - }; - - this.hostDispatcher_.initAndConnect( - createPluginForIt2Me, - email, 'oauth2:' + accessToken, - onStateChanged, onNatTraversalPolicyChanged, - remoting.settings.XMPP_SERVER_ADDRESS, - remoting.settings.XMPP_SERVER_USE_TLS, - remoting.settings.DIRECTORY_BOT_JID, - onError); +remoting.HostSession.prototype.createPluginAndConnect = + function(container, email, accessToken, + onNatTraversalPolicyChanged, onStateChanged, logDebugInfo) { + this.plugin = remoting.HostSession.createPlugin(); + container.appendChild(this.plugin); + this.plugin.onNatTraversalPolicyChanged = onNatTraversalPolicyChanged; + this.plugin.onStateChanged = onStateChanged; + this.plugin.logDebugInfo = logDebugInfo; + this.plugin.localize(chrome.i18n.getMessage); + this.plugin.xmppServerAddress = remoting.settings.XMPP_SERVER_ADDRESS; + this.plugin.xmppServerUseTls = remoting.settings.XMPP_SERVER_USE_TLS; + this.plugin.directoryBotJid = remoting.settings.DIRECTORY_BOT_JID; + this.plugin.connect(email, 'oauth2:' + accessToken); }; /** - * Get the access code generated by the it2me host. Valid only after the - * host state is RECEIVED_ACCESS_CODE. + * Get the access code generated by the host plugin. Valid only after the + * plugin state is RECEIVED_ACCESS_CODE. * @return {string} The access code. */ remoting.HostSession.prototype.getAccessCode = function() { - return this.hostDispatcher_.getAccessCode(); + return this.plugin.accessCode; }; /** - * Get the lifetime for the access code. Valid only after the host state is + * Get the lifetime for the access code. Valid only after the plugin state is * RECEIVED_ACCESS_CODE. * @return {number} The access code lifetime, in seconds. */ remoting.HostSession.prototype.getAccessCodeLifetime = function() { - return this.hostDispatcher_.getAccessCodeLifetime(); + return this.plugin.accessCodeLifetime; }; /** @@ -127,21 +104,22 @@ remoting.HostSession.prototype.getAccessCodeLifetime = function() { * @return {string} The client's email address. */ remoting.HostSession.prototype.getClient = function() { - return this.hostDispatcher_.getClient(); + return this.plugin.client; }; /** - * Disconnect the it2me session. + * Disconnect the client. * @return {void} Nothing. */ remoting.HostSession.prototype.disconnect = function() { - this.hostDispatcher_.disconnect(); + this.plugin.disconnect(); }; /** + * Remove the plugin element from the document. * @return {void} Nothing. */ -remoting.HostSession.prototype.cleanup = function() { - this.hostDispatcher_.cleanup(); +remoting.HostSession.prototype.removePlugin = function() { + this.plugin.parentNode.removeChild(this.plugin); }; diff --git a/remoting/webapp/main.html b/remoting/webapp/main.html index 4d2bb42..eedde24 100644 --- a/remoting/webapp/main.html +++ b/remoting/webapp/main.html @@ -26,8 +26,6 @@ found in the LICENSE file. <script src="host.js"></script> <script src="host_controller.js"></script> <script src="host_dispatcher.js"></script> - <script src="host_it2me_dispatcher.js"></script> - <script src="host_it2me_native_messaging.js"></script> <script src="host_list.js"></script> <script src="host_native_messaging.js"></script> <script src="host_screen.js"></script> diff --git a/remoting/webapp/remoting.js b/remoting/webapp/remoting.js index b0519c2..c393ab1 100644 --- a/remoting/webapp/remoting.js +++ b/remoting/webapp/remoting.js @@ -141,16 +141,6 @@ remoting.init = function() { }; /** - * Returns whether or not IT2Me is supported via the host NPAPI plugin. - * - * @return {boolean} - */ -function isIT2MeSupported_() { - // Currently, IT2Me on Chromebooks is not supported. - return !remoting.runningOnChromeOS(); -} - -/** * Display the user's email address and allow access to the rest of the app, * including parsing URL parameters. * @@ -164,6 +154,21 @@ remoting.onEmail = function(email) { }; /** + * Returns whether or not IT2Me is supported via the host NPAPI plugin. + * + * @return {boolean} + */ +function isIT2MeSupported_() { + var container = document.getElementById('host-plugin-container'); + /** @type {remoting.HostPlugin} */ + var plugin = remoting.HostSession.createPlugin(); + container.appendChild(plugin); + var result = plugin.hasOwnProperty('REQUESTED_ACCESS_CODE'); + container.removeChild(plugin); + return result; +} + +/** * initHomeScreenUi is called if the app is not starting up in session mode, * and also if the user cancels pin entry or the connection in session mode. */ |