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