diff options
author | jamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 20:32:54 +0000 |
---|---|---|
committer | jamiewalch@google.com <jamiewalch@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-25 20:32:54 +0000 |
commit | b880b2d83257b51630ea95a5f5874dc393729f57 (patch) | |
tree | 65408a543500358a6b8d8f88142b8000b5da7905 /remoting/webapp | |
parent | 107af46bf67c5e1b6004a7dc75e96fb742a06589 (diff) | |
download | chromium_src-b880b2d83257b51630ea95a5f5874dc393729f57.zip chromium_src-b880b2d83257b51630ea95a5f5874dc393729f57.tar.gz chromium_src-b880b2d83257b51630ea95a5f5874dc393729f57.tar.bz2 |
Fixed callWithToken error handling.
BUG=124898
TEST=Manual
Review URL: https://chromiumcodereview.appspot.com/10207028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133970 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/webapp')
-rw-r--r-- | remoting/webapp/client_screen.js | 12 | ||||
-rw-r--r-- | remoting/webapp/host_controller.js | 9 | ||||
-rw-r--r-- | remoting/webapp/host_list.js | 70 | ||||
-rw-r--r-- | remoting/webapp/oauth2.js | 37 | ||||
-rw-r--r-- | remoting/webapp/wcs.js | 9 | ||||
-rw-r--r-- | remoting/webapp/wcs_loader.js | 9 |
6 files changed, 91 insertions, 55 deletions
diff --git a/remoting/webapp/client_screen.js b/remoting/webapp/client_screen.js index 8be30fb..2f066e7 100644 --- a/remoting/webapp/client_screen.js +++ b/remoting/webapp/client_screen.js @@ -314,11 +314,15 @@ function startSession_() { /** @type {string} */ (remoting.oauth2.getCachedEmail()), remoting.ClientSession.Mode.IT2ME, onClientStateChange_); - /** @param {string} token The auth token. */ + /** @param {string?} token The auth token. */ var createPluginAndConnect = function(token) { - remoting.clientSession.createPluginAndConnect( - document.getElementById('session-mode'), - token); + if (token) { + remoting.clientSession.createPluginAndConnect( + document.getElementById('session-mode'), + token); + } else { + showConnectError_(remoting.Error.AUTHENTICATION_FAILED); + } }; remoting.oauth2.callWithToken(createPluginAndConnect); } diff --git a/remoting/webapp/host_controller.js b/remoting/webapp/host_controller.js index b5850db..a29779e 100644 --- a/remoting/webapp/host_controller.js +++ b/remoting/webapp/host_controller.js @@ -203,9 +203,14 @@ remoting.HostController.prototype.start = function(hostPin, callback) { * @param {string} publicKey */ function onKeyGenerated(privateKey, publicKey) { remoting.oauth2.callWithToken( - /** @param {string} oauthToken */ + /** @param {string?} oauthToken */ function(oauthToken) { - doRegisterHost(privateKey, publicKey, oauthToken); + if (oauthToken) { + doRegisterHost(privateKey, publicKey, oauthToken); + } else { + // TODO(jamiewalch): Have a more specific error code here? + callback(remoting.HostController.AsyncResult.FAILED); + } }); }; diff --git a/remoting/webapp/host_list.js b/remoting/webapp/host_list.js index 2d0bb3f..e47bf5e 100644 --- a/remoting/webapp/host_list.js +++ b/remoting/webapp/host_list.js @@ -89,14 +89,19 @@ remoting.HostList.prototype.refresh = function(onDone) { var parseHostListResponse = function(xhr) { that.parseHostListResponse_(xhr, onDone); } - /** @param {string} token The OAuth2 token. */ + /** @param {string?} token The OAuth2 token. */ var getHosts = function(token) { - // TODO(simonmorris): Pass the access token in a header, not a URL - // parameter, when crbug.com/116574 has a better fix. - var params = { 'access_token': token }; - remoting.xhr.get( - 'https://www.googleapis.com/chromoting/v1/@me/hosts', - parseHostListResponse, params); + if (token) { + // TODO(simonmorris): Pass the access token in a header, not a URL + // parameter, when crbug.com/116574 has a better fix. + var params = { 'access_token': token }; + remoting.xhr.get( + 'https://www.googleapis.com/chromoting/v1/@me/hosts', + parseHostListResponse, params); + } else { + that.lastError_ = remoting.Error.AUTHENTICATION_FAILED; + onDone(false); + } }; remoting.oauth2.callWithToken(getHosts); }; @@ -226,12 +231,17 @@ remoting.HostList.prototype.deleteHost_ = function(hostTableEntry) { * @return {void} Nothing. */ remoting.HostList.unregisterHostById = function(hostId) { - /** @param {string} token The OAuth2 token. */ + /** @param {string?} token The OAuth2 token. */ var deleteHost = function(token) { - var headers = { 'Authorization': 'OAuth ' + token }; - remoting.xhr.remove( - 'https://www.googleapis.com/chromoting/v1/@me/hosts/' + hostId, - function() {}, '', headers); + if (token) { + var headers = { 'Authorization': 'OAuth ' + token }; + remoting.xhr.remove( + 'https://www.googleapis.com/chromoting/v1/@me/hosts/' + hostId, + function() {}, '', headers); + } else { + console.error('Could not unregister host. Authentication failure.'); + // TODO(jamiewalch): Add a callback to signify success/failure? + } } remoting.oauth2.callWithToken(deleteHost); }; @@ -251,23 +261,27 @@ remoting.HostList.prototype.renameHost = function(hostTableEntry) { window.localStorage.setItem(remoting.HostList.HOSTS_KEY, JSON.stringify(this.hosts_)); - /** @param {string} token */ + /** @param {string?} token */ var renameHost = function(token) { - var headers = { - 'Authorization': 'OAuth ' + token, - 'Content-type' : 'application/json; charset=UTF-8' - }; - var newHostDetails = { data: { - hostId: hostTableEntry.host.hostId, - hostName: hostTableEntry.host.hostName, - publicKey: hostTableEntry.host.publicKey - } }; - remoting.xhr.put( - 'https://www.googleapis.com/chromoting/v1/@me/hosts/' + - hostTableEntry.host.hostId, - function(xhr) {}, - JSON.stringify(newHostDetails), - headers); + if (token) { + var headers = { + 'Authorization': 'OAuth ' + token, + 'Content-type' : 'application/json; charset=UTF-8' + }; + var newHostDetails = { data: { + hostId: hostTableEntry.host.hostId, + hostName: hostTableEntry.host.hostName, + publicKey: hostTableEntry.host.publicKey + } }; + remoting.xhr.put( + 'https://www.googleapis.com/chromoting/v1/@me/hosts/' + + hostTableEntry.host.hostId, + function(xhr) {}, + JSON.stringify(newHostDetails), + headers); + } else { + console.error('Could not rename host. Authentication failure.'); + } } remoting.oauth2.callWithToken(renameHost); }; diff --git a/remoting/webapp/oauth2.js b/remoting/webapp/oauth2.js index e2dc933..5d61c4a 100644 --- a/remoting/webapp/oauth2.js +++ b/remoting/webapp/oauth2.js @@ -339,25 +339,24 @@ remoting.OAuth2.prototype.revokeToken_ = function(token) { * * The access token will remain valid for at least 2 minutes. * - * @param {function(string):void} myfunc - * Function to invoke with access token. + * @param {function(string?):void} myfunc Function to invoke with access token. * @return {void} Nothing. */ remoting.OAuth2.prototype.callWithToken = function(myfunc) { /** @type {remoting.OAuth2} */ var that = this; - 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.'; + if (this.needsNewAccessToken()) { + var onRefresh = function() { + if (that.needsNewAccessToken()) { + myfunc(null); + } else { + myfunc(that.getAccessToken()); } - myfunc(that.getAccessToken()); - }); - return; + }; + this.refreshAccessToken(onRefresh); + } else { + myfunc(this.getAccessToken()); } - - myfunc(this.getAccessToken()); }; /** @@ -381,12 +380,16 @@ remoting.OAuth2.prototype.getEmail = function(setEmail) { setEmail(that.email); }; - /** @param {string} token The access token. */ + /** @param {string?} token The access token. */ var getEmailFromToken = function(token) { - var headers = { 'Authorization': 'OAuth ' + token }; - // TODO(ajwong): Update to new v2 API. - remoting.xhr.get('https://www.googleapis.com/userinfo/email', - onResponse, '', headers); + if (token) { + var headers = { 'Authorization': 'OAuth ' + token }; + // TODO(ajwong): Update to new v2 API. + remoting.xhr.get('https://www.googleapis.com/userinfo/email', + onResponse, '', headers); + } else { + setEmail(null); + } }; this.callWithToken(getEmailFromToken); diff --git a/remoting/webapp/wcs.js b/remoting/webapp/wcs.js index e2bb9d7..25fbbe0 100644 --- a/remoting/webapp/wcs.js +++ b/remoting/webapp/wcs.js @@ -61,9 +61,14 @@ remoting.Wcs = function(wcsIqClient, token, onReady) { */ this.pollForUpdatedToken_ = setInterval( function() { - /** @param {string} token */ + /** @param {string?} token */ var updateAccessToken = function(token) { - that.updateAccessToken_(token); + if (token) { + that.updateAccessToken_(token); + } else { + console.error('pollForUpdatedToken: Authentication failed.'); + // No need to update the token. The hanging GET will fail anyway. + } } remoting.oauth2.callWithToken(updateAccessToken); }, diff --git a/remoting/webapp/wcs_loader.js b/remoting/webapp/wcs_loader.js index 54fd3cc..fdd3736 100644 --- a/remoting/webapp/wcs_loader.js +++ b/remoting/webapp/wcs_loader.js @@ -41,9 +41,14 @@ remoting.WcsLoader.load = function(onReady) { if (!remoting.wcsLoader) { remoting.wcsLoader = new remoting.WcsLoader(); } - /** @param {string} token The OAuth2 access token. */ + /** @param {string?} token The OAuth2 access token. */ var start = function(token) { - remoting.wcsLoader.start_(token, onReady); + if (token) { + remoting.wcsLoader.start_(token, onReady); + } else { + console.error('WcsLoader: Authentication failed.'); + onReady(null); + } }; remoting.oauth2.callWithToken(start); }; |