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

Unified 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: Move jsonParseSafe into base namespace. Created 6 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/remoting_webapp_files.gypi ('k') | remoting/webapp/crd/js/client_plugin_impl.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/webapp/base/js/base.js
diff --git a/remoting/webapp/base/js/base.js b/remoting/webapp/base/js/base.js
index ee909bede327c38f7cac29fcca6f379d5c7ea42e..c337a7bd2019fd92f53beefd06222b5b2230f24c 100644
--- a/remoting/webapp/base/js/base.js
+++ b/remoting/webapp/base/js/base.js
@@ -422,3 +422,26 @@ base.decodeUtf8 = function(buffer) {
return decodeURIComponent(
escape(String.fromCharCode.apply(null, new Uint8Array(buffer))));
}
+
+/**
+ * Generate a nonce, to be used as an xsrf protection token.
+ *
+ * @return {string} A URL-Safe Base64-encoded 128-bit random value. */
+base.generateXsrfToken = function() {
+ var random = new Uint8Array(16);
+ window.crypto.getRandomValues(random);
+ var base64Token = window.btoa(String.fromCharCode.apply(null, random));
+ return base64Token.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
+};
+
+/**
+ * @param {string} jsonString A JSON-encoded string.
+ * @return {*} The decoded object, or undefined if the string cannot be parsed.
+ */
+base.jsonParseSafe = function(jsonString) {
+ try {
+ return JSON.parse(jsonString);
+ } catch (err) {
+ return undefined;
+ }
+}
« no previous file with comments | « remoting/remoting_webapp_files.gypi ('k') | remoting/webapp/crd/js/client_plugin_impl.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698