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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 } | 111 } |
112 | 112 |
113 content_settings::PatternPair GetPatternsFromScopingType( | 113 content_settings::PatternPair GetPatternsFromScopingType( |
114 WebsiteSettingsInfo::ScopingType scoping_type, | 114 WebsiteSettingsInfo::ScopingType scoping_type, |
115 const GURL& primary_url, | 115 const GURL& primary_url, |
116 const GURL& secondary_url) { | 116 const GURL& secondary_url) { |
117 DCHECK(!primary_url.is_empty()); | 117 DCHECK(!primary_url.is_empty()); |
118 content_settings::PatternPair patterns; | 118 content_settings::PatternPair patterns; |
119 | 119 |
120 switch (scoping_type) { | 120 switch (scoping_type) { |
121 case WebsiteSettingsInfo::TOP_LEVEL_DOMAIN_ONLY_SCOPE: | 121 case WebsiteSettingsInfo::TOP_LEVEL_ORIGIN_ONLY_SCOPE: |
122 case WebsiteSettingsInfo::REQUESTING_DOMAIN_ONLY_SCOPE: | |
123 patterns.first = ContentSettingsPattern::FromURL(primary_url); | |
124 patterns.second = ContentSettingsPattern::Wildcard(); | |
125 break; | |
126 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: | 122 case WebsiteSettingsInfo::REQUESTING_ORIGIN_ONLY_SCOPE: |
127 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); | 123 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); |
128 patterns.second = ContentSettingsPattern::Wildcard(); | 124 patterns.second = ContentSettingsPattern::Wildcard(); |
129 break; | 125 break; |
130 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: | 126 case WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE: |
131 DCHECK(!secondary_url.is_empty()); | 127 DCHECK(!secondary_url.is_empty()); |
132 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); | 128 patterns.first = ContentSettingsPattern::FromURLNoWildcard(primary_url); |
133 patterns.second = | 129 patterns.second = |
134 ContentSettingsPattern::FromURLNoWildcard(secondary_url); | 130 ContentSettingsPattern::FromURLNoWildcard(secondary_url); |
135 break; | 131 break; |
136 } | 132 } |
137 return patterns; | 133 return patterns; |
138 } | 134 } |
139 | 135 |
140 } // namespace | 136 } // namespace |
141 | 137 |
142 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, | 138 HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
143 bool is_incognito_profile, | 139 bool is_incognito_profile, |
144 bool is_guest_profile) | 140 bool is_guest_profile) |
145 : | 141 : |
146 #ifndef NDEBUG | 142 #ifndef NDEBUG |
147 used_from_thread_id_(base::PlatformThread::CurrentId()), | 143 used_from_thread_id_(base::PlatformThread::CurrentId()), |
148 #endif | 144 #endif |
149 prefs_(prefs), | 145 prefs_(prefs), |
150 is_off_the_record_(is_incognito_profile || is_guest_profile) { | 146 is_off_the_record_(is_incognito_profile || is_guest_profile), |
| 147 weak_ptr_factory_(this) { |
151 DCHECK(!(is_incognito_profile && is_guest_profile)); | 148 DCHECK(!(is_incognito_profile && is_guest_profile)); |
152 | 149 |
153 content_settings::PolicyProvider* policy_provider = | 150 content_settings::PolicyProvider* policy_provider = |
154 new content_settings::PolicyProvider(prefs_); | 151 new content_settings::PolicyProvider(prefs_); |
155 content_settings_providers_[POLICY_PROVIDER] = policy_provider; | 152 content_settings_providers_[POLICY_PROVIDER] = policy_provider; |
156 policy_provider->AddObserver(this); | 153 policy_provider->AddObserver(this); |
157 | 154 |
158 pref_provider_ = | 155 pref_provider_ = |
159 new content_settings::PrefProvider(prefs_, is_off_the_record_); | 156 new content_settings::PrefProvider(prefs_, is_off_the_record_); |
160 content_settings_providers_[PREF_PROVIDER] = pref_provider_; | 157 content_settings_providers_[PREF_PROVIDER] = pref_provider_; |
161 pref_provider_->AddObserver(this); | 158 pref_provider_->AddObserver(this); |
162 | 159 |
163 // This ensures that content settings are cleared for the guest profile. This | 160 // This ensures that content settings are cleared for the guest profile. This |
164 // wouldn't be needed except that we used to allow settings to be stored for | 161 // wouldn't be needed except that we used to allow settings to be stored for |
165 // the guest profile and so we need to ensure those get cleared. | 162 // the guest profile and so we need to ensure those get cleared. |
166 if (is_guest_profile) | 163 if (is_guest_profile) |
167 pref_provider_->ClearPrefs(); | 164 pref_provider_->ClearPrefs(); |
168 | 165 |
169 content_settings::ObservableProvider* default_provider = | 166 content_settings::ObservableProvider* default_provider = |
170 new content_settings::DefaultProvider(prefs_, is_off_the_record_); | 167 new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
171 default_provider->AddObserver(this); | 168 default_provider->AddObserver(this); |
172 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; | 169 content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
173 | 170 |
174 MigrateKeygenSettings(); | 171 MigrateKeygenSettings(); |
175 | 172 MigrateDomainScopedSettings(); |
176 RecordNumberOfExceptions(); | 173 RecordNumberOfExceptions(); |
177 } | 174 } |
178 | 175 |
179 // static | 176 // static |
180 void HostContentSettingsMap::RegisterProfilePrefs( | 177 void HostContentSettingsMap::RegisterProfilePrefs( |
181 user_prefs::PrefRegistrySyncable* registry) { | 178 user_prefs::PrefRegistrySyncable* registry) { |
182 // Ensure the content settings are all registered. | 179 // Ensure the content settings are all registered. |
183 content_settings::ContentSettingsRegistry::GetInstance(); | 180 content_settings::ContentSettingsRegistry::GetInstance(); |
184 | 181 |
185 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); | 182 registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 rule.secondary_pattern.Matches(secondary_url)) { | 910 rule.secondary_pattern.Matches(secondary_url)) { |
914 if (primary_pattern) | 911 if (primary_pattern) |
915 *primary_pattern = rule.primary_pattern; | 912 *primary_pattern = rule.primary_pattern; |
916 if (secondary_pattern) | 913 if (secondary_pattern) |
917 *secondary_pattern = rule.secondary_pattern; | 914 *secondary_pattern = rule.secondary_pattern; |
918 return base::WrapUnique(rule.value.get()->DeepCopy()); | 915 return base::WrapUnique(rule.value.get()->DeepCopy()); |
919 } | 916 } |
920 } | 917 } |
921 return std::unique_ptr<base::Value>(); | 918 return std::unique_ptr<base::Value>(); |
922 } | 919 } |
| 920 |
| 921 base::WeakPtr<HostContentSettingsMap> HostContentSettingsMap::GetWeakPtr() { |
| 922 return weak_ptr_factory_.GetWeakPtr(); |
| 923 } |
OLD | NEW |