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 /** @const */ var OptionsPage = options.OptionsPage;
9 * CertificateEditCaTrustOverlay class
10 * Encapsulated handling of the 'edit ca trust' and 'import ca' overlay pages.
13 function CertificateEditCaTrustOverlay() {
14 OptionsPage.call(this, 'certificateEditCaTrustOverlay',
16 'certificateEditCaTrustOverlay');
19 cr.addSingletonGetter(CertificateEditCaTrustOverlay);
21 CertificateEditCaTrustOverlay.prototype = {
22 __proto__: OptionsPage.prototype,
25 * Dismisses the overlay.
28 dismissOverlay_: function() {
29 OptionsPage.closeOverlay();
33 * Enables or disables input fields.
36 enableInputs_: function(enabled) {
37 $('certificateCaTrustSSLCheckbox').disabled =
38 $('certificateCaTrustEmailCheckbox').disabled =
39 $('certificateCaTrustObjSignCheckbox').disabled =
40 $('certificateEditCaTrustCancelButton').disabled =
41 $('certificateEditCaTrustOkButton').disabled = !enabled;
45 * Attempt the Edit operation.
46 * The overlay will be left up with inputs disabled until the backend
47 * finishes and dismisses it.
50 finishEdit_: function() {
51 // TODO(mattm): Send checked values as booleans. For now send them as
52 // strings, since WebUIBindings::send does not support any other types :(
53 chrome.send('editCaCertificateTrust',
55 $('certificateCaTrustSSLCheckbox').checked.toString(),
56 $('certificateCaTrustEmailCheckbox').checked.toString(),
57 $('certificateCaTrustObjSignCheckbox').checked.toString()]);
58 this.enableInputs_(false);
62 * Cancel the Edit operation.
65 cancelEdit_: function() {
66 this.dismissOverlay_();
70 * Attempt the Import operation.
71 * The overlay will be left up with inputs disabled until the backend
72 * finishes and dismisses it.
75 finishImport_: function() {
76 // TODO(mattm): Send checked values as booleans. For now send them as
77 // strings, since WebUIBindings::send does not support any other types :(
78 chrome.send('importCaCertificateTrustSelected',
79 [$('certificateCaTrustSSLCheckbox').checked.toString(),
80 $('certificateCaTrustEmailCheckbox').checked.toString(),
81 $('certificateCaTrustObjSignCheckbox').checked.toString()]);
82 this.enableInputs_(false);
86 * Cancel the Import operation.
89 cancelImport_: function() {
90 chrome.send('cancelImportExportCertificate');
91 this.dismissOverlay_();
96 * Callback from CertificateManagerHandler with the trust values.
97 * @param {boolean} trustSSL The initial value of SSL trust checkbox.
98 * @param {boolean} trustEmail The initial value of Email trust checkbox.
99 * @param {boolean} trustObjSign The initial value of Object Signing trust.
101 CertificateEditCaTrustOverlay.populateTrust = function(
102 trustSSL, trustEmail, trustObjSign) {
103 $('certificateCaTrustSSLCheckbox').checked = trustSSL;
104 $('certificateCaTrustEmailCheckbox').checked = trustEmail;
105 $('certificateCaTrustObjSignCheckbox').checked = trustObjSign;
106 CertificateEditCaTrustOverlay.getInstance().enableInputs_(true);
110 * Show the Edit CA Trust overlay.
111 * @param {string} certId The id of the certificate to be passed to the
112 * certificate manager model.
113 * @param {string} certName The display name of the certificate.
116 CertificateEditCaTrustOverlay.show = function(certId, certName) {
117 var self = CertificateEditCaTrustOverlay.getInstance();
118 self.certId = certId;
119 $('certificateEditCaTrustCancelButton').onclick = function(event) {
122 $('certificateEditCaTrustOkButton').onclick = function(event) {
125 $('certificateEditCaTrustDescription').textContent =
126 loadTimeData.getStringF('certificateEditCaTrustDescriptionFormat',
128 self.enableInputs_(false);
129 OptionsPage.navigateToPage('certificateEditCaTrustOverlay');
130 chrome.send('getCaCertificateTrust', [certId]);
134 * Show the Import CA overlay.
135 * @param {string} certId The id of the certificate to be passed to the
136 * certificate manager model.
137 * @param {string} certName The display name of the certificate.
140 CertificateEditCaTrustOverlay.showImport = function(certName) {
141 var self = CertificateEditCaTrustOverlay.getInstance();
142 // TODO(mattm): do we want a view certificate button here like firefox has?
143 $('certificateEditCaTrustCancelButton').onclick = function(event) {
144 self.cancelImport_();
146 $('certificateEditCaTrustOkButton').onclick = function(event) {
147 self.finishImport_();
149 $('certificateEditCaTrustDescription').textContent =
150 loadTimeData.getStringF('certificateImportCaDescriptionFormat',
152 CertificateEditCaTrustOverlay.populateTrust(false, false, false);
153 OptionsPage.navigateToPage('certificateEditCaTrustOverlay');
156 CertificateEditCaTrustOverlay.dismiss = function() {
157 CertificateEditCaTrustOverlay.getInstance().dismissOverlay_();
162 CertificateEditCaTrustOverlay: CertificateEditCaTrustOverlay