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

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

Issue 2451553008: [MD settings] move cookie tree management to cookie tree behavior (Closed)
Patch Set: review changes 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 * @typedef {{hasChildren: boolean,
7 * id: string,
8 * title: string,
9 * totalUsage: string,
10 * type: string}}
11 */
12 var CookieDetails;
13
14 /**
15 * @typedef {{content: string,
16 * label: string}}
17 */
18 var CookieDataForDisplay;
19
20 /**
21 * @typedef {{title: string, 6 * @typedef {{title: string,
22 * id: string, 7 * id: string,
23 * data: CookieDetails}} 8 * data: CookieDetails}}
24 */ 9 */
25 var CookieDataItem; 10 var CookieDataItem;
26 11
27 /** 12 /**
28 * @typedef {{site: string, 13 * @typedef {{site: string,
29 * id: string, 14 * id: string,
30 * localData: string}} 15 * localData: string}}
31 */ 16 */
32 var CookieDataSummaryItem; 17 var CookieDataSummaryItem;
33 18
34 /** 19 /**
35 * @typedef {{id: string, 20 * @typedef {{id: string,
36 * start: number, 21 * start: number,
37 * children: !Array<CookieDetails>}} 22 * children: !Array<CookieDetails>}}
38 */ 23 */
39 var CookieList; 24 var CookieList;
40 25
41 /** 26 /**
42 * @typedef {{id: string, 27 * @typedef {{id: string,
43 * start: !number, 28 * start: number,
44 * count: !number}} 29 * count: number}}
45 */ 30 */
46 var CookieRemovePacket; 31 var CookieRemovePacket;
47 32
48 var categoryLabels = { 33 var categoryLabels = {
49 'app_cache': loadTimeData.getString('cookieAppCache'), 34 'app_cache': loadTimeData.getString('cookieAppCache'),
50 'cache_storage': loadTimeData.getString('cookieCacheStorage'), 35 'cache_storage': loadTimeData.getString('cookieCacheStorage'),
51 'channel_id': loadTimeData.getString('cookieChannelId'), 36 'channel_id': loadTimeData.getString('cookieChannelId'),
52 'cookie': loadTimeData.getString('cookieSingular'), 37 'cookie': loadTimeData.getString('cookieSingular'),
53 'database': loadTimeData.getString('cookieDatabaseStorage'), 38 'database': loadTimeData.getString('cookieDatabaseStorage'),
54 'file_system': loadTimeData.getString('cookieFileSystem'), 39 'file_system': loadTimeData.getString('cookieFileSystem'),
(...skipping 18 matching lines...) Expand all
73 58
74 cr.define('settings', function() { 59 cr.define('settings', function() {
75 'use strict'; 60 'use strict';
76 61
77 /** 62 /**
78 * @constructor 63 * @constructor
79 */ 64 */
80 function CookieTreeNode(data) { 65 function CookieTreeNode(data) {
81 /** 66 /**
82 * The data for this cookie node. 67 * The data for this cookie node.
83 * @private {CookieDetails} 68 * @type {CookieDetails}
84 */ 69 */
85 this.data_ = data; 70 this.data = data;
86 71
87 /** 72 /**
88 * The child cookie nodes. 73 * The child cookie nodes.
89 * @private {!Array<!settings.CookieTreeNode>} 74 * @private {!Array<!settings.CookieTreeNode>}
90 */ 75 */
91 this.children_ = []; 76 this.children_ = [];
92 }; 77 };
93 78
94 CookieTreeNode.prototype = { 79 CookieTreeNode.prototype = {
95 /** 80 /**
(...skipping 15 matching lines...) Expand all
111 * Looks up a parent node and adds a list of CookieTreeNodes to them. 96 * Looks up a parent node and adds a list of CookieTreeNodes to them.
112 * @param {string} parentId The ID of the parent to add the nodes to. 97 * @param {string} parentId The ID of the parent to add the nodes to.
113 * @param {!settings.CookieTreeNode} startingNode The node to start with 98 * @param {!settings.CookieTreeNode} startingNode The node to start with
114 * when looking for the parent node to add the children to. 99 * when looking for the parent node to add the children to.
115 * @param {!Array<!CookieDetails>} newNodes The list containing the data to 100 * @param {!Array<!CookieDetails>} newNodes The list containing the data to
116 add. 101 add.
117 * @return {boolean} True if the parent node was found. 102 * @return {boolean} True if the parent node was found.
118 */ 103 */
119 populateChildNodes: function(parentId, startingNode, newNodes) { 104 populateChildNodes: function(parentId, startingNode, newNodes) {
120 for (var i = 0; i < startingNode.children_.length; ++i) { 105 for (var i = 0; i < startingNode.children_.length; ++i) {
121 if (startingNode.children_[i].data_.id == parentId) { 106 if (startingNode.children_[i].data.id == parentId) {
122 this.addChildNodes(startingNode.children_[i], newNodes); 107 this.addChildNodes(startingNode.children_[i], newNodes);
123 return true; 108 return true;
124 } 109 }
125 110
126 if (this.populateChildNodes( 111 if (this.populateChildNodes(
127 parentId, startingNode.children_[i], newNodes)) { 112 parentId, startingNode.children_[i], newNodes)) {
128 return true; 113 return true;
129 } 114 }
130 } 115 }
131 return false; 116 return false;
(...skipping 13 matching lines...) Expand all
145 130
146 /** 131 /**
147 * Returns an array of cookies from the current node within the cookie tree. 132 * Returns an array of cookies from the current node within the cookie tree.
148 * @return {!Array<!CookieDataItem>} The Cookie List. 133 * @return {!Array<!CookieDataItem>} The Cookie List.
149 */ 134 */
150 getCookieList: function() { 135 getCookieList: function() {
151 var list = []; 136 var list = [];
152 137
153 for (var group of this.children_) { 138 for (var group of this.children_) {
154 for (var cookie of group.children_) { 139 for (var cookie of group.children_) {
155 list.push({title: cookie.data_.title, 140 list.push({title: cookie.data.title,
156 id: cookie.data_.id, 141 id: cookie.data.id,
157 data: cookie.data_}); 142 data: cookie.data});
158 } 143 }
159 } 144 }
160 145
161 return list; 146 return list;
162 }, 147 },
163 148
164 /** 149 /**
165 * Get a summary list of all sites and their stored data. 150 * Get a summary list of all sites and their stored data.
166 * @return {!Array<!CookieDataSummaryItem>} The summary list. 151 * @return {!Array<!CookieDataSummaryItem>} The summary list.
167 */ 152 */
168 getSummaryList: function() { 153 getSummaryList: function() {
169 var list = []; 154 var list = [];
170 for (var i = 0; i < this.children_.length; ++i) { 155 for (var i = 0; i < this.children_.length; ++i) {
171 var siteEntry = this.children_[i]; 156 var siteEntry = this.children_[i];
172 var title = siteEntry.data_.title; 157 var title = siteEntry.data.title;
173 var id = siteEntry.data_.id; 158 var id = siteEntry.data.id;
174 var description = ''; 159 var description = '';
175 160
176 if (siteEntry.children_.length == 0) 161 if (siteEntry.children_.length == 0)
177 continue; 162 continue;
178 163
179 for (var j = 0; j < siteEntry.children_.length; ++j) { 164 for (var j = 0; j < siteEntry.children_.length; ++j) {
180 var descriptionNode = siteEntry.children_[j]; 165 var descriptionNode = siteEntry.children_[j];
181 if (j > 0) 166 if (j > 0)
182 description += ', '; 167 description += ', ';
183 168
184 // Some types, like quota, have no description nodes. 169 // Some types, like quota, have no description nodes.
185 var dataType = ''; 170 var dataType = '';
186 if (descriptionNode.data_.type != undefined) { 171 if (descriptionNode.data.type != undefined) {
187 dataType = descriptionNode.data_.type; 172 dataType = descriptionNode.data.type;
188 } else { 173 } else {
189 // A description node might not have children when it's deleted. 174 // A description node might not have children when it's deleted.
190 if (descriptionNode.children_.length > 0) 175 if (descriptionNode.children_.length > 0)
191 dataType = descriptionNode.children_[0].data_.type; 176 dataType = descriptionNode.children_[0].data.type;
192 } 177 }
193 178
194 var count = 179 var count =
195 (dataType == 'cookie') ? descriptionNode.children_.length : 0; 180 (dataType == 'cookie') ? descriptionNode.children_.length : 0;
196 if (count > 1) { 181 if (count > 1) {
197 description += loadTimeData.getStringF('cookiePlural', count); 182 description += loadTimeData.getStringF('cookiePlural', count);
198 } else { 183 } else {
199 description += getCookieDataCategoryText( 184 description += getCookieDataCategoryText(
200 dataType, descriptionNode.data_.totalUsage); 185 dataType, descriptionNode.data.totalUsage);
201 } 186 }
202 187
203 } 188 }
204 list.push({ site: title, id: id, localData: description }); 189 list.push({ site: title, id: id, localData: description });
205 } 190 }
206 list.sort(function(a, b) { 191 list.sort(function(a, b) {
207 return a.site.localeCompare(b.site); 192 return a.site.localeCompare(b.site);
208 }); 193 });
209 return list; 194 return list;
210 }, 195 },
211 196
212 /** 197 /**
213 * Fetch a CookieTreeNode by ID. 198 * Fetch a CookieTreeNode by ID.
214 * @param {string} id The ID to look up. 199 * @param {string} id The ID to look up.
215 * @param {boolean} recursive Whether to search the children also. 200 * @param {boolean} recursive Whether to search the children also.
216 * @return {settings.CookieTreeNode} The node found, if any. 201 * @return {settings.CookieTreeNode} The node found, if any.
217 */ 202 */
218 fetchNodeById: function(id, recursive) { 203 fetchNodeById: function(id, recursive) {
219 for (var i = 0; i < this.children_.length; ++i) { 204 for (var i = 0; i < this.children_.length; ++i) {
220 if (this.children_[i] == null) 205 if (this.children_[i] == null)
221 return null; 206 return null;
222 if (this.children_[i].data_.id == id) 207 if (this.children_[i].data.id == id)
223 return this.children_[i]; 208 return this.children_[i];
224 if (recursive) { 209 if (recursive) {
225 var node = this.children_[i].fetchNodeById(id, true); 210 var node = this.children_[i].fetchNodeById(id, true);
226 if (node != null) 211 if (node != null)
227 return node; 212 return node;
228 } 213 }
229 } 214 }
230 return null; 215 return null;
231 }, 216 },
232
233 /**
234 * Get cookie data for a given HTML node.
235 * @return {!Array<CookieDataForDisplay>}
236 */
237 getCookieData: function(item) {
238 /** @type {!Array<CookieDataForDisplay>} */
239 var out = [];
240 var fields = cookieInfo[item.data_.type];
241 for (var field of fields) {
242 // Iterate through the keys found in |cookieInfo| for the given |type|
243 // and see if those keys are present in the data. If so, display them
244 // (in the order determined by |cookieInfo|).
245 var key = field[0];
246 if (item.data_[key].length > 0) {
247 var entry = /** @type {CookieDataForDisplay} */({
248 label: loadTimeData.getString(field[1]),
249 content: item.data_[key],
250 });
251 out.push(entry);
252 }
253 }
254 return out;
255 },
256 }; 217 };
257 218
258 return { 219 return {
259 CookieTreeNode: CookieTreeNode, 220 CookieTreeNode: CookieTreeNode,
260 }; 221 };
261 }); 222 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698