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