Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(695)

Side by Side Diff: chrome/browser/resources/settings/site_settings/cookie_tree_behavior.js

Issue 2451553008: [MD settings] move cookie tree management to cookie tree behavior (Closed)
Patch Set: review changes Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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>}
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
23 */
24 rootCookieNode: Object,
25 },
26
27 /** @override */
28 ready: function() {
29 cr.addWebUIListener('onTreeItemRemoved',
30 this.onTreeItemRemoved_.bind(this));
31 this.rootCookieNode = new settings.CookieTreeNode(null);
32 },
33
34 /**
35 * Called when the cookie list is ready to be shown.
36 * @param {!CookieList} list The cookie list to show.
37 * @return {Promise}
38 * @private
39 */
40 loadChildren_: function(list) {
41 var loadChildrenRecurse = function(childList) {
42 var parentId = childList.id;
43 var children = childList.children;
44 var prefix = '';
45 if (parentId !== null) {
46 this.rootCookieNode.populateChildNodes(parentId,
47 this.rootCookieNode, children);
48 prefix = parentId + ', ';
49 }
50 var promises = [];
51 for (let child of children) {
52 if (child.hasChildren) {
53 promises.push(this.browserProxy.loadCookieChildren(
54 prefix + child.id).then(loadChildrenRecurse.bind(this)));
55 }
56 }
57 return Promise.all(promises);
58 }.bind(this);
59
60 // New root being added, clear the list and add the nodes.
61 this.sites = [];
62 this.rootCookieNode.addChildNodes(this.rootCookieNode, list.children);
63 return loadChildrenRecurse(list).then(function() {
64 this.sites = this.rootCookieNode.getSummaryList();
65 return Promise.resolve();
66 }.bind(this));
67 },
68
69 /**
70 * Loads (or reloads) the whole cookie list.
71 * @return {Promise}
72 */
73 loadCookies: function() {
74 return this.browserProxy.reloadCookies().then(
75 this.loadChildren_.bind(this));
76 },
77
78 /**
79 * Called when a single item has been removed (not during delete all).
80 * @param {!CookieRemovePacket} args The details about what to remove.
81 * @private
82 */
83 onTreeItemRemoved_: function(args) {
84 this.rootCookieNode.removeByParentId(args.id, args.start, args.count);
85 this.sites = this.rootCookieNode.getSummaryList();
86 },
87
88 /**
89 * Deletes site data for multiple sites.
90 * @return {Promise}
91 */
92 removeAllCookies: function() {
93 return this.browserProxy.removeAllCookies().then(
94 this.loadChildren_.bind(this));
95 },
96 };
97
98 /** @polymerBehavior */
99 var CookieTreeBehavior = [SiteSettingsBehavior, CookieTreeBehaviorImpl];
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698