Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.cc

Issue 545413002: Detach the dependency from host_content_settings_map to extension. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove ProviderType Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
54
55 typedef std::pair<std::string, std::string> StringPair;
56
57 // TODO(bauerb): Expose constants.
58 const char* kProviderNames[] = {
59 "platform_app",
60 "policy",
61 "extension",
62 "preference",
63 "default"
64 };
65
66 content_settings::SettingSource kProviderSourceMap[] = {
67 content_settings::SETTING_SOURCE_EXTENSION,
68 content_settings::SETTING_SOURCE_POLICY,
69 content_settings::SETTING_SOURCE_EXTENSION,
70 content_settings::SETTING_SOURCE_USER,
71 content_settings::SETTING_SOURCE_USER,
72 };
73 COMPILE_ASSERT(arraysize(kProviderSourceMap) ==
74 HostContentSettingsMap::NUM_PROVIDER_TYPES,
75 kProviderSourceMap_has_incorrect_size);
76
77 // Returns true if the |content_type| supports a resource identifier. 43 // Returns true if the |content_type| supports a resource identifier.
78 // Resource identifiers are supported (but not required) for plug-ins. 44 // Resource identifiers are supported (but not required) for plug-ins.
79 bool SupportsResourceIdentifier(ContentSettingsType content_type) { 45 bool SupportsResourceIdentifier(ContentSettingsType content_type) {
80 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; 46 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
81 } 47 }
82 48
83 } // namespace 49 } // namespace
84 50
85 HostContentSettingsMap::HostContentSettingsMap( 51 HostContentSettingsMap::HostContentSettingsMap(
86 PrefService* prefs, 52 PrefService* prefs,
87 bool incognito) : 53 bool incognito) :
88 #ifndef NDEBUG 54 #ifndef NDEBUG
89 used_from_thread_id_(base::PlatformThread::CurrentId()), 55 used_from_thread_id_(base::PlatformThread::CurrentId()),
90 #endif 56 #endif
91 prefs_(prefs), 57 prefs_(prefs),
92 is_off_the_record_(incognito) { 58 is_off_the_record_(incognito) {
93 content_settings::ObservableProvider* policy_provider = 59 content_settings::ObservableProvider* policy_provider =
94 new content_settings::PolicyProvider(prefs_); 60 new content_settings::PolicyProvider(prefs_);
95 policy_provider->AddObserver(this); 61 policy_provider->AddObserver(this);
96 content_settings_providers_[POLICY_PROVIDER] = policy_provider; 62 content_settings_providers_.push_back(policy_provider);
97 63
98 content_settings::ObservableProvider* pref_provider = 64 pref_provider_ =
99 new content_settings::PrefProvider(prefs_, is_off_the_record_); 65 new content_settings::PrefProvider(prefs_, is_off_the_record_);
100 pref_provider->AddObserver(this); 66 pref_provider_->AddObserver(this);
101 content_settings_providers_[PREF_PROVIDER] = pref_provider; 67 content_settings_providers_.push_back(pref_provider_);
102 68
103 content_settings::ObservableProvider* default_provider = 69 default_provider_ =
104 new content_settings::DefaultProvider(prefs_, is_off_the_record_); 70 new content_settings::DefaultProvider(prefs_, is_off_the_record_);
105 default_provider->AddObserver(this); 71 default_provider_->AddObserver(this);
106 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; 72 content_settings_providers_.push_back(default_provider_);
107 73
108 if (!is_off_the_record_) { 74 if (!is_off_the_record_) {
109 // Migrate obsolete preferences. 75 // Migrate obsolete preferences.
110 MigrateObsoleteClearOnExitPref(); 76 MigrateObsoleteClearOnExitPref();
111 } 77 }
112 } 78 }
113 79
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 80 // static
149 void HostContentSettingsMap::RegisterProfilePrefs( 81 void HostContentSettingsMap::RegisterProfilePrefs(
150 user_prefs::PrefRegistrySyncable* registry) { 82 user_prefs::PrefRegistrySyncable* registry) {
151 registry->RegisterIntegerPref( 83 registry->RegisterIntegerPref(
152 prefs::kContentSettingsWindowLastTabIndex, 84 prefs::kContentSettingsWindowLastTabIndex,
153 0, 85 0,
154 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 86 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
155 registry->RegisterBooleanPref( 87 registry->RegisterBooleanPref(
156 prefs::kContentSettingsClearOnExitMigrated, 88 prefs::kContentSettingsClearOnExitMigrated,
157 false, 89 false,
158 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 90 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
159 91
160 // Register the prefs for the content settings providers. 92 // Register the prefs for the content settings providers.
161 content_settings::DefaultProvider::RegisterProfilePrefs(registry); 93 content_settings::DefaultProvider::RegisterProfilePrefs(registry);
162 content_settings::PrefProvider::RegisterProfilePrefs(registry); 94 content_settings::PrefProvider::RegisterProfilePrefs(registry);
163 content_settings::PolicyProvider::RegisterProfilePrefs(registry); 95 content_settings::PolicyProvider::RegisterProfilePrefs(registry);
164 } 96 }
165 97
98 void HostContentSettingsMap::RegisterProvider(
99 scoped_ptr<content_settings::ObservableProvider> provider) {
100 provider->AddObserver(this);
101 content_settings_providers_.push_back(provider.release());
102
103 #ifndef NDEBUG
104 DCHECK_NE(used_from_thread_id_, base::kInvalidThreadId)
105 << "Used from multiple threads before initialization complete.";
106 #endif
107
108 OnContentSettingChanged(ContentSettingsPattern(),
109 ContentSettingsPattern(),
110 CONTENT_SETTINGS_TYPE_DEFAULT,
111 std::string());
112 }
113
114 size_t HostContentSettingsMap::GetNumProviders() const {
115 return content_settings_providers_.size();
116 }
117
118 const content_settings::ProviderInterface*
119 HostContentSettingsMap::GetProviderAt(
Bernhard Bauer 2014/09/12 09:07:25 The parameter should fit on this line, no?
120 size_t i) const {
121 return content_settings_providers_[i];
122 }
123
166 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( 124 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider(
167 ContentSettingsType content_type, 125 ContentSettingsType content_type,
168 content_settings::ProviderInterface* provider) const { 126 content_settings::ProviderInterface* provider) const {
169 scoped_ptr<content_settings::RuleIterator> rule_iterator( 127 scoped_ptr<content_settings::RuleIterator> rule_iterator(
170 provider->GetRuleIterator(content_type, std::string(), false)); 128 provider->GetRuleIterator(content_type, std::string(), false));
171 129
172 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); 130 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
173 while (rule_iterator->HasNext()) { 131 while (rule_iterator->HasNext()) {
174 content_settings::Rule rule = rule_iterator->Next(); 132 content_settings::Rule rule = rule_iterator->Next();
175 if (rule.primary_pattern == wildcard && 133 if (rule.primary_pattern == wildcard &&
176 rule.secondary_pattern == wildcard) { 134 rule.secondary_pattern == wildcard) {
177 return content_settings::ValueToContentSetting(rule.value.get()); 135 return content_settings::ValueToContentSetting(rule.value.get());
178 } 136 }
179 } 137 }
180 return CONTENT_SETTING_DEFAULT; 138 return CONTENT_SETTING_DEFAULT;
181 } 139 }
182 140
183 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( 141 ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
184 ContentSettingsType content_type, 142 ContentSettingsType content_type,
185 std::string* provider_id) const { 143 std::string* provider_id) const {
186 UsedContentSettingsProviders(); 144 UsedContentSettingsProviders();
187 145
188 // Iterate through the list of providers and return the first non-NULL value 146 // Iterate through the list of providers and return the first non-NULL value
189 // that matches |primary_url| and |secondary_url|. 147 // that matches |primary_url| and |secondary_url|.
190 for (ConstProviderIterator provider = content_settings_providers_.begin(); 148 for (ConstProviderIterator provider = content_settings_providers_.begin();
191 provider != content_settings_providers_.end(); 149 provider != content_settings_providers_.end();
192 ++provider) { 150 ++provider) {
193 if (provider->first == PREF_PROVIDER) 151 if (*provider == pref_provider_)
194 continue; 152 continue;
195 ContentSetting default_setting = 153 ContentSetting default_setting =
196 GetDefaultContentSettingFromProvider(content_type, provider->second); 154 GetDefaultContentSettingFromProvider(content_type, *provider);
197 if (default_setting != CONTENT_SETTING_DEFAULT) { 155 if (default_setting != CONTENT_SETTING_DEFAULT) {
198 if (provider_id) 156 if (provider_id)
199 *provider_id = kProviderNames[provider->first]; 157 *provider_id = (*provider)->GetProviderName();
200 return default_setting; 158 return default_setting;
201 } 159 }
202 } 160 }
203 161
204 // The method GetDefaultContentSetting always has to return an explicit 162 // The method GetDefaultContentSetting always has to return an explicit
205 // value that is to be used as default. We here rely on the 163 // value that is to be used as default. We here rely on the
206 // DefaultProvider to always provide a value. 164 // DefaultProvider to always provide a value.
207 NOTREACHED(); 165 NOTREACHED();
208 return CONTENT_SETTING_DEFAULT; 166 return CONTENT_SETTING_DEFAULT;
209 } 167 }
(...skipping 18 matching lines...) Expand all
228 DCHECK(settings); 186 DCHECK(settings);
229 UsedContentSettingsProviders(); 187 UsedContentSettingsProviders();
230 188
231 settings->clear(); 189 settings->clear();
232 for (ConstProviderIterator provider = content_settings_providers_.begin(); 190 for (ConstProviderIterator provider = content_settings_providers_.begin();
233 provider != content_settings_providers_.end(); 191 provider != content_settings_providers_.end();
234 ++provider) { 192 ++provider) {
235 // For each provider, iterate first the incognito-specific rules, then the 193 // For each provider, iterate first the incognito-specific rules, then the
236 // normal rules. 194 // normal rules.
237 if (is_off_the_record_) { 195 if (is_off_the_record_) {
238 AddSettingsForOneType(provider->second, 196 AddSettingsForOneType(*provider,
239 provider->first,
240 content_type, 197 content_type,
241 resource_identifier, 198 resource_identifier,
242 settings, 199 settings,
243 true); 200 true);
244 } 201 }
245 AddSettingsForOneType(provider->second, 202 AddSettingsForOneType(*provider,
246 provider->first,
247 content_type, 203 content_type,
248 resource_identifier, 204 resource_identifier,
249 settings, 205 settings,
250 false); 206 false);
251 } 207 }
252 } 208 }
253 209
254 void HostContentSettingsMap::SetDefaultContentSetting( 210 void HostContentSettingsMap::SetDefaultContentSetting(
255 ContentSettingsType content_type, 211 ContentSettingsType content_type,
256 ContentSetting setting) { 212 ContentSetting setting) {
(...skipping 17 matching lines...) Expand all
274 const std::string& resource_identifier, 230 const std::string& resource_identifier,
275 base::Value* value) { 231 base::Value* value) {
276 DCHECK(IsValueAllowedForType(prefs_, value, content_type)); 232 DCHECK(IsValueAllowedForType(prefs_, value, content_type));
277 DCHECK(SupportsResourceIdentifier(content_type) || 233 DCHECK(SupportsResourceIdentifier(content_type) ||
278 resource_identifier.empty()); 234 resource_identifier.empty());
279 UsedContentSettingsProviders(); 235 UsedContentSettingsProviders();
280 236
281 for (ProviderIterator provider = content_settings_providers_.begin(); 237 for (ProviderIterator provider = content_settings_providers_.begin();
282 provider != content_settings_providers_.end(); 238 provider != content_settings_providers_.end();
283 ++provider) { 239 ++provider) {
284 if (provider->second->SetWebsiteSetting(primary_pattern, 240 if ((*provider)->SetWebsiteSetting(primary_pattern,
285 secondary_pattern, 241 secondary_pattern,
286 content_type, 242 content_type,
287 resource_identifier, 243 resource_identifier,
288 value)) { 244 value)) {
289 return; 245 return;
290 } 246 }
291 } 247 }
292 NOTREACHED(); 248 NOTREACHED();
293 } 249 }
294 250
295 void HostContentSettingsMap::SetNarrowestWebsiteSetting( 251 void HostContentSettingsMap::SetNarrowestWebsiteSetting(
296 const ContentSettingsPattern& primary_pattern, 252 const ContentSettingsPattern& primary_pattern,
297 const ContentSettingsPattern& secondary_pattern, 253 const ContentSettingsPattern& secondary_pattern,
298 ContentSettingsType content_type, 254 ContentSettingsType content_type,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 ContentSettingsPattern::FromURLNoWildcard(secondary_url), 326 ContentSettingsPattern::FromURLNoWildcard(secondary_url),
371 content_type); 327 content_type);
372 } 328 }
373 329
374 void HostContentSettingsMap::UpdateLastUsageByPattern( 330 void HostContentSettingsMap::UpdateLastUsageByPattern(
375 const ContentSettingsPattern& primary_pattern, 331 const ContentSettingsPattern& primary_pattern,
376 const ContentSettingsPattern& secondary_pattern, 332 const ContentSettingsPattern& secondary_pattern,
377 ContentSettingsType content_type) { 333 ContentSettingsType content_type) {
378 UsedContentSettingsProviders(); 334 UsedContentSettingsProviders();
379 335
380 GetPrefProvider()->UpdateLastUsage( 336 pref_provider_->UpdateLastUsage(
381 primary_pattern, secondary_pattern, content_type); 337 primary_pattern, secondary_pattern, content_type);
382 338
383 FOR_EACH_OBSERVER( 339 FOR_EACH_OBSERVER(
384 content_settings::Observer, 340 content_settings::Observer,
385 observers_, 341 observers_,
386 OnContentSettingUsed(primary_pattern, secondary_pattern, content_type)); 342 OnContentSettingUsed(primary_pattern, secondary_pattern, content_type));
387 } 343 }
388 344
389 base::Time HostContentSettingsMap::GetLastUsage( 345 base::Time HostContentSettingsMap::GetLastUsage(
390 const GURL& primary_url, 346 const GURL& primary_url,
391 const GURL& secondary_url, 347 const GURL& secondary_url,
392 ContentSettingsType content_type) { 348 ContentSettingsType content_type) {
393 return GetLastUsageByPattern( 349 return GetLastUsageByPattern(
394 ContentSettingsPattern::FromURLNoWildcard(primary_url), 350 ContentSettingsPattern::FromURLNoWildcard(primary_url),
395 ContentSettingsPattern::FromURLNoWildcard(secondary_url), 351 ContentSettingsPattern::FromURLNoWildcard(secondary_url),
396 content_type); 352 content_type);
397 } 353 }
398 354
399 base::Time HostContentSettingsMap::GetLastUsageByPattern( 355 base::Time HostContentSettingsMap::GetLastUsageByPattern(
400 const ContentSettingsPattern& primary_pattern, 356 const ContentSettingsPattern& primary_pattern,
401 const ContentSettingsPattern& secondary_pattern, 357 const ContentSettingsPattern& secondary_pattern,
402 ContentSettingsType content_type) { 358 ContentSettingsType content_type) {
403 UsedContentSettingsProviders(); 359 UsedContentSettingsProviders();
404 360
405 return GetPrefProvider()->GetLastUsage( 361 return pref_provider_->GetLastUsage(
406 primary_pattern, secondary_pattern, content_type); 362 primary_pattern, secondary_pattern, content_type);
407 } 363 }
408 364
409 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) { 365 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) {
410 observers_.AddObserver(observer); 366 observers_.AddObserver(observer);
411 } 367 }
412 368
413 void HostContentSettingsMap::RemoveObserver( 369 void HostContentSettingsMap::RemoveObserver(
414 content_settings::Observer* observer) { 370 content_settings::Observer* observer) {
415 observers_.RemoveObserver(observer); 371 observers_.RemoveObserver(observer);
416 } 372 }
417 373
418 void HostContentSettingsMap::SetPrefClockForTesting( 374 void HostContentSettingsMap::SetPrefClockForTesting(
419 scoped_ptr<base::Clock> clock) { 375 scoped_ptr<base::Clock> clock) {
420 UsedContentSettingsProviders(); 376 UsedContentSettingsProviders();
421 377
422 GetPrefProvider()->SetClockForTesting(clock.Pass()); 378 pref_provider_->SetClockForTesting(clock.Pass());
423 } 379 }
424 380
425 void HostContentSettingsMap::AddExceptionForURL( 381 void HostContentSettingsMap::AddExceptionForURL(
426 const GURL& primary_url, 382 const GURL& primary_url,
427 const GURL& secondary_url, 383 const GURL& secondary_url,
428 ContentSettingsType content_type, 384 ContentSettingsType content_type,
429 ContentSetting setting) { 385 ContentSetting setting) {
430 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must 386 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must
431 // match. 387 // match.
432 DCHECK(primary_url == secondary_url); 388 DCHECK(primary_url == secondary_url);
(...skipping 13 matching lines...) Expand all
446 std::string(), 402 std::string(),
447 setting); 403 setting);
448 } 404 }
449 405
450 void HostContentSettingsMap::ClearSettingsForOneType( 406 void HostContentSettingsMap::ClearSettingsForOneType(
451 ContentSettingsType content_type) { 407 ContentSettingsType content_type) {
452 UsedContentSettingsProviders(); 408 UsedContentSettingsProviders();
453 for (ProviderIterator provider = content_settings_providers_.begin(); 409 for (ProviderIterator provider = content_settings_providers_.begin();
454 provider != content_settings_providers_.end(); 410 provider != content_settings_providers_.end();
455 ++provider) { 411 ++provider) {
456 provider->second->ClearAllContentSettingsRules(content_type); 412 (*provider)->ClearAllContentSettingsRules(content_type);
457 } 413 }
458 } 414 }
459 415
460 bool HostContentSettingsMap::IsValueAllowedForType( 416 bool HostContentSettingsMap::IsValueAllowedForType(
461 PrefService* prefs, const base::Value* value, ContentSettingsType type) { 417 PrefService* prefs, const base::Value* value, ContentSettingsType type) {
462 return ContentTypeHasCompoundValue(type) || IsSettingAllowedForType( 418 return ContentTypeHasCompoundValue(type) || IsSettingAllowedForType(
463 prefs, content_settings::ValueToContentSetting(value), type); 419 prefs, content_settings::ValueToContentSetting(value), type);
464 } 420 }
465 421
466 // static 422 // static
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 FOR_EACH_OBSERVER(content_settings::Observer, 497 FOR_EACH_OBSERVER(content_settings::Observer,
542 observers_, 498 observers_,
543 OnContentSettingChanged(primary_pattern, 499 OnContentSettingChanged(primary_pattern,
544 secondary_pattern, 500 secondary_pattern,
545 content_type, 501 content_type,
546 resource_identifier)); 502 resource_identifier));
547 } 503 }
548 504
549 HostContentSettingsMap::~HostContentSettingsMap() { 505 HostContentSettingsMap::~HostContentSettingsMap() {
550 DCHECK(!prefs_); 506 DCHECK(!prefs_);
551 STLDeleteValues(&content_settings_providers_);
552 } 507 }
553 508
554 void HostContentSettingsMap::ShutdownOnUIThread() { 509 void HostContentSettingsMap::ShutdownOnUIThread() {
555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
556 DCHECK(prefs_); 511 DCHECK(prefs_);
557 prefs_ = NULL; 512 prefs_ = NULL;
558 for (ProviderIterator it = content_settings_providers_.begin(); 513 for (ProviderIterator it = content_settings_providers_.begin();
559 it != content_settings_providers_.end(); 514 it != content_settings_providers_.end();
560 ++it) { 515 ++it) {
561 it->second->ShutdownOnUIThread(); 516 (*it)->ShutdownOnUIThread();
562 } 517 }
563 } 518 }
564 519
565 void HostContentSettingsMap::MigrateObsoleteClearOnExitPref() { 520 void HostContentSettingsMap::MigrateObsoleteClearOnExitPref() {
566 // Don't migrate more than once. 521 // Don't migrate more than once.
567 if (prefs_->HasPrefPath(prefs::kContentSettingsClearOnExitMigrated) && 522 if (prefs_->HasPrefPath(prefs::kContentSettingsClearOnExitMigrated) &&
568 prefs_->GetBoolean(prefs::kContentSettingsClearOnExitMigrated)) { 523 prefs_->GetBoolean(prefs::kContentSettingsClearOnExitMigrated)) {
569 return; 524 return;
570 } 525 }
571 526
572 if (!prefs_->GetBoolean(prefs::kClearSiteDataOnExit)) { 527 if (!prefs_->GetBoolean(prefs::kClearSiteDataOnExit)) {
573 // Nothing to be done 528 // Nothing to be done
574 prefs_->SetBoolean(prefs::kContentSettingsClearOnExitMigrated, true); 529 prefs_->SetBoolean(prefs::kContentSettingsClearOnExitMigrated, true);
575 return; 530 return;
576 } 531 }
577 532
578 // Change the default cookie settings: 533 // Change the default cookie settings:
579 // old new 534 // old new
580 // ---------------- ---------------- 535 // ---------------- ----------------
581 // ALLOW SESSION_ONLY 536 // ALLOW SESSION_ONLY
582 // SESSION_ONLY SESSION_ONLY 537 // SESSION_ONLY SESSION_ONLY
583 // BLOCK BLOCK 538 // BLOCK BLOCK
584 ContentSetting default_setting = GetDefaultContentSettingFromProvider( 539 ContentSetting default_setting = GetDefaultContentSettingFromProvider(
585 CONTENT_SETTINGS_TYPE_COOKIES, 540 CONTENT_SETTINGS_TYPE_COOKIES,
586 content_settings_providers_[DEFAULT_PROVIDER]); 541 default_provider_);
587 if (default_setting == CONTENT_SETTING_ALLOW) { 542 if (default_setting == CONTENT_SETTING_ALLOW) {
588 SetDefaultContentSetting( 543 SetDefaultContentSetting(
589 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_SESSION_ONLY); 544 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_SESSION_ONLY);
590 } 545 }
591 546
592 // Change the exceptions using the same rules. 547 // Change the exceptions using the same rules.
593 ContentSettingsForOneType exceptions; 548 ContentSettingsForOneType exceptions;
594 AddSettingsForOneType(content_settings_providers_[PREF_PROVIDER], 549 AddSettingsForOneType(pref_provider_,
595 PREF_PROVIDER,
596 CONTENT_SETTINGS_TYPE_COOKIES, 550 CONTENT_SETTINGS_TYPE_COOKIES,
597 std::string(), 551 std::string(),
598 &exceptions, 552 &exceptions,
599 false); 553 false);
600 for (ContentSettingsForOneType::iterator it = exceptions.begin(); 554 for (ContentSettingsForOneType::iterator it = exceptions.begin();
601 it != exceptions.end(); ++it) { 555 it != exceptions.end(); ++it) {
602 if (it->setting != CONTENT_SETTING_ALLOW) 556 if (it->setting != CONTENT_SETTING_ALLOW)
603 continue; 557 continue;
604 SetWebsiteSetting(it->primary_pattern, 558 SetWebsiteSetting(it->primary_pattern,
605 it->secondary_pattern, 559 it->secondary_pattern,
606 CONTENT_SETTINGS_TYPE_COOKIES, 560 CONTENT_SETTINGS_TYPE_COOKIES,
607 std::string(), 561 std::string(),
608 new base::FundamentalValue(CONTENT_SETTING_SESSION_ONLY)); 562 new base::FundamentalValue(CONTENT_SETTING_SESSION_ONLY));
609 } 563 }
610 564
611 prefs_->SetBoolean(prefs::kContentSettingsClearOnExitMigrated, true); 565 prefs_->SetBoolean(prefs::kContentSettingsClearOnExitMigrated, true);
612 } 566 }
613 567
614 void HostContentSettingsMap::AddSettingsForOneType( 568 void HostContentSettingsMap::AddSettingsForOneType(
615 const content_settings::ProviderInterface* provider, 569 const content_settings::ProviderInterface* provider,
616 ProviderType provider_type,
617 ContentSettingsType content_type, 570 ContentSettingsType content_type,
618 const std::string& resource_identifier, 571 const std::string& resource_identifier,
619 ContentSettingsForOneType* settings, 572 ContentSettingsForOneType* settings,
620 bool incognito) const { 573 bool incognito) const {
621 scoped_ptr<content_settings::RuleIterator> rule_iterator( 574 scoped_ptr<content_settings::RuleIterator> rule_iterator(
622 provider->GetRuleIterator(content_type, 575 provider->GetRuleIterator(content_type,
623 resource_identifier, 576 resource_identifier,
624 incognito)); 577 incognito));
625 while (rule_iterator->HasNext()) { 578 while (rule_iterator->HasNext()) {
626 const content_settings::Rule& rule = rule_iterator->Next(); 579 const content_settings::Rule& rule = rule_iterator->Next();
627 ContentSetting setting_value = CONTENT_SETTING_DEFAULT; 580 ContentSetting setting_value = CONTENT_SETTING_DEFAULT;
628 // TODO(bauerb): Return rules as a list of values, not content settings. 581 // TODO(bauerb): Return rules as a list of values, not content settings.
629 // Handle the case using compound values for its exceptions and arbitrary 582 // Handle the case using compound values for its exceptions and arbitrary
630 // values for its default setting. Here we assume all the exceptions 583 // values for its default setting. Here we assume all the exceptions
631 // are granted as |CONTENT_SETTING_ALLOW|. 584 // are granted as |CONTENT_SETTING_ALLOW|.
632 if (ContentTypeHasCompoundValue(content_type) && 585 if (ContentTypeHasCompoundValue(content_type) &&
633 rule.value.get() && 586 rule.value.get() &&
634 rule.primary_pattern != ContentSettingsPattern::Wildcard()) { 587 rule.primary_pattern != ContentSettingsPattern::Wildcard()) {
635 setting_value = CONTENT_SETTING_ALLOW; 588 setting_value = CONTENT_SETTING_ALLOW;
636 } else { 589 } else {
637 setting_value = content_settings::ValueToContentSetting(rule.value.get()); 590 setting_value = content_settings::ValueToContentSetting(rule.value.get());
638 } 591 }
639 settings->push_back(ContentSettingPatternSource( 592 settings->push_back(ContentSettingPatternSource(
640 rule.primary_pattern, rule.secondary_pattern, 593 rule.primary_pattern, rule.secondary_pattern,
641 setting_value, 594 setting_value,
642 kProviderNames[provider_type], 595 provider->GetProviderName(),
643 incognito)); 596 incognito));
644 } 597 }
645 } 598 }
646 599
647 void HostContentSettingsMap::UsedContentSettingsProviders() const { 600 void HostContentSettingsMap::UsedContentSettingsProviders() const {
648 #ifndef NDEBUG 601 #ifndef NDEBUG
649 if (used_from_thread_id_ == base::kInvalidThreadId) 602 if (used_from_thread_id_ == base::kInvalidThreadId)
650 return; 603 return;
651 604
652 if (base::PlatformThread::CurrentId() != used_from_thread_id_) 605 if (base::PlatformThread::CurrentId() != used_from_thread_id_)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 primary_pattern = &info->primary_pattern; 670 primary_pattern = &info->primary_pattern;
718 secondary_pattern = &info->secondary_pattern; 671 secondary_pattern = &info->secondary_pattern;
719 } 672 }
720 673
721 // The list of |content_settings_providers_| is ordered according to their 674 // The list of |content_settings_providers_| is ordered according to their
722 // precedence. 675 // precedence.
723 for (ConstProviderIterator provider = content_settings_providers_.begin(); 676 for (ConstProviderIterator provider = content_settings_providers_.begin();
724 provider != content_settings_providers_.end(); 677 provider != content_settings_providers_.end();
725 ++provider) { 678 ++provider) {
726 base::Value* value = content_settings::GetContentSettingValueAndPatterns( 679 base::Value* value = content_settings::GetContentSettingValueAndPatterns(
727 provider->second, primary_url, secondary_url, content_type, 680 *provider, primary_url, secondary_url, content_type,
728 resource_identifier, is_off_the_record_, 681 resource_identifier, is_off_the_record_,
729 primary_pattern, secondary_pattern); 682 primary_pattern, secondary_pattern);
730 if (value) { 683 if (value) {
731 if (info) 684 if (info)
732 info->source = kProviderSourceMap[provider->first]; 685 info->source = (*provider)->GetSettingSource();
733 return value; 686 return value;
734 } 687 }
735 } 688 }
736 689
737 if (info) { 690 if (info) {
738 info->source = content_settings::SETTING_SOURCE_NONE; 691 info->source = content_settings::SETTING_SOURCE_NONE;
739 info->primary_pattern = ContentSettingsPattern(); 692 info->primary_pattern = ContentSettingsPattern();
740 info->secondary_pattern = ContentSettingsPattern(); 693 info->secondary_pattern = ContentSettingsPattern();
741 } 694 }
742 return NULL; 695 return NULL;
743 } 696 }
744
745 // static
746 HostContentSettingsMap::ProviderType
747 HostContentSettingsMap::GetProviderTypeFromSource(
748 const std::string& source) {
749 for (size_t i = 0; i < arraysize(kProviderNames); ++i) {
750 if (source == kProviderNames[i])
751 return static_cast<ProviderType>(i);
752 }
753
754 NOTREACHED();
755 return DEFAULT_PROVIDER;
756 }
757
758 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() {
759 return static_cast<content_settings::PrefProvider*>(
760 content_settings_providers_[PREF_PROVIDER]);
761 }
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/host_content_settings_map.h ('k') | chrome/browser/extensions/extension_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698