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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 } | 129 } |
| 130 | 130 |
| 131 content_settings::PatternPair GetPatternsFromScopingType( | 131 content_settings::PatternPair GetPatternsFromScopingType( |
| 132 WebsiteSettingsInfo::ScopingType scoping_type, | 132 WebsiteSettingsInfo::ScopingType scoping_type, |
| 133 const GURL& primary_url, | 133 const GURL& primary_url, |
| 134 const GURL& secondary_url) { | 134 const GURL& secondary_url) { |
| 135 DCHECK(!primary_url.is_empty()); | 135 DCHECK(!primary_url.is_empty()); |
| 136 content_settings::PatternPair patterns; | 136 content_settings::PatternPair patterns; |
| 137 | 137 |
| 138 switch (scoping_type) { | 138 switch (scoping_type) { |
| 139 case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: | 139 case WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE: |
| 140 case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE: | |
| 141 patterns.first = ContentSettingsPattern::FromURL(primary_url); | |
| 142 patterns.second = ContentSettingsPattern::Wildcard(); | |
| 143 break; | |
| 144 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: | 140 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: |
| 145 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); | 141 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| 146 patterns.second = ContentSettingsPattern::Wildcard(); | 142 patterns.second = ContentSettingsPattern::Wildcard(); |
| 147 break; | 143 break; |
| 148 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: | 144 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: |
| 149 DCHECK(!secondary_url.is_empty()); | 145 DCHECK(!secondary_url.is_empty()); |
| 150 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); | 146 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); |
| 151 patterns.second = | 147 patterns.second = |
| 152 ContentSettingsPattern::FromURLNoWildcard(secondary_url); | 148 ContentSettingsPattern::FromURLNoWildcard(secondary_url); |
| 153 break; | 149 break; |
| 154 } | 150 } |
| 155 return patterns; | 151 return patterns; |
| 156 } | 152 } |
| 157 | 153 |
| 158 } // namespace | 154 } // namespace |
| 159 | 155 |
| 160 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, | 156 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
| 161 bool is_incognito_profile, | 157 bool is_incognito_profile, |
| 162 bool is_guest_profile) | 158 bool is_guest_profile) |
| 163 : | 159 : |
| 164 #ifndef NDEBUG | 160 #ifndef NDEBUG |
| 165 used_from_thread_id_(base::PlatformThread::CurrentId()), | 161 used_from_thread_id_(base::PlatformThread::CurrentId()), |
| 166 #endif | 162 #endif |
| 167 prefs_(prefs), | 163 prefs_(prefs), |
| 168 is_off_the_record_(is_incognito_profile || is_guest_profile) { | 164 is_off_the_record_(is_incognito_profile || is_guest_profile), |
| 165 weak_ptr_factory_(this) { | |
| 169 DCHECK(!(is_incognito_profile && is_guest_profile)); | 166 DCHECK(!(is_incognito_profile && is_guest_profile)); |
| 170 | 167 |
| 171 content_settings::PolicyProvider* policy_provider = | 168 content_settings::PolicyProvider* policy_provider = |
| 172 new content_settings::PolicyProvider(prefs_); | 169 new content_settings::PolicyProvider(prefs_); |
| 173 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 170 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
| 174 policy_provider->AddObserver(this); | 171 policy_provider->AddObserver(this); |
| 175 | 172 |
| 176 pref_provider_ = | 173 pref_provider_ = |
| 177 new content_settings::PrefProvider(prefs_, is_off_the_record_); | 174 new content_settings::PrefProvider(prefs_, is_off_the_record_); |
| 178 content_settings_providers_[PREF_PROVIDER] = pref_provider_; | 175 content_settings_providers_[PREF_PROVIDER] = pref_provider_; |
| 179 pref_provider_->AddObserver(this); | 176 pref_provider_->AddObserver(this); |
| 180 | 177 |
| 181 // This ensures that content settings are cleared for the guest profile. This | 178 // This ensures that content settings are cleared for the guest profile. This |
| 182 // wouldn't be needed except that we used to allow settings to be stored for | 179 // wouldn't be needed except that we used to allow settings to be stored for |
| 183 // the guest profile and so we need to ensure those get cleared. | 180 // the guest profile and so we need to ensure those get cleared. |
| 184 if (is_guest_profile) | 181 if (is_guest_profile) |
| 185 pref_provider_->ClearPrefs(); | 182 pref_provider_->ClearPrefs(); |
| 186 | 183 |
| 187 content_settings::ObservableProvider* default_provider = | 184 content_settings::ObservableProvider* default_provider = |
| 188 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 185 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
| 189 default_provider->AddObserver(this); | 186 default_provider->AddObserver(this); |
| 190 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 187 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
| 191 | 188 |
| 192 MigrateKeygenSettings(); | 189 MigrateKeygenSettings(); |
| 193 | 190 MigrateDomainScopedSettings(false); |
|
raymes
2016/07/21 01:13:57
false /* after_sync */
lshang
2016/07/22 02:58:38
Done.
| |
| 194 RecordNumberOfExceptions(); | 191 RecordNumberOfExceptions(); |
| 195 } | 192 } |
| 196 | 193 |
| 197 // static | 194 // static |
| 198 void HostContentSettingsMap::RegisterProfilePrefs( | 195 void HostContentSettingsMap::RegisterProfilePrefs( |
| 199 user_prefs::PrefRegistrySyncable* registry) { | 196 user_prefs::PrefRegistrySyncable* registry) { |
| 200 // Ensure the content settings are all registered. | 197 // Ensure the content settings are all registered. |
| 201 content_settings::ContentSettingsRegistry::GetInstance(); | 198 content_settings::ContentSettingsRegistry::GetInstance(); |
| 202 | 199 |
| 203 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); | 200 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 | 590 |
| 594 if (status == NOT_MIGRATED) { | 591 if (status == NOT_MIGRATED) { |
| 595 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, | 592 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, |
| 596 DomainToOriginMigrationStatus::MIGRATED_BEFORE_SYNC); | 593 DomainToOriginMigrationStatus::MIGRATED_BEFORE_SYNC); |
| 597 } else if (status == MIGRATED_BEFORE_SYNC) { | 594 } else if (status == MIGRATED_BEFORE_SYNC) { |
| 598 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, | 595 prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, |
| 599 DomainToOriginMigrationStatus::MIGRATED_AFTER_SYNC); | 596 DomainToOriginMigrationStatus::MIGRATED_AFTER_SYNC); |
| 600 } | 597 } |
| 601 } | 598 } |
| 602 | 599 |
| 600 base::WeakPtr<HostContentSettingsMap> HostContentSettingsMap::GetWeakPtr() { | |
| 601 return weak_ptr_factory_.GetWeakPtr(); | |
| 602 } | |
| 603 | |
| 603 void HostContentSettingsMap::RecordNumberOfExceptions() { | 604 void HostContentSettingsMap::RecordNumberOfExceptions() { |
| 604 for (const content_settings::WebsiteSettingsInfo* info : | 605 for (const content_settings::WebsiteSettingsInfo* info : |
| 605 *content_settings::WebsiteSettingsRegistry::GetInstance()) { | 606 *content_settings::WebsiteSettingsRegistry::GetInstance()) { |
| 606 ContentSettingsType content_type = info->type(); | 607 ContentSettingsType content_type = info->type(); |
| 607 const std::string type_name = info->name(); | 608 const std::string type_name = info->name(); |
| 608 | 609 |
| 609 ContentSettingsForOneType settings; | 610 ContentSettingsForOneType settings; |
| 610 GetSettingsForOneType(content_type, std::string(), &settings); | 611 GetSettingsForOneType(content_type, std::string(), &settings); |
| 611 size_t num_exceptions = 0; | 612 size_t num_exceptions = 0; |
| 612 for (const ContentSettingPatternSource& setting_entry : settings) { | 613 for (const ContentSettingPatternSource& setting_entry : settings) { |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 rule.secondary_pattern.Matches(secondary_url)) { | 950 rule.secondary_pattern.Matches(secondary_url)) { |
| 950 if (primary_pattern) | 951 if (primary_pattern) |
| 951 *primary_pattern = rule.primary_pattern; | 952 *primary_pattern = rule.primary_pattern; |
| 952 if (secondary_pattern) | 953 if (secondary_pattern) |
| 953 *secondary_pattern = rule.secondary_pattern; | 954 *secondary_pattern = rule.secondary_pattern; |
| 954 return base::WrapUnique(rule.value.get()->DeepCopy()); | 955 return base::WrapUnique(rule.value.get()->DeepCopy()); |
| 955 } | 956 } |
| 956 } | 957 } |
| 957 return std::unique_ptr<base::Value>(); | 958 return std::unique_ptr<base::Value>(); |
| 958 } | 959 } |
| OLD | NEW |