| 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', function() { | 5 cr.define('options', function() { |
| 6 /** @const */ var DeletableItemList = options.DeletableItemList; | 6 /** @const */ var DeletableItemList = options.DeletableItemList; |
| 7 /** @const */ var DeletableItem = options.DeletableItem; | 7 /** @const */ var DeletableItem = options.DeletableItem; |
| 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 8 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
| 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 9 /** @const */ var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 10 | 10 |
| 11 // This structure maps the various cookie type names from C++ (hence the | 11 // This structure maps the various cookie type names from C++ (hence the |
| 12 // underscores) to arrays of the different types of data each has, along with | 12 // underscores) to arrays of the different types of data each has, along with |
| 13 // the i18n name for the description of that data type. | 13 // the i18n name for the description of that data type. |
| 14 /** @const */ var cookieInfo = { | 14 /** @const */ var cookieInfo = { |
| 15 'cookie': [['name', 'label_cookie_name'], | 15 'cookie': [ |
| 16 ['content', 'label_cookie_content'], | 16 ['name', 'label_cookie_name'], ['content', 'label_cookie_content'], |
| 17 ['domain', 'label_cookie_domain'], | 17 ['domain', 'label_cookie_domain'], ['path', 'label_cookie_path'], |
| 18 ['path', 'label_cookie_path'], | 18 ['sendfor', 'label_cookie_send_for'], |
| 19 ['sendfor', 'label_cookie_send_for'], | 19 ['accessibleToScript', 'label_cookie_accessible_to_script'], |
| 20 ['accessibleToScript', 'label_cookie_accessible_to_script'], | 20 ['created', 'label_cookie_created'], ['expires', 'label_cookie_expires'] |
| 21 ['created', 'label_cookie_created'], | 21 ], |
| 22 ['expires', 'label_cookie_expires']], | 22 'app_cache': [ |
| 23 'app_cache': [['manifest', 'label_app_cache_manifest'], | 23 ['manifest', 'label_app_cache_manifest'], |
| 24 ['size', 'label_local_storage_size'], | 24 ['size', 'label_local_storage_size'], ['created', 'label_cookie_created'], |
| 25 ['created', 'label_cookie_created'], | 25 ['accessed', 'label_cookie_last_accessed'] |
| 26 ['accessed', 'label_cookie_last_accessed']], | 26 ], |
| 27 'database': [['name', 'label_cookie_name'], | 27 'database': [ |
| 28 ['desc', 'label_webdb_desc'], | 28 ['name', 'label_cookie_name'], ['desc', 'label_webdb_desc'], |
| 29 ['size', 'label_local_storage_size'], | 29 ['size', 'label_local_storage_size'], |
| 30 ['modified', 'label_local_storage_last_modified']], | 30 ['modified', 'label_local_storage_last_modified'] |
| 31 'local_storage': [['origin', 'label_local_storage_origin'], | 31 ], |
| 32 ['size', 'label_local_storage_size'], | 32 'local_storage': [ |
| 33 ['modified', 'label_local_storage_last_modified']], | 33 ['origin', 'label_local_storage_origin'], |
| 34 'indexed_db': [['origin', 'label_indexed_db_origin'], | 34 ['size', 'label_local_storage_size'], |
| 35 ['size', 'label_indexed_db_size'], | 35 ['modified', 'label_local_storage_last_modified'] |
| 36 ['modified', 'label_indexed_db_last_modified']], | 36 ], |
| 37 'file_system': [['origin', 'label_file_system_origin'], | 37 'indexed_db': [ |
| 38 ['persistent', 'label_file_system_persistent_usage'], | 38 ['origin', 'label_indexed_db_origin'], ['size', 'label_indexed_db_size'], |
| 39 ['temporary', 'label_file_system_temporary_usage']], | 39 ['modified', 'label_indexed_db_last_modified'] |
| 40 'channel_id': [['serverId', 'label_channel_id_server_id'], | 40 ], |
| 41 ['certType', 'label_channel_id_type'], | 41 'file_system': [ |
| 42 ['created', 'label_channel_id_created']], | 42 ['origin', 'label_file_system_origin'], |
| 43 'service_worker': [['origin', 'label_service_worker_origin'], | 43 ['persistent', 'label_file_system_persistent_usage'], |
| 44 ['size', 'label_service_worker_size'], | 44 ['temporary', 'label_file_system_temporary_usage'] |
| 45 ['scopes', 'label_service_worker_scopes']], | 45 ], |
| 46 'cache_storage': [['origin', 'label_cache_storage_origin'], | 46 'channel_id': [ |
| 47 ['size', 'label_cache_storage_size'], | 47 ['serverId', 'label_channel_id_server_id'], |
| 48 ['modified', 'label_cache_storage_last_modified']], | 48 ['certType', 'label_channel_id_type'], |
| 49 ['created', 'label_channel_id_created'] |
| 50 ], |
| 51 'service_worker': [ |
| 52 ['origin', 'label_service_worker_origin'], |
| 53 ['size', 'label_service_worker_size'], |
| 54 ['scopes', 'label_service_worker_scopes'] |
| 55 ], |
| 56 'cache_storage': [ |
| 57 ['origin', 'label_cache_storage_origin'], |
| 58 ['size', 'label_cache_storage_size'], |
| 59 ['modified', 'label_cache_storage_last_modified'] |
| 60 ], |
| 49 'flash_lso': [['domain', 'label_cookie_domain']], | 61 'flash_lso': [['domain', 'label_cookie_domain']], |
| 50 'media_license': [['origin', 'label_media_license_origin'], | 62 'media_license': [ |
| 51 ['size', 'label_media_license_size'], | 63 ['origin', 'label_media_license_origin'], |
| 52 ['modified', 'label_media_license_last_modified']], | 64 ['size', 'label_media_license_size'], |
| 65 ['modified', 'label_media_license_last_modified'] |
| 66 ], |
| 53 }; | 67 }; |
| 54 | 68 |
| 55 /** | 69 /** |
| 56 * Returns the item's height, like offsetHeight but such that it works better | 70 * Returns the item's height, like offsetHeight but such that it works better |
| 57 * when the page is zoomed. See the similar calculation in @{code cr.ui.List}. | 71 * when the page is zoomed. See the similar calculation in @{code cr.ui.List}. |
| 58 * This version also accounts for the animation done in this file. | 72 * This version also accounts for the animation done in this file. |
| 59 * @param {Element} item The item to get the height of. | 73 * @param {Element} item The item to get the height of. |
| 60 * @return {number} The height of the item, calculated with zooming in mind. | 74 * @return {number} The height of the item, calculated with zooming in mind. |
| 61 */ | 75 */ |
| 62 function getItemHeight(item) { | 76 function getItemHeight(item) { |
| 63 var height = item.style.height; | 77 var height = item.style.height; |
| 64 // Use the fixed animation target height if set, in case the element is | 78 // Use the fixed animation target height if set, in case the element is |
| 65 // currently being animated and we'd get an intermediate height below. | 79 // currently being animated and we'd get an intermediate height below. |
| 66 if (height && height.substr(-2) == 'px') | 80 if (height && height.substr(-2) == 'px') |
| 67 return parseInt(height.substr(0, height.length - 2), 10); | 81 return parseInt(height.substr(0, height.length - 2), 10); |
| 68 return item.getBoundingClientRect().height; | 82 return item.getBoundingClientRect().height; |
| 69 } | 83 } |
| 70 | 84 |
| 71 /** | 85 /** |
| 72 * Create tree nodes for the objects in the data array, and insert them all | 86 * Create tree nodes for the objects in the data array, and insert them all |
| 73 * into the given list using its @{code splice} method at the given index. | 87 * into the given list using its @{code splice} method at the given index. |
| 74 * @param {Array<Object>} data The data objects for the nodes to add. | 88 * @param {Array<Object>} data The data objects for the nodes to add. |
| 75 * @param {number} start The index at which to start inserting the nodes. | 89 * @param {number} start The index at which to start inserting the nodes. |
| 76 * @return {Array<options.CookieTreeNode>} An array of CookieTreeNodes added. | 90 * @return {Array<options.CookieTreeNode>} An array of CookieTreeNodes added. |
| 77 */ | 91 */ |
| 78 function spliceTreeNodes(data, start, list) { | 92 function spliceTreeNodes(data, start, list) { |
| 79 var nodes = data.map(function(x) { return new CookieTreeNode(x); }); | 93 var nodes = data.map(function(x) { |
| 94 return new CookieTreeNode(x); |
| 95 }); |
| 80 // Insert [start, 0] at the beginning of the array of nodes, making it | 96 // Insert [start, 0] at the beginning of the array of nodes, making it |
| 81 // into the arguments we want to pass to @{code list.splice} below. | 97 // into the arguments we want to pass to @{code list.splice} below. |
| 82 nodes.splice(0, 0, start, 0); | 98 nodes.splice(0, 0, start, 0); |
| 83 list.splice.apply(list, nodes); | 99 list.splice.apply(list, nodes); |
| 84 // Remove the [start, 0] prefix and return the array of nodes. | 100 // Remove the [start, 0] prefix and return the array of nodes. |
| 85 nodes.splice(0, 2); | 101 nodes.splice(0, 2); |
| 86 return nodes; | 102 return nodes; |
| 87 } | 103 } |
| 88 | 104 |
| 89 /** | 105 /** |
| 90 * Adds information about an app that protects this data item to the | 106 * Adds information about an app that protects this data item to the |
| 91 * |element|. | 107 * |element|. |
| 92 * @param {Element} element The DOM element the information should be | 108 * @param {Element} element The DOM element the information should be |
| 93 appended to. | 109 appended to. |
| 94 * @param {{id: string, name: string}} appInfo Information about an app. | 110 * @param {{id: string, name: string}} appInfo Information about an app. |
| 95 */ | 111 */ |
| 96 function addAppInfo(element, appInfo) { | 112 function addAppInfo(element, appInfo) { |
| 97 var img = element.ownerDocument.createElement('img'); | 113 var img = element.ownerDocument.createElement('img'); |
| 98 img.src = 'chrome://extension-icon/' + appInfo.id + '/16/1'; | 114 img.src = 'chrome://extension-icon/' + appInfo.id + '/16/1'; |
| 99 element.title = loadTimeData.getString('label_protected_by_apps') + | 115 element.title = |
| 100 ' ' + appInfo.name; | 116 loadTimeData.getString('label_protected_by_apps') + ' ' + appInfo.name; |
| 101 img.className = 'protecting-app'; | 117 img.className = 'protecting-app'; |
| 102 element.appendChild(img); | 118 element.appendChild(img); |
| 103 } | 119 } |
| 104 | 120 |
| 105 var parentLookup = {}; | 121 var parentLookup = {}; |
| 106 var lookupRequests = {}; | 122 var lookupRequests = {}; |
| 107 | 123 |
| 108 /** | 124 /** |
| 109 * Creates a new list item for sites data. Note that these are created and | 125 * Creates a new list item for sites data. Note that these are created and |
| 110 * destroyed lazily as they scroll into and out of view, so they must be | 126 * destroyed lazily as they scroll into and out of view, so they must be |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 this.selectedIndex_ = -1; | 391 this.selectedIndex_ = -1; |
| 376 this.disableAnimation_(); | 392 this.disableAnimation_(); |
| 377 this.infoChild.hidden = true; | 393 this.infoChild.hidden = true; |
| 378 this.enableAnimation_(); | 394 this.enableAnimation_(); |
| 379 return; | 395 return; |
| 380 } | 396 } |
| 381 // Set the new selected item and show the item details for it. | 397 // Set the new selected item and show the item details for it. |
| 382 this.selectedIndex_ = itemIndex; | 398 this.selectedIndex_ = itemIndex; |
| 383 this.itemList_[itemIndex].div.setAttribute('selected', ''); | 399 this.itemList_[itemIndex].div.setAttribute('selected', ''); |
| 384 this.disableAnimation_(); | 400 this.disableAnimation_(); |
| 385 this.itemList_[itemIndex].node.setDetailText(this.infoChild, | 401 this.itemList_[itemIndex].node.setDetailText( |
| 386 this.list.infoNodes); | 402 this.infoChild, this.list.infoNodes); |
| 387 this.infoChild.hidden = false; | 403 this.infoChild.hidden = false; |
| 388 this.enableAnimation_(); | 404 this.enableAnimation_(); |
| 389 // If we're near the bottom of the list this may cause the list item to go | 405 // If we're near the bottom of the list this may cause the list item to go |
| 390 // beyond the end of the visible area. Fix it after the animation is done. | 406 // beyond the end of the visible area. Fix it after the animation is done. |
| 391 var list = this.list; | 407 var list = this.list; |
| 392 window.setTimeout(function() { list.scrollIndexIntoView(index); }, 150); | 408 window.setTimeout(function() { |
| 409 list.scrollIndexIntoView(index); |
| 410 }, 150); |
| 393 }, | 411 }, |
| 394 }; | 412 }; |
| 395 | 413 |
| 396 /** | 414 /** |
| 397 * {@code CookieTreeNode}s mirror the structure of the cookie tree lazily, and | 415 * {@code CookieTreeNode}s mirror the structure of the cookie tree lazily, and |
| 398 * contain all the actual data used to generate the {@code CookieListItem}s. | 416 * contain all the actual data used to generate the {@code CookieListItem}s. |
| 399 * @param {Object} data The data object for this node. | 417 * @param {Object} data The data object for this node. |
| 400 * @constructor | 418 * @constructor |
| 401 */ | 419 */ |
| 402 function CookieTreeNode(data) { | 420 function CookieTreeNode(data) { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 // List.getDefaultItemSize_ | 657 // List.getDefaultItemSize_ |
| 640 // List.getDefaultItemHeight_ | 658 // List.getDefaultItemHeight_ |
| 641 // List.getIndexForListOffset_ | 659 // List.getIndexForListOffset_ |
| 642 // List.getItemsInViewPort | 660 // List.getItemsInViewPort |
| 643 // List.redraw | 661 // List.redraw |
| 644 // List.endBatchUpdates | 662 // List.endBatchUpdates |
| 645 // CookiesList.loadChildren | 663 // CookiesList.loadChildren |
| 646 this.parent_ = parent.listIndex; | 664 this.parent_ = parent.listIndex; |
| 647 } | 665 } |
| 648 this.list_ = parent.list; | 666 this.list_ = parent.list; |
| 649 parent.addEventListener('listIndexChange', | 667 parent.addEventListener( |
| 650 this.parentIndexChanged_.bind(this)); | 668 'listIndexChange', this.parentIndexChanged_.bind(this)); |
| 651 } else { | 669 } else { |
| 652 this.parent_ = parent; | 670 this.parent_ = parent; |
| 653 } | 671 } |
| 654 | 672 |
| 655 if (this.data && this.data.id) { | 673 if (this.data && this.data.id) { |
| 656 if (parent) | 674 if (parent) |
| 657 parentLookup[this.data.id] = this; | 675 parentLookup[this.data.id] = this; |
| 658 else | 676 else |
| 659 delete parentLookup[this.data.id]; | 677 delete parentLookup[this.data.id]; |
| 660 } | 678 } |
| 661 | 679 |
| 662 if (this.data && this.data.hasChildren && | 680 if (this.data && this.data.hasChildren && !this.children.length && |
| 663 !this.children.length && !lookupRequests[this.data.id]) { | 681 !lookupRequests[this.data.id]) { |
| 664 lookupRequests[this.data.id] = true; | 682 lookupRequests[this.data.id] = true; |
| 665 chrome.send('loadCookie', [this.pathId]); | 683 chrome.send('loadCookie', [this.pathId]); |
| 666 } | 684 } |
| 667 }, | 685 }, |
| 668 | 686 |
| 669 /** | 687 /** |
| 670 * Called when the parent is a CookieListItem whose index has changed. | 688 * Called when the parent is a CookieListItem whose index has changed. |
| 671 * See the code above that avoids keeping a direct reference to | 689 * See the code above that avoids keeping a direct reference to |
| 672 * CookieListItem parents, to allow them to be garbage collected. | 690 * CookieListItem parents, to allow them to be garbage collected. |
| 673 * @private | 691 * @private |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 } | 787 } |
| 770 }, | 788 }, |
| 771 | 789 |
| 772 /** | 790 /** |
| 773 * Called on selection model selection changes. | 791 * Called on selection model selection changes. |
| 774 * @param {Event} ce The selection change event. | 792 * @param {Event} ce The selection change event. |
| 775 * @private | 793 * @private |
| 776 */ | 794 */ |
| 777 cookieSelectionChange_: function(ce) { | 795 cookieSelectionChange_: function(ce) { |
| 778 ce.changes.forEach(function(change) { | 796 ce.changes.forEach(function(change) { |
| 779 var listItem = this.getListItemByIndex(change.index); | 797 var listItem = this.getListItemByIndex(change.index); |
| 780 if (listItem) { | 798 if (listItem) { |
| 781 if (!change.selected) { | 799 if (!change.selected) { |
| 782 // We set a timeout here, rather than setting the item unexpanded | 800 // We set a timeout here, rather than setting the item unexpanded |
| 783 // immediately, so that if another item gets set expanded right | 801 // immediately, so that if another item gets set expanded right |
| 784 // away, it will be expanded before this item is unexpanded. It | 802 // away, it will be expanded before this item is unexpanded. It |
| 785 // will notice that, and unexpand this item in sync with its own | 803 // will notice that, and unexpand this item in sync with its own |
| 786 // expansion. Later, this callback will end up having no effect. | 804 // expansion. Later, this callback will end up having no effect. |
| 787 window.setTimeout(function() { | 805 window.setTimeout(function() { |
| 788 if (!listItem.selected || !listItem.lead) | 806 if (!listItem.selected || !listItem.lead) |
| 789 listItem.expanded = false; | 807 listItem.expanded = false; |
| 790 }, 0); | 808 }, 0); |
| 791 } else if (listItem.lead) { | 809 } else if (listItem.lead) { |
| 792 listItem.expanded = true; | 810 listItem.expanded = true; |
| 793 } | |
| 794 } | 811 } |
| 795 }, this); | 812 } |
| 813 }, this); |
| 796 }, | 814 }, |
| 797 | 815 |
| 798 /** | 816 /** |
| 799 * Called on selection model lead changes. | 817 * Called on selection model lead changes. |
| 800 * @param {Event} pe The lead change event. | 818 * @param {Event} pe The lead change event. |
| 801 * @private | 819 * @private |
| 802 */ | 820 */ |
| 803 cookieLeadChange_: function(pe) { | 821 cookieLeadChange_: function(pe) { |
| 804 if (pe.oldValue != -1) { | 822 if (pe.oldValue != -1) { |
| 805 var listItem = this.getListItemByIndex(pe.oldValue); | 823 var listItem = this.getListItemByIndex(pe.oldValue); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 parent.endBatchUpdates(); | 970 parent.endBatchUpdates(); |
| 953 }, | 971 }, |
| 954 }; | 972 }; |
| 955 | 973 |
| 956 return { | 974 return { |
| 957 CookiesList: CookiesList, | 975 CookiesList: CookiesList, |
| 958 CookieListItem: CookieListItem, | 976 CookieListItem: CookieListItem, |
| 959 CookieTreeNode: CookieTreeNode, | 977 CookieTreeNode: CookieTreeNode, |
| 960 }; | 978 }; |
| 961 }); | 979 }); |
| OLD | NEW |