Home | History | Annotate | Download | only in options
      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   const OptionsPage = options.OptionsPage;
      7 
      8   /**
      9    * CertificateEditCaTrustOverlay class
     10    * Encapsulated handling of the 'edit ca trust' and 'import ca' overlay pages.
     11    * @class
     12    */
     13   function CertificateEditCaTrustOverlay() {
     14     OptionsPage.call(this, 'certificateEditCaTrustOverlay',
     15                      '',
     16                      'certificateEditCaTrustOverlay');
     17   }
     18 
     19   cr.addSingletonGetter(CertificateEditCaTrustOverlay);
     20 
     21   CertificateEditCaTrustOverlay.prototype = {
     22     __proto__: OptionsPage.prototype,
     23 
     24     /**
     25      * Dismisses the overlay.
     26      * @private
     27      */
     28     dismissOverlay_: function() {
     29       OptionsPage.closeOverlay();
     30     },
     31 
     32     /**
     33      * Enables or disables input fields.
     34      * @private
     35      */
     36     enableInputs_: function(enabled) {
     37       $('certificateCaTrustSSLCheckbox').disabled =
     38       $('certificateCaTrustEmailCheckbox').disabled =
     39       $('certificateCaTrustObjSignCheckbox').disabled =
     40       $('certificateEditCaTrustCancelButton').disabled =
     41       $('certificateEditCaTrustOkButton').disabled = !enabled;
     42     },
     43 
     44     /**
     45      * Attempt the Edit operation.
     46      * The overlay will be left up with inputs disabled until the backend
     47      * finishes and dismisses it.
     48      * @private
     49      */
     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',
     54                   [this.certId,
     55                    $('certificateCaTrustSSLCheckbox').checked.toString(),
     56                    $('certificateCaTrustEmailCheckbox').checked.toString(),
     57                    $('certificateCaTrustObjSignCheckbox').checked.toString()]);
     58       this.enableInputs_(false);
     59     },
     60 
     61     /**
     62      * Cancel the Edit operation.
     63      * @private
     64      */
     65     cancelEdit_: function() {
     66       this.dismissOverlay_();
     67     },
     68 
     69     /**
     70      * Attempt the Import operation.
     71      * The overlay will be left up with inputs disabled until the backend
     72      * finishes and dismisses it.
     73      * @private
     74      */
     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);
     83     },
     84 
     85     /**
     86      * Cancel the Import operation.
     87      * @private
     88      */
     89     cancelImport_: function() {
     90       chrome.send('cancelImportExportCertificate');
     91       this.dismissOverlay_();
     92     },
     93   };
     94 
     95   /**
     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
    100    */
    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);
    107   }
    108 
    109   /**
    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.
    114    * checkbox.
    115    */
    116   CertificateEditCaTrustOverlay.show = function(certId, certName) {
    117     var self = CertificateEditCaTrustOverlay.getInstance();
    118     self.certId = certId;
    119     $('certificateEditCaTrustCancelButton').onclick = function(event) {
    120       self.cancelEdit_();
    121     }
    122     $('certificateEditCaTrustOkButton').onclick = function(event) {
    123       self.finishEdit_();
    124     }
    125     $('certificateEditCaTrustDescription').textContent =
    126         localStrings.getStringF('certificateEditCaTrustDescriptionFormat',
    127                                 certName);
    128     self.enableInputs_(false);
    129     OptionsPage.navigateToPage('certificateEditCaTrustOverlay');
    130     chrome.send('getCaCertificateTrust', [certId]);
    131   }
    132 
    133   /**
    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.
    138    * checkbox.
    139    */
    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_();
    145     }
    146     $('certificateEditCaTrustOkButton').onclick = function(event) {
    147       self.finishImport_();
    148     }
    149     $('certificateEditCaTrustDescription').textContent =
    150         localStrings.getStringF('certificateImportCaDescriptionFormat',
    151                                 certName);
    152     CertificateEditCaTrustOverlay.populateTrust(false, false, false);
    153     OptionsPage.navigateToPage('certificateEditCaTrustOverlay');
    154   }
    155 
    156   CertificateEditCaTrustOverlay.dismiss = function() {
    157     CertificateEditCaTrustOverlay.getInstance().dismissOverlay_();
    158   };
    159 
    160   // Export
    161   return {
    162     CertificateEditCaTrustOverlay: CertificateEditCaTrustOverlay
    163   };
    164 });
    165