| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 setting = GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); | 243 setting = GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES); |
| 244 | 244 |
| 245 return setting; | 245 return setting; |
| 246 } | 246 } |
| 247 | 247 |
| 248 ContentSetting HostContentSettingsMap::GetContentSetting( | 248 ContentSetting HostContentSettingsMap::GetContentSetting( |
| 249 const GURL& primary_url, | 249 const GURL& primary_url, |
| 250 const GURL& secondary_url, | 250 const GURL& secondary_url, |
| 251 ContentSettingsType content_type, | 251 ContentSettingsType content_type, |
| 252 const std::string& resource_identifier) const { | 252 const std::string& resource_identifier) const { |
| 253 scoped_ptr<base::Value> value(GetContentSettingValue( |
| 254 primary_url, secondary_url, content_type, resource_identifier, |
| 255 NULL, NULL)); |
| 256 return content_settings::ValueToContentSetting(value.get()); |
| 257 } |
| 258 |
| 259 base::Value* HostContentSettingsMap::GetContentSettingValue( |
| 260 const GURL& primary_url, |
| 261 const GURL& secondary_url, |
| 262 ContentSettingsType content_type, |
| 263 const std::string& resource_identifier, |
| 264 ContentSettingsPattern* primary_pattern, |
| 265 ContentSettingsPattern* secondary_pattern) const { |
| 253 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); | 266 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); |
| 254 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || | 267 DCHECK(content_settings::SupportsResourceIdentifier(content_type) || |
| 255 resource_identifier.empty()); | 268 resource_identifier.empty()); |
| 256 | 269 |
| 257 if (ShouldAllowAllContent(secondary_url, content_type)) | |
| 258 return CONTENT_SETTING_ALLOW; | |
| 259 | |
| 260 // Iterate through the list of providers and return the first non-NULL value | |
| 261 // that matches |primary_url| and |secondary_url|. | |
| 262 for (ConstProviderIterator provider = content_settings_providers_.begin(); | |
| 263 provider != content_settings_providers_.end(); | |
| 264 ++provider) { | |
| 265 ContentSetting provided_setting = content_settings::GetContentSetting( | |
| 266 provider->second, primary_url, secondary_url, content_type, | |
| 267 resource_identifier, is_off_the_record_); | |
| 268 if (provided_setting != CONTENT_SETTING_DEFAULT) | |
| 269 return provided_setting; | |
| 270 } | |
| 271 return CONTENT_SETTING_DEFAULT; | |
| 272 } | |
| 273 | |
| 274 Value* HostContentSettingsMap::GetContentSettingValue( | |
| 275 const GURL& primary_url, | |
| 276 const GURL& secondary_url, | |
| 277 ContentSettingsType content_type, | |
| 278 const std::string& resource_identifier) const { | |
| 279 // Check if the scheme of the requesting url is whitelisted. | 270 // Check if the scheme of the requesting url is whitelisted. |
| 280 if (ShouldAllowAllContent(secondary_url, content_type)) | 271 if (ShouldAllowAllContent(secondary_url, content_type)) |
| 281 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); | 272 return Value::CreateIntegerValue(CONTENT_SETTING_ALLOW); |
| 282 | 273 |
| 283 // First check if there are specific settings for the |primary_url| and | 274 // The list of |content_settings_providers_| is ordered according to their |
| 284 // |secondary_url|. The list of |content_settings_providers_| is ordered | 275 // precedence. |
| 285 // according to their priority. | |
| 286 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 276 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 287 provider != content_settings_providers_.end(); | 277 provider != content_settings_providers_.end(); |
| 288 ++provider) { | 278 ++provider) { |
| 289 // TODO(marja): Make DefaultProvider return NULL for | 279 base::Value* value = content_settings::GetContentSettingValueAndPatterns( |
| 290 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE, un-skip default provider | |
| 291 // here and remove the code below this loop. | |
| 292 if (provider->first == DEFAULT_PROVIDER) | |
| 293 continue; | |
| 294 base::Value* value = content_settings::GetContentSettingValue( | |
| 295 provider->second, primary_url, secondary_url, content_type, | 280 provider->second, primary_url, secondary_url, content_type, |
| 296 resource_identifier, is_off_the_record_); | 281 resource_identifier, is_off_the_record_, |
| 282 primary_pattern, secondary_pattern); |
| 297 if (value) | 283 if (value) |
| 298 return value; | 284 return value; |
| 299 } | 285 } |
| 300 | 286 |
| 301 // If no specific settings were found for the |primary_url|, |secondary_url| | 287 return NULL; |
| 302 // pair, then the default value for the given |content_type| should be | |
| 303 // returned. For CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE the default is | |
| 304 // 'no filter available'. That's why we return |NULL| for this content type. | |
| 305 if (content_type == CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE) | |
| 306 return NULL; | |
| 307 return Value::CreateIntegerValue(GetDefaultContentSetting(content_type)); | |
| 308 } | 288 } |
| 309 | 289 |
| 310 ContentSettings HostContentSettingsMap::GetContentSettings( | 290 ContentSettings HostContentSettingsMap::GetContentSettings( |
| 311 const GURL& primary_url, | 291 const GURL& primary_url, |
| 312 const GURL& secondary_url) const { | 292 const GURL& secondary_url) const { |
| 313 ContentSettings output; | 293 ContentSettings output; |
| 314 // If we require a resource identifier, set the content settings to default, | 294 // If we require a resource identifier, set the content settings to default, |
| 315 // otherwise make the defaults explicit. Values for content type | 295 // otherwise make the defaults explicit. Values for content type |
| 316 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE can't be mapped to the type | 296 // CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE can't be mapped to the type |
| 317 // |ContentSetting|. So we ignore them here. | 297 // |ContentSetting|. So we ignore them here. |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 provider_type == DEFAULT_PROVIDER)) { | 572 provider_type == DEFAULT_PROVIDER)) { |
| 593 continue; | 573 continue; |
| 594 } | 574 } |
| 595 settings->push_back(PatternSettingSourceTuple( | 575 settings->push_back(PatternSettingSourceTuple( |
| 596 rule.primary_pattern, rule.secondary_pattern, | 576 rule.primary_pattern, rule.secondary_pattern, |
| 597 content_settings::ValueToContentSetting(rule.value.get()), | 577 content_settings::ValueToContentSetting(rule.value.get()), |
| 598 kProviderNames[provider_type], | 578 kProviderNames[provider_type], |
| 599 incognito)); | 579 incognito)); |
| 600 } | 580 } |
| 601 } | 581 } |
| OLD | NEW |