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

Side by Side Diff: remoting/webapp/base/js/base.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: 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 * A module that contains basic utility components and methods for the 7 * A module that contains basic utility components and methods for the
8 * chromoting project 8 * chromoting project
9 * 9 *
10 */ 10 */
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 /** 415 /**
416 * Decodes UTF-8 string from ArrayBuffer. 416 * Decodes UTF-8 string from ArrayBuffer.
417 * 417 *
418 * @param {ArrayBuffer} buffer 418 * @param {ArrayBuffer} buffer
419 * @return {string} 419 * @return {string}
420 */ 420 */
421 base.decodeUtf8 = function(buffer) { 421 base.decodeUtf8 = function(buffer) {
422 return decodeURIComponent( 422 return decodeURIComponent(
423 escape(String.fromCharCode.apply(null, new Uint8Array(buffer)))); 423 escape(String.fromCharCode.apply(null, new Uint8Array(buffer))));
424 } 424 }
425
426 /**
427 * Generate a nonce, to be used as an xsrf protection token.
428 *
429 * @return {string} A URL-Safe Base64-encoded 128-bit random value. */
430 base.generateXsrfToken = function() {
431 var random = new Uint8Array(16);
432 window.crypto.getRandomValues(random);
433 var base64Token = window.btoa(String.fromCharCode.apply(null, random));
434 return base64Token.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
435 };
436
437 /**
438 * @param {string} jsonString A JSON-encoded string.
439 * @return {*} The decoded object, or undefined if the string cannot be parsed.
440 */
441 function jsonParseSafe(jsonString) {
Jamie 2014/10/29 01:35:59 This should be moved into the base namespace, but
kelvinp 2014/10/29 20:28:54 I think it may be easier to fix it up as part of t
Jamie 2014/10/30 19:38:25 In retrospect, I agree. Done.
442 try {
443 return JSON.parse(jsonString);
444 } catch (err) {
445 return undefined;
446 }
447 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698