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" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 | 52 |
53 typedef std::vector<content_settings::Rule> Rules; | 53 typedef std::vector<content_settings::Rule> Rules; |
54 | 54 |
55 typedef std::pair<std::string, std::string> StringPair; | 55 typedef std::pair<std::string, std::string> StringPair; |
56 | 56 |
57 // TODO(bauerb): Expose constants. | 57 // TODO(bauerb): Expose constants. |
58 const char* kProviderNames[] = { | 58 const char* kProviderNames[] = { |
59 "platform_app", | 59 "platform_app", |
60 "policy", | 60 "policy", |
61 "extension", | 61 "extension", |
62 "override", | |
62 "preference", | 63 "preference", |
63 "default" | 64 "default" |
64 }; | 65 }; |
65 | 66 |
66 content_settings::SettingSource kProviderSourceMap[] = { | 67 content_settings::SettingSource kProviderSourceMap[] = { |
67 content_settings::SETTING_SOURCE_EXTENSION, | 68 content_settings::SETTING_SOURCE_EXTENSION, |
68 content_settings::SETTING_SOURCE_POLICY, | 69 content_settings::SETTING_SOURCE_POLICY, |
69 content_settings::SETTING_SOURCE_EXTENSION, | 70 content_settings::SETTING_SOURCE_EXTENSION, |
70 content_settings::SETTING_SOURCE_USER, | 71 content_settings::SETTING_SOURCE_USER, |
71 content_settings::SETTING_SOURCE_USER, | 72 content_settings::SETTING_SOURCE_USER, |
73 content_settings::SETTING_SOURCE_USER, | |
72 }; | 74 }; |
73 COMPILE_ASSERT(arraysize(kProviderSourceMap) == | 75 COMPILE_ASSERT(arraysize(kProviderSourceMap) == |
74 HostContentSettingsMap::NUM_PROVIDER_TYPES, | 76 HostContentSettingsMap::NUM_PROVIDER_TYPES, |
75 kProviderSourceMap_has_incorrect_size); | 77 kProviderSourceMap_has_incorrect_size); |
76 | 78 |
77 // Returns true if the |content_type| supports a resource identifier. | 79 // Returns true if the |content_type| supports a resource identifier. |
78 // Resource identifiers are supported (but not required) for plug-ins. | 80 // Resource identifiers are supported (but not required) for plug-ins. |
79 bool SupportsResourceIdentifier(ContentSettingsType content_type) { | 81 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
80 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 82 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
81 } | 83 } |
82 | 84 |
83 } // namespace | 85 } // namespace |
84 | 86 |
85 HostContentSettingsMap::HostContentSettingsMap( | 87 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
86 PrefService* prefs, | 88 bool incognito) |
87 bool incognito) : | 89 : |
88 #ifndef NDEBUG | 90 #ifndef NDEBUG |
89 used_from_thread_id_(base::PlatformThread::CurrentId()), | 91 used_from_thread_id_(base::PlatformThread::CurrentId()), |
90 #endif | 92 #endif |
91 prefs_(prefs), | 93 prefs_(prefs), |
92 is_off_the_record_(incognito) { | 94 is_off_the_record_(incognito) { |
93 content_settings::ObservableProvider* policy_provider = | 95 content_settings::ObservableProvider* policy_provider = |
94 new content_settings::PolicyProvider(prefs_); | 96 new content_settings::PolicyProvider(prefs_); |
95 policy_provider->AddObserver(this); | 97 policy_provider->AddObserver(this); |
96 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 98 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
97 | 99 |
98 content_settings::ObservableProvider* pref_provider = | 100 content_settings::ObservableProvider* pref_provider = |
99 new content_settings::PrefProvider(prefs_, is_off_the_record_); | 101 new content_settings::PrefProvider(prefs_, is_off_the_record_); |
100 pref_provider->AddObserver(this); | 102 pref_provider->AddObserver(this); |
101 content_settings_providers_[PREF_PROVIDER] = pref_provider; | 103 content_settings_providers_[PREF_PROVIDER] = pref_provider; |
102 | 104 |
103 content_settings::ObservableProvider* default_provider = | 105 content_settings::ObservableProvider* default_provider = |
104 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 106 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
105 default_provider->AddObserver(this); | 107 default_provider->AddObserver(this); |
106 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 108 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
107 | 109 |
110 content_settings_providers_[OVERRIDE_PROVIDER] = | |
111 new content_settings::OverrideProvider(prefs_, is_off_the_record_); | |
112 | |
108 if (!is_off_the_record_) { | 113 if (!is_off_the_record_) { |
109 // Migrate obsolete preferences. | 114 // Migrate obsolete preferences. |
110 MigrateObsoleteClearOnExitPref(); | 115 MigrateObsoleteClearOnExitPref(); |
111 } | 116 } |
112 } | 117 } |
113 | 118 |
114 #if defined(ENABLE_EXTENSIONS) | 119 #if defined(ENABLE_EXTENSIONS) |
115 void HostContentSettingsMap::RegisterExtensionService( | 120 void HostContentSettingsMap::RegisterExtensionService( |
116 ExtensionService* extension_service) { | 121 ExtensionService* extension_service) { |
117 DCHECK(extension_service); | 122 DCHECK(extension_service); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 159 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
155 registry->RegisterBooleanPref( | 160 registry->RegisterBooleanPref( |
156 prefs::kContentSettingsClearOnExitMigrated, | 161 prefs::kContentSettingsClearOnExitMigrated, |
157 false, | 162 false, |
158 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 163 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
159 | 164 |
160 // Register the prefs for the content settings providers. | 165 // Register the prefs for the content settings providers. |
161 content_settings::DefaultProvider::RegisterProfilePrefs(registry); | 166 content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
162 content_settings::PrefProvider::RegisterProfilePrefs(registry); | 167 content_settings::PrefProvider::RegisterProfilePrefs(registry); |
163 content_settings::PolicyProvider::RegisterProfilePrefs(registry); | 168 content_settings::PolicyProvider::RegisterProfilePrefs(registry); |
169 content_settings::OverrideProvider::RegisterProfilePrefs(registry); | |
164 } | 170 } |
165 | 171 |
166 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( | 172 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( |
167 ContentSettingsType content_type, | 173 ContentSettingsType content_type, |
168 content_settings::ProviderInterface* provider) const { | 174 content_settings::ProviderInterface* provider) const { |
169 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 175 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
170 provider->GetRuleIterator(content_type, std::string(), false)); | 176 provider->GetRuleIterator(content_type, std::string(), false)); |
171 | 177 |
172 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 178 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); |
173 while (rule_iterator->HasNext()) { | 179 while (rule_iterator->HasNext()) { |
174 content_settings::Rule rule = rule_iterator->Next(); | 180 content_settings::Rule rule = rule_iterator->Next(); |
175 if (rule.primary_pattern == wildcard && | 181 if (rule.primary_pattern == wildcard && |
176 rule.secondary_pattern == wildcard) { | 182 rule.secondary_pattern == wildcard) { |
177 return content_settings::ValueToContentSetting(rule.value.get()); | 183 return content_settings::ValueToContentSetting(rule.value.get()); |
178 } | 184 } |
179 } | 185 } |
180 return CONTENT_SETTING_DEFAULT; | 186 return CONTENT_SETTING_DEFAULT; |
181 } | 187 } |
182 | 188 |
183 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( | 189 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
184 ContentSettingsType content_type, | 190 ContentSettingsType content_type, |
185 std::string* provider_id) const { | 191 std::string* provider_id) const { |
186 UsedContentSettingsProviders(); | 192 UsedContentSettingsProviders(); |
187 | 193 |
188 // Iterate through the list of providers and return the first non-NULL value | 194 // Iterate through the list of providers and return the first non-NULL value |
189 // that matches |primary_url| and |secondary_url|. | 195 // that matches |primary_url| and |secondary_url|. |
190 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 196 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
191 provider != content_settings_providers_.end(); | 197 provider != content_settings_providers_.end(); |
192 ++provider) { | 198 ++provider) { |
193 if (provider->first == PREF_PROVIDER) | 199 if (provider->first == PREF_PROVIDER || |
200 provider->first == OVERRIDE_PROVIDER) | |
194 continue; | 201 continue; |
195 ContentSetting default_setting = | 202 ContentSetting default_setting = |
196 GetDefaultContentSettingFromProvider(content_type, provider->second); | 203 GetDefaultContentSettingFromProvider(content_type, provider->second); |
197 if (default_setting != CONTENT_SETTING_DEFAULT) { | 204 if (default_setting != CONTENT_SETTING_DEFAULT) { |
198 if (provider_id) | 205 if (provider_id) |
199 *provider_id = kProviderNames[provider->first]; | 206 *provider_id = kProviderNames[provider->first]; |
200 return default_setting; | 207 return default_setting; |
201 } | 208 } |
202 } | 209 } |
203 | 210 |
204 // The method GetDefaultContentSetting always has to return an explicit | 211 // The method GetDefaultContentSetting always has to return an explicit |
205 // value that is to be used as default. We here rely on the | 212 // value that is to be used as default. We here rely on the |
206 // DefaultProvider to always provide a value. | 213 // DefaultProvider to always provide a value. |
207 NOTREACHED(); | 214 NOTREACHED(); |
208 return CONTENT_SETTING_DEFAULT; | 215 return CONTENT_SETTING_DEFAULT; |
209 } | 216 } |
210 | 217 |
211 ContentSetting HostContentSettingsMap::GetContentSetting( | 218 ContentSetting HostContentSettingsMap::GetContentSetting( |
212 const GURL& primary_url, | 219 const GURL& primary_url, |
213 const GURL& secondary_url, | 220 const GURL& secondary_url, |
214 ContentSettingsType content_type, | 221 ContentSettingsType content_type, |
215 const std::string& resource_identifier) const { | 222 const std::string& resource_identifier) const { |
216 DCHECK(!ContentTypeHasCompoundValue(content_type)); | 223 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
217 scoped_ptr<base::Value> value(GetWebsiteSetting( | 224 scoped_ptr<base::Value> value = GetWebsiteSetting( |
218 primary_url, secondary_url, content_type, resource_identifier, NULL)); | 225 primary_url, secondary_url, content_type, resource_identifier, NULL); |
219 return content_settings::ValueToContentSetting(value.get()); | 226 return content_settings::ValueToContentSetting(value.get()); |
220 } | 227 } |
221 | 228 |
222 void HostContentSettingsMap::GetSettingsForOneType( | 229 void HostContentSettingsMap::GetSettingsForOneType( |
223 ContentSettingsType content_type, | 230 ContentSettingsType content_type, |
224 const std::string& resource_identifier, | 231 const std::string& resource_identifier, |
225 ContentSettingsForOneType* settings) const { | 232 ContentSettingsForOneType* settings) const { |
226 DCHECK(SupportsResourceIdentifier(content_type) || | 233 DCHECK(SupportsResourceIdentifier(content_type) || |
227 resource_identifier.empty()); | 234 resource_identifier.empty()); |
228 DCHECK(settings); | 235 DCHECK(settings); |
229 UsedContentSettingsProviders(); | 236 UsedContentSettingsProviders(); |
230 | 237 |
231 settings->clear(); | 238 settings->clear(); |
232 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 239 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
233 provider != content_settings_providers_.end(); | 240 provider != content_settings_providers_.end(); |
234 ++provider) { | 241 ++provider) { |
242 if (provider->first == OVERRIDE_PROVIDER) | |
243 continue; | |
235 // For each provider, iterate first the incognito-specific rules, then the | 244 // For each provider, iterate first the incognito-specific rules, then the |
236 // normal rules. | 245 // normal rules. |
237 if (is_off_the_record_) { | 246 if (is_off_the_record_) { |
238 AddSettingsForOneType(provider->second, | 247 AddSettingsForOneType(provider->second, |
239 provider->first, | 248 provider->first, |
240 content_type, | 249 content_type, |
241 resource_identifier, | 250 resource_identifier, |
242 settings, | 251 settings, |
243 true); | 252 true); |
244 } | 253 } |
(...skipping 29 matching lines...) Expand all Loading... | |
274 const std::string& resource_identifier, | 283 const std::string& resource_identifier, |
275 base::Value* value) { | 284 base::Value* value) { |
276 DCHECK(IsValueAllowedForType(prefs_, value, content_type)); | 285 DCHECK(IsValueAllowedForType(prefs_, value, content_type)); |
277 DCHECK(SupportsResourceIdentifier(content_type) || | 286 DCHECK(SupportsResourceIdentifier(content_type) || |
278 resource_identifier.empty()); | 287 resource_identifier.empty()); |
279 UsedContentSettingsProviders(); | 288 UsedContentSettingsProviders(); |
280 | 289 |
281 for (ProviderIterator provider = content_settings_providers_.begin(); | 290 for (ProviderIterator provider = content_settings_providers_.begin(); |
282 provider != content_settings_providers_.end(); | 291 provider != content_settings_providers_.end(); |
283 ++provider) { | 292 ++provider) { |
293 if (provider->first == OVERRIDE_PROVIDER) | |
Bernhard Bauer
2014/09/11 16:49:56
If you use a new method to change overrides, you c
Daniel Nishi
2014/09/11 20:58:12
Done.
| |
294 continue; | |
284 if (provider->second->SetWebsiteSetting(primary_pattern, | 295 if (provider->second->SetWebsiteSetting(primary_pattern, |
285 secondary_pattern, | 296 secondary_pattern, |
286 content_type, | 297 content_type, |
287 resource_identifier, | 298 resource_identifier, |
288 value)) { | 299 value)) { |
289 return; | 300 return; |
290 } | 301 } |
291 } | 302 } |
292 NOTREACHED(); | 303 NOTREACHED(); |
293 } | 304 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 base::Time HostContentSettingsMap::GetLastUsageByPattern( | 410 base::Time HostContentSettingsMap::GetLastUsageByPattern( |
400 const ContentSettingsPattern& primary_pattern, | 411 const ContentSettingsPattern& primary_pattern, |
401 const ContentSettingsPattern& secondary_pattern, | 412 const ContentSettingsPattern& secondary_pattern, |
402 ContentSettingsType content_type) { | 413 ContentSettingsType content_type) { |
403 UsedContentSettingsProviders(); | 414 UsedContentSettingsProviders(); |
404 | 415 |
405 return GetPrefProvider()->GetLastUsage( | 416 return GetPrefProvider()->GetLastUsage( |
406 primary_pattern, secondary_pattern, content_type); | 417 primary_pattern, secondary_pattern, content_type); |
407 } | 418 } |
408 | 419 |
420 ContentSetting HostContentSettingsMap::GetContentSettingWithoutOverride( | |
421 const GURL& primary_url, | |
422 const GURL& secondary_url, | |
423 ContentSettingsType content_type, | |
424 const std::string& resource_identifier) { | |
425 scoped_ptr<base::Value> value(GetWebsiteSettingWithoutOverride( | |
426 primary_url, secondary_url, content_type, resource_identifier, NULL)); | |
427 return content_settings::ValueToContentSetting(value.get()); | |
428 } | |
429 | |
430 scoped_ptr<base::Value> | |
431 HostContentSettingsMap::GetWebsiteSettingWithoutOverride( | |
432 const GURL& primary_url, | |
433 const GURL& secondary_url, | |
434 ContentSettingsType content_type, | |
435 const std::string& resource_identifier, | |
436 content_settings::SettingInfo* info) const { | |
437 return GetWebsiteSettingInternal(primary_url, | |
438 secondary_url, | |
439 content_type, | |
440 resource_identifier, | |
441 info, | |
442 false); | |
443 } | |
444 | |
445 void HostContentSettingsMap::SetContentSettingOverride( | |
446 ContentSettingsType content_type, | |
447 bool is_enabled) { | |
448 UsedContentSettingsProviders(); | |
449 | |
450 content_settings::OverrideProvider* override = | |
451 static_cast<content_settings::OverrideProvider*>( | |
452 content_settings_providers_[OVERRIDE_PROVIDER]); | |
453 ContentSetting enabled = | |
454 is_enabled ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | |
455 override->SetWebsiteSetting(ContentSettingsPattern::Wildcard(), | |
Bernhard Bauer
2014/09/11 16:49:56
If you already cast to OverrideProvider, you can a
Daniel Nishi
2014/09/11 20:58:12
Done.
| |
456 ContentSettingsPattern::Wildcard(), | |
457 content_type, | |
458 std::string(), | |
459 new base::FundamentalValue(enabled)); | |
460 } | |
461 | |
462 bool HostContentSettingsMap::GetContentSettingOverride( | |
463 ContentSettingsType content_type) { | |
464 UsedContentSettingsProviders(); | |
465 | |
466 content_settings::OverrideProvider* override = | |
467 static_cast<content_settings::OverrideProvider*>( | |
468 content_settings_providers_[OVERRIDE_PROVIDER]); | |
469 return override->IsEnabled(content_type); | |
470 } | |
471 | |
409 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) { | 472 void HostContentSettingsMap::AddObserver(content_settings::Observer* observer) { |
410 observers_.AddObserver(observer); | 473 observers_.AddObserver(observer); |
411 } | 474 } |
412 | 475 |
413 void HostContentSettingsMap::RemoveObserver( | 476 void HostContentSettingsMap::RemoveObserver( |
414 content_settings::Observer* observer) { | 477 content_settings::Observer* observer) { |
415 observers_.RemoveObserver(observer); | 478 observers_.RemoveObserver(observer); |
416 } | 479 } |
417 | 480 |
418 void HostContentSettingsMap::SetPrefClockForTesting( | 481 void HostContentSettingsMap::SetPrefClockForTesting( |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
685 return secondary_url.SchemeIs(extensions::kExtensionScheme); | 748 return secondary_url.SchemeIs(extensions::kExtensionScheme); |
686 default: | 749 default: |
687 return true; | 750 return true; |
688 } | 751 } |
689 } | 752 } |
690 #endif | 753 #endif |
691 return primary_url.SchemeIs(content::kChromeDevToolsScheme) || | 754 return primary_url.SchemeIs(content::kChromeDevToolsScheme) || |
692 primary_url.SchemeIs(content::kChromeUIScheme); | 755 primary_url.SchemeIs(content::kChromeUIScheme); |
693 } | 756 } |
694 | 757 |
695 base::Value* HostContentSettingsMap::GetWebsiteSetting( | 758 scoped_ptr<base::Value> HostContentSettingsMap::GetWebsiteSetting( |
696 const GURL& primary_url, | 759 const GURL& primary_url, |
697 const GURL& secondary_url, | 760 const GURL& secondary_url, |
698 ContentSettingsType content_type, | 761 ContentSettingsType content_type, |
699 const std::string& resource_identifier, | 762 const std::string& resource_identifier, |
700 content_settings::SettingInfo* info) const { | 763 content_settings::SettingInfo* info) const { |
701 DCHECK(SupportsResourceIdentifier(content_type) || | 764 DCHECK(SupportsResourceIdentifier(content_type) || |
702 resource_identifier.empty()); | 765 resource_identifier.empty()); |
703 | 766 |
704 // Check if the scheme of the requesting url is whitelisted. | 767 // Check if the scheme of the requesting url is whitelisted. |
705 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { | 768 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { |
706 if (info) { | 769 if (info) { |
707 info->source = content_settings::SETTING_SOURCE_WHITELIST; | 770 info->source = content_settings::SETTING_SOURCE_WHITELIST; |
708 info->primary_pattern = ContentSettingsPattern::Wildcard(); | 771 info->primary_pattern = ContentSettingsPattern::Wildcard(); |
709 info->secondary_pattern = ContentSettingsPattern::Wildcard(); | 772 info->secondary_pattern = ContentSettingsPattern::Wildcard(); |
710 } | 773 } |
711 return new base::FundamentalValue(CONTENT_SETTING_ALLOW); | 774 return scoped_ptr<base::Value>( |
775 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); | |
712 } | 776 } |
713 | 777 |
778 return GetWebsiteSettingInternal(primary_url, | |
779 secondary_url, | |
780 content_type, | |
781 resource_identifier, | |
782 info, | |
783 true); | |
784 } | |
785 | |
786 // static | |
787 HostContentSettingsMap::ProviderType | |
788 HostContentSettingsMap::GetProviderTypeFromSource(const std::string& source) { | |
789 for (size_t i = 0; i < arraysize(kProviderNames); ++i) { | |
790 if (source == kProviderNames[i]) | |
791 return static_cast<ProviderType>(i); | |
792 } | |
793 | |
794 NOTREACHED(); | |
795 return DEFAULT_PROVIDER; | |
796 } | |
797 | |
798 content_settings::PrefProvider* HostContentSettingsMap::GetPrefProvider() { | |
799 return static_cast<content_settings::PrefProvider*>( | |
800 content_settings_providers_[PREF_PROVIDER]); | |
801 } | |
802 | |
803 scoped_ptr<base::Value> HostContentSettingsMap::GetWebsiteSettingInternal( | |
804 const GURL& primary_url, | |
805 const GURL& secondary_url, | |
806 ContentSettingsType content_type, | |
807 const std::string& resource_identifier, | |
808 content_settings::SettingInfo* info, | |
809 bool get_override) const { | |
810 UsedContentSettingsProviders(); | |
714 ContentSettingsPattern* primary_pattern = NULL; | 811 ContentSettingsPattern* primary_pattern = NULL; |
715 ContentSettingsPattern* secondary_pattern = NULL; | 812 ContentSettingsPattern* secondary_pattern = NULL; |
716 if (info) { | 813 if (info) { |
717 primary_pattern = &info->primary_pattern; | 814 primary_pattern = &info->primary_pattern; |
718 secondary_pattern = &info->secondary_pattern; | 815 secondary_pattern = &info->secondary_pattern; |
719 } | 816 } |
720 | 817 |
721 // The list of |content_settings_providers_| is ordered according to their | 818 // The list of |content_settings_providers_| is ordered according to their |
722 // precedence. | 819 // precedence. |
723 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 820 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
724 provider != content_settings_providers_.end(); | 821 provider != content_settings_providers_.end(); |
725 ++provider) { | 822 ++provider) { |
726 base::Value* value = content_settings::GetContentSettingValueAndPatterns( | 823 if (!get_override && provider->first == OVERRIDE_PROVIDER) |
727 provider->second, primary_url, secondary_url, content_type, | 824 continue; |
728 resource_identifier, is_off_the_record_, | 825 |
729 primary_pattern, secondary_pattern); | 826 scoped_ptr<base::Value> value( |
827 content_settings::GetContentSettingValueAndPatterns(provider->second, | |
828 primary_url, | |
829 secondary_url, | |
830 content_type, | |
831 resource_identifier, | |
832 is_off_the_record_, | |
833 primary_pattern, | |
834 secondary_pattern)); | |
730 if (value) { | 835 if (value) { |
836 if (provider->first == OVERRIDE_PROVIDER && | |
837 content_settings::ValueToContentSetting(value.get()) == | |
838 CONTENT_SETTING_ALLOW) { | |
Bernhard Bauer
2014/09/11 16:49:56
I think you can avoid this by not storing a value
Daniel Nishi
2014/09/11 20:58:12
Done.
| |
839 continue; | |
840 } | |
731 if (info) | 841 if (info) |
732 info->source = kProviderSourceMap[provider->first]; | 842 info->source = kProviderSourceMap[provider->first]; |
733 return value; | 843 return value.Pass(); |
734 } | 844 } |
735 } | 845 } |
736 | 846 |
737 if (info) { | 847 if (info) { |
738 info->source = content_settings::SETTING_SOURCE_NONE; | 848 info->source = content_settings::SETTING_SOURCE_NONE; |
739 info->primary_pattern = ContentSettingsPattern(); | 849 info->primary_pattern = ContentSettingsPattern(); |
740 info->secondary_pattern = ContentSettingsPattern(); | 850 info->secondary_pattern = ContentSettingsPattern(); |
741 } | 851 } |
742 return NULL; | 852 return scoped_ptr<base::Value>(); |
743 } | 853 } |
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 } | |
OLD | NEW |