diff options
author | jamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 23:46:46 +0000 |
---|---|---|
committer | jamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-25 23:46:46 +0000 |
commit | 23e4353dfe2483dcfc7511bf2b23643fbdc5a949 (patch) | |
tree | 10a60918d09269d958da529185e920ee6cb6bce6 /remoting/webapp/host_screen.js | |
parent | e335fd5150fc614e1b9df1d9e7e93ec7793d26f7 (diff) | |
download | chromium_src-23e4353dfe2483dcfc7511bf2b23643fbdc5a949.zip chromium_src-23e4353dfe2483dcfc7511bf2b23643fbdc5a949.tar.gz chromium_src-23e4353dfe2483dcfc7511bf2b23643fbdc5a949.tar.bz2 |
Pass OAuth token refresh errors back to the caller.
This allows the app to advise the user to sign back in to Chromoting only when
we believe it will actually help. As a bonus, the unhelpfully-named
ERROR_GENERIC is now gone--apart from OAuth refresh failures, it was being used
for edge-cases where we don't expect anything to go wrong (these now use the
more suitably-named ERROR_UNEXPECTED).
As part of fixing this, I have cleaned up some OAuth call points that were
written before callWithToken existed, and which weren't using it.
BUG=122899,130794
TEST=Corrupt the oauth2-refresh-token value in HTML Local Storage
Review URL: https://chromiumcodereview.appspot.com/10579012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@144059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp/host_screen.js')
-rw-r--r-- | remoting/webapp/host_screen.js | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/remoting/webapp/host_screen.js b/remoting/webapp/host_screen.js index f904c96..7edb2f0 100644 --- a/remoting/webapp/host_screen.js +++ b/remoting/webapp/host_screen.js @@ -26,20 +26,16 @@ var lastShareWasCancelled_ = false; */ remoting.tryShare = function() { console.log('Attempting to share...'); - lastShareWasCancelled_ = false; - if (remoting.oauth2.needsNewAccessToken()) { - console.log('Refreshing token...'); - remoting.oauth2.refreshAccessToken(function() { - if (remoting.oauth2.needsNewAccessToken()) { - // If we still need it, we're going to infinite loop. - showShareError_(remoting.Error.AUTHENTICATION_FAILED); - throw 'Unable to get access token'; - } - remoting.tryShare(); - }); - return; - } + remoting.oauth2.callWithToken(remoting.tryShareWithToken_, + remoting.defaultOAuthErrorHandler); +}; +/** + * @param {string} token The OAuth access token. + * @private + */ +remoting.tryShareWithToken_ = function(token) { + lastShareWasCancelled_ = false; onNatTraversalPolicyChanged_(true); // Hide warning by default. remoting.setMode(remoting.AppMode.HOST_WAITING_FOR_CODE); document.getElementById('cancel-share-button').disabled = false; @@ -50,7 +46,7 @@ remoting.tryShare = function() { remoting.hostSession.createPluginAndConnect( document.getElementById('host-plugin-container'), /** @type {string} */(remoting.oauth2.getCachedEmail()), - remoting.oauth2.getAccessToken(), + token, onNatTraversalPolicyChanged_, onHostStateChanged_, logDebugInfo_); @@ -124,7 +120,7 @@ function onHostStateChanged_(state) { } else if (state == remoting.HostSession.State.ERROR) { console.error('Host plugin state: ERROR'); - showShareError_(remoting.Error.GENERIC); + showShareError_(remoting.Error.UNEXPECTED); } else { console.error('Unknown state -> ' + state); } @@ -172,7 +168,7 @@ remoting.cancelShare = function() { // the host plugin, like we do for the client, which should handle crash // reporting and it should use a more detailed error message than the // default 'generic' one. See crbug.com/94624 - showShareError_(remoting.Error.GENERIC); + showShareError_(remoting.Error.UNEXPECTED); } disableTimeoutCountdown_(); }; |