Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1047)

Unified Diff: remoting/webapp/crd/js/oauth2_api_impl.js

Issue 945033002: Updated XHR API so call sites are more descriptive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@xhr-test
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/webapp/crd/js/oauth2.js ('k') | remoting/webapp/crd/js/session_connector_impl.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/crd/js/oauth2_api_impl.js
diff --git a/remoting/webapp/crd/js/oauth2_api_impl.js b/remoting/webapp/crd/js/oauth2_api_impl.js
index 1b86d9b2249e1f7fe5371fc5e17c2b7ffcdf60a5..290aeb14d96a7dd87c2ff55af06fccc44d57f901 100644
--- a/remoting/webapp/crd/js/oauth2_api_impl.js
+++ b/remoting/webapp/crd/js/oauth2_api_impl.js
@@ -73,37 +73,36 @@ remoting.OAuth2ApiImpl.prototype.interpretXhrStatus_ =
*/
remoting.OAuth2ApiImpl.prototype.refreshAccessToken = function(
onDone, onError, clientId, clientSecret, refreshToken) {
- /** @param {XMLHttpRequest} xhr */
- var onResponse = function(xhr) {
- if (xhr.status == 200) {
+ /** @param {remoting.Xhr.Response} xhrr */
+ var onResponse = function(xhrr) {
+ if (xhrr.status == 200) {
try {
// Don't use base.jsonParseSafe here unless you also include base.js,
// otherwise this won't work from the OAuth trampoline.
// TODO(jamiewalch): Fix this once we're no longer using the trampoline.
- var tokens = JSON.parse(xhr.responseText);
+ var tokens = JSON.parse(xhrr.responseText);
onDone(tokens['access_token'], tokens['expires_in']);
} catch (/** @type {Error} */ err) {
console.error('Invalid "token" response from server:', err);
onError(remoting.Error.UNEXPECTED);
}
} else {
- console.error('Failed to refresh token. Status: ' + xhr.status +
- ' response: ' + xhr.responseText);
- onError(remoting.Error.fromHttpStatus(xhr.status));
+ console.error('Failed to refresh token. Status: ' + xhrr.status +
+ ' response: ' + xhrr.responseText);
+ onError(remoting.Error.fromHttpStatus(xhrr.status));
}
};
- remoting.xhr.start({
+ new remoting.Xhr({
method: 'POST',
url: this.getOAuth2TokenEndpoint_(),
- onDone: onResponse,
formContent: {
'client_id': clientId,
'client_secret': clientSecret,
'refresh_token': refreshToken,
'grant_type': 'refresh_token'
}
- });
+ }).then(onResponse);
};
/**
@@ -122,14 +121,14 @@ remoting.OAuth2ApiImpl.prototype.refreshAccessToken = function(
*/
remoting.OAuth2ApiImpl.prototype.exchangeCodeForTokens = function(
onDone, onError, clientId, clientSecret, code, redirectUri) {
- /** @param {XMLHttpRequest} xhr */
- var onResponse = function(xhr) {
- if (xhr.status == 200) {
+ /** @param {remoting.Xhr.Response} xhrr */
+ var onResponse = function(xhrr) {
+ if (xhrr.status == 200) {
try {
// Don't use base.jsonParseSafe here unless you also include base.js,
// otherwise this won't work from the OAuth trampoline.
// TODO(jamiewalch): Fix this once we're no longer using the trampoline.
- var tokens = JSON.parse(xhr.responseText);
+ var tokens = JSON.parse(xhrr.responseText);
onDone(tokens['refresh_token'],
tokens['access_token'], tokens['expires_in']);
} catch (/** @type {Error} */ err) {
@@ -137,16 +136,15 @@ remoting.OAuth2ApiImpl.prototype.exchangeCodeForTokens = function(
onError(remoting.Error.UNEXPECTED);
}
} else {
- console.error('Failed to exchange code for token. Status: ' + xhr.status +
- ' response: ' + xhr.responseText);
- onError(remoting.Error.fromHttpStatus(xhr.status));
+ console.error('Failed to exchange code for token. Status: ' +
+ xhrr.status + ' response: ' + xhrr.responseText);
+ onError(remoting.Error.fromHttpStatus(xhrr.status));
}
};
- remoting.xhr.start({
+ new remoting.Xhr({
method: 'POST',
url: this.getOAuth2TokenEndpoint_(),
- onDone: onResponse,
formContent: {
'client_id': clientId,
'client_secret': clientSecret,
@@ -154,7 +152,7 @@ remoting.OAuth2ApiImpl.prototype.exchangeCodeForTokens = function(
'code': code,
'grant_type': 'authorization_code'
}
- });
+ }).then(onResponse);
};
/**
@@ -168,28 +166,27 @@ remoting.OAuth2ApiImpl.prototype.exchangeCodeForTokens = function(
* @return {void} Nothing.
*/
remoting.OAuth2ApiImpl.prototype.getEmail = function(onDone, onError, token) {
- /** @param {XMLHttpRequest} xhr */
- var onResponse = function(xhr) {
- if (xhr.status == 200) {
+ /** @param {remoting.Xhr.Response} xhrr */
+ var onResponse = function(xhrr) {
+ if (xhrr.status == 200) {
try {
- var result = JSON.parse(xhr.responseText);
+ var result = JSON.parse(xhrr.responseText);
onDone(result['email']);
} catch (/** @type {Error} */ err) {
console.error('Invalid "userinfo" response from server:', err);
onError(remoting.Error.UNEXPECTED);
}
} else {
- console.error('Failed to get email. Status: ' + xhr.status +
- ' response: ' + xhr.responseText);
- onError(remoting.Error.fromHttpStatus(xhr.status));
+ console.error('Failed to get email. Status: ' + xhrr.status +
+ ' response: ' + xhrr.responseText);
+ onError(remoting.Error.fromHttpStatus(xhrr.status));
}
};
- remoting.xhr.start({
+ new remoting.Xhr({
method: 'GET',
url: this.getOAuth2ApiUserInfoEndpoint_(),
- onDone: onResponse,
oauthToken: token
- });
+ }).then(onResponse);
};
/**
@@ -204,28 +201,27 @@ remoting.OAuth2ApiImpl.prototype.getEmail = function(onDone, onError, token) {
*/
remoting.OAuth2ApiImpl.prototype.getUserInfo =
function(onDone, onError, token) {
- /** @param {XMLHttpRequest} xhr */
- var onResponse = function(xhr) {
- if (xhr.status == 200) {
+ /** @param {remoting.Xhr.Response} xhrr */
+ var onResponse = function(xhrr) {
+ if (xhrr.status == 200) {
try {
- var result = JSON.parse(xhr.responseText);
+ var result = JSON.parse(xhrr.responseText);
onDone(result['email'], result['name']);
} catch (/** @type {Error} */ err) {
console.error('Invalid "userinfo" response from server:', err);
onError(remoting.Error.UNEXPECTED);
}
} else {
- console.error('Failed to get user info. Status: ' + xhr.status +
- ' response: ' + xhr.responseText);
- onError(remoting.Error.fromHttpStatus(xhr.status));
+ console.error('Failed to get user info. Status: ' + xhrr.status +
+ ' response: ' + xhrr.responseText);
+ onError(remoting.Error.fromHttpStatus(xhrr.status));
}
};
- remoting.xhr.start({
+ new remoting.Xhr({
method: 'GET',
url: this.getOAuth2ApiUserInfoEndpoint_(),
- onDone: onResponse,
oauthToken: token
- });
+ }).then(onResponse);
};
/** @type {remoting.OAuth2Api} */
« no previous file with comments | « remoting/webapp/crd/js/oauth2.js ('k') | remoting/webapp/crd/js/session_connector_impl.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698