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 * Returns whether the category default is set to enabled or not. |
| 13 * @param {number} category The category to check. |
| 14 * @return {boolean} True if the category default is set to enabled. |
| 15 * @private |
| 16 */ |
| 17 isPrefEnabled_: function(pref, category) { |
| 18 // FullScreen is Allow vs. Ask. |
| 19 if (category == settings.ContentSettingsTypes.FULLSCREEN) |
| 20 return pref.value != settings.DefaultValues.ALLOW; |
| 21 |
| 22 return pref.value != settings.DefaultValues.BLOCK; |
| 23 }, |
| 24 |
| 25 /** |
| 26 * A utility function to compute the icon to use for the category. |
| 27 * @param {number} category The category to show the icon for. |
| 28 * @return {string} The id of the icon for the given category. |
| 29 * @private |
| 30 */ |
| 31 computeIcon_: function(category) { |
| 32 switch (category) { |
| 33 case settings.ContentSettingsTypes.COOKIES: |
| 34 return ''; // Haven't found a good cookies icon under iron-icons. |
| 35 case settings.ContentSettingsTypes.JAVASCRIPT: |
| 36 return 'icons:input'; |
| 37 case settings.ContentSettingsTypes.FULLSCREEN: |
| 38 return 'icons:fullscreen'; |
| 39 case settings.ContentSettingsTypes.POPUPS: |
| 40 return 'icons:open-in-new'; |
| 41 case settings.ContentSettingsTypes.GEOLOCATION: |
| 42 return 'communication:location-on'; |
| 43 case settings.ContentSettingsTypes.NOTIFICATION: |
| 44 return 'social:notifications'; |
| 45 case settings.ContentSettingsTypes.CAMERA: |
| 46 return 'av:videocam'; |
| 47 case settings.ContentSettingsTypes.MIC: |
| 48 return 'av:mic'; |
| 49 default: |
| 50 assertNotReached(); |
| 51 return ''; |
| 52 } |
| 53 }, |
| 54 |
| 55 /** |
| 56 * A utility function to compute the title of the category. |
| 57 * @param {number} category The category to show the title for. |
| 58 * @return {string} The title for the given category. |
| 59 * @private |
| 60 */ |
| 61 computeTitle_: function(category) { |
| 62 switch (category) { |
| 63 case settings.ContentSettingsTypes.COOKIES: |
| 64 return loadTimeData.getString('siteSettingsCookies'); |
| 65 case settings.ContentSettingsTypes.JAVASCRIPT: |
| 66 return loadTimeData.getString('siteSettingsJavascript'); |
| 67 case settings.ContentSettingsTypes.FULLSCREEN: |
| 68 return loadTimeData.getString('siteSettingsFullscreen'); |
| 69 case settings.ContentSettingsTypes.POPUPS: |
| 70 return loadTimeData.getString('siteSettingsPopups'); |
| 71 case settings.ContentSettingsTypes.GEOLOCATION: |
| 72 return loadTimeData.getString('siteSettingsLocation'); |
| 73 case settings.ContentSettingsTypes.NOTIFICATION: |
| 74 return loadTimeData.getString('siteSettingsNotifications'); |
| 75 case settings.ContentSettingsTypes.CAMERA: |
| 76 return loadTimeData.getString('siteSettingsCamera'); |
| 77 case settings.ContentSettingsTypes.MIC: |
| 78 return loadTimeData.getString('siteSettingsMic'); |
| 79 default: |
| 80 assertNotReached(); |
| 81 return ''; |
| 82 } |
| 83 }, |
| 84 |
| 85 /** |
| 86 * A utility function to compute the name of the pref for the category. |
| 87 * @param {number} category The category to find the pref name for. |
| 88 * @return {string} The pref name for the given category. |
| 89 * @private |
| 90 */ |
| 91 computeTogglePrefName_: function(category) { |
| 92 return 'profile.default_content_setting_values.' + |
| 93 this.computeCategorySuffix_(category); |
| 94 }, |
| 95 |
| 96 /** |
| 97 * A utility function to compute the name of the pref for the exceptions |
| 98 * for a given category. |
| 99 * @param {number} category The category to find the pref name for. |
| 100 * @return {string} The pref name for the given category exceptions. |
| 101 * @private |
| 102 */ |
| 103 computeExceptionsPrefName_: function(category) { |
| 104 return 'profile.content_settings.exceptions.' + |
| 105 this.computeCategorySuffix_(category); |
| 106 }, |
| 107 |
| 108 /** |
| 109 * A utility function to convert the category enum into its text |
| 110 * representation, for use with prefs. |
| 111 * @param {number} category The category to find the pref name for. |
| 112 * @return {string} The pref name (suffix) for the given category. |
| 113 * @private |
| 114 */ |
| 115 computeCategorySuffix_: function(category) { |
| 116 switch (category) { |
| 117 case settings.ContentSettingsTypes.COOKIES: |
| 118 return 'cookies'; |
| 119 case settings.ContentSettingsTypes.JAVASCRIPT: |
| 120 return 'javascript'; |
| 121 case settings.ContentSettingsTypes.FULLSCREEN: |
| 122 return 'fullscreen'; |
| 123 case settings.ContentSettingsTypes.POPUPS: |
| 124 return 'popups'; |
| 125 case settings.ContentSettingsTypes.GEOLOCATION: |
| 126 return 'geolocation'; |
| 127 case settings.ContentSettingsTypes.NOTIFICATION: |
| 128 return 'notifications'; |
| 129 case settings.ContentSettingsTypes.CAMERA: |
| 130 return 'media_stream_camera'; |
| 131 case settings.ContentSettingsTypes.MIC: |
| 132 return 'media_stream_mic'; |
| 133 default: |
| 134 assertNotReached(); |
| 135 return ''; |
| 136 } |
| 137 }, |
| 138 |
| 139 /** |
| 140 * A utility function to compute the description for the category. |
| 141 * @param {number} category The category to show the description for. |
| 142 * @param {boolean} categoryEnabled The state of the global toggle. |
| 143 * @return {string} The category description. |
| 144 * @private |
| 145 */ |
| 146 computeDesc_: function(category, categoryEnabled) { |
| 147 switch (category) { |
| 148 case settings.ContentSettingsTypes.JAVASCRIPT: |
| 149 // "Allowed (recommended)" vs "Blocked". |
| 150 return categoryEnabled ? |
| 151 loadTimeData.getString('siteSettingsAllowedRecommended') : |
| 152 loadTimeData.getString('siteSettingsBlocked'); |
| 153 case settings.ContentSettingsTypes.POPUPS: |
| 154 // "Allowed" vs "Blocked (recommended)". |
| 155 return categoryEnabled ? |
| 156 loadTimeData.getString('siteSettingsAllowed') : |
| 157 loadTimeData.getString('siteSettingsBlockedRecommended'); |
| 158 case settings.ContentSettingsTypes.NOTIFICATION: |
| 159 // "Ask before sending (recommended)" vs "Blocked". |
| 160 return categoryEnabled ? |
| 161 loadTimeData.getString('siteSettingsAskBeforeSending') : |
| 162 loadTimeData.getString('siteSettingsBlocked'); |
| 163 case settings.ContentSettingsTypes.GEOLOCATION: |
| 164 case settings.ContentSettingsTypes.CAMERA: |
| 165 case settings.ContentSettingsTypes.MIC: |
| 166 // "Ask before accessing (recommended)" vs "Blocked". |
| 167 return categoryEnabled ? |
| 168 loadTimeData.getString('siteSettingsAskBeforeAccessing') : |
| 169 loadTimeData.getString('siteSettingsBlocked'); |
| 170 case settings.ContentSettingsTypes.FULLSCREEN: |
| 171 // "Allowed" vs. "Ask first (recommended)". |
| 172 return categoryEnabled ? |
| 173 loadTimeData.getString('siteSettingsAllowed') : |
| 174 loadTimeData.getString('siteSettingsAskFirstRecommended'); |
| 175 case settings.ContentSettingsTypes.COOKIES: |
| 176 // "Allow sites to save and read cookie data" vs "Blocked". |
| 177 return categoryEnabled ? |
| 178 loadTimeData.getString('siteSettingsCookiesAllowed') : |
| 179 loadTimeData.getString('siteSettingsBlocked'); |
| 180 default: |
| 181 assertNotReached(); |
| 182 return ''; |
| 183 } |
| 184 }, |
| 185 }; |
OLD | NEW |