Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * @fileoverview A behavior for managing a tree of cookies. | |
| 7 */ | |
| 8 | |
| 9 /** @polymerBehavior */ | |
| 10 var CookieTreeBehaviorImpl = { | |
| 11 properties: { | |
| 12 /** | |
| 13 * A summary list of all sites and how many entities each contain. | |
| 14 * @type {Array<CookieDataSummaryItem>} | |
|
Dan Beam
2016/10/27 01:31:55
nit: !Array<!CookieDataSummaryItem>
dschuyler
2016/10/27 20:47:35
Done.
| |
| 15 */ | |
| 16 sites: Array, | |
| 17 | |
| 18 /** | |
| 19 * The cookie tree with the details needed to display individual sites and | |
| 20 * their contained data. | |
| 21 * @type {!settings.CookieTreeNode} | |
| 22 * @protected | |
|
Dan Beam
2016/10/27 01:31:55
if this is protected, don't use _
dschuyler
2016/10/27 20:47:35
Done.
| |
| 23 */ | |
| 24 rootCookieNode_: Object, | |
| 25 }, | |
| 26 | |
| 27 ready: function() { | |
| 28 cr.addWebUIListener('onTreeItemRemoved', | |
| 29 this.onTreeItemRemoved_.bind(this)); | |
| 30 this.rootCookieNode_ = new settings.CookieTreeNode(null); | |
| 31 }, | |
| 32 | |
| 33 /** | |
| 34 * Called when the cookie list is ready to be shown. | |
| 35 * @param {!CookieList} list The cookie list to show. | |
| 36 * @return {Promise} | |
| 37 * @private | |
| 38 */ | |
| 39 loadChildren_: function(list) { | |
| 40 var loadChildrenRecurse = function(childList) { | |
| 41 var parentId = childList.id; | |
| 42 var children = childList.children; | |
| 43 var prefix = ''; | |
| 44 if (parentId !== null) { | |
| 45 this.rootCookieNode_.populateChildNodes(parentId, | |
| 46 this.rootCookieNode_, children); | |
| 47 prefix = parentId + ', '; | |
| 48 } | |
| 49 var promises = []; | |
| 50 for (let child of children) { | |
| 51 if (child.hasChildren) { | |
| 52 promises.push(this.browserProxy.loadCookieChildren( | |
| 53 prefix + child.id).then(loadChildrenRecurse.bind(this))); | |
| 54 } | |
| 55 } | |
| 56 return Promise.all(promises); | |
| 57 }.bind(this); | |
| 58 | |
| 59 // New root being added, clear the list and add the nodes. | |
| 60 this.sites = []; | |
| 61 this.rootCookieNode_.addChildNodes(this.rootCookieNode_, list.children); | |
| 62 return loadChildrenRecurse(list).then(function() { | |
| 63 this.sites = this.rootCookieNode_.getSummaryList(); | |
| 64 return Promise.resolve(); | |
| 65 }.bind(this)); | |
| 66 }, | |
| 67 | |
| 68 /** | |
| 69 * Loads (or reloads) the whole cookie list. | |
| 70 * @return {Promise} | |
| 71 */ | |
| 72 loadCookies: function() { | |
| 73 return this.browserProxy.reloadCookies().then( | |
| 74 this.loadChildren_.bind(this)); | |
| 75 }, | |
| 76 | |
| 77 /** | |
| 78 * Called when a single item has been removed (not during delete all). | |
| 79 * @param {!CookieRemovePacket} args The details about what to remove. | |
| 80 * @private | |
| 81 */ | |
| 82 onTreeItemRemoved_: function(args) { | |
| 83 this.rootCookieNode_.removeByParentId(args.id, args.start, args.count); | |
| 84 this.sites = this.rootCookieNode_.getSummaryList(); | |
| 85 }, | |
| 86 | |
| 87 /** | |
| 88 * Deletes site data for multiple sites. | |
| 89 * @return {Promise} | |
| 90 */ | |
| 91 removeAllCookies: function() { | |
| 92 return this.browserProxy.removeAllCookies().then( | |
| 93 this.loadChildren_.bind(this)); | |
| 94 }, | |
| 95 }; | |
| 96 | |
| 97 /** @polymerBehavior */ | |
| 98 var CookieTreeBehavior = [SiteSettingsBehavior, CookieTreeBehaviorImpl]; | |
| OLD | NEW |