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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 primary_url, secondary_url); | 434 primary_url, secondary_url); |
433 ContentSettingsPattern primary_pattern = patterns.first; | 435 ContentSettingsPattern primary_pattern = patterns.first; |
434 ContentSettingsPattern secondary_pattern = patterns.second; | 436 ContentSettingsPattern secondary_pattern = patterns.second; |
435 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) | 437 if (!primary_pattern.IsValid() || !secondary_pattern.IsValid()) |
436 return; | 438 return; |
437 | 439 |
438 SetContentSetting(primary_pattern, secondary_pattern, content_type, | 440 SetContentSetting(primary_pattern, secondary_pattern, content_type, |
439 resource_identifier, setting); | 441 resource_identifier, setting); |
440 } | 442 } |
441 | 443 |
| 444 void HostContentSettingsMap::MigrateOldSettings() { |
| 445 const ContentSettingsType kMigrateContentSettingTypes[] = { |
| 446 // Only content types of scoping type: REQUESTING_DOMAIN_ONLY_SCOPE, |
| 447 // REQUESTING_ORIGIN_ONLY_SCOPE and TOP_LEVEL_DOMAIN_ONLY_SCOPE need to be |
| 448 // migrated. |
| 449 CONTENT_SETTINGS_TYPE_KEYGEN}; |
| 450 for (const ContentSettingsType& type : kMigrateContentSettingTypes) { |
| 451 WebsiteSettingsInfo::ScopingType scoping_type = |
| 452 content_settings::ContentSettingsRegistry::GetInstance() |
| 453 ->Get(type) |
| 454 ->website_settings_info() |
| 455 ->scoping_type(); |
| 456 DCHECK_NE( |
| 457 scoping_type, |
| 458 WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE); |
| 459 |
| 460 ContentSettingsForOneType settings; |
| 461 GetSettingsForOneType(type, std::string(), &settings); |
| 462 for (const ContentSettingPatternSource& setting_entry : settings) { |
| 463 // Migrate user preference settings only. |
| 464 if (setting_entry.source != "preference") |
| 465 continue; |
| 466 // Migrate old-format settings only. |
| 467 if (setting_entry.secondary_pattern != |
| 468 ContentSettingsPattern::Wildcard()) { |
| 469 GURL url(setting_entry.primary_pattern.ToString()); |
| 470 // Pull out the value of the old-format setting. Only do this if the |
| 471 // patterns are as we expect them to be, otherwise the setting will just |
| 472 // be removed for safety. |
| 473 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; |
| 474 if (setting_entry.primary_pattern == setting_entry.secondary_pattern && |
| 475 url.is_valid()) { |
| 476 content_setting = GetContentSetting(url, url, type, std::string()); |
| 477 } |
| 478 // Remove the old pattern. |
| 479 SetContentSetting(setting_entry.primary_pattern, |
| 480 setting_entry.secondary_pattern, type, std::string(), |
| 481 CONTENT_SETTING_DEFAULT); |
| 482 // Set the new pattern. |
| 483 SetContentSettingDefaultScope(url, GURL(), type, std::string(), |
| 484 content_setting); |
| 485 } |
| 486 } |
| 487 } |
| 488 } |
| 489 |
442 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | 490 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
443 const GURL& primary_url, | 491 const GURL& primary_url, |
444 const GURL& secondary_url, | 492 const GURL& secondary_url, |
445 ContentSettingsType content_type, | 493 ContentSettingsType content_type, |
446 const std::string& resource_identifier) { | 494 const std::string& resource_identifier) { |
447 DCHECK(thread_checker_.CalledOnValidThread()); | 495 DCHECK(thread_checker_.CalledOnValidThread()); |
448 | 496 |
449 ContentSetting setting = GetContentSetting( | 497 ContentSetting setting = GetContentSetting( |
450 primary_url, secondary_url, content_type, resource_identifier); | 498 primary_url, secondary_url, content_type, resource_identifier); |
451 if (setting == CONTENT_SETTING_ALLOW) { | 499 if (setting == CONTENT_SETTING_ALLOW) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 rule.secondary_pattern.Matches(secondary_url)) { | 819 rule.secondary_pattern.Matches(secondary_url)) { |
772 if (primary_pattern) | 820 if (primary_pattern) |
773 *primary_pattern = rule.primary_pattern; | 821 *primary_pattern = rule.primary_pattern; |
774 if (secondary_pattern) | 822 if (secondary_pattern) |
775 *secondary_pattern = rule.secondary_pattern; | 823 *secondary_pattern = rule.secondary_pattern; |
776 return make_scoped_ptr(rule.value.get()->DeepCopy()); | 824 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
777 } | 825 } |
778 } | 826 } |
779 return scoped_ptr<base::Value>(); | 827 return scoped_ptr<base::Value>(); |
780 } | 828 } |
OLD | NEW |