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 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 CONTENT_SETTINGS_TYPE_KEYGEN, | 490 CONTENT_SETTINGS_TYPE_KEYGEN, |
491 std::string(), CONTENT_SETTING_DEFAULT); | 491 std::string(), CONTENT_SETTING_DEFAULT); |
492 // Set the new pattern. | 492 // Set the new pattern. |
493 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, | 493 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, |
494 std::string(), content_setting); | 494 std::string(), content_setting); |
495 } | 495 } |
496 } | 496 } |
497 } | 497 } |
498 } | 498 } |
499 | 499 |
| 500 void HostContentSettingsMap::MigrateDomainScopedSettings() { |
| 501 const ContentSettingsType kDomainScopedTypes[] = { |
| 502 CONTENT_SETTINGS_TYPE_COOKIES, |
| 503 CONTENT_SETTINGS_TYPE_IMAGES, |
| 504 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 505 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 506 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 507 CONTENT_SETTINGS_TYPE_POPUPS}; |
| 508 for (const ContentSettingsType& type : kDomainScopedTypes) { |
| 509 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type)) |
| 510 continue; |
| 511 ContentSettingsForOneType settings; |
| 512 GetSettingsForOneType(type, std::string(), &settings); |
| 513 |
| 514 for (const ContentSettingPatternSource& setting_entry : settings) { |
| 515 // Migrate user preference settings only. |
| 516 if (setting_entry.source != "preference") |
| 517 continue; |
| 518 // Migrate ALLOW settings only. |
| 519 if (setting_entry.setting != CONTENT_SETTING_ALLOW) |
| 520 continue; |
| 521 // Skip default settings. |
| 522 if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) |
| 523 continue; |
| 524 |
| 525 if (setting_entry.secondary_pattern != |
| 526 ContentSettingsPattern::Wildcard()) { |
| 527 NOTREACHED(); |
| 528 continue; |
| 529 } |
| 530 |
| 531 ContentSettingsPattern origin_pattern; |
| 532 if (!ContentSettingsPattern::MigrateFromDomainToOrigin( |
| 533 setting_entry.primary_pattern, &origin_pattern)) { |
| 534 continue; |
| 535 } |
| 536 |
| 537 if (!origin_pattern.IsValid()) |
| 538 continue; |
| 539 |
| 540 GURL origin(origin_pattern.ToString()); |
| 541 DCHECK(origin.is_valid()); |
| 542 |
| 543 // Ensure that the current resolved content setting for this origin is |
| 544 // allowed. Otherwise we may be overriding some narrower setting which is |
| 545 // set to block. |
| 546 ContentSetting origin_setting = |
| 547 GetContentSetting(origin, origin, type, std::string()); |
| 548 |
| 549 // Remove the domain scoped pattern. If |origin_setting| is not |
| 550 // CONTENT_SETTING_ALLOW it implies there is some narrower pattern in |
| 551 // effect, so it's still safe to remove the domain-scoped pattern. |
| 552 SetContentSettingCustomScope(setting_entry.primary_pattern, |
| 553 setting_entry.secondary_pattern, type, |
| 554 std::string(), CONTENT_SETTING_DEFAULT); |
| 555 |
| 556 // If the current resolved content setting is allowed it's safe to set the |
| 557 // origin-scoped pattern. |
| 558 if (origin_setting == CONTENT_SETTING_ALLOW) |
| 559 SetContentSettingCustomScope( |
| 560 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 561 ContentSettingsPattern::Wildcard(), type, std::string(), |
| 562 CONTENT_SETTING_ALLOW); |
| 563 } |
| 564 } |
| 565 } |
| 566 |
500 void HostContentSettingsMap::RecordNumberOfExceptions() { | 567 void HostContentSettingsMap::RecordNumberOfExceptions() { |
501 for (const content_settings::WebsiteSettingsInfo* info : | 568 for (const content_settings::WebsiteSettingsInfo* info : |
502 *content_settings::WebsiteSettingsRegistry::GetInstance()) { | 569 *content_settings::WebsiteSettingsRegistry::GetInstance()) { |
503 ContentSettingsType content_type = info->type(); | 570 ContentSettingsType content_type = info->type(); |
504 const std::string type_name = info->name(); | 571 const std::string type_name = info->name(); |
505 | 572 |
506 ContentSettingsForOneType settings; | 573 ContentSettingsForOneType settings; |
507 GetSettingsForOneType(content_type, std::string(), &settings); | 574 GetSettingsForOneType(content_type, std::string(), &settings); |
508 size_t num_exceptions = 0; | 575 size_t num_exceptions = 0; |
509 for (const ContentSettingPatternSource& setting_entry : settings) { | 576 for (const ContentSettingPatternSource& setting_entry : settings) { |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 rule.secondary_pattern.Matches(secondary_url)) { | 913 rule.secondary_pattern.Matches(secondary_url)) { |
847 if (primary_pattern) | 914 if (primary_pattern) |
848 *primary_pattern = rule.primary_pattern; | 915 *primary_pattern = rule.primary_pattern; |
849 if (secondary_pattern) | 916 if (secondary_pattern) |
850 *secondary_pattern = rule.secondary_pattern; | 917 *secondary_pattern = rule.secondary_pattern; |
851 return base::WrapUnique(rule.value.get()->DeepCopy()); | 918 return base::WrapUnique(rule.value.get()->DeepCopy()); |
852 } | 919 } |
853 } | 920 } |
854 return std::unique_ptr<base::Value>(); | 921 return std::unique_ptr<base::Value>(); |
855 } | 922 } |
OLD | NEW |