0

Implemented cancel connect.

BUG=None
TEST=Manual

Review URL: http://codereview.chromium.org/8273024

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105525 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
jamiewalch@google.com
2011-10-14 18:17:23 +00:00
parent 220661ce55
commit 9208bd558d
3 changed files with 63 additions and 25 deletions
remoting/webapp/me2mom

@@ -205,11 +205,6 @@ found in the LICENSE file.
</div> <!-- code-entry-row --> </div> <!-- code-entry-row -->
</div> <!-- client.unconnected --> </div> <!-- client.unconnected -->
<!-- TODO(jamiewalch): Implement Cancel, being careful when ignoring
the eventual server response not to ignore responses for any
subsequent requests. This should be unified with the host-side
Cancel button in the footer.
-->
<div data-ui-mode="client.connecting" class="message" <div data-ui-mode="client.connecting" class="message"
i18n-content="VERIFYING_CODE"> i18n-content="VERIFYING_CODE">
</div> <!-- client.connecting --> </div> <!-- client.connecting -->
@@ -247,7 +242,7 @@ found in the LICENSE file.
</div> <!-- client-footer-text-cros --> </div> <!-- client-footer-text-cros -->
<div id="waiting-footer" <div id="waiting-footer"
data-ui-mode="host.waiting-for-connection host.waiting-for-code"> data-ui-mode="host.waiting-for-connection host.waiting-for-code client.connecting">
<img src="spinner.gif"> <img src="spinner.gif">
<span class="waiting icon-label" i18n-content="FOOTER_WAITING"></span> <span class="waiting icon-label" i18n-content="FOOTER_WAITING"></span>
<button id="cancel-button" class="big-button" <button id="cancel-button" class="big-button"

@@ -157,6 +157,8 @@ remoting.init = function() {
remoting.oauth2 = new remoting.OAuth2(); remoting.oauth2 = new remoting.OAuth2();
remoting.debug = remoting.debug =
new remoting.DebugLog(document.getElementById('debug-messages')); new remoting.DebugLog(document.getElementById('debug-messages'));
/** @type {XMLHttpRequest} */
remoting.supportHostsXhr = null;
refreshEmail_(); refreshEmail_();
var email = getEmail(); var email = getEmail();
@@ -378,20 +380,20 @@ function onStateChanged_() {
} }
/** /**
* This is the callback that the host plugin invokes to indicate that there * This is the callback that the host plugin invokes to indicate that there
* is additional debug log info to display. * is additional debug log info to display.
* @param {string} msg The message (which will not be localized) to be logged. * @param {string} msg The message (which will not be localized) to be logged.
*/ */
function debugInfoCallback_(msg) { function debugInfoCallback_(msg) {
remoting.debug.log('plugin: ' + msg); remoting.debug.log('plugin: ' + msg);
} }
/** /**
* Show a host-side error message. * Show a host-side error message.
* *
* @param {string} errorTag The error message to be localized and displayed. * @param {string} errorTag The error message to be localized and displayed.
* @return {void} Nothing. * @return {void} Nothing.
*/ */
function showShareError_(errorTag) { function showShareError_(errorTag) {
var errorDiv = document.getElementById('host-plugin-error'); var errorDiv = document.getElementById('host-plugin-error');
l10n.localizeElementFromTag(errorDiv, errorTag); l10n.localizeElementFromTag(errorDiv, errorTag);
@@ -399,6 +401,11 @@ function showShareError_(errorTag) {
remoting.setMode(remoting.AppMode.HOST_SHARE_FAILED); remoting.setMode(remoting.AppMode.HOST_SHARE_FAILED);
} }
/**
* Cancel an active or pending share operation.
*
* @return {void} Nothing.
*/
remoting.cancelShare = function() { remoting.cancelShare = function() {
remoting.debug.log('Canceling share...'); remoting.debug.log('Canceling share...');
remoting.lastShareWasCancelled = true; remoting.lastShareWasCancelled = true;
@@ -418,6 +425,23 @@ remoting.cancelShare = function() {
disableTimeoutCountdown_(); disableTimeoutCountdown_();
} }
/**
* Cancel an incomplete connect operation.
*
* @return {void} Nothing.
*/
remoting.cancelConnect = function() {
if (remoting.supportHostsXhr) {
remoting.supportHostsXhr.abort();
remoting.supportHostsXhr = null;
}
if (remoting.session) {
remoting.session.removePlugin();
remoting.session = null;
}
remoting.setMode(remoting.AppMode.HOME);
}
function updateStatistics() { function updateStatistics() {
if (!remoting.session) if (!remoting.session)
return; return;
@@ -460,6 +484,11 @@ function showToolbarPreview_() {
} }
function onClientStateChange_(oldState) { function onClientStateChange_(oldState) {
if (!remoting.session) {
// If the connection has been cancelled, then we no longer have a reference
// to the session object and should ignore any state changes.
return;
}
var state = remoting.session.state; var state = remoting.session.state;
if (state == remoting.ClientSession.State.CREATED) { if (state == remoting.ClientSession.State.CREATED) {
remoting.debug.log('Created plugin'); remoting.debug.log('Created plugin');
@@ -470,12 +499,12 @@ function onClientStateChange_(oldState) {
} else if (state == remoting.ClientSession.State.INITIALIZING) { } else if (state == remoting.ClientSession.State.INITIALIZING) {
remoting.debug.log('Initializing connection'); remoting.debug.log('Initializing connection');
} else if (state == remoting.ClientSession.State.CONNECTED) { } else if (state == remoting.ClientSession.State.CONNECTED) {
remoting.setMode(remoting.AppMode.IN_SESSION); if (remoting.session) {
recenterToolbar_(); remoting.setMode(remoting.AppMode.IN_SESSION);
showToolbarPreview_(); recenterToolbar_();
updateStatistics(); showToolbarPreview_();
var accessCode = document.getElementById('access-code-entry'); updateStatistics();
accessCode.value = ''; }
} else if (state == remoting.ClientSession.State.CLOSED) { } else if (state == remoting.ClientSession.State.CLOSED) {
if (oldState == remoting.ClientSession.State.CONNECTED) { if (oldState == remoting.ClientSession.State.CONNECTED) {
remoting.session.removePlugin(); remoting.session.removePlugin();
@@ -515,6 +544,8 @@ function onClientStateChange_(oldState) {
function startSession_() { function startSession_() {
remoting.debug.log('Starting session...'); remoting.debug.log('Starting session...');
var accessCode = document.getElementById('access-code-entry');
accessCode.value = ''; // The code has been validated and won't work again.
remoting.username = remoting.username =
/** @type {string} email must be non-NULL to get here */ getEmail(); /** @type {string} email must be non-NULL to get here */ getEmail();
remoting.session = remoting.session =
@@ -547,7 +578,12 @@ function showConnectError_(errorTag) {
remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED); remoting.setMode(remoting.AppMode.CLIENT_CONNECT_FAILED);
} }
/**
* @param {XMLHttpRequest} xhr The XMLHttpRequest object.
* @return {void} Nothing.
*/
function parseServerResponse_(xhr) { function parseServerResponse_(xhr) {
remoting.supportHostsXhr = null;
remoting.debug.log('parseServerResponse: status = ' + xhr.status); remoting.debug.log('parseServerResponse: status = ' + xhr.status);
if (xhr.status == 200) { if (xhr.status == 200) {
var host = JSON.parse(xhr.responseText); var host = JSON.parse(xhr.responseText);
@@ -582,7 +618,7 @@ function resolveSupportId(supportId) {
'Authorization': 'OAuth ' + remoting.oauth2.getAccessToken() 'Authorization': 'OAuth ' + remoting.oauth2.getAccessToken()
}; };
remoting.xhr.get( remoting.supportHostsXhr = remoting.xhr.get(
'https://www.googleapis.com/chromoting/v1/support-hosts/' + 'https://www.googleapis.com/chromoting/v1/support-hosts/' +
encodeURIComponent(supportId), encodeURIComponent(supportId),
parseServerResponse_, parseServerResponse_,
@@ -591,6 +627,7 @@ function resolveSupportId(supportId) {
} }
remoting.tryConnect = function() { remoting.tryConnect = function() {
document.getElementById('cancel-button').disabled = false;
if (remoting.oauth2.needsNewAccessToken()) { if (remoting.oauth2.needsNewAccessToken()) {
remoting.oauth2.refreshAccessToken(function(xhr) { remoting.oauth2.refreshAccessToken(function(xhr) {
if (remoting.oauth2.needsNewAccessToken()) { if (remoting.oauth2.needsNewAccessToken()) {
@@ -635,8 +672,13 @@ remoting.tryConnectWithWcs = function() {
remoting.cancelPendingOperation = function() { remoting.cancelPendingOperation = function() {
document.getElementById('cancel-button').disabled = true; document.getElementById('cancel-button').disabled = true;
if (remoting.getMajorMode() == remoting.AppMode.HOST) { switch (remoting.getMajorMode()) {
remoting.cancelShare(); case remoting.AppMode.HOST:
remoting.cancelShare();
break;
case remoting.AppMode.CLIENT:
remoting.cancelConnect();
break;
} }
} }

@@ -48,7 +48,7 @@ remoting.xhr.urlencodeParamHash = function(paramHash) {
* request. * request.
* @param {boolean} opt_withCredentials Set the withCredentials flags in the * @param {boolean} opt_withCredentials Set the withCredentials flags in the
* XHR. * XHR.
* @return {void} Nothing. * @return {XMLHttpRequest} The request object.
*/ */
remoting.xhr.get = function(url, onDone, opt_parameters, opt_headers, remoting.xhr.get = function(url, onDone, opt_parameters, opt_headers,
opt_withCredentials) { opt_withCredentials) {
@@ -94,6 +94,7 @@ remoting.xhr.get = function(url, onDone, opt_parameters, opt_headers,
} }
xhr.send(null); xhr.send(null);
return xhr;
} }
/** /**