Chromium Code Reviews| 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}} |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 */ | 32 */ |
| 33 var CookieList; | 33 var CookieList; |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * @typedef {{id: string, | 36 * @typedef {{id: string, |
| 37 * start: !number, | 37 * start: !number, |
| 38 * count: !number}} | 38 * count: !number}} |
| 39 */ | 39 */ |
| 40 var CookieRemovePacket; | 40 var CookieRemovePacket; |
| 41 | 41 |
| 42 /** | |
| 43 * Retrieves the human friendly text to show for the type of cookie. | |
| 44 * @param {string} dataType The datatype to look up. | |
| 45 * @param {number} cookieCount How many cookies are involved. | |
| 46 * @param {string} totalUsage How much data is being consumed. | |
| 47 * @return {string} The human-friendly description for this cookie. | |
| 48 */ | |
| 49 function getCookieDataCategoryText(dataType, cookieCount, totalUsage) { | |
| 50 var category = ''; | |
| 51 if (dataType == 'cookie') { | |
| 52 if (cookieCount > 1) | |
| 53 category = loadTimeData.getStringF('cookiePlural', cookieCount); | |
| 54 else | |
| 55 category = loadTimeData.getString('cookieSingular'); | |
| 56 } else if (dataType == 'database') { | |
| 57 category = loadTimeData.getString('cookieDatabaseStorage'); | |
| 58 } else if (dataType == 'local_storage' || dataType == 'indexed_db') { | |
| 59 category = loadTimeData.getString('cookieLocalStorage'); | |
| 60 } else if (dataType == 'app_cache') { | |
| 61 category = loadTimeData.getString('cookieAppCache'); | |
| 62 } else if (dataType == 'file_system') { | |
| 63 category = loadTimeData.getString('cookieFileSystem'); | |
| 64 } else if (dataType == 'quota') { | |
| 65 category = totalUsage; | |
| 66 } else if (dataType == 'channel_id') { | |
| 67 category = loadTimeData.getString('cookieChannelId'); | |
| 68 } else if (dataType == 'service_worker') { | |
| 69 category = loadTimeData.getString('cookieServiceWorker'); | |
| 70 } else if (dataType == 'cache_storage') { | |
| 71 category = loadTimeData.getString('cookieCacheStorage'); | |
| 72 } else if (dataType == 'flash_lso') { | |
| 73 category = loadTimeData.getString('cookieFlashLso'); | |
| 74 } | |
|
dschuyler
2016/08/23 18:53:39
Suggestion: The above is ok, but it might be nicer
Finnur
2016/08/24 11:31:14
I like that suggestion. Closure, doesn't quite lik
| |
| 75 | |
| 76 return category; | |
| 77 } | |
| 78 | |
| 42 cr.define('settings', function() { | 79 cr.define('settings', function() { |
| 43 'use strict'; | 80 'use strict'; |
| 44 | 81 |
| 45 /** | 82 /** |
| 46 * @constructor | 83 * @constructor |
| 47 */ | 84 */ |
| 48 function CookieTreeNode(data) { | 85 function CookieTreeNode(data) { |
| 49 /** | 86 /** |
| 50 * The data for this cookie node. | 87 * The data for this cookie node. |
| 51 * @private {CookieDetails} | 88 * @private {CookieDetails} |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 if (j > 0) | 183 if (j > 0) |
| 147 description += ', '; | 184 description += ', '; |
| 148 | 185 |
| 149 // Some types, like quota, have no description nodes. | 186 // Some types, like quota, have no description nodes. |
| 150 var dataType = ''; | 187 var dataType = ''; |
| 151 if (descriptionNode.data_.type != undefined) | 188 if (descriptionNode.data_.type != undefined) |
| 152 dataType = descriptionNode.data_.type; | 189 dataType = descriptionNode.data_.type; |
| 153 else | 190 else |
| 154 dataType = descriptionNode.children_[0].data_.type; | 191 dataType = descriptionNode.children_[0].data_.type; |
| 155 | 192 |
| 156 var category = ''; | 193 var count = |
| 157 if (dataType == 'cookie') { | 194 (dataType == 'cookie') ? descriptionNode.children_.length : 0; |
| 158 var cookieCount = descriptionNode.children_.length; | 195 description += getCookieDataCategoryText( |
| 159 if (cookieCount > 1) | 196 dataType, count, descriptionNode.data_.totalUsage); |
| 160 category = loadTimeData.getStringF('cookiePlural', cookieCount); | |
| 161 else | |
| 162 category = loadTimeData.getString('cookieSingular'); | |
| 163 } else if (dataType == 'database') { | |
| 164 category = loadTimeData.getString('cookieDatabaseStorage'); | |
| 165 } else if (dataType == 'local_storage' || dataType == 'indexed_db') { | |
| 166 category = loadTimeData.getString('cookieLocalStorage'); | |
| 167 } else if (dataType == 'app_cache') { | |
| 168 category = loadTimeData.getString('cookieAppCache'); | |
| 169 } else if (dataType == 'file_system') { | |
| 170 category = loadTimeData.getString('cookieFileSystem'); | |
| 171 } else if (dataType == 'quota') { | |
| 172 category = descriptionNode.data_.totalUsage; | |
| 173 } else if (dataType == 'channel_id') { | |
| 174 category = loadTimeData.getString('cookieChannelId'); | |
| 175 } else if (dataType == 'service_worker') { | |
| 176 category = loadTimeData.getString('cookieServiceWorker'); | |
| 177 } else if (dataType == 'cache_storage') { | |
| 178 category = loadTimeData.getString('cookieCacheStorage'); | |
| 179 } else if (dataType == 'flash_lso') { | |
| 180 category = loadTimeData.getString('cookieFlashLso'); | |
| 181 } | |
| 182 | |
| 183 description += category; | |
| 184 } | 197 } |
| 185 list.push({ site: title, id: id, localData: description }); | 198 list.push({ site: title, id: id, localData: description }); |
| 186 } | 199 } |
| 187 list.sort(function(a, b) { | 200 list.sort(function(a, b) { |
| 188 return a.site.localeCompare(b.site); | 201 return a.site.localeCompare(b.site); |
| 189 }); | 202 }); |
| 190 return list; | 203 return list; |
| 191 }, | 204 }, |
| 192 | 205 |
| 193 /** | 206 /** |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 root.appendChild(content); | 247 root.appendChild(content); |
| 235 } | 248 } |
| 236 } | 249 } |
| 237 }, | 250 }, |
| 238 }; | 251 }; |
| 239 | 252 |
| 240 return { | 253 return { |
| 241 CookieTreeNode: CookieTreeNode, | 254 CookieTreeNode: CookieTreeNode, |
| 242 }; | 255 }; |
| 243 }); | 256 }); |
| OLD | NEW |