Chromium Code Reviews| 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 // TODO(lshang): Default is temporarily added here to pass the array size | |
| 478 // 0 | |
|
raymes
2016/03/29 04:43:46
nit: fill 80chars
lshang
2016/03/29 05:02:30
Done.
| |
| 479 // error. Will add types that need to be migrated later. | |
| 480 CONTENT_SETTINGS_TYPE_DEFAULT}; | |
|
raymes
2016/03/29 04:43:46
Maybe just put KEYGEN in this CL?
lshang
2016/03/29 05:02:30
Done.
| |
| 481 for (const ContentSettingsType& type : kMigrateContentSettingTypes) { | |
| 482 if (type == CONTENT_SETTINGS_TYPE_DEFAULT) | |
| 483 break; | |
| 484 WebsiteSettingsInfo::ScopingType scoping_type = | |
| 485 content_settings::ContentSettingsRegistry::GetInstance() | |
| 486 ->Get(type) | |
| 487 ->website_settings_info() | |
| 488 ->scoping_type(); | |
| 489 DCHECK_NE( | |
| 490 scoping_type, | |
| 491 WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE); | |
| 492 | |
| 493 ContentSettingsForOneType settings; | |
| 494 GetSettingsForOneType(type, std::string(), &settings); | |
| 495 for (const ContentSettingPatternSource& setting_entry : settings) { | |
| 496 // Migrate user preference settings only. | |
| 497 if (setting_entry.source != "preference") | |
| 498 continue; | |
| 499 // Migrate old-format settings only. | |
| 500 if (setting_entry.secondary_pattern != | |
| 501 ContentSettingsPattern::Wildcard()) { | |
| 502 GURL url(setting_entry.primary_pattern.ToString()); | |
| 503 // Pull out the value of the old-format setting. Only do this if the | |
| 504 // patterns are as we expect them to be, otherwise the setting will just | |
| 505 // be removed for safety. | |
| 506 ContentSetting content_setting = CONTENT_SETTING_DEFAULT; | |
| 507 if (setting_entry.primary_pattern == setting_entry.secondary_pattern && | |
| 508 url.is_valid()) { | |
| 509 content_setting = GetContentSetting(url, url, type, std::string()); | |
| 510 } | |
| 511 // Remove the old pattern. | |
| 512 SetContentSetting(setting_entry.primary_pattern, | |
| 513 setting_entry.secondary_pattern, type, std::string(), | |
| 514 CONTENT_SETTING_DEFAULT); | |
| 515 // Set the new pattern. | |
| 516 SetContentSettingDefaultScope(url, GURL(), type, std::string(), | |
| 517 content_setting); | |
| 518 } | |
| 519 } | |
| 520 } | |
| 521 } | |
| 522 | |
| 470 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( | 523 ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
| 471 const GURL& primary_url, | 524 const GURL& primary_url, |
| 472 const GURL& secondary_url, | 525 const GURL& secondary_url, |
| 473 ContentSettingsType content_type, | 526 ContentSettingsType content_type, |
| 474 const std::string& resource_identifier) { | 527 const std::string& resource_identifier) { |
| 475 DCHECK(thread_checker_.CalledOnValidThread()); | 528 DCHECK(thread_checker_.CalledOnValidThread()); |
| 476 | 529 |
| 477 ContentSetting setting = GetContentSetting( | 530 ContentSetting setting = GetContentSetting( |
| 478 primary_url, secondary_url, content_type, resource_identifier); | 531 primary_url, secondary_url, content_type, resource_identifier); |
| 479 if (setting == CONTENT_SETTING_ALLOW) { | 532 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)) { | 852 rule.secondary_pattern.Matches(secondary_url)) { |
| 800 if (primary_pattern) | 853 if (primary_pattern) |
| 801 *primary_pattern = rule.primary_pattern; | 854 *primary_pattern = rule.primary_pattern; |
| 802 if (secondary_pattern) | 855 if (secondary_pattern) |
| 803 *secondary_pattern = rule.secondary_pattern; | 856 *secondary_pattern = rule.secondary_pattern; |
| 804 return make_scoped_ptr(rule.value.get()->DeepCopy()); | 857 return make_scoped_ptr(rule.value.get()->DeepCopy()); |
| 805 } | 858 } |
| 806 } | 859 } |
| 807 return scoped_ptr<base::Value>(); | 860 return scoped_ptr<base::Value>(); |
| 808 } | 861 } |
| OLD | NEW |