Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / resources / options / certificate_backup_overlay.js
blob9c516b0f2a83412b52796647b67fff2bc1fa4ed5
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;
9   /**
10    * CertificateBackupOverlay class
11    * Encapsulated handling of the 'enter backup password' overlay page.
12    * @class
13    */
14   function CertificateBackupOverlay() {
15     Page.call(this, 'certificateBackupOverlay', '', 'certificateBackupOverlay');
16   }
18   cr.addSingletonGetter(CertificateBackupOverlay);
20   CertificateBackupOverlay.prototype = {
21     __proto__: Page.prototype,
23     /** @override */
24     initializePage: function() {
25       Page.prototype.initializePage.call(this);
27       var self = this;
28       $('certificateBackupCancelButton').onclick = function(event) {
29         self.cancelBackup_();
30       };
31       $('certificateBackupOkButton').onclick = function(event) {
32         self.finishBackup_();
33       };
34       var onBackupPasswordInput = function(event) {
35         self.comparePasswords_();
36       };
37       $('certificateBackupPassword').oninput = onBackupPasswordInput;
38       $('certificateBackupPassword2').oninput = onBackupPasswordInput;
40       self.clearInputFields_();
41     },
43     /**
44      * Clears any uncommitted input, and dismisses the overlay.
45      * @private
46      */
47     dismissOverlay_: function() {
48       this.clearInputFields_();
49       PageManager.closeOverlay();
50     },
52     /**
53      * Attempt the Backup operation.
54      * The overlay will be left up with inputs disabled until the backend
55      * finishes and dismisses it.
56      * @private
57      */
58     finishBackup_: function() {
59       chrome.send('exportPersonalCertificatePasswordSelected',
60                   [$('certificateBackupPassword').value]);
61       $('certificateBackupCancelButton').disabled = true;
62       $('certificateBackupOkButton').disabled = true;
63       $('certificateBackupPassword').disabled = true;
64       $('certificateBackupPassword2').disabled = true;
65     },
67     /**
68      * Cancel the Backup operation.
69      * @private
70      */
71     cancelBackup_: function() {
72       chrome.send('cancelImportExportCertificate');
73       this.dismissOverlay_();
74     },
76     /**
77      * Compares the password fields and sets the button state appropriately.
78      * @private
79      */
80     comparePasswords_: function() {
81       var password1 = $('certificateBackupPassword').value;
82       var password2 = $('certificateBackupPassword2').value;
83       $('certificateBackupOkButton').disabled =
84           !password1 || password1 != password2;
85     },
87     /**
88      * Clears the value of each input field.
89      * @private
90      */
91     clearInputFields_: function() {
92       $('certificateBackupPassword').value = '';
93       $('certificateBackupPassword2').value = '';
94       $('certificateBackupPassword').disabled = false;
95       $('certificateBackupPassword2').disabled = false;
96       $('certificateBackupCancelButton').disabled = false;
97       $('certificateBackupOkButton').disabled = true;
98     },
99   };
101   CertificateBackupOverlay.show = function() {
102     CertificateBackupOverlay.getInstance().clearInputFields_();
103     PageManager.showPageByName('certificateBackupOverlay');
104   };
106   CertificateBackupOverlay.dismiss = function() {
107     CertificateBackupOverlay.getInstance().dismissOverlay_();
108   };
110   // Export
111   return {
112     CertificateBackupOverlay: CertificateBackupOverlay
113   };