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

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

Issue 2450423002: [MD settings] cookie and site data from dialog to subpage (Closed)
Patch Set: improved closure type reference 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 (function() {
6 'use strict';
7
8 /**
9 * 'site-data-details-subpage' Display cookie contents.
10 */
11 Polymer({
12 is: 'site-data-details-subpage',
13
14 behaviors: [settings.RouteObserverBehavior, CookieTreeBehavior],
15
16 properties: {
17 /**
18 * The cookie entries for the given site.
19 * @type {!Array<!CookieDataItem>}
20 * @private
21 */
22 entries_: Array,
23
24 /** Set the page title on the settings-subpage parent. */
25 pageTitle: {
26 type: String,
27 notify: true,
28 },
29
30 /**
31 * The site to show details for.
32 * @type {!settings.CookieTreeNode}
33 * @private
34 */
35 site_: Object,
36 },
37
38 attached: function() {
39 this.addEventListener('cookie-tree-changed',
40 this.onCookiesLoaded_.bind(this));
Dan Beam 2016/11/02 06:13:11 nit: listeners: {'cookie-tree-changed': 'onCookies
dschuyler 2016/11/02 18:24:49 Done.
41 },
42
43 /**
44 * settings.RouteObserverBehavior
45 * @param {!settings.Route} route
46 * @protected
47 */
48 currentRouteChanged: function(route) {
49 if (settings.getCurrentRoute() != settings.Route.SITE_SETTINGS_DATA_DETAILS)
50 return;
51 this.siteTitle_ = settings.getQueryParameters().get('site');
52 if (!this.siteTitle_)
53 return;
54 this.loadCookies().then(this.onCookiesLoaded_.bind(this));
55 this.pageTitle = this.siteTitle_;
56 },
57
58 /**
59 * @return {!Array<!CookieDataForDisplay>}
60 * @private
61 */
62 getCookieNodes_: function(cookie) {
63 var node = this.rootCookieNode.fetchNodeById(cookie.id, true);
64 if (!node)
65 return [];
66 return getCookieData(node.data);
67 },
68
69 /**
70 * settings.RouteObserverBehavior
71 * @private
72 */
73 onCookiesLoaded_: function() {
74 var node = this.rootCookieNode.fetchNodeBySite(this.siteTitle_);
75 if (node) {
76 this.site_ = node;
77 this.entries_ = this.site_.getCookieList();
78 } else {
79 this.entries_ = [];
80 }
81 },
82
83 /**
84 * Recursively look up a node path for a leaf node with a given id.
85 * @param {!settings.CookieTreeNode} node The node to start with.
86 * @param {string} currentPath The path constructed so far.
87 * @param {string} targetId The id of the target leaf node to look for.
88 * @return {string} The path of the node returned (or blank if not found).
89 * @private
90 */
91 nodePath_: function(node, currentPath, targetId) {
92 if (node.data.id == targetId)
93 return currentPath;
94
95 for (var i = 0; i < node.children_.length; ++i) {
96 var child = node.children_[i];
97 var path = this.nodePath_(
98 child, currentPath + ',' + child.data.id, targetId);
99 if (path.length > 0)
100 return path;
101 }
102 return '';
103 },
104
105 /**
106 * A handler for when the user opts to remove a single cookie.
107 * @param {!Event} item
108 * @return {string}
109 * @private
110 */
111 getEntryDescription_: function(item) {
112 // Frequently there are multiple cookies per site. To avoid showing a list
113 // of '1 cookie', '1 cookie', ... etc, it is better to show the title of the
114 // cookie to differentiate them.
115 if (item.data.type == 'cookie')
116 return item.title;
117 return getCookieDataCategoryText(item.data.type, item.data.totalUsage);
118 },
119
120 /**
121 * A handler for when the user opts to remove a single cookie.
122 * @param {!Event} event
123 * @private
124 */
125 onRemove_: function(event) {
126 this.browserProxy.removeCookie(this.nodePath_(
127 this.site_, this.site_.data.id, event.currentTarget.dataset.id));
128 },
129
130 /**
131 * A handler for when the user opts to remove all cookies.
132 */
133 removeAll: function() {
134 this.browserProxy.removeCookie(this.site_.data.id);
135 },
136 });
137
138 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698