| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/content_settings/content_settings_base_provider.h" | 6 #include "chrome/browser/content_settings/content_settings_base_provider.h" |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 ContentSetting BaseProvider::GetContentSetting( | 67 ContentSetting BaseProvider::GetContentSetting( |
| 68 const GURL& requesting_url, | 68 const GURL& requesting_url, |
| 69 const GURL& embedding_url, | 69 const GURL& embedding_url, |
| 70 ContentSettingsType content_type, | 70 ContentSettingsType content_type, |
| 71 const ResourceIdentifier& resource_identifier) const { | 71 const ResourceIdentifier& resource_identifier) const { |
| 72 // Support for embedding_patterns is not implemented yet. | 72 // Support for embedding_patterns is not implemented yet. |
| 73 DCHECK(requesting_url == embedding_url); | 73 DCHECK(requesting_url == embedding_url); |
| 74 | 74 |
| 75 if (!RequiresResourceIdentifier(content_type)) | 75 if (!RequiresResourceIdentifier(content_type) || |
| 76 (RequiresResourceIdentifier(content_type) && resource_identifier.empty())) |
| 76 return GetNonDefaultContentSettings(requesting_url).settings[content_type]; | 77 return GetNonDefaultContentSettings(requesting_url).settings[content_type]; |
| 77 | 78 |
| 78 if (RequiresResourceIdentifier(content_type) && resource_identifier.empty()) | |
| 79 return CONTENT_SETTING_DEFAULT; | |
| 80 | |
| 81 // TODO(markusheintz) Remove this DCHECK. | |
| 82 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 83 switches::kEnableResourceContentSettings)) { | |
| 84 DCHECK(!resource_identifier.empty()); | |
| 85 } | |
| 86 | |
| 87 // Resolve content settings with resource identifier. | 79 // Resolve content settings with resource identifier. |
| 88 // 1. Check for pattern that exactly match the url/host | 80 // 1. Check for pattern that exactly match the url/host |
| 89 // 1.1 In the content-settings-map | 81 // 1.1 In the content-settings-map |
| 90 // 1.2 In the off_the_record content-settings-map | 82 // 1.2 In the off_the_record content-settings-map |
| 91 // 3. Shorten the url subdomain by subdomain and try to find a pattern in | 83 // 3. Shorten the url subdomain by subdomain and try to find a pattern in |
| 92 // 3.1 OTR content-settings-map | 84 // 3.1 OTR content-settings-map |
| 93 // 3.2 content-settings-map | 85 // 3.2 content-settings-map |
| 94 base::AutoLock auto_lock(lock_); | 86 base::AutoLock auto_lock(lock_); |
| 95 const std::string host(net::GetHostOrSpecFromURL(requesting_url)); | 87 const std::string host(net::GetHostOrSpecFromURL(requesting_url)); |
| 96 ContentSettingsTypeResourceIdentifierPair | 88 ContentSettingsTypeResourceIdentifierPair |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 next_dot - ContentSettingsPattern::kDomainWildcardLength + 1); | 135 next_dot - ContentSettingsPattern::kDomainWildcardLength + 1); |
| 144 } | 136 } |
| 145 | 137 |
| 146 return CONTENT_SETTING_DEFAULT; | 138 return CONTENT_SETTING_DEFAULT; |
| 147 } | 139 } |
| 148 | 140 |
| 149 void BaseProvider::GetAllContentSettingsRules( | 141 void BaseProvider::GetAllContentSettingsRules( |
| 150 ContentSettingsType content_type, | 142 ContentSettingsType content_type, |
| 151 const ResourceIdentifier& resource_identifier, | 143 const ResourceIdentifier& resource_identifier, |
| 152 Rules* content_setting_rules) const { | 144 Rules* content_setting_rules) const { |
| 153 DCHECK(RequiresResourceIdentifier(content_type) != | |
| 154 resource_identifier.empty()); | |
| 155 DCHECK(content_setting_rules); | 145 DCHECK(content_setting_rules); |
| 156 content_setting_rules->clear(); | 146 content_setting_rules->clear(); |
| 157 | 147 |
| 158 const HostContentSettings* map_to_return = | 148 const HostContentSettings* map_to_return = |
| 159 is_off_the_record_ ? &off_the_record_settings_ : &host_content_settings_; | 149 is_off_the_record_ ? &off_the_record_settings_ : &host_content_settings_; |
| 160 ContentSettingsTypeResourceIdentifierPair requested_setting( | 150 ContentSettingsTypeResourceIdentifierPair requested_setting( |
| 161 content_type, resource_identifier); | 151 content_type, resource_identifier); |
| 162 | 152 |
| 163 base::AutoLock auto_lock(lock_); | 153 base::AutoLock auto_lock(lock_); |
| 164 for (HostContentSettings::const_iterator i(map_to_return->begin()); | 154 for (HostContentSettings::const_iterator i(map_to_return->begin()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 key.find('.', ContentSettingsPattern::kDomainWildcardLength); | 220 key.find('.', ContentSettingsPattern::kDomainWildcardLength); |
| 231 if (next_dot == std::string::npos) | 221 if (next_dot == std::string::npos) |
| 232 break; | 222 break; |
| 233 key.erase(ContentSettingsPattern::kDomainWildcardLength, | 223 key.erase(ContentSettingsPattern::kDomainWildcardLength, |
| 234 next_dot - ContentSettingsPattern::kDomainWildcardLength + 1); | 224 next_dot - ContentSettingsPattern::kDomainWildcardLength + 1); |
| 235 } | 225 } |
| 236 | 226 |
| 237 return output; | 227 return output; |
| 238 } | 228 } |
| 239 | 229 |
| 230 void BaseProvider::UpdateContentSettingsMap( |
| 231 const ContentSettingsPattern& requesting_pattern, |
| 232 const ContentSettingsPattern& embedding_pattern, |
| 233 ContentSettingsType content_type, |
| 234 const ResourceIdentifier& resource_identifier, |
| 235 ContentSetting content_setting) { |
| 236 std::string pattern_str(requesting_pattern.CanonicalizePattern()); |
| 237 HostContentSettings* content_settings_map = host_content_settings(); |
| 238 ExtendedContentSettings& extended_settings = |
| 239 (*content_settings_map)[pattern_str]; |
| 240 extended_settings.content_settings.settings[content_type] = content_setting; |
| 241 } |
| 242 |
| 240 // static | 243 // static |
| 241 ContentSetting BaseProvider::ClickToPlayFixup(ContentSettingsType content_type, | 244 ContentSetting BaseProvider::ClickToPlayFixup(ContentSettingsType content_type, |
| 242 ContentSetting setting) { | 245 ContentSetting setting) { |
| 243 if (setting == CONTENT_SETTING_ASK && | 246 if (setting == CONTENT_SETTING_ASK && |
| 244 content_type == CONTENT_SETTINGS_TYPE_PLUGINS && | 247 content_type == CONTENT_SETTINGS_TYPE_PLUGINS && |
| 245 !CommandLine::ForCurrentProcess()->HasSwitch( | 248 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 246 switches::kEnableClickToPlay)) { | 249 switches::kEnableClickToPlay)) { |
| 247 return CONTENT_SETTING_BLOCK; | 250 return CONTENT_SETTING_BLOCK; |
| 248 } | 251 } |
| 249 return setting; | 252 return setting; |
| 250 } | 253 } |
| 251 | 254 |
| 252 } // namespace content_settings | 255 } // namespace content_settings |
| OLD | NEW |