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({ |
(...skipping 13 matching lines...) Expand all Loading... |
24 subOptionLabel: String, | 24 subOptionLabel: String, |
25 | 25 |
26 /* The on/off text for |optionLabel_| below. */ | 26 /* The on/off text for |optionLabel_| below. */ |
27 toggleOffLabel: String, | 27 toggleOffLabel: String, |
28 toggleOnLabel: String, | 28 toggleOnLabel: String, |
29 | 29 |
30 /** @private {chrome.settingsPrivate.PrefObject} */ | 30 /** @private {chrome.settingsPrivate.PrefObject} */ |
31 controlParams_: { | 31 controlParams_: { |
32 type: Object, | 32 type: Object, |
33 value: function() { | 33 value: function() { |
34 return /** @type {chrome.settingsPrivate.PrefObject} */({}); | 34 return /** @type {chrome.settingsPrivate.PrefObject} */ ({}); |
35 }, | 35 }, |
36 }, | 36 }, |
37 | 37 |
38 /** | 38 /** |
39 * The label to be shown next to the toggle (above |optionDescription|). | 39 * The label to be shown next to the toggle (above |optionDescription|). |
40 * This will be either toggleOffLabel or toggleOnLabel. | 40 * This will be either toggleOffLabel or toggleOnLabel. |
41 * @private | 41 * @private |
42 */ | 42 */ |
43 optionLabel_: String, | 43 optionLabel_: String, |
44 | 44 |
45 /** @private {!DefaultContentSetting} */ | 45 /** @private {!DefaultContentSetting} */ |
46 priorDefaultContentSetting_: { | 46 priorDefaultContentSetting_: { |
47 type: Object, | 47 type: Object, |
48 value: function() { | 48 value: function() { |
49 return /** @type {DefaultContentSetting} */({}); | 49 return /** @type {DefaultContentSetting} */ ({}); |
50 }, | 50 }, |
51 }, | 51 }, |
52 | 52 |
53 /** | 53 /** |
54 * 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 |
55 * tri-state value. | 55 * tri-state value. |
56 * @private {chrome.settingsPrivate.PrefObject} | 56 * @private {chrome.settingsPrivate.PrefObject} |
57 */ | 57 */ |
58 subControlParams_: { | 58 subControlParams_: { |
59 type: Object, | 59 type: Object, |
60 value: function() { | 60 value: function() { |
61 return /** @type {chrome.settingsPrivate.PrefObject} */({}); | 61 return /** @type {chrome.settingsPrivate.PrefObject} */ ({}); |
62 }, | 62 }, |
63 }, | 63 }, |
64 }, | 64 }, |
65 | 65 |
66 observers: [ | 66 observers: [ |
67 'onCategoryChanged_(category)', | 67 'onCategoryChanged_(category)', |
68 'onChangePermissionControl_(category, controlParams_.value, ' + | 68 'onChangePermissionControl_(category, controlParams_.value, ' + |
69 'subControlParams_.value)', | 69 'subControlParams_.value)', |
70 ], | 70 ], |
71 | 71 |
72 /** @override */ | 72 /** @override */ |
73 ready: function() { | 73 ready: function() { |
74 this.addWebUIListener('contentSettingCategoryChanged', | 74 this.addWebUIListener( |
75 this.onCategoryChanged_.bind(this)); | 75 'contentSettingCategoryChanged', this.onCategoryChanged_.bind(this)); |
76 }, | 76 }, |
77 | 77 |
78 /** @return {boolean} */ | 78 /** @return {boolean} */ |
79 get categoryEnabled() { | 79 get categoryEnabled() { |
80 return !!assert(this.controlParams_).value; | 80 return !!assert(this.controlParams_).value; |
81 }, | 81 }, |
82 | 82 |
83 /** | 83 /** |
84 * A handler for changing the default permission value for a content type. | 84 * A handler for changing the default permission value for a content type. |
85 * @private | 85 * @private |
86 */ | 86 */ |
87 onChangePermissionControl_: function() { | 87 onChangePermissionControl_: function() { |
88 switch (this.category) { | 88 switch (this.category) { |
89 case settings.ContentSettingsTypes.ADS: | 89 case settings.ContentSettingsTypes.ADS: |
90 case settings.ContentSettingsTypes.BACKGROUND_SYNC: | 90 case settings.ContentSettingsTypes.BACKGROUND_SYNC: |
91 case settings.ContentSettingsTypes.IMAGES: | 91 case settings.ContentSettingsTypes.IMAGES: |
92 case settings.ContentSettingsTypes.JAVASCRIPT: | 92 case settings.ContentSettingsTypes.JAVASCRIPT: |
93 case settings.ContentSettingsTypes.POPUPS: | 93 case settings.ContentSettingsTypes.POPUPS: |
94 case settings.ContentSettingsTypes.PROTOCOL_HANDLERS: | 94 case settings.ContentSettingsTypes.PROTOCOL_HANDLERS: |
95 | 95 |
96 // "Allowed" vs "Blocked". | 96 // "Allowed" vs "Blocked". |
97 this.browserProxy.setDefaultValueForContentType( | 97 this.browserProxy.setDefaultValueForContentType( |
98 this.category, | 98 this.category, |
99 this.categoryEnabled ? | 99 this.categoryEnabled ? settings.PermissionValues.ALLOW : |
100 settings.PermissionValues.ALLOW : | 100 settings.PermissionValues.BLOCK); |
101 settings.PermissionValues.BLOCK); | |
102 break; | 101 break; |
103 case settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS: | 102 case settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS: |
104 case settings.ContentSettingsTypes.CAMERA: | 103 case settings.ContentSettingsTypes.CAMERA: |
105 case settings.ContentSettingsTypes.GEOLOCATION: | 104 case settings.ContentSettingsTypes.GEOLOCATION: |
106 case settings.ContentSettingsTypes.MIC: | 105 case settings.ContentSettingsTypes.MIC: |
107 case settings.ContentSettingsTypes.NOTIFICATIONS: | 106 case settings.ContentSettingsTypes.NOTIFICATIONS: |
108 case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS: | 107 case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS: |
109 case settings.ContentSettingsTypes.MIDI_DEVICES: | 108 case settings.ContentSettingsTypes.MIDI_DEVICES: |
110 // "Ask" vs "Blocked". | 109 // "Ask" vs "Blocked". |
111 this.browserProxy.setDefaultValueForContentType( | 110 this.browserProxy.setDefaultValueForContentType( |
112 this.category, | 111 this.category, |
113 this.categoryEnabled ? | 112 this.categoryEnabled ? settings.PermissionValues.ASK : |
114 settings.PermissionValues.ASK : | 113 settings.PermissionValues.BLOCK); |
115 settings.PermissionValues.BLOCK); | |
116 break; | 114 break; |
117 case settings.ContentSettingsTypes.COOKIES: | 115 case settings.ContentSettingsTypes.COOKIES: |
118 // This category is tri-state: "Allow", "Block", "Keep data until | 116 // This category is tri-state: "Allow", "Block", "Keep data until |
119 // browser quits". | 117 // browser quits". |
120 var value = settings.PermissionValues.BLOCK; | 118 var value = settings.PermissionValues.BLOCK; |
121 if (this.categoryEnabled) { | 119 if (this.categoryEnabled) { |
122 value = this.subControlParams_.value ? | 120 value = this.subControlParams_.value ? |
123 settings.PermissionValues.SESSION_ONLY : | 121 settings.PermissionValues.SESSION_ONLY : |
124 settings.PermissionValues.ALLOW; | 122 settings.PermissionValues.ALLOW; |
125 } | 123 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 basePref.enforcement = chrome.settingsPrivate.Enforcement.ENFORCED; | 160 basePref.enforcement = chrome.settingsPrivate.Enforcement.ENFORCED; |
163 basePref.controlledBy = | 161 basePref.controlledBy = |
164 update.source == ContentSettingProvider.EXTENSION ? | 162 update.source == ContentSettingProvider.EXTENSION ? |
165 chrome.settingsPrivate.ControlledBy.EXTENSION : | 163 chrome.settingsPrivate.ControlledBy.EXTENSION : |
166 chrome.settingsPrivate.ControlledBy.USER_POLICY; | 164 chrome.settingsPrivate.ControlledBy.USER_POLICY; |
167 } | 165 } |
168 | 166 |
169 var prefValue = this.computeIsSettingEnabled(update.setting); | 167 var prefValue = this.computeIsSettingEnabled(update.setting); |
170 // The controlParams_ must be replaced (rather than just value changes) so | 168 // The controlParams_ must be replaced (rather than just value changes) so |
171 // that observers will be notified of the change. | 169 // that observers will be notified of the change. |
172 this.controlParams_ = /** @type {chrome.settingsPrivate.PrefObject} */( | 170 this.controlParams_ = /** @type {chrome.settingsPrivate.PrefObject} */ ( |
173 Object.assign({'value': prefValue}, basePref)); | 171 Object.assign({'value': prefValue}, basePref)); |
174 | 172 |
175 var subPrefValue = false; | 173 var subPrefValue = false; |
176 if (this.category == settings.ContentSettingsTypes.PLUGINS || | 174 if (this.category == settings.ContentSettingsTypes.PLUGINS || |
177 this.category == settings.ContentSettingsTypes.COOKIES) { | 175 this.category == settings.ContentSettingsTypes.COOKIES) { |
178 if (this.category == settings.ContentSettingsTypes.PLUGINS && | 176 if (this.category == settings.ContentSettingsTypes.PLUGINS && |
179 update.setting == settings.PermissionValues.IMPORTANT_CONTENT) { | 177 update.setting == settings.PermissionValues.IMPORTANT_CONTENT) { |
180 subPrefValue = true; | 178 subPrefValue = true; |
181 } else if (this.category == settings.ContentSettingsTypes.COOKIES && | 179 } else if ( |
| 180 this.category == settings.ContentSettingsTypes.COOKIES && |
182 update.setting == settings.PermissionValues.SESSION_ONLY) { | 181 update.setting == settings.PermissionValues.SESSION_ONLY) { |
183 subPrefValue = true; | 182 subPrefValue = true; |
184 } | 183 } |
185 } | 184 } |
186 // The subControlParams_ must be replaced (rather than just value changes) | 185 // The subControlParams_ must be replaced (rather than just value changes) |
187 // so that observers will be notified of the change. | 186 // so that observers will be notified of the change. |
188 this.subControlParams_ = /** @type {chrome.settingsPrivate.PrefObject} */( | 187 this.subControlParams_ = /** @type {chrome.settingsPrivate.PrefObject} */ ( |
189 Object.assign({'value': subPrefValue}, basePref)); | 188 Object.assign({'value': subPrefValue}, basePref)); |
190 }, | 189 }, |
191 | 190 |
192 /** | 191 /** |
193 * Handles changes to the category pref and the |category| member variable. | 192 * Handles changes to the category pref and the |category| member variable. |
194 * @private | 193 * @private |
195 */ | 194 */ |
196 onCategoryChanged_: function() { | 195 onCategoryChanged_: function() { |
197 this.browserProxy | 196 this.browserProxy.getDefaultValueForContentType(this.category) |
198 .getDefaultValueForContentType( | 197 .then(function(defaultValue) { |
199 this.category).then(function(defaultValue) { | 198 this.updateControlParams_(defaultValue); |
200 this.updateControlParams_(defaultValue); | |
201 | 199 |
202 // Flash only shows ALLOW or BLOCK descriptions on the toggle. | 200 // Flash only shows ALLOW or BLOCK descriptions on the toggle. |
203 var setting = defaultValue.setting; | 201 var setting = defaultValue.setting; |
204 if (this.category == settings.ContentSettingsTypes.PLUGINS && | 202 if (this.category == settings.ContentSettingsTypes.PLUGINS && |
205 setting == settings.PermissionValues.IMPORTANT_CONTENT) { | 203 setting == settings.PermissionValues.IMPORTANT_CONTENT) { |
206 setting = settings.PermissionValues.ALLOW; | 204 setting = settings.PermissionValues.ALLOW; |
207 } else if ( | 205 } else if ( |
208 this.category == settings.ContentSettingsTypes.COOKIES && | 206 this.category == settings.ContentSettingsTypes.COOKIES && |
209 setting == settings.PermissionValues.SESSION_ONLY) { | 207 setting == settings.PermissionValues.SESSION_ONLY) { |
210 setting = settings.PermissionValues.ALLOW; | 208 setting = settings.PermissionValues.ALLOW; |
211 } | 209 } |
212 var categoryEnabled = setting != settings.PermissionValues.BLOCK; | 210 var categoryEnabled = setting != settings.PermissionValues.BLOCK; |
213 this.optionLabel_ = | 211 this.optionLabel_ = |
214 categoryEnabled ? this.toggleOnLabel : this.toggleOffLabel; | 212 categoryEnabled ? this.toggleOnLabel : this.toggleOffLabel; |
215 }.bind(this)); | 213 }.bind(this)); |
216 }, | 214 }, |
217 | 215 |
218 /** | 216 /** |
219 * @return {boolean} | 217 * @return {boolean} |
220 * @private | 218 * @private |
221 */ | 219 */ |
222 isToggleDisabled_: function() { | 220 isToggleDisabled_: function() { |
223 return this.category == settings.ContentSettingsTypes.POPUPS && | 221 return this.category == settings.ContentSettingsTypes.POPUPS && |
224 loadTimeData.getBoolean('isGuest'); | 222 loadTimeData.getBoolean('isGuest'); |
225 }, | 223 }, |
226 }); | 224 }); |
OLD | NEW |