1 // Copyright (c) 2012 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.
5 cr.define('options', function() {
6 var OptionsPage = options.OptionsPage;
7 var Page = cr.ui.pageManager.Page;
8 var PageManager = cr.ui.pageManager.PageManager;
10 /////////////////////////////////////////////////////////////////////////////
11 // CertificateManagerTab class:
15 * @param {!string} id The id of this tab.
16 * @param {boolean} isKiosk True if dialog is shown during CrOS kiosk launch.
18 function CertificateManagerTab(id, isKiosk) {
19 this.tree = $(id + '-tree');
21 options.CertificatesTree.decorate(this.tree);
22 this.tree.addEventListener('change',
23 this.handleCertificatesTreeChange_.bind(this));
27 this.viewButton = $(id + '-view');
28 this.viewButton.onclick = function(e) {
29 var selected = tree.selectedItem;
30 chrome.send('viewCertificate', [selected.data.id]);
33 this.editButton = $(id + '-edit');
34 if (this.editButton !== null) {
35 if (id == 'serverCertsTab') {
36 this.editButton.onclick = function(e) {
37 var selected = tree.selectedItem;
38 chrome.send('editServerCertificate', [selected.data.id]);
40 } else if (id == 'caCertsTab') {
41 this.editButton.onclick = function(e) {
42 var data = tree.selectedItem.data;
43 CertificateEditCaTrustOverlay.show(data.id, data.name);
48 this.backupButton = $(id + '-backup');
49 if (this.backupButton !== null) {
50 if (id == 'personalCertsTab' && isKiosk) {
51 this.backupButton.hidden = true;
53 this.backupButton.onclick = function(e) {
54 var selected = tree.selectedItem;
55 chrome.send('exportPersonalCertificate', [selected.data.id]);
60 this.backupAllButton = $(id + '-backup-all');
61 if (this.backupAllButton !== null) {
62 if (id == 'personalCertsTab' && isKiosk) {
63 this.backupAllButton.hidden = true;
65 this.backupAllButton.onclick = function(e) {
66 chrome.send('exportAllPersonalCertificates');
71 this.importButton = $(id + '-import');
72 if (this.importButton !== null) {
73 if (id == 'personalCertsTab') {
75 this.importButton.hidden = true;
77 this.importButton.onclick = function(e) {
78 chrome.send('importPersonalCertificate', [false]);
81 } else if (id == 'serverCertsTab') {
82 this.importButton.onclick = function(e) {
83 chrome.send('importServerCertificate');
85 } else if (id == 'caCertsTab') {
86 this.importButton.onclick = function(e) {
87 chrome.send('importCaCertificate');
92 this.importAndBindButton = $(id + '-import-and-bind');
93 if (this.importAndBindButton !== null) {
94 if (id == 'personalCertsTab') {
95 this.importAndBindButton.onclick = function(e) {
96 chrome.send('importPersonalCertificate', [true]);
101 this.exportButton = $(id + '-export');
102 if (this.exportButton !== null) {
103 if (id == 'personalCertsTab' && isKiosk) {
104 this.exportButton.hidden = true;
106 this.exportButton.onclick = function(e) {
107 var selected = tree.selectedItem;
108 chrome.send('exportCertificate', [selected.data.id]);
113 this.deleteButton = $(id + '-delete');
114 this.deleteButton.onclick = function(e) {
115 var data = tree.selectedItem.data;
117 loadTimeData.getStringF(id + 'DeleteConfirm', data.name),
118 loadTimeData.getString(id + 'DeleteImpact'),
119 loadTimeData.getString('ok'),
120 loadTimeData.getString('cancel'),
122 tree.selectedItem = null;
123 chrome.send('deleteCertificate', [data.id]);
128 CertificateManagerTab.prototype = {
130 * Update button state.
132 * @param {!Object} data The data of the selected item.
134 updateButtonState: function(data) {
135 var isCert = !!data && data.isCert;
136 var readOnly = !!data && data.readonly;
137 var extractable = !!data && data.extractable;
138 var hasChildren = this.tree.items.length > 0;
139 var isPolicy = !!data && data.policy;
140 this.viewButton.disabled = !isCert;
141 if (this.editButton !== null)
142 this.editButton.disabled = !isCert || isPolicy;
143 if (this.backupButton !== null)
144 this.backupButton.disabled = !isCert || !extractable;
145 if (this.backupAllButton !== null)
146 this.backupAllButton.disabled = !hasChildren;
147 if (this.exportButton !== null)
148 this.exportButton.disabled = !isCert;
149 this.deleteButton.disabled = !isCert || readOnly || isPolicy;
153 * Handles certificate tree selection change.
155 * @param {!Event} e The change event object.
157 handleCertificatesTreeChange_: function(e) {
159 if (this.tree.selectedItem)
160 data = this.tree.selectedItem.data;
162 this.updateButtonState(data);
166 /////////////////////////////////////////////////////////////////////////////
167 // CertificateManager class:
170 * Encapsulated handling of ChromeOS accounts options page.
173 function CertificateManager(model) {
174 Page.call(this, 'certificates',
175 loadTimeData.getString('certificateManagerPageTabTitle'),
176 'certificateManagerPage');
179 cr.addSingletonGetter(CertificateManager);
181 CertificateManager.prototype = {
182 __proto__: Page.prototype,
185 initializePage: function(isKiosk) {
186 Page.prototype.initializePage.call(this);
188 this.personalTab = new CertificateManagerTab('personalCertsTab',
190 this.serverTab = new CertificateManagerTab('serverCertsTab', !!isKiosk);
191 this.caTab = new CertificateManagerTab('caCertsTab', !!isKiosk);
192 this.otherTab = new CertificateManagerTab('otherCertsTab', !!isKiosk);
194 this.addEventListener('visibleChange', this.handleVisibleChange_);
196 $('certificate-confirm').onclick = function() {
197 PageManager.closeOverlay();
204 * Handler for Page's visible property change event.
206 * @param {Event} e Property change event.
208 handleVisibleChange_: function(e) {
209 if (!this.initalized_ && this.visible) {
210 this.initalized_ = true;
211 OptionsPage.showTab($('personal-certs-nav-tab'));
212 chrome.send('populateCertificateManager');
217 // CertificateManagerHandler callbacks.
218 CertificateManager.onPopulateTree = function(args) {
219 $(args[0]).populate(args[1]);
222 CertificateManager.exportPersonalAskPassword = function(args) {
223 CertificateBackupOverlay.show();
226 CertificateManager.importPersonalAskPassword = function(args) {
227 CertificateRestoreOverlay.show();
230 CertificateManager.onModelReady = function(userDbAvailable,
232 if (!userDbAvailable)
235 $('personalCertsTab-import-and-bind').disabled = false;
236 $('personalCertsTab-import').disabled = false;
237 $('serverCertsTab-import').disabled = false;
238 $('caCertsTab-import').disabled = false;
243 CertificateManagerTab: CertificateManagerTab,
244 CertificateManager: CertificateManager