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

Side by Side Diff: reference_extension/client.js

Issue 3107031: entd: Restart on token init failure (Closed) Base URL: http://src.chromium.org/git/entd.git
Patch Set: Created 10 years, 4 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
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 /**
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 function getLastLogLine(log) { 42 function getLastLogLine(log) {
43 var ary = log.split(/\r?\n/); 43 var ary = log.split(/\r?\n/);
44 for (var i = 1; i < ary.length; ++i) { 44 for (var i = 1; i < ary.length; ++i) {
45 if (ary[ary.length - i]) 45 if (ary[ary.length - i])
46 return ary[ary.length - i]; 46 return ary[ary.length - i];
47 } 47 }
48 48
49 return ''; 49 return '';
50 } 50 }
51 51
52 client.reload =
53 function reload() {
54 document.location.href = document.location.pathname + "?reload";
55 }
56
52 /** 57 /**
53 * Get a url to a resource inside the extension. 58 * Get a url to a resource inside the extension.
54 * 59 *
55 * @param {string} url The path portion of the URL you are interested in. 60 * @param {string} url The path portion of the URL you are interested in.
56 */ 61 */
57 client.getURL = 62 client.getURL =
58 function getURL(url) { 63 function getURL(url) {
59 if (typeof 'chrome' != undefined && chrome.extension) 64 if (typeof 'chrome' != undefined && chrome.extension)
60 return chrome.extension.getURL(url); 65 return chrome.extension.getURL(url);
61 66
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } 161 }
157 } 162 }
158 163
159 } else { 164 } else {
160 $("#entd-status"). 165 $("#entd-status").
161 text('Waiting...'). 166 text('Waiting...').
162 attr('status', 'red'); 167 attr('status', 'red');
163 168
164 if (!daemonError) { 169 if (!daemonError) {
165 daemonError = true; 170 daemonError = true;
166 client.showError( 171 var msg;
167 'The Enterprise Daemon has not started. You must log out or ' + 172
168 'reboot after installing the policy. If the problem persists, ' + 173 if (document.location.search.match(/reload/)) {
169 'try clearing your TPM in the BIOS.', 'Error', 174 msg = 'Please wait while the Enterprise Daemon restarts.';
170 { details: JSON.stringify(retval)} ); 175 } else {
176 msg = 'The Enterprise Daemon has not started. You must log out or ' +
177 'reboot after installing the policy. If the problem persists, ' +
178 'try clearing your TPM in the BIOS.';
179 }
180
181 client.showError(msg, 'Error', { details: JSON.stringify(retval) } );
171 } 182 }
172 } 183 }
173 184
174 if (ready) { 185 if (ready) {
175 if (retval.data.browserPolicyChanged) { 186 if (retval.data.browserPolicyChanged) {
176 $('#entd-message'). 187 $('#entd-message').
177 text('Your browser settings have been changed, you ' + 188 text('Your browser settings have been changed, you ' +
178 'must log out before they take effect.'). 189 'must log out before they take effect.').
179 attr('status', 'red'); 190 attr('status', 'red');
180 } else { 191 } else {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 client.invokePolicyCallback('setUserPin', { slotId: token.slotId }, 373 client.invokePolicyCallback('setUserPin', { slotId: token.slotId },
363 onerror); 374 onerror);
364 } else if (token.state == 'stop:ready') { 375 } else if (token.state == 'stop:ready') {
365 // User pin is set, all done. 376 // User pin is set, all done.
366 $('.status.token-user').attr('status', 'green'); 377 $('.status.token-user').attr('status', 'green');
367 client.showSuccess('The PKCS#11 token has been successfully ' + 378 client.showSuccess('The PKCS#11 token has been successfully ' +
368 'initialized. You may now install certificates.', 379 'initialized. You may now install certificates.',
369 'Token Initialized'); 380 'Token Initialized');
370 return; 381 return;
371 } else if (token.state == 'stop:error') { 382 } else if (token.state == 'stop:error') {
372 client.showTokenDetails(token); 383 // If the token failed to initialize, it might be left in a broken
384 // state. This can happen if the hardware times out. We ask entd
385 // to restart, because it should be able to detect the broken token
386 // and delete it.
387 client.invokePolicyCallback("restart");
388 client.showTokenDetails(token, { okCallback: client.reload() });
373 return; 389 return;
374 } 390 }
375 391
376 setTimeout(function () { 392 setTimeout(function () {
377 client.invokePolicyCallback('listTokens', null, 393 client.invokePolicyCallback('listTokens', null,
378 oncomplete_list); 394 oncomplete_list);
379 }, 1000); 395 }, 1000);
380 }; 396 };
381 397
382 if (!force && token.state == 'stop:ready') { 398 if (!force && token.state == 'stop:ready') {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 attr('status', 'error'); 698 attr('status', 'error');
683 } 699 }
684 700
685 /** 701 /**
686 * Show the details for a given token in a modal dialog box. 702 * Show the details for a given token in a modal dialog box.
687 * 703 *
688 * Shows the token details in a modal Error, Success, or Alert box, depending 704 * Shows the token details in a modal Error, Success, or Alert box, depending
689 * on the state of the token. 705 * on the state of the token.
690 */ 706 */
691 client.showTokenDetails = 707 client.showTokenDetails =
692 function showTokenDetails(token) { 708 function showTokenDetails(token, options) {
693 var options = { details: '' }; 709 var options = options || {};
710
711 options.details = '';
694 if (token.log) 712 if (token.log)
695 options.details += token.log + '\n'; 713 options.details += token.log + '\n';
696 714
697 options.details += 'current state: ' + token.state + 715 options.details += 'current state: ' + token.state +
698 '\nslotId: ' + token.slotId + '\nflags: '; 716 '\nslotId: ' + token.slotId + '\nflags: ';
699 717
700 for (var key in token.flags) { 718 for (var key in token.flags) {
701 if (token.flags[key]) 719 if (token.flags[key])
702 options.details += '\n* ' + key; 720 options.details += '\n* ' + key;
703 } 721 }
704 722
705 if (token.state == 'stop:error') { 723 if (token.state == 'stop:error') {
706 var msg = client.getLastLogLine(token.log); 724 var msg = client.getLastLogLine(token.log);
707 if (!msg) 725 if (!msg)
708 msg = 'There was an error initializing your token'; 726 msg = 'There was an error initializing your token.';
727
709 client.showError(msg, 'Error', options); 728 client.showError(msg, 'Error', options);
710 return; 729 return;
711 } 730 }
712 731
713 if (token.state == 'stop:ready') { 732 if (token.state == 'stop:ready') {
714 client.showSuccess('Token is initialized', 'Token Information', options); 733 client.showSuccess('Token is initialized', 'Token Information', options);
715 return; 734 return;
716 } 735 }
717 736
718 client.showAlert('Token is not initialized: ' + token.state, 737 client.showAlert('Token is not initialized: ' + token.state,
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 JSON.stringify(retval)); 1101 JSON.stringify(retval));
1083 } 1102 }
1084 } else { 1103 } else {
1085 param = new client.CallbackError( 1104 param = new client.CallbackError(
1086 name, arg, 1105 name, arg,
1087 { msg: 'Error invoking callback: ' + name + ': http status: ' + 1106 { msg: 'Error invoking callback: ' + name + ': http status: ' +
1088 this.status } ); 1107 this.status } );
1089 } 1108 }
1090 1109
1091 param.xhrStatus = xhr.status; 1110 param.xhrStatus = xhr.status;
1092 oncomplete(param); 1111 if (typeof oncomplete == "function")
1112 oncomplete(param);
1093 }; 1113 };
1094 1114
1095 xhr.open('POST', 'http://127.0.0.1:' + client.policyCallbackPort + 1115 xhr.open('POST', 'http://127.0.0.1:' + client.policyCallbackPort +
1096 '/dispatch'); 1116 '/dispatch');
1097 xhr.setRequestHeader('X-Entd-Request', 1117 xhr.setRequestHeader('X-Entd-Request',
1098 client.manifest.requestHeaderValue || 'magic'); 1118 client.manifest.requestHeaderValue || 'magic');
1099 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8'); 1119 xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
1100 xhr.send(JSON.stringify({'function': name, 'argument': arg})); 1120 xhr.send(JSON.stringify({'function': name, 'argument': arg}));
1101 }; 1121 };
1102 1122
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 * @param {string} name The name of the callback that returned this data. 1159 * @param {string} name The name of the callback that returned this data.
1140 * @param {Object} arg The argument object originally passed to the callback. 1160 * @param {Object} arg The argument object originally passed to the callback.
1141 * @param {Object} data The data returned by the callback. 1161 * @param {Object} data The data returned by the callback.
1142 */ 1162 */
1143 client.CallbackError = 1163 client.CallbackError =
1144 function CallbackError(name, arg, data) { 1164 function CallbackError(name, arg, data) {
1145 this.init_(name, arg, data); 1165 this.init_(name, arg, data);
1146 }; 1166 };
1147 1167
1148 client.CallbackError.prototype.init_ = client.CallbackSuccess.prototype.init_; 1168 client.CallbackError.prototype.init_ = client.CallbackSuccess.prototype.init_;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698