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
3 // found in the LICENSE file.
5 #include "chrome/browser/content_settings/host_content_settings_map.h"
9 #include "base/basictypes.h"
10 #include "base/command_line.h"
11 #include "base/prefs/pref_service.h"
12 #include "base/stl_util.h"
13 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.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_provider.h"
18 #include "chrome/browser/content_settings/content_settings_default_provider.h"
19 #include "chrome/browser/content_settings/content_settings_details.h"
20 #include "chrome/browser/content_settings/content_settings_internal_extension_provider.h"
21 #include "chrome/browser/content_settings/content_settings_observable_provider.h"
22 #include "chrome/browser/content_settings/content_settings_policy_provider.h"
23 #include "chrome/browser/content_settings/content_settings_pref_provider.h"
24 #include "chrome/browser/content_settings/content_settings_provider.h"
25 #include "chrome/browser/content_settings/content_settings_rule.h"
26 #include "chrome/browser/content_settings/content_settings_utils.h"
27 #include "chrome/browser/extensions/api/content_settings/content_settings_service.h"
28 #include "chrome/browser/extensions/extension_service.h"
29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/content_settings_pattern.h"
31 #include "chrome/common/pref_names.h"
32 #include "chrome/common/url_constants.h"
33 #include "components/pref_registry/pref_registry_syncable.h"
34 #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"
39 #include "extensions/browser/extension_prefs.h"
40 #include "extensions/common/constants.h"
41 #include "net/base/net_errors.h"
42 #include "net/base/static_cookie_policy.h"
45 using base::UserMetricsAction;
46 using content::BrowserThread;
50 typedef std::vector<content_settings::Rule> Rules;
52 typedef std::pair<std::string, std::string> StringPair;
54 // TODO(bauerb): Expose constants.
55 const char* kProviderNames[] = {
63 content_settings::SettingSource kProviderSourceMap[] = {
64 content_settings::SETTING_SOURCE_EXTENSION,
65 content_settings::SETTING_SOURCE_POLICY,
66 content_settings::SETTING_SOURCE_EXTENSION,
67 content_settings::SETTING_SOURCE_USER,
68 content_settings::SETTING_SOURCE_USER,
70 COMPILE_ASSERT(arraysize(kProviderSourceMap) ==
71 HostContentSettingsMap::NUM_PROVIDER_TYPES,
72 kProviderSourceMap_has_incorrect_size);
74 // Returns true if the |content_type| supports a resource identifier.
75 // Resource identifiers are supported (but not required) for plug-ins.
76 bool SupportsResourceIdentifier(ContentSettingsType content_type) {
77 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS;
82 HostContentSettingsMap::HostContentSettingsMap(
86 used_from_thread_id_(base::PlatformThread::CurrentId()),
89 is_off_the_record_(incognito) {
90 content_settings::ObservableProvider* policy_provider =
91 new content_settings::PolicyProvider(prefs_);
92 policy_provider->AddObserver(this);
93 content_settings_providers_[POLICY_PROVIDER] = policy_provider;
95 content_settings::ObservableProvider* pref_provider =
96 new content_settings::PrefProvider(prefs_, is_off_the_record_);
97 pref_provider->AddObserver(this);
98 content_settings_providers_[PREF_PROVIDER] = pref_provider;
100 content_settings::ObservableProvider* default_provider =
101 new content_settings::DefaultProvider(prefs_, is_off_the_record_);
102 default_provider->AddObserver(this);
103 content_settings_providers_[DEFAULT_PROVIDER] = default_provider;
105 if (!is_off_the_record_) {
106 // Migrate obsolete preferences.
107 MigrateObsoleteClearOnExitPref();
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]);
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;
124 content_settings::ObservableProvider* custom_extension_provider =
125 new content_settings::CustomExtensionProvider(
126 extensions::ContentSettingsService::Get(
127 extension_service->GetBrowserContext())->content_settings_store(),
129 custom_extension_provider->AddObserver(this);
130 content_settings_providers_[CUSTOM_EXTENSION_PROVIDER] =
131 custom_extension_provider;
134 DCHECK(used_from_thread_id_ != base::kInvalidThreadId)
135 << "Used from multiple threads before initialization complete.";
138 OnContentSettingChanged(ContentSettingsPattern(),
139 ContentSettingsPattern(),
140 CONTENT_SETTINGS_TYPE_DEFAULT,
146 void HostContentSettingsMap::RegisterProfilePrefs(
147 user_prefs::PrefRegistrySyncable* registry) {
148 registry->RegisterIntegerPref(
149 prefs::kContentSettingsWindowLastTabIndex,
151 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
152 registry->RegisterIntegerPref(
153 prefs::kContentSettingsDefaultWhitelistVersion,
155 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
156 registry->RegisterBooleanPref(
157 prefs::kContentSettingsClearOnExitMigrated,
159 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
161 // Register the prefs for the content settings providers.
162 content_settings::DefaultProvider::RegisterProfilePrefs(registry);
163 content_settings::PrefProvider::RegisterProfilePrefs(registry);
164 content_settings::PolicyProvider::RegisterProfilePrefs(registry);
167 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider(
168 ContentSettingsType content_type,
169 content_settings::ProviderInterface* provider) const {
170 scoped_ptr<content_settings::RuleIterator> rule_iterator(
171 provider->GetRuleIterator(content_type, std::string(), false));
173 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard();
174 while (rule_iterator->HasNext()) {
175 content_settings::Rule rule = rule_iterator->Next();
176 if (rule.primary_pattern == wildcard &&
177 rule.secondary_pattern == wildcard) {
178 return content_settings::ValueToContentSetting(rule.value.get());
181 return CONTENT_SETTING_DEFAULT;
184 ContentSetting HostContentSettingsMap::GetDefaultContentSetting(
185 ContentSettingsType content_type,
186 std::string* provider_id) const {
187 UsedContentSettingsProviders();
189 // Iterate through the list of providers and return the first non-NULL value
190 // that matches |primary_url| and |secondary_url|.
191 for (ConstProviderIterator provider = content_settings_providers_.begin();
192 provider != content_settings_providers_.end();
194 if (provider->first == PREF_PROVIDER)
196 ContentSetting default_setting =
197 GetDefaultContentSettingFromProvider(content_type, provider->second);
198 if (default_setting != CONTENT_SETTING_DEFAULT) {
200 *provider_id = kProviderNames[provider->first];
201 return default_setting;
205 // The method GetDefaultContentSetting always has to return an explicit
206 // value that is to be used as default. We here rely on the
207 // DefaultProvider to always provide a value.
209 return CONTENT_SETTING_DEFAULT;
212 ContentSetting HostContentSettingsMap::GetContentSetting(
213 const GURL& primary_url,
214 const GURL& secondary_url,
215 ContentSettingsType content_type,
216 const std::string& resource_identifier) const {
217 DCHECK(!ContentTypeHasCompoundValue(content_type));
218 scoped_ptr<base::Value> value(GetWebsiteSetting(
219 primary_url, secondary_url, content_type, resource_identifier, NULL));
220 return content_settings::ValueToContentSetting(value.get());
223 void HostContentSettingsMap::GetSettingsForOneType(
224 ContentSettingsType content_type,
225 const std::string& resource_identifier,
226 ContentSettingsForOneType* settings) const {
227 DCHECK(SupportsResourceIdentifier(content_type) ||
228 resource_identifier.empty());
230 UsedContentSettingsProviders();
233 for (ConstProviderIterator provider = content_settings_providers_.begin();
234 provider != content_settings_providers_.end();
236 // For each provider, iterate first the incognito-specific rules, then the
238 if (is_off_the_record_) {
239 AddSettingsForOneType(provider->second,
246 AddSettingsForOneType(provider->second,
255 void HostContentSettingsMap::SetDefaultContentSetting(
256 ContentSettingsType content_type,
257 ContentSetting setting) {
258 DCHECK(IsSettingAllowedForType(prefs_, setting, content_type));
260 base::Value* value = NULL;
261 if (setting != CONTENT_SETTING_DEFAULT)
262 value = new base::FundamentalValue(setting);
264 ContentSettingsPattern::Wildcard(),
265 ContentSettingsPattern::Wildcard(),
271 void HostContentSettingsMap::SetWebsiteSetting(
272 const ContentSettingsPattern& primary_pattern,
273 const ContentSettingsPattern& secondary_pattern,
274 ContentSettingsType content_type,
275 const std::string& resource_identifier,
276 base::Value* value) {
277 DCHECK(IsValueAllowedForType(prefs_, value, content_type));
278 DCHECK(SupportsResourceIdentifier(content_type) ||
279 resource_identifier.empty());
280 UsedContentSettingsProviders();
282 for (ProviderIterator provider = content_settings_providers_.begin();
283 provider != content_settings_providers_.end();
285 if (provider->second->SetWebsiteSetting(primary_pattern,
296 void HostContentSettingsMap::SetContentSetting(
297 const ContentSettingsPattern& primary_pattern,
298 const ContentSettingsPattern& secondary_pattern,
299 ContentSettingsType content_type,
300 const std::string& resource_identifier,
301 ContentSetting setting) {
302 DCHECK(!ContentTypeHasCompoundValue(content_type));
304 if (setting == CONTENT_SETTING_ALLOW &&
305 (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION ||
306 content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS)) {
307 UpdateLastUsageByPattern(primary_pattern, secondary_pattern, content_type);
310 base::Value* value = NULL;
311 if (setting != CONTENT_SETTING_DEFAULT)
312 value = new base::FundamentalValue(setting);
313 SetWebsiteSetting(primary_pattern,
320 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage(
321 const GURL& primary_url,
322 const GURL& secondary_url,
323 ContentSettingsType content_type,
324 const std::string& resource_identifier) {
325 DCHECK_CURRENTLY_ON(BrowserThread::UI);
327 ContentSetting setting = GetContentSetting(
328 primary_url, secondary_url, content_type, resource_identifier);
329 if (setting == CONTENT_SETTING_ALLOW) {
330 UpdateLastUsageByPattern(
331 ContentSettingsPattern::FromURLNoWildcard(primary_url),
332 ContentSettingsPattern::FromURLNoWildcard(secondary_url),
338 void HostContentSettingsMap::UpdateLastUsage(const GURL& primary_url,
339 const GURL& secondary_url,
340 ContentSettingsType content_type) {
341 UpdateLastUsageByPattern(
342 ContentSettingsPattern::FromURLNoWildcard(primary_url),
343 ContentSettingsPattern::FromURLNoWildcard(secondary_url),
347 void HostContentSettingsMap::UpdateLastUsageByPattern(
348 const ContentSettingsPattern& primary_pattern,
349 const ContentSettingsPattern& secondary_pattern,
350 ContentSettingsType content_type) {
351 UsedContentSettingsProviders();
353 GetPrefProvider()->UpdateLastUsage(
354 primary_pattern, secondary_pattern, content_type);
357 base::Time HostContentSettingsMap::GetLastUsage(
358 const GURL& primary_url,
359 const GURL& secondary_url,
360 ContentSettingsType content_type) {
361 return GetLastUsageByPattern(
362 ContentSettingsPattern::FromURLNoWildcard(primary_url),
363 ContentSettingsPattern::FromURLNoWildcard(secondary_url),
367 base::Time HostContentSettingsMap::GetLastUsageByPattern(
368 const ContentSettingsPattern& primary_pattern,
369 const ContentSettingsPattern& secondary_pattern,
370 ContentSettingsType content_type) {
371 UsedContentSettingsProviders();
373 return GetPrefProvider()->GetLastUsage(
374 primary_pattern, secondary_pattern, content_type);
377 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) {
378 observers_.AddObserver(observer);
381 void HostContentSettingsMap::RemoveObserver(
382 content_settings::Observer* observer) {
383 observers_.RemoveObserver(observer);
386 void HostContentSettingsMap::SetPrefClockForTesting(
387 scoped_ptr<base::Clock> clock) {
388 UsedContentSettingsProviders();
390 GetPrefProvider()->SetClockForTesting(clock.Pass());
393 void HostContentSettingsMap::AddExceptionForURL(
394 const GURL& primary_url,
395 const GURL& secondary_url,
396 ContentSettingsType content_type,
397 ContentSetting setting) {
398 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must
400 DCHECK(primary_url == secondary_url);
401 DCHECK(!ContentTypeHasCompoundValue(content_type));
403 // Make sure there is no entry that would override the pattern we are about
404 // to insert for exactly this URL.
405 SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(primary_url),
406 ContentSettingsPattern::Wildcard(),
409 CONTENT_SETTING_DEFAULT);
411 SetContentSetting(ContentSettingsPattern::FromURL(primary_url),
412 ContentSettingsPattern::Wildcard(),
418 void HostContentSettingsMap::ClearSettingsForOneType(
419 ContentSettingsType content_type) {
420 UsedContentSettingsProviders();
421 for (ProviderIterator provider = content_settings_providers_.begin();
422 provider != content_settings_providers_.end();
424 provider->second->ClearAllContentSettingsRules(content_type);
428 bool HostContentSettingsMap::IsValueAllowedForType(
429 PrefService* prefs, const base::Value* value, ContentSettingsType type) {
430 return ContentTypeHasCompoundValue(type) || IsSettingAllowedForType(
431 prefs, content_settings::ValueToContentSetting(value), type);
435 bool HostContentSettingsMap::IsSettingAllowedForType(
437 ContentSetting setting,
438 ContentSettingsType content_type) {
439 // We don't yet support stored content settings for mixed scripting.
440 if (content_type == CONTENT_SETTINGS_TYPE_MIXEDSCRIPT)
443 // BLOCK semantics are not implemented for fullscreen.
444 if (content_type == CONTENT_SETTINGS_TYPE_FULLSCREEN &&
445 setting == CONTENT_SETTING_BLOCK) {
449 // We don't support ALLOW for media default setting.
450 if (content_type == CONTENT_SETTINGS_TYPE_MEDIASTREAM &&
451 setting == CONTENT_SETTING_ALLOW) {
455 #if defined(OS_ANDROID)
456 // App banners store a dictionary.
457 if (content_type == CONTENT_SETTINGS_TYPE_APP_BANNER)
461 // DEFAULT, ALLOW and BLOCK are always allowed.
462 if (setting == CONTENT_SETTING_DEFAULT ||
463 setting == CONTENT_SETTING_ALLOW ||
464 setting == CONTENT_SETTING_BLOCK) {
467 switch (content_type) {
468 case CONTENT_SETTINGS_TYPE_COOKIES:
469 return setting == CONTENT_SETTING_SESSION_ONLY;
470 case CONTENT_SETTINGS_TYPE_PLUGINS:
471 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
472 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
473 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
474 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
475 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
476 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
477 case CONTENT_SETTINGS_TYPE_PPAPI_BROKER:
478 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
479 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
480 return setting == CONTENT_SETTING_ASK;
487 bool HostContentSettingsMap::ContentTypeHasCompoundValue(
488 ContentSettingsType type) {
489 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE,
490 // CONTENT_SETTINGS_TYPE_MEDIASTREAM, and
491 // CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS are of type dictionary/map.
492 // Compound types like dictionaries can't be mapped to the type
494 #if defined(OS_ANDROID)
495 if (type == CONTENT_SETTINGS_TYPE_APP_BANNER)
499 return (type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE ||
500 type == CONTENT_SETTINGS_TYPE_MEDIASTREAM ||
501 type == CONTENT_SETTINGS_TYPE_SSL_CERT_DECISIONS);
504 void HostContentSettingsMap::OnContentSettingChanged(
505 const ContentSettingsPattern& primary_pattern,
506 const ContentSettingsPattern& secondary_pattern,
507 ContentSettingsType content_type,
508 std::string resource_identifier) {
509 const ContentSettingsDetails details(primary_pattern,
512 resource_identifier);
513 // TODO(dhnishi): Remove usage of this notification.
514 content::NotificationService::current()->Notify(
515 chrome::NOTIFICATION_CONTENT_SETTINGS_CHANGED,
516 content::Source<HostContentSettingsMap>(this),
517 content::Details<const ContentSettingsDetails>(&details));
519 FOR_EACH_OBSERVER(content_settings::Observer,
521 OnContentSettingChanged(primary_pattern,
524 resource_identifier));
527 HostContentSettingsMap::~HostContentSettingsMap() {
529 STLDeleteValues(&content_settings_providers_);
532 void HostContentSettingsMap::ShutdownOnUIThread() {
533 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
536 for (ProviderIterator it = content_settings_providers_.begin();
537 it != content_settings_providers_.end();
539 it->second->ShutdownOnUIThread();
543 void HostContentSettingsMap::MigrateObsoleteClearOnExitPref() {
544 // Don't migrate more than once.
545 if (prefs_->HasPrefPath(prefs::kContentSettingsClearOnExitMigrated) &&
546 prefs_->GetBoolean(prefs::kContentSettingsClearOnExitMigrated)) {
550 if (!prefs_->GetBoolean(prefs::kClearSiteDataOnExit)) {
551 // Nothing to be done
552 prefs_->SetBoolean(prefs::kContentSettingsClearOnExitMigrated, true);
556 // Change the default cookie settings:
558 // ---------------- ----------------
559 // ALLOW SESSION_ONLY
560 // SESSION_ONLY SESSION_ONLY
562 ContentSetting default_setting = GetDefaultContentSettingFromProvider(
563 CONTENT_SETTINGS_TYPE_COOKIES,
564 content_settings_providers_[DEFAULT_PROVIDER]);
565 if (default_setting == CONTENT_SETTING_ALLOW) {
566 SetDefaultContentSetting(
567 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_SESSION_ONLY);
570 // Change the exceptions using the same rules.
571 ContentSettingsForOneType exceptions;
572 AddSettingsForOneType(content_settings_providers_[PREF_PROVIDER],
574 CONTENT_SETTINGS_TYPE_COOKIES,
578 for (ContentSettingsForOneType::iterator it = exceptions.begin();
579 it != exceptions.end(); ++it) {
580 if (it->setting != CONTENT_SETTING_ALLOW)
582 SetWebsiteSetting(it->primary_pattern,
583 it->secondary_pattern,
584 CONTENT_SETTINGS_TYPE_COOKIES,
586 new base::FundamentalValue(CONTENT_SETTING_SESSION_ONLY));
589 prefs_->SetBoolean(prefs::kContentSettingsClearOnExitMigrated, true);
592 void HostContentSettingsMap::AddSettingsForOneType(
593 const content_settings::ProviderInterface* provider,
594 ProviderType provider_type,
595 ContentSettingsType content_type,
596 const std::string& resource_identifier,
597 ContentSettingsForOneType* settings,
598 bool incognito) const {
599 scoped_ptr<content_settings::RuleIterator> rule_iterator(
600 provider->GetRuleIterator(content_type,
603 while (rule_iterator->HasNext()) {
604 const content_settings::Rule& rule = rule_iterator->Next();
605 ContentSetting setting_value = CONTENT_SETTING_DEFAULT;
606 // TODO(bauerb): Return rules as a list of values, not content settings.
607 // Handle the case using compound values for its exceptions and arbitrary
608 // values for its default setting. Here we assume all the exceptions
609 // are granted as |CONTENT_SETTING_ALLOW|.
610 if (ContentTypeHasCompoundValue(content_type) &&
612 rule.primary_pattern != ContentSettingsPattern::Wildcard()) {
613 setting_value = CONTENT_SETTING_ALLOW;
615 setting_value = content_settings::ValueToContentSetting(rule.value.get());
617 settings->push_back(ContentSettingPatternSource(
618 rule.primary_pattern, rule.secondary_pattern,
620 kProviderNames[provider_type],
625 void HostContentSettingsMap::UsedContentSettingsProviders() const {
627 if (used_from_thread_id_ == base::kInvalidThreadId)
630 if (base::PlatformThread::CurrentId() != used_from_thread_id_)
631 used_from_thread_id_ = base::kInvalidThreadId;
635 bool HostContentSettingsMap::ShouldAllowAllContent(
636 const GURL& primary_url,
637 const GURL& secondary_url,
638 ContentSettingsType content_type) {
639 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS ||
640 content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION ||
641 content_type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
644 #if defined(OS_ANDROID) || defined(OS_CHROMEOS)
645 if (content_type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) {
649 if (secondary_url.SchemeIs(content::kChromeUIScheme) &&
650 content_type == CONTENT_SETTINGS_TYPE_COOKIES &&
651 primary_url.SchemeIsSecure()) {
654 if (primary_url.SchemeIs(extensions::kExtensionScheme)) {
655 switch (content_type) {
656 case CONTENT_SETTINGS_TYPE_PLUGINS:
657 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
658 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC:
659 case CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA:
661 case CONTENT_SETTINGS_TYPE_COOKIES:
662 return secondary_url.SchemeIs(extensions::kExtensionScheme);
667 return primary_url.SchemeIs(content::kChromeDevToolsScheme) ||
668 primary_url.SchemeIs(content::kChromeUIScheme);
671 base::Value* HostContentSettingsMap::GetWebsiteSetting(
672 const GURL& primary_url,
673 const GURL& secondary_url,
674 ContentSettingsType content_type,
675 const std::string& resource_identifier,
676 content_settings::SettingInfo* info) const {
677 DCHECK(SupportsResourceIdentifier(content_type) ||
678 resource_identifier.empty());
680 // Check if the scheme of the requesting url is whitelisted.
681 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) {
683 info->source = content_settings::SETTING_SOURCE_WHITELIST;
684 info->primary_pattern = ContentSettingsPattern::Wildcard();
685 info->secondary_pattern = ContentSettingsPattern::Wildcard();
687 return new base::FundamentalValue(CONTENT_SETTING_ALLOW);
690 ContentSettingsPattern* primary_pattern = NULL;
691 ContentSettingsPattern* secondary_pattern = NULL;
693 primary_pattern = &info->primary_pattern;
694 secondary_pattern = &info->secondary_pattern;
697 // The list of |content_settings_providers_| is ordered according to their
699 for (ConstProviderIterator provider = content_settings_providers_.begin();
700 provider != content_settings_providers_.end();
702 base::Value* value = content_settings::GetContentSettingValueAndPatterns(
703 provider->second, primary_url, secondary_url, content_type,
704 resource_identifier, is_off_the_record_,
705 primary_pattern, secondary_pattern);
708 info->source = kProviderSourceMap[provider->first];
714 info->source = content_settings::SETTING_SOURCE_NONE;
715 info->primary_pattern = ContentSettingsPattern();
716 info->secondary_pattern = ContentSettingsPattern();
722 HostContentSettingsMap::ProviderType
723 HostContentSettingsMap::GetProviderTypeFromSource(
724 const std::string& source) {
725 for (size_t i = 0; i < arraysize(kProviderNames); ++i) {
726 if (source == kProviderNames[i])
727 return static_cast<ProviderType>(i);
731 return DEFAULT_PROVIDER;
734 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() {
735 return static_cast<content_settings::PrefProvider*>(
736 content_settings_providers_[PREF_PROVIDER]);