 Chromium Code Reviews
 Chromium Code Reviews Issue 6770012:
  Handle the PasswordManagerAllowShowPasswords preference in the options webui.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 6770012:
  Handle the PasswordManagerAllowShowPasswords preference in the options webui.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 ArrayDataModel = cr.ui.ArrayDataModel; | 6 const ArrayDataModel = cr.ui.ArrayDataModel; | 
| 7 const DeletableItemList = options.DeletableItemList; | 7 const DeletableItemList = options.DeletableItemList; | 
| 8 const DeletableItem = options.DeletableItem; | 8 const DeletableItem = options.DeletableItem; | 
| 9 const List = cr.ui.List; | 9 const List = cr.ui.List; | 
| 10 | 10 | 
| 11 /** | 11 /** | 
| 12 * Creates a new passwords list item. | 12 * Creates a new passwords list item. | 
| 13 * @param {Array} entry An array of the form [url, username, password]. | 13 * @param {Array} entry An array of the form [url, username, password]. | 
| 14 * @constructor | 14 * @constructor | 
| 15 * @extends {cr.ui.ListItem} | 15 * @extends {cr.ui.ListItem} | 
| 16 */ | 16 */ | 
| 17 function PasswordListItem(entry) { | 17 function PasswordListItem(entry, showPasswords) { | 
| 18 var el = cr.doc.createElement('div'); | 18 var el = cr.doc.createElement('div'); | 
| 19 el.dataItem = entry; | 19 el.dataItem = entry; | 
| 20 el.__proto__ = PasswordListItem.prototype; | 20 el.__proto__ = PasswordListItem.prototype; | 
| 21 el.decorate(); | 21 el.decorate(showPasswords); | 
| 22 | 22 | 
| 23 return el; | 23 return el; | 
| 24 } | 24 } | 
| 25 | 25 | 
| 26 PasswordListItem.prototype = { | 26 PasswordListItem.prototype = { | 
| 27 __proto__: DeletableItem.prototype, | 27 __proto__: DeletableItem.prototype, | 
| 28 | 28 | 
| 29 /** @inheritDoc */ | 29 /** @inheritDoc */ | 
| 30 decorate: function() { | 30 decorate: function(showPasswords) { | 
| 31 DeletableItem.prototype.decorate.call(this); | 31 DeletableItem.prototype.decorate.call(this); | 
| 32 | 32 | 
| 33 // The URL of the site. | 33 // The URL of the site. | 
| 34 var urlLabel = this.ownerDocument.createElement('div'); | 34 var urlLabel = this.ownerDocument.createElement('div'); | 
| 35 urlLabel.classList.add('favicon-cell'); | 35 urlLabel.classList.add('favicon-cell'); | 
| 36 urlLabel.classList.add('url'); | 36 urlLabel.classList.add('url'); | 
| 37 urlLabel.textContent = this.url; | 37 urlLabel.textContent = this.url; | 
| 38 urlLabel.style.backgroundImage = url('chrome://favicon/' + this.url); | 38 urlLabel.style.backgroundImage = url('chrome://favicon/' + this.url); | 
| 39 this.contentElement.appendChild(urlLabel); | 39 this.contentElement.appendChild(urlLabel); | 
| 40 | 40 | 
| 41 // The stored username. | 41 // The stored username. | 
| 42 var usernameLabel = this.ownerDocument.createElement('div'); | 42 var usernameLabel = this.ownerDocument.createElement('div'); | 
| 43 usernameLabel.className = 'name'; | 43 usernameLabel.className = 'name'; | 
| 44 usernameLabel.textContent = this.username; | 44 usernameLabel.textContent = this.username; | 
| 45 this.contentElement.appendChild(usernameLabel); | 45 this.contentElement.appendChild(usernameLabel); | 
| 46 | 46 | 
| 47 // The stored password. | 47 // The stored password. | 
| 48 var passwordInputDiv = this.ownerDocument.createElement('div'); | 48 var passwordInputDiv = this.ownerDocument.createElement('div'); | 
| 49 passwordInputDiv.className = 'password'; | 49 passwordInputDiv.className = 'password'; | 
| 50 | 50 | 
| 51 // The password input field. | 51 // The password input field. | 
| 52 var passwordInput = this.ownerDocument.createElement('input'); | 52 var passwordInput = this.ownerDocument.createElement('input'); | 
| 53 passwordInput.type = 'password'; | 53 passwordInput.type = 'password'; | 
| 54 passwordInput.className = 'inactive-password'; | 54 passwordInput.className = 'inactive-password'; | 
| 55 passwordInput.readOnly = true; | 55 passwordInput.readOnly = true; | 
| 56 passwordInput.value = this.password; | 56 passwordInput.value = showPasswords ? this.password : "********"; | 
| 57 passwordInputDiv.appendChild(passwordInput); | 57 passwordInputDiv.appendChild(passwordInput); | 
| 58 | 58 | 
| 59 // The show/hide button. | 59 // The show/hide button. | 
| 60 var button = this.ownerDocument.createElement('button'); | 60 if (showPasswords) { | 
| 61 button.classList.add('hidden'); | 61 var button = this.ownerDocument.createElement('button'); | 
| 62 button.classList.add('password-button'); | 62 button.classList.add('hidden'); | 
| 63 button.textContent = localStrings.getString('passwordShowButton'); | 63 button.classList.add('password-button'); | 
| 64 button.addEventListener('click', this.onClick_, true); | 64 button.textContent = localStrings.getString('passwordShowButton'); | 
| 65 passwordInputDiv.appendChild(button); | 65 button.addEventListener('click', this.onClick_, true); | 
| 66 passwordInputDiv.appendChild(button); | |
| 67 } | |
| 66 | 68 | 
| 67 this.contentElement.appendChild(passwordInputDiv); | 69 this.contentElement.appendChild(passwordInputDiv); | 
| 68 }, | 70 }, | 
| 69 | 71 | 
| 70 /** @inheritDoc */ | 72 /** @inheritDoc */ | 
| 71 selectionChanged: function() { | 73 selectionChanged: function() { | 
| 72 var passwordInput = this.querySelector('input[type=password]'); | 74 var passwordInput = this.querySelector('input[type=password]'); | 
| 73 var textInput = this.querySelector('input[type=text]'); | 75 var textInput = this.querySelector('input[type=text]'); | 
| 74 var input = passwordInput || textInput; | 76 var input = passwordInput || textInput; | 
| 75 var button = input.nextSibling; | 77 var button = input.nextSibling; | 
| 78 // button doesn't exist when passwords can't be shown. | |
| 
James Hawkins
2011/04/11 17:13:26
nit: |button|
 | |
| 79 if (!button) | |
| 80 return; | |
| 76 if (this.selected) { | 81 if (this.selected) { | 
| 77 input.classList.remove('inactive-password'); | 82 input.classList.remove('inactive-password'); | 
| 78 button.classList.remove('hidden'); | 83 button.classList.remove('hidden'); | 
| 79 } else { | 84 } else { | 
| 80 input.classList.add('inactive-password'); | 85 input.classList.add('inactive-password'); | 
| 81 button.classList.add('hidden'); | 86 button.classList.add('hidden'); | 
| 82 } | 87 } | 
| 83 }, | 88 }, | 
| 84 | 89 | 
| 85 /** | 90 /** | 
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 /** | 187 /** | 
| 183 * Create a new passwords list. | 188 * Create a new passwords list. | 
| 184 * @constructor | 189 * @constructor | 
| 185 * @extends {cr.ui.List} | 190 * @extends {cr.ui.List} | 
| 186 */ | 191 */ | 
| 187 var PasswordsList = cr.ui.define('list'); | 192 var PasswordsList = cr.ui.define('list'); | 
| 188 | 193 | 
| 189 PasswordsList.prototype = { | 194 PasswordsList.prototype = { | 
| 190 __proto__: DeletableItemList.prototype, | 195 __proto__: DeletableItemList.prototype, | 
| 191 | 196 | 
| 197 /** | |
| 198 * Whether passwords can be revealed or not. | |
| 199 * @type {boolean} | |
| 200 * @private | |
| 201 */ | |
| 202 showPasswords_: true, | |
| 203 | |
| 192 /** @inheritDoc */ | 204 /** @inheritDoc */ | 
| 193 createItem: function(entry) { | 205 decorate: function() { | 
| 194 return new PasswordListItem(entry); | 206 DeletableItemList.prototype.decorate.call(this); | 
| 207 Preferences.getInstance().addEventListener( | |
| 208 "profile.password_manager_allow_show_passwords", | |
| 209 this.onPreferenceChanged_.bind(this)); | |
| 210 }, | |
| 211 | |
| 212 /** | |
| 213 * Listener for changes on the preference. | |
| 214 * @param {Event} event The preference update event. | |
| 215 * @private | |
| 216 */ | |
| 217 onPreferenceChanged_: function(event) { | |
| 218 this.showPasswords_ = event.value.value; | |
| 219 this.redraw(); | |
| 195 }, | 220 }, | 
| 196 | 221 | 
| 197 /** @inheritDoc */ | 222 /** @inheritDoc */ | 
| 223 createItem: function(entry) { | |
| 224 return new PasswordListItem(entry, this.showPasswords_); | |
| 225 }, | |
| 226 | |
| 227 /** @inheritDoc */ | |
| 198 deleteItemAtIndex: function(index) { | 228 deleteItemAtIndex: function(index) { | 
| 199 PasswordManager.removeSavedPassword(index); | 229 PasswordManager.removeSavedPassword(index); | 
| 200 }, | 230 }, | 
| 201 | 231 | 
| 202 /** | 232 /** | 
| 203 * The length of the list. | 233 * The length of the list. | 
| 204 */ | 234 */ | 
| 205 get length() { | 235 get length() { | 
| 206 return this.dataModel.length; | 236 return this.dataModel.length; | 
| 207 }, | 237 }, | 
| (...skipping 27 matching lines...) Expand all Loading... | |
| 235 }, | 265 }, | 
| 236 }; | 266 }; | 
| 237 | 267 | 
| 238 return { | 268 return { | 
| 239 PasswordListItem: PasswordListItem, | 269 PasswordListItem: PasswordListItem, | 
| 240 PasswordExceptionsListItem: PasswordExceptionsListItem, | 270 PasswordExceptionsListItem: PasswordExceptionsListItem, | 
| 241 PasswordsList: PasswordsList, | 271 PasswordsList: PasswordsList, | 
| 242 PasswordExceptionsList: PasswordExceptionsList, | 272 PasswordExceptionsList: PasswordExceptionsList, | 
| 243 }; | 273 }; | 
| 244 }); | 274 }); | 
| OLD | NEW |