Chromium Code Reviews| Index: chrome/browser/resources/settings/site_settings/cookie_tree_behavior.js |
| diff --git a/chrome/browser/resources/settings/site_settings/cookie_tree_behavior.js b/chrome/browser/resources/settings/site_settings/cookie_tree_behavior.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..24b2548e5cadd3ed2022296b264a4f21af95a6f0 |
| --- /dev/null |
| +++ b/chrome/browser/resources/settings/site_settings/cookie_tree_behavior.js |
| @@ -0,0 +1,98 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview A behavior for managing a tree of cookies. |
| + */ |
| + |
| +/** @polymerBehavior */ |
| +var CookieTreeBehaviorImpl = { |
| + properties: { |
| + /** |
| + * A summary list of all sites and how many entities each contain. |
| + * @type {Array<CookieDataSummaryItem>} |
|
Dan Beam
2016/10/27 01:31:55
nit: !Array<!CookieDataSummaryItem>
dschuyler
2016/10/27 20:47:35
Done.
|
| + */ |
| + sites: Array, |
| + |
| + /** |
| + * The cookie tree with the details needed to display individual sites and |
| + * their contained data. |
| + * @type {!settings.CookieTreeNode} |
| + * @protected |
|
Dan Beam
2016/10/27 01:31:55
if this is protected, don't use _
dschuyler
2016/10/27 20:47:35
Done.
|
| + */ |
| + rootCookieNode_: Object, |
| + }, |
| + |
| + ready: function() { |
| + cr.addWebUIListener('onTreeItemRemoved', |
| + this.onTreeItemRemoved_.bind(this)); |
| + this.rootCookieNode_ = new settings.CookieTreeNode(null); |
| + }, |
| + |
| + /** |
| + * Called when the cookie list is ready to be shown. |
| + * @param {!CookieList} list The cookie list to show. |
| + * @return {Promise} |
| + * @private |
| + */ |
| + loadChildren_: function(list) { |
| + var loadChildrenRecurse = function(childList) { |
| + var parentId = childList.id; |
| + var children = childList.children; |
| + var prefix = ''; |
| + if (parentId !== null) { |
| + this.rootCookieNode_.populateChildNodes(parentId, |
| + this.rootCookieNode_, children); |
| + prefix = parentId + ', '; |
| + } |
| + var promises = []; |
| + for (let child of children) { |
| + if (child.hasChildren) { |
| + promises.push(this.browserProxy.loadCookieChildren( |
| + prefix + child.id).then(loadChildrenRecurse.bind(this))); |
| + } |
| + } |
| + return Promise.all(promises); |
| + }.bind(this); |
| + |
| + // New root being added, clear the list and add the nodes. |
| + this.sites = []; |
| + this.rootCookieNode_.addChildNodes(this.rootCookieNode_, list.children); |
| + return loadChildrenRecurse(list).then(function() { |
| + this.sites = this.rootCookieNode_.getSummaryList(); |
| + return Promise.resolve(); |
| + }.bind(this)); |
| + }, |
| + |
| + /** |
| + * Loads (or reloads) the whole cookie list. |
| + * @return {Promise} |
| + */ |
| + loadCookies: function() { |
| + return this.browserProxy.reloadCookies().then( |
| + this.loadChildren_.bind(this)); |
| + }, |
| + |
| + /** |
| + * Called when a single item has been removed (not during delete all). |
| + * @param {!CookieRemovePacket} args The details about what to remove. |
| + * @private |
| + */ |
| + onTreeItemRemoved_: function(args) { |
| + this.rootCookieNode_.removeByParentId(args.id, args.start, args.count); |
| + this.sites = this.rootCookieNode_.getSummaryList(); |
| + }, |
| + |
| + /** |
| + * Deletes site data for multiple sites. |
| + * @return {Promise} |
| + */ |
| + removeAllCookies: function() { |
| + return this.browserProxy.removeAllCookies().then( |
| + this.loadChildren_.bind(this)); |
| + }, |
| +}; |
| + |
| +/** @polymerBehavior */ |
| +var CookieTreeBehavior = [SiteSettingsBehavior, CookieTreeBehaviorImpl]; |