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 |
| 11 /** | 11 /** |
| 12 * Creates a new passwords list item. | 12 * Creates a new passwords list item. |
| 13 * @param {cr.ui.ArrayDataModel} dataModel The data model that contains this | 13 * @param {cr.ui.ArrayDataModel} dataModel The data model that contains this |
| 14 * item. | 14 * item. |
| 15 * @param {Array} entry An array of the form [url, username, password]. When | 15 * @param {Array} entry An array of the form [url, username, password, |
| 16 * the list has been filtered, a fourth element [index] may be present. | 16 * federation]. When the list has been filtered, a fifth element [index] |
| 17 * may be present. | |
|
Dan Beam
2015/03/03 22:49:54
nit:
/** @const {number} */ var URL_DATA_INDEX
| |
| 17 * @param {boolean} showPasswords If true, add a button to the element to | 18 * @param {boolean} showPasswords If true, add a button to the element to |
| 18 * allow the user to reveal the saved password. | 19 * allow the user to reveal the saved password. |
| 19 * @constructor | 20 * @constructor |
| 20 * @extends {options.DeletableItem} | 21 * @extends {options.DeletableItem} |
| 21 */ | 22 */ |
| 22 function PasswordListItem(dataModel, entry, showPasswords) { | 23 function PasswordListItem(dataModel, entry, showPasswords) { |
| 23 var el = cr.doc.createElement('div'); | 24 var el = cr.doc.createElement('div'); |
| 24 el.dataItem = entry; | 25 el.dataItem = entry; |
| 25 el.dataModel = dataModel; | 26 el.dataModel = dataModel; |
| 26 el.__proto__ = PasswordListItem.prototype; | 27 el.__proto__ = PasswordListItem.prototype; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 54 'origin/' + this.url, 16); | 55 'origin/' + this.url, 16); |
| 55 this.contentElement.appendChild(urlLabel); | 56 this.contentElement.appendChild(urlLabel); |
| 56 | 57 |
| 57 // The stored username. | 58 // The stored username. |
| 58 var usernameLabel = this.ownerDocument.createElement('div'); | 59 var usernameLabel = this.ownerDocument.createElement('div'); |
| 59 usernameLabel.className = 'name'; | 60 usernameLabel.className = 'name'; |
| 60 usernameLabel.textContent = this.username; | 61 usernameLabel.textContent = this.username; |
| 61 usernameLabel.title = this.username; | 62 usernameLabel.title = this.username; |
| 62 this.contentElement.appendChild(usernameLabel); | 63 this.contentElement.appendChild(usernameLabel); |
| 63 | 64 |
| 64 // The stored password. | 65 if (this.federation) { |
| 65 var passwordInputDiv = this.ownerDocument.createElement('div'); | 66 // The federation. |
| 66 passwordInputDiv.className = 'password'; | 67 var federationDiv = this.ownerDocument.createElement('div'); |
| 68 federationDiv.className = 'federation'; | |
| 69 federationDiv.textContent = this.federation; | |
| 70 this.contentElement.appendChild(federationDiv); | |
| 71 } else { | |
| 72 // The stored password. | |
| 73 var passwordInputDiv = this.ownerDocument.createElement('div'); | |
| 74 passwordInputDiv.className = 'password'; | |
| 67 | 75 |
| 68 // The password input field. | 76 // The password input field. |
| 69 var passwordInput = this.ownerDocument.createElement('input'); | 77 var passwordInput = this.ownerDocument.createElement('input'); |
| 70 passwordInput.type = 'password'; | 78 passwordInput.type = 'password'; |
| 71 passwordInput.className = 'inactive-password'; | 79 passwordInput.className = 'inactive-password'; |
| 72 passwordInput.readOnly = true; | 80 passwordInput.readOnly = true; |
| 73 passwordInput.value = this.showPasswords_ ? this.password : '********'; | 81 passwordInput.value = this.showPasswords_ ? this.password : '********'; |
| 74 passwordInputDiv.appendChild(passwordInput); | 82 passwordInputDiv.appendChild(passwordInput); |
| 75 var deletableItem = this; | 83 var deletableItem = this; |
| 76 passwordInput.addEventListener('focus', function() { | 84 passwordInput.addEventListener('focus', function() { |
| 77 deletableItem.handleFocus(); | |
| 78 }); | |
| 79 this.passwordField = passwordInput; | |
| 80 this.setFocusable_(false); | |
| 81 | |
| 82 // The show/hide button. | |
| 83 if (this.showPasswords_) { | |
| 84 var button = this.ownerDocument.createElement('button'); | |
| 85 button.hidden = true; | |
| 86 button.className = 'list-inline-button custom-appearance'; | |
| 87 button.textContent = loadTimeData.getString('passwordShowButton'); | |
| 88 button.addEventListener('click', this.onClick_.bind(this), true); | |
| 89 button.addEventListener('mousedown', function(event) { | |
| 90 // Don't focus on this button by mousedown. | |
| 91 event.preventDefault(); | |
| 92 // Don't handle list item selection. It causes focus change. | |
| 93 event.stopPropagation(); | |
| 94 }, false); | |
| 95 button.addEventListener('focus', function() { | |
| 96 deletableItem.handleFocus(); | 85 deletableItem.handleFocus(); |
| 97 }); | 86 }); |
| 98 passwordInputDiv.appendChild(button); | 87 this.passwordField = passwordInput; |
| 99 this.passwordShowButton = button; | 88 this.setFocusable_(false); |
| 89 | |
| 90 // The show/hide button. | |
| 91 if (this.showPasswords_) { | |
| 92 var button = this.ownerDocument.createElement('button'); | |
| 93 button.hidden = true; | |
| 94 button.className = 'list-inline-button custom-appearance'; | |
| 95 button.textContent = loadTimeData.getString('passwordShowButton'); | |
| 96 button.addEventListener('click', this.onClick_.bind(this), true); | |
| 97 button.addEventListener('mousedown', function(event) { | |
| 98 // Don't focus on this button by mousedown. | |
| 99 event.preventDefault(); | |
| 100 // Don't handle list item selection. It causes focus change. | |
| 101 event.stopPropagation(); | |
| 102 }, false); | |
| 103 button.addEventListener('focus', function() { | |
| 104 deletableItem.handleFocus(); | |
| 105 }); | |
| 106 passwordInputDiv.appendChild(button); | |
| 107 this.passwordShowButton = button; | |
| 108 } | |
| 109 this.contentElement.appendChild(passwordInputDiv); | |
| 100 } | 110 } |
| 101 | 111 |
| 102 this.contentElement.appendChild(passwordInputDiv); | |
| 103 }, | 112 }, |
| 104 | 113 |
| 105 /** @override */ | 114 /** @override */ |
| 106 selectionChanged: function() { | 115 selectionChanged: function() { |
| 107 var input = this.passwordField; | 116 var input = this.passwordField; |
| 108 var button = this.passwordShowButton; | 117 var button = this.passwordShowButton; |
| 109 // The button doesn't exist when passwords can't be shown. | 118 // The button doesn't exist when passwords can't be shown. |
| 110 if (!button) | 119 if (!button) |
| 111 return; | 120 return; |
| 112 | 121 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 if (button) | 163 if (button) |
| 155 button.textContent = loadTimeData.getString('passwordShowButton'); | 164 button.textContent = loadTimeData.getString('passwordShowButton'); |
| 156 }, | 165 }, |
| 157 | 166 |
| 158 /** | 167 /** |
| 159 * Get the original index of this item in the data model. | 168 * Get the original index of this item in the data model. |
| 160 * @return {number} The index. | 169 * @return {number} The index. |
| 161 * @private | 170 * @private |
| 162 */ | 171 */ |
| 163 getOriginalIndex_: function() { | 172 getOriginalIndex_: function() { |
| 164 var index = this.dataItem[3]; | 173 var index = this.dataItem[4]; |
| 165 return index ? index : this.dataModel.indexOf(this.dataItem); | 174 return index ? index : this.dataModel.indexOf(this.dataItem); |
| 166 }, | 175 }, |
| 167 | 176 |
| 168 /** | 177 /** |
| 169 * On-click event handler. Swaps the type of the input field from password | 178 * On-click event handler. Swaps the type of the input field from password |
| 170 * to text and back. | 179 * to text and back. |
| 171 * @private | 180 * @private |
| 172 */ | 181 */ |
| 173 onClick_: function(event) { | 182 onClick_: function(event) { |
| 174 if (this.passwordField.type == 'password') { | 183 if (this.passwordField.type == 'password') { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 204 /** | 213 /** |
| 205 * Get and set the password for the entry. | 214 * Get and set the password for the entry. |
| 206 * @type {string} | 215 * @type {string} |
| 207 */ | 216 */ |
| 208 get password() { | 217 get password() { |
| 209 return this.dataItem[2]; | 218 return this.dataItem[2]; |
| 210 }, | 219 }, |
| 211 set password(password) { | 220 set password(password) { |
| 212 this.dataItem[2] = password; | 221 this.dataItem[2] = password; |
| 213 }, | 222 }, |
| 223 | |
| 224 /** | |
| 225 * Get and set the federation for the entry. | |
| 226 * @type {string} | |
| 227 */ | |
| 228 get federation() { | |
| 229 return this.dataItem[3]; | |
| 230 }, | |
| 231 set federation(federation) { | |
| 232 this.dataItem[3] = password; | |
| 233 }, | |
| 214 }; | 234 }; |
| 215 | 235 |
| 216 /** | 236 /** |
| 217 * Creates a new PasswordExceptions list item. | 237 * Creates a new PasswordExceptions list item. |
| 218 * @param {Array} entry A pair of the form [url, username]. | 238 * @param {Array} entry A pair of the form [url, username]. |
| 219 * @constructor | 239 * @constructor |
| 220 * @extends {options.DeletableItem} | 240 * @extends {options.DeletableItem} |
| 221 */ | 241 */ |
| 222 function PasswordExceptionsListItem(entry) { | 242 function PasswordExceptionsListItem(entry) { |
| 223 var el = cr.doc.createElement('div'); | 243 var el = cr.doc.createElement('div'); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 | 331 |
| 312 if (loadTimeData.getBoolean('disableShowPasswords')) | 332 if (loadTimeData.getBoolean('disableShowPasswords')) |
| 313 showPasswords = false; | 333 showPasswords = false; |
| 314 | 334 |
| 315 return new PasswordListItem(this.dataModel, entry, showPasswords); | 335 return new PasswordListItem(this.dataModel, entry, showPasswords); |
| 316 }, | 336 }, |
| 317 | 337 |
| 318 /** @override */ | 338 /** @override */ |
| 319 deleteItemAtIndex: function(index) { | 339 deleteItemAtIndex: function(index) { |
| 320 var item = this.dataModel.item(index); | 340 var item = this.dataModel.item(index); |
| 321 if (item && item.length > 3) { | 341 if (item && item.length > 4) { |
|
Dan Beam
2015/03/03 22:49:54
nit:
if (item && item[FEDERATION_INDEX]) { //
| |
| 322 // The fourth element, if present, is the original index to delete. | 342 // The fifth element, if present, is the original index to delete. |
| 323 index = item[3]; | 343 index = item[4]; |
| 324 } | 344 } |
| 325 PasswordManager.removeSavedPassword(index); | 345 PasswordManager.removeSavedPassword(index); |
| 326 }, | 346 }, |
| 327 | 347 |
| 328 /** | 348 /** |
| 329 * The length of the list. | 349 * The length of the list. |
| 330 */ | 350 */ |
| 331 get length() { | 351 get length() { |
| 332 return this.dataModel.length; | 352 return this.dataModel.length; |
| 333 }, | 353 }, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 }, | 395 }, |
| 376 }; | 396 }; |
| 377 | 397 |
| 378 return { | 398 return { |
| 379 PasswordListItem: PasswordListItem, | 399 PasswordListItem: PasswordListItem, |
| 380 PasswordExceptionsListItem: PasswordExceptionsListItem, | 400 PasswordExceptionsListItem: PasswordExceptionsListItem, |
| 381 PasswordsList: PasswordsList, | 401 PasswordsList: PasswordsList, |
| 382 PasswordExceptionsList: PasswordExceptionsList, | 402 PasswordExceptionsList: PasswordExceptionsList, |
| 383 }; | 403 }; |
| 384 }); | 404 }); |
| OLD | NEW |