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

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

Issue 1754073002: Migrate old settings for ContentSettingTypes with wildcard as secondary_pattern (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@scoping_set_content_setting
Patch Set: rebase Created 4 years, 9 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // This ensures that content settings are cleared for the guest profile. This 157 // This ensures that content settings are cleared for the guest profile. This
158 // wouldn't be needed except that we used to allow settings to be stored for 158 // wouldn't be needed except that we used to allow settings to be stored for
159 // the guest profile and so we need to ensure those get cleared. 159 // the guest profile and so we need to ensure those get cleared.
160 if (is_guest_profile) 160 if (is_guest_profile)
161 pref_provider->ClearPrefs(); 161 pref_provider->ClearPrefs();
162 162
163 content_settings::ObservableProvider* default_provider = 163 content_settings::ObservableProvider* default_provider =
164 new content_settings::DefaultProvider(prefs_, is_off_the_record_); 164 new content_settings::DefaultProvider(prefs_, is_off_the_record_);
165 default_provider->AddObserver(this); 165 default_provider->AddObserver(this);
166 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; 166 content_settings_providers_[DEFAULT_PROVIDER] = default_provider;
167
168 MigrateOldSettings();
167 } 169 }
168 170
169 // static 171 // static
170 void HostContentSettingsMap::RegisterProfilePrefs( 172 void HostContentSettingsMap::RegisterProfilePrefs(
171 user_prefs::PrefRegistrySyncable* registry) { 173 user_prefs::PrefRegistrySyncable* registry) {
172 // Ensure the content settings are all registered. 174 // Ensure the content settings are all registered.
173 content_settings::ContentSettingsRegistry::GetInstance(); 175 content_settings::ContentSettingsRegistry::GetInstance();
174 176
175 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); 177 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0);
176 178
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 primary_url, secondary_url); 460 primary_url, secondary_url);
459 ContentSettingsPattern primary_pattern = patterns.first; 461 ContentSettingsPattern primary_pattern = patterns.first;
460 ContentSettingsPattern secondary_pattern = patterns.second; 462 ContentSettingsPattern secondary_pattern = patterns.second;
461 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) 463 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid())
462 return; 464 return;
463 465
464 SetContentSetting(primary_pattern, secondary_pattern, content_type, 466 SetContentSetting(primary_pattern, secondary_pattern, content_type,
465 resource_identifier, setting); 467 resource_identifier, setting);
466 } 468 }
467 469
470 void HostContentSettingsMap::MigrateOldSettings() {
471 const ContentSettingsType kMigrateContentSettingTypes[] = {
472 // Only content types of scoping type: REQUESTING_DOMAIN_ONLY_SCOPE,
473 // REQUESTING_ORIGIN_ONLY_SCOPE and TOP_LEVEL_DOMAIN_ONLY_SCOPE need to be
474 // migrated.
475 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
476 };
477 for (const ContentSettingsType& type : kMigrateContentSettingTypes) {
478 WebsiteSettingsInfo::ScopingType scoping_type =
479 content_settings::ContentSettingsRegistry::GetInstance()
480 ->Get(type)
481 ->website_settings_info()
482 ->scoping_type();
483 if (scoping_type ==
484 WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE)
485 return;
raymes 2016/03/07 01:47:55 I think we should make this a DCHECK_NE (instead o
lshang 2016/03/23 13:58:36 Done.
486 ContentSettingsForOneType settings;
487 GetSettingsForOneType(type, std::string(), &settings);
488 for (const ContentSettingPatternSource& setting_entry : settings) {
489 // Migrate old-format settings only.
490 if (setting_entry.secondary_pattern !=
491 ContentSettingsPattern::Wildcard()) {
492 GURL url(setting_entry.primary_pattern.ToString());
493 // Pull out the value of the old-format setting. Only do this if the
494 // patterns are as we expect them to be, otherwise the setting will just
495 // be removed for safety.
496 ContentSetting content_setting = CONTENT_SETTING_DEFAULT;
497 if (setting_entry.primary_pattern == setting_entry.secondary_pattern &&
498 url.is_valid()) {
499 content_setting = GetContentSetting(url, url, type, std::string());
500 }
501 // Remove the old pattern.
502 SetContentSetting(setting_entry.primary_pattern,
503 setting_entry.secondary_pattern, type, std::string(),
504 CONTENT_SETTING_DEFAULT);
505 // Set the new pattern.
506 if (content_setting) {
raymes 2016/03/07 01:47:55 I think you can remove this check (the branch will
lshang 2016/03/23 13:58:36 Done.
507 SetContentSettingDefaultScope(url, GURL(), type, std::string(),
508 content_setting);
509 }
510 }
511 }
512 }
513 }
514
468 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( 515 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage(
469 const GURL& primary_url, 516 const GURL& primary_url,
470 const GURL& secondary_url, 517 const GURL& secondary_url,
471 ContentSettingsType content_type, 518 ContentSettingsType content_type,
472 const std::string& resource_identifier) { 519 const std::string& resource_identifier) {
473 DCHECK(thread_checker_.CalledOnValidThread()); 520 DCHECK(thread_checker_.CalledOnValidThread());
474 521
475 ContentSetting setting = GetContentSetting( 522 ContentSetting setting = GetContentSetting(
476 primary_url, secondary_url, content_type, resource_identifier); 523 primary_url, secondary_url, content_type, resource_identifier);
477 if (setting == CONTENT_SETTING_ALLOW) { 524 if (setting == CONTENT_SETTING_ALLOW) {
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 rule.secondary_pattern.Matches(secondary_url)) { 844 rule.secondary_pattern.Matches(secondary_url)) {
798 if (primary_pattern) 845 if (primary_pattern)
799 *primary_pattern = rule.primary_pattern; 846 *primary_pattern = rule.primary_pattern;
800 if (secondary_pattern) 847 if (secondary_pattern)
801 *secondary_pattern = rule.secondary_pattern; 848 *secondary_pattern = rule.secondary_pattern;
802 return make_scoped_ptr(rule.value.get()->DeepCopy()); 849 return make_scoped_ptr(rule.value.get()->DeepCopy());
803 } 850 }
804 } 851 }
805 return scoped_ptr<base::Value>(); 852 return scoped_ptr<base::Value>();
806 } 853 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698