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