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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 // This ensures that content settings are cleared for the guest profile. This | 159 // This ensures that content settings are cleared for the guest profile. This |
160 // wouldn't be needed except that we used to allow settings to be stored for | 160 // wouldn't be needed except that we used to allow settings to be stored for |
161 // the guest profile and so we need to ensure those get cleared. | 161 // the guest profile and so we need to ensure those get cleared. |
162 if (is_guest_profile) | 162 if (is_guest_profile) |
163 pref_provider->ClearPrefs(); | 163 pref_provider->ClearPrefs(); |
164 | 164 |
165 content_settings::ObservableProvider* default_provider = | 165 content_settings::ObservableProvider* default_provider = |
166 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 166 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
167 default_provider->AddObserver(this); | 167 default_provider->AddObserver(this); |
168 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 168 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
| 169 |
| 170 MigrateOldSettings(); |
169 } | 171 } |
170 | 172 |
171 // static | 173 // static |
172 void HostContentSettingsMap::RegisterProfilePrefs( | 174 void HostContentSettingsMap::RegisterProfilePrefs( |
173 user_prefs::PrefRegistrySyncable* registry) { | 175 user_prefs::PrefRegistrySyncable* registry) { |
174 // Ensure the content settings are all registered. | 176 // Ensure the content settings are all registered. |
175 content_settings::ContentSettingsRegistry::GetInstance(); | 177 content_settings::ContentSettingsRegistry::GetInstance(); |
176 | 178 |
177 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); | 179 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
178 | 180 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 primary_url, secondary_url); | 462 primary_url, secondary_url); |
461 ContentSettingsPattern primary_pattern = patterns.first; | 463 ContentSettingsPattern primary_pattern = patterns.first; |
462 ContentSettingsPattern secondary_pattern = patterns.second; | 464 ContentSettingsPattern secondary_pattern = patterns.second; |
463 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) | 465 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) |
464 return; | 466 return; |
465 | 467 |
466 SetContentSetting(primary_pattern, secondary_pattern, content_type, | 468 SetContentSetting(primary_pattern, secondary_pattern, content_type, |
467 resource_identifier, setting); | 469 resource_identifier, setting); |
468 } | 470 } |
469 | 471 |
| 472 void HostContentSettingsMap::MigrateOldSettings() { |
| 473 const ContentSettingsType kMigrateContentSettingTypes[] = { |
| 474 // Only content types of scoping type: REQUESTING_DOMAIN_ONLY_SCOPE, |
| 475 // REQUESTING_ORIGIN_ONLY_SCOPE and TOP_LEVEL_DOMAIN_ONLY_SCOPE need to be |
| 476 // migrated. |
| 477 CONTENT_SETTINGS_TYPE_KEYGEN}; |
| 478 for (const ContentSettingsType& type : kMigrateContentSettingTypes) { |
| 479 WebsiteSettingsInfo::ScopingType scoping_type = |
| 480 content_settings::ContentSettingsRegistry::GetInstance() |
| 481 ->Get(type) |
| 482 ->website_settings_info() |
| 483 ->scoping_type(); |
| 484 DCHECK_NE( |
| 485 scoping_type, |
| 486 WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE); |
| 487 |
| 488 ContentSettingsForOneType settings; |
| 489 GetSettingsForOneType(type, std::string(), &settings); |
| 490 for (const ContentSettingPatternSource& setting_entry : settings) { |
| 491 // Migrate user preference settings only. |
| 492 if (setting_entry.source != "preference") |
| 493 continue; |
| 494 // Migrate old-format settings only. |
| 495 if (setting_entry.secondary_pattern != |
| 496 ContentSettingsPattern::Wildcard()) { |
| 497 GURL url(setting_entry.primary_pattern.ToString()); |
| 498 // Pull out the value of the old-format setting. Only do this if the |
| 499 // patterns are as we expect them to be, otherwise the setting will just |
| 500 // be removed for safety. |
| 501 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; |
| 502 if (setting_entry.primary_pattern == setting_entry.secondary_pattern && |
| 503 url.is_valid()) { |
| 504 content_setting = GetContentSetting(url, url, type, std::string()); |
| 505 } |
| 506 // Remove the old pattern. |
| 507 SetContentSetting(setting_entry.primary_pattern, |
| 508 setting_entry.secondary_pattern, type, std::string(), |
| 509 CONTENT_SETTING_DEFAULT); |
| 510 // Set the new pattern. |
| 511 SetContentSettingDefaultScope(url, GURL(), type, std::string(), |
| 512 content_setting); |
| 513 } |
| 514 } |
| 515 } |
| 516 } |
| 517 |
470 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | 518 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
471 const GURL& primary_url, | 519 const GURL& primary_url, |
472 const GURL& secondary_url, | 520 const GURL& secondary_url, |
473 ContentSettingsType content_type, | 521 ContentSettingsType content_type, |
474 const std::string& resource_identifier) { | 522 const std::string& resource_identifier) { |
475 DCHECK(thread_checker_.CalledOnValidThread()); | 523 DCHECK(thread_checker_.CalledOnValidThread()); |
476 | 524 |
477 ContentSetting setting = GetContentSetting( | 525 ContentSetting setting = GetContentSetting( |
478 primary_url, secondary_url, content_type, resource_identifier); | 526 primary_url, secondary_url, content_type, resource_identifier); |
479 if (setting == CONTENT_SETTING_ALLOW) { | 527 if (setting == CONTENT_SETTING_ALLOW) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 rule.secondary_pattern.Matches(secondary_url)) { | 847 rule.secondary_pattern.Matches(secondary_url)) { |
800 if (primary_pattern) | 848 if (primary_pattern) |
801 *primary_pattern = rule.primary_pattern; | 849 *primary_pattern = rule.primary_pattern; |
802 if (secondary_pattern) | 850 if (secondary_pattern) |
803 *secondary_pattern = rule.secondary_pattern; | 851 *secondary_pattern = rule.secondary_pattern; |
804 return make_scoped_ptr(rule.value.get()->DeepCopy()); | 852 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
805 } | 853 } |
806 } | 854 } |
807 return scoped_ptr<base::Value>(); | 855 return scoped_ptr<base::Value>(); |
808 } | 856 } |
OLD | NEW |