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 struct PatternPair { | |
raymes
2016/03/02 04:22:51
nit: it looks like there is already a content_sett
lshang
2016/03/02 05:21:56
Done.
Good catch! Yeah I think we'd better use the
| |
112 ContentSettingsPattern primary_pattern; | |
113 ContentSettingsPattern secondary_pattern; | |
114 }; | |
115 | |
116 PatternPair GetPatternsFromScopingType( | |
117 WebsiteSettingsInfo::ScopingType scoping_type, | |
118 const GURL& primary_url, | |
119 const GURL& secondary_url) { | |
120 PatternPair patterns; | |
121 | |
122 switch (scoping_type) { | |
123 case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: | |
124 case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE: | |
125 patterns.primary_pattern = ContentSettingsPattern::FromURL(primary_url); | |
126 patterns.secondary_pattern = ContentSettingsPattern::Wildcard(); | |
127 break; | |
128 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: | |
129 patterns.primary_pattern = | |
130 ContentSettingsPattern::FromURLNoWildcard(primary_url); | |
131 patterns.secondary_pattern = ContentSettingsPattern::Wildcard(); | |
132 break; | |
133 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: | |
134 patterns.primary_pattern = | |
135 ContentSettingsPattern::FromURLNoWildcard(primary_url); | |
136 patterns.secondary_pattern = | |
137 ContentSettingsPattern::FromURLNoWildcard(secondary_url); | |
138 break; | |
139 } | |
140 return patterns; | |
141 } | |
142 | |
109 } // namespace | 143 } // namespace |
110 | 144 |
111 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, | 145 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
112 bool is_incognito_profile, | 146 bool is_incognito_profile, |
113 bool is_guest_profile) | 147 bool is_guest_profile) |
114 : | 148 : |
115 #ifndef NDEBUG | 149 #ifndef NDEBUG |
116 used_from_thread_id_(base::PlatformThread::CurrentId()), | 150 used_from_thread_id_(base::PlatformThread::CurrentId()), |
117 #endif | 151 #endif |
118 prefs_(prefs), | 152 prefs_(prefs), |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 ContentSettingsPattern::Wildcard(), content_type, | 310 ContentSettingsPattern::Wildcard(), content_type, |
277 std::string(), std::move(value)); | 311 std::string(), std::move(value)); |
278 } | 312 } |
279 | 313 |
280 void HostContentSettingsMap::SetWebsiteSettingDefaultScope( | 314 void HostContentSettingsMap::SetWebsiteSettingDefaultScope( |
281 const GURL& requesting_url, | 315 const GURL& requesting_url, |
282 const GURL& top_level_url, | 316 const GURL& top_level_url, |
283 ContentSettingsType content_type, | 317 ContentSettingsType content_type, |
284 const std::string& resource_identifier, | 318 const std::string& resource_identifier, |
285 base::Value* value) { | 319 base::Value* value) { |
286 using content_settings::WebsiteSettingsInfo; | |
287 | |
288 const WebsiteSettingsInfo* info = | 320 const WebsiteSettingsInfo* info = |
289 content_settings::WebsiteSettingsRegistry::GetInstance()->Get( | 321 content_settings::WebsiteSettingsRegistry::GetInstance()->Get( |
290 content_type); | 322 content_type); |
291 ContentSettingsPattern primary_pattern; | 323 PatternPair patterns = GetPatternsFromScopingType( |
292 ContentSettingsPattern secondary_pattern; | 324 info->scoping_type(), requesting_url, top_level_url); |
293 switch (info->scoping_type()) { | 325 ContentSettingsPattern primary_pattern = patterns.primary_pattern; |
294 case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: | 326 ContentSettingsPattern secondary_pattern = patterns.secondary_pattern; |
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()) | 327 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) |
318 return; | 328 return; |
329 | |
319 SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, | 330 SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, |
320 resource_identifier, make_scoped_ptr(value)); | 331 resource_identifier, make_scoped_ptr(value)); |
321 } | 332 } |
322 | 333 |
323 void HostContentSettingsMap::SetWebsiteSettingCustomScope( | 334 void HostContentSettingsMap::SetWebsiteSettingCustomScope( |
324 const ContentSettingsPattern& primary_pattern, | 335 const ContentSettingsPattern& primary_pattern, |
325 const ContentSettingsPattern& secondary_pattern, | 336 const ContentSettingsPattern& secondary_pattern, |
326 ContentSettingsType content_type, | 337 ContentSettingsType content_type, |
327 const std::string& resource_identifier, | 338 const std::string& resource_identifier, |
328 scoped_ptr<base::Value> value) { | 339 scoped_ptr<base::Value> value) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 if (setting != CONTENT_SETTING_DEFAULT) { | 441 if (setting != CONTENT_SETTING_DEFAULT) { |
431 DCHECK(content_settings::ContentSettingsRegistry::GetInstance() | 442 DCHECK(content_settings::ContentSettingsRegistry::GetInstance() |
432 ->Get(content_type) | 443 ->Get(content_type) |
433 ->IsSettingValid(setting)); | 444 ->IsSettingValid(setting)); |
434 value.reset(new base::FundamentalValue(setting)); | 445 value.reset(new base::FundamentalValue(setting)); |
435 } | 446 } |
436 SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, | 447 SetWebsiteSettingCustomScope(primary_pattern, secondary_pattern, content_type, |
437 resource_identifier, std::move(value)); | 448 resource_identifier, std::move(value)); |
438 } | 449 } |
439 | 450 |
451 void HostContentSettingsMap::SetContentSettingDefaultScope( | |
452 const GURL& primary_url, | |
453 const GURL& secondary_url, | |
454 ContentSettingsType content_type, | |
455 const std::string& resource_identifier, | |
456 ContentSetting setting) { | |
457 using content_settings::ContentSettingsInfo; | |
458 const ContentSettingsInfo* info = | |
459 content_settings::ContentSettingsRegistry::GetInstance()->Get( | |
460 content_type); | |
461 DCHECK(info); | |
462 | |
463 PatternPair patterns = | |
464 GetPatternsFromScopingType(info->website_settings_info()->scoping_type(), | |
465 primary_url, secondary_url); | |
466 ContentSettingsPattern primary_pattern = patterns.primary_pattern; | |
467 ContentSettingsPattern secondary_pattern = patterns.secondary_pattern; | |
468 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) | |
469 return; | |
470 | |
471 SetContentSetting(primary_pattern, secondary_pattern, content_type, | |
472 resource_identifier, setting); | |
473 } | |
474 | |
440 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | 475 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
441 const GURL& primary_url, | 476 const GURL& primary_url, |
442 const GURL& secondary_url, | 477 const GURL& secondary_url, |
443 ContentSettingsType content_type, | 478 ContentSettingsType content_type, |
444 const std::string& resource_identifier) { | 479 const std::string& resource_identifier) { |
445 DCHECK(thread_checker_.CalledOnValidThread()); | 480 DCHECK(thread_checker_.CalledOnValidThread()); |
446 | 481 |
447 ContentSetting setting = GetContentSetting( | 482 ContentSetting setting = GetContentSetting( |
448 primary_url, secondary_url, content_type, resource_identifier); | 483 primary_url, secondary_url, content_type, resource_identifier); |
449 if (setting == CONTENT_SETTING_ALLOW) { | 484 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)) { | 804 rule.secondary_pattern.Matches(secondary_url)) { |
770 if (primary_pattern) | 805 if (primary_pattern) |
771 *primary_pattern = rule.primary_pattern; | 806 *primary_pattern = rule.primary_pattern; |
772 if (secondary_pattern) | 807 if (secondary_pattern) |
773 *secondary_pattern = rule.secondary_pattern; | 808 *secondary_pattern = rule.secondary_pattern; |
774 return make_scoped_ptr(rule.value.get()->DeepCopy()); | 809 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
775 } | 810 } |
776 } | 811 } |
777 return scoped_ptr<base::Value>(); | 812 return scoped_ptr<base::Value>(); |
778 } | 813 } |
OLD | NEW |