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

Side by Side Diff: chrome/browser/resources/settings/location_page/site_list.js

Issue 1372053002: Flesh out the location-page class to make it more general. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split list into two Created 5 years, 2 months 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
7 * 'cr-settings-site-list' is the widget that shows Allowed and Blocked sites.
8 *
9 * Example:
10 *
11 * <cr-settings-site-list
12 * category="[[category]]"
13 * categories="[[categories]]"
14 * category-subtype="[[allowOrBlock.BLOCK]]"
15 * category-subtypes="[[allowOrBlock]]>
16 * </cr-settings-site-list>
17 * ... other pages ...
18 *
19 * @group Chrome Settings Elements
20 * @element cr-settings-site-list
21 */
22 Polymer({
23 is: 'cr-settings-site-list',
24
25 properties: {
26 /**
27 * Array of sites to display in the widget.
28 */
29 siteList: {
30 type: Array,
31 },
32
33 /**
34 * The ID of the category this widget is displaying data for.
35 * See |categories| for possible values.
36 */
37 category: {
38 type: Number,
39 },
40
41 /**
42 * An enum containing all the possible category numbers. Corresponds to
43 * the values found in the ContentSettingsType.
44 */
45 categories: {
46 type: Object,
47 },
48
49 /**
50 * The type of category this widget is displaying data for. Normally
51 * either ALLOW or BLOCK, representing which sites are allowed or blocked
52 * respectively.
53 */
54 categorySubtype: {
55 type: Number,
56 },
57
58 /**
59 * An enum containing the list of all possible category subtypes.
60 */
61 categorySubtypes: {
62 type: Object,
63 },
64
65 /**
66 * What the main toggle for the category is set to (the global default if
67 * no other policy is in effect).
68 */
69 toggleState: {
Dan Beam 2015/10/05 16:52:57 categoryEnabled or typeEnabled
Finnur 2015/10/06 16:31:09 Done.
70 type: Boolean,
71 value: false,
72 },
73
74 /**
75 * The site that was selected by the user in the dropdown list.
76 */
77 siteSelected: {
Dan Beam 2015/10/05 16:52:57 selectedSite or selectedOrigin
Finnur 2015/10/06 16:31:09 Done.
78 type: String,
79 notify: true,
80 },
81
82 /**
83 * Whether to show the Allow action in the action menu.
84 */
85 showAllowAction: {
86 type: Boolean,
87 },
88
89 /**
90 * Whether to show the Block action in the action menu.
91 */
92 showBlockAction: {
93 type: Boolean,
94 },
95
96 /**
97 * The label to show for the Allow action menu item.
98 */
99 allowActionLabel: {
100 type: String,
101 },
102
103 /**
104 * The label to show for the Block action menu item.
105 */
106 blockActionLabel: {
107 type: String,
108 },
109
110 /**
111 * The label to show for the Reset action menu item.
112 */
113 resetActionLabel: {
114 type: String,
115 },
Dan Beam 2015/10/05 16:52:57 all of these should be private where possible (i.e
Finnur 2015/10/06 16:31:09 Done.
Jeremy Klein 2015/10/06 17:07:21 I believe this was fixed in mid-August here: http
Dan Beam 2015/10/07 15:21:16 our version of the compiler is older than that
116 },
117
118 ready: function() {
119 // By default we hide and only appear if there's something to show.
120 this.hidden = true;
Dan Beam 2015/10/05 16:52:57 please do this in css instead
Finnur 2015/10/06 16:31:09 Do you mean something like this? (first answer) ht
121
122 this.setupActionMenu_();
123 chrome.send('fetchContentSettingsData',
124 [this.category, this.categorySubtype == this.categorySubtypes.ALLOW]);
Dan Beam 2015/10/05 16:52:57 why can't we get these prefs from |this.prefs| and
Finnur 2015/10/06 16:31:09 I've converted the other file to use prefs, I don'
125 },
126
127 attached: function() {
128 var self = this;
129 if (this.categorySubtype == this.categorySubtypes.ALLOW) {
130 cr.define('Settings', function() {
131 return {
132 receiveAllowedData: function() {
133 return self.receiveSiteList_.apply(self, arguments);
134 },
135 };
136 });
137 } else {
138 cr.define('Settings', function() {
139 return {
140 receiveBlockedData: function() {
141 return self.receiveSiteList_.apply(self, arguments);
142 },
143 };
144 });
145 }
146 },
147
148 /**
149 * Setup the values to use for the action menu.
150 * @private
151 */
152 setupActionMenu_: function() {
153 this.showAllowAction = this.categorySubtype == this.categorySubtypes.BLOCK;
154 this.showBlockAction =
155 this.categorySubtype == this.categorySubtypes.ALLOW &&
156 this.category != this.categories.FULLSCREEN;
157
158 this.allowActionLabel = 'Allow'; // TODO(finnur): i18n.
159 this.blockActionLabel = 'Block';
160 this.resetActionLabel = 'Reset to Ask';
161 },
162
163 /**
164 * Receive the site list and the toggle state (from the native level).
165 * @param {array} siteList The list of all sites to display for this category
166 * subtype.
167 * @param {boolean} toggleState The state of the global toggle for this
168 * category.
169 * @private
170 */
171 receiveSiteList_: function(siteList, toggleState) {
172 this.siteList = siteList;
173 this.toggleState = toggleState;
174 this.hidden = !this.showSiteList_(siteList, toggleState);
175 },
176
177 /**
178 * A handler for selecting a site (by double clicking on the name).
Dan Beam 2015/10/05 16:52:57 why are we handling double click? do the mocks sa
Finnur 2015/10/06 16:31:09 Hmm... I guess not. Click is more appropriate, I p
179 * @private
180 */
181 handleDblClick_: function(event) {
182 this.siteSelected = event.model.item.url;
183 },
184
185 /**
186 * A handler for activating one of the menu action items.
187 * @private
188 */
189 selectAction_: function(event) {
190 console.log('site: ' + event.model.item.url);
191 console.log('action ' + event.target.selectedItems[0].textContent);
Dan Beam 2015/10/05 16:52:58 debugging code
Finnur 2015/10/06 16:31:09 Done.
192 },
193
194 /**
195 * Returns the appropriate header value for display.
196 * @param {array} siteList The list of all sites to display for this category
197 * subtype.
198 * @param {boolean} toggleState The state of the global toggle for this
199 * category.
200 * @private
201 */
202 computeSiteListHeader_: function(siteList, toggleState) {
203 if (this.categorySubtype == this.categorySubtypes.ALLOW) {
204 return loadTimeData.getStringF(
205 'titleAndCount',
206 loadTimeData.getString(
207 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'),
208 siteList.length);
209 } else {
210 return loadTimeData.getStringF(
211 'titleAndCount',
212 loadTimeData.getString('siteSettingsBlock'),
213 siteList.length);
214 }
215 },
216
217 /**
218 * Returns whether to show the site list.
219 * @param {array} siteList The list of all sites to display for this category
220 * subtype.
221 * @param {boolean} toggleState The state of the global toggle for this
222 * category.
223 * @private
224 */
225 showSiteList_: function(siteList, toggleState) {
226 if (this.categorySubtype == this.categorySubtypes.ALLOW) {
Dan Beam 2015/10/05 16:52:57 pull this.categorySubtype == this.categorySubtypes
Finnur 2015/10/06 16:31:09 Done.
227 return siteList.length > 0;
228 } else {
229 return siteList.length > 0 && toggleState;
230 }
Dan Beam 2015/10/05 16:52:57 no curlies
Finnur 2015/10/06 16:31:09 Done.
231 },
232
233 /**
234 * Returns the icon to use for a given site.
235 * @param {string} url The url of the site to fetch the icon for.
236 * @private
237 */
238 computeSiteIcon_: function(url) {
239 return 'communication:message'; // TODO(finnur): Implement actual favicons.
240 },
241
242 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698