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 // The following constants should be synchronized with the constants in | 11 // The following constants should be synchronized with the constants in |
12 // chrome/browser/ui/webui/options/password_manager_handler.cc. | 12 // chrome/browser/ui/webui/options/password_manager_handler.cc. |
13 /** @const */ var ORIGIN_FIELD = 'origin'; | 13 /** @const */ var URL_FIELD = 'url'; |
14 /** @const */ var SHOWN_URL_FIELD = 'shownUrl'; | 14 /** @const */ var SHOWN_ORIGIN_FIELD = 'shownOrigin'; |
15 /** @const */ var IS_ANDROID_URI_FIELD = 'isAndroidUri'; | 15 /** @const */ var IS_CLICKABLE_FIELD = 'isClickable'; |
16 /** @const */ var IS_SECURE_FIELD = 'isSecure'; | 16 /** @const */ var IS_SECURE_FIELD = 'isSecure'; |
17 /** @const */ var USERNAME_FIELD = 'username'; | 17 /** @const */ var USERNAME_FIELD = 'username'; |
18 /** @const */ var PASSWORD_FIELD = 'password'; | 18 /** @const */ var PASSWORD_FIELD = 'password'; |
19 /** @const */ var FEDERATION_FIELD = 'federation'; | 19 /** @const */ var FEDERATION_FIELD = 'federation'; |
20 /** @const */ var ORIGINAL_INDEX_FIELD = 'index'; | 20 /** @const */ var ORIGINAL_INDEX_FIELD = 'index'; |
21 | 21 |
22 /** | 22 /** |
23 * Creates a new passwords list item. | 23 * Creates a new passwords list item. |
24 * @param {cr.ui.ArrayDataModel} dataModel The data model that contains this | 24 * @param {cr.ui.ArrayDataModel} dataModel The data model that contains this |
25 * item. | 25 * item. |
26 * @param {Object} entry A dictionary of data on new list item. When the | 26 * @param {Object} entry A dictionary of data on new list item. When the |
27 * list has been filtered, one more element [index] may be present. | 27 * list has been filtered, one more element [index] may be present. |
28 * @param {boolean} showPasswords If true, add a button to the element to | 28 * @param {boolean} showPasswords If true, add a button to the element to |
29 * allow the user to reveal the saved password. | 29 * allow the user to reveal the saved password. |
30 * @constructor | 30 * @constructor |
31 * @extends {options.DeletableItem} | 31 * @extends {options.DeletableItem} |
32 */ | 32 */ |
33 function PasswordListItem(dataModel, entry, showPasswords) { | 33 function PasswordListItem(dataModel, entry, showPasswords) { |
34 var el = cr.doc.createElement('div'); | 34 var el = cr.doc.createElement('div'); |
35 el.dataItem = entry; | 35 el.dataItem = entry; |
36 el.dataModel = dataModel; | 36 el.dataModel = dataModel; |
37 el.__proto__ = PasswordListItem.prototype; | 37 el.__proto__ = PasswordListItem.prototype; |
38 el.showPasswords_ = showPasswords; | 38 el.showPasswords_ = showPasswords; |
39 el.decorate(); | 39 el.decorate(); |
40 | 40 |
41 return el; | 41 return el; |
42 } | 42 } |
43 | 43 |
44 /** | 44 /** |
45 * Returns title for password's origin. If the origin is Android URI, returns | 45 * Returns title for password's origin. If the origin is not clickable, |
46 * the origin as it is. Removes the scheme if the url is insecure and removes | 46 * returns the origin as it is. For clickable origins, removes the scheme if |
47 * trailing punctuation symbols. | 47 * the url is insecure and removes trailing punctuation symbols. |
48 * @param {Object} item A dictionary of data on the list item. | 48 * @param {Object} item A dictionary of data on the list item. |
49 * @return {string} The title for password's origin. | 49 * @return {string} The title for password's origin. |
50 */ | 50 */ |
51 function getTitleForPasswordOrigin(item) { | 51 function getTitleForPasswordOrigin(item) { |
52 var title = item.url; | 52 var title = item.url; |
53 if (item.isAndroidUri) | 53 if (!item.isClickable) |
54 return title; | 54 return title; |
55 if (!item.isSecure) { | 55 if (!item.isSecure) { |
56 var ind = title.indexOf('://'); | 56 var ind = title.indexOf('://'); |
57 if (ind >= 0) { | 57 if (ind >= 0) { |
58 title = title.substring(ind + 3); | 58 title = title.substring(ind + 3); |
59 } | 59 } |
60 } | 60 } |
61 // Since the direction is switched to RTL, punctuation symbols appear on the | 61 // Since the direction is switched to RTL, punctuation symbols appear on the |
62 // left side, that is wrong. So, just remove trailing punctuation symbols. | 62 // left side, that is wrong. So, just remove trailing punctuation symbols. |
63 title = title.replace(/[^A-Za-z0-9]+$/, ''); | 63 title = title.replace(/[^A-Za-z0-9]+$/, ''); |
64 return title; | 64 return title; |
65 } | 65 } |
66 | 66 |
67 /** | 67 /** |
68 * Helper function that creates an HTML element for displaying the origin of | 68 * Helper function that creates an HTML element for displaying the origin of |
69 * saved password. | 69 * saved password. |
70 * @param {Object} item A dictionary of data on the list item. | 70 * @param {Object} item A dictionary of data on the list item. |
71 * @param {Element} urlDiv div-element that will enclose the created | 71 * @param {Element} urlDiv div-element that will enclose the created |
72 * element. | 72 * element. |
73 * @return {Element} The element for displaying password origin. | 73 * @return {Element} The element for displaying password origin. |
74 */ | 74 */ |
75 function createUrlLink(item, urlDiv) { | 75 function createUrlLink(item, urlDiv) { |
76 var urlLink; | 76 var urlLink; |
77 if (!item.isAndroidUri) { | 77 if (item.isClickable) { |
78 urlLink = item.ownerDocument.createElement('a'); | 78 urlLink = item.ownerDocument.createElement('a'); |
79 urlLink.href = item.url; | 79 urlLink.href = item.url; |
80 urlLink.setAttribute('target', '_blank'); | 80 urlLink.setAttribute('target', '_blank'); |
81 urlLink.textContent = item.shownUrl.split('').reverse().join(''); | 81 urlLink.textContent = item.shownOrigin.split('').reverse().join(''); |
82 | |
83 urlDiv.classList.add('left-elided-url'); | 82 urlDiv.classList.add('left-elided-url'); |
84 } else { | 83 } else { |
85 urlLink = item.ownerDocument.createElement('span'); | 84 urlLink = item.ownerDocument.createElement('span'); |
86 urlLink.textContent = item.shownUrl; | 85 urlLink.textContent = item.shownOrigin; |
87 } | 86 } |
88 urlLink.addEventListener('focus', function() { | 87 urlLink.addEventListener('focus', function() { |
89 item.handleFocus(); | 88 item.handleFocus(); |
90 }.bind(item)); | 89 }.bind(item)); |
91 return urlLink; | 90 return urlLink; |
92 } | 91 } |
93 | 92 |
94 PasswordListItem.prototype = { | 93 PasswordListItem.prototype = { |
95 __proto__: DeletableItem.prototype, | 94 __proto__: DeletableItem.prototype, |
96 | 95 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } else { | 258 } else { |
260 this.hidePassword(); | 259 this.hidePassword(); |
261 } | 260 } |
262 }, | 261 }, |
263 | 262 |
264 /** | 263 /** |
265 * Get and set the URL for the entry. | 264 * Get and set the URL for the entry. |
266 * @type {string} | 265 * @type {string} |
267 */ | 266 */ |
268 get url() { | 267 get url() { |
269 return this.dataItem[ORIGIN_FIELD]; | 268 return this.dataItem[URL_FIELD]; |
270 }, | 269 }, |
271 set url(url) { | 270 set url(url) { |
272 this.dataItem[ORIGIN_FIELD] = url; | 271 this.dataItem[URL_FIELD] = url; |
273 }, | 272 }, |
274 | 273 |
275 /** | 274 /** |
276 * Get and set the shown url for the entry. | 275 * Get and set the shown origin for the entry. |
277 * @type {string} | 276 * @type {string} |
278 */ | 277 */ |
279 get shownUrl() { | 278 get shownOrigin() { |
280 return this.dataItem[SHOWN_URL_FIELD]; | 279 return this.dataItem[SHOWN_ORIGIN_FIELD]; |
281 }, | 280 }, |
282 set shownUrl(shownUrl) { | 281 set shownOrigin(shownOrigin) { |
283 this.dataItem[SHOWN_URL_FIELD] = shownUrl; | 282 this.dataItem[SHOWN_ORIGIN_FIELD] = shownOrigin; |
284 }, | 283 }, |
285 | 284 |
286 /** | 285 /** |
287 * Get and set whether the origin is Android URI. | 286 * Get and set whether the origin is clickable. |
288 * @type {boolean} | 287 * @type {boolean} |
289 */ | 288 */ |
290 get isAndroidUri() { | 289 get isClickable() { |
291 return this.dataItem[IS_ANDROID_URI_FIELD]; | 290 return this.dataItem[IS_CLICKABLE_FIELD]; |
292 }, | 291 }, |
293 set isAndroidUri(isAndroidUri) { | 292 set isClickable(isClickable) { |
294 this.dataItem[IS_ANDROID_URI_FIELD] = isAndroidUri; | 293 this.dataItem[IS_CLICKABLE_FIELD] = isClickable; |
295 }, | 294 }, |
296 | 295 |
297 /** | 296 /** |
298 * Get and set whether the origin uses secure scheme. | 297 * Get and set whether the origin uses secure scheme. |
299 * @type {boolean} | 298 * @type {boolean} |
300 */ | 299 */ |
301 get isSecure() { | 300 get isSecure() { |
302 return this.dataItem[IS_SECURE_FIELD]; | 301 return this.dataItem[IS_SECURE_FIELD]; |
303 }, | 302 }, |
304 set isSecure(isSecure) { | 303 set isSecure(isSecure) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 var tabIndex = focusable ? 0 : -1; | 394 var tabIndex = focusable ? 0 : -1; |
396 this.urlLink.tabIndex = tabIndex; | 395 this.urlLink.tabIndex = tabIndex; |
397 this.closeButtonElement.tabIndex = tabIndex; | 396 this.closeButtonElement.tabIndex = tabIndex; |
398 }, | 397 }, |
399 | 398 |
400 /** | 399 /** |
401 * Get the url for the entry. | 400 * Get the url for the entry. |
402 * @type {string} | 401 * @type {string} |
403 */ | 402 */ |
404 get url() { | 403 get url() { |
405 return this.dataItem[ORIGIN_FIELD]; | 404 return this.dataItem[URL_FIELD]; |
406 }, | 405 }, |
407 set url(url) { | 406 set url(url) { |
408 this.dataItem[ORIGIN_FIELD] = url; | 407 this.dataItem[URL_FIELD] = url; |
409 }, | 408 }, |
410 | 409 |
411 /** | 410 /** |
412 * Get and set the shown url for the entry. | 411 * Get and set the shown origin for the entry. |
413 * @type {string} | 412 * @type {string} |
414 */ | 413 */ |
415 get shownUrl() { | 414 get shownOrigin() { |
416 return this.dataItem[SHOWN_URL_FIELD]; | 415 return this.dataItem[SHOWN_ORIGIN_FIELD]; |
417 }, | 416 }, |
418 set shownUrl(shownUrl) { | 417 set shownOrigin(shownOrigin) { |
419 this.dataItem[SHOWN_URL_FIELD] = shownUrl; | 418 this.dataItem[SHOWN_ORIGIN_FIELD] = shownOrigin; |
420 }, | 419 }, |
421 | 420 |
422 /** | 421 /** |
423 * Get and set whether the origin is Android URI. | 422 * Get and set whether the origin is clickable. |
424 * @type {boolean} | 423 * @type {boolean} |
425 */ | 424 */ |
426 get isAndroidUri() { | 425 get isClickable() { |
427 return this.dataItem[IS_ANDROID_URI_FIELD]; | 426 return this.dataItem[IS_CLICKABLE_FIELD]; |
428 }, | 427 }, |
429 set isAndroidUri(isAndroidUri) { | 428 set isClickable(isClickable) { |
430 this.dataItem[IS_ANDROID_URI_FIELD] = isAndroidUri; | 429 this.dataItem[IS_CLICKABLE_FIELD] = isClickable; |
431 }, | 430 }, |
432 | 431 |
433 /** | 432 /** |
434 * Get and set whether the origin uses secure scheme. | 433 * Get and set whether the origin uses secure scheme. |
435 * @type {boolean} | 434 * @type {boolean} |
436 */ | 435 */ |
437 get isSecure() { | 436 get isSecure() { |
438 return this.dataItem[IS_SECURE_FIELD]; | 437 return this.dataItem[IS_SECURE_FIELD]; |
439 }, | 438 }, |
440 set isSecure(isSecure) { | 439 set isSecure(isSecure) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 get length() { | 548 get length() { |
550 return this.dataModel.length; | 549 return this.dataModel.length; |
551 }, | 550 }, |
552 }; | 551 }; |
553 | 552 |
554 return { | 553 return { |
555 PasswordListItem: PasswordListItem, | 554 PasswordListItem: PasswordListItem, |
556 PasswordExceptionsListItem: PasswordExceptionsListItem, | 555 PasswordExceptionsListItem: PasswordExceptionsListItem, |
557 PasswordsList: PasswordsList, | 556 PasswordsList: PasswordsList, |
558 PasswordExceptionsList: PasswordExceptionsList, | 557 PasswordExceptionsList: PasswordExceptionsList, |
559 ORIGIN_FIELD: ORIGIN_FIELD, | 558 URL_FIELD: URL_FIELD, |
560 SHOWN_URL_FIELD: SHOWN_URL_FIELD, | 559 SHOWN_ORIGIN_FIELD: SHOWN_ORIGIN_FIELD, |
| 560 IS_CLICKABLE_FIELD: IS_CLICKABLE_FIELD, |
561 IS_SECURE_FIELD: IS_SECURE_FIELD, | 561 IS_SECURE_FIELD: IS_SECURE_FIELD, |
562 USERNAME_FIELD: USERNAME_FIELD, | 562 USERNAME_FIELD: USERNAME_FIELD, |
563 PASSWORD_FIELD: PASSWORD_FIELD, | 563 PASSWORD_FIELD: PASSWORD_FIELD, |
564 FEDERATION_FIELD: FEDERATION_FIELD, | 564 FEDERATION_FIELD: FEDERATION_FIELD, |
565 ORIGINAL_INDEX_FIELD: ORIGINAL_INDEX_FIELD | 565 ORIGINAL_INDEX_FIELD: ORIGINAL_INDEX_FIELD |
566 }; | 566 }; |
567 }); | 567 }); |
OLD | NEW |