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 {{title: string, | 6 * @typedef {{title: string, |
| 7 * id: string, | 7 * id: string, |
| 8 * data: CookieDetails}} | 8 * data: CookieDetails}} |
| 9 */ | 9 */ |
| 10 var CookieDataItem; | 10 var CookieDataItem; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 var node = id == null ? this : this.fetchNodeById(id, true); | 127 var node = id == null ? this : this.fetchNodeById(id, true); |
| 128 node.children_.splice(firstChild, count); | 128 node.children_.splice(firstChild, count); |
| 129 }, | 129 }, |
| 130 | 130 |
| 131 /** | 131 /** |
| 132 * 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. |
| 133 * @return {!Array<!CookieDataItem>} The Cookie List. | 133 * @return {!Array<!CookieDataItem>} The Cookie List. |
| 134 */ | 134 */ |
| 135 getCookieList: function() { | 135 getCookieList: function() { |
| 136 var list = []; | 136 var list = []; |
| 137 | |
| 138 for (var group of this.children_) { | 137 for (var group of this.children_) { |
| 139 for (var cookie of group.children_) { | 138 for (var cookie of group.children_) { |
| 140 list.push({title: cookie.data.title, | 139 list.push({title: cookie.data.title, |
| 141 id: cookie.data.id, | 140 id: cookie.data.id, |
| 142 data: cookie.data}); | 141 data: cookie.data}); |
| 143 } | 142 } |
| 144 } | 143 } |
| 145 | |
| 146 return list; | 144 return list; |
| 147 }, | 145 }, |
| 148 | 146 |
| 149 /** | 147 /** |
| 150 * Get a summary list of all sites and their stored data. | 148 * Get a summary list of all sites and their stored data. |
| 151 * @return {!Array<!CookieDataSummaryItem>} The summary list. | 149 * @return {!Array<!CookieDataSummaryItem>} The summary list. |
| 152 */ | 150 */ |
| 153 getSummaryList: function() { | 151 getSummaryList: function() { |
| 154 var list = []; | 152 var list = []; |
| 155 for (var i = 0; i < this.children_.length; ++i) { | 153 for (var i = 0; i < this.children_.length; ++i) { |
| 156 var siteEntry = this.children_[i]; | 154 var siteEntry = this.children_[i]; |
| 157 var title = siteEntry.data.title; | 155 var title = siteEntry.data.title; |
| 158 var id = siteEntry.data.id; | 156 var id = siteEntry.data.id; |
| 159 var description = ''; | 157 var description = ''; |
| 160 | |
| 161 if (siteEntry.children_.length == 0) | 158 if (siteEntry.children_.length == 0) |
| 162 continue; | 159 continue; |
| 163 | 160 |
| 164 for (var j = 0; j < siteEntry.children_.length; ++j) { | 161 for (var j = 0; j < siteEntry.children_.length; ++j) { |
| 165 var descriptionNode = siteEntry.children_[j]; | 162 var descriptionNode = siteEntry.children_[j]; |
| 166 if (j > 0) | 163 if (j > 0) |
| 167 description += ', '; | 164 description += ', '; |
| 168 | 165 |
| 169 // Some types, like quota, have no description nodes. | 166 // Some types, like quota, have no description nodes. |
| 170 var dataType = ''; | 167 var dataType = ''; |
| 171 if (descriptionNode.data.type != undefined) { | 168 if (descriptionNode.data.type != undefined) { |
| 172 dataType = descriptionNode.data.type; | 169 dataType = descriptionNode.data.type; |
| 173 } else { | 170 } else { |
| 174 // A description node might not have children when it's deleted. | 171 // A description node might not have children when it's deleted. |
| 175 if (descriptionNode.children_.length > 0) | 172 if (descriptionNode.children_.length > 0) |
| 176 dataType = descriptionNode.children_[0].data.type; | 173 dataType = descriptionNode.children_[0].data.type; |
| 177 } | 174 } |
| 178 | |
| 179 var count = | 175 var count = |
| 180 (dataType == 'cookie') ? descriptionNode.children_.length : 0; | 176 (dataType == 'cookie') ? descriptionNode.children_.length : 0; |
| 181 if (count > 1) { | 177 if (count > 1) { |
| 182 description += loadTimeData.getStringF('cookiePlural', count); | 178 description += loadTimeData.getStringF('cookiePlural', count); |
| 183 } else { | 179 } else { |
| 184 description += getCookieDataCategoryText( | 180 description += getCookieDataCategoryText( |
| 185 dataType, descriptionNode.data.totalUsage); | 181 dataType, descriptionNode.data.totalUsage); |
| 186 } | 182 } |
| 187 | |
|
Dan Beam
2016/11/01 06:33:27
why did you make all these changes? ^
dschuyler
2016/11/01 18:55:34
Personal readability and over application of the c
Dan Beam
2016/11/01 19:10:15
yeah, last removal is fine
| |
| 188 } | 183 } |
| 189 list.push({ site: title, id: id, localData: description }); | 184 list.push({ site: title, id: id, localData: description }); |
| 190 } | 185 } |
| 191 list.sort(function(a, b) { | 186 list.sort(function(a, b) { |
| 192 return a.site.localeCompare(b.site); | 187 return a.site.localeCompare(b.site); |
| 193 }); | 188 }); |
| 194 return list; | 189 return list; |
| 195 }, | 190 }, |
| 196 | 191 |
| 197 /** | 192 /** |
| 198 * Fetch a CookieTreeNode by ID. | 193 * Fetch a CookieTreeNode by ID. |
| 199 * @param {string} id The ID to look up. | 194 * @param {string} id The ID to look up. |
| 200 * @param {boolean} recursive Whether to search the children also. | 195 * @param {boolean} recursive Whether to search the children also. |
| 201 * @return {settings.CookieTreeNode} The node found, if any. | 196 * @return {settings.CookieTreeNode} The node found, if any. |
| 202 */ | 197 */ |
| 203 fetchNodeById: function(id, recursive) { | 198 fetchNodeById: function(id, recursive) { |
| 204 for (var i = 0; i < this.children_.length; ++i) { | 199 for (var i = 0; i < this.children_.length; ++i) { |
| 205 if (this.children_[i] == null) | 200 if (this.children_[i] == null) |
| 206 return null; | 201 return null; |
| 207 if (this.children_[i].data.id == id) | 202 if (this.children_[i].data.id == id) |
| 208 return this.children_[i]; | 203 return this.children_[i]; |
| 209 if (recursive) { | 204 if (recursive) { |
| 210 var node = this.children_[i].fetchNodeById(id, true); | 205 var node = this.children_[i].fetchNodeById(id, true); |
| 211 if (node != null) | 206 if (node != null) |
| 212 return node; | 207 return node; |
| 213 } | 208 } |
| 214 } | 209 } |
| 215 return null; | 210 return null; |
| 216 }, | 211 }, |
| 212 | |
| 213 /** | |
| 214 * Fetch a CookieTreeNode by site. | |
| 215 * @param {string} site The web site to look up. | |
| 216 * @param {boolean} recursive Whether to search the children also. | |
| 217 * @return {settings.CookieTreeNode} The node found, if any. | |
|
Dan Beam
2016/11/01 06:33:27
?settings.CookieTreeNode
dschuyler
2016/11/01 18:55:34
Done.
| |
| 218 */ | |
| 219 fetchNodeBySite: function(site, recursive) { | |
| 220 for (var i = 0; i < this.children_.length; ++i) { | |
| 221 if (this.children_[i] == null) | |
|
Dan Beam
2016/11/01 06:33:27
when does this happen?
dschuyler
2016/11/01 18:55:34
This was based on a similar existing function. Thi
| |
| 222 return null; | |
| 223 if (this.children_[i].data.title == site) | |
| 224 return this.children_[i]; | |
| 225 if (recursive) { | |
| 226 var node = this.children_[i].fetchNodeBySite(site, true); | |
| 227 if (node != null) | |
| 228 return node; | |
| 229 } | |
| 230 } | |
| 231 return null; | |
| 232 }, | |
| 217 }; | 233 }; |
| 218 | 234 |
| 219 return { | 235 return { |
| 220 CookieTreeNode: CookieTreeNode, | 236 CookieTreeNode: CookieTreeNode, |
| 221 }; | 237 }; |
| 222 }); | 238 }); |
| OLD | NEW |