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 "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/content_settings/content_settings_utils.h" | 9 #include "chrome/browser/content_settings/content_settings_utils.h" |
10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 10 #include "chrome/browser/content_settings/host_content_settings_map.h" |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 bool CookieSettings::IsCookieSessionOnly(const GURL& origin) const { | 124 bool CookieSettings::IsCookieSessionOnly(const GURL& origin) const { |
125 ContentSetting setting = GetCookieSetting(origin, origin, true, NULL); | 125 ContentSetting setting = GetCookieSetting(origin, origin, true, NULL); |
126 DCHECK(IsValidSetting(setting)); | 126 DCHECK(IsValidSetting(setting)); |
127 return (setting == CONTENT_SETTING_SESSION_ONLY); | 127 return (setting == CONTENT_SETTING_SESSION_ONLY); |
128 } | 128 } |
129 | 129 |
130 void CookieSettings::GetCookieSettings( | 130 void CookieSettings::GetCookieSettings( |
131 ContentSettingsForOneType* settings) const { | 131 ContentSettingsForOneType* settings) const { |
132 return host_content_settings_map_->GetSettingsForOneType( | 132 return host_content_settings_map_->GetSettingsForOneType( |
133 CONTENT_SETTINGS_TYPE_COOKIES, "", settings); | 133 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), settings); |
134 } | 134 } |
135 | 135 |
136 void CookieSettings::SetDefaultCookieSetting(ContentSetting setting) { | 136 void CookieSettings::SetDefaultCookieSetting(ContentSetting setting) { |
137 DCHECK(IsValidSetting(setting)); | 137 DCHECK(IsValidSetting(setting)); |
138 host_content_settings_map_->SetDefaultContentSetting( | 138 host_content_settings_map_->SetDefaultContentSetting( |
139 CONTENT_SETTINGS_TYPE_COOKIES, setting); | 139 CONTENT_SETTINGS_TYPE_COOKIES, setting); |
140 } | 140 } |
141 | 141 |
142 void CookieSettings::SetCookieSetting( | 142 void CookieSettings::SetCookieSetting( |
143 const ContentSettingsPattern& primary_pattern, | 143 const ContentSettingsPattern& primary_pattern, |
144 const ContentSettingsPattern& secondary_pattern, | 144 const ContentSettingsPattern& secondary_pattern, |
145 ContentSetting setting) { | 145 ContentSetting setting) { |
146 DCHECK(IsValidSetting(setting)); | 146 DCHECK(IsValidSetting(setting)); |
147 if (setting == CONTENT_SETTING_SESSION_ONLY) { | 147 if (setting == CONTENT_SETTING_SESSION_ONLY) { |
148 DCHECK(secondary_pattern == ContentSettingsPattern::Wildcard()); | 148 DCHECK(secondary_pattern == ContentSettingsPattern::Wildcard()); |
149 } | 149 } |
150 host_content_settings_map_->SetContentSetting( | 150 host_content_settings_map_->SetContentSetting(primary_pattern, |
151 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_COOKIES, "", | 151 secondary_pattern, |
152 setting); | 152 CONTENT_SETTINGS_TYPE_COOKIES, |
| 153 std::string(), |
| 154 setting); |
153 } | 155 } |
154 | 156 |
155 void CookieSettings::ResetCookieSetting( | 157 void CookieSettings::ResetCookieSetting( |
156 const ContentSettingsPattern& primary_pattern, | 158 const ContentSettingsPattern& primary_pattern, |
157 const ContentSettingsPattern& secondary_pattern) { | 159 const ContentSettingsPattern& secondary_pattern) { |
158 host_content_settings_map_->SetContentSetting( | 160 host_content_settings_map_->SetContentSetting(primary_pattern, |
159 primary_pattern, secondary_pattern, CONTENT_SETTINGS_TYPE_COOKIES, "", | 161 secondary_pattern, |
160 CONTENT_SETTING_DEFAULT); | 162 CONTENT_SETTINGS_TYPE_COOKIES, |
| 163 std::string(), |
| 164 CONTENT_SETTING_DEFAULT); |
161 } | 165 } |
162 | 166 |
163 void CookieSettings::ShutdownOnUIThread() { | 167 void CookieSettings::ShutdownOnUIThread() { |
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
165 pref_change_registrar_.RemoveAll(); | 169 pref_change_registrar_.RemoveAll(); |
166 } | 170 } |
167 | 171 |
168 ContentSetting CookieSettings::GetCookieSetting( | 172 ContentSetting CookieSettings::GetCookieSetting( |
169 const GURL& url, | 173 const GURL& url, |
170 const GURL& first_party_url, | 174 const GURL& first_party_url, |
171 bool setting_cookie, | 175 bool setting_cookie, |
172 content_settings::SettingSource* source) const { | 176 content_settings::SettingSource* source) const { |
173 if (HostContentSettingsMap::ShouldAllowAllContent( | 177 if (HostContentSettingsMap::ShouldAllowAllContent( |
174 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) | 178 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) |
175 return CONTENT_SETTING_ALLOW; | 179 return CONTENT_SETTING_ALLOW; |
176 | 180 |
177 // First get any host-specific settings. | 181 // First get any host-specific settings. |
178 content_settings::SettingInfo info; | 182 content_settings::SettingInfo info; |
179 scoped_ptr<base::Value> value( | 183 scoped_ptr<base::Value> value(host_content_settings_map_->GetWebsiteSetting( |
180 host_content_settings_map_->GetWebsiteSetting( | 184 url, |
181 url, first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, "", &info)); | 185 first_party_url, |
| 186 CONTENT_SETTINGS_TYPE_COOKIES, |
| 187 std::string(), |
| 188 &info)); |
182 if (source) | 189 if (source) |
183 *source = info.source; | 190 *source = info.source; |
184 | 191 |
185 // If no explicit exception has been made and third-party cookies are blocked | 192 // If no explicit exception has been made and third-party cookies are blocked |
186 // by default, apply that rule. | 193 // by default, apply that rule. |
187 if (info.primary_pattern.MatchesAllHosts() && | 194 if (info.primary_pattern.MatchesAllHosts() && |
188 info.secondary_pattern.MatchesAllHosts() && | 195 info.secondary_pattern.MatchesAllHosts() && |
189 ShouldBlockThirdPartyCookies() && | 196 ShouldBlockThirdPartyCookies() && |
190 !first_party_url.SchemeIs(extensions::kExtensionScheme)) { | 197 !first_party_url.SchemeIs(extensions::kExtensionScheme)) { |
191 bool not_strict = CommandLine::ForCurrentProcess()->HasSwitch( | 198 bool not_strict = CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 23 matching lines...) Expand all Loading... |
215 | 222 |
216 base::AutoLock auto_lock(lock_); | 223 base::AutoLock auto_lock(lock_); |
217 block_third_party_cookies_ = pref_change_registrar_.prefs()->GetBoolean( | 224 block_third_party_cookies_ = pref_change_registrar_.prefs()->GetBoolean( |
218 prefs::kBlockThirdPartyCookies); | 225 prefs::kBlockThirdPartyCookies); |
219 } | 226 } |
220 | 227 |
221 bool CookieSettings::ShouldBlockThirdPartyCookies() const { | 228 bool CookieSettings::ShouldBlockThirdPartyCookies() const { |
222 base::AutoLock auto_lock(lock_); | 229 base::AutoLock auto_lock(lock_); |
223 return block_third_party_cookies_; | 230 return block_third_party_cookies_; |
224 } | 231 } |
OLD | NEW |