OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/content_settings/content_settings_default_provider.h" | 14 #include "chrome/browser/content_settings/content_settings_default_provider.h" |
15 #include "chrome/browser/content_settings/content_settings_details.h" | 15 #include "chrome/browser/content_settings/content_settings_details.h" |
16 #include "chrome/browser/content_settings/content_settings_extension_provider.h" | 16 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
17 #include "chrome/browser/content_settings/content_settings_observable_provider.h " | 17 #include "chrome/browser/content_settings/content_settings_observable_provider.h " |
18 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 18 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
19 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 19 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
20 #include "chrome/browser/content_settings/content_settings_provider.h" | 20 #include "chrome/browser/content_settings/content_settings_provider.h" |
21 #include "chrome/browser/content_settings/content_settings_rule.h" | 21 #include "chrome/browser/content_settings/content_settings_rule.h" |
22 #include "chrome/browser/content_settings/content_settings_utils.h" | |
marja
2011/12/06 09:47:12
I don't think you should remove this include, this
markusheintz_
2011/12/06 16:29:59
Done.
| |
23 #include "chrome/browser/extensions/extension_service.h" | 22 #include "chrome/browser/extensions/extension_service.h" |
24 #include "chrome/browser/prefs/pref_service.h" | 23 #include "chrome/browser/prefs/pref_service.h" |
25 #include "chrome/common/chrome_notification_types.h" | 24 #include "chrome/common/chrome_notification_types.h" |
26 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/content_settings_pattern.h" | 26 #include "chrome/common/content_settings_pattern.h" |
28 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
30 #include "content/browser/user_metrics.h" | 29 #include "content/browser/user_metrics.h" |
31 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
61 HostContentSettingsMap::NUM_PROVIDER_TYPES, | 60 HostContentSettingsMap::NUM_PROVIDER_TYPES, |
62 kProviderSourceMap_has_incorrect_size); | 61 kProviderSourceMap_has_incorrect_size); |
63 | 62 |
64 bool ContentTypeHasCompoundValue(ContentSettingsType type) { | 63 bool ContentTypeHasCompoundValue(ContentSettingsType type) { |
65 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are | 64 // Values for content type CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE are |
66 // of type dictionary/map. Compound types like dictionaries can't be mapped to | 65 // of type dictionary/map. Compound types like dictionaries can't be mapped to |
67 // the type |ContentSetting|. | 66 // the type |ContentSetting|. |
68 return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE; | 67 return type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE; |
69 } | 68 } |
70 | 69 |
71 ContentSetting GetDefaultSetting( | 70 // Returns true if the |content_type| supports a resource identifier. |
72 content_settings::RuleIterator* rule_iterator) { | 71 // Resource identifiers are supported (but not required) for plug-ins. |
73 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | 72 bool SupportsResourceIdentifier(ContentSettingsType content_type) { |
74 while (rule_iterator->HasNext()) { | 73 return content_type == CONTENT_SETTINGS_TYPE_PLUGINS; |
75 content_settings::Rule rule = rule_iterator->Next(); | |
76 if (rule.primary_pattern == wildcard && | |
77 rule.secondary_pattern == wildcard) { | |
78 return content_settings::ValueToContentSetting(rule.value.get()); | |
79 } | |
80 } | |
81 return CONTENT_SETTING_DEFAULT; | |
82 } | 74 } |
83 | 75 |
84 } // namespace | 76 } // namespace |
85 | 77 |
86 HostContentSettingsMap::HostContentSettingsMap( | 78 HostContentSettingsMap::HostContentSettingsMap( |
87 PrefService* prefs, | 79 PrefService* prefs, |
88 ExtensionService* extension_service, | 80 ExtensionService* extension_service, |
89 bool incognito) | 81 bool incognito) |
90 : prefs_(prefs), | 82 : prefs_(prefs), |
91 is_off_the_record_(incognito) { | 83 is_off_the_record_(incognito) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 content_settings::DefaultProvider::RegisterUserPrefs(prefs); | 117 content_settings::DefaultProvider::RegisterUserPrefs(prefs); |
126 content_settings::PrefProvider::RegisterUserPrefs(prefs); | 118 content_settings::PrefProvider::RegisterUserPrefs(prefs); |
127 content_settings::PolicyProvider::RegisterUserPrefs(prefs); | 119 content_settings::PolicyProvider::RegisterUserPrefs(prefs); |
128 } | 120 } |
129 | 121 |
130 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( | 122 ContentSetting HostContentSettingsMap::GetDefaultContentSettingFromProvider( |
131 ContentSettingsType content_type, | 123 ContentSettingsType content_type, |
132 content_settings::ProviderInterface* provider) const { | 124 content_settings::ProviderInterface* provider) const { |
133 scoped_ptr<content_settings::RuleIterator> rule_iterator( | 125 scoped_ptr<content_settings::RuleIterator> rule_iterator( |
134 provider->GetRuleIterator(content_type, "", false)); | 126 provider->GetRuleIterator(content_type, "", false)); |
135 return GetDefaultSetting(rule_iterator.get()); | 127 |
128 ContentSettingsPattern wildcard = ContentSettingsPattern::Wildcard(); | |
129 while (rule_iterator->HasNext()) { | |
130 content_settings::Rule rule = rule_iterator->Next(); | |
131 if (rule.primary_pattern == wildcard && | |
132 rule.secondary_pattern == wildcard) { | |
133 return content_settings::ValueToContentSetting(rule.value.get()); | |
134 } | |
135 } | |
136 return CONTENT_SETTING_DEFAULT; | |
136 } | 137 } |
137 | 138 |
138 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( | 139 ContentSetting HostContentSettingsMap::GetDefaultContentSetting( |
139 ContentSettingsType content_type, | 140 ContentSettingsType content_type, |
140 std::string* provider_id) const { | 141 std::string* provider_id) const { |
141 DCHECK(!ContentTypeHasCompoundValue(content_type)); | 142 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
142 | 143 |
143 // Iterate through the list of providers and return the first non-NULL value | 144 // Iterate through the list of providers and return the first non-NULL value |
144 // that matches |primary_url| and |secondary_url|. | 145 // that matches |primary_url| and |secondary_url|. |
145 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 146 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
(...skipping 15 matching lines...) Expand all Loading... | |
161 // DefaultProvider to always provide a value. | 162 // DefaultProvider to always provide a value. |
162 NOTREACHED(); | 163 NOTREACHED(); |
163 return CONTENT_SETTING_DEFAULT; | 164 return CONTENT_SETTING_DEFAULT; |
164 } | 165 } |
165 | 166 |
166 ContentSetting HostContentSettingsMap::GetContentSetting( | 167 ContentSetting HostContentSettingsMap::GetContentSetting( |
167 const GURL& primary_url, | 168 const GURL& primary_url, |
168 const GURL& secondary_url, | 169 const GURL& secondary_url, |
169 ContentSettingsType content_type, | 170 ContentSettingsType content_type, |
170 const std::string& resource_identifier) const { | 171 const std::string& resource_identifier) const { |
172 DCHECK(!ContentTypeHasCompoundValue(content_type)); | |
171 scoped_ptr<base::Value> value(GetWebsiteSetting( | 173 scoped_ptr<base::Value> value(GetWebsiteSetting( |
172 primary_url, secondary_url, content_type, resource_identifier, NULL)); | 174 primary_url, secondary_url, content_type, resource_identifier, NULL)); |
173 return content_settings::ValueToContentSetting(value.get()); | 175 return content_settings::ValueToContentSetting(value.get()); |
174 } | 176 } |
175 | 177 |
176 void HostContentSettingsMap::GetSettingsForOneType( | 178 void HostContentSettingsMap::GetSettingsForOneType( |
177 ContentSettingsType content_type, | 179 ContentSettingsType content_type, |
178 const std::string& resource_identifier, | 180 const std::string& resource_identifier, |
179 ContentSettingsForOneType* settings) const { | 181 ContentSettingsForOneType* settings) const { |
180 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 182 DCHECK(SupportsResourceIdentifier(content_type) || |
181 resource_identifier.empty()); | 183 resource_identifier.empty()); |
182 DCHECK(settings); | 184 DCHECK(settings); |
183 | 185 |
184 settings->clear(); | 186 settings->clear(); |
185 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 187 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
186 provider != content_settings_providers_.end(); | 188 provider != content_settings_providers_.end(); |
187 ++provider) { | 189 ++provider) { |
188 // For each provider, iterate first the incognito-specific rules, then the | 190 // For each provider, iterate first the incognito-specific rules, then the |
189 // normal rules. | 191 // normal rules. |
190 if (is_off_the_record_) { | 192 if (is_off_the_record_) { |
191 AddSettingsForOneType(provider->second, | 193 AddSettingsForOneType(provider->second, |
192 provider->first, | 194 provider->first, |
193 content_type, | 195 content_type, |
194 resource_identifier, | 196 resource_identifier, |
195 settings, | 197 settings, |
196 true); | 198 true); |
197 } | 199 } |
198 AddSettingsForOneType(provider->second, | 200 AddSettingsForOneType(provider->second, |
199 provider->first, | 201 provider->first, |
200 content_type, | 202 content_type, |
201 resource_identifier, | 203 resource_identifier, |
202 settings, | 204 settings, |
203 false); | 205 false); |
204 } | 206 } |
205 } | 207 } |
206 | 208 |
207 void HostContentSettingsMap::SetDefaultContentSetting( | 209 void HostContentSettingsMap::SetDefaultContentSetting( |
208 ContentSettingsType content_type, | 210 ContentSettingsType content_type, |
209 ContentSetting setting) { | 211 ContentSetting setting) { |
210 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 212 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
211 DCHECK(IsSettingAllowedForType(setting, content_type)); | 213 DCHECK(IsSettingAllowedForType(setting, content_type)); |
212 | 214 |
213 base::Value* value = NULL; | 215 base::Value* value = NULL; |
214 if (setting != CONTENT_SETTING_DEFAULT) | 216 if (setting != CONTENT_SETTING_DEFAULT) |
215 value = Value::CreateIntegerValue(setting); | 217 value = Value::CreateIntegerValue(setting); |
216 SetWebsiteSetting( | 218 SetWebsiteSetting( |
217 ContentSettingsPattern::Wildcard(), | 219 ContentSettingsPattern::Wildcard(), |
218 ContentSettingsPattern::Wildcard(), | 220 ContentSettingsPattern::Wildcard(), |
219 content_type, | 221 content_type, |
220 std::string(), | 222 std::string(), |
221 value); | 223 value); |
222 } | 224 } |
223 | 225 |
224 void HostContentSettingsMap::SetWebsiteSetting( | 226 void HostContentSettingsMap::SetWebsiteSetting( |
225 const ContentSettingsPattern& primary_pattern, | 227 const ContentSettingsPattern& primary_pattern, |
226 const ContentSettingsPattern& secondary_pattern, | 228 const ContentSettingsPattern& secondary_pattern, |
227 ContentSettingsType content_type, | 229 ContentSettingsType content_type, |
228 const std::string& resource_identifier, | 230 const std::string& resource_identifier, |
229 base::Value* value) { | 231 base::Value* value) { |
230 DCHECK(IsValueAllowedForType(value, content_type)); | 232 DCHECK(IsValueAllowedForType(value, content_type)); |
231 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 233 DCHECK(SupportsResourceIdentifier(content_type) || |
232 resource_identifier.empty()); | 234 resource_identifier.empty()); |
233 for (ProviderIterator provider = content_settings_providers_.begin(); | 235 for (ProviderIterator provider = content_settings_providers_.begin(); |
234 provider != content_settings_providers_.end(); | 236 provider != content_settings_providers_.end(); |
235 ++provider) { | 237 ++provider) { |
236 if (provider->second->SetWebsiteSetting(primary_pattern, | 238 if (provider->second->SetWebsiteSetting(primary_pattern, |
237 secondary_pattern, | 239 secondary_pattern, |
238 content_type, | 240 content_type, |
239 resource_identifier, | 241 resource_identifier, |
240 value)) { | 242 value)) { |
241 return; | 243 return; |
242 } | 244 } |
243 } | 245 } |
244 NOTREACHED(); | 246 NOTREACHED(); |
245 } | 247 } |
246 | 248 |
247 void HostContentSettingsMap::SetContentSetting( | 249 void HostContentSettingsMap::SetContentSetting( |
248 const ContentSettingsPattern& primary_pattern, | 250 const ContentSettingsPattern& primary_pattern, |
249 const ContentSettingsPattern& secondary_pattern, | 251 const ContentSettingsPattern& secondary_pattern, |
250 ContentSettingsType content_type, | 252 ContentSettingsType content_type, |
251 const std::string& resource_identifier, | 253 const std::string& resource_identifier, |
252 ContentSetting setting) { | 254 ContentSetting setting) { |
253 DCHECK_NE(content_type, CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE); | 255 DCHECK(!ContentTypeHasCompoundValue(content_type)); |
254 base::Value* value = NULL; | 256 base::Value* value = NULL; |
255 if (setting != CONTENT_SETTING_DEFAULT) | 257 if (setting != CONTENT_SETTING_DEFAULT) |
256 value = Value::CreateIntegerValue(setting); | 258 value = Value::CreateIntegerValue(setting); |
257 SetWebsiteSetting(primary_pattern, | 259 SetWebsiteSetting(primary_pattern, |
258 secondary_pattern, | 260 secondary_pattern, |
259 content_type, | 261 content_type, |
260 resource_identifier, | 262 resource_identifier, |
261 value); | 263 value); |
262 } | 264 } |
263 | 265 |
264 void HostContentSettingsMap::AddExceptionForURL( | 266 void HostContentSettingsMap::AddExceptionForURL( |
265 const GURL& primary_url, | 267 const GURL& primary_url, |
266 const GURL& secondary_url, | 268 const GURL& secondary_url, |
267 ContentSettingsType content_type, | 269 ContentSettingsType content_type, |
268 const std::string& resource_identifier, | 270 const std::string& resource_identifier, |
269 ContentSetting setting) { | 271 ContentSetting setting) { |
270 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must | 272 // TODO(markusheintz): Until the UI supports pattern pairs, both urls must |
271 // match. | 273 // match. |
272 DCHECK(primary_url == secondary_url); | 274 DCHECK(primary_url == secondary_url); |
275 DCHECK(!ContentTypeHasCompoundValue(content_type)); | |
273 | 276 |
274 // Make sure there is no entry that would override the pattern we are about | 277 // Make sure there is no entry that would override the pattern we are about |
275 // to insert for exactly this URL. | 278 // to insert for exactly this URL. |
276 SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(primary_url), | 279 SetContentSetting(ContentSettingsPattern::FromURLNoWildcard(primary_url), |
277 ContentSettingsPattern::Wildcard(), | 280 ContentSettingsPattern::Wildcard(), |
278 content_type, | 281 content_type, |
279 resource_identifier, | 282 resource_identifier, |
280 CONTENT_SETTING_DEFAULT); | 283 CONTENT_SETTING_DEFAULT); |
281 | 284 |
282 SetContentSetting(ContentSettingsPattern::FromURL(primary_url), | 285 SetContentSetting(ContentSettingsPattern::FromURL(primary_url), |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 primary_url.SchemeIs(chrome::kChromeInternalScheme) || | 411 primary_url.SchemeIs(chrome::kChromeInternalScheme) || |
409 primary_url.SchemeIs(chrome::kChromeUIScheme); | 412 primary_url.SchemeIs(chrome::kChromeUIScheme); |
410 } | 413 } |
411 | 414 |
412 base::Value* HostContentSettingsMap::GetWebsiteSetting( | 415 base::Value* HostContentSettingsMap::GetWebsiteSetting( |
413 const GURL& primary_url, | 416 const GURL& primary_url, |
414 const GURL& secondary_url, | 417 const GURL& secondary_url, |
415 ContentSettingsType content_type, | 418 ContentSettingsType content_type, |
416 const std::string& resource_identifier, | 419 const std::string& resource_identifier, |
417 content_settings::SettingInfo* info) const { | 420 content_settings::SettingInfo* info) const { |
418 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 421 DCHECK(SupportsResourceIdentifier(content_type) || |
419 resource_identifier.empty()); | 422 resource_identifier.empty()); |
420 | 423 |
421 // Check if the scheme of the requesting url is whitelisted. | 424 // Check if the scheme of the requesting url is whitelisted. |
422 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { | 425 if (ShouldAllowAllContent(primary_url, secondary_url, content_type)) { |
423 if (info) { | 426 if (info) { |
424 info->source = content_settings::SETTING_SOURCE_WHITELIST; | 427 info->source = content_settings::SETTING_SOURCE_WHITELIST; |
425 info->primary_pattern = ContentSettingsPattern::Wildcard(); | 428 info->primary_pattern = ContentSettingsPattern::Wildcard(); |
426 info->secondary_pattern = ContentSettingsPattern::Wildcard(); | 429 info->secondary_pattern = ContentSettingsPattern::Wildcard(); |
427 } | 430 } |
428 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); | 431 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); |
429 } | 432 } |
430 | 433 |
431 ContentSettingsPattern* primary_pattern = NULL; | 434 ContentSettingsPattern* primary_pattern = NULL; |
432 ContentSettingsPattern* secondary_pattern = NULL; | 435 ContentSettingsPattern* secondary_pattern = NULL; |
433 if (info) { | 436 if (info) { |
434 primary_pattern = &info->primary_pattern; | 437 primary_pattern = &info->primary_pattern; |
435 secondary_pattern = &info->secondary_pattern; | 438 secondary_pattern = &info->secondary_pattern; |
436 } | 439 } |
437 | 440 |
438 // The list of |content_settings_providers_| is ordered according to their | 441 // The list of |content_settings_providers_| is ordered according to their |
439 // precedence. | 442 // precedence. |
440 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 443 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
441 provider != content_settings_providers_.end(); | 444 provider != content_settings_providers_.end(); |
442 ++provider) { | 445 ++provider) { |
443 base::Value* value = content_settings::GetContentSettingValueAndPatterns( | 446 base::Value* value = content_settings::GetContentSettingValueAndPatterns( |
marja
2011/12/06 09:47:12
(Here.)
markusheintz_
2011/12/06 16:29:59
Done.
| |
444 provider->second, primary_url, secondary_url, content_type, | 447 provider->second, primary_url, secondary_url, content_type, |
445 resource_identifier, is_off_the_record_, | 448 resource_identifier, is_off_the_record_, |
446 primary_pattern, secondary_pattern); | 449 primary_pattern, secondary_pattern); |
447 if (value) { | 450 if (value) { |
448 if (info) | 451 if (info) |
449 info->source = kProviderSourceMap[provider->first]; | 452 info->source = kProviderSourceMap[provider->first]; |
450 return value; | 453 return value; |
451 } | 454 } |
452 } | 455 } |
453 | 456 |
454 if (info) { | 457 if (info) { |
455 info->source = content_settings::SETTING_SOURCE_NONE; | 458 info->source = content_settings::SETTING_SOURCE_NONE; |
456 info->primary_pattern = ContentSettingsPattern(); | 459 info->primary_pattern = ContentSettingsPattern(); |
457 info->secondary_pattern = ContentSettingsPattern(); | 460 info->secondary_pattern = ContentSettingsPattern(); |
458 } | 461 } |
459 return NULL; | 462 return NULL; |
460 } | 463 } |
OLD | NEW |