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 * @typedef {{hasChildren: boolean, | 6 * @typedef {{hasChildren: boolean, |
7 * id: string, | 7 * id: string, |
8 * title: string, | 8 * title: string, |
9 * totalUsage: string, | 9 * totalUsage: string, |
10 * type: string}} | 10 * type: string}} |
11 */ | 11 */ |
12 var CookieDetails; | 12 var CookieDetails; |
13 | 13 |
14 /** | 14 /** |
| 15 * @typedef {{content: string, |
| 16 * label: string}} |
| 17 */ |
| 18 var CookieDataForDisplay; |
| 19 |
| 20 /** |
15 * @typedef {{title: string, | 21 * @typedef {{title: string, |
16 * id: string, | 22 * id: string, |
17 * data: CookieDetails}} | 23 * data: CookieDetails}} |
18 */ | 24 */ |
19 var CookieDataItem; | 25 var CookieDataItem; |
20 | 26 |
21 /** | 27 /** |
22 * @typedef {{site: string, | 28 * @typedef {{site: string, |
23 * id: string, | 29 * id: string, |
24 * localData: string}} | 30 * localData: string}} |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 * @return {!Array<!CookieDataSummaryItem>} The summary list. | 165 * @return {!Array<!CookieDataSummaryItem>} The summary list. |
160 */ | 166 */ |
161 getSummaryList: function() { | 167 getSummaryList: function() { |
162 var list = []; | 168 var list = []; |
163 for (var i = 0; i < this.children_.length; ++i) { | 169 for (var i = 0; i < this.children_.length; ++i) { |
164 var siteEntry = this.children_[i]; | 170 var siteEntry = this.children_[i]; |
165 var title = siteEntry.data_.title; | 171 var title = siteEntry.data_.title; |
166 var id = siteEntry.data_.id; | 172 var id = siteEntry.data_.id; |
167 var description = ''; | 173 var description = ''; |
168 | 174 |
| 175 if (siteEntry.children_.length == 0) |
| 176 continue; |
| 177 |
169 for (var j = 0; j < siteEntry.children_.length; ++j) { | 178 for (var j = 0; j < siteEntry.children_.length; ++j) { |
170 var descriptionNode = siteEntry.children_[j]; | 179 var descriptionNode = siteEntry.children_[j]; |
171 if (j > 0) | 180 if (j > 0) |
172 description += ', '; | 181 description += ', '; |
173 | 182 |
174 // Some types, like quota, have no description nodes. | 183 // Some types, like quota, have no description nodes. |
175 var dataType = ''; | 184 var dataType = ''; |
176 if (descriptionNode.data_.type != undefined) { | 185 if (descriptionNode.data_.type != undefined) { |
177 dataType = descriptionNode.data_.type; | 186 dataType = descriptionNode.data_.type; |
178 } else { | 187 } else { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 if (recursive) { | 223 if (recursive) { |
215 var node = this.children_[i].fetchNodeById(id, true); | 224 var node = this.children_[i].fetchNodeById(id, true); |
216 if (node != null) | 225 if (node != null) |
217 return node; | 226 return node; |
218 } | 227 } |
219 } | 228 } |
220 return null; | 229 return null; |
221 }, | 230 }, |
222 | 231 |
223 /** | 232 /** |
224 * Add cookie data to a given HTML node. | 233 * Get cookie data for a given HTML node. |
225 * @param {HTMLElement} root The node to add the data to. | 234 * @return {!Array<CookieDataForDisplay>} |
226 * @param {!settings.CookieTreeNode} item The data to add. | |
227 */ | 235 */ |
228 addCookieData: function(root, item) { | 236 getCookieData: function(item) { |
| 237 /** @type {!Array<CookieDataForDisplay>} */ |
| 238 var out = []; |
229 var fields = cookieInfo[item.data_.type]; | 239 var fields = cookieInfo[item.data_.type]; |
230 for (var field of fields) { | 240 for (var field of fields) { |
231 // Iterate through the keys found in |cookieInfo| for the given |type| | 241 // Iterate through the keys found in |cookieInfo| for the given |type| |
232 // and see if those keys are present in the data. If so, display them | 242 // and see if those keys are present in the data. If so, display them |
233 // (in the order determined by |cookieInfo|). | 243 // (in the order determined by |cookieInfo|). |
234 var key = field[0]; | 244 var key = field[0]; |
235 if (item.data_[key].length > 0) { | 245 if (item.data_[key].length > 0) { |
236 var label = loadTimeData.getString(field[1]); | 246 var entry = /** @type {CookieDataForDisplay} */({ |
237 | 247 label: loadTimeData.getString(field[1]), |
238 var header = document.createElement('div'); | 248 content: item.data_[key], |
239 header.appendChild(document.createTextNode(label)); | 249 }); |
240 var content = document.createElement('div'); | 250 out.push(entry); |
241 content.appendChild(document.createTextNode(item.data_[key])); | |
242 root.appendChild(header); | |
243 root.appendChild(content); | |
244 } | 251 } |
245 } | 252 } |
| 253 return out; |
246 }, | 254 }, |
247 }; | 255 }; |
248 | 256 |
249 return { | 257 return { |
250 CookieTreeNode: CookieTreeNode, | 258 CookieTreeNode: CookieTreeNode, |
251 }; | 259 }; |
252 }); | 260 }); |
OLD | NEW |