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

Unified Diff: reference_extension/client.js

Issue 6874035: entd: require a per-entd-invocation session id in every request (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/entd.git@master
Patch Set: Allow a developer switch to disable session id' Created 9 years, 8 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 | « main.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: reference_extension/client.js
diff --git a/reference_extension/client.js b/reference_extension/client.js
index bab4f056e9b1c423615ba608dc696d9e6d778cfa..8bfdd17fbbff7bda7145ee964aeced166fd9c589 100644
--- a/reference_extension/client.js
+++ b/reference_extension/client.js
@@ -23,6 +23,11 @@ function onLoad() {
client.onManifestLoaded =
function onManifestLoaded() {
+ client.loadSessionId();
+}
+
+client.onSessionIdLoaded =
+function onSessionIdLoaded() {
client.loadInfo();
}
@@ -70,7 +75,6 @@ function getURL(url) {
/**
* Load the manifest.json file for this extension.
*
- * Once it loads, set the title of the options page to match.
*/
client.loadManifest =
function loadManifest() {
@@ -94,6 +98,37 @@ function loadManifest() {
};
/**
+ * Load the session-id.json file for this session of entd.
+ *
+ */
+client.loadSessionId =
+function loadSessionId() {
+ var xhr = new XMLHttpRequest();
+ xhr.onreadystatechange = function () {
+ if (this.readyState != 4)
+ return;
+
+ if (this.status == 0) {
+ // Status is 0 rather than 200 for this. I assume that's because we're
+ // loading from the chrome-extension: scheme, rather than a real
+ // web server.
+ if (this.responseText != "") {
+ client.session_id = JSON.parse(this.responseText);
+ } else {
+ // Assume an old Chrome OS is being used with this extension.
+ console.log('no session-id.json - old chrome os?');
+ client.session_id = { session_id: '' }
+ }
+ console.log('session_id: ' + this.responseText);
+ client.onSessionIdLoaded();
+ }
+ };
+
+ xhr.open('GET', client.getURL('session-id.json'));
+ xhr.send();
+};
+
+/**
* Load the basic information from the enterprise daemon.
*
* This invokes cb:info and populates the user interface with the results.
@@ -1134,6 +1169,7 @@ function invokePolicyCallback(name, arg, oncomplete) {
'/dispatch');
xhr.setRequestHeader('X-Entd-Request',
client.manifest.requestHeaderValue || 'magic');
+ xhr.setRequestHeader('X-Entd-Session-Id', client.session_id.session_id);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.send(JSON.stringify({'function': name, 'argument': arg}));
};
« no previous file with comments | « main.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698