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

Side by Side Diff: chrome/browser/resources/settings/site_settings/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: List population 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 * 'settings-site-list' is the widget that shows a list of Allowed and
michaelpg 2015/10/22 16:11:34 nit: "is the widget that shows" --> "shows"
Finnur 2015/10/26 14:38:04 Done.
8 * Blocked sites.
9 *
10 * Example:
11 * <settings-site-list prefs="{{prefs}}"
12 * category="[[category]]">
13 * </settings-site-list>
14 *
15 * @group Chrome Settings Elements
16 * @element settings-site-list
17 */
18 Polymer({
19 is: 'settings-site-list',
20 behaviors: [SiteSettingsBehavior],
21
22 properties: {
23 /**
24 * Preferences state.
25 */
26 prefs: {
27 type: Object,
28 notify: true,
29 },
30
31 /**
32 * The site that was selected by the user in the dropdown list.
33 */
34 selectedOrigin: {
35 type: String,
36 notify: true,
37 },
38
39 /**
40 * Array of sites to display in the widget.
michaelpg 2015/10/22 16:11:34 /** @type {Array<{url: String}>} */
Finnur 2015/10/26 14:38:04 Doesn't work. Not sure what the error means...
41 */
42 sites_: {
43 type: Array,
44 value: [],
michaelpg 2015/10/22 16:11:34 function() { return []; }, ^ so multiple <setting
Finnur 2015/10/26 14:38:04 Done.
45 },
46
47 /**
48 * The ID of the category this widget is displaying data for.
49 * See |categories| for possible values.
michaelpg 2015/10/22 16:11:33 update reference
Finnur 2015/10/26 14:38:04 Done.
50 */
51 category: {
michaelpg 2015/10/22 16:11:34 category: Number, &c for all following properties
Finnur 2015/10/26 14:38:04 Done.
52 type: Number,
53 },
54
55 /**
56 * The type of category this widget is displaying data for. Normally
57 * either ALLOW or BLOCK, representing which sites are allowed or blocked
58 * respectively.
59 */
60 categorySubtype: {
61 type: Number,
62 },
63
64 /**
65 * Represents the state of the main toggle shown for the category. For
66 * example, the Location category can be set to Block/Ask so false, in that
67 * case, represents Block and true represents Ask.
68 */
69 categoryEnabled: {
70 type: Boolean,
71 },
72
73 /**
74 * Whether to show the Allow action in the action menu.
75 */
76 showAllowAction_: {
77 type: Boolean,
78 },
79
80 /**
81 * Whether to show the Block action in the action menu.
82 */
83 showBlockAction_: {
84 type: Boolean,
85 },
86
87 /**
88 * All possible actions in the action menu.
89 */
90 actions_: {
91 type: Object,
michaelpg 2015/10/22 16:11:33 readOnly: true,
Finnur 2015/10/26 14:38:04 Done.
92 values: {
93 ALLOW: 'Allow',
94 BLOCK: 'Block',
95 RESET: 'Reset',
96 }
97 },
98
99 i18n_: {
100 readOnly: true,
101 type: Object,
102 value: function() {
103 return {
104 allowAction: loadTimeData.getString('siteSettingsActionAllow'),
michaelpg 2015/10/22 16:11:34 2-space indent
Finnur 2015/10/26 14:38:04 Done.
105 blockAction: loadTimeData.getString('siteSettingsActionBlock'),
106 resetAction: loadTimeData.getString('siteSettingsActionReset'),
107 };
108 },
109 },
110 },
111
112 ready: function() {
113 CrSettingsPrefs.initialized.then(function() {
114 this.categoryEnabled = this.isPrefEnabled_(this.category);
115
116 this.setupActionMenu_();
117 this.populateList_();
118 this.$.category.hidden =
119 !this.showSiteList_(this.sites_, this.categoryEnabled);
120 }.bind(this));
121 },
122
123 /**
124 * Handles the expanding and collapsing of the sites list.
125 * @private
126 */
127 onToggle_: function(e) {
128 if (this.$.category.opened)
129 this.$.icon.icon = 'icons:expand-less';
130 else
131 this.$.icon.icon = 'icons:expand-more';
132 },
133
134 /**
135 * Populate the sites list for display.
136 * @private
137 */
138 populateList_: function() {
139 var newList = [];
140 var pref = this.getPref_(this.computeExceptionsPrefName_(this.category));
141 var sites = pref['value'];
michaelpg 2015/10/22 16:11:33 nit: pref.value
Finnur 2015/10/26 14:38:04 Done.
142 for (var origin in sites) {
143 if (sites[origin]['setting'] == this.categorySubtype) {
144 var tokens = origin.split(',');
145 newList.push({ url: tokens[0] });
146 }
147 }
148
149 this.sites_ = newList;
150 },
151
152 /**
153 * Setup the values to use for the action menu.
154 * @private
155 */
156 setupActionMenu_: function() {
michaelpg 2015/10/22 16:11:34 ubernit: setUpActionMenu_
Finnur 2015/10/26 14:38:04 uberdone.
157 this.showAllowAction_ =
158 this.categorySubtype == settings.DefaultValues.BLOCK;
159 this.showBlockAction_ =
160 this.categorySubtype == settings.DefaultValues.ALLOW &&
161 this.category != settings.ContentSettingsTypes.FULLSCREEN;
162 },
163
164 /**
165 * A handler for selecting a site (by clicking on the origin).
166 * @private
167 */
168 onOriginClick_: function(event) {
michaelpg 2015/10/22 16:11:34 Tap
Finnur 2015/10/26 14:38:04 Done.
169 this.selectedOrigin = event.model.item.url;
170 },
171
172 /**
173 * A handler for activating one of the menu action items.
174 * @private
175 */
176 onActionMenuIronSelect_: function(event) {
177 // TODO(finnur): Implement.
178 },
179
180 /**
181 * Returns the appropriate header value for display.
182 * @param {array<string>} siteList The list of all sites to display for this
183 * category subtype.
184 * @param {boolean} toggleState The state of the global toggle for this
185 * category.
186 * @private
187 */
188 computeSiteListHeader_: function(siteList, toggleState) {
189 if (this.categorySubtype == settings.DefaultValues.ALLOW) {
190 return loadTimeData.getStringF(
191 'titleAndCount',
192 loadTimeData.getString(
193 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'),
194 siteList.length);
195 } else {
196 return loadTimeData.getStringF(
197 'titleAndCount',
198 loadTimeData.getString('siteSettingsBlock'),
199 siteList.length);
200 }
201 },
202
203 /**
204 * Returns true if this widget is showing the allow list.
205 * @private
206 */
207 isAllowList_: function() {
208 return this.categorySubtype == settings.DefaultValues.ALLOW;
209 },
210
211 /**
212 * Returns whether to show the site list.
213 * @param {array} siteList The list of all sites to display for this category
214 * subtype.
215 * @param {boolean} toggleState The state of the global toggle for this
216 * category.
217 * @private
218 */
219 showSiteList_: function(siteList, toggleState) {
220 if (this.isAllowList_()) {
221 return siteList.length > 0;
222 } else {
223 return siteList.length > 0 && toggleState;
224 }
225 },
226
227 /**
228 * Returns the icon to use for a given site.
229 * @param {string} url The url of the site to fetch the icon for.
230 * @private
231 */
232 computeSiteIcon_: function(url) {
233 // TODO(finnur): For now, we're returning a placeholder image for each site
234 // but the actual favicon for each site will need to be returned.
235 return 'communication:message';
236 },
237 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698