| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 prefs->GetBoolean(prefs::kBlockThirdPartyCookies)) { | 88 prefs->GetBoolean(prefs::kBlockThirdPartyCookies)) { |
| 89 if (block_third_party_cookies_) { | 89 if (block_third_party_cookies_) { |
| 90 content::RecordAction( | 90 content::RecordAction( |
| 91 UserMetricsAction("ThirdPartyCookieBlockingEnabled")); | 91 UserMetricsAction("ThirdPartyCookieBlockingEnabled")); |
| 92 } else { | 92 } else { |
| 93 content::RecordAction( | 93 content::RecordAction( |
| 94 UserMetricsAction("ThirdPartyCookieBlockingDisabled")); | 94 UserMetricsAction("ThirdPartyCookieBlockingDisabled")); |
| 95 } | 95 } |
| 96 | 96 |
| 97 pref_change_registrar_.Init(prefs); | 97 pref_change_registrar_.Init(prefs); |
| 98 pref_change_registrar_.Add(prefs::kBlockThirdPartyCookies, this); | 98 pref_change_registrar_.Add( |
| 99 prefs::kBlockThirdPartyCookies, |
| 100 base::Bind(&CookieSettings::OnBlockThirdPartyCookiesChanged, |
| 101 base::Unretained(this))); |
| 99 } | 102 } |
| 100 | 103 |
| 101 ContentSetting | 104 ContentSetting |
| 102 CookieSettings::GetDefaultCookieSetting(std::string* provider_id) const { | 105 CookieSettings::GetDefaultCookieSetting(std::string* provider_id) const { |
| 103 return host_content_settings_map_->GetDefaultContentSetting( | 106 return host_content_settings_map_->GetDefaultContentSetting( |
| 104 CONTENT_SETTINGS_TYPE_COOKIES, provider_id); | 107 CONTENT_SETTINGS_TYPE_COOKIES, provider_id); |
| 105 } | 108 } |
| 106 | 109 |
| 107 bool CookieSettings::IsReadingCookieAllowed(const GURL& url, | 110 bool CookieSettings::IsReadingCookieAllowed(const GURL& url, |
| 108 const GURL& first_party_url) const { | 111 const GURL& first_party_url) const { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 151 } |
| 149 | 152 |
| 150 void CookieSettings::ResetCookieSetting( | 153 void CookieSettings::ResetCookieSetting( |
| 151 const ContentSettingsPattern& primary_pattern, | 154 const ContentSettingsPattern& primary_pattern, |
| 152 const ContentSettingsPattern& secondary_pattern) { | 155 const ContentSettingsPattern& secondary_pattern) { |
| 153 host_content_settings_map_->SetContentSetting( | 156 host_content_settings_map_->SetContentSetting( |
| 154 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_COOKIES, "", | 157 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_COOKIES, "", |
| 155 CONTENT_SETTING_DEFAULT); | 158 CONTENT_SETTING_DEFAULT); |
| 156 } | 159 } |
| 157 | 160 |
| 158 void CookieSettings::OnPreferenceChanged(PrefServiceBase* prefs, | |
| 159 const std::string& name) { | |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 161 DCHECK_EQ(std::string(prefs::kBlockThirdPartyCookies), name); | |
| 162 | |
| 163 base::AutoLock auto_lock(lock_); | |
| 164 block_third_party_cookies_ = prefs->GetBoolean( | |
| 165 prefs::kBlockThirdPartyCookies); | |
| 166 } | |
| 167 | |
| 168 void CookieSettings::ShutdownOnUIThread() { | 161 void CookieSettings::ShutdownOnUIThread() { |
| 169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 170 pref_change_registrar_.RemoveAll(); | 163 pref_change_registrar_.RemoveAll(); |
| 171 } | 164 } |
| 172 | 165 |
| 173 ContentSetting CookieSettings::GetCookieSetting( | 166 ContentSetting CookieSettings::GetCookieSetting( |
| 174 const GURL& url, | 167 const GURL& url, |
| 175 const GURL& first_party_url, | 168 const GURL& first_party_url, |
| 176 bool setting_cookie, | 169 bool setting_cookie, |
| 177 content_settings::SettingSource* source) const { | 170 content_settings::SettingSource* source) const { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 208 return CONTENT_SETTING_BLOCK; | 201 return CONTENT_SETTING_BLOCK; |
| 209 } | 202 } |
| 210 | 203 |
| 211 // We should always have a value, at least from the default provider. | 204 // We should always have a value, at least from the default provider. |
| 212 DCHECK(value.get()); | 205 DCHECK(value.get()); |
| 213 return content_settings::ValueToContentSetting(value.get()); | 206 return content_settings::ValueToContentSetting(value.get()); |
| 214 } | 207 } |
| 215 | 208 |
| 216 CookieSettings::~CookieSettings() {} | 209 CookieSettings::~CookieSettings() {} |
| 217 | 210 |
| 211 void CookieSettings::OnBlockThirdPartyCookiesChanged() { |
| 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 213 |
| 214 base::AutoLock auto_lock(lock_); |
| 215 block_third_party_cookies_ = pref_change_registrar_.prefs()->GetBoolean( |
| 216 prefs::kBlockThirdPartyCookies); |
| 217 } |
| 218 |
| 218 bool CookieSettings::ShouldBlockThirdPartyCookies() const { | 219 bool CookieSettings::ShouldBlockThirdPartyCookies() const { |
| 219 base::AutoLock auto_lock(lock_); | 220 base::AutoLock auto_lock(lock_); |
| 220 return block_third_party_cookies_; | 221 return block_third_party_cookies_; |
| 221 } | 222 } |
| OLD | NEW |