| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 | 51 |
| 52 const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = { | 52 const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = { |
| 53 {"platform_app", content_settings::SETTING_SOURCE_EXTENSION}, | 53 {"platform_app", content_settings::SETTING_SOURCE_EXTENSION}, |
| 54 {"policy", content_settings::SETTING_SOURCE_POLICY}, | 54 {"policy", content_settings::SETTING_SOURCE_POLICY}, |
| 55 {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED}, | 55 {"supervised_user", content_settings::SETTING_SOURCE_SUPERVISED}, |
| 56 {"extension", content_settings::SETTING_SOURCE_EXTENSION}, | 56 {"extension", content_settings::SETTING_SOURCE_EXTENSION}, |
| 57 {"preference", content_settings::SETTING_SOURCE_USER}, | 57 {"preference", content_settings::SETTING_SOURCE_USER}, |
| 58 {"default", content_settings::SETTING_SOURCE_USER}, | 58 {"default", content_settings::SETTING_SOURCE_USER}, |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Enum describing the status of domain to origin migration of content settings. |
| 62 // Migration will be done twice: once upon construction of the |
| 63 // HostContentSettingsMap (before syncing any content settings) and once after |
| 64 // sync has finished. We always migrate before sync to ensure that settings will |
| 65 // get migrated even if a user doesn't have sync enabled. We migrate after sync |
| 66 // to ensure that any sync'd settings will be migrated. Once these events have |
| 67 // occurred, we won't perform migration again. |
| 68 enum DomainToOriginMigrationStatus { |
| 69 // Haven't been migrated at all. |
| 70 NOT_MIGRATED, |
| 71 // Have done migration in the constructor of HostContentSettingsMap. |
| 72 MIGRATED_BEFORE_SYNC, |
| 73 // Have done migration both in HostContentSettingsMap construction and and |
| 74 // after sync is finished. No migration will happen after this point. |
| 75 MIGRATED_AFTER_SYNC, |
| 76 }; |
| 77 |
| 61 static_assert( | 78 static_assert( |
| 62 arraysize(kProviderNamesSourceMap) == | 79 arraysize(kProviderNamesSourceMap) == |
| 63 HostContentSettingsMap::NUM_PROVIDER_TYPES, | 80 HostContentSettingsMap::NUM_PROVIDER_TYPES, |
| 64 "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements"); | 81 "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements"); |
| 65 | 82 |
| 66 // Returns true if the |content_type| supports a resource identifier. | 83 // Returns true if the |content_type| supports a resource identifier. |
| 67 // Resource identifiers are supported (but not required) for plugins. | 84 // Resource identifiers are supported (but not required) for plugins. |
| 68 bool SupportsResourceIdentifier(ContentSettingsType content_type) { | 85 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
| 69 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 86 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
| 70 } | 87 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 RecordNumberOfExceptions(); | 193 RecordNumberOfExceptions(); |
| 177 } | 194 } |
| 178 | 195 |
| 179 // static | 196 // static |
| 180 void HostContentSettingsMap::RegisterProfilePrefs( | 197 void HostContentSettingsMap::RegisterProfilePrefs( |
| 181 user_prefs::PrefRegistrySyncable* registry) { | 198 user_prefs::PrefRegistrySyncable* registry) { |
| 182 // Ensure the content settings are all registered. | 199 // Ensure the content settings are all registered. |
| 183 content_settings::ContentSettingsRegistry::GetInstance(); | 200 content_settings::ContentSettingsRegistry::GetInstance(); |
| 184 | 201 |
| 185 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); | 202 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
| 203 registry->RegisterIntegerPref(prefs::kDomainToOriginMigrationStatus, |
| 204 NOT_MIGRATED); |
| 186 | 205 |
| 187 // Register the prefs for the content settings providers. | 206 // Register the prefs for the content settings providers. |
| 188 content_settings::DefaultProvider::RegisterProfilePrefs(registry); | 207 content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
| 189 content_settings::PrefProvider::RegisterProfilePrefs(registry); | 208 content_settings::PrefProvider::RegisterProfilePrefs(registry); |
| 190 content_settings::PolicyProvider::RegisterProfilePrefs(registry); | 209 content_settings::PolicyProvider::RegisterProfilePrefs(registry); |
| 191 } | 210 } |
| 192 | 211 |
| 193 void HostContentSettingsMap::RegisterProvider( | 212 void HostContentSettingsMap::RegisterProvider( |
| 194 ProviderType type, | 213 ProviderType type, |
| 195 std::unique_ptr<content_settings::ObservableProvider> provider) { | 214 std::unique_ptr<content_settings::ObservableProvider> provider) { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 CONTENT_SETTINGS_TYPE_KEYGEN, | 509 CONTENT_SETTINGS_TYPE_KEYGEN, |
| 491 std::string(), CONTENT_SETTING_DEFAULT); | 510 std::string(), CONTENT_SETTING_DEFAULT); |
| 492 // Set the new pattern. | 511 // Set the new pattern. |
| 493 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, | 512 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, |
| 494 std::string(), content_setting); | 513 std::string(), content_setting); |
| 495 } | 514 } |
| 496 } | 515 } |
| 497 } | 516 } |
| 498 } | 517 } |
| 499 | 518 |
| 500 void HostContentSettingsMap::MigrateDomainScopedSettings() { | 519 void HostContentSettingsMap::MigrateDomainScopedSettings(bool after_sync) { |
| 520 DomainToOriginMigrationStatus status = |
| 521 static_cast<DomainToOriginMigrationStatus>( |
| 522 prefs_->GetInteger(prefs::kDomainToOriginMigrationStatus)); |
| 523 if (status == MIGRATED_AFTER_SYNC) |
| 524 return; |
| 525 if (status == MIGRATED_BEFORE_SYNC && !after_sync) |
| 526 return; |
| 527 DCHECK(status != NOT_MIGRATED || !after_sync); |
| 528 |
| 501 const ContentSettingsType kDomainScopedTypes[] = { | 529 const ContentSettingsType kDomainScopedTypes[] = { |
| 502 CONTENT_SETTINGS_TYPE_COOKIES, | 530 CONTENT_SETTINGS_TYPE_COOKIES, |
| 503 CONTENT_SETTINGS_TYPE_IMAGES, | 531 CONTENT_SETTINGS_TYPE_IMAGES, |
| 504 CONTENT_SETTINGS_TYPE_PLUGINS, | 532 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 505 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 533 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 506 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 534 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 507 CONTENT_SETTINGS_TYPE_POPUPS}; | 535 CONTENT_SETTINGS_TYPE_POPUPS}; |
| 508 for (const ContentSettingsType& type : kDomainScopedTypes) { | 536 for (const ContentSettingsType& type : kDomainScopedTypes) { |
| 509 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type)) | 537 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type)) |
| 510 continue; | 538 continue; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 | 583 |
| 556 // If the current resolved content setting is allowed it's safe to set the | 584 // If the current resolved content setting is allowed it's safe to set the |
| 557 // origin-scoped pattern. | 585 // origin-scoped pattern. |
| 558 if (origin_setting == CONTENT_SETTING_ALLOW) | 586 if (origin_setting == CONTENT_SETTING_ALLOW) |
| 559 SetContentSettingCustomScope( | 587 SetContentSettingCustomScope( |
| 560 ContentSettingsPattern::FromURLNoWildcard(origin), | 588 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 561 ContentSettingsPattern::Wildcard(), type, std::string(), | 589 ContentSettingsPattern::Wildcard(), type, std::string(), |
| 562 CONTENT_SETTING_ALLOW); | 590 CONTENT_SETTING_ALLOW); |
| 563 } | 591 } |
| 564 } | 592 } |
| 593 |
| 594 if (status == NOT_MIGRATED) { |
| 595 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, |
| 596 MIGRATED_BEFORE_SYNC); |
| 597 } else if (status == MIGRATED_BEFORE_SYNC) { |
| 598 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, |
| 599 MIGRATED_AFTER_SYNC); |
| 600 } |
| 565 } | 601 } |
| 566 | 602 |
| 567 void HostContentSettingsMap::RecordNumberOfExceptions() { | 603 void HostContentSettingsMap::RecordNumberOfExceptions() { |
| 568 for (const content_settings::WebsiteSettingsInfo* info : | 604 for (const content_settings::WebsiteSettingsInfo* info : |
| 569 *content_settings::WebsiteSettingsRegistry::GetInstance()) { | 605 *content_settings::WebsiteSettingsRegistry::GetInstance()) { |
| 570 ContentSettingsType content_type = info->type(); | 606 ContentSettingsType content_type = info->type(); |
| 571 const std::string type_name = info->name(); | 607 const std::string type_name = info->name(); |
| 572 | 608 |
| 573 ContentSettingsForOneType settings; | 609 ContentSettingsForOneType settings; |
| 574 GetSettingsForOneType(content_type, std::string(), &settings); | 610 GetSettingsForOneType(content_type, std::string(), &settings); |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 rule.secondary_pattern.Matches(secondary_url)) { | 949 rule.secondary_pattern.Matches(secondary_url)) { |
| 914 if (primary_pattern) | 950 if (primary_pattern) |
| 915 *primary_pattern = rule.primary_pattern; | 951 *primary_pattern = rule.primary_pattern; |
| 916 if (secondary_pattern) | 952 if (secondary_pattern) |
| 917 *secondary_pattern = rule.secondary_pattern; | 953 *secondary_pattern = rule.secondary_pattern; |
| 918 return base::WrapUnique(rule.value.get()->DeepCopy()); | 954 return base::WrapUnique(rule.value.get()->DeepCopy()); |
| 919 } | 955 } |
| 920 } | 956 } |
| 921 return std::unique_ptr<base::Value>(); | 957 return std::unique_ptr<base::Value>(); |
| 922 } | 958 } |
| OLD | NEW |