Chromium Code Reviews| 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 DCHECK(setting_entry.secondary_pattern == | |
|
msramek
2016/06/30 16:16:21
I would prefer
if (...) {
NOTREACHED();
conti
lshang
2016/07/04 02:46:00
Done. Fair enough.
| |
| 526 ContentSettingsPattern::Wildcard()); | |
| 527 | |
| 528 ContentSettingsPattern origin_pattern; | |
| 529 if (!ContentSettingsPattern::MigrateFromDomainToOrigin( | |
| 530 setting_entry.primary_pattern, &origin_pattern)) { | |
| 531 continue; | |
| 532 } | |
| 533 | |
| 534 if (!origin_pattern.IsValid()) | |
| 535 continue; | |
| 536 | |
| 537 GURL origin(origin_pattern.ToString()); | |
| 538 DCHECK(origin.is_valid()); | |
| 539 | |
| 540 // Ensure that the current resolved content setting for this origin is | |
| 541 // allowed. Otherwise we may be overriding some narrower setting which is | |
| 542 // set to block. | |
| 543 ContentSetting origin_setting = | |
| 544 GetContentSetting(origin, origin, type, std::string()); | |
| 545 | |
| 546 // Remove the domain scoped pattern. If |origin_setting| is not | |
| 547 // CONTENT_SETTING_ALLOW it implies there is some narrower pattern in | |
| 548 // effect, so it's still safe to remove the domain-scoped pattern. | |
| 549 SetContentSettingCustomScope(setting_entry.primary_pattern, | |
| 550 setting_entry.secondary_pattern, type, | |
| 551 std::string(), CONTENT_SETTING_DEFAULT); | |
| 552 | |
| 553 // If the current resolved content setting is allowed it's safe to set the | |
| 554 // origin-scoped pattern. | |
| 555 if (origin_setting == CONTENT_SETTING_ALLOW) | |
| 556 SetContentSettingCustomScope( | |
| 557 ContentSettingsPattern::FromURLNoWildcard(origin), | |
| 558 ContentSettingsPattern::Wildcard(), type, std::string(), | |
| 559 CONTENT_SETTING_ALLOW); | |
| 560 } | |
| 561 } | |
| 562 } | |
| 563 | |
| 500 void HostContentSettingsMap::RecordNumberOfExceptions() { | 564 void HostContentSettingsMap::RecordNumberOfExceptions() { |
| 501 for (const content_settings::WebsiteSettingsInfo* info : | 565 for (const content_settings::WebsiteSettingsInfo* info : |
| 502 *content_settings::WebsiteSettingsRegistry::GetInstance()) { | 566 *content_settings::WebsiteSettingsRegistry::GetInstance()) { |
| 503 ContentSettingsType content_type = info->type(); | 567 ContentSettingsType content_type = info->type(); |
| 504 const std::string type_name = info->name(); | 568 const std::string type_name = info->name(); |
| 505 | 569 |
| 506 ContentSettingsForOneType settings; | 570 ContentSettingsForOneType settings; |
| 507 GetSettingsForOneType(content_type, std::string(), &settings); | 571 GetSettingsForOneType(content_type, std::string(), &settings); |
| 508 size_t num_exceptions = 0; | 572 size_t num_exceptions = 0; |
| 509 for (const ContentSettingPatternSource& setting_entry : settings) { | 573 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)) { | 910 rule.secondary_pattern.Matches(secondary_url)) { |
| 847 if (primary_pattern) | 911 if (primary_pattern) |
| 848 *primary_pattern = rule.primary_pattern; | 912 *primary_pattern = rule.primary_pattern; |
| 849 if (secondary_pattern) | 913 if (secondary_pattern) |
| 850 *secondary_pattern = rule.secondary_pattern; | 914 *secondary_pattern = rule.secondary_pattern; |
| 851 return base::WrapUnique(rule.value.get()->DeepCopy()); | 915 return base::WrapUnique(rule.value.get()->DeepCopy()); |
| 852 } | 916 } |
| 853 } | 917 } |
| 854 return std::unique_ptr<base::Value>(); | 918 return std::unique_ptr<base::Value>(); |
| 855 } | 919 } |
| OLD | NEW |