diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-18 20:53:45 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-18 20:53:45 +0000 |
commit | 5b41cd6e6cda5992948be27072fd0fa9727fd99f (patch) | |
tree | c3bcc3ac8ec3a0200b51b9de4e30cbf0b55012f0 /remoting | |
parent | 0f9aa2e7195ccff91b69016823835133e3946316 (diff) | |
download | chromium_src-5b41cd6e6cda5992948be27072fd0fa9727fd99f.zip chromium_src-5b41cd6e6cda5992948be27072fd0fa9727fd99f.tar.gz chromium_src-5b41cd6e6cda5992948be27072fd0fa9727fd99f.tar.bz2 |
Improve error handling when trying to connect to host.
BUG=73108
TEST=Connect to a host after disabling network.
Review URL: http://codereview.chromium.org/7388005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92881 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r-- | remoting/webapp/me2mom/choice.html | 3 | ||||
-rw-r--r-- | remoting/webapp/me2mom/oauth2.js | 10 | ||||
-rw-r--r-- | remoting/webapp/me2mom/remoting.js | 47 |
3 files changed, 38 insertions, 22 deletions
diff --git a/remoting/webapp/me2mom/choice.html b/remoting/webapp/me2mom/choice.html index 2a31cbb..7a453d3 100644 --- a/remoting/webapp/me2mom/choice.html +++ b/remoting/webapp/me2mom/choice.html @@ -176,6 +176,9 @@ found in the LICENSE file. </div> <!-- connecting --> <div id="connect-failed" class="mode"> + <div id="no-response" class="message"> + Failed to get response from server. + </div> <div id="invalid-access-code" class="message"> Invalid access code. </div> diff --git a/remoting/webapp/me2mom/oauth2.js b/remoting/webapp/me2mom/oauth2.js index c7a0c72..503cfec 100644 --- a/remoting/webapp/me2mom/oauth2.js +++ b/remoting/webapp/me2mom/oauth2.js @@ -177,7 +177,8 @@ remoting.OAuth2.prototype.processTokenResponse_ = function(xhr) { * * Will throw if !isAuthenticated(). * - * @param {function(): void} onDone Callback to invoke on completion. + * @param {function(XMLHttpRequest): void} onDone Callback to invoke on + * completion. * @return {void} */ remoting.OAuth2.prototype.refreshAccessToken = function(onDone) { @@ -196,7 +197,7 @@ remoting.OAuth2.prototype.refreshAccessToken = function(onDone) { remoting.xhr.post(this.OAUTH2_TOKEN_ENDPOINT_, function(xhr) { that.processTokenResponse_(xhr); - onDone(); + onDone(xhr); }, parameters); } @@ -221,7 +222,8 @@ remoting.OAuth2.prototype.doAuthRedirect = function() { * Asynchronously exchanges an authorization code for a refresh token. * * @param {string} code The new refresh token. - * @param {function():void} onDone Callback to invoke on completion. + * @param {function(XMLHttpRequest):void} onDone Callback to invoke on + * completion. * @return {void} */ remoting.OAuth2.prototype.exchangeCodeForToken = function(code, onDone) { @@ -237,7 +239,7 @@ remoting.OAuth2.prototype.exchangeCodeForToken = function(code, onDone) { remoting.xhr.post(this.OAUTH2_TOKEN_ENDPOINT_, function(xhr) { that.processTokenResponse_(xhr); - onDone(); + onDone(xhr); }, parameters); } diff --git a/remoting/webapp/me2mom/remoting.js b/remoting/webapp/me2mom/remoting.js index 041e04f..d4aa384 100644 --- a/remoting/webapp/me2mom/remoting.js +++ b/remoting/webapp/me2mom/remoting.js @@ -396,22 +396,28 @@ function startSession_() { } function showConnectError_(responseCode, responseString) { - var invalid = document.getElementById('invalid-access-code'); - var other = document.getElementById('other-connect-error'); - if (responseCode == 404) { - invalid.style.display = 'block'; - other.style.display = 'none'; + var errors = [ + document.getElementById('no-response'), + document.getElementById('invalid-access-code'), + document.getElementById('other-connect-error') + ]; + var showError = null; + if (responseCode == 0) { + showError = errors[0]; + } else if (responseCode == 404) { + showError = errors[1]; } else { - invalid.style.display = 'none'; - other.style.display = 'block'; + showError = errors[2]; var responseNode = document.getElementById('server-response'); responseNode.innerText = responseString + ' (' + responseCode + ')'; } + setMode_(showError.id, errors); remoting.accessCode = ''; remoting.setClientMode('connect-failed'); } function parseServerResponse_(xhr) { + remoting.debug.log('parseServerResponse: status = ' + xhr.status); if (xhr.status == 200) { var host = JSON.parse(xhr.responseText); if (host.data && host.data.jabberId) { @@ -443,17 +449,7 @@ function resolveSupportId(supportId) { headers); } -remoting.tryConnect = function() { - if (remoting.oauth2.needsNewAccessToken()) { - remoting.oauth2.refreshAccessToken(function() { - if (remoting.oauth2.needsNewAccessToken()) { - // If we still need it, we're going to infinite loop. - throw 'Unable to get access token.'; - } - remoting.tryConnect(); - }); - return; - } +remoting.doTryConnect = function() { var accessCode = document.getElementById('access-code-entry').value; remoting.accessCode = normalizeAccessCode_(accessCode); // At present, only 12-digit access codes are supported, of which the first @@ -467,6 +463,21 @@ remoting.tryConnect = function() { } } +remoting.tryConnect = function() { + if (remoting.oauth2.needsNewAccessToken()) { + remoting.oauth2.refreshAccessToken(function(xhr) { + if (remoting.oauth2.needsNewAccessToken()) { + // Failed to get access token + showConnectError_(xhr.status); + return; + } + remoting.doTryConnect(); + }); + } else { + remoting.doTryConnect(); + } +} + remoting.cancelPendingOperation = function() { document.getElementById('cancel-button').disabled = true; if (remoting.currentMode == remoting.AppMode.HOST) { |