OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 * 'category-default-setting' is the polymer element for showing a certain | 7 * 'category-default-setting' is the polymer element for showing a certain |
8 * category under Site Settings. | 8 * category under Site Settings. |
9 */ | 9 */ |
10 Polymer({ | 10 Polymer({ |
11 is: 'category-default-setting', | 11 is: 'category-default-setting', |
12 | 12 |
13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], | 13 behaviors: [SiteSettingsBehavior, WebUIListenerBehavior], |
14 | 14 |
15 properties: { | 15 properties: { |
16 /* The second line, shown under the |optionLabel_| line. (optional) */ | |
17 optionDescription: String, | |
18 | |
19 /* The second line, shown under the |subOptionLabel| line. (optional) */ | |
20 subOptionDescription: String, | |
21 | |
22 /* The sub-option is a separate toggle. Setting this label will show the | |
23 * additional toggle. Shown above |subOptionDescription|. (optional) */ | |
24 subOptionLabel: String, | |
25 | |
26 /* The on/off text for |optionLabel_| below. */ | |
27 toggleOffLabel: String, | |
28 toggleOnLabel: String, | |
stevenjb
2017/04/01 00:15:37
This is fine, but I still personally think label,
dschuyler
2017/04/01 00:20:59
Seems reasonable. I'd like to rework this code to
| |
29 | |
16 /** @private {chrome.settingsPrivate.PrefObject} */ | 30 /** @private {chrome.settingsPrivate.PrefObject} */ |
17 controlParams_: { | 31 controlParams_: { |
18 type: Object, | 32 type: Object, |
19 value: function() { | 33 value: function() { |
20 return /** @type {chrome.settingsPrivate.PrefObject} */({}); | 34 return /** @type {chrome.settingsPrivate.PrefObject} */({}); |
21 }, | 35 }, |
22 }, | 36 }, |
23 | 37 |
38 /** | |
39 * The label to be shown next to the toggle (above |optionDescription|). | |
40 * This will be either toggleOffLabel or toggleOnLabel. | |
41 * @private | |
42 */ | |
43 optionLabel_: String, | |
44 | |
24 /** @private {!DefaultContentSetting} */ | 45 /** @private {!DefaultContentSetting} */ |
25 priorDefaultContentSetting_: { | 46 priorDefaultContentSetting_: { |
26 type: Object, | 47 type: Object, |
27 value: function() { | 48 value: function() { |
28 return /** @type {DefaultContentSetting} */({}); | 49 return /** @type {DefaultContentSetting} */({}); |
29 }, | 50 }, |
30 }, | 51 }, |
31 | 52 |
32 /** | 53 /** |
33 * The description to be shown next to the slider. | |
34 * @private | |
35 */ | |
36 sliderDescription_: String, | |
37 | |
38 /** | |
39 * Cookies and Flash settings have a sub-control that is used to mimic a | 54 * Cookies and Flash settings have a sub-control that is used to mimic a |
40 * tri-state value. | 55 * tri-state value. |
41 * @private {chrome.settingsPrivate.PrefObject} | 56 * @private {chrome.settingsPrivate.PrefObject} |
42 */ | 57 */ |
43 subControlParams_: { | 58 subControlParams_: { |
44 type: Object, | 59 type: Object, |
45 value: function() { | 60 value: function() { |
46 return /** @type {chrome.settingsPrivate.PrefObject} */({}); | 61 return /** @type {chrome.settingsPrivate.PrefObject} */({}); |
47 }, | 62 }, |
48 }, | 63 }, |
49 | |
50 /* Labels for the toggle on/off positions. */ | |
51 toggleOffLabel: String, | |
52 toggleOnLabel: String, | |
53 | |
54 subOptionLabel: String, | |
55 subOptionSecondary: { | |
56 type: String, | |
57 value: null, // Needs default value so binding fires upon initialization. | |
58 }, | |
59 }, | 64 }, |
60 | 65 |
61 observers: [ | 66 observers: [ |
62 'onCategoryChanged_(category)', | 67 'onCategoryChanged_(category)', |
63 'onChangePermissionControl_(category, controlParams_.value, ' + | 68 'onChangePermissionControl_(category, controlParams_.value, ' + |
64 'subControlParams_.value)', | 69 'subControlParams_.value)', |
65 ], | 70 ], |
66 | 71 |
67 ready: function() { | 72 ready: function() { |
68 this.addWebUIListener('contentSettingCategoryChanged', | 73 this.addWebUIListener('contentSettingCategoryChanged', |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 /** | 191 /** |
187 * Handles changes to the category pref and the |category| member variable. | 192 * Handles changes to the category pref and the |category| member variable. |
188 * @private | 193 * @private |
189 */ | 194 */ |
190 onCategoryChanged_: function() { | 195 onCategoryChanged_: function() { |
191 this.browserProxy | 196 this.browserProxy |
192 .getDefaultValueForContentType( | 197 .getDefaultValueForContentType( |
193 this.category).then(function(defaultValue) { | 198 this.category).then(function(defaultValue) { |
194 this.updateControlParams_(defaultValue); | 199 this.updateControlParams_(defaultValue); |
195 | 200 |
196 // Flash only shows ALLOW or BLOCK descriptions on the slider. | 201 // Flash only shows ALLOW or BLOCK descriptions on the toggle. |
197 var setting = defaultValue.setting; | 202 var setting = defaultValue.setting; |
198 if (this.category == settings.ContentSettingsTypes.PLUGINS && | 203 if (this.category == settings.ContentSettingsTypes.PLUGINS && |
199 setting == settings.PermissionValues.IMPORTANT_CONTENT) { | 204 setting == settings.PermissionValues.IMPORTANT_CONTENT) { |
200 setting = settings.PermissionValues.ALLOW; | 205 setting = settings.PermissionValues.ALLOW; |
201 } else if ( | 206 } else if ( |
202 this.category == settings.ContentSettingsTypes.COOKIES && | 207 this.category == settings.ContentSettingsTypes.COOKIES && |
203 setting == settings.PermissionValues.SESSION_ONLY) { | 208 setting == settings.PermissionValues.SESSION_ONLY) { |
204 setting = settings.PermissionValues.ALLOW; | 209 setting = settings.PermissionValues.ALLOW; |
205 } | 210 } |
206 var categoryEnabled = setting != settings.PermissionValues.BLOCK; | 211 var categoryEnabled = setting != settings.PermissionValues.BLOCK; |
207 this.sliderDescription_ = | 212 this.optionLabel_ = |
208 categoryEnabled ? this.toggleOnLabel : this.toggleOffLabel; | 213 categoryEnabled ? this.toggleOnLabel : this.toggleOffLabel; |
209 }.bind(this)); | 214 }.bind(this)); |
210 }, | 215 }, |
211 | 216 |
212 /** | 217 /** |
213 * @return {boolean} | 218 * @return {boolean} |
214 * @private | 219 * @private |
215 */ | 220 */ |
216 isToggleDisabled_: function() { | 221 isToggleDisabled_: function() { |
217 return this.category == settings.ContentSettingsTypes.POPUPS && | 222 return this.category == settings.ContentSettingsTypes.POPUPS && |
218 loadTimeData.getBoolean('isGuest'); | 223 loadTimeData.getBoolean('isGuest'); |
219 }, | 224 }, |
220 | |
221 /** | |
222 * Returns classname to indicate secondary label exists. | |
223 * @param {boolean} subOptionLabel | |
224 * @return {string} | |
225 * @private | |
226 */ | |
227 subOptionClass_: function(subOptionLabel) { | |
228 return subOptionLabel ? 'two-line' : ''; | |
229 } | |
230 }); | 225 }); |
OLD | NEW |