OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * 'cr-settings-location-page' is the settings page for location access. | 7 * 'cr-settings-location-page' is the settings page for location access. |
8 * | 8 * |
9 * Example: | 9 * Example: |
10 * | 10 * |
11 * <cr-settings-location-page prefs="{{prefs}}"> | 11 * <cr-settings-location-page prefs="{{prefs}}"> |
12 * </cr-settings-location-page> | 12 * </cr-settings-location-page> |
13 * ... other pages ... | 13 * ... other pages ... |
14 * | 14 * |
15 * @group Chrome Settings Elements | 15 * @group Chrome Settings Elements |
16 * @element cr-settings-location-page | 16 * @element cr-settings-location-page |
17 */ | 17 */ |
18 Polymer({ | 18 Polymer({ |
19 /* TODO(finnur): Rename this to cr-settings-site-category. */ | |
19 is: 'cr-settings-location-page', | 20 is: 'cr-settings-location-page', |
20 | 21 |
21 properties: { | 22 properties: { |
22 /** | 23 /** |
23 * Preferences state. | 24 * Preferences state. |
24 */ | 25 */ |
25 prefs: { | 26 prefs: { |
26 type: Object, | 27 type: Object, |
27 notify: true, | 28 notify: true, |
28 }, | 29 }, |
(...skipping 23 matching lines...) Expand all Loading... | |
52 | 53 |
53 /** | 54 /** |
54 * Title for the page header and navigation menu. | 55 * Title for the page header and navigation menu. |
55 */ | 56 */ |
56 pageTitle: { | 57 pageTitle: { |
57 type: String, | 58 type: String, |
58 value: '', | 59 value: '', |
59 }, | 60 }, |
60 | 61 |
61 /** | 62 /** |
62 * Name of the 'iron-icon' to show. | 63 * What the main toggle for the category is set to (the global default when |
63 */ | 64 * no other policy is in effect). |
64 icon: { | 65 */ |
65 type: String, | 66 categoryEnabled: { |
66 value: 'communication:location-on', | 67 type: Boolean, |
68 }, | |
69 | |
70 /** | |
71 * The ID of the category this widget is displaying data for. | |
72 * See |categories| for possible values. | |
73 */ | |
74 category: { | |
75 type: Number, | |
76 }, | |
77 | |
78 /** | |
79 * An enum containing all the possible category numbers. Corresponds to | |
80 * the values found in the ContentSettingsType. | |
Dan Beam
2015/10/10 01:27:40
we shouldn't have to copy this or make new referen
Finnur
2015/10/15 15:46:32
Moved to constants.js.
| |
81 */ | |
82 categories: { | |
83 type: Object, | |
84 }, | |
85 | |
86 /** | |
87 * An enum containing the two possible values for the site list (allowed | |
88 * list and blocked list). | |
89 */ | |
90 defaultValues: { | |
67 readOnly: true, | 91 readOnly: true, |
68 }, | 92 type: Object, |
69 | 93 value: { |
70 /** | 94 ALLOW: 1, |
71 * Array of objects with url members. | 95 BLOCK: 2, |
72 */ | 96 ASK: 3, |
Dan Beam
2015/10/10 01:27:40
this should probably be in the same constants file
Finnur
2015/10/15 15:46:32
Ditto.
| |
73 block: { | 97 }, |
74 type: Array, | 98 }, |
75 }, | 99 }, |
76 | 100 |
77 /** | 101 observers: [ |
78 * Array of objects with url members. | 102 'categoryPrefChanged_(prefs.profile.' + |
79 */ | 103 'default_content_setting_values.cookies.value)', |
80 allow: { | 104 'categoryPrefChanged_(prefs.profile.' + |
81 type: Array, | 105 'default_content_setting_values.javascript.value)', |
82 }, | 106 'categoryPrefChanged_(prefs.profile.' + |
83 }, | 107 'default_content_setting_values.fullscreen.value)', |
108 'categoryPrefChanged_(prefs.profile.' + | |
109 'default_content_setting_values.popups.value)', | |
110 'categoryPrefChanged_(prefs.profile.' + | |
111 'default_content_setting_values.geolocation.value)', | |
112 'categoryPrefChanged_(prefs.profile.' + | |
113 'default_content_setting_values.notifications.value)', | |
114 'categoryPrefChanged_(prefs.profile.' + | |
115 'default_content_setting_values.media_stream_camera.value)', | |
116 'categoryPrefChanged_(prefs.profile.' + | |
117 'default_content_setting_values.media_stream_mic.value)', | |
Dan Beam
2015/10/10 01:27:40
'categoryPrefChanged_(prefs.profile.default_conten
Finnur
2015/10/15 15:46:32
Done.
| |
118 ], | |
84 | 119 |
85 ready: function() { | 120 ready: function() { |
86 this.block = []; | 121 CrSettingsPrefs.initialized.then(function() { |
87 this.allow = []; | 122 this.categoryEnabled = this.isPrefEnabled_(this.category); |
88 }, | 123 }.bind(this)); |
89 | 124 }, |
90 getTitleAndCount_: function(title, count) { | 125 |
91 return loadTimeData.getStringF( | 126 /** |
92 'titleAndCount', loadTimeData.getString(title), count); | 127 * Gets the pref at the given key. Asserts if the pref is not found. |
Dan Beam
2015/10/10 01:27:40
nit: Asserts -> Throws
Finnur
2015/10/15 15:46:32
Done.
| |
128 * @param {string} key | |
Dan Beam
2015/10/10 01:27:40
key -> prefPath
Finnur
2015/10/15 15:46:32
Done.
| |
129 * @return {!chrome.settingsPrivate.PrefObject} | |
130 */ | |
131 getPref_: function(key) { | |
132 var pref = /** @type {!chrome.settingsPrivate.PrefObject} */( | |
133 this.get(key, this.prefs)); | |
134 assert(typeof pref != 'undefined', 'Pref is missing: ' + key); | |
135 return pref; | |
136 }, | |
137 | |
138 /** | |
139 * Sets the value of the pref at the given key. Asserts if the pref is not | |
140 * found. | |
141 * @param {string} key | |
142 * @param {*} value | |
143 */ | |
144 setPrefValue_: function(key, value) { | |
145 this.getPref_(key); | |
Dan Beam
2015/10/10 01:27:40
why are you calling getPref_ here? just for the a
Finnur
2015/10/15 15:46:32
Hmm... redundant. Removed.
| |
146 this.set('prefs.' + key + '.value', value); | |
147 }, | |
148 | |
149 /** | |
150 * Handles when the global toggle changes. | |
151 * @private | |
152 */ | |
153 categoryPrefChanged_: function() { | |
154 this.categoryEnabled = this.isPrefEnabled_(this.category); | |
155 }, | |
156 | |
157 /** | |
158 * A handler for flipping the toggle value. | |
159 * @private | |
160 */ | |
161 handleToggleChange_: function(event) { | |
162 assert(CrSettingsPrefs.isInitialized); | |
163 | |
164 switch (this.category) { | |
165 case this.categories.COOKIES: | |
166 case this.categories.JAVASCRIPT: | |
167 case this.categories.POPUPS: | |
168 // "Allowed" vs "Blocked". | |
169 this.setPrefValue_(this.computePrefName_(this.category), | |
170 this.categoryEnabled ? | |
171 this.defaultValues.ALLOW : | |
172 this.defaultValues.BLOCK); | |
173 break; | |
174 case this.categories.NOTIFICATION: | |
175 case this.categories.GEOLOCATION: | |
176 case this.categories.CAMERA: | |
177 case this.categories.MIC: | |
178 // "Ask" vs "Blocked". | |
179 this.setPrefValue_(this.computePrefName_(this.category), | |
180 this.categoryEnabled ? | |
181 this.defaultValues.ASK : | |
182 this.defaultValues.BLOCK); | |
183 break; | |
184 case this.categories.FULLSCREEN: | |
185 // "Allowed" vs. "Ask first". | |
186 this.setPrefValue_(this.computePrefName_(this.category), | |
187 this.categoryEnabled ? | |
188 this.defaultValues.ALLOW : | |
189 this.defaultValues.ASK); | |
190 break; | |
191 default: | |
192 assertNotReached(); | |
193 } | |
194 }, | |
195 | |
196 /** | |
197 * Returns whether the category default is set to enabled or not. | |
198 * @param {number} category The category to show the icon for. | |
199 * @private | |
200 */ | |
201 isPrefEnabled_: function(category) { | |
202 var pref = this.getPref_(this.computePrefName_(this.category)); | |
203 | |
204 // FullScreen is Allow vs. Ask. | |
205 if (category == this.categories.FULLSCREEN) | |
206 return pref.value != this.defaultValues.ALLOW; | |
207 | |
208 return pref.value != this.defaultValues.BLOCK; | |
209 }, | |
210 | |
211 /** | |
212 * A utility function to compute the icon to use for the category. | |
213 * @param {number} category The category to show the icon for. | |
214 * @private | |
215 */ | |
216 computeIcon_: function(category) { | |
217 // Wonder if any of these enum values are directly accessible from .js? | |
218 switch (category) { | |
219 case this.categories.COOKIES: | |
220 return ''; // Haven't found a good cookies icon under iron-icons. | |
221 case this.categories.JAVASCRIPT: | |
222 return 'icons:input'; | |
223 case this.categories.FULLSCREEN: | |
224 return 'icons:fullscreen'; | |
225 case this.categories.POPUPS: | |
226 return 'icons:open-in-new'; | |
227 case this.categories.GEOLOCATION: | |
228 return 'communication:location-on'; | |
229 case this.categories.NOTIFICATION: | |
230 return 'social:notifications'; | |
231 case this.categories.CAMERA: | |
232 return 'av:videocam'; | |
233 case this.categories.MIC: | |
234 return 'av:mic'; | |
235 default: | |
236 assertNotReached(); | |
237 return ''; | |
238 } | |
239 }, | |
240 | |
241 /** | |
242 * A utility function to compute the title of the category. | |
243 * @param {number} category The category to show the title for. | |
244 * @private | |
245 */ | |
246 computeTitle_: function(category) { | |
247 switch (category) { | |
248 case this.categories.COOKIES: | |
249 return loadTimeData.getString('siteSettingsCookies'); | |
250 case this.categories.JAVASCRIPT: | |
251 return loadTimeData.getString('siteSettingsJavascript'); | |
252 case this.categories.FULLSCREEN: | |
253 return loadTimeData.getString('siteSettingsFullscreen'); | |
254 case this.categories.POPUPS: | |
255 return loadTimeData.getString('siteSettingsPopups'); | |
256 case this.categories.GEOLOCATION: | |
257 return loadTimeData.getString('siteSettingsLocation'); | |
258 case this.categories.NOTIFICATION: | |
259 return loadTimeData.getString('siteSettingsNotifications'); | |
260 case this.categories.CAMERA: | |
261 return loadTimeData.getString('siteSettingsCamera'); | |
262 case this.categories.MIC: | |
263 return loadTimeData.getString('siteSettingsMic'); | |
264 default: | |
265 assertNotReached(); | |
266 return ''; | |
267 } | |
268 }, | |
269 | |
270 /** | |
271 * A utility function to compute the name of the pref for the category. | |
272 * @param {number} category The category to find the pref name for. | |
273 * @private | |
274 */ | |
275 computePrefName_: function(category) { | |
276 switch (category) { | |
277 case this.categories.COOKIES: | |
278 return 'profile.default_content_setting_values.cookies'; | |
279 case this.categories.JAVASCRIPT: | |
280 return 'profile.default_content_setting_values.javascript'; | |
281 case this.categories.FULLSCREEN: | |
282 return 'profile.default_content_setting_values.fullscreen'; | |
283 case this.categories.POPUPS: | |
284 return 'profile.default_content_setting_values.popups'; | |
285 case this.categories.GEOLOCATION: | |
286 return 'profile.default_content_setting_values.geolocation'; | |
287 case this.categories.NOTIFICATION: | |
288 return 'profile.default_content_setting_values.notifications'; | |
289 case this.categories.CAMERA: | |
290 return 'profile.default_content_setting_values.media_stream_camera'; | |
291 case this.categories.MIC: | |
292 return 'profile.default_content_setting_values.media_stream_mic'; | |
293 default: | |
294 assertNotReached(); | |
295 return ''; | |
296 } | |
297 }, | |
298 | |
299 /** | |
300 * A utility function to compute the description for the category. | |
301 * @param {number} category The category to show the description for. | |
302 * @param {boolean} categoryEnabled The state of the global toggle. | |
303 * @private | |
304 */ | |
305 computeDesc_: function(category, categoryEnabled) { | |
306 switch (category) { | |
307 case this.categories.JAVASCRIPT: | |
308 // "Allowed (recommended)" vs "Blocked". | |
309 return categoryEnabled ? | |
310 loadTimeData.getString('siteSettingsAllowedRecommended') : | |
311 loadTimeData.getString('siteSettingsBlocked'); | |
312 case this.categories.POPUPS: | |
313 // "Allowed" vs "Blocked (recommended)". | |
314 return categoryEnabled ? | |
315 loadTimeData.getString('siteSettingsAllowed') : | |
316 loadTimeData.getString('siteSettingsBlockedRecommended'); | |
317 case this.categories.NOTIFICATION: | |
318 // "Ask before sending (recommended)" vs "Blocked". | |
319 return categoryEnabled ? | |
320 loadTimeData.getString('siteSettingsAskBeforeSending') : | |
321 loadTimeData.getString('siteSettingsBlocked'); | |
322 case this.categories.GEOLOCATION: | |
323 case this.categories.CAMERA: | |
324 case this.categories.MIC: | |
325 // "Ask before accessing (recommended)" vs "Blocked". | |
326 return categoryEnabled ? | |
327 loadTimeData.getString('siteSettingsAskBeforeAccessing') : | |
328 loadTimeData.getString('siteSettingsBlocked'); | |
329 case this.categories.FULLSCREEN: | |
330 // "Allowed" vs. "Ask first (recommended)". | |
331 return categoryEnabled ? | |
332 loadTimeData.getString('siteSettingsAllowed') : | |
333 loadTimeData.getString('siteSettingsAskFirstRecommended'); | |
334 case this.categories.COOKIES: | |
335 // "Allow sites to save and read cookie data" vs "Blocked". | |
336 return categoryEnabled ? | |
337 loadTimeData.getString('siteSettingsCookiesAllowed') : | |
338 loadTimeData.getString('siteSettingsBlocked'); | |
339 default: | |
340 assertNotReached(); | |
341 return ''; | |
342 } | |
93 }, | 343 }, |
94 }); | 344 }); |
OLD | NEW |