| 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 (let child of children) { | 51 for (let child of children) { |
| 52 if (child.hasChildren) { | 52 if (child.hasChildren) { |
| 53 promises.push(this.browserProxy.loadCookieChildren( | 53 promises.push(this.browserProxy.loadCookieChildren(prefix + child.id) |
| 54 prefix + child.id).then(loadChildrenRecurse.bind(this))); | 54 .then(loadChildrenRecurse.bind(this))); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 return Promise.all(promises); | 57 return Promise.all(promises); |
| 58 }.bind(this); | 58 }.bind(this); |
| 59 | 59 |
| 60 // New root being added, clear the list and add the nodes. | 60 // New root being added, clear the list and add the nodes. |
| 61 this.sites = []; | 61 this.sites = []; |
| 62 this.rootCookieNode.addChildNodes(this.rootCookieNode, list.children); | 62 this.rootCookieNode.addChildNodes(this.rootCookieNode, list.children); |
| 63 return loadChildrenRecurse(list).then(function() { | 63 return loadChildrenRecurse(list).then(function() { |
| 64 this.sites = this.rootCookieNode.getSummaryList(); | 64 this.sites = this.rootCookieNode.getSummaryList(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 90 * @return {Promise} | 90 * @return {Promise} |
| 91 */ | 91 */ |
| 92 removeAllCookies: function() { | 92 removeAllCookies: function() { |
| 93 return this.browserProxy.removeAllCookies().then( | 93 return this.browserProxy.removeAllCookies().then( |
| 94 this.loadChildren_.bind(this)); | 94 this.loadChildren_.bind(this)); |
| 95 }, | 95 }, |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 /** @polymerBehavior */ | 98 /** @polymerBehavior */ |
| 99 var CookieTreeBehavior = [SiteSettingsBehavior, CookieTreeBehaviorImpl]; | 99 var CookieTreeBehavior = [SiteSettingsBehavior, CookieTreeBehaviorImpl]; |
| OLD | NEW |