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

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

Issue 687873003: Allow the background page to get an OAuth token for apps v1. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move jsonParseSafe into base namespace. Created 6 years, 1 month 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
« no previous file with comments | « remoting/webapp/crd/js/oauth2_api.js ('k') | remoting/webapp/crd/js/session_connector_impl.js » ('j') | 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 'use strict'; 5 'use strict';
6 6
7 /** @suppress {duplicate} */ 7 /** @suppress {duplicate} */
8 var remoting = remoting || {}; 8 var remoting = remoting || {};
9 9
10 /** @type {remoting.HostSession} */ remoting.hostSession = null; 10 /** @type {remoting.HostSession} */ remoting.hostSession = null;
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 var result = {}; 417 var result = {};
418 var parts = window.location.search.substring(1).split('&'); 418 var parts = window.location.search.substring(1).split('&');
419 for (var i = 0; i < parts.length; i++) { 419 for (var i = 0; i < parts.length; i++) {
420 var pair = parts[i].split('='); 420 var pair = parts[i].split('=');
421 result[pair[0]] = decodeURIComponent(pair[1]); 421 result[pair[0]] = decodeURIComponent(pair[1]);
422 } 422 }
423 return result; 423 return result;
424 } 424 }
425 425
426 /** 426 /**
427 * @param {string} jsonString A JSON-encoded string.
428 * @return {*} The decoded object, or undefined if the string cannot be parsed.
429 */
430 function jsonParseSafe(jsonString) {
431 try {
432 return JSON.parse(jsonString);
433 } catch (err) {
434 return undefined;
435 }
436 }
437
438 /**
439 * Return the current time as a formatted string suitable for logging. 427 * Return the current time as a formatted string suitable for logging.
440 * 428 *
441 * @return {string} The current time, formatted as [mmdd/hhmmss.xyz] 429 * @return {string} The current time, formatted as [mmdd/hhmmss.xyz]
442 */ 430 */
443 remoting.timestamp = function() { 431 remoting.timestamp = function() {
444 /** 432 /**
445 * @param {number} num A number. 433 * @param {number} num A number.
446 * @param {number} len The required length of the answer. 434 * @param {number} len The required length of the answer.
447 * @return {string} The number, formatted as a string of the specified length 435 * @return {string} The number, formatted as a string of the specified length
448 * by prepending zeroes as necessary. 436 * by prepending zeroes as necessary.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 if (oauthSettings.indexOf(setting) == -1) { 509 if (oauthSettings.indexOf(setting) == -1) {
522 var copy = {} 510 var copy = {}
523 copy[setting] = window.localStorage.getItem(setting); 511 copy[setting] = window.localStorage.getItem(setting);
524 chrome.storage.local.set(copy); 512 chrome.storage.local.set(copy);
525 window.localStorage.removeItem(setting); 513 window.localStorage.removeItem(setting);
526 } 514 }
527 } 515 }
528 } 516 }
529 517
530 /** 518 /**
531 * Generate a nonce, to be used as an xsrf protection token.
532 *
533 * @return {string} A URL-Safe Base64-encoded 128-bit random value. */
534 remoting.generateXsrfToken = function() {
535 var random = new Uint8Array(16);
536 window.crypto.getRandomValues(random);
537 var base64Token = window.btoa(String.fromCharCode.apply(null, random));
538 return base64Token.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
539 };
540
541 /**
542 * Tests whether we are running on Mac. 519 * Tests whether we are running on Mac.
543 * 520 *
544 * @return {boolean} True if the platform is Mac. 521 * @return {boolean} True if the platform is Mac.
545 */ 522 */
546 remoting.platformIsMac = function() { 523 remoting.platformIsMac = function() {
547 return navigator.platform.indexOf('Mac') != -1; 524 return navigator.platform.indexOf('Mac') != -1;
548 } 525 }
549 526
550 /** 527 /**
551 * Tests whether we are running on Windows. 528 * Tests whether we are running on Windows.
(...skipping 16 matching lines...) Expand all
568 } 545 }
569 546
570 /** 547 /**
571 * Tests whether we are running on ChromeOS. 548 * Tests whether we are running on ChromeOS.
572 * 549 *
573 * @return {boolean} True if the platform is ChromeOS. 550 * @return {boolean} True if the platform is ChromeOS.
574 */ 551 */
575 remoting.platformIsChromeOS = function() { 552 remoting.platformIsChromeOS = function() {
576 return navigator.userAgent.match(/\bCrOS\b/) != null; 553 return navigator.userAgent.match(/\bCrOS\b/) != null;
577 } 554 }
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/oauth2_api.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