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

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

Issue 2965643004: MD Settings: Convert remaining classes to ES6 syntax. (Closed)
Patch Set: Fix Created 3 years, 5 months 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
« no previous file with comments | « chrome/browser/resources/settings/passwords_and_forms_page/passwords_section.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 {{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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 */ 52 */
53 function getCookieDataCategoryText(dataType, totalUsage) { 53 function getCookieDataCategoryText(dataType, totalUsage) {
54 if (dataType == 'quota') 54 if (dataType == 'quota')
55 return totalUsage; 55 return totalUsage;
56 return categoryLabels[dataType]; 56 return categoryLabels[dataType];
57 } 57 }
58 58
59 cr.define('settings', function() { 59 cr.define('settings', function() {
60 'use strict'; 60 'use strict';
61 61
62 /** 62 class CookieTreeNode {
63 * @constructor 63 constructor(data) {
64 */ 64 /**
65 function CookieTreeNode(data) { 65 * The data for this cookie node.
66 /** 66 * @type {CookieDetails}
67 * The data for this cookie node. 67 */
68 * @type {CookieDetails} 68 this.data = data;
69 */
70 this.data = data;
71 69
72 /** 70 /**
73 * The child cookie nodes. 71 * The child cookie nodes.
74 * @private {!Array<!settings.CookieTreeNode>} 72 * @private {!Array<!settings.CookieTreeNode>}
75 */ 73 */
76 this.children_ = []; 74 this.children_ = [];
77 } 75 }
78 76
79 CookieTreeNode.prototype = {
80 /** 77 /**
81 * Converts a list of cookies and add them as CookieTreeNode children to 78 * Converts a list of cookies and add them as CookieTreeNode children to
82 * the given parent node. 79 * the given parent node.
83 * @param {!settings.CookieTreeNode} parentNode The parent node to add 80 * @param {!settings.CookieTreeNode} parentNode The parent node to add
84 * children to. 81 * children to.
85 * @param {!Array<!CookieDetails>} newNodes The list containing the data to 82 * @param {!Array<!CookieDetails>} newNodes The list containing the data to
86 * add. 83 * add.
87 */ 84 */
88 addChildNodes: function(parentNode, newNodes) { 85 addChildNodes(parentNode, newNodes) {
89 var nodes = newNodes.map(function(x) { 86 var nodes = newNodes.map(function(x) {
90 return new settings.CookieTreeNode(x); 87 return new settings.CookieTreeNode(x);
91 }); 88 });
92 parentNode.children_ = nodes; 89 parentNode.children_ = nodes;
93 }, 90 }
94 91
95 /** 92 /**
96 * Looks up a parent node and adds a list of CookieTreeNodes to them. 93 * Looks up a parent node and adds a list of CookieTreeNodes to them.
97 * @param {string} parentId The ID of the parent to add the nodes to. 94 * @param {string} parentId The ID of the parent to add the nodes to.
98 * @param {!settings.CookieTreeNode} startingNode The node to start with 95 * @param {!settings.CookieTreeNode} startingNode The node to start with
99 * when looking for the parent node to add the children to. 96 * when looking for the parent node to add the children to.
100 * @param {!Array<!CookieDetails>} newNodes The list containing the data to 97 * @param {!Array<!CookieDetails>} newNodes The list containing the data to
101 add. 98 add.
102 * @return {boolean} True if the parent node was found. 99 * @return {boolean} True if the parent node was found.
103 */ 100 */
104 populateChildNodes: function(parentId, startingNode, newNodes) { 101 populateChildNodes(parentId, startingNode, newNodes) {
105 for (var i = 0; i < startingNode.children_.length; ++i) { 102 for (var i = 0; i < startingNode.children_.length; ++i) {
106 if (startingNode.children_[i].data.id == parentId) { 103 if (startingNode.children_[i].data.id == parentId) {
107 this.addChildNodes(startingNode.children_[i], newNodes); 104 this.addChildNodes(startingNode.children_[i], newNodes);
108 return true; 105 return true;
109 } 106 }
110 107
111 if (this.populateChildNodes( 108 if (this.populateChildNodes(
112 parentId, startingNode.children_[i], newNodes)) { 109 parentId, startingNode.children_[i], newNodes)) {
113 return true; 110 return true;
114 } 111 }
115 } 112 }
116 return false; 113 return false;
117 }, 114 }
118 115
119 /** 116 /**
120 * Removes child nodes from a node with a given id. 117 * Removes child nodes from a node with a given id.
121 * @param {string} id The id of the parent node to delete from. 118 * @param {string} id The id of the parent node to delete from.
122 * @param {number} firstChild The index of the first child to start deleting 119 * @param {number} firstChild The index of the first child to start deleting
123 * from. 120 * from.
124 * @param {number} count The number of children to delete. 121 * @param {number} count The number of children to delete.
125 */ 122 */
126 removeByParentId: function(id, firstChild, count) { 123 removeByParentId(id, firstChild, count) {
127 var node = id == null ? this : this.fetchNodeById(id, true); 124 var node = id == null ? this : this.fetchNodeById(id, true);
128 node.children_.splice(firstChild, count); 125 node.children_.splice(firstChild, count);
129 }, 126 }
130 127
131 /** 128 /**
132 * Returns an array of cookies from the current node within the cookie tree. 129 * Returns an array of cookies from the current node within the cookie tree.
133 * @return {!Array<!CookieDataItem>} The Cookie List. 130 * @return {!Array<!CookieDataItem>} The Cookie List.
134 */ 131 */
135 getCookieList: function() { 132 getCookieList() {
136 var list = []; 133 var list = [];
137 for (var i = 0; i < this.children_.length; i++) { 134 for (var i = 0; i < this.children_.length; i++) {
138 var child = this.children_[i]; 135 var child = this.children_[i];
139 for (var j = 0; j < child.children_.length; j++) { 136 for (var j = 0; j < child.children_.length; j++) {
140 var cookie = child.children_[j]; 137 var cookie = child.children_[j];
141 list.push({ 138 list.push({
142 title: cookie.data.title, 139 title: cookie.data.title,
143 id: cookie.data.id, 140 id: cookie.data.id,
144 data: cookie.data 141 data: cookie.data
145 }); 142 });
146 } 143 }
147 } 144 }
148 145
149 return list; 146 return list;
150 }, 147 }
151 148
152 /** 149 /**
153 * Get a summary list of all sites and their stored data. 150 * Get a summary list of all sites and their stored data.
154 * @return {!Array<!CookieDataSummaryItem>} The summary list. 151 * @return {!Array<!CookieDataSummaryItem>} The summary list.
155 */ 152 */
156 getSummaryList: function() { 153 getSummaryList() {
157 var list = []; 154 var list = [];
158 for (var i = 0; i < this.children_.length; ++i) { 155 for (var i = 0; i < this.children_.length; ++i) {
159 var siteEntry = this.children_[i]; 156 var siteEntry = this.children_[i];
160 var title = siteEntry.data.title; 157 var title = siteEntry.data.title;
161 var id = siteEntry.data.id; 158 var id = siteEntry.data.id;
162 var description = ''; 159 var description = '';
163 160
164 if (siteEntry.children_.length == 0) 161 if (siteEntry.children_.length == 0)
165 continue; 162 continue;
166 163
(...skipping 20 matching lines...) Expand all
187 description += getCookieDataCategoryText( 184 description += getCookieDataCategoryText(
188 dataType, descriptionNode.data.totalUsage); 185 dataType, descriptionNode.data.totalUsage);
189 } 186 }
190 } 187 }
191 list.push({site: title, id: id, localData: description}); 188 list.push({site: title, id: id, localData: description});
192 } 189 }
193 list.sort(function(a, b) { 190 list.sort(function(a, b) {
194 return a.site.localeCompare(b.site); 191 return a.site.localeCompare(b.site);
195 }); 192 });
196 return list; 193 return list;
197 }, 194 }
198 195
199 /** 196 /**
200 * Fetch a CookieTreeNode by ID. 197 * Fetch a CookieTreeNode by ID.
201 * @param {string} id The ID to look up. 198 * @param {string} id The ID to look up.
202 * @param {boolean} recursive Whether to search the children also. 199 * @param {boolean} recursive Whether to search the children also.
203 * @return {settings.CookieTreeNode} The node found, if any. 200 * @return {settings.CookieTreeNode} The node found, if any.
204 */ 201 */
205 fetchNodeById: function(id, recursive) { 202 fetchNodeById(id, recursive) {
206 for (var i = 0; i < this.children_.length; ++i) { 203 for (var i = 0; i < this.children_.length; ++i) {
207 if (this.children_[i] == null) 204 if (this.children_[i] == null)
208 return null; 205 return null;
209 if (this.children_[i].data.id == id) 206 if (this.children_[i].data.id == id)
210 return this.children_[i]; 207 return this.children_[i];
211 if (recursive) { 208 if (recursive) {
212 var node = this.children_[i].fetchNodeById(id, true); 209 var node = this.children_[i].fetchNodeById(id, true);
213 if (node != null) 210 if (node != null)
214 return node; 211 return node;
215 } 212 }
216 } 213 }
217 return null; 214 return null;
218 }, 215 }
219 216
220 /** 217 /**
221 * Fetch a CookieTreeNode by site. 218 * Fetch a CookieTreeNode by site.
222 * @param {string} site The web site to look up. 219 * @param {string} site The web site to look up.
223 * @return {?settings.CookieTreeNode} The node found, if any. 220 * @return {?settings.CookieTreeNode} The node found, if any.
224 */ 221 */
225 fetchNodeBySite: function(site) { 222 fetchNodeBySite(site) {
226 for (var i = 0; i < this.children_.length; ++i) { 223 for (var i = 0; i < this.children_.length; ++i) {
227 if (this.children_[i].data.title == site) 224 if (this.children_[i].data.title == site)
228 return this.children_[i]; 225 return this.children_[i];
229 } 226 }
230 return null; 227 return null;
231 }, 228 }
232 }; 229 }
233 230
234 return { 231 return {
235 CookieTreeNode: CookieTreeNode, 232 CookieTreeNode: CookieTreeNode,
236 }; 233 };
237 }); 234 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/settings/passwords_and_forms_page/passwords_section.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698