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 | |
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 if (status == NOT_MIGRATED && after_sync) | |
raymes
2016/07/21 00:58:54
This should never happen, right? I think this shou
lshang
2016/07/22 01:33:07
Done.
| |
527 return; | |
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 DomainToOriginMigrationStatus::MIGRATED_BEFORE_SYNC); | |
597 } else if (status == MIGRATED_BEFORE_SYNC) { | |
598 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, | |
599 DomainToOriginMigrationStatus::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 |