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->RegisterBooleanPref( | 111 registry->RegisterBooleanPref( |
156 prefs::kContentSettingsClearOnExitMigrated, | 112 prefs::kContentSettingsClearOnExitMigrated, |
157 false, | 113 false, |
158 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 114 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
159 | 115 |
160 // Register the prefs for the content settings providers. | 116 // Register the prefs for the content settings providers. |
161 content_settings::DefaultProvider::RegisterProfilePrefs(registry); | 117 content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
162 content_settings::PrefProvider::RegisterProfilePrefs(registry); | 118 content_settings::PrefProvider::RegisterProfilePrefs(registry); |
163 content_settings::PolicyProvider::RegisterProfilePrefs(registry); | 119 content_settings::PolicyProvider::RegisterProfilePrefs(registry); |
164 } | 120 } |
165 | 121 |
| 122 void HostContentSettingsMap::RegisterProvider( |
| 123 ProviderType type, |
| 124 scoped_ptr<content_settings::ObservableProvider> provider) { |
| 125 DCHECK(!content_settings_providers_[type]); |
| 126 provider->AddObserver(this); |
| 127 content_settings_providers_[type] = provider.release(); |
| 128 |
| 129 #ifndef NDEBUG |
| 130 DCHECK_NE(used_from_thread_id_, base::kInvalidThreadId) |
| 131 << "Used from multiple threads before initialization complete."; |
| 132 #endif |
| 133 |
| 134 OnContentSettingChanged(ContentSettingsPattern(), |
| 135 ContentSettingsPattern(), |
| 136 CONTENT_SETTINGS_TYPE_DEFAULT, |
| 137 std::string()); |
| 138 } |
| 139 |
166 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( | 140 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( |
167 ContentSettingsType content_type, | 141 ContentSettingsType content_type, |
168 content_settings::ProviderInterface* provider) const { | 142 content_settings::ProviderInterface* provider) const { |
169 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 143 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
170 provider->GetRuleIterator(content_type, std::string(), false)); | 144 provider->GetRuleIterator(content_type, std::string(), false)); |
171 | 145 |
172 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 146 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
173 while (rule_iterator->HasNext()) { | 147 while (rule_iterator->HasNext()) { |
174 content_settings::Rule rule = rule_iterator->Next(); | 148 content_settings::Rule rule = rule_iterator->Next(); |
175 if (rule.primary_pattern == wildcard && | 149 if (rule.primary_pattern == wildcard && |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 } | 726 } |
753 | 727 |
754 NOTREACHED(); | 728 NOTREACHED(); |
755 return DEFAULT_PROVIDER; | 729 return DEFAULT_PROVIDER; |
756 } | 730 } |
757 | 731 |
758 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { | 732 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { |
759 return static_cast<content_settings::PrefProvider*>( | 733 return static_cast<content_settings::PrefProvider*>( |
760 content_settings_providers_[PREF_PROVIDER]); | 734 content_settings_providers_[PREF_PROVIDER]); |
761 } | 735 } |
OLD | NEW |