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 Page = cr.ui.pageManager.Page;
7 /** @const */ var PageManager = cr.ui.pageManager.PageManager;
10 * CertificateEditCaTrustOverlay class
11 * Encapsulated handling of the 'edit ca trust' and 'import ca' overlay pages.
14 function CertificateEditCaTrustOverlay() {
15 Page.call(this, 'certificateEditCaTrustOverlay', '',
16 'certificateEditCaTrustOverlay');
19 cr.addSingletonGetter(CertificateEditCaTrustOverlay);
21 CertificateEditCaTrustOverlay.prototype = {
22 __proto__: Page.prototype,
25 * Dismisses the overlay.
28 dismissOverlay_: function() {
29 PageManager.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 PageManager.showPageByName('certificateEditCaTrustOverlay');
130 chrome.send('getCaCertificateTrust', [certId]);
134 * Show the Import CA overlay.
135 * @param {string} certName The display name of the certificate.
138 CertificateEditCaTrustOverlay.showImport = function(certName) {
139 var self = CertificateEditCaTrustOverlay.getInstance();
140 // TODO(mattm): do we want a view certificate button here like firefox has?
141 $('certificateEditCaTrustCancelButton').onclick = function(event) {
142 self.cancelImport_();
144 $('certificateEditCaTrustOkButton').onclick = function(event) {
145 self.finishImport_();
147 $('certificateEditCaTrustDescription').textContent =
148 loadTimeData.getStringF('certificateImportCaDescriptionFormat',
150 CertificateEditCaTrustOverlay.populateTrust(false, false, false);
151 PageManager.showPageByName('certificateEditCaTrustOverlay');
154 CertificateEditCaTrustOverlay.dismiss = function() {
155 CertificateEditCaTrustOverlay.getInstance().dismissOverlay_();
160 CertificateEditCaTrustOverlay: CertificateEditCaTrustOverlay