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