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 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 sync | |
|
raymes
2016/07/25 03:56:38
nit: and after sync is finished. No migration will
lshang
2016/07/25 04:51:09
Done.
| |
| 74 // process(this is a clean up after sync). Migration is all finished at this | |
| 75 // stage. | |
| 76 MIGRATED_AFTER_SYNC, | |
| 77 }; | |
| 78 | |
| 61 static_assert( | 79 static_assert( |
| 62 arraysize(kProviderNamesSourceMap) == | 80 arraysize(kProviderNamesSourceMap) == |
| 63 HostContentSettingsMap::NUM_PROVIDER_TYPES, | 81 HostContentSettingsMap::NUM_PROVIDER_TYPES, |
| 64 "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements"); | 82 "kProviderNamesSourceMap should have NUM_PROVIDER_TYPES elements"); |
| 65 | 83 |
| 66 // Returns true if the |content_type| supports a resource identifier. | 84 // Returns true if the |content_type| supports a resource identifier. |
| 67 // Resource identifiers are supported (but not required) for plugins. | 85 // Resource identifiers are supported (but not required) for plugins. |
| 68 bool SupportsResourceIdentifier(ContentSettingsType content_type) { | 86 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
| 69 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; | 87 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
| 70 } | 88 } |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 176 RecordNumberOfExceptions(); | 194 RecordNumberOfExceptions(); |
| 177 } | 195 } |
| 178 | 196 |
| 179 // static | 197 // static |
| 180 void HostContentSettingsMap::RegisterProfilePrefs( | 198 void HostContentSettingsMap::RegisterProfilePrefs( |
| 181 user_prefs::PrefRegistrySyncable* registry) { | 199 user_prefs::PrefRegistrySyncable* registry) { |
| 182 // Ensure the content settings are all registered. | 200 // Ensure the content settings are all registered. |
| 183 content_settings::ContentSettingsRegistry::GetInstance(); | 201 content_settings::ContentSettingsRegistry::GetInstance(); |
| 184 | 202 |
| 185 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); | 203 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
| 204 registry->RegisterIntegerPref(prefs::kDomainToOriginMigrationStatus, | |
| 205 DomainToOriginMigrationStatus::NOT_MIGRATED); | |
| 186 | 206 |
| 187 // Register the prefs for the content settings providers. | 207 // Register the prefs for the content settings providers. |
| 188 content_settings::DefaultProvider::RegisterProfilePrefs(registry); | 208 content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
| 189 content_settings::PrefProvider::RegisterProfilePrefs(registry); | 209 content_settings::PrefProvider::RegisterProfilePrefs(registry); |
| 190 content_settings::PolicyProvider::RegisterProfilePrefs(registry); | 210 content_settings::PolicyProvider::RegisterProfilePrefs(registry); |
| 191 } | 211 } |
| 192 | 212 |
| 193 void HostContentSettingsMap::RegisterProvider( | 213 void HostContentSettingsMap::RegisterProvider( |
| 194 ProviderType type, | 214 ProviderType type, |
| 195 std::unique_ptr<content_settings::ObservableProvider> provider) { | 215 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, | 510 CONTENT_SETTINGS_TYPE_KEYGEN, |
| 491 std::string(), CONTENT_SETTING_DEFAULT); | 511 std::string(), CONTENT_SETTING_DEFAULT); |
| 492 // Set the new pattern. | 512 // Set the new pattern. |
| 493 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, | 513 SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, |
| 494 std::string(), content_setting); | 514 std::string(), content_setting); |
| 495 } | 515 } |
| 496 } | 516 } |
| 497 } | 517 } |
| 498 } | 518 } |
| 499 | 519 |
| 500 void HostContentSettingsMap::MigrateDomainScopedSettings() { | 520 void HostContentSettingsMap::MigrateDomainScopedSettings(bool after_sync) { |
| 521 int status = prefs_->GetInteger(prefs::kDomainToOriginMigrationStatus); | |
| 522 if (status == MIGRATED_AFTER_SYNC) | |
| 523 return; | |
| 524 if (status == MIGRATED_BEFORE_SYNC && !after_sync) | |
| 525 return; | |
| 526 DCHECK(status != NOT_MIGRATED || !after_sync); | |
| 527 | |
| 501 const ContentSettingsType kDomainScopedTypes[] = { | 528 const ContentSettingsType kDomainScopedTypes[] = { |
| 502 CONTENT_SETTINGS_TYPE_COOKIES, | 529 CONTENT_SETTINGS_TYPE_COOKIES, |
| 503 CONTENT_SETTINGS_TYPE_IMAGES, | 530 CONTENT_SETTINGS_TYPE_IMAGES, |
| 504 CONTENT_SETTINGS_TYPE_PLUGINS, | 531 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 505 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 532 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 506 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 533 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 507 CONTENT_SETTINGS_TYPE_POPUPS}; | 534 CONTENT_SETTINGS_TYPE_POPUPS}; |
| 508 for (const ContentSettingsType& type : kDomainScopedTypes) { | 535 for (const ContentSettingsType& type : kDomainScopedTypes) { |
| 509 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type)) | 536 if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type)) |
| 510 continue; | 537 continue; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 555 | 582 |
| 556 // If the current resolved content setting is allowed it's safe to set the | 583 // If the current resolved content setting is allowed it's safe to set the |
| 557 // origin-scoped pattern. | 584 // origin-scoped pattern. |
| 558 if (origin_setting == CONTENT_SETTING_ALLOW) | 585 if (origin_setting == CONTENT_SETTING_ALLOW) |
| 559 SetContentSettingCustomScope( | 586 SetContentSettingCustomScope( |
| 560 ContentSettingsPattern::FromURLNoWildcard(origin), | 587 ContentSettingsPattern::FromURLNoWildcard(origin), |
| 561 ContentSettingsPattern::Wildcard(), type, std::string(), | 588 ContentSettingsPattern::Wildcard(), type, std::string(), |
| 562 CONTENT_SETTING_ALLOW); | 589 CONTENT_SETTING_ALLOW); |
| 563 } | 590 } |
| 564 } | 591 } |
| 592 | |
| 593 if (status == NOT_MIGRATED) { | |
| 594 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, | |
| 595 DomainToOriginMigrationStatus::MIGRATED_BEFORE_SYNC); | |
|
raymes
2016/07/25 03:56:38
nit: no need for the DomainToOriginMigrationStatus
lshang
2016/07/25 04:51:09
Done.
| |
| 596 } else if (status == MIGRATED_BEFORE_SYNC) { | |
| 597 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, | |
| 598 DomainToOriginMigrationStatus::MIGRATED_AFTER_SYNC); | |
| 599 } | |
| 565 } | 600 } |
| 566 | 601 |
| 567 void HostContentSettingsMap::RecordNumberOfExceptions() { | 602 void HostContentSettingsMap::RecordNumberOfExceptions() { |
| 568 for (const content_settings::WebsiteSettingsInfo* info : | 603 for (const content_settings::WebsiteSettingsInfo* info : |
| 569 *content_settings::WebsiteSettingsRegistry::GetInstance()) { | 604 *content_settings::WebsiteSettingsRegistry::GetInstance()) { |
| 570 ContentSettingsType content_type = info->type(); | 605 ContentSettingsType content_type = info->type(); |
| 571 const std::string type_name = info->name(); | 606 const std::string type_name = info->name(); |
| 572 | 607 |
| 573 ContentSettingsForOneType settings; | 608 ContentSettingsForOneType settings; |
| 574 GetSettingsForOneType(content_type, std::string(), &settings); | 609 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)) { | 948 rule.secondary_pattern.Matches(secondary_url)) { |
| 914 if (primary_pattern) | 949 if (primary_pattern) |
| 915 *primary_pattern = rule.primary_pattern; | 950 *primary_pattern = rule.primary_pattern; |
| 916 if (secondary_pattern) | 951 if (secondary_pattern) |
| 917 *secondary_pattern = rule.secondary_pattern; | 952 *secondary_pattern = rule.secondary_pattern; |
| 918 return base::WrapUnique(rule.value.get()->DeepCopy()); | 953 return base::WrapUnique(rule.value.get()->DeepCopy()); |
| 919 } | 954 } |
| 920 } | 955 } |
| 921 return std::unique_ptr<base::Value>(); | 956 return std::unique_ptr<base::Value>(); |
| 922 } | 957 } |
| OLD | NEW |