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

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: remove logs and format 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 14 matching lines...) Expand all
25 #include "components/content_settings/core/browser/content_settings_pref_provide r.h" 25 #include "components/content_settings/core/browser/content_settings_pref_provide r.h"
26 #include "components/content_settings/core/browser/content_settings_provider.h" 26 #include "components/content_settings/core/browser/content_settings_provider.h"
27 #include "components/content_settings/core/browser/content_settings_registry.h" 27 #include "components/content_settings/core/browser/content_settings_registry.h"
28 #include "components/content_settings/core/browser/content_settings_rule.h" 28 #include "components/content_settings/core/browser/content_settings_rule.h"
29 #include "components/content_settings/core/browser/content_settings_utils.h" 29 #include "components/content_settings/core/browser/content_settings_utils.h"
30 #include "components/content_settings/core/browser/website_settings_registry.h" 30 #include "components/content_settings/core/browser/website_settings_registry.h"
31 #include "components/content_settings/core/common/content_settings_pattern.h" 31 #include "components/content_settings/core/common/content_settings_pattern.h"
32 #include "components/content_settings/core/common/pref_names.h" 32 #include "components/content_settings/core/common/pref_names.h"
33 #include "components/pref_registry/pref_registry_syncable.h" 33 #include "components/pref_registry/pref_registry_syncable.h"
34 #include "components/prefs/pref_service.h" 34 #include "components/prefs/pref_service.h"
35 #include "components/syncable_prefs/pref_model_associator.h"
35 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
36 #include "net/base/static_cookie_policy.h" 37 #include "net/base/static_cookie_policy.h"
37 #include "url/gurl.h" 38 #include "url/gurl.h"
38 39
39 using content_settings::WebsiteSettingsInfo; 40 using content_settings::WebsiteSettingsInfo;
40 41
41 namespace { 42 namespace {
42 43
43 typedef std::vector<content_settings::Rule> Rules; 44 typedef std::vector<content_settings::Rule> Rules;
44 45
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 112 }
112 113
113 content_settings::PatternPair GetPatternsFromScopingType( 114 content_settings::PatternPair GetPatternsFromScopingType(
114 WebsiteSettingsInfo::ScopingType scoping_type, 115 WebsiteSettingsInfo::ScopingType scoping_type,
115 const GURL& primary_url, 116 const GURL& primary_url,
116 const GURL& secondary_url) { 117 const GURL& secondary_url) {
117 DCHECK(!primary_url.is_empty()); 118 DCHECK(!primary_url.is_empty());
118 content_settings::PatternPair patterns; 119 content_settings::PatternPair patterns;
119 120
120 switch (scoping_type) { 121 switch (scoping_type) {
121 case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: 122 case WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE:
122 case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE:
123 patterns.first = ContentSettingsPattern::FromURL(primary_url);
124 patterns.second = ContentSettingsPattern::Wildcard();
125 break;
126 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: 123 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE:
127 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); 124 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url);
128 patterns.second = ContentSettingsPattern::Wildcard(); 125 patterns.second = ContentSettingsPattern::Wildcard();
129 break; 126 break;
130 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: 127 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE:
131 DCHECK(!secondary_url.is_empty()); 128 DCHECK(!secondary_url.is_empty());
132 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); 129 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url);
133 patterns.second = 130 patterns.second =
134 ContentSettingsPattern::FromURLNoWildcard(secondary_url); 131 ContentSettingsPattern::FromURLNoWildcard(secondary_url);
135 break; 132 break;
(...skipping 29 matching lines...) Expand all
165 // the guest profile and so we need to ensure those get cleared. 162 // the guest profile and so we need to ensure those get cleared.
166 if (is_guest_profile) 163 if (is_guest_profile)
167 pref_provider_->ClearPrefs(); 164 pref_provider_->ClearPrefs();
168 165
169 content_settings::ObservableProvider* default_provider = 166 content_settings::ObservableProvider* default_provider =
170 new content_settings::DefaultProvider(prefs_, is_off_the_record_); 167 new content_settings::DefaultProvider(prefs_, is_off_the_record_);
171 default_provider->AddObserver(this); 168 default_provider->AddObserver(this);
172 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; 169 content_settings_providers_[DEFAULT_PROVIDER] = default_provider;
173 170
174 MigrateKeygenSettings(); 171 MigrateKeygenSettings();
172 MigrateDomainScopedSettings();
173 RecordNumberOfExceptions();
175 174
176 RecordNumberOfExceptions(); 175 syncable_prefs::PrefModelAssociator::SetMergeDataFinishedCallback(
176 base::Bind(&HostContentSettingsMap::MigrateDomainScopedSettings,
177 base::Unretained(this)));
177 } 178 }
178 179
179 // static 180 // static
180 void HostContentSettingsMap::RegisterProfilePrefs( 181 void HostContentSettingsMap::RegisterProfilePrefs(
181 user_prefs::PrefRegistrySyncable* registry) { 182 user_prefs::PrefRegistrySyncable* registry) {
182 // Ensure the content settings are all registered. 183 // Ensure the content settings are all registered.
183 content_settings::ContentSettingsRegistry::GetInstance(); 184 content_settings::ContentSettingsRegistry::GetInstance();
184 185
185 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); 186 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0);
186 187
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 CONTENT_SETTINGS_TYPE_KEYGEN, 491 CONTENT_SETTINGS_TYPE_KEYGEN,
491 std::string(), CONTENT_SETTING_DEFAULT); 492 std::string(), CONTENT_SETTING_DEFAULT);
492 // Set the new pattern. 493 // Set the new pattern.
493 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, 494 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN,
494 std::string(), content_setting); 495 std::string(), content_setting);
495 } 496 }
496 } 497 }
497 } 498 }
498 } 499 }
499 500
501 void HostContentSettingsMap::MigrateDomainScopedSettings() {
502 const ContentSettingsType kDomainScopedTypes[] = {
503 CONTENT_SETTINGS_TYPE_COOKIES,
504 #if !defined(OS_ANDROID) && !defined(OS_IOS)
raymes 2016/06/16 03:23:51 Rather than the ifdefs, can we just check to see i
lshang 2016/06/20 01:34:22 Done.
505 CONTENT_SETTINGS_TYPE_IMAGES,
506 CONTENT_SETTINGS_TYPE_PLUGINS,
507 #endif
508 #if !defined(OS_IOS)
509 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
510 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
511 #endif
512 CONTENT_SETTINGS_TYPE_POPUPS
513 };
514 for (const ContentSettingsType& type : kDomainScopedTypes) {
515 DCHECK(content_settings::ContentSettingsRegistry::GetInstance()->Get(type));
516 ContentSettingsForOneType settings;
517 GetSettingsForOneType(type, std::string(), &settings);
518
519 for (const ContentSettingPatternSource& setting_entry : settings) {
520 // Migrate user preference settings only.
521 if (setting_entry.source != "preference")
522 continue;
523 // Migrate ALLOW settings only.
524 if (setting_entry.setting != CONTENT_SETTING_ALLOW)
525 continue;
526 // Skip default settings.
527 if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard() &&
528 setting_entry.secondary_pattern == ContentSettingsPattern::Wildcard())
raymes 2016/06/16 03:23:51 nit: add {}
lshang 2016/06/20 01:34:22 Done.
529 continue;
raymes 2016/06/16 03:23:50 Should we also DCHECK that the secondary_pattern i
lshang 2016/06/20 01:34:22 Done.
530 if (setting_entry.primary_pattern.IsGeneratedFromURLDomainScoped()) {
raymes 2016/06/16 03:23:50 What about using "continue" here (if this evaluate
lshang 2016/06/20 01:34:22 Done.
531 ContentSettingsPattern origin_pattern =
532 ContentSettingsPattern::FromDomainToOrigin(
533 setting_entry.primary_pattern);
534 GURL origin(origin_pattern.ToString());
535 if (origin.is_valid()) {
raymes 2016/06/16 03:23:51 Same here
lshang 2016/06/20 01:34:22 Done.
536 ContentSetting origin_setting =
raymes 2016/06/16 03:23:51 Maybe say: // Ensure that the current resolved con
lshang 2016/06/20 01:34:22 Done.
537 GetContentSetting(origin, origin, type, std::string());
538
539 // Remove the domiain scoped pattern.
raymes 2016/06/16 03:23:50 // Remove the domain scoped pattern. If |origin_se
lshang 2016/06/20 01:34:22 Done.
540 SetContentSettingCustomScope(setting_entry.primary_pattern,
541 setting_entry.secondary_pattern, type,
542 std::string(), CONTENT_SETTING_DEFAULT);
543
544 // If the current setting of narrow-down origin is ALLOW, then add a
545 // new setting entry of this origin.
raymes 2016/06/16 03:23:51 // If the current resolved content setting is allo
lshang 2016/06/20 01:34:22 Done.
546 if (origin_setting == CONTENT_SETTING_ALLOW)
547 SetContentSettingDefaultScope(origin, GURL(), type, std::string(),
548 CONTENT_SETTING_ALLOW);
549 }
550 }
551 }
552 }
553 }
554
500 void HostContentSettingsMap::RecordNumberOfExceptions() { 555 void HostContentSettingsMap::RecordNumberOfExceptions() {
501 for (const content_settings::WebsiteSettingsInfo* info : 556 for (const content_settings::WebsiteSettingsInfo* info :
502 *content_settings::WebsiteSettingsRegistry::GetInstance()) { 557 *content_settings::WebsiteSettingsRegistry::GetInstance()) {
503 ContentSettingsType content_type = info->type(); 558 ContentSettingsType content_type = info->type();
504 const std::string type_name = info->name(); 559 const std::string type_name = info->name();
505 560
506 ContentSettingsForOneType settings; 561 ContentSettingsForOneType settings;
507 GetSettingsForOneType(content_type, std::string(), &settings); 562 GetSettingsForOneType(content_type, std::string(), &settings);
508 size_t num_exceptions = 0; 563 size_t num_exceptions = 0;
509 for (const ContentSettingPatternSource& setting_entry : settings) { 564 for (const ContentSettingPatternSource& setting_entry : settings) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 observers_, 702 observers_,
648 OnContentSettingChanged(primary_pattern, 703 OnContentSettingChanged(primary_pattern,
649 secondary_pattern, 704 secondary_pattern,
650 content_type, 705 content_type,
651 resource_identifier)); 706 resource_identifier));
652 } 707 }
653 708
654 HostContentSettingsMap::~HostContentSettingsMap() { 709 HostContentSettingsMap::~HostContentSettingsMap() {
655 DCHECK(!prefs_); 710 DCHECK(!prefs_);
656 STLDeleteValues(&content_settings_providers_); 711 STLDeleteValues(&content_settings_providers_);
712 syncable_prefs::PrefModelAssociator::ResetMergeDataFinishedCallback();
657 } 713 }
658 714
659 void HostContentSettingsMap::ShutdownOnUIThread() { 715 void HostContentSettingsMap::ShutdownOnUIThread() {
660 DCHECK(thread_checker_.CalledOnValidThread()); 716 DCHECK(thread_checker_.CalledOnValidThread());
661 DCHECK(prefs_); 717 DCHECK(prefs_);
662 prefs_ = NULL; 718 prefs_ = NULL;
663 for (ProviderIterator it = content_settings_providers_.begin(); 719 for (ProviderIterator it = content_settings_providers_.begin();
664 it != content_settings_providers_.end(); 720 it != content_settings_providers_.end();
665 ++it) { 721 ++it) {
666 it->second->ShutdownOnUIThread(); 722 it->second->ShutdownOnUIThread();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 rule.secondary_pattern.Matches(secondary_url)) { 902 rule.secondary_pattern.Matches(secondary_url)) {
847 if (primary_pattern) 903 if (primary_pattern)
848 *primary_pattern = rule.primary_pattern; 904 *primary_pattern = rule.primary_pattern;
849 if (secondary_pattern) 905 if (secondary_pattern)
850 *secondary_pattern = rule.secondary_pattern; 906 *secondary_pattern = rule.secondary_pattern;
851 return base::WrapUnique(rule.value.get()->DeepCopy()); 907 return base::WrapUnique(rule.value.get()->DeepCopy());
852 } 908 }
853 } 909 }
854 return std::unique_ptr<base::Value>(); 910 return std::unique_ptr<base::Value>();
855 } 911 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698