Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: components/content_settings/core/browser/host_content_settings_map.cc

Issue 1895993003: Add migration code to change existing domain scoped content settings to be origin scoped (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments and split the CL Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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()) {
525 continue;
526 }
527
528 DCHECK(setting_entry.secondary_pattern ==
raymes 2016/06/20 04:03:26 DCHECK_EQ
lshang 2016/06/23 01:32:31 Compiler complains when I change to use DCHECK_EQ
raymes 2016/06/27 07:23:29 What's the error?
529 ContentSettingsPattern::Wildcard());
530
531 if (!setting_entry.primary_pattern.IsGeneratedUsingFromURL())
532 continue;
533
534 ContentSettingsPattern origin_pattern =
535 ContentSettingsPattern::FromDomainToOrigin(
536 setting_entry.primary_pattern);
537 GURL origin(origin_pattern.ToString());
538 if (!origin.is_valid())
raymes 2016/06/20 04:03:26 Are there cases where this is possible? Should we
lshang 2016/06/23 01:32:31 Done.
539 continue;
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698