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) { |
| 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) { |
| 32 this.set('prefs.' + prefPath + '.value', value); |
| 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.computePrefName_(this.category)); |
| 43 |
| 44 // FullScreen is Allow vs. Ask. |
| 45 if (category == siteSettings.ContentSettingsTypes.FULLSCREEN) |
| 46 return pref.value != siteSettings.DefaultValues.ALLOW; |
| 47 |
| 48 return pref.value != siteSettings.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? |
| 59 switch (category) { |
| 60 case siteSettings.ContentSettingsTypes.COOKIES: |
| 61 return ''; // Haven't found a good cookies icon under iron-icons. |
| 62 case siteSettings.ContentSettingsTypes.JAVASCRIPT: |
| 63 return 'icons:input'; |
| 64 case siteSettings.ContentSettingsTypes.FULLSCREEN: |
| 65 return 'icons:fullscreen'; |
| 66 case siteSettings.ContentSettingsTypes.POPUPS: |
| 67 return 'icons:open-in-new'; |
| 68 case siteSettings.ContentSettingsTypes.GEOLOCATION: |
| 69 return 'communication:location-on'; |
| 70 case siteSettings.ContentSettingsTypes.NOTIFICATION: |
| 71 return 'social:notifications'; |
| 72 case siteSettings.ContentSettingsTypes.CAMERA: |
| 73 return 'av:videocam'; |
| 74 case siteSettings.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 siteSettings.ContentSettingsTypes.COOKIES: |
| 91 return loadTimeData.getString('siteSettingsCookies'); |
| 92 case siteSettings.ContentSettingsTypes.JAVASCRIPT: |
| 93 return loadTimeData.getString('siteSettingsJavascript'); |
| 94 case siteSettings.ContentSettingsTypes.FULLSCREEN: |
| 95 return loadTimeData.getString('siteSettingsFullscreen'); |
| 96 case siteSettings.ContentSettingsTypes.POPUPS: |
| 97 return loadTimeData.getString('siteSettingsPopups'); |
| 98 case siteSettings.ContentSettingsTypes.GEOLOCATION: |
| 99 return loadTimeData.getString('siteSettingsLocation'); |
| 100 case siteSettings.ContentSettingsTypes.NOTIFICATION: |
| 101 return loadTimeData.getString('siteSettingsNotifications'); |
| 102 case siteSettings.ContentSettingsTypes.CAMERA: |
| 103 return loadTimeData.getString('siteSettingsCamera'); |
| 104 case siteSettings.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 computePrefName_: function(category) { |
| 119 switch (category) { |
| 120 case siteSettings.ContentSettingsTypes.COOKIES: |
| 121 return 'profile.default_content_setting_values.cookies'; |
| 122 case siteSettings.ContentSettingsTypes.JAVASCRIPT: |
| 123 return 'profile.default_content_setting_values.javascript'; |
| 124 case siteSettings.ContentSettingsTypes.FULLSCREEN: |
| 125 return 'profile.default_content_setting_values.fullscreen'; |
| 126 case siteSettings.ContentSettingsTypes.POPUPS: |
| 127 return 'profile.default_content_setting_values.popups'; |
| 128 case siteSettings.ContentSettingsTypes.GEOLOCATION: |
| 129 return 'profile.default_content_setting_values.geolocation'; |
| 130 case siteSettings.ContentSettingsTypes.NOTIFICATION: |
| 131 return 'profile.default_content_setting_values.notifications'; |
| 132 case siteSettings.ContentSettingsTypes.CAMERA: |
| 133 return 'profile.default_content_setting_values.media_stream_camera'; |
| 134 case siteSettings.ContentSettingsTypes.MIC: |
| 135 return 'profile.default_content_setting_values.media_stream_mic'; |
| 136 default: |
| 137 assertNotReached(); |
| 138 return ''; |
| 139 } |
| 140 }, |
| 141 |
| 142 /** |
| 143 * A utility function to compute the description for the category. |
| 144 * @param {number} category The category to show the description for. |
| 145 * @param {boolean} categoryEnabled The state of the global toggle. |
| 146 * @return {string} The category description. |
| 147 * @private |
| 148 */ |
| 149 computeDesc_: function(category, categoryEnabled) { |
| 150 switch (category) { |
| 151 case siteSettings.ContentSettingsTypes.JAVASCRIPT: |
| 152 // "Allowed (recommended)" vs "Blocked". |
| 153 return categoryEnabled ? |
| 154 loadTimeData.getString('siteSettingsAllowedRecommended') : |
| 155 loadTimeData.getString('siteSettingsBlocked'); |
| 156 case siteSettings.ContentSettingsTypes.POPUPS: |
| 157 // "Allowed" vs "Blocked (recommended)". |
| 158 return categoryEnabled ? |
| 159 loadTimeData.getString('siteSettingsAllowed') : |
| 160 loadTimeData.getString('siteSettingsBlockedRecommended'); |
| 161 case siteSettings.ContentSettingsTypes.NOTIFICATION: |
| 162 // "Ask before sending (recommended)" vs "Blocked". |
| 163 return categoryEnabled ? |
| 164 loadTimeData.getString('siteSettingsAskBeforeSending') : |
| 165 loadTimeData.getString('siteSettingsBlocked'); |
| 166 case siteSettings.ContentSettingsTypes.GEOLOCATION: |
| 167 case siteSettings.ContentSettingsTypes.CAMERA: |
| 168 case siteSettings.ContentSettingsTypes.MIC: |
| 169 // "Ask before accessing (recommended)" vs "Blocked". |
| 170 return categoryEnabled ? |
| 171 loadTimeData.getString('siteSettingsAskBeforeAccessing') : |
| 172 loadTimeData.getString('siteSettingsBlocked'); |
| 173 case siteSettings.ContentSettingsTypes.FULLSCREEN: |
| 174 // "Allowed" vs. "Ask first (recommended)". |
| 175 return categoryEnabled ? |
| 176 loadTimeData.getString('siteSettingsAllowed') : |
| 177 loadTimeData.getString('siteSettingsAskFirstRecommended'); |
| 178 case siteSettings.ContentSettingsTypes.COOKIES: |
| 179 // "Allow sites to save and read cookie data" vs "Blocked". |
| 180 return categoryEnabled ? |
| 181 loadTimeData.getString('siteSettingsCookiesAllowed') : |
| 182 loadTimeData.getString('siteSettingsBlocked'); |
| 183 default: |
| 184 assertNotReached(); |
| 185 return ''; |
| 186 } |
| 187 }, |
| 188 }; |
OLD | NEW |