OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 * @fileoverview A behavior for managing a tree of cookies. | 6 * @fileoverview A behavior for managing a tree of cookies. |
7 */ | 7 */ |
8 | 8 |
9 /** @polymerBehavior */ | 9 /** @polymerBehavior */ |
10 var CookieTreeBehaviorImpl = { | 10 var CookieTreeBehaviorImpl = { |
11 properties: { | 11 properties: { |
12 /** | 12 /** |
13 * A summary list of all sites and how many entities each contain. | 13 * A summary list of all sites and how many entities each contain. |
14 * @type {!Array<!CookieDataSummaryItem>} | 14 * @type {!Array<!CookieDataSummaryItem>} |
15 */ | 15 */ |
16 sites: Array, | 16 sites: Array, |
17 | 17 |
18 /** | 18 /** |
19 * The cookie tree with the details needed to display individual sites and | 19 * The cookie tree with the details needed to display individual sites and |
20 * their contained data. | 20 * their contained data. |
21 * @type {!settings.CookieTreeNode} | 21 * @type {!settings.CookieTreeNode} |
22 * @protected | 22 * @protected |
23 */ | 23 */ |
24 rootCookieNode: Object, | 24 rootCookieNode: Object, |
25 }, | 25 }, |
26 | 26 |
27 /** @override */ | 27 /** @override */ |
28 ready: function() { | 28 ready: function() { |
29 cr.addWebUIListener('onTreeItemRemoved', | 29 cr.addWebUIListener( |
30 this.onTreeItemRemoved_.bind(this)); | 30 'onTreeItemRemoved', this.onTreeItemRemoved_.bind(this)); |
31 this.rootCookieNode = new settings.CookieTreeNode(null); | 31 this.rootCookieNode = new settings.CookieTreeNode(null); |
32 }, | 32 }, |
33 | 33 |
34 /** | 34 /** |
35 * Called when the cookie list is ready to be shown. | 35 * Called when the cookie list is ready to be shown. |
36 * @param {!CookieList} list The cookie list to show. | 36 * @param {!CookieList} list The cookie list to show. |
37 * @return {Promise} | 37 * @return {Promise} |
38 * @private | 38 * @private |
39 */ | 39 */ |
40 loadChildren_: function(list) { | 40 loadChildren_: function(list) { |
41 var loadChildrenRecurse = function(childList) { | 41 var loadChildrenRecurse = function(childList) { |
42 var parentId = childList.id; | 42 var parentId = childList.id; |
43 var children = childList.children; | 43 var children = childList.children; |
44 var prefix = ''; | 44 var prefix = ''; |
45 if (parentId !== null) { | 45 if (parentId !== null) { |
46 this.rootCookieNode.populateChildNodes(parentId, | 46 this.rootCookieNode.populateChildNodes( |
47 this.rootCookieNode, children); | 47 parentId, this.rootCookieNode, children); |
48 prefix = parentId + ', '; | 48 prefix = parentId + ', '; |
49 } | 49 } |
50 var promises = []; | 50 var promises = []; |
51 for (var i = 0; i < children.length; i++) { | 51 for (var i = 0; i < children.length; i++) { |
52 var child = children[i]; | 52 var child = children[i]; |
53 if (child.hasChildren) { | 53 if (child.hasChildren) { |
54 promises.push(this.browserProxy.loadCookieChildren( | 54 promises.push(this.browserProxy.loadCookieChildren(prefix + child.id) |
55 prefix + child.id).then(loadChildrenRecurse.bind(this))); | 55 .then(loadChildrenRecurse.bind(this))); |
56 } | 56 } |
57 } | 57 } |
58 return Promise.all(promises); | 58 return Promise.all(promises); |
59 }.bind(this); | 59 }.bind(this); |
60 | 60 |
61 // New root being added, clear the list and add the nodes. | 61 // New root being added, clear the list and add the nodes. |
62 this.sites = []; | 62 this.sites = []; |
63 this.rootCookieNode.addChildNodes(this.rootCookieNode, list.children); | 63 this.rootCookieNode.addChildNodes(this.rootCookieNode, list.children); |
64 return loadChildrenRecurse(list).then(function() { | 64 return loadChildrenRecurse(list).then(function() { |
65 this.sites = this.rootCookieNode.getSummaryList(); | 65 this.sites = this.rootCookieNode.getSummaryList(); |
(...skipping 25 matching lines...) Expand all Loading... |
91 * @return {Promise} | 91 * @return {Promise} |
92 */ | 92 */ |
93 removeAllCookies: function() { | 93 removeAllCookies: function() { |
94 return this.browserProxy.removeAllCookies().then( | 94 return this.browserProxy.removeAllCookies().then( |
95 this.loadChildren_.bind(this)); | 95 this.loadChildren_.bind(this)); |
96 }, | 96 }, |
97 }; | 97 }; |
98 | 98 |
99 /** @polymerBehavior */ | 99 /** @polymerBehavior */ |
100 var CookieTreeBehavior = [SiteSettingsBehavior, CookieTreeBehaviorImpl]; | 100 var CookieTreeBehavior = [SiteSettingsBehavior, CookieTreeBehaviorImpl]; |
OLD | NEW |