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.
19 function CertificateManagerTab(id
, isKiosk
) {
20 this.tree
= $(id
+ '-tree');
22 options
.CertificatesTree
.decorate(this.tree
);
23 this.tree
.addEventListener('change',
24 this.handleCertificatesTreeChange_
.bind(this));
28 this.viewButton
= $(id
+ '-view');
29 this.viewButton
.onclick = function(e
) {
30 var selected
= tree
.selectedItem
;
31 chrome
.send('viewCertificate', [selected
.data
.id
]);
34 this.editButton
= $(id
+ '-edit');
35 if (this.editButton
!== null) {
36 if (id
== 'serverCertsTab') {
37 this.editButton
.onclick = function(e
) {
38 var selected
= tree
.selectedItem
;
39 chrome
.send('editServerCertificate', [selected
.data
.id
]);
41 } else if (id
== 'caCertsTab') {
42 this.editButton
.onclick = function(e
) {
43 var data
= tree
.selectedItem
.data
;
44 CertificateEditCaTrustOverlay
.show(data
.id
, data
.name
);
49 this.backupButton
= $(id
+ '-backup');
50 if (this.backupButton
!== null) {
51 if (id
== 'personalCertsTab' && isKiosk
) {
52 this.backupButton
.hidden
= true;
54 this.backupButton
.onclick = function(e
) {
55 var selected
= tree
.selectedItem
;
56 chrome
.send('exportPersonalCertificate', [selected
.data
.id
]);
61 this.backupAllButton
= $(id
+ '-backup-all');
62 if (this.backupAllButton
!== null) {
63 if (id
== 'personalCertsTab' && isKiosk
) {
64 this.backupAllButton
.hidden
= true;
66 this.backupAllButton
.onclick = function(e
) {
67 chrome
.send('exportAllPersonalCertificates');
72 this.importButton
= $(id
+ '-import');
73 if (this.importButton
!== null) {
74 if (id
== 'personalCertsTab') {
76 this.importButton
.hidden
= true;
78 this.importButton
.onclick = function(e
) {
79 chrome
.send('importPersonalCertificate', [false]);
82 } else if (id
== 'serverCertsTab') {
83 this.importButton
.onclick = function(e
) {
84 chrome
.send('importServerCertificate');
86 } else if (id
== 'caCertsTab') {
87 this.importButton
.onclick = function(e
) {
88 chrome
.send('importCaCertificate');
93 this.importAndBindButton
= $(id
+ '-import-and-bind');
94 if (this.importAndBindButton
!== null) {
95 if (id
== 'personalCertsTab') {
96 this.importAndBindButton
.onclick = function(e
) {
97 chrome
.send('importPersonalCertificate', [true]);
102 this.exportButton
= $(id
+ '-export');
103 if (this.exportButton
!== null) {
104 if (id
== 'personalCertsTab' && isKiosk
) {
105 this.exportButton
.hidden
= true;
107 this.exportButton
.onclick = function(e
) {
108 var selected
= tree
.selectedItem
;
109 chrome
.send('exportCertificate', [selected
.data
.id
]);
114 this.deleteButton
= $(id
+ '-delete');
115 this.deleteButton
.onclick = function(e
) {
116 var data
= tree
.selectedItem
.data
;
118 loadTimeData
.getStringF(id
+ 'DeleteConfirm', data
.name
),
119 loadTimeData
.getString(id
+ 'DeleteImpact'),
120 loadTimeData
.getString('ok'),
121 loadTimeData
.getString('cancel'),
123 tree
.selectedItem
= null;
124 chrome
.send('deleteCertificate', [data
.id
]);
129 CertificateManagerTab
.prototype = {
131 * Update button state.
133 * @param {!Object} data The data of the selected item.
135 updateButtonState: function(data
) {
136 var isCert
= !!data
&& data
.isCert
;
137 var readOnly
= !!data
&& data
.readonly
;
138 var extractable
= !!data
&& data
.extractable
;
139 var hasChildren
= this.tree
.items
.length
> 0;
140 var isPolicy
= !!data
&& data
.policy
;
141 this.viewButton
.disabled
= !isCert
;
142 if (this.editButton
!== null)
143 this.editButton
.disabled
= !isCert
|| isPolicy
;
144 if (this.backupButton
!== null)
145 this.backupButton
.disabled
= !isCert
|| !extractable
;
146 if (this.backupAllButton
!== null)
147 this.backupAllButton
.disabled
= !hasChildren
;
148 if (this.exportButton
!== null)
149 this.exportButton
.disabled
= !isCert
;
150 this.deleteButton
.disabled
= !isCert
|| readOnly
|| isPolicy
;
154 * Handles certificate tree selection change.
156 * @param {!Event} e The change event object.
158 handleCertificatesTreeChange_: function(e
) {
160 if (this.tree
.selectedItem
)
161 data
= this.tree
.selectedItem
.data
;
163 this.updateButtonState(data
);
167 /////////////////////////////////////////////////////////////////////////////
168 // CertificateManager class:
171 * Encapsulated handling of ChromeOS accounts options page.
173 * @extends {cr.ui.pageManager.Page}
175 function CertificateManager(model
) {
176 Page
.call(this, 'certificates',
177 loadTimeData
.getString('certificateManagerPageTabTitle'),
178 'certificateManagerPage');
181 cr
.addSingletonGetter(CertificateManager
);
183 CertificateManager
.prototype = {
184 __proto__
: Page
.prototype,
187 initializePage: function(isKiosk
) {
188 Page
.prototype.initializePage
.call(this);
190 this.personalTab
= new CertificateManagerTab('personalCertsTab',
192 this.serverTab
= new CertificateManagerTab('serverCertsTab', !!isKiosk
);
193 this.caTab
= new CertificateManagerTab('caCertsTab', !!isKiosk
);
194 this.otherTab
= new CertificateManagerTab('otherCertsTab', !!isKiosk
);
196 this.addEventListener('visibleChange', this.handleVisibleChange_
);
198 $('certificate-confirm').onclick = function() {
199 PageManager
.closeOverlay();
206 * Handler for Page's visible property change event.
208 * @param {Event} e Property change event.
210 handleVisibleChange_: function(e
) {
211 if (!this.initalized_
&& this.visible
) {
212 this.initalized_
= true;
213 OptionsPage
.showTab($('personal-certs-nav-tab'));
214 chrome
.send('populateCertificateManager');
219 // CertificateManagerHandler callbacks.
220 CertificateManager
.onPopulateTree = function(args
) {
221 $(args
[0]).populate(args
[1]);
224 CertificateManager
.exportPersonalAskPassword = function(args
) {
225 CertificateBackupOverlay
.show();
228 CertificateManager
.importPersonalAskPassword = function(args
) {
229 CertificateRestoreOverlay
.show();
232 CertificateManager
.onModelReady = function(userDbAvailable
,
234 if (!userDbAvailable
)
237 $('personalCertsTab-import-and-bind').disabled
= false;
238 $('personalCertsTab-import').disabled
= false;
239 $('serverCertsTab-import').disabled
= false;
240 $('caCertsTab-import').disabled
= false;
245 CertificateManagerTab
: CertificateManagerTab
,
246 CertificateManager
: CertificateManager