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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "components/content_settings/core/browser/content_settings_utils.h" | 27 #include "components/content_settings/core/browser/content_settings_utils.h" |
28 #include "components/content_settings/core/browser/website_settings_registry.h" | 28 #include "components/content_settings/core/browser/website_settings_registry.h" |
29 #include "components/content_settings/core/common/content_settings_pattern.h" | 29 #include "components/content_settings/core/common/content_settings_pattern.h" |
30 #include "components/content_settings/core/common/pref_names.h" | 30 #include "components/content_settings/core/common/pref_names.h" |
31 #include "components/pref_registry/pref_registry_syncable.h" | 31 #include "components/pref_registry/pref_registry_syncable.h" |
32 #include "components/prefs/pref_service.h" | 32 #include "components/prefs/pref_service.h" |
33 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
34 #include "net/base/static_cookie_policy.h" | 34 #include "net/base/static_cookie_policy.h" |
35 #include "url/gurl.h" | 35 #include "url/gurl.h" |
36 | 36 |
| 37 using content_settings::WebsiteSettingsInfo; |
| 38 |
37 namespace { | 39 namespace { |
38 | 40 |
39 typedef std::vector<content_settings::Rule> Rules; | 41 typedef std::vector<content_settings::Rule> Rules; |
40 | 42 |
41 typedef std::pair<std::string, std::string> StringPair; | 43 typedef std::pair<std::string, std::string> StringPair; |
42 | 44 |
43 struct ProviderNamesSourceMapEntry { | 45 struct ProviderNamesSourceMapEntry { |
44 const char* provider_name; | 46 const char* provider_name; |
45 content_settings::SettingSource provider_source; | 47 content_settings::SettingSource provider_source; |
46 }; | 48 }; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 content_settings::ValueToContentSetting(value.get()); | 101 content_settings::ValueToContentSetting(value.get()); |
100 if (setting != CONTENT_SETTING_ALLOW) | 102 if (setting != CONTENT_SETTING_ALLOW) |
101 return value; | 103 return value; |
102 DCHECK(content_settings_info->IsSettingValid(CONTENT_SETTING_ASK)); | 104 DCHECK(content_settings_info->IsSettingValid(CONTENT_SETTING_ASK)); |
103 return content_settings::ContentSettingToValue(CONTENT_SETTING_ASK); | 105 return content_settings::ContentSettingToValue(CONTENT_SETTING_ASK); |
104 } | 106 } |
105 | 107 |
106 return value; | 108 return value; |
107 } | 109 } |
108 | 110 |
| 111 content_settings::PatternPair GetPatternsFromScopingType( |
| 112 WebsiteSettingsInfo::ScopingType scoping_type, |
| 113 const GURL& primary_url, |
| 114 const GURL& secondary_url) { |
| 115 content_settings::PatternPair patterns; |
| 116 |
| 117 switch (scoping_type) { |
| 118 case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: |
| 119 case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE: |
| 120 patterns.first = ContentSettingsPattern::FromURL(primary_url); |
| 121 patterns.second = ContentSettingsPattern::Wildcard(); |
| 122 break; |
| 123 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: |
| 124 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| 125 patterns.second = ContentSettingsPattern::Wildcard(); |
| 126 break; |
| 127 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: |
| 128 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| 129 patterns.second = |
| 130 ContentSettingsPattern::FromURLNoWildcard(secondary_url); |
| 131 break; |
| 132 } |
| 133 return patterns; |
| 134 } |
| 135 |
109 } // namespace | 136 } // namespace |
110 | 137 |
111 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, | 138 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
112 bool is_incognito_profile, | 139 bool is_incognito_profile, |
113 bool is_guest_profile) | 140 bool is_guest_profile) |
114 : | 141 : |
115 #ifndef NDEBUG | 142 #ifndef NDEBUG |
116 used_from_thread_id_(base::PlatformThread::CurrentId()), | 143 used_from_thread_id_(base::PlatformThread::CurrentId()), |
117 #endif | 144 #endif |
118 prefs_(prefs), | 145 prefs_(prefs), |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 ContentSettingsPattern::Wildcard(), content_type, | 303 ContentSettingsPattern::Wildcard(), content_type, |
277 std::string(), std::move(value)); | 304 std::string(), std::move(value)); |
278 } | 305 } |
279 | 306 |
280 void HostContentSettingsMap::SetWebsiteSettingDefaultScope( | 307 void HostContentSettingsMap::SetWebsiteSettingDefaultScope( |
281 const GURL& requesting_url, | 308 const GURL& requesting_url, |
282 const GURL& top_level_url, | 309 const GURL& top_level_url, |
283 ContentSettingsType content_type, | 310 ContentSettingsType content_type, |
284 const std::string& resource_identifier, | 311 const std::string& resource_identifier, |
285 base::Value* value) { | 312 base::Value* value) { |
286 using content_settings::WebsiteSettingsInfo; | |
287 | |
288 const WebsiteSettingsInfo* info = | 313 const WebsiteSettingsInfo* info = |
289 content_settings::WebsiteSettingsRegistry::GetInstance()->Get( | 314 content_settings::WebsiteSettingsRegistry::GetInstance()->Get( |
290 content_type); | 315 content_type); |
291 ContentSettingsPattern primary_pattern; | 316 content_settings::PatternPair patterns = GetPatternsFromScopingType( |
292 ContentSettingsPattern secondary_pattern; | 317 info->scoping_type(), requesting_url, top_level_url); |
293 switch (info->scoping_type()) { | 318 ContentSettingsPattern primary_pattern = patterns.first; |
294 case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: | 319 ContentSettingsPattern secondary_pattern = patterns.second; |
295 primary_pattern = ContentSettingsPattern::FromURL(top_level_url); | |
296 secondary_pattern = ContentSettingsPattern::Wildcard(); | |
297 DCHECK(requesting_url.is_empty()); | |
298 break; | |
299 case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE: | |
300 primary_pattern = ContentSettingsPattern::FromURL(requesting_url); | |
301 secondary_pattern = ContentSettingsPattern::Wildcard(); | |
302 DCHECK(top_level_url.is_empty()); | |
303 break; | |
304 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: | |
305 primary_pattern = | |
306 ContentSettingsPattern::FromURLNoWildcard(requesting_url); | |
307 secondary_pattern = ContentSettingsPattern::Wildcard(); | |
308 DCHECK(top_level_url.is_empty()); | |
309 break; | |
310 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: | |
311 primary_pattern = | |
312 ContentSettingsPattern::FromURLNoWildcard(requesting_url); | |
313 secondary_pattern = | |
314 ContentSettingsPattern::FromURLNoWildcard(top_level_url); | |
315 break; | |
316 } | |
317 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) | 320 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) |
318 return; | 321 return; |
| 322 |
319 SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, | 323 SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, |
320 resource_identifier, make_scoped_ptr(value)); | 324 resource_identifier, make_scoped_ptr(value)); |
321 } | 325 } |
322 | 326 |
323 void HostContentSettingsMap::SetWebsiteSettingCustomScope( | 327 void HostContentSettingsMap::SetWebsiteSettingCustomScope( |
324 const ContentSettingsPattern& primary_pattern, | 328 const ContentSettingsPattern& primary_pattern, |
325 const ContentSettingsPattern& secondary_pattern, | 329 const ContentSettingsPattern& secondary_pattern, |
326 ContentSettingsType content_type, | 330 ContentSettingsType content_type, |
327 const std::string& resource_identifier, | 331 const std::string& resource_identifier, |
328 scoped_ptr<base::Value> value) { | 332 scoped_ptr<base::Value> value) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 if (setting != CONTENT_SETTING_DEFAULT) { | 434 if (setting != CONTENT_SETTING_DEFAULT) { |
431 DCHECK(content_settings::ContentSettingsRegistry::GetInstance() | 435 DCHECK(content_settings::ContentSettingsRegistry::GetInstance() |
432 ->Get(content_type) | 436 ->Get(content_type) |
433 ->IsSettingValid(setting)); | 437 ->IsSettingValid(setting)); |
434 value.reset(new base::FundamentalValue(setting)); | 438 value.reset(new base::FundamentalValue(setting)); |
435 } | 439 } |
436 SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, | 440 SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, |
437 resource_identifier, std::move(value)); | 441 resource_identifier, std::move(value)); |
438 } | 442 } |
439 | 443 |
| 444 void HostContentSettingsMap::SetContentSettingDefaultScope( |
| 445 const GURL& primary_url, |
| 446 const GURL& secondary_url, |
| 447 ContentSettingsType content_type, |
| 448 const std::string& resource_identifier, |
| 449 ContentSetting setting) { |
| 450 using content_settings::ContentSettingsInfo; |
| 451 const ContentSettingsInfo* info = |
| 452 content_settings::ContentSettingsRegistry::GetInstance()->Get( |
| 453 content_type); |
| 454 DCHECK(info); |
| 455 |
| 456 content_settings::PatternPair patterns = |
| 457 GetPatternsFromScopingType(info->website_settings_info()->scoping_type(), |
| 458 primary_url, secondary_url); |
| 459 ContentSettingsPattern primary_pattern = patterns.first; |
| 460 ContentSettingsPattern secondary_pattern = patterns.second; |
| 461 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) |
| 462 return; |
| 463 |
| 464 SetContentSetting(primary_pattern, secondary_pattern, content_type, |
| 465 resource_identifier, setting); |
| 466 } |
| 467 |
440 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | 468 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
441 const GURL& primary_url, | 469 const GURL& primary_url, |
442 const GURL& secondary_url, | 470 const GURL& secondary_url, |
443 ContentSettingsType content_type, | 471 ContentSettingsType content_type, |
444 const std::string& resource_identifier) { | 472 const std::string& resource_identifier) { |
445 DCHECK(thread_checker_.CalledOnValidThread()); | 473 DCHECK(thread_checker_.CalledOnValidThread()); |
446 | 474 |
447 ContentSetting setting = GetContentSetting( | 475 ContentSetting setting = GetContentSetting( |
448 primary_url, secondary_url, content_type, resource_identifier); | 476 primary_url, secondary_url, content_type, resource_identifier); |
449 if (setting == CONTENT_SETTING_ALLOW) { | 477 if (setting == CONTENT_SETTING_ALLOW) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 rule.secondary_pattern.Matches(secondary_url)) { | 797 rule.secondary_pattern.Matches(secondary_url)) { |
770 if (primary_pattern) | 798 if (primary_pattern) |
771 *primary_pattern = rule.primary_pattern; | 799 *primary_pattern = rule.primary_pattern; |
772 if (secondary_pattern) | 800 if (secondary_pattern) |
773 *secondary_pattern = rule.secondary_pattern; | 801 *secondary_pattern = rule.secondary_pattern; |
774 return make_scoped_ptr(rule.value.get()->DeepCopy()); | 802 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
775 } | 803 } |
776 } | 804 } |
777 return scoped_ptr<base::Value>(); | 805 return scoped_ptr<base::Value>(); |
778 } | 806 } |
OLD | NEW |