| 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 Behavior common to Site Settings classes. | 6 * @fileoverview Behavior common to Site Settings classes. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /** @polymerBehavior */ | 9 /** @polymerBehavior */ |
| 10 var SiteSettingsBehaviorImpl = { | 10 var SiteSettingsBehaviorImpl = { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 * @param {number} category The category ID to look up. | 64 * @param {number} category The category ID to look up. |
| 65 * @return {string} The category found or blank string if not found. | 65 * @return {string} The category found or blank string if not found. |
| 66 * @protected | 66 * @protected |
| 67 */ | 67 */ |
| 68 computeCategoryTextId: function(category) { | 68 computeCategoryTextId: function(category) { |
| 69 switch (category) { | 69 switch (category) { |
| 70 case settings.ContentSettingsTypes.CAMERA: | 70 case settings.ContentSettingsTypes.CAMERA: |
| 71 return 'camera'; | 71 return 'camera'; |
| 72 case settings.ContentSettingsTypes.COOKIES: | 72 case settings.ContentSettingsTypes.COOKIES: |
| 73 return 'cookies'; | 73 return 'cookies'; |
| 74 case settings.ContentSettingsTypes.FULLSCREEN: | |
| 75 return 'fullscreen'; | |
| 76 case settings.ContentSettingsTypes.GEOLOCATION: | 74 case settings.ContentSettingsTypes.GEOLOCATION: |
| 77 return 'location'; | 75 return 'location'; |
| 78 case settings.ContentSettingsTypes.IMAGES: | 76 case settings.ContentSettingsTypes.IMAGES: |
| 79 return 'images'; | 77 return 'images'; |
| 80 case settings.ContentSettingsTypes.JAVASCRIPT: | 78 case settings.ContentSettingsTypes.JAVASCRIPT: |
| 81 return 'javascript'; | 79 return 'javascript'; |
| 82 case settings.ContentSettingsTypes.MIC: | 80 case settings.ContentSettingsTypes.MIC: |
| 83 return 'microphone'; | 81 return 'microphone'; |
| 84 case settings.ContentSettingsTypes.NOTIFICATIONS: | 82 case settings.ContentSettingsTypes.NOTIFICATIONS: |
| 85 return 'notifications'; | 83 return 'notifications'; |
| 86 case settings.ContentSettingsTypes.POPUPS: | 84 case settings.ContentSettingsTypes.POPUPS: |
| 87 return 'popups'; | 85 return 'popups'; |
| 88 default: | 86 default: |
| 89 return ''; | 87 return ''; |
| 90 } | 88 } |
| 91 }, | 89 }, |
| 92 | 90 |
| 93 /** | 91 /** |
| 94 * A utility function to compute the icon to use for the category. | 92 * A utility function to compute the icon to use for the category, both for |
| 93 * the overall category as well as the individual permission in the details |
| 94 * for a site. |
| 95 * @param {number} category The category to show the icon for. | 95 * @param {number} category The category to show the icon for. |
| 96 * @return {string} The id of the icon for the given category. | 96 * @return {string} The id of the icon for the given category. |
| 97 * @protected | 97 * @protected |
| 98 */ | 98 */ |
| 99 computeIconForContentCategory: function(category) { | 99 computeIconForContentCategory: function(category) { |
| 100 switch (category) { | 100 switch (category) { |
| 101 case settings.ContentSettingsTypes.CAMERA: | 101 case settings.ContentSettingsTypes.CAMERA: |
| 102 return 'av:videocam'; | 102 return 'av:videocam'; |
| 103 case settings.ContentSettingsTypes.COOKIES: | 103 case settings.ContentSettingsTypes.COOKIES: |
| 104 return 'md-settings-icons:cookie'; | 104 return 'md-settings-icons:cookie'; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 116 return 'social:notifications'; | 116 return 'social:notifications'; |
| 117 case settings.ContentSettingsTypes.POPUPS: | 117 case settings.ContentSettingsTypes.POPUPS: |
| 118 return 'icons:open-in-new'; | 118 return 'icons:open-in-new'; |
| 119 default: | 119 default: |
| 120 assertNotReached('Invalid category: ' + category); | 120 assertNotReached('Invalid category: ' + category); |
| 121 return ''; | 121 return ''; |
| 122 } | 122 } |
| 123 }, | 123 }, |
| 124 | 124 |
| 125 /** | 125 /** |
| 126 * A utility function to compute the title of the category. | 126 * A utility function to compute the title of the category, both for |
| 127 * the overall category as well as the individual permission in the details |
| 128 * for a site. |
| 127 * @param {number} category The category to show the title for. | 129 * @param {number} category The category to show the title for. |
| 128 * @return {string} The title for the given category. | 130 * @return {string} The title for the given category. |
| 129 * @protected | 131 * @protected |
| 130 */ | 132 */ |
| 131 computeTitleForContentCategory: function(category) { | 133 computeTitleForContentCategory: function(category) { |
| 132 switch (category) { | 134 switch (category) { |
| 133 case settings.ContentSettingsTypes.CAMERA: | 135 case settings.ContentSettingsTypes.CAMERA: |
| 134 return loadTimeData.getString('siteSettingsCamera'); | 136 return loadTimeData.getString('siteSettingsCamera'); |
| 135 case settings.ContentSettingsTypes.COOKIES: | 137 case settings.ContentSettingsTypes.COOKIES: |
| 136 return loadTimeData.getString('siteSettingsCookies'); | 138 return loadTimeData.getString('siteSettingsCookies'); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 148 return loadTimeData.getString('siteSettingsNotifications'); | 150 return loadTimeData.getString('siteSettingsNotifications'); |
| 149 case settings.ContentSettingsTypes.POPUPS: | 151 case settings.ContentSettingsTypes.POPUPS: |
| 150 return loadTimeData.getString('siteSettingsPopups'); | 152 return loadTimeData.getString('siteSettingsPopups'); |
| 151 default: | 153 default: |
| 152 assertNotReached('Invalid category: ' + category); | 154 assertNotReached('Invalid category: ' + category); |
| 153 return ''; | 155 return ''; |
| 154 } | 156 } |
| 155 }, | 157 }, |
| 156 | 158 |
| 157 /** | 159 /** |
| 158 * A utility function to compute the name of the pref for the category. | |
| 159 * @param {number} category The category to find the pref name for. | |
| 160 * @return {string} The pref name for the given category. | |
| 161 * @protected | |
| 162 */ | |
| 163 computeCategoryPrefName: function(category) { | |
| 164 return 'profile.default_content_setting_values.' + | |
| 165 this.computeCategorySuffix(category); | |
| 166 }, | |
| 167 | |
| 168 /** | |
| 169 * A utility function to compute the name of the pref for the exceptions | |
| 170 * for a given category. | |
| 171 * @param {number} category The category to find the pref name for. | |
| 172 * @return {string} The pref name for the given category exceptions. | |
| 173 * @protected | |
| 174 */ | |
| 175 computeCategoryExceptionsPrefName: function(category) { | |
| 176 return 'profile.content_settings.exceptions.' + | |
| 177 this.computeCategorySuffix(category); | |
| 178 }, | |
| 179 | |
| 180 /** | |
| 181 * A utility function to convert the category enum into its text | |
| 182 * representation, for use with prefs. | |
| 183 * @param {number} category The category to find the pref name for. | |
| 184 * @return {string} The pref name (suffix) for the given category. | |
| 185 * @protected | |
| 186 */ | |
| 187 computeCategorySuffix: function(category) { | |
| 188 switch (category) { | |
| 189 case settings.ContentSettingsTypes.CAMERA: | |
| 190 return 'media_stream_camera'; | |
| 191 case settings.ContentSettingsTypes.COOKIES: | |
| 192 return 'cookies'; | |
| 193 case settings.ContentSettingsTypes.FULLSCREEN: | |
| 194 return 'fullscreen'; | |
| 195 case settings.ContentSettingsTypes.GEOLOCATION: | |
| 196 return 'geolocation'; | |
| 197 case settings.ContentSettingsTypes.IMAGES: | |
| 198 return 'images'; | |
| 199 case settings.ContentSettingsTypes.JAVASCRIPT: | |
| 200 return 'javascript'; | |
| 201 case settings.ContentSettingsTypes.MIC: | |
| 202 return 'media_stream_mic'; | |
| 203 case settings.ContentSettingsTypes.NOTIFICATIONS: | |
| 204 return 'notifications'; | |
| 205 case settings.ContentSettingsTypes.POPUPS: | |
| 206 return 'popups'; | |
| 207 default: | |
| 208 assertNotReached(); | |
| 209 return ''; | |
| 210 } | |
| 211 }, | |
| 212 | |
| 213 /** | |
| 214 * A utility function to compute the description for the category. | 160 * A utility function to compute the description for the category. |
| 215 * @param {number} category The category to show the description for. | 161 * @param {number} category The category to show the description for. |
| 216 * @param {boolean} categoryEnabled The state of the global toggle. | 162 * @param {boolean} categoryEnabled The state of the global toggle. |
| 217 * @param {boolean} showRecommendation Whether to show the '(recommended)' | 163 * @param {boolean} showRecommendation Whether to show the '(recommended)' |
| 218 * label prefix. | 164 * label prefix. |
| 219 * @return {string} The category description. | 165 * @return {string} The category description. |
| 220 * @protected | 166 * @protected |
| 221 */ | 167 */ |
| 222 computeCategoryDesc: function(category, categoryEnabled, showRecommendation) { | 168 computeCategoryDesc: function(category, categoryEnabled, showRecommendation) { |
| 223 switch (category) { | 169 switch (category) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 249 case settings.ContentSettingsTypes.CAMERA: | 195 case settings.ContentSettingsTypes.CAMERA: |
| 250 case settings.ContentSettingsTypes.MIC: | 196 case settings.ContentSettingsTypes.MIC: |
| 251 // "Ask before accessing (recommended)" vs "Blocked". | 197 // "Ask before accessing (recommended)" vs "Blocked". |
| 252 if (!categoryEnabled) { | 198 if (!categoryEnabled) { |
| 253 return loadTimeData.getString('siteSettingsBlocked'); | 199 return loadTimeData.getString('siteSettingsBlocked'); |
| 254 } | 200 } |
| 255 return showRecommendation ? | 201 return showRecommendation ? |
| 256 loadTimeData.getString( | 202 loadTimeData.getString( |
| 257 'siteSettingsAskBeforeAccessingRecommended') : | 203 'siteSettingsAskBeforeAccessingRecommended') : |
| 258 loadTimeData.getString('siteSettingsAskBeforeAccessing'); | 204 loadTimeData.getString('siteSettingsAskBeforeAccessing'); |
| 259 case settings.ContentSettingsTypes.FULLSCREEN: | |
| 260 // "Allowed" vs. "Ask first (recommended)". | |
| 261 if (categoryEnabled) { | |
| 262 return loadTimeData.getString('siteSettingsAllowed'); | |
| 263 } | |
| 264 return showRecommendation ? | |
| 265 loadTimeData.getString('siteSettingsAskFirstRecommended') : | |
| 266 loadTimeData.getString('siteSettingsAskFirst'); | |
| 267 case settings.ContentSettingsTypes.COOKIES: | 205 case settings.ContentSettingsTypes.COOKIES: |
| 268 // "Allow sites to save and read cookie data" vs "Blocked". | 206 // "Allow sites to save and read cookie data" vs "Blocked". |
| 269 if (!categoryEnabled) { | 207 if (!categoryEnabled) { |
| 270 return loadTimeData.getString('siteSettingsBlocked'); | 208 return loadTimeData.getString('siteSettingsBlocked'); |
| 271 } | 209 } |
| 272 return showRecommendation ? | 210 return showRecommendation ? |
| 273 loadTimeData.getString('siteSettingsCookiesAllowedRecommended') : | 211 loadTimeData.getString('siteSettingsCookiesAllowedRecommended') : |
| 274 loadTimeData.getString('siteSettingsCookiesAllowed'); | 212 loadTimeData.getString('siteSettingsCookiesAllowed'); |
| 275 case settings.ContentSettingsTypes.IMAGES: | 213 case settings.ContentSettingsTypes.IMAGES: |
| 276 if (!categoryEnabled) { | 214 if (!categoryEnabled) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 * @private | 258 * @private |
| 321 */ | 259 */ |
| 322 computeSiteIcon: function(site) { | 260 computeSiteIcon: function(site) { |
| 323 var url = this.ensureUrlHasScheme(site.originForDisplay); | 261 var url = this.ensureUrlHasScheme(site.originForDisplay); |
| 324 return 'background-image: ' + getFaviconImageSet(url); | 262 return 'background-image: ' + getFaviconImageSet(url); |
| 325 }, | 263 }, |
| 326 }; | 264 }; |
| 327 | 265 |
| 328 /** @polymerBehavior */ | 266 /** @polymerBehavior */ |
| 329 var SiteSettingsBehavior = [SiteSettingsBehaviorImpl]; | 267 var SiteSettingsBehavior = [SiteSettingsBehaviorImpl]; |
| OLD | NEW |