| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/content_settings/content_settings_extension_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
| 11 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 11 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
| 12 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 12 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
| 13 #include "chrome/browser/content_settings/content_settings_provider.h" | 13 #include "chrome/browser/content_settings/content_settings_provider.h" |
| 14 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 17 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 21 #include "content/browser/browser_thread.h" | 22 #include "content/browser/browser_thread.h" |
| 22 #include "content/browser/user_metrics.h" | 23 #include "content/browser/user_metrics.h" |
| 23 #include "content/common/notification_service.h" | 24 #include "content/common/notification_service.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // PrefContentSettingProvider to always provide a value. | 156 // PrefContentSettingProvider to always provide a value. |
| 156 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); | 157 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); |
| 157 return setting; | 158 return setting; |
| 158 } | 159 } |
| 159 | 160 |
| 160 ContentSetting HostContentSettingsMap::GetContentSetting( | 161 ContentSetting HostContentSettingsMap::GetContentSetting( |
| 161 const GURL& url, | 162 const GURL& url, |
| 162 ContentSettingsType content_type, | 163 ContentSettingsType content_type, |
| 163 const std::string& resource_identifier) const { | 164 const std::string& resource_identifier) const { |
| 164 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); | 165 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); |
| 166 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), |
| 167 resource_identifier.empty()); |
| 165 return GetContentSettingInternal(url, content_type, resource_identifier); | 168 return GetContentSettingInternal(url, content_type, resource_identifier); |
| 166 } | 169 } |
| 167 | 170 |
| 168 ContentSetting HostContentSettingsMap::GetContentSettingInternal( | 171 ContentSetting HostContentSettingsMap::GetContentSettingInternal( |
| 169 const GURL& url, | 172 const GURL& url, |
| 170 ContentSettingsType content_type, | 173 ContentSettingsType content_type, |
| 171 const std::string& resource_identifier) const { | 174 const std::string& resource_identifier) const { |
| 172 ContentSetting setting = GetNonDefaultContentSetting(url, | 175 ContentSetting setting = GetNonDefaultContentSetting(url, |
| 173 content_type, | 176 content_type, |
| 174 resource_identifier); | 177 resource_identifier); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 output.settings[j] = GetNonDefaultContentSetting( | 257 output.settings[j] = GetNonDefaultContentSetting( |
| 255 url, ContentSettingsType(j) , ""); | 258 url, ContentSettingsType(j) , ""); |
| 256 } | 259 } |
| 257 return output; | 260 return output; |
| 258 } | 261 } |
| 259 | 262 |
| 260 void HostContentSettingsMap::GetSettingsForOneType( | 263 void HostContentSettingsMap::GetSettingsForOneType( |
| 261 ContentSettingsType content_type, | 264 ContentSettingsType content_type, |
| 262 const std::string& resource_identifier, | 265 const std::string& resource_identifier, |
| 263 SettingsForOneType* settings) const { | 266 SettingsForOneType* settings) const { |
| 267 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), |
| 268 resource_identifier.empty()); |
| 264 DCHECK(settings); | 269 DCHECK(settings); |
| 265 // Collect content_settings::Rules for the given content_type and | 270 // Collect content_settings::Rules for the given content_type and |
| 266 // resource_identifier from the content settings providers. | 271 // resource_identifier from the content settings providers. |
| 267 std::map<std::string, PatternSettingPair> | 272 std::map<std::string, PatternSettingPair> |
| 268 pattern_str_pattern_setting_pair_map; | 273 pattern_str_pattern_setting_pair_map; |
| 269 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 274 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
| 270 provider != content_settings_providers_.end(); | 275 provider != content_settings_providers_.end(); |
| 271 ++provider) { | 276 ++provider) { |
| 272 Rules rules; | 277 Rules rules; |
| 273 (*provider)->GetAllContentSettingsRules( | 278 (*provider)->GetAllContentSettingsRules( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 302 (*provider)->UpdateDefaultSetting(content_type, setting); | 307 (*provider)->UpdateDefaultSetting(content_type, setting); |
| 303 } | 308 } |
| 304 } | 309 } |
| 305 | 310 |
| 306 void HostContentSettingsMap::SetContentSetting( | 311 void HostContentSettingsMap::SetContentSetting( |
| 307 const ContentSettingsPattern& pattern, | 312 const ContentSettingsPattern& pattern, |
| 308 ContentSettingsType content_type, | 313 ContentSettingsType content_type, |
| 309 const std::string& resource_identifier, | 314 const std::string& resource_identifier, |
| 310 ContentSetting setting) { | 315 ContentSetting setting) { |
| 311 DCHECK(IsSettingAllowedForType(setting, content_type)); | 316 DCHECK(IsSettingAllowedForType(setting, content_type)); |
| 317 DCHECK_NE(content_settings::RequiresResourceIdentifier(content_type), |
| 318 resource_identifier.empty()); |
| 312 for (ProviderIterator provider = content_settings_providers_.begin(); | 319 for (ProviderIterator provider = content_settings_providers_.begin(); |
| 313 provider != content_settings_providers_.end(); | 320 provider != content_settings_providers_.end(); |
| 314 ++provider) { | 321 ++provider) { |
| 315 (*provider)->SetContentSetting( | 322 (*provider)->SetContentSetting( |
| 316 pattern, pattern, content_type, resource_identifier, setting); | 323 pattern, pattern, content_type, resource_identifier, setting); |
| 317 } | 324 } |
| 318 } | 325 } |
| 319 | 326 |
| 320 void HostContentSettingsMap::AddExceptionForURL( | 327 void HostContentSettingsMap::AddExceptionForURL( |
| 321 const GURL& url, | 328 const GURL& url, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 500 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
| 494 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | 501 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? |
| 495 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | 502 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); |
| 496 } | 503 } |
| 497 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | 504 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { |
| 498 SetBlockThirdPartyCookies(cookie_behavior == | 505 SetBlockThirdPartyCookies(cookie_behavior == |
| 499 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 506 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
| 500 } | 507 } |
| 501 } | 508 } |
| 502 } | 509 } |
| OLD | NEW |