| 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; | 11 /** @const */ var URL_DATA_INDEX = 0; |
| 12 /** @const */ var USERNAME_DATA_INDEX = 1; | 12 /** @const */ var SHOWN_URL_DATA_INDEX = 1; |
| 13 /** @const */ var PASSWORD_DATA_INDEX = 2; | 13 /** @const */ var IS_URL_SECURE_DATA_INDEX = 2; |
| 14 /** @const */ var FEDERATION_DATA_INDEX = 3; | 14 /** @const */ var USERNAME_DATA_INDEX = 3; |
| 15 /** @const */ var ORIGINAL_DATA_INDEX = 4; | 15 /** @const */ var PASSWORD_DATA_INDEX = 4; |
| 16 /** @const */ var FEDERATION_DATA_INDEX = 5; |
| 17 /** @const */ var ORIGINAL_DATA_INDEX = 6; |
| 16 | 18 |
| 17 /** | 19 /** |
| 18 * Creates a new passwords list item. | 20 * Creates a new passwords list item. |
| 19 * @param {cr.ui.ArrayDataModel} dataModel The data model that contains this | 21 * @param {cr.ui.ArrayDataModel} dataModel The data model that contains this |
| 20 * item. | 22 * item. |
| 21 * @param {Array} entry An array of the form [url, username, password, | 23 * @param {Array} entry An array of the form [url, username, password, |
| 22 * federation]. When the list has been filtered, a fifth element [index] | 24 * federation]. When the list has been filtered, a fifth element [index] |
| 23 * may be present. | 25 * may be present. |
| 24 * @param {boolean} showPasswords If true, add a button to the element to | 26 * @param {boolean} showPasswords If true, add a button to the element to |
| 25 * allow the user to reveal the saved password. | 27 * allow the user to reveal the saved password. |
| 26 * @constructor | 28 * @constructor |
| 27 * @extends {options.DeletableItem} | 29 * @extends {options.DeletableItem} |
| 28 */ | 30 */ |
| 29 function PasswordListItem(dataModel, entry, showPasswords) { | 31 function PasswordListItem(dataModel, entry, showPasswords) { |
| 30 var el = cr.doc.createElement('div'); | 32 var el = cr.doc.createElement('div'); |
| 31 el.dataItem = entry; | 33 el.dataItem = entry; |
| 32 el.dataModel = dataModel; | 34 el.dataModel = dataModel; |
| 33 el.__proto__ = PasswordListItem.prototype; | 35 el.__proto__ = PasswordListItem.prototype; |
| 34 el.showPasswords_ = showPasswords; | 36 el.showPasswords_ = showPasswords; |
| 35 el.decorate(); | 37 el.decorate(); |
| 36 | 38 |
| 37 return el; | 39 return el; |
| 38 } | 40 } |
| 39 | 41 |
| 40 PasswordListItem.prototype = { | 42 PasswordListItem.prototype = { |
| 41 __proto__: DeletableItem.prototype, | 43 __proto__: DeletableItem.prototype, |
| 42 | 44 |
| 45 |
| 43 /** @override */ | 46 /** @override */ |
| 44 decorate: function() { | 47 decorate: function() { |
| 45 DeletableItem.prototype.decorate.call(this); | 48 DeletableItem.prototype.decorate.call(this); |
| 46 | 49 |
| 47 // The URL of the site. | 50 // The URL of the site. |
| 48 var urlLabel = this.ownerDocument.createElement('div'); | 51 var urlDiv = this.ownerDocument.createElement('div'); |
| 49 urlLabel.classList.add('favicon-cell'); | 52 urlDiv.className = 'favicon-cell left-elided-url url'; |
| 50 urlLabel.classList.add('weakrtl'); | 53 urlDiv.setAttribute('title', this.url); |
| 51 urlLabel.classList.add('url'); | 54 var urlLink = this.ownerDocument.createElement('a'); |
| 52 urlLabel.setAttribute('title', this.url); | 55 urlLink.href = this.url; |
| 53 urlLabel.textContent = this.url; | 56 urlLink.textContent = this.shownUrl.split('').reverse().join(''); |
| 57 urlDiv.appendChild(urlLink); |
| 54 | 58 |
| 55 // The favicon URL is prefixed with "origin/", which essentially removes | 59 // The favicon URL is prefixed with "origin/", which essentially removes |
| 56 // the URL path past the top-level domain and ensures that a scheme (e.g., | 60 // the URL path past the top-level domain and ensures that a scheme (e.g., |
| 57 // http) is being used. This ensures that the favicon returned is the | 61 // http) is being used. This ensures that the favicon returned is the |
| 58 // default favicon for the domain and that the URL has a scheme if none | 62 // default favicon for the domain and that the URL has a scheme if none |
| 59 // is present in the password manager. | 63 // is present in the password manager. |
| 60 urlLabel.style.backgroundImage = getFaviconImageSet( | 64 if (this.isUrlSecure) { |
| 61 'origin/' + this.url, 16); | 65 urlDiv.style.backgroundImage = getFaviconImageSet( |
| 62 this.contentElement.appendChild(urlLabel); | 66 'origin/' + this.url, 16); |
| 67 } |
| 68 this.contentElement.appendChild(urlDiv); |
| 63 | 69 |
| 64 // The stored username. | 70 // The stored username. |
| 65 var usernameLabel = this.ownerDocument.createElement('div'); | 71 var usernameDiv = this.ownerDocument.createElement('div'); |
| 66 usernameLabel.className = 'name'; | 72 usernameDiv.className = 'name'; |
| 67 usernameLabel.textContent = this.username; | 73 usernameDiv.title = this.username; |
| 68 usernameLabel.title = this.username; | 74 this.contentElement.appendChild(usernameDiv); |
| 69 this.contentElement.appendChild(usernameLabel); | 75 var usernameInput = this.ownerDocument.createElement('input'); |
| 76 usernameInput.type = 'text'; |
| 77 usernameInput.className = 'inactive-item'; |
| 78 usernameInput.readOnly = true; |
| 79 usernameInput.value = this.username; |
| 80 usernameDiv.appendChild(usernameInput); |
| 81 this.usernameField = usernameInput; |
| 70 | 82 |
| 71 if (this.federation) { | 83 if (this.federation) { |
| 72 // The federation. | 84 // The federation. |
| 73 var federationDiv = this.ownerDocument.createElement('div'); | 85 var federationDiv = this.ownerDocument.createElement('div'); |
| 74 federationDiv.className = 'federation'; | 86 federationDiv.className = 'federation'; |
| 75 federationDiv.textContent = this.federation; | 87 federationDiv.textContent = this.federation; |
| 76 this.contentElement.appendChild(federationDiv); | 88 this.contentElement.appendChild(federationDiv); |
| 77 } else { | 89 } else { |
| 78 // The stored password. | 90 // The stored password. |
| 79 var passwordInputDiv = this.ownerDocument.createElement('div'); | 91 var passwordInputDiv = this.ownerDocument.createElement('div'); |
| 80 passwordInputDiv.className = 'password'; | 92 passwordInputDiv.className = 'password'; |
| 81 | 93 |
| 82 // The password input field. | 94 // The password input field. |
| 83 var passwordInput = this.ownerDocument.createElement('input'); | 95 var passwordInput = this.ownerDocument.createElement('input'); |
| 84 passwordInput.type = 'password'; | 96 passwordInput.type = 'password'; |
| 85 passwordInput.className = 'inactive-password'; | 97 passwordInput.className = 'inactive-item'; |
| 86 passwordInput.readOnly = true; | 98 passwordInput.readOnly = true; |
| 87 passwordInput.value = this.showPasswords_ ? this.password : '********'; | 99 passwordInput.value = this.showPasswords_ ? this.password : '********'; |
| 88 passwordInputDiv.appendChild(passwordInput); | 100 passwordInputDiv.appendChild(passwordInput); |
| 89 var deletableItem = this; | 101 var deletableItem = this; |
| 90 passwordInput.addEventListener('focus', function() { | 102 passwordInput.addEventListener('focus', function() { |
| 91 deletableItem.handleFocus(); | 103 deletableItem.handleFocus(); |
| 92 }); | 104 }); |
| 93 this.passwordField = passwordInput; | 105 this.passwordField = passwordInput; |
| 94 this.setFocusable_(false); | 106 this.setFocusable_(false); |
| 95 | 107 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 107 event.stopPropagation(); | 119 event.stopPropagation(); |
| 108 }, false); | 120 }, false); |
| 109 button.addEventListener('focus', function() { | 121 button.addEventListener('focus', function() { |
| 110 deletableItem.handleFocus(); | 122 deletableItem.handleFocus(); |
| 111 }); | 123 }); |
| 112 passwordInputDiv.appendChild(button); | 124 passwordInputDiv.appendChild(button); |
| 113 this.passwordShowButton = button; | 125 this.passwordShowButton = button; |
| 114 } | 126 } |
| 115 this.contentElement.appendChild(passwordInputDiv); | 127 this.contentElement.appendChild(passwordInputDiv); |
| 116 } | 128 } |
| 117 | |
| 118 }, | 129 }, |
| 119 | 130 |
| 120 /** @override */ | 131 /** @override */ |
| 121 selectionChanged: function() { | 132 selectionChanged: function() { |
| 122 var input = this.passwordField; | 133 var usernameInput = this.usernameField; |
| 134 var passwordInput = this.passwordField; |
| 123 var button = this.passwordShowButton; | 135 var button = this.passwordShowButton; |
| 124 // The button doesn't exist when passwords can't be shown. | 136 // The button doesn't exist when passwords can't be shown. |
| 125 if (!button) | 137 if (!button) |
| 126 return; | 138 return; |
| 127 | 139 |
| 128 if (this.selected) { | 140 if (this.selected) { |
| 129 input.classList.remove('inactive-password'); | 141 usernameInput.classList.remove('inactive-item'); |
| 142 passwordInput.classList.remove('inactive-item'); |
| 130 this.setFocusable_(true); | 143 this.setFocusable_(true); |
| 131 button.hidden = false; | 144 button.hidden = false; |
| 132 input.focus(); | 145 passwordInput.focus(); |
| 133 } else { | 146 } else { |
| 134 input.classList.add('inactive-password'); | 147 usernameInput.classList.add('inactive-item'); |
| 148 passwordInput.classList.add('inactive-item'); |
| 135 this.setFocusable_(false); | 149 this.setFocusable_(false); |
| 136 button.hidden = true; | 150 button.hidden = true; |
| 137 } | 151 } |
| 138 }, | 152 }, |
| 139 | 153 |
| 140 /** | 154 /** |
| 141 * Set the focusability of this row. | 155 * Set the focusability of this row. |
| 142 * @param {boolean} focusable | 156 * @param {boolean} focusable |
| 143 * @private | 157 * @private |
| 144 */ | 158 */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 * @type {string} | 213 * @type {string} |
| 200 */ | 214 */ |
| 201 get url() { | 215 get url() { |
| 202 return this.dataItem[URL_DATA_INDEX]; | 216 return this.dataItem[URL_DATA_INDEX]; |
| 203 }, | 217 }, |
| 204 set url(url) { | 218 set url(url) { |
| 205 this.dataItem[URL_DATA_INDEX] = url; | 219 this.dataItem[URL_DATA_INDEX] = url; |
| 206 }, | 220 }, |
| 207 | 221 |
| 208 /** | 222 /** |
| 223 * Get and set the shown url for the entry. |
| 224 * @type {string} |
| 225 */ |
| 226 get shownUrl() { |
| 227 return this.dataItem[SHOWN_URL_DATA_INDEX]; |
| 228 }, |
| 229 set shownUrl(shownUrl) { |
| 230 this.dataItem[SHOWN_URL_DATA_INDEX] = shownUrl; |
| 231 }, |
| 232 |
| 233 /** |
| 234 * Get and set whether the origin uses secure scheme. |
| 235 * @type {boolean} |
| 236 */ |
| 237 get isUrlSecure() { |
| 238 return this.dataItem[IS_URL_SECURE_DATA_INDEX]; |
| 239 }, |
| 240 set isUrlSecure(isUrlSecure) { |
| 241 this.dataItem[IS_URL_SECURE_DATA_INDEX] = isUrlSecure; |
| 242 }, |
| 243 |
| 244 /** |
| 209 * Get and set the username for the entry. | 245 * Get and set the username for the entry. |
| 210 * @type {string} | 246 * @type {string} |
| 211 */ | 247 */ |
| 212 get username() { | 248 get username() { |
| 213 return this.dataItem[USERNAME_DATA_INDEX]; | 249 return this.dataItem[USERNAME_DATA_INDEX]; |
| 214 }, | 250 }, |
| 215 set username(username) { | 251 set username(username) { |
| 216 this.dataItem[USERNAME_DATA_INDEX] = username; | 252 this.dataItem[USERNAME_DATA_INDEX] = username; |
| 217 }, | 253 }, |
| 218 | 254 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 PasswordExceptionsListItem.prototype = { | 293 PasswordExceptionsListItem.prototype = { |
| 258 __proto__: DeletableItem.prototype, | 294 __proto__: DeletableItem.prototype, |
| 259 | 295 |
| 260 /** | 296 /** |
| 261 * Call when an element is decorated as a list item. | 297 * Call when an element is decorated as a list item. |
| 262 */ | 298 */ |
| 263 decorate: function() { | 299 decorate: function() { |
| 264 DeletableItem.prototype.decorate.call(this); | 300 DeletableItem.prototype.decorate.call(this); |
| 265 | 301 |
| 266 // The URL of the site. | 302 // The URL of the site. |
| 267 var urlLabel = this.ownerDocument.createElement('div'); | 303 var urlDiv = this.ownerDocument.createElement('div'); |
| 268 urlLabel.className = 'url'; | 304 urlDiv.className = 'url'; |
| 269 urlLabel.classList.add('favicon-cell'); | 305 urlDiv.classList.add('favicon-cell'); |
| 270 urlLabel.classList.add('weakrtl'); | 306 urlDiv.classList.add('left-elided-url'); |
| 271 urlLabel.textContent = this.url; | 307 urlDiv.setAttribute('title', this.url); |
| 308 var urlLink = this.ownerDocument.createElement('a'); |
| 309 urlLink.href = this.url; |
| 310 urlLink.textContent = this.shownUrl.split('').reverse().join(''); |
| 311 urlDiv.appendChild(urlLink); |
| 272 | 312 |
| 273 // The favicon URL is prefixed with "origin/", which essentially removes | 313 // The favicon URL is prefixed with "origin/", which essentially removes |
| 274 // the URL path past the top-level domain and ensures that a scheme (e.g., | 314 // the URL path past the top-level domain and ensures that a scheme (e.g., |
| 275 // http) is being used. This ensures that the favicon returned is the | 315 // http) is being used. This ensures that the favicon returned is the |
| 276 // default favicon for the domain and that the URL has a scheme if none | 316 // default favicon for the domain and that the URL has a scheme if none |
| 277 // is present in the password manager. | 317 // is present in the password manager. |
| 278 urlLabel.style.backgroundImage = getFaviconImageSet( | 318 if (this.isUrlSecure) { |
| 279 'origin/' + this.url, 16); | 319 urlDiv.style.backgroundImage = getFaviconImageSet( |
| 280 this.contentElement.appendChild(urlLabel); | 320 'origin/' + this.url, 16); |
| 321 } |
| 322 this.contentElement.appendChild(urlDiv); |
| 281 }, | 323 }, |
| 282 | 324 |
| 283 /** | 325 /** |
| 284 * Get the url for the entry. | 326 * Get the url for the entry. |
| 285 * @type {string} | 327 * @type {string} |
| 286 */ | 328 */ |
| 287 get url() { | 329 get url() { |
| 288 return this.dataItem; | 330 return this.dataItem[URL_DATA_INDEX]; |
| 289 }, | 331 }, |
| 290 set url(url) { | 332 set url(url) { |
| 291 this.dataItem = url; | 333 this.dataItem[URL_DATA_INDEX] = url; |
| 334 }, |
| 335 |
| 336 /** |
| 337 * Get and set the shown url for the entry. |
| 338 * @type {string} |
| 339 */ |
| 340 get shownUrl() { |
| 341 return this.dataItem[SHOWN_URL_DATA_INDEX]; |
| 342 }, |
| 343 set shownUrl(shownUrl) { |
| 344 this.dataItem[SHOWN_URL_DATA_INDEX] = shownUrl; |
| 345 }, |
| 346 |
| 347 /** |
| 348 * Get and set whether the origin uses secure scheme. |
| 349 * @type {boolean} |
| 350 */ |
| 351 get isUrlSecure() { |
| 352 return this.dataItem[IS_URL_SECURE_DATA_INDEX]; |
| 353 }, |
| 354 set isUrlSecure(isUrlSecure) { |
| 355 this.dataItem[IS_URL_SECURE_DATA_INDEX] = isUrlSecure; |
| 292 }, | 356 }, |
| 293 }; | 357 }; |
| 294 | 358 |
| 295 /** | 359 /** |
| 296 * Create a new passwords list. | 360 * Create a new passwords list. |
| 297 * @constructor | 361 * @constructor |
| 298 * @extends {options.DeletableItemList} | 362 * @extends {options.DeletableItemList} |
| 299 */ | 363 */ |
| 300 var PasswordsList = cr.ui.define('list'); | 364 var PasswordsList = cr.ui.define('list'); |
| 301 | 365 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 get length() { | 463 get length() { |
| 400 return this.dataModel.length; | 464 return this.dataModel.length; |
| 401 }, | 465 }, |
| 402 }; | 466 }; |
| 403 | 467 |
| 404 return { | 468 return { |
| 405 PasswordListItem: PasswordListItem, | 469 PasswordListItem: PasswordListItem, |
| 406 PasswordExceptionsListItem: PasswordExceptionsListItem, | 470 PasswordExceptionsListItem: PasswordExceptionsListItem, |
| 407 PasswordsList: PasswordsList, | 471 PasswordsList: PasswordsList, |
| 408 PasswordExceptionsList: PasswordExceptionsList, | 472 PasswordExceptionsList: PasswordExceptionsList, |
| 473 URL_DATA_INDEX: URL_DATA_INDEX, |
| 474 SHOWN_URL_DATA_INDEX: SHOWN_URL_DATA_INDEX, |
| 475 IS_URL_SECURE_DATA_INDEX: IS_URL_SECURE_DATA_INDEX, |
| 476 USERNAME_DATA_INDEX: USERNAME_DATA_INDEX, |
| 477 PASSWORD_DATA_INDEX: PASSWORD_DATA_INDEX, |
| 478 FEDERATION_DATA_INDEX: FEDERATION_DATA_INDEX, |
| 479 ORIGINAL_DATA_INDEX: ORIGINAL_DATA_INDEX |
| 409 }; | 480 }; |
| 410 }); | 481 }); |
| OLD | NEW |