Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: chrome/browser/resources/settings/site_settings/site_data.js

Issue 2451553008: [MD settings] move cookie tree management to cookie tree behavior (Closed)
Patch Set: touchups Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
dschuyler 2016/10/26 00:18:38 Items in this file generally moved to cookie_tree_
10 Polymer({ 10 Polymer({
11 is: 'site-data', 11 is: 'site-data',
12 12
13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], 13 behaviors: [CookieTreeBehavior],
14 14
15 properties: { 15 properties: {
16 /** 16 /**
17 * A summary list of all sites and how many entities each contain.
18 * @type {Array<CookieDataSummaryItem>}
19 */
20 sites: Array,
21
22 /**
23 * The cookie tree with the details needed to display individual sites and
24 * their contained data.
25 * @type {!settings.CookieTreeNode}
26 * @private
27 */
28 treeNodes_: Object,
29
30 /**
31 * The current filter applied to the cookie data list. 17 * The current filter applied to the cookie data list.
32 * @private 18 * @private
33 */ 19 */
34 filterString_: { 20 filterString_: {
35 type: String, 21 type: String,
36 value: '', 22 value: '',
37 }, 23 },
38 24
39 /** @private */ 25 /** @private */
40 confirmationDeleteMsg_: String, 26 confirmationDeleteMsg_: String,
41 27
42 /** @private */ 28 /** @private */
43 idToDelete_: String, 29 idToDelete_: String,
44 }, 30 },
45 31
46 /** @override */ 32 /** @override */
47 ready: function() { 33 ready: function() {
48 this.addWebUIListener('onTreeItemRemoved', 34 this.loadCookies();
49 this.onTreeItemRemoved_.bind(this));
50 this.treeNodes_ = new settings.CookieTreeNode(null);
51 // Start the initial request.
52 this.reloadCookies_();
53 }, 35 },
54 36
55 /** 37 /**
56 * Reloads the whole cookie list.
57 * @private
58 */
59 reloadCookies_: function() {
60 this.browserProxy.reloadCookies().then(function(list) {
61 this.loadChildren_(list);
62 }.bind(this));
63 },
64
65 /**
66 * A filter function for the list. 38 * A filter function for the list.
67 * @param {!CookieDataSummaryItem} item The item to possibly filter out. 39 * @param {!CookieDataSummaryItem} item The item to possibly filter out.
68 * @return {boolean} Whether to show the item. 40 * @return {boolean} Whether to show the item.
69 * @private 41 * @private
70 */ 42 */
71 showItem_: function(item) { 43 showItem_: function(item) {
72 if (this.filterString_.length == 0) 44 if (this.filterString_.length == 0)
73 return true; 45 return true;
74 return item.site.indexOf(this.filterString_) > -1; 46 return item.site.indexOf(this.filterString_) > -1;
75 }, 47 },
(...skipping 13 matching lines...) Expand all
89 * Returns the string to use for the Remove label. 61 * Returns the string to use for the Remove label.
90 * @return {string} filterString The current filter string. 62 * @return {string} filterString The current filter string.
91 * @private 63 * @private
92 */ 64 */
93 computeRemoveLabel_: function(filterString) { 65 computeRemoveLabel_: function(filterString) {
94 if (filterString.length == 0) 66 if (filterString.length == 0)
95 return loadTimeData.getString('siteSettingsCookieRemoveAll'); 67 return loadTimeData.getString('siteSettingsCookieRemoveAll');
96 return loadTimeData.getString('siteSettingsCookieRemoveAllShown'); 68 return loadTimeData.getString('siteSettingsCookieRemoveAllShown');
97 }, 69 },
98 70
99 /**
100 * Called when the cookie list is ready to be shown.
101 * @param {!CookieList} list The cookie list to show.
102 * @private
103 */
104 loadChildren_: function(list) {
105 var loadChildrenRecurse = function(list) {
106 var parentId = list.id;
107 var children = list.children;
108 var prefix = '';
109 if (parentId !== null) {
110 this.treeNodes_.populateChildNodes(parentId, this.treeNodes_, children);
111 prefix = parentId + ', ';
112 }
113 var promises = [];
114 for (let child of children) {
115 if (child.hasChildren) {
116 promises.push(this.browserProxy.loadCookieChildren(
117 prefix + child.id).then(loadChildrenRecurse.bind(this)));
118 }
119 }
120 return Promise.all(promises);
121 }.bind(this);
122
123 // New root being added, clear the list and add the nodes.
124 this.sites = [];
125 this.treeNodes_.addChildNodes(this.treeNodes_, list.children);
126 loadChildrenRecurse(list).then(function() {
127 this.sites = this.treeNodes_.getSummaryList();
128 }.bind(this));
129 },
130
131 /**
132 * Called when a single item has been removed (not during delete all).
133 * @param {!CookieRemovePacket} args The details about what to remove.
134 * @private
135 */
136 onTreeItemRemoved_: function(args) {
137 this.treeNodes_.removeByParentId(args.id, args.start, args.count);
138 this.sites = this.treeNodes_.getSummaryList();
139 },
140
141 /** @private */ 71 /** @private */
142 onCloseDialog_: function() { 72 onCloseDialog_: function() {
143 this.$.confirmDeleteDialog.close(); 73 this.$.confirmDeleteDialog.close();
144 }, 74 },
145 75
146 /** 76 /**
147 * Shows a dialog to confirm the deletion of multiple sites. 77 * Shows a dialog to confirm the deletion of multiple sites.
148 * @private 78 * @private
149 */ 79 */
150 onConfirmDeleteMultipleSites_: function() { 80 onConfirmDeleteMultipleSites_: function() {
(...skipping 22 matching lines...) Expand all
173 onDeleteSite_: function() { 103 onDeleteSite_: function() {
174 this.browserProxy.removeCookie(this.idToDelete_); 104 this.browserProxy.removeCookie(this.idToDelete_);
175 }, 105 },
176 106
177 /** 107 /**
178 * Deletes site data for multiple sites. 108 * Deletes site data for multiple sites.
179 * @private 109 * @private
180 */ 110 */
181 onDeleteMultipleSites_: function() { 111 onDeleteMultipleSites_: function() {
182 if (this.filterString_.length == 0) { 112 if (this.filterString_.length == 0) {
183 this.browserProxy.removeAllCookies().then(function(list) { 113 this.removeAllCookies();
184 this.loadChildren_(list);
185 }.bind(this));
186 } else { 114 } else {
187 var items = this.$.list.items; 115 var items = this.$.list.items;
188 for (var i = 0; i < items.length; ++i) { 116 for (var i = 0; i < items.length; ++i) {
189 if (this.showItem_(items[i])) 117 if (this.showItem_(items[i]))
190 this.browserProxy.removeCookie(items[i].id); 118 this.browserProxy.removeCookie(items[i].id);
191 } 119 }
192 } 120 }
193 }, 121 },
194 122
195 /** 123 /**
196 * @param {!{model: !{item: CookieDataSummaryItem}}} event 124 * @param {!{model: !{item: CookieDataSummaryItem}}} event
197 * @private 125 * @private
198 */ 126 */
199 onSiteTap_: function(event) { 127 onSiteTap_: function(event) {
200 var dialog = document.createElement('site-data-details-dialog'); 128 var dialog = document.createElement('site-data-details-dialog');
201 dialog.category = this.category; 129 dialog.category = this.category;
202 this.shadowRoot.appendChild(dialog); 130 this.shadowRoot.appendChild(dialog);
203 131
204 var node = this.treeNodes_.fetchNodeById(event.model.item.id, false); 132 var node = this.rootCookieNode_.fetchNodeById(event.model.item.id, false);
205 dialog.open(node); 133 dialog.open(node);
206 134
207 dialog.addEventListener('close', function(event) { 135 dialog.addEventListener('close', function(event) {
208 dialog.remove(); 136 dialog.remove();
209 }); 137 });
210 }, 138 },
211 }); 139 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698