OLD | NEW |
---|---|
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-password-prompt-dialog' shows a dialog which asks for the user to | 8 * 'settings-password-prompt-dialog' shows a dialog which asks for the user to |
9 * enter their password. It validates the password is correct. Once the user has | 9 * enter their password. It validates the password is correct. Once the user has |
10 * entered their account password, the page fires an 'authenticated' event and | 10 * entered their account password, the page fires an 'authenticated' event and |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 * opening it. | 83 * opening it. |
84 */ | 84 */ |
85 open: function() { | 85 open: function() { |
86 // Wait until the dialog is attached to the DOM before trying to open it. | 86 // Wait until the dialog is attached to the DOM before trying to open it. |
87 var dialog = /** @type {{isConnected: boolean}} */ (this.$.dialog); | 87 var dialog = /** @type {{isConnected: boolean}} */ (this.$.dialog); |
88 if (!dialog.isConnected) { | 88 if (!dialog.isConnected) { |
89 setTimeout(this.open.bind(this)); | 89 setTimeout(this.open.bind(this)); |
90 return; | 90 return; |
91 } | 91 } |
92 | 92 |
93 if (this.$.dialog.open) | |
94 return; | |
95 | |
93 this.$.dialog.showModal(); | 96 this.$.dialog.showModal(); |
94 }, | 97 }, |
95 | 98 |
96 /** Close the dialog. */ | 99 /** @private */ |
97 close: function() { | 100 onCancelTap_: function() { |
98 if (this.$.dialog.open) | 101 if (this.$.dialog.open) |
99 this.$.dialog.close(); | 102 this.$.dialog.close(); |
100 | 103 |
101 this.password_ = ''; | 104 this.password_ = ''; |
102 }, | 105 }, |
103 | 106 |
104 /** Cancel the password prompt. */ | 107 /** @private */ |
105 cancel: function() { | 108 onKeydown_: function(e) { |
106 if (this.$.dialog.open) | 109 if (e.key == 'Enter') |
107 this.$.dialog.cancel(); | 110 this.checkPassword_(); |
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; | |
112 }, | 111 }, |
113 | 112 |
114 /** | 113 /** |
115 * Run the account password check. | 114 * Run the account password check. |
116 * @private | 115 * @private |
117 */ | 116 */ |
118 checkPassword_: function() { | 117 checkPassword_: function() { |
tommycli
2016/08/25 23:35:21
One more thing: It would be good to change this to
jdufault
2016/08/25 23:45:39
Done.
| |
119 clearTimeout(this.clearAccountPasswordTimeout_); | 118 clearTimeout(this.clearAccountPasswordTimeout_); |
120 | 119 |
121 // The user might have started entering a password and then deleted it all. | 120 // The user might have started entering a password and then deleted it all. |
122 // Do not submit/show an error in this case. | 121 // Do not submit/show an error in this case. |
123 if (!this.password_) { | 122 if (!this.password_) { |
124 this.passwordInvalid_ = false; | 123 this.passwordInvalid_ = false; |
125 return; | 124 return; |
126 } | 125 } |
127 | 126 |
128 function onPasswordChecked(valid) { | 127 function onPasswordChecked(valid) { |
129 // The password might have been cleared during the duration of the | 128 // The password might have been cleared during the duration of the |
130 // getActiveModes call. | 129 // getActiveModes call. |
131 this.passwordInvalid_ = !valid && !!this.password_; | 130 this.passwordInvalid_ = !valid && !!this.password_; |
132 | 131 |
133 if (valid) { | 132 if (valid) { |
134 // Create the |this.setModes| closure and automatically clear it after | 133 // Create the |this.setModes| closure and automatically clear it after |
135 // |PASSWORD_ACTIVE_DURATION_MS|. | 134 // |PASSWORD_ACTIVE_DURATION_MS|. |
136 var password = this.password_; | 135 var password = this.password_; |
137 this.password_ = ''; | 136 this.password_ = ''; |
138 | 137 |
139 this.setModes = function(modes, credentials, onComplete) { | 138 this.setModes = function(modes, credentials, onComplete) { |
140 chrome.quickUnlockPrivate.setModes( | 139 chrome.quickUnlockPrivate.setModes( |
141 password, modes, credentials, onComplete); | 140 password, modes, credentials, onComplete); |
142 }; | 141 }; |
143 | 142 |
144 function clearSetModes() { | 143 function clearSetModes() { |
145 // Reset the password so that any cached references to this.setModes | 144 // Reset the password so that any cached references to this.setModes |
146 // will fail. | 145 // will fail. |
147 password = ''; | 146 password = ''; |
tommycli
2016/08/25 23:34:25
err... does this actually do anything? I assume yo
jdufault
2016/08/25 23:45:39
This makes it so that calling the closure from a s
| |
148 this.setModes = null; | 147 this.setModes = null; |
149 } | 148 } |
150 | 149 |
151 this.clearAccountPasswordTimeout_ = setTimeout( | 150 this.clearAccountPasswordTimeout_ = setTimeout( |
152 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); | 151 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); |
153 this.close(); | 152 this.$.dialog.close(); |
tommycli
2016/08/25 23:34:25
You no longer wish to clear the password_ member v
jdufault
2016/08/25 23:45:39
Added clarifying comment.
| |
154 } | 153 } |
155 } | 154 } |
156 | 155 |
157 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); | 156 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); |
158 }, | 157 }, |
159 | 158 |
160 /** @private */ | 159 /** @private */ |
161 onPasswordChanged_: function() { | 160 onPasswordChanged_: function() { |
162 this.passwordInvalid_ = false; | 161 this.passwordInvalid_ = false; |
163 }, | 162 }, |
164 | 163 |
165 /** @private */ | 164 /** @private */ |
166 enableConfirm_: function() { | 165 enableConfirm_: function() { |
167 return !!this.password_ && !this.passwordInvalid_; | 166 return !!this.password_ && !this.passwordInvalid_; |
168 } | 167 } |
169 }); | 168 }); |
170 | 169 |
171 })(); | 170 })(); |
OLD | NEW |