| 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" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/profiles/profile_dependency_manager.h" | 12 #include "chrome/browser/profiles/profile_dependency_manager.h" |
| 13 #include "chrome/browser/profiles/profile_keyed_service.h" | 13 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 14 #include "chrome/common/chrome_notification_types.h" | 14 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/content_settings_pattern.h" | 16 #include "chrome/common/content_settings_pattern.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/url_constants.h" |
| 18 #include "content/browser/user_metrics.h" | 19 #include "content/browser/user_metrics.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "net/base/static_cookie_policy.h" | 25 #include "net/base/static_cookie_policy.h" |
| 25 | 26 |
| 26 using content::BrowserThread; | 27 using content::BrowserThread; |
| 27 | 28 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 void CookieSettings::ShutdownOnUIThread() { | 195 void CookieSettings::ShutdownOnUIThread() { |
| 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 196 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 196 pref_change_registrar_.RemoveAll(); | 197 pref_change_registrar_.RemoveAll(); |
| 197 } | 198 } |
| 198 | 199 |
| 199 ContentSetting CookieSettings::GetCookieSetting( | 200 ContentSetting CookieSettings::GetCookieSetting( |
| 200 const GURL& url, | 201 const GURL& url, |
| 201 const GURL& first_party_url, | 202 const GURL& first_party_url, |
| 202 bool setting_cookie) const { | 203 bool setting_cookie) const { |
| 203 if (HostContentSettingsMap::ShouldAllowAllContent( | 204 if (HostContentSettingsMap::ShouldAllowAllContent( |
| 204 first_party_url, | 205 first_party_url, url, CONTENT_SETTINGS_TYPE_COOKIES)) |
| 205 CONTENT_SETTINGS_TYPE_COOKIES)) { | |
| 206 return CONTENT_SETTING_ALLOW; | 206 return CONTENT_SETTING_ALLOW; |
| 207 } | |
| 208 | 207 |
| 209 ContentSettingsPattern primary_pattern; | 208 ContentSettingsPattern primary_pattern; |
| 210 ContentSettingsPattern secondary_pattern; | 209 ContentSettingsPattern secondary_pattern; |
| 211 // First get any host-specific settings. | 210 // First get any host-specific settings. |
| 212 scoped_ptr<base::Value> value( | 211 scoped_ptr<base::Value> value( |
| 213 host_content_settings_map_->GetContentSettingValue( | 212 host_content_settings_map_->GetContentSettingValue( |
| 214 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", | 213 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", |
| 215 &primary_pattern, &secondary_pattern)); | 214 &primary_pattern, &secondary_pattern)); |
| 216 | 215 |
| 217 // 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 |
| 218 // by default, apply that rule. | 217 // by default, apply that rule. |
| 219 if (primary_pattern == ContentSettingsPattern::Wildcard() && | 218 if (primary_pattern == ContentSettingsPattern::Wildcard() && |
| 220 secondary_pattern == ContentSettingsPattern::Wildcard() && | 219 secondary_pattern == ContentSettingsPattern::Wildcard() && |
| 221 ShouldBlockThirdPartyCookies()) { | 220 ShouldBlockThirdPartyCookies() && |
| 221 !first_party_url.SchemeIs(chrome::kExtensionScheme)) { |
| 222 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( | 222 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( |
| 223 switches::kBlockReadingThirdPartyCookies); | 223 switches::kBlockReadingThirdPartyCookies); |
| 224 net::StaticCookiePolicy policy(strict ? | 224 net::StaticCookiePolicy policy(strict ? |
| 225 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : | 225 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : |
| 226 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 226 net::StaticCookiePolicy::BLOCK_SETTING_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); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 |