summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorgarykac <garykac@chromium.org>2015-03-19 19:31:39 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-20 02:32:19 +0000
commita59c430f5028228e62f780b2e129e93a4cb72843 (patch)
tree9235d8487ef18b9f2dc319b13ff6698702737666 /remoting
parentf1df20df06365f2c8e41872c567e4801a8cf9392 (diff)
downloadchromium_src-a59c430f5028228e62f780b2e129e93a4cb72843.zip
chromium_src-a59c430f5028228e62f780b2e129e93a4cb72843.tar.gz
chromium_src-a59c430f5028228e62f780b2e129e93a4cb72843.tar.bz2
[Chromoting] Move app-specific code out of remoting.js
After this cl, the last remaining reference to remoting.AppMode in AppRemoting is in app_remoting.js. That will be addressed in a followup cl. Move the following out of remoting.js and into app-specific locations: * remoting.signOut (into crd_event_handlers.js) * remoting.showErrorMessage (into desktop_remoting.js) * isWindowed_ (into desktop_remoting.js) * remoting.promptClose (into desktop_remoting.js) * remoting.isMe2MeInstallable (into local_host_section.js) Rename Delegate.signInFailed -> Delegate.handleAuthError Add Application.onAuthError to call Delegate.handleAuthError Change references to global remoting.showErrorMessage to remoting.app.onAuthError BUG= Review URL: https://codereview.chromium.org/1020743002 Cr-Commit-Position: refs/heads/master@{#321502}
Diffstat (limited to 'remoting')
-rw-r--r--remoting/webapp/crd/js/crd_event_handlers.js15
-rw-r--r--remoting/webapp/crd/js/crd_main.js20
-rw-r--r--remoting/webapp/crd/js/desktop_remoting.js57
-rw-r--r--remoting/webapp/crd/js/host_list.js15
-rw-r--r--remoting/webapp/crd/js/host_setup_dialog.js10
-rw-r--r--remoting/webapp/crd/js/local_host_section.js20
-rw-r--r--remoting/webapp/crd/js/remoting.js100
7 files changed, 124 insertions, 113 deletions
diff --git a/remoting/webapp/crd/js/crd_event_handlers.js b/remoting/webapp/crd/js/crd_event_handlers.js
index fb96ee0..991c36b 100644
--- a/remoting/webapp/crd/js/crd_event_handlers.js
+++ b/remoting/webapp/crd/js/crd_event_handlers.js
@@ -84,3 +84,18 @@ remoting.initElementEventHandlers = function() {
registerEventListeners(host_actions);
registerEventListeners(auth_actions);
}
+
+/**
+ * Sign the user out of Chromoting by clearing (and revoking, if possible) the
+ * OAuth refresh token.
+ *
+ * Also clear all local storage, to avoid leaking information.
+ */
+remoting.signOut = function() {
+ remoting.oauth2.removeCachedAuthToken().then(function(){
+ chrome.storage.local.clear();
+ remoting.setMode(remoting.AppMode.HOME);
+ window.location.reload();
+ });
+};
+
diff --git a/remoting/webapp/crd/js/crd_main.js b/remoting/webapp/crd/js/crd_main.js
index 2f7b03f..20ae60a 100644
--- a/remoting/webapp/crd/js/crd_main.js
+++ b/remoting/webapp/crd/js/crd_main.js
@@ -17,7 +17,8 @@ remoting.initHostlist_ = function() {
document.getElementById('host-list-empty'),
document.getElementById('host-list-error-message'),
document.getElementById('host-list-refresh-failed-button'),
- document.getElementById('host-list-loading-indicator'));
+ document.getElementById('host-list-loading-indicator'),
+ remoting.showErrorMessage);
isHostModeSupported_().then(
/** @param {Boolean} supported */
@@ -180,6 +181,23 @@ remoting.startDesktopRemotingForTesting = function() {
}
}
+/**
+ * @param {!remoting.Error} error The failure reason.
+ */
+remoting.showErrorMessage = function(error) {
+ l10n.localizeElementFromTag(
+ document.getElementById('token-refresh-error-message'),
+ error.getTag());
+ var auth_failed = (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED));
+ if (auth_failed && base.isAppsV2()) {
+ remoting.handleAuthFailureAndRelaunch();
+ } else {
+ document.getElementById('token-refresh-auth-failed').hidden = !auth_failed;
+ document.getElementById('token-refresh-other-error').hidden = auth_failed;
+ remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED);
+ }
+};
+
remoting.startDesktopRemoting = function() {
remoting.app = new remoting.Application(remoting.app_capabilities());
diff --git a/remoting/webapp/crd/js/desktop_remoting.js b/remoting/webapp/crd/js/desktop_remoting.js
index 66c46fe..e9b54c9 100644
--- a/remoting/webapp/crd/js/desktop_remoting.js
+++ b/remoting/webapp/crd/js/desktop_remoting.js
@@ -81,7 +81,8 @@ remoting.DesktopRemoting.prototype.init = function() {
document.getElementById('session-toolbar'));
remoting.optionsMenu = remoting.toolbar.createOptionsMenu();
- window.addEventListener('beforeunload', remoting.promptClose, false);
+ window.addEventListener('beforeunload',
+ this.promptClose_.bind(this), false);
window.addEventListener('unload',
remoting.app.disconnect.bind(remoting.app), false);
}
@@ -114,7 +115,7 @@ remoting.DesktopRemoting.prototype.init = function() {
document.getElementById('startup-mode-box-it2me').hidden = false;
}
};
- isWindowed_(onIsWindowed);
+ this.isWindowed_(onIsWindowed);
}
remoting.ClientPlugin.factory.preloadPlugin();
@@ -324,6 +325,56 @@ remoting.DesktopRemoting.prototype.handleError = function(error) {
remoting.DesktopRemoting.prototype.handleExit = function() {
};
+/**
+ * Determine whether or not the app is running in a window.
+ * @param {function(boolean):void} callback Callback to receive whether or not
+ * the current tab is running in windowed mode.
+ * @private
+ */
+remoting.DesktopRemoting.prototype.isWindowed_ = function(callback) {
+ /** @param {chrome.Window} win The current window. */
+ var windowCallback = function(win) {
+ callback(win.type == 'popup');
+ };
+ /** @param {chrome.Tab} tab The current tab. */
+ var tabCallback = function(tab) {
+ if (tab.pinned) {
+ callback(false);
+ } else {
+ chrome.windows.get(tab.windowId, null, windowCallback);
+ }
+ };
+ if (chrome.tabs) {
+ chrome.tabs.getCurrent(tabCallback);
+ } else {
+ console.error('chome.tabs is not available.');
+ }
+}
+
+/**
+ * If an IT2Me client or host is active then prompt the user before closing.
+ * If a Me2Me client is active then don't bother, since closing the window is
+ * the more intuitive way to end a Me2Me session, and re-connecting is easy.
+ * @private
+ */
+remoting.DesktopRemoting.prototype.promptClose_ = function() {
+ var sessionConnector = remoting.app.getSessionConnector();
+ if (sessionConnector &&
+ sessionConnector.getConnectionMode() ==
+ remoting.DesktopConnectedView.Mode.IT2ME) {
+ switch (remoting.currentMode) {
+ case remoting.AppMode.CLIENT_CONNECTING:
+ case remoting.AppMode.HOST_WAITING_FOR_CODE:
+ case remoting.AppMode.HOST_WAITING_FOR_CONNECTION:
+ case remoting.AppMode.HOST_SHARED:
+ case remoting.AppMode.IN_SESSION:
+ return chrome.i18n.getMessage(/*i18n-content*/'CLOSE_PROMPT');
+ default:
+ return null;
+ }
+ }
+};
+
/** @returns {remoting.DesktopConnectedView} */
remoting.DesktopRemoting.prototype.getConnectedViewForTesting = function() {
return this.connectedView_;
@@ -333,4 +384,4 @@ remoting.DesktopRemoting.prototype.getConnectedViewForTesting = function() {
* Global instance of remoting.DesktopRemoting used for testing.
* @type {remoting.DesktopRemoting}
*/
-remoting.desktopDelegateForTesting = null; \ No newline at end of file
+remoting.desktopDelegateForTesting = null;
diff --git a/remoting/webapp/crd/js/host_list.js b/remoting/webapp/crd/js/host_list.js
index 8626909..5d7d875 100644
--- a/remoting/webapp/crd/js/host_list.js
+++ b/remoting/webapp/crd/js/host_list.js
@@ -26,9 +26,11 @@ var remoting = remoting || {};
* @param {HTMLElement} loadingIndicator The HTML <span> to update while the
* host list is being loaded. The first element of this span should be
* the reload button.
+ * @param {function(!remoting.Error)} onError Function to call when an error
+ * occurs.
*/
remoting.HostList = function(table, noHosts, errorMsg, errorButton,
- loadingIndicator) {
+ loadingIndicator, onError) {
/** @private {Element} */
this.table_ = table;
/**
@@ -43,6 +45,8 @@ remoting.HostList = function(table, noHosts, errorMsg, errorButton,
this.errorButton_ = errorButton;
/** @private {HTMLElement} */
this.loadingIndicator_ = loadingIndicator;
+ this.onError_ = onError;
+
/** @private {Array<remoting.HostTableEntry>} */
this.hostTableEntries_ = [];
/** @private {Array<remoting.Host>} */
@@ -53,7 +57,8 @@ remoting.HostList = function(table, noHosts, errorMsg, errorButton,
this.localHostSection_ = new remoting.LocalHostSection(
/** @type {HTMLElement} */ (document.querySelector('.daemon-control')),
new remoting.LocalHostSection.Controller(
- this, new remoting.HostSetupDialog(remoting.hostController)));
+ this,
+ new remoting.HostSetupDialog(remoting.hostController, onError)));
/** @private {number} */
this.webappMajorVersion_ = parseInt(chrome.runtime.getManifest().version, 10);
@@ -295,7 +300,7 @@ remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) {
this.hostTableEntries_.splice(index, 1);
}
remoting.hostListApi.remove(hostTableEntry.host.hostId, base.doNothing,
- remoting.showErrorMessage);
+ this.onError_);
};
/**
@@ -316,7 +321,7 @@ remoting.HostList.prototype.renameHost = function(hostTableEntry) {
hostTableEntry.host.hostName,
hostTableEntry.host.publicKey,
function() {},
- remoting.showErrorMessage);
+ this.onError_);
};
/**
@@ -343,7 +348,7 @@ remoting.HostList.prototype.unregisterHostById = function(hostId, opt_onDone) {
onDone();
});
};
- remoting.hostListApi.remove(hostId, onRemoved, remoting.showErrorMessage);
+ remoting.hostListApi.remove(hostId, onRemoved, this.onError_);
};
/**
diff --git a/remoting/webapp/crd/js/host_setup_dialog.js b/remoting/webapp/crd/js/host_setup_dialog.js
index 9065b53..40cc7d5 100644
--- a/remoting/webapp/crd/js/host_setup_dialog.js
+++ b/remoting/webapp/crd/js/host_setup_dialog.js
@@ -93,11 +93,15 @@ remoting.HostSetupFlow.prototype.switchToErrorState = function(error) {
/**
* @param {remoting.HostController} hostController The HostController
- * responsible for the host daemon.
+ * responsible for the host daemon.
+ * @param {function(!remoting.Error)} onError Function to call when an error
+ * occurs.
* @constructor
*/
-remoting.HostSetupDialog = function(hostController) {
+remoting.HostSetupDialog = function(hostController, onError) {
this.hostController_ = hostController;
+ this.onError_ = onError;
+
this.pinEntry_ = document.getElementById('daemon-pin-entry');
this.pinConfirm_ = document.getElementById('daemon-pin-confirm');
this.pinErrorDiv_ = document.getElementById('daemon-pin-error-div');
@@ -165,7 +169,7 @@ remoting.HostSetupDialog.prototype.showForStart = function() {
// case where the refresh token is invalid.
remoting.identity.getToken().then(
that.showForStartWithToken_.bind(that, state),
- remoting.Error.handler(remoting.showErrorMessage));
+ remoting.Error.handler(that.onError_));
};
this.hostController_.getLocalHostState(onState);
diff --git a/remoting/webapp/crd/js/local_host_section.js b/remoting/webapp/crd/js/local_host_section.js
index 50bebe7..f0b7211 100644
--- a/remoting/webapp/crd/js/local_host_section.js
+++ b/remoting/webapp/crd/js/local_host_section.js
@@ -96,7 +96,7 @@ remoting.LocalHostSection.prototype.canChangeState = function() {
// Return false if the host is uninstallable. The NOT_INSTALLED check is
// required to handle the special case for Ubuntu, as we report the host as
// uninstallable on Linux.
- if (!remoting.isMe2MeInstallable() &&
+ if (!this.isMe2MeInstallable_() &&
state === remoting.HostController.State.NOT_INSTALLED) {
return false;
}
@@ -107,6 +107,24 @@ remoting.LocalHostSection.prototype.canChangeState = function() {
return this.isEnabled_() || !this.hasError_;
};
+/**
+ * Returns true if the current platform is fully supported. It's only used when
+ * we detect that host native messaging components are not installed. In that
+ * case the result of this function determines if the webapp should show the
+ * controls that allow to install and enable Me2Me host.
+ *
+ * @return {boolean}
+ * @private
+ */
+remoting.LocalHostSection.prototype.isMe2MeInstallable_ = function() {
+ // The chromoting host is currently not installable on ChromeOS.
+ // For Linux, we have a install package for Ubuntu but not other distros.
+ // Since we cannot tell from javascript alone the Linux distro the client is
+ // on, we don't show the daemon-control UI for Linux unless the host is
+ // installed.
+ return remoting.platformIsWindows() || remoting.platformIsMac();
+}
+
/** @private */
remoting.LocalHostSection.prototype.updateUI_ = function() {
this.hostTableEntry_.setHost(this.host_);
diff --git a/remoting/webapp/crd/js/remoting.js b/remoting/webapp/crd/js/remoting.js
index 9de89ba..f3deae1 100644
--- a/remoting/webapp/crd/js/remoting.js
+++ b/remoting/webapp/crd/js/remoting.js
@@ -51,23 +51,6 @@ remoting.initGlobalObjects = function() {
}
/**
- * Returns true if the current platform is fully supported. It's only used when
- * we detect that host native messaging components are not installed. In that
- * case the result of this function determines if the webapp should show the
- * controls that allow to install and enable Me2Me host.
- *
- * @return {boolean}
- */
-remoting.isMe2MeInstallable = function() {
- // The chromoting host is currently not installable on ChromeOS.
- // For Linux, we have a install package for Ubuntu but not other distros.
- // Since we cannot tell from javascript alone the Linux distro the client is
- // on, we don't show the daemon-control UI for Linux unless the host is
- // installed.
- return remoting.platformIsWindows() || remoting.platformIsMac();
-}
-
-/**
* @return {string} Information about the current extension.
*/
remoting.getExtensionInfo = function() {
@@ -82,43 +65,6 @@ remoting.getExtensionInfo = function() {
};
/**
- * If an IT2Me client or host is active then prompt the user before closing.
- * If a Me2Me client is active then don't bother, since closing the window is
- * the more intuitive way to end a Me2Me session, and re-connecting is easy.
- */
-remoting.promptClose = function() {
- var sessionConnector = remoting.app.getSessionConnector();
- if (sessionConnector &&
- sessionConnector.getConnectionMode() ===
- remoting.DesktopConnectedView.Mode.IT2ME) {
- switch (remoting.currentMode) {
- case remoting.AppMode.CLIENT_CONNECTING:
- case remoting.AppMode.HOST_WAITING_FOR_CODE:
- case remoting.AppMode.HOST_WAITING_FOR_CONNECTION:
- case remoting.AppMode.HOST_SHARED:
- case remoting.AppMode.IN_SESSION:
- return chrome.i18n.getMessage(/*i18n-content*/'CLOSE_PROMPT');
- default:
- return null;
- }
- }
-};
-
-/**
- * Sign the user out of Chromoting by clearing (and revoking, if possible) the
- * OAuth refresh token.
- *
- * Also clear all local storage, to avoid leaking information.
- */
-remoting.signOut = function() {
- remoting.oauth2.removeCachedAuthToken().then(function(){
- chrome.storage.local.clear();
- remoting.setMode(remoting.AppMode.HOME);
- window.location.reload();
- });
-};
-
-/**
* Callback function called when the browser window gets a paste operation.
*
* @param {Event} event
@@ -170,49 +116,3 @@ remoting.timestamp = function() {
pad(now.getSeconds(), 2) + '.' + pad(now.getMilliseconds(), 3);
return '[' + timestamp + ']';
};
-
-/**
- * Show an error message, optionally including a short-cut for signing in to
- * Chromoting again.
- *
- * @param {!remoting.Error} error
- * @return {void} Nothing.
- */
-remoting.showErrorMessage = function(error) {
- l10n.localizeElementFromTag(
- document.getElementById('token-refresh-error-message'),
- error.getTag());
- var auth_failed = (error.hasTag(remoting.Error.Tag.AUTHENTICATION_FAILED));
- if (auth_failed && base.isAppsV2()) {
- remoting.handleAuthFailureAndRelaunch();
- } else {
- document.getElementById('token-refresh-auth-failed').hidden = !auth_failed;
- document.getElementById('token-refresh-other-error').hidden = auth_failed;
- remoting.setMode(remoting.AppMode.TOKEN_REFRESH_FAILED);
- }
-};
-
-/**
- * Determine whether or not the app is running in a window.
- * @param {function(boolean):void} callback Callback to receive whether or not
- * the current tab is running in windowed mode.
- */
-function isWindowed_(callback) {
- /** @param {chrome.Window} win The current window. */
- var windowCallback = function(win) {
- callback(win.type == 'popup');
- };
- /** @param {chrome.Tab} tab The current tab. */
- var tabCallback = function(tab) {
- if (tab.pinned) {
- callback(false);
- } else {
- chrome.windows.get(tab.windowId, null, windowCallback);
- }
- };
- if (chrome.tabs) {
- chrome.tabs.getCurrent(tabCallback);
- } else {
- console.error('chome.tabs is not available.');
- }
-}