| 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(); |
| 103 }, |
| 100 | 104 |
| 105 /** |
| 106 * Called whenever the dialog is closed. |
| 107 * @private |
| 108 */ |
| 109 onClose_: function() { |
| 101 this.password_ = ''; | 110 this.password_ = ''; |
| 102 }, | 111 }, |
| 103 | 112 |
| 104 /** Cancel the password prompt. */ | 113 /** @private */ |
| 105 cancel: function() { | 114 onKeydown_: function(e) { |
| 106 if (this.$.dialog.open) | 115 if (e.key == 'Enter') |
| 107 this.$.dialog.cancel(); | 116 this.submitPassword_(); |
| 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 }, | 117 }, |
| 113 | 118 |
| 114 /** | 119 /** |
| 115 * Run the account password check. | 120 * Run the account password check. |
| 116 * @private | 121 * @private |
| 117 */ | 122 */ |
| 118 checkPassword_: function() { | 123 submitPassword_: function() { |
| 119 clearTimeout(this.clearAccountPasswordTimeout_); | 124 clearTimeout(this.clearAccountPasswordTimeout_); |
| 120 | 125 |
| 121 // The user might have started entering a password and then deleted it all. | 126 // The user might have started entering a password and then deleted it all. |
| 122 // Do not submit/show an error in this case. | 127 // Do not submit/show an error in this case. |
| 123 if (!this.password_) { | 128 if (!this.password_) { |
| 124 this.passwordInvalid_ = false; | 129 this.passwordInvalid_ = false; |
| 125 return; | 130 return; |
| 126 } | 131 } |
| 127 | 132 |
| 128 function onPasswordChecked(valid) { | 133 function onPasswordChecked(valid) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 143 | 148 |
| 144 function clearSetModes() { | 149 function clearSetModes() { |
| 145 // Reset the password so that any cached references to this.setModes | 150 // Reset the password so that any cached references to this.setModes |
| 146 // will fail. | 151 // will fail. |
| 147 password = ''; | 152 password = ''; |
| 148 this.setModes = null; | 153 this.setModes = null; |
| 149 } | 154 } |
| 150 | 155 |
| 151 this.clearAccountPasswordTimeout_ = setTimeout( | 156 this.clearAccountPasswordTimeout_ = setTimeout( |
| 152 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); | 157 clearSetModes.bind(this), PASSWORD_ACTIVE_DURATION_MS); |
| 153 this.close(); | 158 // Closing the dialog will clear this.password_. |
| 159 this.$.dialog.close(); |
| 154 } | 160 } |
| 155 } | 161 } |
| 156 | 162 |
| 157 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); | 163 checkAccountPassword_(this.password_, onPasswordChecked.bind(this)); |
| 158 }, | 164 }, |
| 159 | 165 |
| 160 /** @private */ | 166 /** @private */ |
| 161 onPasswordChanged_: function() { | 167 onPasswordChanged_: function() { |
| 162 this.passwordInvalid_ = false; | 168 this.passwordInvalid_ = false; |
| 163 }, | 169 }, |
| 164 | 170 |
| 165 /** @private */ | 171 /** @private */ |
| 166 enableConfirm_: function() { | 172 enableConfirm_: function() { |
| 167 return !!this.password_ && !this.passwordInvalid_; | 173 return !!this.password_ && !this.passwordInvalid_; |
| 168 } | 174 } |
| 169 }); | 175 }); |
| 170 | 176 |
| 171 })(); | 177 })(); |
| OLD | NEW |