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

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: Fix closure (bad merge) 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 * profile-name="[[profileName_]]"> 21 * set-modes="[[setModes]]">
21 * </settings-quick-unlock-authenticate> 22 * </settings-password-prompt-dialog>
23 *
24 * this.$.passwordPrompt.open()
22 */ 25 */
23 26
24 (function() { 27 (function() {
25 'use strict'; 28 'use strict';
26 29
27 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes. 30 /** @const */ var PASSWORD_ACTIVE_DURATION_MS = 10 * 60 * 1000; // Ten minutes.
28 /** @const */ var AUTOSUBMIT_DELAY_MS = 500; // .5 seconds
29 31
30 /** 32 /**
31 * Helper method that checks if |password| is valid. 33 * Helper method that checks if |password| is valid.
32 * @param {string} password 34 * @param {string} password
33 * @param {function(boolean):void} onCheck 35 * @param {function(boolean):void} onCheck
34 */ 36 */
35 function checkAccountPassword_(password, onCheck) { 37 function checkAccountPassword_(password, onCheck) {
36 // 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
37 // unlock modes without changing any credentials. 39 // unlock modes without changing any credentials.
38 chrome.quickUnlockPrivate.getActiveModes(function(modes) { 40 chrome.quickUnlockPrivate.getActiveModes(function(modes) {
39 var credentials = 41 var credentials =
40 /** @type {!Array<string>} */ (Array(modes.length).fill('')); 42 /** @type {!Array<string>} */ (Array(modes.length).fill(''));
41 chrome.quickUnlockPrivate.setModes(password, modes, credentials, onCheck); 43 chrome.quickUnlockPrivate.setModes(password, modes, credentials, onCheck);
42 }); 44 });
43 } 45 }
44 46
45 Polymer({ 47 Polymer({
46 is: 'settings-quick-unlock-authenticate', 48 is: 'settings-password-prompt-dialog',
47
48 behavior: [settings.RouteObserverBehavior],
49 49
50 properties: { 50 properties: {
51 /** 51 /**
52 * A wrapper around chrome.quickUnlockPrivate.setModes with the account 52 * A wrapper around chrome.quickUnlockPrivate.setModes with the account
53 * password already supplied. If this is null, the authentication screen 53 * password already supplied. If this is null, the authentication screen
54 * needs to be redisplayed. This property will be cleared after 54 * needs to be redisplayed. This property will be cleared after
55 * PASSWORD_ACTIVE_DURATION_MS milliseconds. 55 * PASSWORD_ACTIVE_DURATION_MS milliseconds.
56 */ 56 */
57 setModes: { 57 setModes: {
58 type: Object, 58 type: Object,
59 notify: true 59 notify: true
60 }, 60 },
61 61
62 /** 62 /**
63 * Name of the profile.
64 */
65 profileName: String,
66
67 /**
68 * 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
69 * 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
70 * 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
71 * captured closure variable inside of setModes. 66 * captured closure variable inside of setModes.
72 * @private 67 * @private
73 */ 68 */
74 password_: String, 69 password_: {
70 type: String,
71 observer: 'onPasswordChanged_'
72 },
75 73
76 /** 74 /**
77 * Helper property which marks password as valid/invalid. 75 * Helper property which marks password as valid/invalid.
78 * @private 76 * @private
79 */ 77 */
80 passwordInvalid_: Boolean 78 passwordInvalid_: Boolean
81 }, 79 },
82 80
83 /** @protected */ 81 /**
84 currentRouteChanged: function() { 82 * Open up the dialog. This will wait until the dialog has loaded before
85 // Clear local state if this screen is not active so if this screen shows 83 * opening it.
86 // up again the user will get a fresh UI. 84 */
87 if (settings.getCurrentRoute() == settings.Route.QUICK_UNLOCK_AUTHENTICATE) 85 open: function() {
86 // Wait until the dialog is attached to the DOM before trying to open it.
87 var dialog = /** @type {{isConnected: boolean}} */ (this.$.dialog);
88 if (!dialog.isConnected) {
89 setTimeout(this.open.bind(this));
88 return; 90 return;
91 }
92
93 this.$.dialog.showModal();
94 },
95
96 /** Close the dialog. */
97 close: function() {
98 if (this.$.dialog.open)
99 this.$.dialog.close();
89 100
90 this.password_ = ''; 101 this.password_ = '';
91 this.passwordInvalid_ = false; 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;
92 }, 112 },
93 113
94 /** 114 /**
95 * Start or restart a timer to check the account password and move past the 115 * Run the account password check.
96 * authentication screen.
97 * @private 116 * @private
98 */ 117 */
99 startDelayedPasswordCheck_: function() { 118 checkPassword_: function() {
100 clearTimeout(this.delayedPasswordCheckTimeout_);
101 this.delayedPasswordCheckTimeout_ =
102 setTimeout(this.checkPasswordNow_.bind(this), AUTOSUBMIT_DELAY_MS);
103 },
104
105 /**
106 * Run the account password check right now. This will cancel any delayed
107 * check.
108 * @private
109 */
110 checkPasswordNow_: function() {
111 clearTimeout(this.delayedPasswordCheckTimeout_);
112 clearTimeout(this.clearAccountPasswordTimeout_); 119 clearTimeout(this.clearAccountPasswordTimeout_);
113 120
114 // 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.
115 // Do not submit/show an error in this case. 122 // Do not submit/show an error in this case.
116 if (!this.password_) { 123 if (!this.password_) {
117 this.passwordInvalid_ = false; 124 this.passwordInvalid_ = false;
118 return; 125 return;
119 } 126 }
120 127
121 function onPasswordChecked(valid) { 128 function onPasswordChecked(valid) {
(...skipping 13 matching lines...) Expand all
135 }; 142 };
136 143
137 function clearSetModes() { 144 function clearSetModes() {
138 // Reset the password so that any cached references to this.setModes 145 // Reset the password so that any cached references to this.setModes
139 // will fail. 146 // will fail.
140 password = ''; 147 password = '';
141 this.setModes = null; 148 this.setModes = null;
142 } 149 }
143 150
144 this.clearAccountPasswordTimeout_ = setTimeout( 151 this.clearAccountPasswordTimeout_ = setTimeout(
145 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); 152 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS);
146 153 this.close();
147 settings.navigateTo(settings.Route.QUICK_UNLOCK_CHOOSE_METHOD);
148 } 154 }
149 } 155 }
150 156
151 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_;
152 } 168 }
153 }); 169 });
154 170
155 })(); 171 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698