Home | History | Annotate | Download | only in options
      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.
      4 
      5 cr.define('options', function() {
      6   /** @const */ var OptionsPage = options.OptionsPage;
      7 
      8   /**
      9    * CertificateBackupOverlay class
     10    * Encapsulated handling of the 'enter backup password' overlay page.
     11    * @class
     12    */
     13   function CertificateBackupOverlay() {
     14     OptionsPage.call(this, 'certificateBackupOverlay',
     15                      '',
     16                      'certificateBackupOverlay');
     17   }
     18 
     19   cr.addSingletonGetter(CertificateBackupOverlay);
     20 
     21   CertificateBackupOverlay.prototype = {
     22     __proto__: OptionsPage.prototype,
     23 
     24     /**
     25      * Initializes the page.
     26      */
     27     initializePage: function() {
     28       OptionsPage.prototype.initializePage.call(this);
     29 
     30       var self = this;
     31       $('certificateBackupCancelButton').onclick = function(event) {
     32         self.cancelBackup_();
     33       };
     34       $('certificateBackupOkButton').onclick = function(event) {
     35         self.finishBackup_();
     36       };
     37       var onBackupPasswordInput = function(event) {
     38         self.comparePasswords_();
     39       };
     40       $('certificateBackupPassword').oninput = onBackupPasswordInput;
     41       $('certificateBackupPassword2').oninput = onBackupPasswordInput;
     42 
     43       self.clearInputFields_();
     44     },
     45 
     46     /**
     47      * Clears any uncommitted input, and dismisses the overlay.
     48      * @private
     49      */
     50     dismissOverlay_: function() {
     51       this.clearInputFields_();
     52       OptionsPage.closeOverlay();
     53     },
     54 
     55     /**
     56      * Attempt the Backup operation.
     57      * The overlay will be left up with inputs disabled until the backend
     58      * finishes and dismisses it.
     59      * @private
     60      */
     61     finishBackup_: function() {
     62       chrome.send('exportPersonalCertificatePasswordSelected',
     63                   [$('certificateBackupPassword').value]);
     64       $('certificateBackupCancelButton').disabled = true;
     65       $('certificateBackupOkButton').disabled = true;
     66       $('certificateBackupPassword').disabled = true;
     67       $('certificateBackupPassword2').disabled = true;
     68     },
     69 
     70     /**
     71      * Cancel the Backup operation.
     72      * @private
     73      */
     74     cancelBackup_: function() {
     75       chrome.send('cancelImportExportCertificate');
     76       this.dismissOverlay_();
     77     },
     78 
     79     /**
     80      * Compares the password fields and sets the button state appropriately.
     81      * @private
     82      */
     83     comparePasswords_: function() {
     84       var password1 = $('certificateBackupPassword').value;
     85       var password2 = $('certificateBackupPassword2').value;
     86       $('certificateBackupOkButton').disabled =
     87           !password1 || password1 != password2;
     88     },
     89 
     90     /**
     91      * Clears the value of each input field.
     92      * @private
     93      */
     94     clearInputFields_: function() {
     95       $('certificateBackupPassword').value = '';
     96       $('certificateBackupPassword2').value = '';
     97       $('certificateBackupPassword').disabled = false;
     98       $('certificateBackupPassword2').disabled = false;
     99       $('certificateBackupCancelButton').disabled = false;
    100       $('certificateBackupOkButton').disabled = true;
    101     },
    102   };
    103 
    104   CertificateBackupOverlay.show = function() {
    105     CertificateBackupOverlay.getInstance().clearInputFields_();
    106     OptionsPage.navigateToPage('certificateBackupOverlay');
    107   };
    108 
    109   CertificateBackupOverlay.dismiss = function() {
    110     CertificateBackupOverlay.getInstance().dismissOverlay_();
    111   };
    112 
    113   // Export
    114   return {
    115     CertificateBackupOverlay: CertificateBackupOverlay
    116   };
    117 });
    118