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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « main.cc ('k') | no next file » | 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) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS 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 * Namespace object for the client side code. 6 * Namespace object for the client side code.
7 */ 7 */
8 var client = new Object(); 8 var client = new Object();
9 9
10 /** 10 /**
11 * Port to contact the policy's callback server. 11 * Port to contact the policy's callback server.
12 */ 12 */
13 client.policyCallbackPort = 5199; 13 client.policyCallbackPort = 5199;
14 14
15 /** 15 /**
16 * Initialize the client. 16 * Initialize the client.
17 */ 17 */
18 client.onLoad = 18 client.onLoad =
19 function onLoad() { 19 function onLoad() {
20 client.modalShade = document.getElementById('modal-shade'); 20 client.modalShade = document.getElementById('modal-shade');
21 client.loadManifest(); 21 client.loadManifest();
22 }; 22 };
23 23
24 client.onManifestLoaded = 24 client.onManifestLoaded =
25 function onManifestLoaded() { 25 function onManifestLoaded() {
26 client.loadSessionId();
27 }
28
29 client.onSessionIdLoaded =
30 function onSessionIdLoaded() {
26 client.loadInfo(); 31 client.loadInfo();
27 } 32 }
28 33
29 /** 34 /**
30 * Called when client.initPkcs11() completes successfully. 35 * Called when client.initPkcs11() completes successfully.
31 */ 36 */
32 client.onPkcs11Ready = 37 client.onPkcs11Ready =
33 function onPkcs11Ready() { 38 function onPkcs11Ready() {
34 client.loadTokens(); 39 client.loadTokens();
35 client.loadCertificates(); 40 client.loadCertificates();
(...skipping 27 matching lines...) Expand all
63 function getURL(url) { 68 function getURL(url) {
64 if (typeof 'chrome' != undefined && chrome.extension) 69 if (typeof 'chrome' != undefined && chrome.extension)
65 return chrome.extension.getURL(url); 70 return chrome.extension.getURL(url);
66 71
67 return url; 72 return url;
68 }; 73 };
69 74
70 /** 75 /**
71 * Load the manifest.json file for this extension. 76 * Load the manifest.json file for this extension.
72 * 77 *
73 * Once it loads, set the title of the options page to match.
74 */ 78 */
75 client.loadManifest = 79 client.loadManifest =
76 function loadManifest() { 80 function loadManifest() {
77 var xhr = new XMLHttpRequest(); 81 var xhr = new XMLHttpRequest();
78 xhr.onreadystatechange = function () { 82 xhr.onreadystatechange = function () {
79 if (this.readyState != 4) 83 if (this.readyState != 4)
80 return; 84 return;
81 85
82 if (this.status == 0) { 86 if (this.status == 0) {
83 // Status is 0 rather than 200 for this. I assume that's because we're 87 // Status is 0 rather than 200 for this. I assume that's because we're
84 // loading from the chrome-extension: scheme, rather than a real 88 // loading from the chrome-extension: scheme, rather than a real
85 // web server. 89 // web server.
86 client.manifest = JSON.parse(this.responseText); 90 client.manifest = JSON.parse(this.responseText);
87 console.log('manifest: ' + this.responseText); 91 console.log('manifest: ' + this.responseText);
88 client.onManifestLoaded(); 92 client.onManifestLoaded();
89 } 93 }
90 }; 94 };
91 95
92 xhr.open('GET', client.getURL('manifest.json')); 96 xhr.open('GET', client.getURL('manifest.json'));
93 xhr.send(); 97 xhr.send();
94 }; 98 };
95 99
96 /** 100 /**
101 * Load the session-id.json file for this session of entd.
102 *
103 */
104 client.loadSessionId =
105 function loadSessionId() {
106 var xhr = new XMLHttpRequest();
107 xhr.onreadystatechange = function () {
108 if (this.readyState != 4)
109 return;
110
111 if (this.status == 0) {
112 // Status is 0 rather than 200 for this. I assume that's because we're
113 // loading from the chrome-extension: scheme, rather than a real
114 // web server.
115 if (this.responseText != "") {
116 client.session_id = JSON.parse(this.responseText);
117 } else {
118 // Assume an old Chrome OS is being used with this extension.
119 console.log('no session-id.json - old chrome os?');
120 client.session_id = { session_id: '' }
121 }
122 console.log('session_id: ' + this.responseText);
123 client.onSessionIdLoaded();
124 }
125 };
126
127 xhr.open('GET', client.getURL('session-id.json'));
128 xhr.send();
129 };
130
131 /**
97 * Load the basic information from the enterprise daemon. 132 * Load the basic information from the enterprise daemon.
98 * 133 *
99 * This invokes cb:info and populates the user interface with the results. 134 * This invokes cb:info and populates the user interface with the results.
100 */ 135 */
101 client.loadInfo = 136 client.loadInfo =
102 function loadInfo() { 137 function loadInfo() {
103 var daemonError = false; 138 var daemonError = false;
104 var pkcs11Error = false; 139 var pkcs11Error = false;
105 var tpmError = false; 140 var tpmError = false;
106 141
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 1162
1128 param.xhrStatus = xhr.status; 1163 param.xhrStatus = xhr.status;
1129 if (typeof oncomplete == "function") 1164 if (typeof oncomplete == "function")
1130 oncomplete(param); 1165 oncomplete(param);
1131 }; 1166 };
1132 1167
1133 xhr.open('POST', 'http://127.0.0.1:' + client.policyCallbackPort + 1168 xhr.open('POST', 'http://127.0.0.1:' + client.policyCallbackPort +
1134 '/dispatch'); 1169 '/dispatch');
1135 xhr.setRequestHeader('X-Entd-Request', 1170 xhr.setRequestHeader('X-Entd-Request',
1136 client.manifest.requestHeaderValue || 'magic'); 1171 client.manifest.requestHeaderValue || 'magic');
1172 xhr.setRequestHeader('X-Entd-Session-Id', client.session_id.session_id);
1137 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 1173 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
1138 xhr.send(JSON.stringify({'function': name, 'argument': arg})); 1174 xhr.send(JSON.stringify({'function': name, 'argument': arg}));
1139 }; 1175 };
1140 1176
1141 /** 1177 /**
1142 * client.CallbackSuccess constructor. 1178 * client.CallbackSuccess constructor.
1143 * 1179 *
1144 * An instance of this class holds the return value of a successful policy 1180 * An instance of this class holds the return value of a successful policy
1145 * callback. The data property of this object will contain the return 1181 * callback. The data property of this object will contain the return
1146 * value of the callback. 1182 * value of the callback.
(...skipping 30 matching lines...) Expand all
1177 * @param {string} name The name of the callback that returned this data. 1213 * @param {string} name The name of the callback that returned this data.
1178 * @param {Object} arg The argument object originally passed to the callback. 1214 * @param {Object} arg The argument object originally passed to the callback.
1179 * @param {Object} data The data returned by the callback. 1215 * @param {Object} data The data returned by the callback.
1180 */ 1216 */
1181 client.CallbackError = 1217 client.CallbackError =
1182 function CallbackError(name, arg, data) { 1218 function CallbackError(name, arg, data) {
1183 this.init_(name, arg, data); 1219 this.init_(name, arg, data);
1184 }; 1220 };
1185 1221
1186 client.CallbackError.prototype.init_ = client.CallbackSuccess.prototype.init_; 1222 client.CallbackError.prototype.init_ = client.CallbackSuccess.prototype.init_;
OLDNEW
« 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