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 "components/content_settings/core/browser/host_content_settings_map.h" | 5 #include "components/content_settings/core/browser/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" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 bool SupportsResourceIdentifier(ContentSettingsType content_type) { | 61 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
62 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 62 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
63 } | 63 } |
64 | 64 |
65 bool SchemeCanBeWhitelisted(const std::string& scheme) { | 65 bool SchemeCanBeWhitelisted(const std::string& scheme) { |
66 return scheme == content_settings::kChromeDevToolsScheme || | 66 return scheme == content_settings::kChromeDevToolsScheme || |
67 scheme == content_settings::kExtensionScheme || | 67 scheme == content_settings::kExtensionScheme || |
68 scheme == content_settings::kChromeUIScheme; | 68 scheme == content_settings::kChromeUIScheme; |
69 } | 69 } |
70 | 70 |
| 71 // Prevents content settings marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW from |
| 72 // inheriting CONTENT_SETTING_ALLOW settings from regular to incognito. |
| 73 scoped_ptr<base::Value> CoerceSettingInheritedToIncognito( |
| 74 ContentSettingsType content_type, |
| 75 scoped_ptr<base::Value> value) { |
| 76 const content_settings::ContentSettingsInfo* info = |
| 77 content_settings::ContentSettingsRegistry::GetInstance()->Get( |
| 78 content_type); |
| 79 if (!info) |
| 80 return value; |
| 81 if (info->incognito_behavior() != |
| 82 content_settings::ContentSettingsInfo::INHERIT_IN_INCOGNITO_EXCEPT_ALLOW) |
| 83 return value; |
| 84 ContentSetting setting = content_settings::ValueToContentSetting(value.get()); |
| 85 if (setting != CONTENT_SETTING_ALLOW) |
| 86 return value; |
| 87 DCHECK(info->IsSettingValid(CONTENT_SETTING_ASK)); |
| 88 return content_settings::ContentSettingToValue(CONTENT_SETTING_ASK); |
| 89 } |
| 90 |
71 } // namespace | 91 } // namespace |
72 | 92 |
73 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, | 93 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
74 bool incognito) | 94 bool incognito) |
75 : | 95 : |
76 #ifndef NDEBUG | 96 #ifndef NDEBUG |
77 used_from_thread_id_(base::PlatformThread::CurrentId()), | 97 used_from_thread_id_(base::PlatformThread::CurrentId()), |
78 #endif | 98 #endif |
79 prefs_(prefs), | 99 prefs_(prefs), |
80 is_off_the_record_(incognito) { | 100 is_off_the_record_(incognito) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 170 |
151 // Iterate through the list of providers and return the first non-NULL value | 171 // Iterate through the list of providers and return the first non-NULL value |
152 // that matches |primary_url| and |secondary_url|. | 172 // that matches |primary_url| and |secondary_url|. |
153 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 173 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
154 provider != content_settings_providers_.end(); | 174 provider != content_settings_providers_.end(); |
155 ++provider) { | 175 ++provider) { |
156 if (provider->first == PREF_PROVIDER) | 176 if (provider->first == PREF_PROVIDER) |
157 continue; | 177 continue; |
158 ContentSetting default_setting = | 178 ContentSetting default_setting = |
159 GetDefaultContentSettingFromProvider(content_type, provider->second); | 179 GetDefaultContentSettingFromProvider(content_type, provider->second); |
| 180 if (is_off_the_record_) { |
| 181 default_setting = content_settings::ValueToContentSetting( |
| 182 CoerceSettingInheritedToIncognito( |
| 183 content_type, |
| 184 content_settings::ContentSettingToValue(default_setting)).get()); |
| 185 } |
160 if (default_setting != CONTENT_SETTING_DEFAULT) { | 186 if (default_setting != CONTENT_SETTING_DEFAULT) { |
161 if (provider_id) | 187 if (provider_id) |
162 *provider_id = kProviderNamesSourceMap[provider->first].provider_name; | 188 *provider_id = kProviderNamesSourceMap[provider->first].provider_name; |
163 return default_setting; | 189 return default_setting; |
164 } | 190 } |
165 } | 191 } |
166 | 192 |
167 return CONTENT_SETTING_DEFAULT; | 193 return CONTENT_SETTING_DEFAULT; |
168 } | 194 } |
169 | 195 |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 if (info) { | 672 if (info) { |
647 primary_pattern = &info->primary_pattern; | 673 primary_pattern = &info->primary_pattern; |
648 secondary_pattern = &info->secondary_pattern; | 674 secondary_pattern = &info->secondary_pattern; |
649 } | 675 } |
650 | 676 |
651 // The list of |content_settings_providers_| is ordered according to their | 677 // The list of |content_settings_providers_| is ordered according to their |
652 // precedence. | 678 // precedence. |
653 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 679 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
654 provider != content_settings_providers_.end(); | 680 provider != content_settings_providers_.end(); |
655 ++provider) { | 681 ++provider) { |
656 | 682 scoped_ptr<base::Value> value = GetContentSettingValueAndPatterns( |
657 scoped_ptr<base::Value> value( | 683 provider->second, primary_url, secondary_url, content_type, |
658 content_settings::GetContentSettingValueAndPatterns(provider->second, | 684 resource_identifier, is_off_the_record_, primary_pattern, |
659 primary_url, | 685 secondary_pattern); |
660 secondary_url, | |
661 content_type, | |
662 resource_identifier, | |
663 is_off_the_record_, | |
664 primary_pattern, | |
665 secondary_pattern)); | |
666 if (value) { | 686 if (value) { |
667 if (info) | 687 if (info) |
668 info->source = kProviderNamesSourceMap[provider->first].provider_source; | 688 info->source = kProviderNamesSourceMap[provider->first].provider_source; |
669 return value.Pass(); | 689 return value.Pass(); |
670 } | 690 } |
671 } | 691 } |
672 | 692 |
673 if (info) { | 693 if (info) { |
674 info->source = content_settings::SETTING_SOURCE_NONE; | 694 info->source = content_settings::SETTING_SOURCE_NONE; |
675 info->primary_pattern = ContentSettingsPattern(); | 695 info->primary_pattern = ContentSettingsPattern(); |
676 info->secondary_pattern = ContentSettingsPattern(); | 696 info->secondary_pattern = ContentSettingsPattern(); |
677 } | 697 } |
678 return scoped_ptr<base::Value>(); | 698 return scoped_ptr<base::Value>(); |
679 } | 699 } |
| 700 |
| 701 // static |
| 702 scoped_ptr<base::Value> |
| 703 HostContentSettingsMap::GetContentSettingValueAndPatterns( |
| 704 const content_settings::ProviderInterface* provider, |
| 705 const GURL& primary_url, |
| 706 const GURL& secondary_url, |
| 707 ContentSettingsType content_type, |
| 708 const std::string& resource_identifier, |
| 709 bool include_incognito, |
| 710 ContentSettingsPattern* primary_pattern, |
| 711 ContentSettingsPattern* secondary_pattern) { |
| 712 if (include_incognito) { |
| 713 // Check incognito-only specific settings. It's essential that the |
| 714 // |RuleIterator| gets out of scope before we get a rule iterator for the |
| 715 // normal mode. |
| 716 scoped_ptr<content_settings::RuleIterator> incognito_rule_iterator( |
| 717 provider->GetRuleIterator(content_type, resource_identifier, |
| 718 true /* incognito */)); |
| 719 scoped_ptr<base::Value> value = GetContentSettingValueAndPatterns( |
| 720 incognito_rule_iterator.get(), primary_url, secondary_url, |
| 721 primary_pattern, secondary_pattern); |
| 722 if (value) |
| 723 return value; |
| 724 } |
| 725 // No settings from the incognito; use the normal mode. |
| 726 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
| 727 provider->GetRuleIterator(content_type, resource_identifier, |
| 728 false /* incognito */)); |
| 729 scoped_ptr<base::Value> value = GetContentSettingValueAndPatterns( |
| 730 rule_iterator.get(), primary_url, secondary_url, primary_pattern, |
| 731 secondary_pattern); |
| 732 if (value && include_incognito) |
| 733 value = CoerceSettingInheritedToIncognito(content_type, value.Pass()); |
| 734 return value; |
| 735 } |
| 736 |
| 737 // static |
| 738 scoped_ptr<base::Value> |
| 739 HostContentSettingsMap::GetContentSettingValueAndPatterns( |
| 740 content_settings::RuleIterator* rule_iterator, |
| 741 const GURL& primary_url, |
| 742 const GURL& secondary_url, |
| 743 ContentSettingsPattern* primary_pattern, |
| 744 ContentSettingsPattern* secondary_pattern) { |
| 745 while (rule_iterator->HasNext()) { |
| 746 const content_settings::Rule& rule = rule_iterator->Next(); |
| 747 if (rule.primary_pattern.Matches(primary_url) && |
| 748 rule.secondary_pattern.Matches(secondary_url)) { |
| 749 if (primary_pattern) |
| 750 *primary_pattern = rule.primary_pattern; |
| 751 if (secondary_pattern) |
| 752 *secondary_pattern = rule.secondary_pattern; |
| 753 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
| 754 } |
| 755 } |
| 756 return scoped_ptr<base::Value>(); |
| 757 } |
OLD | NEW |