Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1705)

Side by Side Diff: chrome/browser/resources/settings/people_page/password_prompt_dialog.js

Issue 2208473007: Rework quick unlock settings to follow new specs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkgr
Patch Set: Rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * 7 *
8 * 'settings-quick-unlock-authenticate' shows a password input prompt to the 8 * 'settings-password-prompt-dialog' shows a dialog which asks for the user to
9 * user. It validates the password is correct. Once the user has entered their 9 * enter their password. It validates the password is correct. Once the user has
10 * account password, the page navigates to the quick unlock setup methods page. 10 * entered their account password, the page fires an 'authenticated' event and
11 * updates the setModes binding.
11 * 12 *
12 * This element provides a wrapper around chrome.quickUnlockPrivate.setModes 13 * The setModes binding is a wrapper around chrome.quickUnlockPrivate.setModes
13 * which has a prebound account password (the |set-modes| property). The account 14 * which has a prebound account password. The account password by itself is not
14 * password by itself is not available for other elements to access. 15 * available for other elements to access.
15 * 16 *
16 * Example: 17 * Example:
17 * 18 *
18 * <settings-quick-unlock-authenticate 19 * <settings-password-prompt-dialog
19 * set-modes="[[setModes]]" 20 * id="passwordPrompt"
20 * current-route="{{currentRoute}}" 21 * set-modes="{{setModes}}">
21 * profile-name="[[profileName_]]"> 22 * </settings-password-prompt-dialog>
22 * </settings-quick-unlock-authenticate> 23 *
24 * this.$.passwordPrompt.open()
23 */ 25 */
24 26
25 (function() { 27 (function() {
26 'use strict'; 28 'use strict';
27 29
28 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes. 30 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes.
29 /** @const */ var AUTOSUBMIT_DELAY_MS = 500; // .5 seconds
30 31
31 /** 32 /**
32 * Helper method that checks if |password| is valid. 33 * Helper method that checks if |password| is valid.
33 * @param {string} password 34 * @param {string} password
34 * @param {function(boolean):void} onCheck 35 * @param {function(boolean):void} onCheck
35 */ 36 */
36 function checkAccountPassword_(password, onCheck) { 37 function checkAccountPassword_(password, onCheck) {
37 // We check the account password by trying to update the active set of quick 38 // We check the account password by trying to update the active set of quick
38 // unlock modes without changing any credentials. 39 // unlock modes without changing any credentials.
39 chrome.quickUnlockPrivate.getActiveModes(function(modes) { 40 chrome.quickUnlockPrivate.getActiveModes(function(modes) {
40 var credentials = 41 var credentials =
41 /** @type {!Array<string>} */ (Array(modes.length).fill('')); 42 /** @type {!Array<string>} */ (Array(modes.length).fill(''));
42 chrome.quickUnlockPrivate.setModes(password, modes, credentials, onCheck); 43 chrome.quickUnlockPrivate.setModes(password, modes, credentials, onCheck);
43 }); 44 });
44 } 45 }
45 46
46 Polymer({ 47 Polymer({
47 is: 'settings-quick-unlock-authenticate', 48 is: 'settings-password-prompt-dialog',
48 49
49 properties: { 50 properties: {
50 /** @type {!settings.Route} */
51 currentRoute: {
52 type: Object,
53 observer: 'onRouteChanged_',
54 },
55
56 /** 51 /**
57 * A wrapper around chrome.quickUnlockPrivate.setModes with the account 52 * A wrapper around chrome.quickUnlockPrivate.setModes with the account
58 * password already supplied. If this is null, the authentication screen 53 * password already supplied. If this is null, the authentication screen
59 * needs to be redisplayed. This property will be cleared after 54 * needs to be redisplayed. This property will be cleared after
60 * PASSWORD_ACTIVE_DURATION_MS milliseconds. 55 * PASSWORD_ACTIVE_DURATION_MS milliseconds.
61 */ 56 */
62 setModes: { 57 setModes: {
63 type: Object, 58 type: Object,
64 notify: true 59 notify: true
65 }, 60 },
66 61
67 /** 62 /**
68 * Name of the profile.
69 */
70 profileName: String,
71
72 /**
73 * The actual value of the password field. This is cleared whenever the 63 * The actual value of the password field. This is cleared whenever the
74 * authentication screen is not displayed so that the user's password is not 64 * authentication screen is not displayed so that the user's password is not
75 * easily available to an attacker. The actual password is stored as an 65 * easily available to an attacker. The actual password is stored as an
76 * captured closure variable inside of setModes. 66 * captured closure variable inside of setModes.
77 * @private 67 * @private
78 */ 68 */
79 password_: String, 69 password_: {
70 type: String,
71 observer: 'onPasswordChanged_'
72 },
80 73
81 /** 74 /**
82 * Helper property which marks password as valid/invalid. 75 * Helper property which marks password as valid/invalid.
83 * @private 76 * @private
84 */ 77 */
85 passwordInvalid_: Boolean 78 passwordInvalid_: Boolean
86 }, 79 },
87 80
88 /** @private */ 81 /**
89 onRouteChanged_: function(currentRoute) { 82 * Open up the dialog. This will wait until the dialog has loaded before
90 // Clear local state if this screen is not active so if this screen shows 83 * opening it.
91 // up again the user will get a fresh UI. 84 */
92 if (this.currentRoute != settings.Route.QUICK_UNLOCK_AUTHENTICATE) { 85 open: function() {
93 this.password_ = ''; 86 // Wait until the dialog is attached to the DOM before trying to open it.
94 this.passwordInvalid_ = false; 87 var dialog = /** @type {{isConnected: boolean}} */ (this.$.dialog);
88 if (!dialog.isConnected) {
89 setTimeout(this.open.bind(this));
90 return;
95 } 91 }
92
93 this.$.dialog.showModal();
94 },
95
96 /** Close the dialog. */
97 close: function() {
98 if (this.$.dialog.open)
99 this.$.dialog.close();
100
101 this.password_ = '';
102 },
103
104 /** Cancel the password prompt. */
105 cancel: function() {
106 if (this.$.dialog.open)
107 this.$.dialog.cancel();
108
109 // We bind setModes_ in an on-change event, so when the user hits cancel
110 // after they enter their valid password we may have authenticated them.
111 this.setModes_ = undefined;
96 }, 112 },
97 113
98 /** 114 /**
99 * Start or restart a timer to check the account password and move past the 115 * Run the account password check.
100 * authentication screen.
101 * @private 116 * @private
102 */ 117 */
103 startDelayedPasswordCheck_: function() { 118 checkPassword_: function() {
104 clearTimeout(this.delayedPasswordCheckTimeout_);
105 this.delayedPasswordCheckTimeout_ =
106 setTimeout(this.checkPasswordNow_.bind(this), AUTOSUBMIT_DELAY_MS);
107 },
108
109 /**
110 * Run the account password check right now. This will cancel any delayed
111 * check.
112 * @private
113 */
114 checkPasswordNow_: function() {
115 clearTimeout(this.delayedPasswordCheckTimeout_);
116 clearTimeout(this.clearAccountPasswordTimeout_); 119 clearTimeout(this.clearAccountPasswordTimeout_);
117 120
118 // The user might have started entering a password and then deleted it all. 121 // The user might have started entering a password and then deleted it all.
119 // Do not submit/show an error in this case. 122 // Do not submit/show an error in this case.
120 if (!this.password_) { 123 if (!this.password_) {
121 this.passwordInvalid_ = false; 124 this.passwordInvalid_ = false;
122 return; 125 return;
123 } 126 }
124 127
125 function onPasswordChecked(valid) { 128 function onPasswordChecked(valid) {
(...skipping 13 matching lines...) Expand all
139 }; 142 };
140 143
141 function clearSetModes() { 144 function clearSetModes() {
142 // Reset the password so that any cached references to this.setModes 145 // Reset the password so that any cached references to this.setModes
143 // will fail. 146 // will fail.
144 password = ''; 147 password = '';
145 this.setModes = null; 148 this.setModes = null;
146 } 149 }
147 150
148 this.clearAccountPasswordTimeout_ = setTimeout( 151 this.clearAccountPasswordTimeout_ = setTimeout(
149 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); 152 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS);
150 153 this.close();
151 settings.navigateTo(settings.Route.QUICK_UNLOCK_CHOOSE_METHOD);
152 } 154 }
153 } 155 }
154 156
155 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); 157 checkAccountPassword_(this.password_, onPasswordChecked.bind(this));
158 },
159
160 /** @private */
161 onPasswordChanged_: function() {
162 this.passwordInvalid_ = false;
163 },
164
165 /** @private */
166 enableConfirm_: function() {
167 return !!this.password_ && !this.passwordInvalid_;
156 } 168 }
157 }); 169 });
158 170
159 })(); 171 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698