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

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 site that was selected by the user in the dropdown list.
33 */
34 selectedOrigin: {
michaelpg 2015/10/28 18:02:20 nit: selectedSite?
Finnur 2015/10/29 12:21:21 Technically, Origin is more accurate than Site, si
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 },
46
47 /**
48 * The ID of the category this widget is displaying data for.
49 * See site_settings/constants.js for possible values.
50 */
51 category: Number,
52
53 /**
54 * The type of category this widget is displaying data for. Normally
55 * either ALLOW or BLOCK, representing which sites are allowed or blocked
56 * respectively.
57 */
58 categorySubtype: Number,
59
60 /**
61 * Represents the state of the main toggle shown for the category. For
62 * example, the Location category can be set to Block/Ask so false, in that
63 * case, represents Block and true represents Ask.
64 */
65 categoryEnabled: Boolean,
66
67 /**
68 * Whether to show the Allow action in the action menu.
69 */
70 showAllowAction_: Boolean,
71
72 /**
73 * Whether to show the Block action in the action menu.
74 */
75 showBlockAction_: Boolean,
76
77 /**
78 * All possible actions in the action menu.
79 */
80 actions_: {
81 readOnly: true,
82 type: Object,
83 values: {
84 ALLOW: 'Allow',
85 BLOCK: 'Block',
86 RESET: 'Reset',
87 }
88 },
89
90 i18n_: {
91 readOnly: true,
92 type: Object,
93 value: function() {
94 return {
95 allowAction: loadTimeData.getString('siteSettingsActionAllow'),
96 blockAction: loadTimeData.getString('siteSettingsActionBlock'),
97 resetAction: loadTimeData.getString('siteSettingsActionReset'),
98 };
99 },
100 },
101 },
102
103 ready: function() {
104 CrSettingsPrefs.initialized.then(function() {
105 this.categoryEnabled = this.isPrefEnabled_(this.category);
106
107 this.setUpActionMenu_();
108 this.populateList_();
109 this.$.category.hidden =
110 !this.showSiteList_(this.sites_, this.categoryEnabled);
111 }.bind(this));
112 },
113
114 /**
115 * Handles the expanding and collapsing of the sites list.
116 * @private
117 */
118 onToggle_: function(e) {
119 if (this.$.category.opened)
120 this.$.icon.icon = 'icons:expand-less';
121 else
122 this.$.icon.icon = 'icons:expand-more';
123 },
124
125 /**
126 * Populate the sites list for display.
127 * @private
128 */
129 populateList_: function() {
130 var newList = [];
131 var pref = this.getPref_(this.computeExceptionsPrefName_(this.category));
132 var sites = pref.value;
133 for (var origin in sites) {
134 if (sites[origin]['setting'] == this.categorySubtype) {
135 var tokens = origin.split(',');
136 newList.push({ url: tokens[0] });
137 }
138 }
139
140 this.sites_ = newList;
141 },
142
143 /**
144 * Setup the values to use for the action menu.
145 * @private
146 */
147 setUpActionMenu_: function() {
148 this.showAllowAction_ =
149 this.categorySubtype == settings.DefaultValues.BLOCK;
150 this.showBlockAction_ =
151 this.categorySubtype == settings.DefaultValues.ALLOW &&
152 this.category != settings.ContentSettingsTypes.FULLSCREEN;
153 },
154
155 /**
156 * A handler for selecting a site (by clicking on the origin).
157 * @private
158 */
159 onOriginTap_: function(event) {
160 this.selectedOrigin = event.model.item.url;
161 },
162
163 /**
164 * A handler for activating one of the menu action items.
165 * @private
166 */
167 onActionMenuIronSelect_: function(event) {
168 // TODO(finnur): Implement.
169 },
170
171 /**
172 * Returns the appropriate header value for display.
173 * @param {array<string>} siteList The list of all sites to display for this
174 * category subtype.
175 * @param {boolean} toggleState The state of the global toggle for this
176 * category.
177 * @private
178 */
179 computeSiteListHeader_: function(siteList, toggleState) {
180 if (this.categorySubtype == settings.DefaultValues.ALLOW) {
181 return loadTimeData.getStringF(
182 'titleAndCount',
183 loadTimeData.getString(
184 toggleState ? 'siteSettingsAllow' : 'siteSettingsExceptions'),
185 siteList.length);
186 } else {
187 return loadTimeData.getStringF(
188 'titleAndCount',
189 loadTimeData.getString('siteSettingsBlock'),
190 siteList.length);
191 }
192 },
193
194 /**
195 * Returns true if this widget is showing the allow list.
196 * @private
197 */
198 isAllowList_: function() {
199 return this.categorySubtype == settings.DefaultValues.ALLOW;
200 },
201
202 /**
203 * Returns whether to show the site list.
204 * @param {array} siteList The list of all sites to display for this category
205 * subtype.
206 * @param {boolean} toggleState The state of the global toggle for this
207 * category.
208 * @private
209 */
210 showSiteList_: function(siteList, toggleState) {
211 if (this.isAllowList_()) {
212 return siteList.length > 0;
213 } else {
214 return siteList.length > 0 && toggleState;
michaelpg 2015/10/28 18:02:20 If this is a BLOCK list, and the category is set t
Finnur 2015/10/29 12:21:21 At first I thought you'd spotted a bug, but on clo
michaelpg 2015/10/29 19:41:58 If this is an ALLOW list, we always show it if it
Finnur 2015/10/30 12:13:46 Correct. That's how it works on Chrome for Android
215 }
216 },
217
218 /**
219 * Returns the icon to use for a given site.
220 * @param {string} url The url of the site to fetch the icon for.
221 * @private
222 */
223 computeSiteIcon_: function(url) {
224 // TODO(finnur): For now, we're returning a placeholder image for each site
225 // but the actual favicon for each site will need to be returned.
226 return 'communication:message';
227 },
228 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698