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

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: Initial upload 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
tommycli 2016/08/05 17:46:19 Nice adaptation of existing code here!
jdufault 2016/08/05 20:59:52 :)
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();
96 }, 94 },
97 95
98 /** 96 /**
99 * Start or restart a timer to check the account password and move past the 97 * Close the dialog.
100 * authentication screen.
101 * @private
102 */ 98 */
103 startDelayedPasswordCheck_: function() { 99 close: function() {
104 clearTimeout(this.delayedPasswordCheckTimeout_); 100 if (this.$.dialog.open)
105 this.delayedPasswordCheckTimeout_ = 101 this.$.dialog.close();
106 setTimeout(this.checkPasswordNow_.bind(this), AUTOSUBMIT_DELAY_MS);
107 }, 102 },
108 103
109 /** 104 /**
110 * Run the account password check right now. This will cancel any delayed 105 * Run the account password check.
111 * check.
112 * @private 106 * @private
113 */ 107 */
114 checkPasswordNow_: function() { 108 checkPassword_: function() {
115 clearTimeout(this.delayedPasswordCheckTimeout_);
116 clearTimeout(this.clearAccountPasswordTimeout_); 109 clearTimeout(this.clearAccountPasswordTimeout_);
117 110
118 // The user might have started entering a password and then deleted it all. 111 // The user might have started entering a password and then deleted it all.
119 // Do not submit/show an error in this case. 112 // Do not submit/show an error in this case.
120 if (!this.password_) { 113 if (!this.password_) {
121 this.passwordInvalid_ = false; 114 this.passwordInvalid_ = false;
122 return; 115 return;
123 } 116 }
124 117
125 function onPasswordChecked(valid) { 118 function onPasswordChecked(valid) {
(...skipping 13 matching lines...) Expand all
139 }; 132 };
140 133
141 function clearSetModes() { 134 function clearSetModes() {
142 // Reset the password so that any cached references to this.setModes 135 // Reset the password so that any cached references to this.setModes
143 // will fail. 136 // will fail.
144 password = ''; 137 password = '';
145 this.setModes = null; 138 this.setModes = null;
146 } 139 }
147 140
148 this.clearAccountPasswordTimeout_ = setTimeout( 141 this.clearAccountPasswordTimeout_ = setTimeout(
149 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); 142 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS);
150 143 this.$.dialog.close();
151 settings.navigateTo(settings.Route.QUICK_UNLOCK_CHOOSE_METHOD);
152 } 144 }
153 } 145 }
154 146
155 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); 147 checkAccountPassword_(this.password_, onPasswordChecked.bind(this));
148 },
149
150 /** @private */
151 onPasswordChanged_: function() {
152 this.passwordInvalid_ = false;
153 },
154
155 /** @private */
156 enableConfirm_: function() {
157 return !!this.password_ && !this.passwordInvalid_;
156 } 158 }
157 }); 159 });
158 160
159 })(); 161 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698