Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 Behavior common to Site Settings classes. | |
| 7 */ | |
| 8 | |
| 9 /** @polymerBehavior */ | |
| 10 var SiteSettingsBehavior = { | |
| 11 /** | |
| 12 * Gets the pref at the given prefPath. Throws if the pref is not found. | |
| 13 * @param {string} prefPath | |
| 14 * @return {!chrome.settingsPrivate.PrefObject} | |
| 15 * @private | |
| 16 */ | |
| 17 getPref_: function(prefPath) { | |
|
michaelpg
2015/10/22 16:11:34
extract into separate behavior for this and settin
Finnur
2015/10/26 14:38:05
It is a bit unfortunate that behaviors can't inher
michaelpg
2015/10/26 22:15:22
You could override getPref_. Each behavior overrid
Finnur
2015/10/27 11:30:48
I suspect you are suggestion a solution to a diffe
| |
| 18 var pref = /** @type {!chrome.settingsPrivate.PrefObject} */( | |
| 19 this.get(prefPath, this.prefs)); | |
| 20 assert(typeof pref != 'undefined', 'Pref is missing: ' + prefPath); | |
| 21 return pref; | |
| 22 }, | |
| 23 | |
| 24 /** | |
| 25 * Sets the value of the pref at the given prefPath. Throws if the pref is not | |
| 26 * found. | |
| 27 * @param {string} prefPath | |
| 28 * @param {*} value | |
| 29 * @private | |
| 30 */ | |
| 31 setPrefValue_: function(prefPath, value) { | |
|
michaelpg
2015/10/22 16:11:34
same
Finnur
2015/10/26 14:38:05
Done.
| |
| 32 this.set('prefs.' + prefPath + '.value', value); | |
|
michaelpg
2015/10/22 16:11:34
contradictory to the comment, this doesn't throw i
Finnur
2015/10/26 14:38:05
Done.
| |
| 33 }, | |
| 34 | |
| 35 /** | |
| 36 * Returns whether the category default is set to enabled or not. | |
| 37 * @param {number} category The category to check. | |
| 38 * @return {boolean} True if the category default is set to enabled. | |
| 39 * @private | |
| 40 */ | |
| 41 isPrefEnabled_: function(category) { | |
| 42 var pref = this.getPref_(this.computeTogglePrefName_(this.category)); | |
| 43 | |
| 44 // FullScreen is Allow vs. Ask. | |
| 45 if (category == settings.ContentSettingsTypes.FULLSCREEN) | |
| 46 return pref.value != settings.DefaultValues.ALLOW; | |
| 47 | |
| 48 return pref.value != settings.DefaultValues.BLOCK; | |
| 49 }, | |
| 50 | |
| 51 /** | |
| 52 * A utility function to compute the icon to use for the category. | |
| 53 * @param {number} category The category to show the icon for. | |
| 54 * @return {string} The id of the icon for the given category. | |
| 55 * @private | |
| 56 */ | |
| 57 computeIcon_: function(category) { | |
| 58 // Wonder if any of these enum values are directly accessible from .js? | |
|
michaelpg
2015/10/22 16:11:34
make a TODO or remove comment (i'm not sure what t
Finnur
2015/10/26 14:38:05
Removed (the todo is kind of covered already in co
| |
| 59 switch (category) { | |
| 60 case settings.ContentSettingsTypes.COOKIES: | |
| 61 return ''; // Haven't found a good cookies icon under iron-icons. | |
| 62 case settings.ContentSettingsTypes.JAVASCRIPT: | |
| 63 return 'icons:input'; | |
| 64 case settings.ContentSettingsTypes.FULLSCREEN: | |
| 65 return 'icons:fullscreen'; | |
| 66 case settings.ContentSettingsTypes.POPUPS: | |
| 67 return 'icons:open-in-new'; | |
| 68 case settings.ContentSettingsTypes.GEOLOCATION: | |
| 69 return 'communication:location-on'; | |
| 70 case settings.ContentSettingsTypes.NOTIFICATION: | |
| 71 return 'social:notifications'; | |
| 72 case settings.ContentSettingsTypes.CAMERA: | |
| 73 return 'av:videocam'; | |
| 74 case settings.ContentSettingsTypes.MIC: | |
| 75 return 'av:mic'; | |
| 76 default: | |
| 77 assertNotReached(); | |
| 78 return ''; | |
| 79 } | |
| 80 }, | |
| 81 | |
| 82 /** | |
| 83 * A utility function to compute the title of the category. | |
| 84 * @param {number} category The category to show the title for. | |
| 85 * @return {string} The title for the given category. | |
| 86 * @private | |
| 87 */ | |
| 88 computeTitle_: function(category) { | |
| 89 switch (category) { | |
| 90 case settings.ContentSettingsTypes.COOKIES: | |
| 91 return loadTimeData.getString('siteSettingsCookies'); | |
| 92 case settings.ContentSettingsTypes.JAVASCRIPT: | |
| 93 return loadTimeData.getString('siteSettingsJavascript'); | |
| 94 case settings.ContentSettingsTypes.FULLSCREEN: | |
| 95 return loadTimeData.getString('siteSettingsFullscreen'); | |
| 96 case settings.ContentSettingsTypes.POPUPS: | |
| 97 return loadTimeData.getString('siteSettingsPopups'); | |
| 98 case settings.ContentSettingsTypes.GEOLOCATION: | |
| 99 return loadTimeData.getString('siteSettingsLocation'); | |
| 100 case settings.ContentSettingsTypes.NOTIFICATION: | |
| 101 return loadTimeData.getString('siteSettingsNotifications'); | |
| 102 case settings.ContentSettingsTypes.CAMERA: | |
| 103 return loadTimeData.getString('siteSettingsCamera'); | |
| 104 case settings.ContentSettingsTypes.MIC: | |
| 105 return loadTimeData.getString('siteSettingsMic'); | |
| 106 default: | |
| 107 assertNotReached(); | |
| 108 return ''; | |
| 109 } | |
| 110 }, | |
| 111 | |
| 112 /** | |
| 113 * A utility function to compute the name of the pref for the category. | |
| 114 * @param {number} category The category to find the pref name for. | |
| 115 * @return {string} The pref name for the given category. | |
| 116 * @private | |
| 117 */ | |
| 118 computeTogglePrefName_: function(category) { | |
| 119 return 'profile.default_content_setting_values.' + | |
| 120 this.computeCategorySuffix_(category); | |
| 121 }, | |
| 122 | |
| 123 /** | |
| 124 * A utility function to compute the name of the pref for the exceptions | |
| 125 * for a given category. | |
| 126 * @param {number} category The category to find the pref name for. | |
| 127 * @return {string} The pref name for the given category exceptions. | |
| 128 * @private | |
| 129 */ | |
| 130 computeExceptionsPrefName_: function(category) { | |
| 131 return 'profile.content_settings.exceptions.' + | |
| 132 this.computeCategorySuffix_(category); | |
| 133 }, | |
| 134 | |
| 135 /** | |
| 136 * A utility function to convert the category enum into its text | |
| 137 * representation, for use with prefs. | |
| 138 * @param {number} category The category to find the pref name for. | |
| 139 * @return {string} The pref name (suffix) for the given category. | |
| 140 * @private | |
| 141 */ | |
| 142 computeCategorySuffix_: function(category) { | |
| 143 switch (category) { | |
| 144 case settings.ContentSettingsTypes.COOKIES: | |
| 145 return 'cookies'; | |
| 146 case settings.ContentSettingsTypes.JAVASCRIPT: | |
| 147 return 'javascript'; | |
| 148 case settings.ContentSettingsTypes.FULLSCREEN: | |
| 149 return 'fullscreen'; | |
| 150 case settings.ContentSettingsTypes.POPUPS: | |
| 151 return 'popups'; | |
| 152 case settings.ContentSettingsTypes.GEOLOCATION: | |
| 153 return 'geolocation'; | |
| 154 case settings.ContentSettingsTypes.NOTIFICATION: | |
| 155 return 'notifications'; | |
| 156 case settings.ContentSettingsTypes.CAMERA: | |
| 157 return 'media_stream_camera'; | |
| 158 case settings.ContentSettingsTypes.MIC: | |
| 159 return 'media_stream_mic'; | |
| 160 default: | |
| 161 assertNotReached(); | |
| 162 return ''; | |
| 163 } | |
| 164 }, | |
| 165 | |
| 166 /** | |
| 167 * A utility function to compute the description for the category. | |
| 168 * @param {number} category The category to show the description for. | |
| 169 * @param {boolean} categoryEnabled The state of the global toggle. | |
| 170 * @return {string} The category description. | |
| 171 * @private | |
| 172 */ | |
| 173 computeDesc_: function(category, categoryEnabled) { | |
| 174 switch (category) { | |
| 175 case settings.ContentSettingsTypes.JAVASCRIPT: | |
| 176 // "Allowed (recommended)" vs "Blocked". | |
| 177 return categoryEnabled ? | |
| 178 loadTimeData.getString('siteSettingsAllowedRecommended') : | |
| 179 loadTimeData.getString('siteSettingsBlocked'); | |
| 180 case settings.ContentSettingsTypes.POPUPS: | |
| 181 // "Allowed" vs "Blocked (recommended)". | |
| 182 return categoryEnabled ? | |
| 183 loadTimeData.getString('siteSettingsAllowed') : | |
| 184 loadTimeData.getString('siteSettingsBlockedRecommended'); | |
| 185 case settings.ContentSettingsTypes.NOTIFICATION: | |
| 186 // "Ask before sending (recommended)" vs "Blocked". | |
| 187 return categoryEnabled ? | |
| 188 loadTimeData.getString('siteSettingsAskBeforeSending') : | |
| 189 loadTimeData.getString('siteSettingsBlocked'); | |
| 190 case settings.ContentSettingsTypes.GEOLOCATION: | |
| 191 case settings.ContentSettingsTypes.CAMERA: | |
| 192 case settings.ContentSettingsTypes.MIC: | |
| 193 // "Ask before accessing (recommended)" vs "Blocked". | |
| 194 return categoryEnabled ? | |
| 195 loadTimeData.getString('siteSettingsAskBeforeAccessing') : | |
| 196 loadTimeData.getString('siteSettingsBlocked'); | |
| 197 case settings.ContentSettingsTypes.FULLSCREEN: | |
| 198 // "Allowed" vs. "Ask first (recommended)". | |
| 199 return categoryEnabled ? | |
| 200 loadTimeData.getString('siteSettingsAllowed') : | |
| 201 loadTimeData.getString('siteSettingsAskFirstRecommended'); | |
| 202 case settings.ContentSettingsTypes.COOKIES: | |
| 203 // "Allow sites to save and read cookie data" vs "Blocked". | |
| 204 return categoryEnabled ? | |
| 205 loadTimeData.getString('siteSettingsCookiesAllowed') : | |
| 206 loadTimeData.getString('siteSettingsBlocked'); | |
| 207 default: | |
| 208 assertNotReached(); | |
| 209 return ''; | |
| 210 } | |
| 211 }, | |
| 212 }; | |
| OLD | NEW |