Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 cr.define('options.passwordManager', function() { | 5 cr.define('options.passwordManager', function() { |
| 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 7 /** @const */ var DeletableItemList = options.DeletableItemList; | 7 /** @const */ var DeletableItemList = options.DeletableItemList; |
| 8 /** @const */ var DeletableItem = options.DeletableItem; | 8 /** @const */ var DeletableItem = options.DeletableItem; |
| 9 /** @const */ var List = cr.ui.List; | 9 /** @const */ var List = cr.ui.List; |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 this.contentElement.appendChild(usernameLabel); | 62 this.contentElement.appendChild(usernameLabel); |
| 63 | 63 |
| 64 // The stored password. | 64 // The stored password. |
| 65 var passwordInputDiv = this.ownerDocument.createElement('div'); | 65 var passwordInputDiv = this.ownerDocument.createElement('div'); |
| 66 passwordInputDiv.className = 'password'; | 66 passwordInputDiv.className = 'password'; |
| 67 | 67 |
| 68 // The password input field. | 68 // The password input field. |
| 69 var passwordInput = this.ownerDocument.createElement('input'); | 69 var passwordInput = this.ownerDocument.createElement('input'); |
| 70 passwordInput.type = 'password'; | 70 passwordInput.type = 'password'; |
| 71 passwordInput.className = 'inactive-password'; | 71 passwordInput.className = 'inactive-password'; |
| 72 this.closeButtonElement.tabIndex = -1; | |
| 73 passwordInput.tabIndex = -1; | |
| 74 passwordInput.readOnly = true; | 72 passwordInput.readOnly = true; |
| 75 passwordInput.value = this.showPasswords_ ? this.password : '********'; | 73 passwordInput.value = this.showPasswords_ ? this.password : '********'; |
| 76 passwordInputDiv.appendChild(passwordInput); | 74 passwordInputDiv.appendChild(passwordInput); |
| 77 this.passwordField = passwordInput; | 75 this.passwordField = passwordInput; |
| 76 this.setFocusable(false); | |
| 78 | 77 |
| 79 // The show/hide button. | 78 // The show/hide button. |
| 80 if (this.showPasswords_) { | 79 if (this.showPasswords_) { |
| 81 var button = this.ownerDocument.createElement('button'); | 80 var button = this.ownerDocument.createElement('button'); |
| 82 button.hidden = true; | 81 button.hidden = true; |
| 83 button.className = 'list-inline-button custom-appearance'; | 82 button.className = 'list-inline-button custom-appearance'; |
| 84 button.textContent = loadTimeData.getString('passwordShowButton'); | 83 button.textContent = loadTimeData.getString('passwordShowButton'); |
| 85 button.addEventListener('click', this.onClick_.bind(this), true); | 84 button.addEventListener('click', this.onClick_.bind(this), true); |
| 86 button.addEventListener('mousedown', function(event) { | 85 button.addEventListener('mousedown', function(event) { |
| 87 // Don't focus on this button by mousedown. | 86 // Don't focus on this button by mousedown. |
| 88 event.preventDefault(); | 87 event.preventDefault(); |
| 89 // Don't handle list item selection. It causes focus change. | 88 // Don't handle list item selection. It causes focus change. |
| 90 event.stopPropagation(); | 89 event.stopPropagation(); |
| 91 }, false); | 90 }, false); |
| 92 passwordInputDiv.appendChild(button); | 91 passwordInputDiv.appendChild(button); |
| 93 this.passwordShowButton = button; | 92 this.passwordShowButton = button; |
| 94 } | 93 } |
| 95 | 94 |
| 95 // |handleFocus| is defined in the base class and |closeButtonElement_| | |
| 96 // listens for the focus event. Listening for focusin on |this| will also | |
| 97 // include |closeButtonElement_|. | |
| 98 this.closeButtonElement_.removeEventListener('focus', this.handleFocus); | |
|
Dan Beam
2015/01/24 02:42:25
shouldn't this be:
this.closeButtonElement_.rem
hcarmona
2015/01/26 19:06:24
Acknowledged.
| |
| 99 this.addEventListener('focusin', this.handleFocus); | |
|
Dan Beam
2015/01/24 02:42:25
don't pass a 'focusin' event to a method that expe
hcarmona
2015/01/26 19:06:24
Rather than adding a focusin event to the Password
| |
| 100 | |
| 96 this.contentElement.appendChild(passwordInputDiv); | 101 this.contentElement.appendChild(passwordInputDiv); |
| 97 }, | 102 }, |
| 98 | 103 |
| 99 /** @override */ | 104 /** @override */ |
| 100 selectionChanged: function() { | 105 selectionChanged: function() { |
| 101 var input = this.passwordField; | 106 var input = this.passwordField; |
| 102 var button = this.passwordShowButton; | 107 var button = this.passwordShowButton; |
| 103 // The button doesn't exist when passwords can't be shown. | 108 // The button doesn't exist when passwords can't be shown. |
| 104 if (!button) | 109 if (!button) |
| 105 return; | 110 return; |
| 106 | 111 |
| 107 if (this.selected) { | 112 if (this.selected) { |
| 113 input.classList.remove('inactive-password'); | |
| 114 this.setFocusable(true); | |
| 115 button.hidden = false; | |
| 108 input.focus(); | 116 input.focus(); |
| 109 input.classList.remove('inactive-password'); | |
| 110 input.tabIndex = 0; | |
| 111 this.closeButtonElement.tabIndex = 0; | |
| 112 button.hidden = false; | |
| 113 } else { | 117 } else { |
| 114 input.classList.add('inactive-password'); | 118 input.classList.add('inactive-password'); |
| 115 input.tabIndex = -1; | 119 this.setFocusable(false); |
| 116 this.closeButtonElement.tabIndex = -1; | |
| 117 button.hidden = true; | 120 button.hidden = true; |
| 118 } | 121 } |
| 119 }, | 122 }, |
| 120 | 123 |
| 121 /** | 124 /** |
| 125 * Set the focusability of this row. | |
| 126 * @param {boolean} focusable | |
| 127 */ | |
| 128 setFocusable: function(focusable) { | |
| 129 var tabIndex = focusable ? 0 : -1; | |
| 130 this.passwordField.tabIndex = this.closeButtonElement.tabIndex = tabIndex; | |
| 131 }, | |
| 132 | |
| 133 /** | |
| 122 * Reveals the plain text password of this entry. | 134 * Reveals the plain text password of this entry. |
| 123 */ | 135 */ |
| 124 showPassword: function(password) { | 136 showPassword: function(password) { |
| 125 this.passwordField.value = password; | 137 this.passwordField.value = password; |
| 126 this.passwordField.type = 'text'; | 138 this.passwordField.type = 'text'; |
| 127 | 139 |
| 128 var button = this.passwordShowButton; | 140 var button = this.passwordShowButton; |
| 129 if (button) | 141 if (button) |
| 130 button.textContent = loadTimeData.getString('passwordHideButton'); | 142 button.textContent = loadTimeData.getString('passwordHideButton'); |
| 131 }, | 143 }, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 * @private | 280 * @private |
| 269 */ | 281 */ |
| 270 showPasswords_: true, | 282 showPasswords_: true, |
| 271 | 283 |
| 272 /** @override */ | 284 /** @override */ |
| 273 decorate: function() { | 285 decorate: function() { |
| 274 DeletableItemList.prototype.decorate.call(this); | 286 DeletableItemList.prototype.decorate.call(this); |
| 275 Preferences.getInstance().addEventListener( | 287 Preferences.getInstance().addEventListener( |
| 276 'profile.password_manager_allow_show_passwords', | 288 'profile.password_manager_allow_show_passwords', |
| 277 this.onPreferenceChanged_.bind(this)); | 289 this.onPreferenceChanged_.bind(this)); |
| 290 this.addEventListener('focus', this.onFocusIn_); | |
| 278 }, | 291 }, |
| 279 | 292 |
| 280 /** | 293 /** |
| 281 * Listener for changes on the preference. | 294 * Listener for changes on the preference. |
| 282 * @param {Event} event The preference update event. | 295 * @param {Event} event The preference update event. |
| 283 * @private | 296 * @private |
| 284 */ | 297 */ |
| 285 onPreferenceChanged_: function(event) { | 298 onPreferenceChanged_: function(event) { |
| 286 this.showPasswords_ = event.value.value; | 299 this.showPasswords_ = event.value.value; |
| 287 this.redraw(); | 300 this.redraw(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 309 } | 322 } |
| 310 PasswordManager.removeSavedPassword(index); | 323 PasswordManager.removeSavedPassword(index); |
| 311 }, | 324 }, |
| 312 | 325 |
| 313 /** | 326 /** |
| 314 * The length of the list. | 327 * The length of the list. |
| 315 */ | 328 */ |
| 316 get length() { | 329 get length() { |
| 317 return this.dataModel.length; | 330 return this.dataModel.length; |
| 318 }, | 331 }, |
| 332 | |
| 333 /** | |
| 334 * Will make to first row focusable if none are selected. This makes it | |
| 335 * possible to tab into the rows without pressing up/down first. | |
| 336 * @param {Event} e The focusin event. | |
|
Dan Beam
2015/01/24 02:42:25
this is no longer a focusin event
hcarmona
2015/01/26 19:06:24
Done.
| |
| 337 * @private | |
| 338 */ | |
| 339 onFocusIn_: function(e) { | |
|
Dan Beam
2015/01/24 02:42:24
onFocus_
hcarmona
2015/01/26 19:06:24
Done.
| |
| 340 if (!this.selectedItem && this.items) | |
| 341 this.items[0].setFocusable(true); | |
| 342 }, | |
| 319 }; | 343 }; |
| 320 | 344 |
| 321 /** | 345 /** |
| 322 * Create a new passwords list. | 346 * Create a new passwords list. |
| 323 * @constructor | 347 * @constructor |
| 324 * @extends {options.DeletableItemList} | 348 * @extends {options.DeletableItemList} |
| 325 */ | 349 */ |
| 326 var PasswordExceptionsList = cr.ui.define('list'); | 350 var PasswordExceptionsList = cr.ui.define('list'); |
| 327 | 351 |
| 328 PasswordExceptionsList.prototype = { | 352 PasswordExceptionsList.prototype = { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 349 }, | 373 }, |
| 350 }; | 374 }; |
| 351 | 375 |
| 352 return { | 376 return { |
| 353 PasswordListItem: PasswordListItem, | 377 PasswordListItem: PasswordListItem, |
| 354 PasswordExceptionsListItem: PasswordExceptionsListItem, | 378 PasswordExceptionsListItem: PasswordExceptionsListItem, |
| 355 PasswordsList: PasswordsList, | 379 PasswordsList: PasswordsList, |
| 356 PasswordExceptionsList: PasswordExceptionsList, | 380 PasswordExceptionsList: PasswordExceptionsList, |
| 357 }; | 381 }; |
| 358 }); | 382 }); |
| OLD | NEW |