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

Side by Side Diff: chrome/browser/resources/options/certificate_manager.js

Issue 9814030: get rid of old options pages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixes Created 8 years, 9 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('options', function() {
6
7 var OptionsPage = options.OptionsPage;
8
9 /////////////////////////////////////////////////////////////////////////////
10 // CertificateManagerTab class:
11
12 /**
13 * blah
14 * @param {!string} id The id of this tab.
15 */
16 function CertificateManagerTab(id) {
17 this.tree = $(id + '-tree');
18
19 options.CertificatesTree.decorate(this.tree);
20 this.tree.addEventListener('change',
21 this.handleCertificatesTreeChange_.bind(this));
22
23 var tree = this.tree;
24
25 this.viewButton = $(id + '-view');
26 this.viewButton.onclick = function(e) {
27 var selected = tree.selectedItem;
28 chrome.send('viewCertificate', [selected.data.id]);
29 }
30
31 this.editButton = $(id + '-edit');
32 if (this.editButton !== null) {
33 if (id == 'serverCertsTab') {
34 this.editButton.onclick = function(e) {
35 var selected = tree.selectedItem;
36 chrome.send('editServerCertificate', [selected.data.id]);
37 }
38 } else if (id == 'caCertsTab') {
39 this.editButton.onclick = function(e) {
40 var data = tree.selectedItem.data;
41 CertificateEditCaTrustOverlay.show(data.id, data.name);
42 }
43 }
44 }
45
46 this.backupButton = $(id + '-backup');
47 if (this.backupButton !== null) {
48 this.backupButton.onclick = function(e) {
49 var selected = tree.selectedItem;
50 chrome.send('exportPersonalCertificate', [selected.data.id]);
51 }
52 }
53
54 this.backupAllButton = $(id + '-backup-all');
55 if (this.backupAllButton !== null) {
56 this.backupAllButton.onclick = function(e) {
57 chrome.send('exportAllPersonalCertificates', []);
58 }
59 }
60
61 this.importButton = $(id + '-import');
62 if (this.importButton !== null) {
63 if (id == 'personalCertsTab') {
64 this.importButton.onclick = function(e) {
65 chrome.send('importPersonalCertificate', [false]);
66 }
67 } else if (id == 'serverCertsTab') {
68 this.importButton.onclick = function(e) {
69 chrome.send('importServerCertificate', []);
70 }
71 } else if (id == 'caCertsTab') {
72 this.importButton.onclick = function(e) {
73 chrome.send('importCaCertificate', []);
74 }
75 }
76 }
77
78 this.importAndBindButton = $(id + '-import-and-bind');
79 if (this.importAndBindButton !== null) {
80 if (id == 'personalCertsTab') {
81 this.importAndBindButton.onclick = function(e) {
82 chrome.send('importPersonalCertificate', [true]);
83 }
84 }
85 }
86
87 this.exportButton = $(id + '-export');
88 if (this.exportButton !== null) {
89 this.exportButton.onclick = function(e) {
90 var selected = tree.selectedItem;
91 chrome.send('exportCertificate', [selected.data.id]);
92 }
93 }
94
95 this.deleteButton = $(id + '-delete');
96 this.deleteButton.onclick = function(e) {
97 var data = tree.selectedItem.data;
98 AlertOverlay.show(
99 localStrings.getStringF(id + 'DeleteConfirm', data.name),
100 localStrings.getString(id + 'DeleteImpact'),
101 localStrings.getString('ok'),
102 localStrings.getString('cancel'),
103 function() {
104 tree.selectedItem = null;
105 chrome.send('deleteCertificate', [data.id]);
106 });
107 }
108 }
109
110 CertificateManagerTab.prototype = {
111
112 /**
113 * Update button state.
114 * @private
115 * @param {!Object} data The data of the selected item.
116 */
117 updateButtonState: function(data) {
118 var isCert = !!data && data.id.substr(0, 5) == 'cert-';
119 var readOnly = !!data && data.readonly;
120 var hasChildren = this.tree.items.length > 0;
121 this.viewButton.disabled = !isCert;
122 if (this.editButton !== null)
123 this.editButton.disabled = !isCert;
124 if (this.backupButton !== null)
125 this.backupButton.disabled = !isCert;
126 if (this.backupAllButton !== null)
127 this.backupAllButton.disabled = !hasChildren;
128 if (this.exportButton !== null)
129 this.exportButton.disabled = !isCert;
130 this.deleteButton.disabled = !isCert || readOnly;
131 },
132
133 /**
134 * Handles certificate tree selection change.
135 * @private
136 * @param {!Event} e The change event object.
137 */
138 handleCertificatesTreeChange_: function(e) {
139 var data = null;
140 if (this.tree.selectedItem) {
141 data = this.tree.selectedItem.data;
142 }
143
144 this.updateButtonState(data);
145 },
146
147 }
148
149 // TODO(xiyuan): Use notification from backend instead of polling.
150 // TPM token check polling timer.
151 var tpmPollingTimer;
152
153 // Initiate tpm token check if needed.
154 function checkTpmToken() {
155 var importAndBindButton = $('personalCertsTab-import-and-bind');
156
157 if (importAndBindButton && importAndBindButton.disabled)
158 chrome.send('checkTpmTokenReady');
159 }
160
161 // Stop tpm polling timer.
162 function stopTpmTokenCheckPolling() {
163 if (tpmPollingTimer) {
164 window.clearTimeout(tpmPollingTimer);
165 tpmPollingTimer = undefined;
166 }
167 }
168
169 /////////////////////////////////////////////////////////////////////////////
170 // CertificateManager class:
171
172 /**
173 * Encapsulated handling of ChromeOS accounts options page.
174 * @constructor
175 */
176 function CertificateManager(model) {
177 OptionsPage.call(this, 'certificates',
178 templateData.certificateManagerPageTabTitle,
179 'certificateManagerPage');
180 }
181
182 cr.addSingletonGetter(CertificateManager);
183
184 CertificateManager.prototype = {
185 __proto__: OptionsPage.prototype,
186
187 initializePage: function() {
188 OptionsPage.prototype.initializePage.call(this);
189
190 this.personalTab = new CertificateManagerTab('personalCertsTab');
191 this.serverTab = new CertificateManagerTab('serverCertsTab');
192 this.caTab = new CertificateManagerTab('caCertsTab');
193 this.otherTab = new CertificateManagerTab('otherCertsTab');
194
195 this.addEventListener('visibleChange', this.handleVisibleChange_);
196 },
197
198 initalized_: false,
199
200 /**
201 * Handler for OptionsPage's visible property change event.
202 * @private
203 * @param {Event} e Property change event.
204 */
205 handleVisibleChange_: function(e) {
206 if (!this.initalized_ && this.visible) {
207 this.initalized_ = true;
208 OptionsPage.showTab($('personal-certs-nav-tab'));
209 chrome.send('populateCertificateManager');
210 }
211
212 if (cr.isChromeOS) {
213 // Ensure TPM token check on visible and stop polling when hidden.
214 if (this.visible)
215 checkTpmToken();
216 else
217 stopTpmTokenCheckPolling();
218 }
219 }
220 };
221
222 // CertificateManagerHandler callbacks.
223 CertificateManager.onPopulateTree = function(args) {
224 $(args[0]).populate(args[1]);
225 };
226
227 CertificateManager.exportPersonalAskPassword = function(args) {
228 CertificateBackupOverlay.show();
229 };
230
231 CertificateManager.importPersonalAskPassword = function(args) {
232 CertificateRestoreOverlay.show();
233 };
234
235 CertificateManager.onCheckTpmTokenReady = function(ready) {
236 var importAndBindButton = $('personalCertsTab-import-and-bind');
237 if (importAndBindButton) {
238 importAndBindButton.disabled = !ready;
239
240 // Check again after 5 seconds if Tpm is not ready and certificate manager
241 // is still visible.
242 if (!ready && CertificateManager.getInstance().visible)
243 tpmPollingTimer = window.setTimeout(checkTpmToken, 5000);
244 }
245 };
246
247 // Export
248 return {
249 CertificateManagerTab: CertificateManagerTab,
250 CertificateManager: CertificateManager
251 };
252
253 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698