Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / resources / chromeos / login / screen_confirm_password.js
blob2c287408a5e505a5ab8cf94924b86ad3ec3d1846
1 // Copyright 2013 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 /**
6  * @fileoverview Password confirmation screen implementation.
7  */
9 login.createScreen('ConfirmPasswordScreen', 'confirm-password', function() {
10   return {
11     EXTERNAL_API: [
12       'show'
13     ],
15     /**
16      * Callback to run when the screen is dismissed.
17      * @type {function(string)}
18      */
19     callback_: null,
21     /** @override */
22     decorate: function() {
23       $('confirm-password-input').addEventListener(
24           'keydown', this.onPasswordFieldKeyDown_.bind(this));
25       $('confirm-password-confirm-button').addEventListener(
26           'click', this.onConfirmPassword_.bind(this));
28       $('saml-confirm-password').addEventListener('cancel', function(e) {
29           Oobe.showScreen({id: SCREEN_ACCOUNT_PICKER});
30           Oobe.resetSigninUI(true);
31       });
32       $('saml-confirm-password').addEventListener('passwordEnter', function(e) {
33         this.callback_(e.detail.password);
34       }.bind(this));
35     },
37     get defaultControl() {
38       return $('confirm-password-input');
39     },
41     /** @override */
42     onBeforeShow: function(data) {
43       $('login-header-bar').signinUIState =
44           SIGNIN_UI_STATE.SAML_PASSWORD_CONFIRM;
45     },
47     /** @override */
48     onAfterShow: function(data) {
49       if (Oobe.isNewGaiaFlow())
50         $('saml-confirm-password').focus();
51     },
53     /** @override */
54     onBeforeHide: function() {
55       if (Oobe.isNewGaiaFlow())
56         $('saml-confirm-password').reset();
57     },
59     /**
60      * Handle 'keydown' event on password input field.
61      */
62     onPasswordFieldKeyDown_: function(e) {
63       if (e.keyIdentifier == 'Enter')
64         this.onConfirmPassword_();
65     },
67     /**
68      * Invoked when user clicks on the 'confirm' button.
69      */
70     onConfirmPassword_: function() {
71       this.callback_($('confirm-password-input').value);
72     },
74     /**
75      * Shows the confirm password screen.
76      * @param {string} email The authenticated user's e-mail.
77      * @param {number} attemptCount Number of attempts tried, starting at 0.
78      * @param {function(string)} callback The callback to be invoked when the
79      *     screen is dismissed.
80      */
81     show: function(email, attemptCount, callback) {
82       this.callback_ = callback;
83       this.classList.toggle('error', attemptCount > 0);
84       if (Oobe.isNewGaiaFlow()) {
85         $('saml-confirm-password-contents').hidden = true;
86         var samlConfirmPassword = $('saml-confirm-password');
87         samlConfirmPassword.reset();
88         samlConfirmPassword.hidden = false;
89         samlConfirmPassword.email = email;
90         if (attemptCount > 0)
91           samlConfirmPassword.invalidate();
92       } else {
93        $('confirm-password-input').value = '';
94       }
95       Oobe.showScreen({id: SCREEN_CONFIRM_PASSWORD});
96       $('progress-dots').hidden = true;
97     }
98   };
99 });