Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[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
14 function CertificateBackupOverlay() {
15 Page.call(this, 'certificateBackupOverlay', '', 'certificateBackupOverlay');
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_();
31 $('certificateBackupOkButton').onclick = function(event) {
32 self.finishBackup_();
34 var onBackupPasswordInput = function(event) {
35 self.comparePasswords_();
37 $('certificateBackupPassword').oninput = onBackupPasswordInput;
38 $('certificateBackupPassword2').oninput = onBackupPasswordInput;
40 self.clearInputFields_();
43 /**
44 * Clears any uncommitted input, and dismisses the overlay.
45 * @private
47 dismissOverlay_: function() {
48 this.clearInputFields_();
49 PageManager.closeOverlay();
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
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;
67 /**
68 * Cancel the Backup operation.
69 * @private
71 cancelBackup_: function() {
72 chrome.send('cancelImportExportCertificate');
73 this.dismissOverlay_();
76 /**
77 * Compares the password fields and sets the button state appropriately.
78 * @private
80 comparePasswords_: function() {
81 var password1 = $('certificateBackupPassword').value;
82 var password2 = $('certificateBackupPassword2').value;
83 $('certificateBackupOkButton').disabled =
84 !password1 || password1 != password2;
87 /**
88 * Clears the value of each input field.
89 * @private
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;
101 CertificateBackupOverlay.show = function() {
102 CertificateBackupOverlay.getInstance().clearInputFields_();
103 PageManager.showPageByName('certificateBackupOverlay');
106 CertificateBackupOverlay.dismiss = function() {
107 CertificateBackupOverlay.getInstance().dismissOverlay_();
110 // Export
111 return {
112 CertificateBackupOverlay: CertificateBackupOverlay