| 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 15 matching lines...) Expand all Loading... |
| 26 created: function() { | 26 created: function() { |
| 27 this.browserProxy = | 27 this.browserProxy = |
| 28 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); | 28 settings.SiteSettingsPrefsBrowserProxyImpl.getInstance(); |
| 29 }, | 29 }, |
| 30 | 30 |
| 31 ready: function() { | 31 ready: function() { |
| 32 this.PermissionValues = settings.PermissionValues; | 32 this.PermissionValues = settings.PermissionValues; |
| 33 }, | 33 }, |
| 34 | 34 |
| 35 /** | 35 /** |
| 36 * A utility function to compute the description for the category. | |
| 37 * @param {string} category The category to show the description for. | |
| 38 * @param {string} setting The string value of the setting. | |
| 39 * @param {boolean} showRecommendation Whether to show the '(recommended)' | |
| 40 * label prefix. | |
| 41 * @return {string} The category description. | |
| 42 * @protected | |
| 43 */ | |
| 44 computeCategoryDesc: function(category, setting, showRecommendation) { | |
| 45 var categoryEnabled = this.computeIsSettingEnabled(setting); | |
| 46 switch (category) { | |
| 47 case settings.ContentSettingsTypes.JAVASCRIPT: | |
| 48 // "Allowed (recommended)" vs "Blocked". | |
| 49 if (!categoryEnabled) { | |
| 50 return loadTimeData.getString('siteSettingsBlocked'); | |
| 51 } | |
| 52 return showRecommendation ? | |
| 53 loadTimeData.getString('siteSettingsAllowedRecommended') : | |
| 54 loadTimeData.getString('siteSettingsAllowed'); | |
| 55 case settings.ContentSettingsTypes.POPUPS: | |
| 56 // "Allowed" vs "Blocked (recommended)". | |
| 57 if (categoryEnabled) { | |
| 58 return loadTimeData.getString('siteSettingsAllowed'); | |
| 59 } | |
| 60 return showRecommendation ? | |
| 61 loadTimeData.getString('siteSettingsBlockedRecommended') : | |
| 62 loadTimeData.getString('siteSettingsBlocked'); | |
| 63 case settings.ContentSettingsTypes.NOTIFICATIONS: | |
| 64 // "Ask before sending (recommended)" vs "Blocked". | |
| 65 if (!categoryEnabled) { | |
| 66 return loadTimeData.getString('siteSettingsBlocked'); | |
| 67 } | |
| 68 return showRecommendation ? | |
| 69 loadTimeData.getString('siteSettingsAskBeforeSendingRecommended') : | |
| 70 loadTimeData.getString('siteSettingsAskBeforeSending'); | |
| 71 case settings.ContentSettingsTypes.CAMERA: | |
| 72 case settings.ContentSettingsTypes.GEOLOCATION: | |
| 73 case settings.ContentSettingsTypes.MIC: | |
| 74 // "Ask before accessing (recommended)" vs "Blocked". | |
| 75 if (!categoryEnabled) { | |
| 76 return loadTimeData.getString('siteSettingsBlocked'); | |
| 77 } | |
| 78 return showRecommendation ? | |
| 79 loadTimeData.getString( | |
| 80 'siteSettingsAskBeforeAccessingRecommended') : | |
| 81 loadTimeData.getString('siteSettingsAskBeforeAccessing'); | |
| 82 case settings.ContentSettingsTypes.COOKIES: | |
| 83 // Tri-state: "Allow sites to save and read cookie data" vs "Blocked" | |
| 84 // vs "Keep local data only until you quit your browser". | |
| 85 if (setting == settings.PermissionValues.BLOCK) | |
| 86 return loadTimeData.getString('siteSettingsBlocked'); | |
| 87 if (setting == settings.PermissionValues.SESSION_ONLY) | |
| 88 return loadTimeData.getString('deleteDataPostSession'); | |
| 89 return showRecommendation ? | |
| 90 loadTimeData.getString('siteSettingsCookiesAllowedRecommended') : | |
| 91 loadTimeData.getString('siteSettingsCookiesAllowed'); | |
| 92 case settings.ContentSettingsTypes.PROTOCOL_HANDLERS: | |
| 93 // "Allow sites to ask to become default handlers" vs "Blocked". | |
| 94 if (!categoryEnabled) { | |
| 95 return loadTimeData.getString('siteSettingsHandlersBlocked'); | |
| 96 } | |
| 97 return showRecommendation ? | |
| 98 loadTimeData.getString('siteSettingsHandlersAskRecommended') : | |
| 99 loadTimeData.getString('siteSettingsHandlersAsk'); | |
| 100 case settings.ContentSettingsTypes.IMAGES: | |
| 101 if (!categoryEnabled) { | |
| 102 return loadTimeData.getString('siteSettingsDontShowImages'); | |
| 103 } | |
| 104 return showRecommendation ? | |
| 105 loadTimeData.getString('siteSettingsShowAllRecommended') : | |
| 106 loadTimeData.getString('siteSettingsShowAll'); | |
| 107 case settings.ContentSettingsTypes.PLUGINS: | |
| 108 if (setting == settings.PermissionValues.ALLOW) | |
| 109 return loadTimeData.getString('siteSettingsFlashAllow'); | |
| 110 if (setting == settings.PermissionValues.BLOCK) | |
| 111 return loadTimeData.getString('siteSettingsFlashBlock'); | |
| 112 return loadTimeData.getString('siteSettingsFlashAskBefore'); | |
| 113 case settings.ContentSettingsTypes.BACKGROUND_SYNC: | |
| 114 // "Allow sites to finish sending and receiving data" vs "Do not allow". | |
| 115 if (!categoryEnabled) { | |
| 116 return loadTimeData.getString('siteSettingsBackgroundSyncBlocked'); | |
| 117 } | |
| 118 return showRecommendation ? | |
| 119 loadTimeData.getString( | |
| 120 'siteSettingsAllowRecentlyClosedSitesRecommended') : | |
| 121 loadTimeData.getString('siteSettingsAllowRecentlyClosedSites'); | |
| 122 case settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS: | |
| 123 // "Ask when a site wants to auto-download multiple" vs "Do not allow". | |
| 124 if (!categoryEnabled) { | |
| 125 return loadTimeData.getString('siteSettingsAutoDownloadBlock'); | |
| 126 } | |
| 127 return showRecommendation ? | |
| 128 loadTimeData.getString('siteSettingsAutoDownloadAskRecommended') : | |
| 129 loadTimeData.getString('siteSettingsAutoDownloadAsk'); | |
| 130 case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS: | |
| 131 // "Ask when a plugin accesses your computer" vs "Do not allow". | |
| 132 if (!categoryEnabled) { | |
| 133 return loadTimeData.getString('siteSettingsUnsandboxedPluginsBlock'); | |
| 134 } | |
| 135 return showRecommendation ? | |
| 136 loadTimeData.getString( | |
| 137 'siteSettingsUnsandboxedPluginsAskRecommended') : | |
| 138 loadTimeData.getString('siteSettingsUnsandboxedPluginsAsk'); | |
| 139 default: | |
| 140 assertNotReached('Invalid category: ' + category); | |
| 141 return ''; | |
| 142 } | |
| 143 }, | |
| 144 | |
| 145 /** | |
| 146 * Ensures the URL has a scheme (assumes http if omitted). | 36 * Ensures the URL has a scheme (assumes http if omitted). |
| 147 * @param {string} url The URL with or without a scheme. | 37 * @param {string} url The URL with or without a scheme. |
| 148 * @return {string} The URL with a scheme, or an empty string. | 38 * @return {string} The URL with a scheme, or an empty string. |
| 149 */ | 39 */ |
| 150 ensureUrlHasScheme: function(url) { | 40 ensureUrlHasScheme: function(url) { |
| 151 if (url.length == 0) return url; | 41 if (url.length == 0) return url; |
| 152 return url.includes('://') ? url : 'http://' + url; | 42 return url.includes('://') ? url : 'http://' + url; |
| 153 }, | 43 }, |
| 154 | 44 |
| 155 /** | 45 /** |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 incognito: exception.incognito, | 186 incognito: exception.incognito, |
| 297 setting: exception.setting, | 187 setting: exception.setting, |
| 298 source: exception.source, | 188 source: exception.source, |
| 299 }; | 189 }; |
| 300 }, | 190 }, |
| 301 | 191 |
| 302 }; | 192 }; |
| 303 | 193 |
| 304 /** @polymerBehavior */ | 194 /** @polymerBehavior */ |
| 305 var SiteSettingsBehavior = [SiteSettingsBehaviorImpl]; | 195 var SiteSettingsBehavior = [SiteSettingsBehaviorImpl]; |
| OLD | NEW |