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 = { |
(...skipping 20 matching lines...) Expand all Loading... |
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 = 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( | 46 this.rootCookieNode.populateChildNodes( |
47 parentId, 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(prefix + child.id) | 54 promises.push(this.browserProxy.loadCookieChildren(prefix + child.id) |
55 .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 }; |
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(() => { |
65 this.sites = this.rootCookieNode.getSummaryList(); | 65 this.sites = this.rootCookieNode.getSummaryList(); |
66 return Promise.resolve(); | 66 return Promise.resolve(); |
67 }.bind(this)); | 67 }); |
68 }, | 68 }, |
69 | 69 |
70 /** | 70 /** |
71 * Loads (or reloads) the whole cookie list. | 71 * Loads (or reloads) the whole cookie list. |
72 * @return {Promise} | 72 * @return {Promise} |
73 */ | 73 */ |
74 loadCookies: function() { | 74 loadCookies: function() { |
75 return this.browserProxy.reloadCookies().then( | 75 return this.browserProxy.reloadCookies().then( |
76 this.loadChildren_.bind(this)); | 76 this.loadChildren_.bind(this)); |
77 }, | 77 }, |
(...skipping 13 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 |