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

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

Powered by Google App Engine
This is Rietveld 408576698