summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorjamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-02 04:08:40 +0000
committerjamiewalch@chromium.org <jamiewalch@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-02 04:08:40 +0000
commit6ca79ac814a08ac8ee2e7a1f0eb28934bd7051cd (patch)
tree4863ac7442b9b2150c51434cf017271844fa21a3 /remoting
parent457eaeb40454ac430d095da7f99f79b010167a6d (diff)
downloadchromium_src-6ca79ac814a08ac8ee2e7a1f0eb28934bd7051cd.zip
chromium_src-6ca79ac814a08ac8ee2e7a1f0eb28934bd7051cd.tar.gz
chromium_src-6ca79ac814a08ac8ee2e7a1f0eb28934bd7051cd.tar.bz2
Don't reload the web-app at any point in the client-side flow.
This improves responsiveness and also means that the v2 app now works for more then one connection without needing to be reloaded explicitly. BUG=134213 Review URL: https://chromiumcodereview.appspot.com/13191012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191768 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/webapp/appsv2.patch29
-rw-r--r--remoting/webapp/client_screen.js56
-rw-r--r--remoting/webapp/client_session.js4
-rw-r--r--remoting/webapp/event_handlers.js33
-rw-r--r--remoting/webapp/host_table_entry.js4
-rw-r--r--remoting/webapp/session_connector.js71
6 files changed, 109 insertions, 88 deletions
diff --git a/remoting/webapp/appsv2.patch b/remoting/webapp/appsv2.patch
index 8c2fabb..22cea58 100644
--- a/remoting/webapp/appsv2.patch
+++ b/remoting/webapp/appsv2.patch
@@ -2,7 +2,7 @@ diff --git a/remoting/webapp/event_handlers.js b/remoting/webapp/event_handlers.
index 5dfc368..f69d984 100644
--- a/event_handlers.js
+++ b/event_handlers.js
-@@ -57,7 +57,6 @@ function onLoad() {
+@@ -54,7 +54,6 @@ function onLoad() {
fn: remoting.sendCtrlAltDel },
{ event: 'click', id: 'send-print-screen',
fn: remoting.sendPrintScreen },
@@ -10,7 +10,7 @@ index 5dfc368..f69d984 100644
{ event: 'click', id: 'share-button', fn: remoting.tryShare },
{ event: 'click', id: 'access-mode-button', fn: goEnterAccessCode },
{ event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare },
-@@ -117,6 +116,4 @@ function onBeforeUnload() {
+@@ -104,6 +103,4 @@ function onBeforeUnload() {
}
window.addEventListener('load', onLoad, false);
@@ -21,35 +21,20 @@ diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controlle
index 83c9844..98f63c3 100644
--- a/host_controller.js
+++ b/host_controller.js
-@@ -341,7 +341,7 @@ remoting.HostController.prototype.getLocalHostStateAndId = function(onDone) {
- onDone(state, that.localHostId_);
+@@ -351,7 +351,7 @@ remoting.HostController.prototype.getLocalHostStateAndId = function(onDone) {
+ onDone(hostId);
};
try {
- this.plugin_.getDaemonConfig(onConfig);
+ onConfig('{}');
} catch (err) {
- onDone(remoting.HostController.State.NOT_IMPLEMENTED, null);
+ onDone(null);
}
-diff --git a/remoting/webapp/host_table_entry.js b/remoting/webapp/host_table_entry.js
-index 4eb09d9..6d2ce85 100644
---- a/host_table_entry.js
-+++ b/host_table_entry.js
-@@ -176,9 +176,7 @@ remoting.HostTableEntry.prototype.updateStatus = function(opt_forEdit) {
- /** @type {string} */
- var encodedHostId = encodeURIComponent(this.host.hostId)
- this.onConnectReference_ = function() {
-- var hostUrl = chrome.extension.getURL('main.html') +
-- '?mode=me2me&hostId=' + encodedHostId;
-- window.location.assign(hostUrl);
-+ remoting.connectMe2Me(encodedHostId, true);
- };
- this.tableRow.addEventListener('click', this.onConnectReference_, false);
- }
diff --git a/remoting/webapp/main.html b/remoting/webapp/main.html
index 061caeb..f61e532 100644
--- a/main.html
+++ b/main.html
-@@ -33,6 +33,7 @@ found in the LICENSE file.
+@@ -34,6 +34,7 @@ found in the LICENSE file.
<script src="host_settings.js"></script>
<script src="host_setup_dialog.js"></script>
<script src="host_table_entry.js"></script>
@@ -135,7 +120,7 @@ index f89072a..2fadd83 100644
remoting.stats = new remoting.ConnectionStats(
document.getElementById('statistics'));
remoting.formatIq = new remoting.FormatIq();
-@@ -129,9 +126,6 @@ remoting.initHomeScreenUi = function () {
+@@ -131,9 +128,6 @@ remoting.initHomeScreenUi = function () {
document.getElementById('share-button').disabled =
!remoting.hostController.isPluginSupported();
remoting.setMode(remoting.AppMode.HOME);
diff --git a/remoting/webapp/client_screen.js b/remoting/webapp/client_screen.js
index 5bdcbb4..77ff7ec 100644
--- a/remoting/webapp/client_screen.js
+++ b/remoting/webapp/client_screen.js
@@ -28,10 +28,12 @@ remoting.clientSession = null;
* Initiate an IT2Me connection.
*/
remoting.connectIT2Me = function() {
- remoting.connector = new remoting.SessionConnector(
- document.getElementById('session-mode'),
- remoting.onConnected,
- showConnectError_);
+ if (!remoting.connector) {
+ remoting.connector = new remoting.SessionConnector(
+ document.getElementById('session-mode'),
+ remoting.onConnected,
+ showConnectError_);
+ }
var accessCode = document.getElementById('access-code-entry').value;
remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
remoting.connector.connectIT2Me(accessCode);
@@ -222,7 +224,7 @@ remoting.connectMe2Me = function(hostId) {
if (event.target == connect) {
remoting.connectMe2MeHostVersionAcknowledged_(host);
} else {
- window.location.replace(chrome.extension.getURL('main.html'));
+ remoting.setMode(remoting.AppMode.HOME);
}
}
connect.addEventListener('click', onClick, false);
@@ -241,25 +243,44 @@ remoting.connectMe2Me = function(hostId) {
* @return {void} Nothing.
*/
remoting.connectMe2MeHostVersionAcknowledged_ = function(host) {
- remoting.connector = new remoting.SessionConnector(
- document.getElementById('session-mode'),
- remoting.onConnected,
- showConnectError_);
+ if (!remoting.connector) {
+ remoting.connector = new remoting.SessionConnector(
+ document.getElementById('session-mode'),
+ remoting.onConnected,
+ showConnectError_);
+ }
remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
/** @param {function(string):void} onPinFetched */
var requestPin = function(onPinFetched) {
/** @type {Element} */
var pinForm = document.getElementById('pin-form');
- /** @param {Event} event */
- var onSubmit = function(event) {
- event.preventDefault();
- pinForm.removeEventListener('submit', onSubmit, false);
- var pin = document.getElementById('pin-entry').value;
- remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
- onPinFetched(pin);
+ /** @type {Element} */
+ var pinCancel = document.getElementById('cancel-pin-entry-button');
+ /**
+ * Event handler for both the 'submit' and 'cancel' actions. Using
+ * a single handler for both greatly simplifies the task of making
+ * them one-shot. If separate handlers were used, each would have
+ * to unregister both itself and the other.
+ *
+ * @param {Event} event The click or submit event.
+ */
+ var onSubmitOrCancel = function(event) {
+ pinForm.removeEventListener('submit', onSubmitOrCancel, false);
+ pinCancel.removeEventListener('click', onSubmitOrCancel, false);
+ var pinField = document.getElementById('pin-entry');
+ var pin = pinField.value;
+ pinField.value = '';
+ if (event.target == pinForm) {
+ event.preventDefault();
+ remoting.setMode(remoting.AppMode.CLIENT_CONNECTING);
+ onPinFetched(pin);
+ } else {
+ remoting.setMode(remoting.AppMode.HOME);
+ }
};
- pinForm.addEventListener('submit', onSubmit, false);
+ pinForm.addEventListener('submit', onSubmitOrCancel, false);
+ pinCancel.addEventListener('click', onSubmitOrCancel, false);
var message = document.getElementById('pin-message');
l10n.localizeElement(message, host.hostName);
@@ -270,7 +291,6 @@ remoting.connectMe2MeHostVersionAcknowledged_ = function(host) {
/** @param {remoting.ClientSession} clientSession */
remoting.onConnected = function(clientSession) {
- remoting.connector = null;
remoting.clientSession = clientSession;
remoting.clientSession.setOnStateChange(onClientStateChange_);
setConnectionInterruptedButtonsText_();
diff --git a/remoting/webapp/client_session.js b/remoting/webapp/client_session.js
index bbc428a..2dc2e9c 100644
--- a/remoting/webapp/client_session.js
+++ b/remoting/webapp/client_session.js
@@ -111,9 +111,9 @@ remoting.ClientSession = function(hostJid, clientJid, hostPublicKey, accessCode,
if (this.mode == remoting.ClientSession.Mode.IT2ME) {
// Resize-to-client is not supported for IT2Me hosts.
- this.resizeToClientButton_.parentNode.removeChild(
- this.resizeToClientButton_);
+ this.resizeToClientButton_.hidden = true;
} else {
+ this.resizeToClientButton_.hidden = false;
this.resizeToClientButton_.addEventListener(
'click', this.callSetScreenMode_, false);
}
diff --git a/remoting/webapp/event_handlers.js b/remoting/webapp/event_handlers.js
index ff132ef..8fa384e 100644
--- a/remoting/webapp/event_handlers.js
+++ b/remoting/webapp/event_handlers.js
@@ -8,8 +8,8 @@
var remoting = remoting || {};
function onLoad() {
- var restartWebapp = function() {
- window.location.replace(chrome.extension.getURL('main.html'));
+ var goHome = function() {
+ remoting.setMode(remoting.AppMode.HOME);
};
var goEnterAccessCode = function() {
// We don't need a token until we authenticate, but asking for one here
@@ -26,12 +26,9 @@ function onLoad() {
if (remoting.currentMode == remoting.AppMode.CLIENT_CONNECT_FAILED_IT2ME) {
remoting.setMode(remoting.AppMode.CLIENT_UNCONNECTED);
} else {
- restartWebapp();
+ remoting.setMode(remoting.AppMode.HOME);
}
};
- var reload = function() {
- window.location.reload();
- };
/** @param {Event} event The event. */
var sendAccessCode = function(event) {
remoting.connectIT2Me();
@@ -62,13 +59,13 @@ function onLoad() {
{ event: 'click', id: 'access-mode-button', fn: goEnterAccessCode },
{ event: 'click', id: 'cancel-share-button', fn: remoting.cancelShare },
{ event: 'click', id: 'stop-sharing-button', fn: remoting.cancelShare },
- { event: 'click', id: 'host-finished-button', fn: restartWebapp },
- { event: 'click', id: 'client-finished-it2me-button', fn: restartWebapp },
- { event: 'click', id: 'client-finished-me2me-button', fn: restartWebapp },
- { event: 'click', id: 'cancel-pin-entry-button', fn: restartWebapp },
- { event: 'click', id: 'client-reconnect-button', fn: reload },
+ { event: 'click', id: 'host-finished-button', fn: goHome },
+ { event: 'click', id: 'client-finished-it2me-button', fn: goHome },
+ { event: 'click', id: 'client-finished-me2me-button', fn: goHome },
+ { event: 'click', id: 'client-reconnect-button',
+ fn: function() { remoting.connector.reconnect(); } },
{ event: 'click', id: 'cancel-access-code-button', fn: cancelAccessCode},
- { event: 'click', id: 'cancel-connect-button', fn: restartWebapp },
+ { event: 'click', id: 'cancel-connect-button', fn: goHome },
{ event: 'click', id: 'toolbar-stub',
fn: function() { remoting.toolbar.toggle(); } },
{ event: 'click', id: 'start-daemon',
@@ -81,14 +78,10 @@ function onLoad() {
fn: remoting.showIT2MeUiAndSave },
{ event: 'click', id: 'get-started-me2me',
fn: remoting.showMe2MeUiAndSave },
- { event: 'click', id: 'daemon-pin-cancel',
- fn: function() { remoting.setMode(remoting.AppMode.HOME); } },
- { event: 'click', id: 'host-config-done-dismiss',
- fn: function() { remoting.setMode(remoting.AppMode.HOME); } },
- { event: 'click', id: 'host-config-error-dismiss',
- fn: function() { remoting.setMode(remoting.AppMode.HOME); } },
- { event: 'click', id: 'token-refresh-error-ok',
- fn: function() { remoting.setMode(remoting.AppMode.HOME); } },
+ { event: 'click', id: 'daemon-pin-cancel', fn: goHome },
+ { event: 'click', id: 'host-config-done-dismiss', fn: goHome },
+ { event: 'click', id: 'host-config-error-dismiss', fn: goHome },
+ { event: 'click', id: 'token-refresh-error-ok', fn: goHome },
{ event: 'click', id: 'token-refresh-error-sign-in', fn: doAuthRedirect }
];
diff --git a/remoting/webapp/host_table_entry.js b/remoting/webapp/host_table_entry.js
index a5026c8..c564b5d 100644
--- a/remoting/webapp/host_table_entry.js
+++ b/remoting/webapp/host_table_entry.js
@@ -176,9 +176,7 @@ remoting.HostTableEntry.prototype.updateStatus = function(opt_forEdit) {
/** @type {string} */
var encodedHostId = encodeURIComponent(this.host.hostId)
this.onConnectReference_ = function() {
- var hostUrl = chrome.extension.getURL('main.html') +
- '?mode=me2me&hostId=' + encodedHostId;
- window.location.assign(hostUrl);
+ remoting.connectMe2Me(encodedHostId);
};
this.tableRow.addEventListener('click', this.onConnectReference_, false);
}
diff --git a/remoting/webapp/session_connector.js b/remoting/webapp/session_connector.js
index 994746d..649d129 100644
--- a/remoting/webapp/session_connector.js
+++ b/remoting/webapp/session_connector.js
@@ -38,12 +38,38 @@ remoting.SessionConnector = function(pluginParent, onOk, onError) {
this.onError_ = onError;
/**
+ * @type {string}
+ * @private
+ */
+ this.clientJid_ = '';
+
+ /**
* @type {remoting.ClientSession.Mode}
* @private
*/
this.connectionMode_ = remoting.ClientSession.Mode.ME2ME;
/**
+ * A timer that polls for an updated access token.
+ *
+ * @type {number}
+ * @private
+ */
+ this.wcsAccessTokenRefreshTimer_ = 0;
+
+ // Initialize/declare per-connection state.
+ this.reset();
+
+ // Pre-load WCS to improve connection time.
+ remoting.identity.callWithToken(this.loadWcs_.bind(this), this.onError_);
+};
+
+/**
+ * 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.
+ */
+remoting.SessionConnector.prototype.reset = function() {
+ /**
* String used to identify the host to which to connect. For IT2Me, this is
* the first 7 digits of the access code; for Me2Me it is the host identifier.
*
@@ -74,12 +100,6 @@ remoting.SessionConnector = function(pluginParent, onOk, onError) {
this.hostPublicKey_ = '';
/**
- * @type {string}
- * @private
- */
- this.clientJid_ = '';
-
- /**
* @type {boolean}
* @private
*/
@@ -98,16 +118,8 @@ remoting.SessionConnector = function(pluginParent, onOk, onError) {
this.pendingXhr_ = null;
/**
- * A timer that polls for an updated access token.
- *
- * @type {number}
- * @private
- */
- this.wcsAccessTokenRefreshTimer_ = 0;
-
- /**
* Function to interactively obtain the PIN from the user.
- * @param {function(string):void} onPinFetched Called when the PIN is fetched.
+ * @type {function(function(string):void):void}
* @private
*/
this.fetchPin_ = function(onPinFetched) {};
@@ -121,9 +133,6 @@ remoting.SessionConnector = function(pluginParent, onOk, onError) {
* @private
*/
this.hostDisplayName_ = '';
-
- // Pre-load WCS to improve connection time.
- remoting.identity.callWithToken(this.loadWcs_.bind(this), this.onError_);
};
/**
@@ -135,10 +144,14 @@ remoting.SessionConnector = function(pluginParent, onOk, onError) {
* @return {void} Nothing.
*/
remoting.SessionConnector.prototype.connectMe2Me = function(host, fetchPin) {
+ // Cancel any existing connect operation.
+ this.cancel();
+
this.hostId_ = host.hostId;
this.hostJid_ = host.jabberId;
this.fetchPin_ = fetchPin;
this.hostDisplayName_ = host.hostName;
+ this.connectionMode_ = remoting.ClientSession.Mode.ME2ME;
this.createSessionIfReady_();
};
@@ -153,6 +166,9 @@ remoting.SessionConnector.prototype.connectIT2Me = function(accessCode) {
var kHostSecretLen = 5;
var kAccessCodeLen = kSupportIdLen + kHostSecretLen;
+ // Cancel any existing connect operation.
+ this.cancel();
+
var normalizedAccessCode = this.normalizeAccessCode_(accessCode);
if (normalizedAccessCode.length != kAccessCodeLen) {
this.onError_(remoting.Error.INVALID_ACCESS_CODE);
@@ -167,6 +183,19 @@ remoting.SessionConnector.prototype.connectIT2Me = function(accessCode) {
};
/**
+ * Reconnect a closed connection.
+ *
+ * @return {void} Nothing.
+ */
+remoting.SessionConnector.prototype.reconnect = function() {
+ if (this.connectionMode_ == remoting.ClientSession.Mode.IT2ME) {
+ console.error('reconnect not supported for IT2Me.');
+ return;
+ }
+ this.createSessionIfReady_();
+};
+
+/**
* Cancel a connection-in-progress.
*/
remoting.SessionConnector.prototype.cancel = function() {
@@ -178,11 +207,7 @@ remoting.SessionConnector.prototype.cancel = function() {
this.pendingXhr_.abort();
this.pendingXhr_ = null;
}
- this.hostId_ = '';
- this.hostJid_ = '';
- this.passPhrase_ = '';
- this.hostPublicKey_ = '';
- this.refreshHostJidIfOffline_ = true;
+ this.reset();
};
/**