| 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 "chrome/browser/content_settings/cookie_settings.h" | 5 #include "chrome/browser/content_settings/cookie_settings.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/content_settings/content_settings_utils.h" | 8 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // First get any host-specific settings. | 193 // First get any host-specific settings. |
| 194 content_settings::SettingInfo info; | 194 content_settings::SettingInfo info; |
| 195 scoped_ptr<base::Value> value( | 195 scoped_ptr<base::Value> value( |
| 196 host_content_settings_map_->GetWebsiteSetting( | 196 host_content_settings_map_->GetWebsiteSetting( |
| 197 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", &info)); | 197 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", &info)); |
| 198 if (source) | 198 if (source) |
| 199 *source = info.source; | 199 *source = info.source; |
| 200 | 200 |
| 201 // If no explicit exception has been made and third-party cookies are blocked | 201 // If no explicit exception has been made and third-party cookies are blocked |
| 202 // by default, apply that rule. | 202 // by default, apply that rule. |
| 203 if (info.primary_pattern == ContentSettingsPattern::Wildcard() && | 203 if (info.primary_pattern.MatchesAllHosts() && |
| 204 info.secondary_pattern == ContentSettingsPattern::Wildcard() && | 204 info.secondary_pattern.MatchesAllHosts() && |
| 205 ShouldBlockThirdPartyCookies() && | 205 ShouldBlockThirdPartyCookies() && |
| 206 !first_party_url.SchemeIs(chrome::kExtensionScheme)) { | 206 !first_party_url.SchemeIs(chrome::kExtensionScheme)) { |
| 207 bool not_strict = CommandLine::ForCurrentProcess()->HasSwitch( | 207 bool not_strict = CommandLine::ForCurrentProcess()->HasSwitch( |
| 208 switches::kOnlyBlockSettingThirdPartyCookies); | 208 switches::kOnlyBlockSettingThirdPartyCookies); |
| 209 net::StaticCookiePolicy policy(not_strict ? | 209 net::StaticCookiePolicy policy(not_strict ? |
| 210 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES : | 210 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES : |
| 211 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES); | 211 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES); |
| 212 int rv; | 212 int rv; |
| 213 if (setting_cookie) | 213 if (setting_cookie) |
| 214 rv = policy.CanSetCookie(url, first_party_url); | 214 rv = policy.CanSetCookie(url, first_party_url); |
| 215 else | 215 else |
| 216 rv = policy.CanGetCookies(url, first_party_url); | 216 rv = policy.CanGetCookies(url, first_party_url); |
| 217 DCHECK_NE(net::ERR_IO_PENDING, rv); | 217 DCHECK_NE(net::ERR_IO_PENDING, rv); |
| 218 if (rv != net::OK) | 218 if (rv != net::OK) |
| 219 return CONTENT_SETTING_BLOCK; | 219 return CONTENT_SETTING_BLOCK; |
| 220 } | 220 } |
| 221 | 221 |
| 222 // We should always have a value, at least from the default provider. | 222 // We should always have a value, at least from the default provider. |
| 223 DCHECK(value.get()); | 223 DCHECK(value.get()); |
| 224 return content_settings::ValueToContentSetting(value.get()); | 224 return content_settings::ValueToContentSetting(value.get()); |
| 225 } | 225 } |
| 226 | 226 |
| 227 CookieSettings::~CookieSettings() {} | 227 CookieSettings::~CookieSettings() {} |
| 228 | 228 |
| 229 bool CookieSettings::ShouldBlockThirdPartyCookies() const { | 229 bool CookieSettings::ShouldBlockThirdPartyCookies() const { |
| 230 base::AutoLock auto_lock(lock_); | 230 base::AutoLock auto_lock(lock_); |
| 231 return block_third_party_cookies_; | 231 return block_third_party_cookies_; |
| 232 } | 232 } |
| OLD | NEW |