diff options
author | weitaosu@chromium.org <weitaosu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-09 17:03:37 +0000 |
---|---|---|
committer | weitaosu@chromium.org <weitaosu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-09 17:03:37 +0000 |
commit | 71299e36fa43c7cfe3302df7c946e2068098a895 (patch) | |
tree | a0a4f003dd7d318524ae81730a86f55e5bfd2329 /remoting/webapp | |
parent | f8e46614369594c29c72b0ae1a4b53ad259ed4af (diff) | |
download | chromium_src-71299e36fa43c7cfe3302df7c946e2068098a895.zip chromium_src-71299e36fa43c7cfe3302df7c946e2068098a895.tar.gz chromium_src-71299e36fa43c7cfe3302df7c946e2068098a895.tar.bz2 |
Refactor HostSetupDialog and HostInstallDialog.
1. Moved all the host installation logic to the HOST_INSTALL step in HostSetupDialog
2. On Windows host installation now occurs before the pin prompt when user enables remote connection.
3. HostInstallDialog now handles both the prompt (Linux/Mac) and non-prompt (windows) scenarios.
4. Renamed onDone and onError in HostInstallDialog to onOk and onCancel. The install prompt doesn't perform any task itself and won't incur any error so onOk an onCancel are better names.
This CL is a precursor to the change that enables automatic host installation for IT2Me on windows.
BUG=134215
Review URL: https://codereview.chromium.org/243993002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269344 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp')
-rw-r--r-- | remoting/webapp/connection_stats.js | 2 | ||||
-rw-r--r-- | remoting/webapp/host_controller.js | 36 | ||||
-rw-r--r-- | remoting/webapp/host_dispatcher.js | 3 | ||||
-rw-r--r-- | remoting/webapp/host_install_dialog.js | 79 | ||||
-rw-r--r-- | remoting/webapp/host_screen.js | 13 | ||||
-rw-r--r-- | remoting/webapp/host_setup_dialog.js | 76 |
6 files changed, 126 insertions, 83 deletions
diff --git a/remoting/webapp/connection_stats.js b/remoting/webapp/connection_stats.js index b9c77bf..3f7404e 100644 --- a/remoting/webapp/connection_stats.js +++ b/remoting/webapp/connection_stats.js @@ -52,7 +52,7 @@ remoting.ConnectionStats.prototype.update = function(stats) { /** * @param {number} value * @param {string} units - * @returns {string} Formatted number. + * @return {string} Formatted number. */ function formatStatNumber(value, units) { if (value != undefined) { diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js index f8860c0..056cdd9 100644 --- a/remoting/webapp/host_controller.js +++ b/remoting/webapp/host_controller.js @@ -124,7 +124,19 @@ remoting.HostController.prototype.getConsent = function(onDone, onError) { * @return {void} */ remoting.HostController.prototype.installHost = function(onDone, onError) { - this.hostDispatcher_.installHost(onDone, onError); + /** @type {remoting.HostController} */ + var that = this; + + /** @param {remoting.HostController.AsyncResult} asyncResult */ + var onHostInstalled = function(asyncResult) { + // Refresh the dispatcher after the host has been installed. + if (asyncResult == remoting.HostController.AsyncResult.OK) { + that.hostDispatcher_ = that.createDispatcher_(); + } + onDone(asyncResult); + }; + + this.hostDispatcher_.installHost(onHostInstalled, onError); }; /** @@ -344,27 +356,7 @@ remoting.HostController.prototype.start = function(hostPin, consent, onDone, onError); } - /** @param {remoting.HostController.AsyncResult} asyncResult */ - var onHostInstalled = function(asyncResult) { - if (asyncResult == remoting.HostController.AsyncResult.OK) { - // Now that the host is installed, we need to get a new dispatcher that - // dispatches to the NM host instead of the NPAPI plugin. - console.log('Recreating the host dispatcher.'); - that.hostDispatcher_ = that.createDispatcher_(); - that.hostDispatcher_.getHostName(startWithHostname, onError); - } else if (asyncResult == remoting.HostController.AsyncResult.CANCELLED) { - onError(remoting.Error.CANCELLED); - } else { - onError(remoting.Error.UNEXPECTED); - } - } - - // Perform the installation step here on Windows. - if (navigator.platform == 'Win32') { - this.installHost(onHostInstalled, onError); - } else { - this.hostDispatcher_.getHostName(startWithHostname, onError); - } + this.hostDispatcher_.getHostName(startWithHostname, onError); }; /** diff --git a/remoting/webapp/host_dispatcher.js b/remoting/webapp/host_dispatcher.js index 6861e38..a5ea504 100644 --- a/remoting/webapp/host_dispatcher.js +++ b/remoting/webapp/host_dispatcher.js @@ -327,6 +327,9 @@ remoting.HostDispatcher.prototype.getUsageStatsConsent = }; /** + * This function installs the chromoting host using the NPAPI plugin and should + * only be called on Windows. + * * @param {function(remoting.HostController.AsyncResult):void} onDone * @param {function(remoting.Error):void} onError * @return {void} diff --git a/remoting/webapp/host_install_dialog.js b/remoting/webapp/host_install_dialog.js index 95fdd96..f94cca6 100644 --- a/remoting/webapp/host_install_dialog.js +++ b/remoting/webapp/host_install_dialog.js @@ -27,8 +27,8 @@ remoting.HostInstallDialog = function() { this.continueInstallButton_.disabled = false; this.cancelInstallButton_.disabled = false; - /** @private*/ - this.onDoneHandler_ = function() {} + /** @param {remoting.HostController.AsyncResult} asyncResult @private*/ + this.onDoneHandler_ = function(asyncResult) {} /** @param {remoting.Error} error @private */ this.onErrorHandler_ = function(error) {} @@ -49,42 +49,55 @@ remoting.HostInstallDialog.hostDownloadUrls = { /** * Starts downloading host components and shows installation prompt. * - * @param {function():void} onDone Callback called when user clicks Ok, - * presumably after installing the host. The handler must verify that the - * host has been installed and call tryAgain() otherwise. + * @param {remoting.HostController} hostController Used to install the host on + * Windows. + * @param {function(remoting.HostController.AsyncResult):void} onDone Callback + * called when user clicks Ok, presumably after installing the host. The + * handler must verify that the host has been installed and call tryAgain() + * otherwise. * @param {function(remoting.Error):void} onError Callback called when user - * clicks Cancel button or there is some other unexpected error. - * @returns {void} + * clicks Cancel button or there is some other unexpected error. + * @return {void} */ -remoting.HostInstallDialog.prototype.show = function(onDone, onError) { - this.continueInstallButton_.addEventListener( - 'click', this.onOkClickedHandler_, false); - this.cancelInstallButton_.addEventListener( - 'click', this.onCancelClickedHandler_, false); - remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT); - - var hostPackageUrl = - remoting.HostInstallDialog.hostDownloadUrls[navigator.platform]; - if (hostPackageUrl === undefined) { - this.onErrorHandler_(remoting.Error.CANCELLED); - return; +remoting.HostInstallDialog.prototype.show = function( + hostController, onDone, onError) { + // On Windows, host installation is automatic (handled by the NPAPI plugin) + // and we don't show the dialog. On Mac and Linux, we show the dialog and the + // user is expected to manually install the host before clicking OK. + // TODO (weitaosu): Make host installation automatic for IT2Me (like Me2Me) on + // Windows. Currently hostController is always null for IT2Me. + if (navigator.platform == 'Win32' && hostController != null) { + hostController.installHost(onDone, onError); + } else { + this.continueInstallButton_.addEventListener( + 'click', this.onOkClickedHandler_, false); + this.cancelInstallButton_.addEventListener( + 'click', this.onCancelClickedHandler_, false); + remoting.setMode(remoting.AppMode.HOST_INSTALL_PROMPT); + + var hostPackageUrl = + remoting.HostInstallDialog.hostDownloadUrls[navigator.platform]; + if (hostPackageUrl === undefined) { + this.onErrorHandler_(remoting.Error.CANCELLED); + return; + } + + // Start downloading the package. + window.location = hostPackageUrl; + + /** @type {function(remoting.HostController.AsyncResult):void} */ + this.onDoneHandler_ = onDone; + + /** @type {function(remoting.Error):void} */ + this.onErrorHandler_ = onError; } - - // Start downloading the package. - window.location = hostPackageUrl; - - /** @type {function():void} */ - this.onDoneHandler_ = onDone; - - /** @type {function(remoting.Error):void} */ - this.onErrorHandler_ = onError; } /** - * onDone handler must call this method if it detects that the host components - * are still unavailable. The same onDone and onError callbacks will be used - * when user clicks Ok or Cancel. - */ + * In manual host installation, onDone handler must call this method if it + * detects that the host components are still unavailable. The same onDone + * and onError callbacks will be used when user clicks Ok or Cancel. + */ remoting.HostInstallDialog.prototype.tryAgain = function() { this.retryInstallButton_.addEventListener( 'click', this.onRetryClickedHandler_.bind(this), false); @@ -101,7 +114,7 @@ remoting.HostInstallDialog.prototype.onOkClicked_ = function() { this.continueInstallButton_.disabled = true; this.cancelInstallButton_.disabled = true; - this.onDoneHandler_(); + this.onDoneHandler_(remoting.HostController.AsyncResult.OK); } remoting.HostInstallDialog.prototype.onCancelClicked_ = function() { diff --git a/remoting/webapp/host_screen.js b/remoting/webapp/host_screen.js index 1bebc74..45e9975 100644 --- a/remoting/webapp/host_screen.js +++ b/remoting/webapp/host_screen.js @@ -58,10 +58,19 @@ remoting.tryShare = function() { // If we failed to initialize dispatcher then prompt the user to install the // host. if (hostInstallDialog == null) { + var onDone = function(asyncResult) { + // TODO (weitaosu): Ignore asyncResult for now because it is not set + // during manual host installation. We should fix it after switching + // to automatic host installation on Windows. + tryInitializeDispatcher(); + }; + hostInstallDialog = new remoting.HostInstallDialog(); - (/** @type {remoting.HostInstallDialog} */ hostInstallDialog) - .show(tryInitializeDispatcher, onInstallPromptError); + (/** @type {remoting.HostInstallDialog} */ hostInstallDialog).show( + null, + onDone, + onInstallPromptError); } else { (/** @type {remoting.HostInstallDialog} */ hostInstallDialog).tryAgain(); } diff --git a/remoting/webapp/host_setup_dialog.js b/remoting/webapp/host_setup_dialog.js index f8c12bf..13717a2 100644 --- a/remoting/webapp/host_setup_dialog.js +++ b/remoting/webapp/host_setup_dialog.js @@ -219,11 +219,8 @@ remoting.HostSetupDialog.prototype.showForStartWithToken_ = state != remoting.HostController.State.NOT_INSTALLED && state != remoting.HostController.State.INSTALLING; - // Skip the installation step when the host is already installed or when using - // NPAPI plugin on Windows (because on Windows the plugin takes care of - // installation). - if (installed || (navigator.platform == 'Win32' && - this.hostController_.usingNpapiPlugin())) { + // Skip the installation step when the host is already installed. + if (installed) { flow.shift(); } @@ -276,6 +273,16 @@ remoting.HostSetupDialog.prototype.startNewFlow_ = function(sequence) { }; /** + * @param {string} tag + * @private + */ +remoting.HostSetupDialog.prototype.showProcessingMessage_ = function(tag) { + var messageDiv = document.getElementById('host-setup-processing-message'); + l10n.localizeElementFromTag(messageDiv, tag); + remoting.setMode(remoting.AppMode.HOST_SETUP_PROCESSING); +} + +/** * Updates current UI mode according to the current state of the setup * flow and start the action corresponding to the current step (if * any). @@ -284,12 +291,6 @@ remoting.HostSetupDialog.prototype.startNewFlow_ = function(sequence) { remoting.HostSetupDialog.prototype.updateState_ = function() { remoting.updateLocalHostState(); - /** @param {string} tag */ - function showProcessingMessage(tag) { - var messageDiv = document.getElementById('host-setup-processing-message'); - l10n.localizeElementFromTag(messageDiv, tag); - remoting.setMode(remoting.AppMode.HOST_SETUP_PROCESSING); - } /** @param {string} tag1 * @param {string=} opt_tag2 */ function showDoneMessage(tag1, opt_tag2) { @@ -318,13 +319,13 @@ remoting.HostSetupDialog.prototype.updateState_ = function() { } else if (state == remoting.HostSetupFlow.State.INSTALL_HOST) { this.installHost_(); } else if (state == remoting.HostSetupFlow.State.STARTING_HOST) { - showProcessingMessage(/*i18n-content*/'HOST_SETUP_STARTING'); + this.showProcessingMessage_(/*i18n-content*/'HOST_SETUP_STARTING'); this.startHost_(); } else if (state == remoting.HostSetupFlow.State.UPDATING_PIN) { - showProcessingMessage(/*i18n-content*/'HOST_SETUP_UPDATING_PIN'); + this.showProcessingMessage_(/*i18n-content*/'HOST_SETUP_UPDATING_PIN'); this.updatePin_(); } else if (state == remoting.HostSetupFlow.State.STOPPING_HOST) { - showProcessingMessage(/*i18n-content*/'HOST_SETUP_STOPPING'); + this.showProcessingMessage_(/*i18n-content*/'HOST_SETUP_STOPPING'); this.stopHost_(); } else if (state == remoting.HostSetupFlow.State.HOST_STARTED) { // TODO(jamiewalch): Only display the second string if the computer's power @@ -355,36 +356,61 @@ remoting.HostSetupDialog.prototype.installHost_ = function() { /** @type {remoting.HostSetupFlow} */ var flow = this.flow_; - var onDone = function() { - that.hostController_.getLocalHostState(onHostState); - }; - /** @param {remoting.Error} error */ var onError = function(error) { flow.switchToErrorState(error); that.updateState_(); - } + }; + + /** @param {remoting.HostController.AsyncResult} asyncResult */ + var onDone = function(asyncResult) { + if (asyncResult == remoting.HostController.AsyncResult.OK) { + that.hostController_.getLocalHostState(onHostState); + } else if (asyncResult == remoting.HostController.AsyncResult.CANCELLED) { + onError(remoting.Error.CANCELLED); + } else { + onError(remoting.Error.UNEXPECTED); + } + }; /** @param {remoting.HostController.State} state */ var onHostState = function(state) { - // Verify if the host has been installed. If not then try to prompt the user - // again. var installed = state != remoting.HostController.State.NOT_INSTALLED && state != remoting.HostController.State.INSTALLING; - // On Windows we perform the host installation after showing the pin form. - if (installed || navigator.platform == 'Win32') { + if (installed) { that.flow_.switchToNextStep(); that.updateState_(); } else { - hostInstallDialog.tryAgain(); + // For Mac/Linux, prompt the user again if the host is not installed. + if (navigator.platform != 'Win32') { + hostInstallDialog.tryAgain(); + } else { + // For Windows, report an error in the unlikely case that + // HostController.installHost reports AsyncResult.OK but the host is not + // installed. + console.error('The chromoting host is not installed.'); + onError(remoting.Error.UNEXPECTED); + } } + }; + + if (navigator.platform == 'Win32') { + // Currently we show two dialogs (each with a UAC prompt) when a user + // enables the host for the first time, one for installing the host (by the + // plugin) and the other for starting the host (by the native messaging + // host). We'd like to reduce it to one but don't have a good solution + // right now. + // We also show the same message on the two dialogs because. We don't want + // to confuse the user by saying "Installing Remote Desktop" because in + // their mind "Remote Deskto" (the webapp) has already been installed. + that.showProcessingMessage_(/*i18n-content*/'HOST_SETUP_STARTING'); } /** @type {remoting.HostInstallDialog} */ var hostInstallDialog = new remoting.HostInstallDialog(); - hostInstallDialog.show(onDone, onError); + hostInstallDialog.show(this.hostController_, onDone, onError); } /** |