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

Side by Side Diff: remoting/webapp/me2mom/remoting.js

Issue 7048020: Don't use letters in me2mom access code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « remoting/protocol/auth_token_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // TODO(ajwong): This seems like a bad idea to share the exact same object 5 // TODO(ajwong): This seems like a bad idea to share the exact same object
6 // with the background page. Why are we doing it like this? 6 // with the background page. Why are we doing it like this?
7 var remoting = chrome.extension.getBackgroundPage().remoting; 7 var remoting = chrome.extension.getBackgroundPage().remoting;
8 8
9 XMPP_LOGIN_NAME = 'xmpp_login'; 9 XMPP_LOGIN_NAME = 'xmpp_login';
10 XMPP_TOKEN_NAME = 'xmpp_token'; 10 XMPP_TOKEN_NAME = 'xmpp_token';
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 var host = JSON.parse(xhr.responseText); 256 var host = JSON.parse(xhr.responseText);
257 if (host.data && host.data.jabberId) { 257 if (host.data && host.data.jabberId) {
258 remoting.hostjid = host.data.jabberId; 258 remoting.hostjid = host.data.jabberId;
259 startSession_(); 259 startSession_();
260 return; 260 return;
261 } 261 }
262 } 262 }
263 showConnectError_(xhr.status, xhr.responseText); 263 showConnectError_(xhr.status, xhr.responseText);
264 } 264 }
265 265
266 function normalizeAccessCode(accessCode) {
267 // Trim whitespace from beginning and the end.
268 // TODO(sergeyu): Do we need to do any other normalization here?
269 return accessCode.replace(/^\s+|\s+$/, '');
270 }
271
266 function resolveSupportId(support_id) { 272 function resolveSupportId(support_id) {
267 var xhr = new XMLHttpRequest(); 273 var xhr = new XMLHttpRequest();
268 xhr.onreadystatechange = function() { 274 xhr.onreadystatechange = function() {
269 if (xhr.readyState != 4) { 275 if (xhr.readyState != 4) {
270 return; 276 return;
271 } 277 }
272 parseServerResponse_(xhr); 278 parseServerResponse_(xhr);
273 }; 279 };
274 280
275 xhr.open('GET', 281 xhr.open('GET',
276 'https://www.googleapis.com/chromoting/v1/support-hosts/' + 282 'https://www.googleapis.com/chromoting/v1/support-hosts/' +
277 encodeURIComponent(support_id), 283 encodeURIComponent(support_id),
278 true); 284 true);
279 xhr.setRequestHeader('Authorization', 285 xhr.setRequestHeader('Authorization',
280 'OAuth ' + remoting.oauth2.getAccessToken()); 286 'OAuth ' + remoting.oauth2.getAccessToken());
281 xhr.send(null); 287 xhr.send(null);
282 } 288 }
283 289
284 function tryConnect(form) { 290 function tryConnect(form) {
285 remoting.accessCode = form['access_code_entry'].value; 291 remoting.accessCode = normalizeAccessCode(form['access_code_entry'].value);
286 // TODO(jamiewalch): Since the mapping from (SupportId, HostSecret) to 292 // TODO(jamiewalch): Since the mapping from (SupportId, HostSecret) to
287 // AccessCode is not yet defined, assume it's hyphen-separated for now. 293 // AccessCode is not yet defined, assume it's hyphen-separated for now.
288 var parts = remoting.accessCode.split('-'); 294 var parts = remoting.accessCode.split('-');
289 if (parts.length != 2) { 295 if (parts.length != 2) {
290 showConnectError_(404); 296 showConnectError_(404);
291 } else { 297 } else {
292 setClientMode('connecting'); 298 setClientMode('connecting');
293 if (remoting.oauth2.needsNewAccessToken()) { 299 if (remoting.oauth2.needsNewAccessToken()) {
294 remoting.oauth2.refreshAccessToken(function() { 300 remoting.oauth2.refreshAccessToken(function() {
295 resolveSupportId(parts[0]); 301 resolveSupportId(parts[0]);
296 }); 302 });
297 return; 303 return;
298 } else { 304 } else {
299 resolveSupportId(parts[0]); 305 resolveSupportId(parts[0]);
300 } 306 }
301 } 307 }
302 } 308 }
303 309
304 function cancelConnect() { 310 function cancelConnect() {
305 remoting.accessCode = ''; 311 remoting.accessCode = '';
306 setClientMode('unconnected'); 312 setClientMode('unconnected');
307 } 313 }
OLDNEW
« no previous file with comments | « remoting/protocol/auth_token_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698