| OLD | NEW |
| 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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 * | 462 * |
| 463 * @return {string} A URL-Safe Base64-encoded 128-bit random value. */ | 463 * @return {string} A URL-Safe Base64-encoded 128-bit random value. */ |
| 464 base.generateXsrfToken = function() { | 464 base.generateXsrfToken = function() { |
| 465 var random = new Uint8Array(16); | 465 var random = new Uint8Array(16); |
| 466 window.crypto.getRandomValues(random); | 466 window.crypto.getRandomValues(random); |
| 467 var base64Token = window.btoa(String.fromCharCode.apply(null, random)); | 467 var base64Token = window.btoa(String.fromCharCode.apply(null, random)); |
| 468 return base64Token.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); | 468 return base64Token.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ''); |
| 469 }; | 469 }; |
| 470 | 470 |
| 471 /** | 471 /** |
| 472 * @return {Object.<string, string>} The URL parameters. |
| 473 */ |
| 474 base.getUrlParameters = function() { |
| 475 var result = {}; |
| 476 var parts = window.location.search.substring(1).split('&'); |
| 477 for (var i = 0; i < parts.length; i++) { |
| 478 var pair = parts[i].split('='); |
| 479 result[pair[0]] = decodeURIComponent(pair[1]); |
| 480 } |
| 481 return result; |
| 482 } |
| 483 |
| 484 /** |
| 472 * @param {string} jsonString A JSON-encoded string. | 485 * @param {string} jsonString A JSON-encoded string. |
| 473 * @return {Object|undefined} The decoded object, or undefined if the string | 486 * @return {Object|undefined} The decoded object, or undefined if the string |
| 474 * cannot be parsed. | 487 * cannot be parsed. |
| 475 */ | 488 */ |
| 476 base.jsonParseSafe = function(jsonString) { | 489 base.jsonParseSafe = function(jsonString) { |
| 477 try { | 490 try { |
| 478 return /** @type {Object} */ (JSON.parse(jsonString)); | 491 return /** @type {Object} */ (JSON.parse(jsonString)); |
| 479 } catch (err) { | 492 } catch (err) { |
| 480 return undefined; | 493 return undefined; |
| 481 } | 494 } |
| 482 } | 495 } |
| OLD | NEW |