| 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" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/clock.h" | 15 #include "base/time/clock.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | |
| 17 #include "chrome/browser/content_settings/content_settings_custom_extension_prov
ider.h" | |
| 18 #include "chrome/browser/content_settings/content_settings_default_provider.h" | 16 #include "chrome/browser/content_settings/content_settings_default_provider.h" |
| 19 #include "chrome/browser/content_settings/content_settings_details.h" | 17 #include "chrome/browser/content_settings/content_settings_details.h" |
| 20 #include "chrome/browser/content_settings/content_settings_internal_extension_pr
ovider.h" | |
| 21 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" | 18 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" |
| 22 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 19 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
| 23 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 20 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
| 24 #include "chrome/browser/content_settings/content_settings_provider.h" | 21 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 25 #include "chrome/browser/content_settings/content_settings_rule.h" | 22 #include "chrome/browser/content_settings/content_settings_rule.h" |
| 26 #include "chrome/browser/content_settings/content_settings_utils.h" | 23 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 27 #include "chrome/browser/extensions/api/content_settings/content_settings_servic
e.h" | |
| 28 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/common/url_constants.h" | 26 #include "chrome/common/url_constants.h" |
| 31 #include "components/content_settings/core/common/content_settings_pattern.h" | 27 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 32 #include "components/pref_registry/pref_registry_syncable.h" | 28 #include "components/pref_registry/pref_registry_syncable.h" |
| 33 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_service.h" | |
| 35 #include "content/public/browser/notification_source.h" | |
| 36 #include "content/public/browser/user_metrics.h" | |
| 37 #include "content/public/common/content_switches.h" | 30 #include "content/public/common/content_switches.h" |
| 38 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 39 #include "net/base/static_cookie_policy.h" | 32 #include "net/base/static_cookie_policy.h" |
| 40 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 41 | 34 |
| 42 #if defined(ENABLE_EXTENSIONS) | 35 #if defined(ENABLE_EXTENSIONS) |
| 43 #include "chrome/browser/extensions/extension_service.h" | |
| 44 #include "extensions/browser/extension_prefs.h" | |
| 45 #include "extensions/common/constants.h" | 36 #include "extensions/common/constants.h" |
| 46 #endif | 37 #endif |
| 47 | 38 |
| 48 using base::UserMetricsAction; | |
| 49 using content::BrowserThread; | 39 using content::BrowserThread; |
| 50 | 40 |
| 51 namespace { | 41 namespace { |
| 52 | 42 |
| 53 typedef std::vector<content_settings::Rule> Rules; | 43 typedef std::vector<content_settings::Rule> Rules; |
| 54 | 44 |
| 55 typedef std::pair<std::string, std::string> StringPair; | 45 typedef std::pair<std::string, std::string> StringPair; |
| 56 | 46 |
| 57 // TODO(bauerb): Expose constants. | 47 // TODO(bauerb): Expose constants. |
| 58 const char* kProviderNames[] = { | 48 const char* kProviderNames[] = { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 94 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
| 105 default_provider->AddObserver(this); | 95 default_provider->AddObserver(this); |
| 106 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 96 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
| 107 | 97 |
| 108 if (!is_off_the_record_) { | 98 if (!is_off_the_record_) { |
| 109 // Migrate obsolete preferences. | 99 // Migrate obsolete preferences. |
| 110 MigrateObsoleteClearOnExitPref(); | 100 MigrateObsoleteClearOnExitPref(); |
| 111 } | 101 } |
| 112 } | 102 } |
| 113 | 103 |
| 114 #if defined(ENABLE_EXTENSIONS) | |
| 115 void HostContentSettingsMap::RegisterExtensionService( | |
| 116 ExtensionService* extension_service) { | |
| 117 DCHECK(extension_service); | |
| 118 DCHECK(!content_settings_providers_[INTERNAL_EXTENSION_PROVIDER]); | |
| 119 DCHECK(!content_settings_providers_[CUSTOM_EXTENSION_PROVIDER]); | |
| 120 | |
| 121 content_settings::InternalExtensionProvider* internal_extension_provider = | |
| 122 new content_settings::InternalExtensionProvider(extension_service); | |
| 123 internal_extension_provider->AddObserver(this); | |
| 124 content_settings_providers_[INTERNAL_EXTENSION_PROVIDER] = | |
| 125 internal_extension_provider; | |
| 126 | |
| 127 content_settings::ObservableProvider* custom_extension_provider = | |
| 128 new content_settings::CustomExtensionProvider( | |
| 129 extensions::ContentSettingsService::Get( | |
| 130 extension_service->GetBrowserContext())->content_settings_store(), | |
| 131 is_off_the_record_); | |
| 132 custom_extension_provider->AddObserver(this); | |
| 133 content_settings_providers_[CUSTOM_EXTENSION_PROVIDER] = | |
| 134 custom_extension_provider; | |
| 135 | |
| 136 #ifndef NDEBUG | |
| 137 DCHECK(used_from_thread_id_ != base::kInvalidThreadId) | |
| 138 << "Used from multiple threads before initialization complete."; | |
| 139 #endif | |
| 140 | |
| 141 OnContentSettingChanged(ContentSettingsPattern(), | |
| 142 ContentSettingsPattern(), | |
| 143 CONTENT_SETTINGS_TYPE_DEFAULT, | |
| 144 std::string()); | |
| 145 } | |
| 146 #endif | |
| 147 | |
| 148 // static | 104 // static |
| 149 void HostContentSettingsMap::RegisterProfilePrefs( | 105 void HostContentSettingsMap::RegisterProfilePrefs( |
| 150 user_prefs::PrefRegistrySyncable* registry) { | 106 user_prefs::PrefRegistrySyncable* registry) { |
| 151 registry->RegisterIntegerPref( | 107 registry->RegisterIntegerPref( |
| 152 prefs::kContentSettingsWindowLastTabIndex, | 108 prefs::kContentSettingsWindowLastTabIndex, |
| 153 0, | 109 0, |
| 154 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 110 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 155 registry->RegisterIntegerPref( | 111 registry->RegisterIntegerPref( |
| 156 prefs::kContentSettingsDefaultWhitelistVersion, | 112 prefs::kContentSettingsDefaultWhitelistVersion, |
| 157 0, | 113 0, |
| 158 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 114 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 159 registry->RegisterBooleanPref( | 115 registry->RegisterBooleanPref( |
| 160 prefs::kContentSettingsClearOnExitMigrated, | 116 prefs::kContentSettingsClearOnExitMigrated, |
| 161 false, | 117 false, |
| 162 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 118 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 163 | 119 |
| 164 // Register the prefs for the content settings providers. | 120 // Register the prefs for the content settings providers. |
| 165 content_settings::DefaultProvider::RegisterProfilePrefs(registry); | 121 content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
| 166 content_settings::PrefProvider::RegisterProfilePrefs(registry); | 122 content_settings::PrefProvider::RegisterProfilePrefs(registry); |
| 167 content_settings::PolicyProvider::RegisterProfilePrefs(registry); | 123 content_settings::PolicyProvider::RegisterProfilePrefs(registry); |
| 168 } | 124 } |
| 169 | 125 |
| 126 void HostContentSettingsMap::RegisterProvider( |
| 127 ProviderType type, |
| 128 scoped_ptr<content_settings::ObservableProvider> provider) { |
| 129 DCHECK(!content_settings_providers_[type]); |
| 130 provider->AddObserver(this); |
| 131 content_settings_providers_[type] = provider.release(); |
| 132 |
| 133 #ifndef NDEBUG |
| 134 DCHECK_NE(used_from_thread_id_, base::kInvalidThreadId) |
| 135 << "Used from multiple threads before initialization complete."; |
| 136 #endif |
| 137 |
| 138 OnContentSettingChanged(ContentSettingsPattern(), |
| 139 ContentSettingsPattern(), |
| 140 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 141 std::string()); |
| 142 } |
| 143 |
| 170 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( | 144 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( |
| 171 ContentSettingsType content_type, | 145 ContentSettingsType content_type, |
| 172 content_settings::ProviderInterface* provider) const { | 146 content_settings::ProviderInterface* provider) const { |
| 173 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 147 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
| 174 provider->GetRuleIterator(content_type, std::string(), false)); | 148 provider->GetRuleIterator(content_type, std::string(), false)); |
| 175 | 149 |
| 176 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 150 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
| 177 while (rule_iterator->HasNext()) { | 151 while (rule_iterator->HasNext()) { |
| 178 content_settings::Rule rule = rule_iterator->Next(); | 152 content_settings::Rule rule = rule_iterator->Next(); |
| 179 if (rule.primary_pattern == wildcard && | 153 if (rule.primary_pattern == wildcard && |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 } | 730 } |
| 757 | 731 |
| 758 NOTREACHED(); | 732 NOTREACHED(); |
| 759 return DEFAULT_PROVIDER; | 733 return DEFAULT_PROVIDER; |
| 760 } | 734 } |
| 761 | 735 |
| 762 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { | 736 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { |
| 763 return static_cast<content_settings::PrefProvider*>( | 737 return static_cast<content_settings::PrefProvider*>( |
| 764 content_settings_providers_[PREF_PROVIDER]); | 738 content_settings_providers_[PREF_PROVIDER]); |
| 765 } | 739 } |
| OLD | NEW |