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/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/content_settings/content_settings_extension_provider.h" | 10 #include "chrome/browser/content_settings/content_settings_extension_provider.h" |
11 #include "chrome/browser/content_settings/content_settings_policy_provider.h" | 11 #include "chrome/browser/content_settings/content_settings_policy_provider.h" |
12 #include "chrome/browser/content_settings/content_settings_pref_provider.h" | 12 #include "chrome/browser/content_settings/content_settings_pref_provider.h" |
13 #include "chrome/browser/content_settings/content_settings_provider.h" | 13 #include "chrome/browser/content_settings/content_settings_provider.h" |
14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
16 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
22 #include "content/browser/user_metrics.h" | 22 #include "content/browser/user_metrics.h" |
23 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
24 #include "content/common/notification_source.h" | 24 #include "content/common/notification_source.h" |
25 #include "content/common/notification_type.h" | 25 #include "content/common/notification_type.h" |
26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 27 #include "net/base/net_errors.h" |
27 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
28 #include "net/base/static_cookie_policy.h" | 29 #include "net/base/static_cookie_policy.h" |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 // Returns true if we should allow all content types for this URL. This is | 33 // Returns true if we should allow all content types for this URL. This is |
33 // true for various internal objects like chrome:// URLs, so UI and other | 34 // true for various internal objects like chrome:// URLs, so UI and other |
34 // things users think of as "not webpages" don't break. | 35 // things users think of as "not webpages" don't break. |
35 static bool ShouldAllowAllContent(const GURL& url) { | 36 static bool ShouldAllowAllContent(const GURL& url) { |
36 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | 37 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // value that is to be used as default. We here rely on the | 155 // value that is to be used as default. We here rely on the |
155 // PrefContentSettingProvider to always provide a value. | 156 // PrefContentSettingProvider to always provide a value. |
156 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); | 157 CHECK_NE(CONTENT_SETTING_DEFAULT, setting); |
157 return setting; | 158 return setting; |
158 } | 159 } |
159 | 160 |
160 ContentSetting HostContentSettingsMap::GetContentSetting( | 161 ContentSetting HostContentSettingsMap::GetContentSetting( |
161 const GURL& url, | 162 const GURL& url, |
162 ContentSettingsType content_type, | 163 ContentSettingsType content_type, |
163 const std::string& resource_identifier) const { | 164 const std::string& resource_identifier) const { |
| 165 DCHECK_NE(CONTENT_SETTINGS_TYPE_COOKIES, content_type); |
| 166 return GetContentSettingInternal(url, content_type, resource_identifier); |
| 167 } |
| 168 |
| 169 ContentSetting HostContentSettingsMap::GetContentSettingInternal( |
| 170 const GURL& url, |
| 171 ContentSettingsType content_type, |
| 172 const std::string& resource_identifier) const { |
164 ContentSetting setting = GetNonDefaultContentSetting(url, | 173 ContentSetting setting = GetNonDefaultContentSetting(url, |
165 content_type, | 174 content_type, |
166 resource_identifier); | 175 resource_identifier); |
167 if (setting == CONTENT_SETTING_DEFAULT) | 176 if (setting == CONTENT_SETTING_DEFAULT) |
168 return GetDefaultContentSetting(content_type); | 177 return GetDefaultContentSetting(content_type); |
169 return setting; | 178 return setting; |
170 } | 179 } |
171 | 180 |
| 181 ContentSetting HostContentSettingsMap::GetCookieContentSetting( |
| 182 const GURL& url, |
| 183 const GURL& first_party_url, |
| 184 bool setting_cookie) const { |
| 185 ContentSetting setting = CONTENT_SETTING_ALLOW; |
| 186 if (BlockThirdPartyCookies()) { |
| 187 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( |
| 188 switches::kBlockReadingThirdPartyCookies); |
| 189 net::StaticCookiePolicy policy(strict ? |
| 190 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : |
| 191 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
| 192 int rv; |
| 193 if (setting_cookie) |
| 194 rv = policy.CanSetCookie(url, first_party_url); |
| 195 else |
| 196 rv = policy.CanGetCookies(url, first_party_url); |
| 197 DCHECK_NE(net::ERR_IO_PENDING, rv); |
| 198 if (rv != net::OK) |
| 199 setting = CONTENT_SETTING_BLOCK; |
| 200 } |
| 201 |
| 202 if (setting == CONTENT_SETTING_ALLOW) |
| 203 setting = GetContentSettingInternal(url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
| 204 |
| 205 return setting; |
| 206 } |
| 207 |
172 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( | 208 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( |
173 const GURL& url, | 209 const GURL& url, |
174 ContentSettingsType content_type, | 210 ContentSettingsType content_type, |
175 const std::string& resource_identifier) const { | 211 const std::string& resource_identifier) const { |
176 if (ShouldAllowAllContent(url)) | 212 if (ShouldAllowAllContent(url)) |
177 return CONTENT_SETTING_ALLOW; | 213 return CONTENT_SETTING_ALLOW; |
178 | 214 |
179 // Iterate through the list of providers and break when the first non default | 215 // Iterate through the list of providers and break when the first non default |
180 // setting is found. | 216 // setting is found. |
181 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); | 217 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 463 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
428 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | 464 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? |
429 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | 465 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); |
430 } | 466 } |
431 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | 467 if (!prefs->HasPrefPath(prefs::kBlockThirdPartyCookies)) { |
432 SetBlockThirdPartyCookies(cookie_behavior == | 468 SetBlockThirdPartyCookies(cookie_behavior == |
433 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 469 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
434 } | 470 } |
435 } | 471 } |
436 } | 472 } |
OLD | NEW |