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/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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 host_content_settings_map_->GetContentSettingValue( | 212 host_content_settings_map_->GetContentSettingValue( |
213 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", | 213 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", |
214 &primary_pattern, &secondary_pattern)); | 214 &primary_pattern, &secondary_pattern)); |
215 | 215 |
216 // If no explicit exception has been made and third-party cookies are blocked | 216 // If no explicit exception has been made and third-party cookies are blocked |
217 // by default, apply that rule. | 217 // by default, apply that rule. |
218 if (primary_pattern == ContentSettingsPattern::Wildcard() && | 218 if (primary_pattern == ContentSettingsPattern::Wildcard() && |
219 secondary_pattern == ContentSettingsPattern::Wildcard() && | 219 secondary_pattern == ContentSettingsPattern::Wildcard() && |
220 ShouldBlockThirdPartyCookies() && | 220 ShouldBlockThirdPartyCookies() && |
221 !first_party_url.SchemeIs(chrome::kExtensionScheme)) { | 221 !first_party_url.SchemeIs(chrome::kExtensionScheme)) { |
222 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( | 222 bool not_strict = CommandLine::ForCurrentProcess()->HasSwitch( |
223 switches::kBlockReadingThirdPartyCookies); | 223 switches::kOnlyBlockSettingThirdPartyCookies); |
224 net::StaticCookiePolicy policy(strict ? | 224 net::StaticCookiePolicy policy(not_strict ? |
225 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : | 225 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES : |
226 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 226 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES); |
227 int rv; | 227 int rv; |
228 if (setting_cookie) | 228 if (setting_cookie) |
229 rv = policy.CanSetCookie(url, first_party_url); | 229 rv = policy.CanSetCookie(url, first_party_url); |
230 else | 230 else |
231 rv = policy.CanGetCookies(url, first_party_url); | 231 rv = policy.CanGetCookies(url, first_party_url); |
232 DCHECK_NE(net::ERR_IO_PENDING, rv); | 232 DCHECK_NE(net::ERR_IO_PENDING, rv); |
233 if (rv != net::OK) | 233 if (rv != net::OK) |
234 return CONTENT_SETTING_BLOCK; | 234 return CONTENT_SETTING_BLOCK; |
235 } | 235 } |
236 | 236 |
237 // We should always have a value, at least from the default provider. | 237 // We should always have a value, at least from the default provider. |
238 DCHECK(value.get()); | 238 DCHECK(value.get()); |
239 return content_settings::ValueToContentSetting(value.get()); | 239 return content_settings::ValueToContentSetting(value.get()); |
240 } | 240 } |
241 | 241 |
242 // static | 242 // static |
243 void CookieSettings::RegisterUserPrefs(PrefService* prefs) { | 243 void CookieSettings::RegisterUserPrefs(PrefService* prefs) { |
244 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, | 244 prefs->RegisterBooleanPref(prefs::kBlockThirdPartyCookies, |
245 false, | 245 false, |
246 PrefService::SYNCABLE_PREF); | 246 PrefService::SYNCABLE_PREF); |
247 } | 247 } |
248 | 248 |
249 bool CookieSettings::ShouldBlockThirdPartyCookies() const { | 249 bool CookieSettings::ShouldBlockThirdPartyCookies() const { |
250 base::AutoLock auto_lock(lock_); | 250 base::AutoLock auto_lock(lock_); |
251 return block_third_party_cookies_; | 251 return block_third_party_cookies_; |
252 } | 252 } |
OLD | NEW |