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); |
| 75 passwordInput.addEventListener('focus', this.handleFocus.bind(this)); | |
|
Dan Beam
2015/01/27 22:22:13
i think this is still confusing, how about:
var
hcarmona
2015/01/28 01:13:36
Done.
| |
| 77 this.passwordField = passwordInput; | 76 this.passwordField = passwordInput; |
| 77 this.setFocusable(false); | |
| 78 | 78 |
| 79 // The show/hide button. | 79 // The show/hide button. |
| 80 if (this.showPasswords_) { | 80 if (this.showPasswords_) { |
| 81 var button = this.ownerDocument.createElement('button'); | 81 var button = this.ownerDocument.createElement('button'); |
| 82 button.hidden = true; | 82 button.hidden = true; |
| 83 button.className = 'list-inline-button custom-appearance'; | 83 button.className = 'list-inline-button custom-appearance'; |
| 84 button.textContent = loadTimeData.getString('passwordShowButton'); | 84 button.textContent = loadTimeData.getString('passwordShowButton'); |
| 85 button.addEventListener('click', this.onClick_.bind(this), true); | 85 button.addEventListener('click', this.onClick_.bind(this), true); |
| 86 button.addEventListener('mousedown', function(event) { | 86 button.addEventListener('mousedown', function(event) { |
| 87 // Don't focus on this button by mousedown. | 87 // Don't focus on this button by mousedown. |
| 88 event.preventDefault(); | 88 event.preventDefault(); |
| 89 // Don't handle list item selection. It causes focus change. | 89 // Don't handle list item selection. It causes focus change. |
| 90 event.stopPropagation(); | 90 event.stopPropagation(); |
| 91 }, false); | 91 }, false); |
| 92 button.addEventListener('focus', this.handleFocus.bind(this)); | |
| 92 passwordInputDiv.appendChild(button); | 93 passwordInputDiv.appendChild(button); |
| 93 this.passwordShowButton = button; | 94 this.passwordShowButton = button; |
| 94 } | 95 } |
| 95 | 96 |
| 96 this.contentElement.appendChild(passwordInputDiv); | 97 this.contentElement.appendChild(passwordInputDiv); |
| 97 }, | 98 }, |
| 98 | 99 |
| 99 /** @override */ | 100 /** @override */ |
| 100 selectionChanged: function() { | 101 selectionChanged: function() { |
| 101 var input = this.passwordField; | 102 var input = this.passwordField; |
| 102 var button = this.passwordShowButton; | 103 var button = this.passwordShowButton; |
| 103 // The button doesn't exist when passwords can't be shown. | 104 // The button doesn't exist when passwords can't be shown. |
| 104 if (!button) | 105 if (!button) |
| 105 return; | 106 return; |
| 106 | 107 |
| 107 if (this.selected) { | 108 if (this.selected) { |
| 109 input.classList.remove('inactive-password'); | |
| 110 this.setFocusable(true); | |
| 111 button.hidden = false; | |
| 108 input.focus(); | 112 input.focus(); |
| 109 input.classList.remove('inactive-password'); | |
| 110 input.tabIndex = 0; | |
| 111 this.closeButtonElement.tabIndex = 0; | |
| 112 button.hidden = false; | |
| 113 } else { | 113 } else { |
| 114 input.classList.add('inactive-password'); | 114 input.classList.add('inactive-password'); |
| 115 input.tabIndex = -1; | 115 this.setFocusable(false); |
| 116 this.closeButtonElement.tabIndex = -1; | |
| 117 button.hidden = true; | 116 button.hidden = true; |
| 118 } | 117 } |
| 119 }, | 118 }, |
| 120 | 119 |
| 121 /** | 120 /** |
| 121 * Set the focusability of this row. | |
| 122 * @param {boolean} focusable | |
|
Dan Beam
2015/01/27 22:22:12
nit: make @private + add _
hcarmona
2015/01/28 01:13:36
Done.
| |
| 123 */ | |
| 124 setFocusable: function(focusable) { | |
| 125 var tabIndex = focusable ? 0 : -1; | |
| 126 this.passwordField.tabIndex = this.closeButtonElement.tabIndex = tabIndex; | |
| 127 }, | |
| 128 | |
| 129 /** | |
| 122 * Reveals the plain text password of this entry. | 130 * Reveals the plain text password of this entry. |
| 123 */ | 131 */ |
| 124 showPassword: function(password) { | 132 showPassword: function(password) { |
| 125 this.passwordField.value = password; | 133 this.passwordField.value = password; |
| 126 this.passwordField.type = 'text'; | 134 this.passwordField.type = 'text'; |
| 127 | 135 |
| 128 var button = this.passwordShowButton; | 136 var button = this.passwordShowButton; |
| 129 if (button) | 137 if (button) |
| 130 button.textContent = loadTimeData.getString('passwordHideButton'); | 138 button.textContent = loadTimeData.getString('passwordHideButton'); |
| 131 }, | 139 }, |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 * @private | 276 * @private |
| 269 */ | 277 */ |
| 270 showPasswords_: true, | 278 showPasswords_: true, |
| 271 | 279 |
| 272 /** @override */ | 280 /** @override */ |
| 273 decorate: function() { | 281 decorate: function() { |
| 274 DeletableItemList.prototype.decorate.call(this); | 282 DeletableItemList.prototype.decorate.call(this); |
| 275 Preferences.getInstance().addEventListener( | 283 Preferences.getInstance().addEventListener( |
| 276 'profile.password_manager_allow_show_passwords', | 284 'profile.password_manager_allow_show_passwords', |
| 277 this.onPreferenceChanged_.bind(this)); | 285 this.onPreferenceChanged_.bind(this)); |
| 286 this.addEventListener('focus', this.onFocus_); | |
|
Dan Beam
2015/01/27 22:22:13
nit: this.onFocus_.bind(this)
hcarmona
2015/01/28 01:13:36
Done.
| |
| 278 }, | 287 }, |
| 279 | 288 |
| 280 /** | 289 /** |
| 281 * Listener for changes on the preference. | 290 * Listener for changes on the preference. |
| 282 * @param {Event} event The preference update event. | 291 * @param {Event} event The preference update event. |
| 283 * @private | 292 * @private |
| 284 */ | 293 */ |
| 285 onPreferenceChanged_: function(event) { | 294 onPreferenceChanged_: function(event) { |
| 286 this.showPasswords_ = event.value.value; | 295 this.showPasswords_ = event.value.value; |
| 287 this.redraw(); | 296 this.redraw(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 309 } | 318 } |
| 310 PasswordManager.removeSavedPassword(index); | 319 PasswordManager.removeSavedPassword(index); |
| 311 }, | 320 }, |
| 312 | 321 |
| 313 /** | 322 /** |
| 314 * The length of the list. | 323 * The length of the list. |
| 315 */ | 324 */ |
| 316 get length() { | 325 get length() { |
| 317 return this.dataModel.length; | 326 return this.dataModel.length; |
| 318 }, | 327 }, |
| 328 | |
| 329 /** | |
| 330 * Will make to first row focusable if none are selected. This makes it | |
| 331 * possible to tab into the rows without pressing up/down first. | |
| 332 * @param {Event} e The focus event. | |
| 333 * @private | |
| 334 */ | |
| 335 onFocus_: function(e) { | |
| 336 if (!this.selectedItem && this.items) | |
| 337 this.items[0].setFocusable(true); | |
| 338 }, | |
| 319 }; | 339 }; |
| 320 | 340 |
| 321 /** | 341 /** |
| 322 * Create a new passwords list. | 342 * Create a new passwords list. |
| 323 * @constructor | 343 * @constructor |
| 324 * @extends {options.DeletableItemList} | 344 * @extends {options.DeletableItemList} |
| 325 */ | 345 */ |
| 326 var PasswordExceptionsList = cr.ui.define('list'); | 346 var PasswordExceptionsList = cr.ui.define('list'); |
| 327 | 347 |
| 328 PasswordExceptionsList.prototype = { | 348 PasswordExceptionsList.prototype = { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 349 }, | 369 }, |
| 350 }; | 370 }; |
| 351 | 371 |
| 352 return { | 372 return { |
| 353 PasswordListItem: PasswordListItem, | 373 PasswordListItem: PasswordListItem, |
| 354 PasswordExceptionsListItem: PasswordExceptionsListItem, | 374 PasswordExceptionsListItem: PasswordExceptionsListItem, |
| 355 PasswordsList: PasswordsList, | 375 PasswordsList: PasswordsList, |
| 356 PasswordExceptionsList: PasswordExceptionsList, | 376 PasswordExceptionsList: PasswordExceptionsList, |
| 357 }; | 377 }; |
| 358 }); | 378 }); |
| OLD | NEW |