| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 if (setting == settings.PermissionValues.BLOCK) | 110 if (setting == settings.PermissionValues.BLOCK) |
| 111 return loadTimeData.getString('siteSettingsFlashBlock'); | 111 return loadTimeData.getString('siteSettingsFlashBlock'); |
| 112 return loadTimeData.getString('siteSettingsFlashAskBefore'); | 112 return loadTimeData.getString('siteSettingsFlashAskBefore'); |
| 113 case settings.ContentSettingsTypes.BACKGROUND_SYNC: | 113 case settings.ContentSettingsTypes.BACKGROUND_SYNC: |
| 114 // "Allow sites to finish sending and receiving data" vs "Do not allow". | 114 // "Allow sites to finish sending and receiving data" vs "Do not allow". |
| 115 if (!categoryEnabled) { | 115 if (!categoryEnabled) { |
| 116 return loadTimeData.getString('siteSettingsBackgroundSyncBlocked'); | 116 return loadTimeData.getString('siteSettingsBackgroundSyncBlocked'); |
| 117 } | 117 } |
| 118 return showRecommendation ? | 118 return showRecommendation ? |
| 119 loadTimeData.getString( | 119 loadTimeData.getString( |
| 120 'siteSettingsAllowRecentlyClosedSitesRecommended') : | 120 'siteSettingsAllowRecentlyClosedSitesRecommended') : |
| 121 loadTimeData.getString('siteSettingsAllowRecentlyClosedSites'); | 121 loadTimeData.getString('siteSettingsAllowRecentlyClosedSites'); |
| 122 case settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS: | 122 case settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS: |
| 123 // "Ask when a site wants to auto-download multiple" vs "Do not allow". | 123 // "Ask when a site wants to auto-download multiple" vs "Do not allow". |
| 124 if (!categoryEnabled) { | 124 if (!categoryEnabled) { |
| 125 return loadTimeData.getString('siteSettingsAutoDownloadBlock'); | 125 return loadTimeData.getString('siteSettingsAutoDownloadBlock'); |
| 126 } | 126 } |
| 127 return showRecommendation ? | 127 return showRecommendation ? |
| 128 loadTimeData.getString('siteSettingsAutoDownloadAskRecommended') : | 128 loadTimeData.getString('siteSettingsAutoDownloadAskRecommended') : |
| 129 loadTimeData.getString('siteSettingsAutoDownloadAsk'); | 129 loadTimeData.getString('siteSettingsAutoDownloadAsk'); |
| 130 case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS: | 130 case settings.ContentSettingsTypes.UNSANDBOXED_PLUGINS: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 141 return ''; | 141 return ''; |
| 142 } | 142 } |
| 143 }, | 143 }, |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * Ensures the URL has a scheme (assumes http if omitted). | 146 * Ensures the URL has a scheme (assumes http if omitted). |
| 147 * @param {string} url The URL with or without a scheme. | 147 * @param {string} url The URL with or without a scheme. |
| 148 * @return {string} The URL with a scheme, or an empty string. | 148 * @return {string} The URL with a scheme, or an empty string. |
| 149 */ | 149 */ |
| 150 ensureUrlHasScheme: function(url) { | 150 ensureUrlHasScheme: function(url) { |
| 151 if (url.length == 0) return url; | 151 if (url.length == 0) |
| 152 return url; |
| 152 return url.includes('://') ? url : 'http://' + url; | 153 return url.includes('://') ? url : 'http://' + url; |
| 153 }, | 154 }, |
| 154 | 155 |
| 155 /** | 156 /** |
| 156 * Removes redundant ports, such as port 80 for http and 443 for https. | 157 * Removes redundant ports, such as port 80 for http and 443 for https. |
| 157 * @param {string} url The URL to sanitize. | 158 * @param {string} url The URL to sanitize. |
| 158 * @return {string} The URL without redundant ports, if any. | 159 * @return {string} The URL without redundant ports, if any. |
| 159 */ | 160 */ |
| 160 sanitizePort: function(url) { | 161 sanitizePort: function(url) { |
| 161 var urlWithScheme = this.ensureUrlHasScheme(url); | 162 var urlWithScheme = this.ensureUrlHasScheme(url); |
| 162 if (urlWithScheme.startsWith('https://') && | 163 if (urlWithScheme.startsWith('https://') && |
| 163 urlWithScheme.endsWith(':443')) { | 164 urlWithScheme.endsWith(':443')) { |
| 164 return url.slice(0, -4); | 165 return url.slice(0, -4); |
| 165 } | 166 } |
| 166 if (urlWithScheme.startsWith('http://') && | 167 if (urlWithScheme.startsWith('http://') && urlWithScheme.endsWith(':80')) { |
| 167 urlWithScheme.endsWith(':80')) { | |
| 168 return url.slice(0, -3); | 168 return url.slice(0, -3); |
| 169 } | 169 } |
| 170 return url; | 170 return url; |
| 171 }, | 171 }, |
| 172 | 172 |
| 173 /** | 173 /** |
| 174 * Adds the wildcard prefix to a pattern string (if missing). | 174 * Adds the wildcard prefix to a pattern string (if missing). |
| 175 * @param {string} pattern The pattern to add the wildcard to. | 175 * @param {string} pattern The pattern to add the wildcard to. |
| 176 * @return {string} The resulting pattern. | 176 * @return {string} The resulting pattern. |
| 177 * @private | 177 * @private |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 incognito: exception.incognito, | 296 incognito: exception.incognito, |
| 297 setting: exception.setting, | 297 setting: exception.setting, |
| 298 source: exception.source, | 298 source: exception.source, |
| 299 }; | 299 }; |
| 300 }, | 300 }, |
| 301 | 301 |
| 302 }; | 302 }; |
| 303 | 303 |
| 304 /** @polymerBehavior */ | 304 /** @polymerBehavior */ |
| 305 var SiteSettingsBehavior = [SiteSettingsBehaviorImpl]; | 305 var SiteSettingsBehavior = [SiteSettingsBehaviorImpl]; |
| OLD | NEW |