| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 /** | 5 /** |
| 6 * @fileoverview | 6 * @fileoverview |
| 7 * 'site-data' handles showing the local storage summary list for all sites. | 7 * 'site-data' handles showing the local storage summary list for all sites. |
| 8 */ | 8 */ |
| 9 | 9 |
| 10 Polymer({ | 10 Polymer({ |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 */ | 26 */ |
| 27 treeNodes_: Object, | 27 treeNodes_: Object, |
| 28 | 28 |
| 29 /** | 29 /** |
| 30 * Keeps track of how many outstanding requests for more data there are. | 30 * Keeps track of how many outstanding requests for more data there are. |
| 31 */ | 31 */ |
| 32 requests_: Number, | 32 requests_: Number, |
| 33 }, | 33 }, |
| 34 | 34 |
| 35 ready: function() { | 35 ready: function() { |
| 36 this.addWebUIListener('loadChildren', this.loadChildren_.bind(this)); | |
| 37 this.addWebUIListener('onTreeItemRemoved', | 36 this.addWebUIListener('onTreeItemRemoved', |
| 38 this.onTreeItemRemoved_.bind(this)); | 37 this.onTreeItemRemoved_.bind(this)); |
| 39 this.treeNodes_ = new settings.CookieTreeNode(null); | 38 this.treeNodes_ = new settings.CookieTreeNode(null); |
| 40 // Start the initial request. | 39 // Start the initial request. |
| 41 this.browserProxy.reloadCookies(); | 40 this.reloadCookies_(); |
| 42 this.requests_ = 1; | |
| 43 }, | 41 }, |
| 44 | 42 |
| 43 /** |
| 44 * Reloads the whole cookie list. |
| 45 * @private |
| 46 */ |
| 47 reloadCookies_: function() { |
| 48 this.browserProxy.reloadCookies().then(function(list) { |
| 49 this.loadChildren_(list); |
| 50 }.bind(this)); |
| 51 }, |
| 52 |
| 53 /** |
| 54 * Returns whether remove all should be shown. |
| 55 * @param {Array<CookieDataSummaryItem>} sites The sites list to use to |
| 56 * determine whether the button should be visible. |
| 57 * @private |
| 58 */ |
| 59 removeAllIsVisible_: function(sites) { |
| 60 return sites.length > 0; |
| 61 }, |
| 62 |
| 63 /** |
| 64 * Called when the cookie list is ready to be shown. |
| 65 * @param {!CookieList} list The cookie list to show. |
| 66 * @private |
| 67 */ |
| 45 loadChildren_: function(list) { | 68 loadChildren_: function(list) { |
| 46 var parentId = list[0]; | 69 var parentId = list.id; |
| 47 var data = list[1]; | 70 var data = list.children; |
| 48 | 71 |
| 49 if (parentId == null) { | 72 if (parentId == null) { |
| 73 // New root being added, clear the list and add the nodes. |
| 74 this.sites = []; |
| 75 this.requests_ = 0; |
| 50 this.treeNodes_.addChildNodes(this.treeNodes_, data); | 76 this.treeNodes_.addChildNodes(this.treeNodes_, data); |
| 51 } else { | 77 } else { |
| 52 this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data); | 78 this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, data); |
| 53 } | 79 } |
| 54 | 80 |
| 55 for (var i = 0; i < data.length; ++i) { | 81 for (var i = 0; i < data.length; ++i) { |
| 56 var prefix = parentId == null ? '' : parentId + ', '; | 82 var prefix = parentId == null ? '' : parentId + ', '; |
| 57 if (data[i].hasChildren) { | 83 if (data[i].hasChildren) { |
| 58 this.requests_ += 1; | 84 ++this.requests_; |
| 59 this.browserProxy.loadCookieChildren(prefix + data[i].id); | 85 this.browserProxy.loadCookieChildren( |
| 86 prefix + data[i].id).then(function(list) { |
| 87 --this.requests_; |
| 88 this.loadChildren_(list); |
| 89 }.bind(this)); |
| 60 } | 90 } |
| 61 } | 91 } |
| 62 | 92 |
| 63 if (--this.requests_ == 0) | 93 if (this.requests_ == 0) |
| 64 this.sites = this.treeNodes_.getSummaryList(); | 94 this.sites = this.treeNodes_.getSummaryList(); |
| 95 |
| 96 // If this reaches below zero then we're forgetting to increase the |
| 97 // outstanding request count and the summary list won't be updated at the |
| 98 // end. |
| 99 assert(this.requests_ >= 0); |
| 65 }, | 100 }, |
| 66 | 101 |
| 67 /** | 102 /** |
| 68 * Called when an item is removed. | 103 * Called when a single item has been removed (not during delete all). |
| 104 * @param {!CookieRemovePacket} args The details about what to remove. |
| 69 */ | 105 */ |
| 70 onTreeItemRemoved_: function(args) { | 106 onTreeItemRemoved_: function(args) { |
| 71 this.treeNodes_.removeByParentId(args[0], args[1], args[2]); | 107 this.treeNodes_.removeByParentId(args.id, args.start, args.count); |
| 72 this.sites = this.treeNodes_.getSummaryList(); | 108 this.sites = this.treeNodes_.getSummaryList(); |
| 73 }, | 109 }, |
| 74 | 110 |
| 75 /** | 111 /** |
| 76 * @param {!{model: !{item: !{title: string, id: string}}}} event | 112 * Deletes all site data for a given site. |
| 113 * @param {!{model: !{item: CookieDataSummaryItem}}} event |
| 114 * @private |
| 115 */ |
| 116 onDeleteSite_: function(event) { |
| 117 this.browserProxy.removeCookie(event.model.item.id); |
| 118 }, |
| 119 |
| 120 /** |
| 121 * Deletes site data for all sites. |
| 122 * @private |
| 123 */ |
| 124 onDeleteAllSites_: function() { |
| 125 this.browserProxy.removeAllCookies().then(function(list) { |
| 126 this.loadChildren_(list); |
| 127 }.bind(this)); |
| 128 }, |
| 129 |
| 130 /** |
| 131 * @param {!{model: !{item: CookieDataSummaryItem}}} event |
| 77 * @private | 132 * @private |
| 78 */ | 133 */ |
| 79 onSiteTap_: function(event) { | 134 onSiteTap_: function(event) { |
| 80 var dialog = document.createElement('site-data-details-dialog'); | 135 var dialog = document.createElement('site-data-details-dialog'); |
| 81 dialog.category = this.category; | 136 dialog.category = this.category; |
| 82 this.shadowRoot.appendChild(dialog); | 137 this.shadowRoot.appendChild(dialog); |
| 83 | 138 |
| 84 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false); | 139 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false); |
| 85 dialog.open(node); | 140 dialog.open(node); |
| 86 | 141 |
| 87 dialog.addEventListener('close', function(event) { | 142 dialog.addEventListener('close', function(event) { |
| 88 dialog.remove(); | 143 dialog.remove(); |
| 89 }); | 144 }); |
| 90 }, | 145 }, |
| 91 }); | 146 }); |
| OLD | NEW |