| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/content_settings/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // Returns true if the |content_type| supports a resource identifier. | 71 // Returns true if the |content_type| supports a resource identifier. |
| 72 // Resource identifiers are supported (but not required) for plug-ins. | 72 // Resource identifiers are supported (but not required) for plug-ins. |
| 73 bool SupportsResourceIdentifier(ContentSettingsType content_type) { | 73 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
| 74 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 74 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace | 77 } // namespace |
| 78 | 78 |
| 79 HostContentSettingsMap::HostContentSettingsMap( | 79 HostContentSettingsMap::HostContentSettingsMap( |
| 80 PrefService* prefs, | 80 PrefService* prefs, |
| 81 bool incognito) | 81 bool incognito) : |
| 82 : prefs_(prefs), | 82 #ifndef NDEBUG |
| 83 used_content_settings_providers_(false), |
| 84 #endif |
| 85 prefs_(prefs), |
| 83 is_off_the_record_(incognito) { | 86 is_off_the_record_(incognito) { |
| 84 content_settings::ObservableProvider* policy_provider = | 87 content_settings::ObservableProvider* policy_provider = |
| 85 new content_settings::PolicyProvider(prefs_); | 88 new content_settings::PolicyProvider(prefs_); |
| 86 policy_provider->AddObserver(this); | 89 policy_provider->AddObserver(this); |
| 87 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 90 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
| 88 | 91 |
| 89 content_settings::ObservableProvider* pref_provider = | 92 content_settings::ObservableProvider* pref_provider = |
| 90 new content_settings::PrefProvider(prefs_, is_off_the_record_); | 93 new content_settings::PrefProvider(prefs_, is_off_the_record_); |
| 91 pref_provider->AddObserver(this); | 94 pref_provider->AddObserver(this); |
| 92 content_settings_providers_[PREF_PROVIDER] = pref_provider; | 95 content_settings_providers_[PREF_PROVIDER] = pref_provider; |
| 93 | 96 |
| 94 content_settings::ObservableProvider* default_provider = | 97 content_settings::ObservableProvider* default_provider = |
| 95 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 98 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
| 96 default_provider->AddObserver(this); | 99 default_provider->AddObserver(this); |
| 97 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 100 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
| 98 | 101 |
| 99 if (!is_off_the_record_) { | 102 if (!is_off_the_record_) { |
| 100 // Migrate obsolete preferences. | 103 // Migrate obsolete preferences. |
| 101 MigrateObsoleteClearOnExitPref(); | 104 MigrateObsoleteClearOnExitPref(); |
| 102 } | 105 } |
| 103 } | 106 } |
| 104 | 107 |
| 105 #if defined(ENABLE_EXTENSIONS) | 108 #if defined(ENABLE_EXTENSIONS) |
| 106 void HostContentSettingsMap::RegisterExtensionService( | 109 void HostContentSettingsMap::RegisterExtensionService( |
| 107 ExtensionService* extension_service) { | 110 ExtensionService* extension_service) { |
| 108 DCHECK(extension_service); | 111 DCHECK(extension_service); |
| 112 #ifndef NDEBUG |
| 113 DCHECK(!used_content_settings_providers_); |
| 114 #endif |
| 109 DCHECK(!content_settings_providers_[INTERNAL_EXTENSION_PROVIDER]); | 115 DCHECK(!content_settings_providers_[INTERNAL_EXTENSION_PROVIDER]); |
| 110 DCHECK(!content_settings_providers_[CUSTOM_EXTENSION_PROVIDER]); | 116 DCHECK(!content_settings_providers_[CUSTOM_EXTENSION_PROVIDER]); |
| 111 | 117 |
| 112 content_settings::InternalExtensionProvider* internal_extension_provider = | 118 content_settings::InternalExtensionProvider* internal_extension_provider = |
| 113 new content_settings::InternalExtensionProvider(extension_service); | 119 new content_settings::InternalExtensionProvider(extension_service); |
| 114 internal_extension_provider->AddObserver(this); | 120 internal_extension_provider->AddObserver(this); |
| 115 content_settings_providers_[INTERNAL_EXTENSION_PROVIDER] = | 121 content_settings_providers_[INTERNAL_EXTENSION_PROVIDER] = |
| 116 internal_extension_provider; | 122 internal_extension_provider; |
| 117 | 123 |
| 118 content_settings::ObservableProvider* custom_extension_provider = | 124 content_settings::ObservableProvider* custom_extension_provider = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 rule.secondary_pattern == wildcard) { | 167 rule.secondary_pattern == wildcard) { |
| 162 return content_settings::ValueToContentSetting(rule.value.get()); | 168 return content_settings::ValueToContentSetting(rule.value.get()); |
| 163 } | 169 } |
| 164 } | 170 } |
| 165 return CONTENT_SETTING_DEFAULT; | 171 return CONTENT_SETTING_DEFAULT; |
| 166 } | 172 } |
| 167 | 173 |
| 168 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( | 174 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
| 169 ContentSettingsType content_type, | 175 ContentSettingsType content_type, |
| 170 std::string* provider_id) const { | 176 std::string* provider_id) const { |
| 177 UsedContentSettingsProviders(); |
| 178 |
| 171 // Iterate through the list of providers and return the first non-NULL value | 179 // Iterate through the list of providers and return the first non-NULL value |
| 172 // that matches |primary_url| and |secondary_url|. | 180 // that matches |primary_url| and |secondary_url|. |
| 173 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 181 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 174 provider != content_settings_providers_.end(); | 182 provider != content_settings_providers_.end(); |
| 175 ++provider) { | 183 ++provider) { |
| 176 if (provider->first == PREF_PROVIDER) | 184 if (provider->first == PREF_PROVIDER) |
| 177 continue; | 185 continue; |
| 178 ContentSetting default_setting = | 186 ContentSetting default_setting = |
| 179 GetDefaultContentSettingFromProvider(content_type, provider->second); | 187 GetDefaultContentSettingFromProvider(content_type, provider->second); |
| 180 if (default_setting != CONTENT_SETTING_DEFAULT) { | 188 if (default_setting != CONTENT_SETTING_DEFAULT) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 202 return content_settings::ValueToContentSetting(value.get()); | 210 return content_settings::ValueToContentSetting(value.get()); |
| 203 } | 211 } |
| 204 | 212 |
| 205 void HostContentSettingsMap::GetSettingsForOneType( | 213 void HostContentSettingsMap::GetSettingsForOneType( |
| 206 ContentSettingsType content_type, | 214 ContentSettingsType content_type, |
| 207 const std::string& resource_identifier, | 215 const std::string& resource_identifier, |
| 208 ContentSettingsForOneType* settings) const { | 216 ContentSettingsForOneType* settings) const { |
| 209 DCHECK(SupportsResourceIdentifier(content_type) || | 217 DCHECK(SupportsResourceIdentifier(content_type) || |
| 210 resource_identifier.empty()); | 218 resource_identifier.empty()); |
| 211 DCHECK(settings); | 219 DCHECK(settings); |
| 220 UsedContentSettingsProviders(); |
| 212 | 221 |
| 213 settings->clear(); | 222 settings->clear(); |
| 214 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 223 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 215 provider != content_settings_providers_.end(); | 224 provider != content_settings_providers_.end(); |
| 216 ++provider) { | 225 ++provider) { |
| 217 // For each provider, iterate first the incognito-specific rules, then the | 226 // For each provider, iterate first the incognito-specific rules, then the |
| 218 // normal rules. | 227 // normal rules. |
| 219 if (is_off_the_record_) { | 228 if (is_off_the_record_) { |
| 220 AddSettingsForOneType(provider->second, | 229 AddSettingsForOneType(provider->second, |
| 221 provider->first, | 230 provider->first, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 251 | 260 |
| 252 void HostContentSettingsMap::SetWebsiteSetting( | 261 void HostContentSettingsMap::SetWebsiteSetting( |
| 253 const ContentSettingsPattern& primary_pattern, | 262 const ContentSettingsPattern& primary_pattern, |
| 254 const ContentSettingsPattern& secondary_pattern, | 263 const ContentSettingsPattern& secondary_pattern, |
| 255 ContentSettingsType content_type, | 264 ContentSettingsType content_type, |
| 256 const std::string& resource_identifier, | 265 const std::string& resource_identifier, |
| 257 base::Value* value) { | 266 base::Value* value) { |
| 258 DCHECK(IsValueAllowedForType(prefs_, value, content_type)); | 267 DCHECK(IsValueAllowedForType(prefs_, value, content_type)); |
| 259 DCHECK(SupportsResourceIdentifier(content_type) || | 268 DCHECK(SupportsResourceIdentifier(content_type) || |
| 260 resource_identifier.empty()); | 269 resource_identifier.empty()); |
| 270 UsedContentSettingsProviders(); |
| 271 |
| 261 for (ProviderIterator provider = content_settings_providers_.begin(); | 272 for (ProviderIterator provider = content_settings_providers_.begin(); |
| 262 provider != content_settings_providers_.end(); | 273 provider != content_settings_providers_.end(); |
| 263 ++provider) { | 274 ++provider) { |
| 264 if (provider->second->SetWebsiteSetting(primary_pattern, | 275 if (provider->second->SetWebsiteSetting(primary_pattern, |
| 265 secondary_pattern, | 276 secondary_pattern, |
| 266 content_type, | 277 content_type, |
| 267 resource_identifier, | 278 resource_identifier, |
| 268 value)) { | 279 value)) { |
| 269 return; | 280 return; |
| 270 } | 281 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 321 |
| 311 SetContentSetting(ContentSettingsPattern::FromURL(primary_url), | 322 SetContentSetting(ContentSettingsPattern::FromURL(primary_url), |
| 312 ContentSettingsPattern::Wildcard(), | 323 ContentSettingsPattern::Wildcard(), |
| 313 content_type, | 324 content_type, |
| 314 resource_identifier, | 325 resource_identifier, |
| 315 setting); | 326 setting); |
| 316 } | 327 } |
| 317 | 328 |
| 318 void HostContentSettingsMap::ClearSettingsForOneType( | 329 void HostContentSettingsMap::ClearSettingsForOneType( |
| 319 ContentSettingsType content_type) { | 330 ContentSettingsType content_type) { |
| 331 UsedContentSettingsProviders(); |
| 320 for (ProviderIterator provider = content_settings_providers_.begin(); | 332 for (ProviderIterator provider = content_settings_providers_.begin(); |
| 321 provider != content_settings_providers_.end(); | 333 provider != content_settings_providers_.end(); |
| 322 ++provider) { | 334 ++provider) { |
| 323 provider->second->ClearAllContentSettingsRules(content_type); | 335 provider->second->ClearAllContentSettingsRules(content_type); |
| 324 } | 336 } |
| 325 } | 337 } |
| 326 | 338 |
| 327 bool HostContentSettingsMap::IsValueAllowedForType( | 339 bool HostContentSettingsMap::IsValueAllowedForType( |
| 328 PrefService* prefs, const base::Value* value, ContentSettingsType type) { | 340 PrefService* prefs, const base::Value* value, ContentSettingsType type) { |
| 329 return ContentTypeHasCompoundValue(type) || IsSettingAllowedForType( | 341 return ContentTypeHasCompoundValue(type) || IsSettingAllowedForType( |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 setting_value = content_settings::ValueToContentSetting(rule.value.get()); | 510 setting_value = content_settings::ValueToContentSetting(rule.value.get()); |
| 499 } | 511 } |
| 500 settings->push_back(ContentSettingPatternSource( | 512 settings->push_back(ContentSettingPatternSource( |
| 501 rule.primary_pattern, rule.secondary_pattern, | 513 rule.primary_pattern, rule.secondary_pattern, |
| 502 setting_value, | 514 setting_value, |
| 503 kProviderNames[provider_type], | 515 kProviderNames[provider_type], |
| 504 incognito)); | 516 incognito)); |
| 505 } | 517 } |
| 506 } | 518 } |
| 507 | 519 |
| 520 void HostContentSettingsMap::UsedContentSettingsProviders() const { |
| 521 #ifndef NDEBUG |
| 522 used_content_settings_providers_ = true; |
| 523 #endif |
| 524 } |
| 525 |
| 508 bool HostContentSettingsMap::ShouldAllowAllContent( | 526 bool HostContentSettingsMap::ShouldAllowAllContent( |
| 509 const GURL& primary_url, | 527 const GURL& primary_url, |
| 510 const GURL& secondary_url, | 528 const GURL& secondary_url, |
| 511 ContentSettingsType content_type) { | 529 ContentSettingsType content_type) { |
| 512 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS || | 530 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS || |
| 513 content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { | 531 content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 514 return false; | 532 return false; |
| 515 } | 533 } |
| 516 if (secondary_url.SchemeIs(chrome::kChromeUIScheme) && | 534 if (secondary_url.SchemeIs(chrome::kChromeUIScheme) && |
| 517 content_type == CONTENT_SETTINGS_TYPE_COOKIES && | 535 content_type == CONTENT_SETTINGS_TYPE_COOKIES && |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 HostContentSettingsMap::GetProviderTypeFromSource( | 601 HostContentSettingsMap::GetProviderTypeFromSource( |
| 584 const std::string& source) { | 602 const std::string& source) { |
| 585 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { | 603 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { |
| 586 if (source == kProviderNames[i]) | 604 if (source == kProviderNames[i]) |
| 587 return static_cast<ProviderType>(i); | 605 return static_cast<ProviderType>(i); |
| 588 } | 606 } |
| 589 | 607 |
| 590 NOTREACHED(); | 608 NOTREACHED(); |
| 591 return DEFAULT_PROVIDER; | 609 return DEFAULT_PROVIDER; |
| 592 } | 610 } |
| OLD | NEW |