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

Side by Side Diff: remoting/webapp/crd/js/oauth2_api_impl.js

Issue 803653004: Update Chromoting to use /third_party/closure_compiler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Define Entry for browser_tests Created 5 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * OAuth2 API flow implementations. 7 * OAuth2 API flow implementations.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 onDone, onError, clientId, clientSecret, refreshToken) { 75 onDone, onError, clientId, clientSecret, refreshToken) {
76 /** @param {XMLHttpRequest} xhr */ 76 /** @param {XMLHttpRequest} xhr */
77 var onResponse = function(xhr) { 77 var onResponse = function(xhr) {
78 if (xhr.status == 200) { 78 if (xhr.status == 200) {
79 try { 79 try {
80 // Don't use base.jsonParseSafe here unless you also include base.js, 80 // Don't use base.jsonParseSafe here unless you also include base.js,
81 // otherwise this won't work from the OAuth trampoline. 81 // otherwise this won't work from the OAuth trampoline.
82 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. 82 // TODO(jamiewalch): Fix this once we're no longer using the trampoline.
83 var tokens = JSON.parse(xhr.responseText); 83 var tokens = JSON.parse(xhr.responseText);
84 onDone(tokens['access_token'], tokens['expires_in']); 84 onDone(tokens['access_token'], tokens['expires_in']);
85 } catch (err) { 85 } catch (/** @type {Error} */ err) {
86 console.error('Invalid "token" response from server:', 86 console.error('Invalid "token" response from server:', err);
87 /** @type {*} */ (err));
88 onError(remoting.Error.UNEXPECTED); 87 onError(remoting.Error.UNEXPECTED);
89 } 88 }
90 } else { 89 } else {
91 console.error('Failed to refresh token. Status: ' + xhr.status + 90 console.error('Failed to refresh token. Status: ' + xhr.status +
92 ' response: ' + xhr.responseText); 91 ' response: ' + xhr.responseText);
93 onError(remoting.Error.fromHttpError(xhr.status)); 92 onError(remoting.Error.fromHttpError(xhr.status));
94 } 93 }
95 }; 94 };
96 95
97 var parameters = { 96 var parameters = {
(...skipping 25 matching lines...) Expand all
123 /** @param {XMLHttpRequest} xhr */ 122 /** @param {XMLHttpRequest} xhr */
124 var onResponse = function(xhr) { 123 var onResponse = function(xhr) {
125 if (xhr.status == 200) { 124 if (xhr.status == 200) {
126 try { 125 try {
127 // Don't use base.jsonParseSafe here unless you also include base.js, 126 // Don't use base.jsonParseSafe here unless you also include base.js,
128 // otherwise this won't work from the OAuth trampoline. 127 // otherwise this won't work from the OAuth trampoline.
129 // TODO(jamiewalch): Fix this once we're no longer using the trampoline. 128 // TODO(jamiewalch): Fix this once we're no longer using the trampoline.
130 var tokens = JSON.parse(xhr.responseText); 129 var tokens = JSON.parse(xhr.responseText);
131 onDone(tokens['refresh_token'], 130 onDone(tokens['refresh_token'],
132 tokens['access_token'], tokens['expires_in']); 131 tokens['access_token'], tokens['expires_in']);
133 } catch (err) { 132 } catch (/** @type {Error} */ err) {
134 console.error('Invalid "token" response from server:', 133 console.error('Invalid "token" response from server:', err);
135 /** @type {*} */ (err));
136 onError(remoting.Error.UNEXPECTED); 134 onError(remoting.Error.UNEXPECTED);
137 } 135 }
138 } else { 136 } else {
139 console.error('Failed to exchange code for token. Status: ' + xhr.status + 137 console.error('Failed to exchange code for token. Status: ' + xhr.status +
140 ' response: ' + xhr.responseText); 138 ' response: ' + xhr.responseText);
141 onError(remoting.Error.fromHttpError(xhr.status)); 139 onError(remoting.Error.fromHttpError(xhr.status));
142 } 140 }
143 }; 141 };
144 142
145 var parameters = { 143 var parameters = {
(...skipping 16 matching lines...) Expand all
162 * @param {string} token Access token. 160 * @param {string} token Access token.
163 * @return {void} Nothing. 161 * @return {void} Nothing.
164 */ 162 */
165 remoting.OAuth2ApiImpl.prototype.getEmail = function(onDone, onError, token) { 163 remoting.OAuth2ApiImpl.prototype.getEmail = function(onDone, onError, token) {
166 /** @param {XMLHttpRequest} xhr */ 164 /** @param {XMLHttpRequest} xhr */
167 var onResponse = function(xhr) { 165 var onResponse = function(xhr) {
168 if (xhr.status == 200) { 166 if (xhr.status == 200) {
169 try { 167 try {
170 var result = JSON.parse(xhr.responseText); 168 var result = JSON.parse(xhr.responseText);
171 onDone(result['email']); 169 onDone(result['email']);
172 } catch (err) { 170 } catch (/** @type {Error} */ err) {
173 console.error('Invalid "userinfo" response from server:', 171 console.error('Invalid "userinfo" response from server:', err);
174 /** @type {*} */ (err));
175 onError(remoting.Error.UNEXPECTED); 172 onError(remoting.Error.UNEXPECTED);
176 } 173 }
177 } else { 174 } else {
178 console.error('Failed to get email. Status: ' + xhr.status + 175 console.error('Failed to get email. Status: ' + xhr.status +
179 ' response: ' + xhr.responseText); 176 ' response: ' + xhr.responseText);
180 onError(remoting.Error.fromHttpError(xhr.status)); 177 onError(remoting.Error.fromHttpError(xhr.status));
181 } 178 }
182 }; 179 };
183 var headers = { 'Authorization': 'OAuth ' + token }; 180 var headers = { 'Authorization': 'OAuth ' + token };
184 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), 181 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(),
(...skipping 11 matching lines...) Expand all
196 * @return {void} Nothing. 193 * @return {void} Nothing.
197 */ 194 */
198 remoting.OAuth2ApiImpl.prototype.getUserInfo = 195 remoting.OAuth2ApiImpl.prototype.getUserInfo =
199 function(onDone, onError, token) { 196 function(onDone, onError, token) {
200 /** @param {XMLHttpRequest} xhr */ 197 /** @param {XMLHttpRequest} xhr */
201 var onResponse = function(xhr) { 198 var onResponse = function(xhr) {
202 if (xhr.status == 200) { 199 if (xhr.status == 200) {
203 try { 200 try {
204 var result = JSON.parse(xhr.responseText); 201 var result = JSON.parse(xhr.responseText);
205 onDone(result['email'], result['name']); 202 onDone(result['email'], result['name']);
206 } catch (err) { 203 } catch (/** @type {Error} */ err) {
207 console.error('Invalid "userinfo" response from server:', 204 console.error('Invalid "userinfo" response from server:', err);
208 /** @type {*} */ (err));
209 onError(remoting.Error.UNEXPECTED); 205 onError(remoting.Error.UNEXPECTED);
210 } 206 }
211 } else { 207 } else {
212 console.error('Failed to get user info. Status: ' + xhr.status + 208 console.error('Failed to get user info. Status: ' + xhr.status +
213 ' response: ' + xhr.responseText); 209 ' response: ' + xhr.responseText);
214 onError(remoting.Error.fromHttpError(xhr.status)); 210 onError(remoting.Error.fromHttpError(xhr.status));
215 } 211 }
216 }; 212 };
217 var headers = { 'Authorization': 'OAuth ' + token }; 213 var headers = { 'Authorization': 'OAuth ' + token };
218 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(), 214 remoting.xhr.get(this.getOAuth2ApiUserInfoEndpoint_(),
219 onResponse, '', headers); 215 onResponse, '', headers);
220 }; 216 };
221 217
222 /** @type {remoting.OAuth2Api} */ 218 /** @type {remoting.OAuth2Api} */
223 remoting.oauth2Api = new remoting.OAuth2ApiImpl(); 219 remoting.oauth2Api = new remoting.OAuth2ApiImpl();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698