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 <list> | 7 #include <list> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "googleurl/src/gurl.h" | 31 #include "googleurl/src/gurl.h" |
32 #include "net/base/net_errors.h" | 32 #include "net/base/net_errors.h" |
33 #include "net/base/net_util.h" | 33 #include "net/base/net_util.h" |
34 #include "net/base/static_cookie_policy.h" | 34 #include "net/base/static_cookie_policy.h" |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // Returns true if we should allow all content types for this URL. This is | 38 // Returns true if we should allow all content types for this URL. This is |
39 // true for various internal objects like chrome:// URLs, so UI and other | 39 // true for various internal objects like chrome:// URLs, so UI and other |
40 // things users think of as "not webpages" don't break. | 40 // things users think of as "not webpages" don't break. |
41 static bool ShouldAllowAllContent(const GURL& url) { | 41 static bool ShouldAllowAllContent(const GURL& url, |
| 42 ContentSettingsType content_type) { |
| 43 if (content_type == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) |
| 44 return false; |
42 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | 45 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
43 url.SchemeIs(chrome::kChromeInternalScheme) || | 46 url.SchemeIs(chrome::kChromeInternalScheme) || |
44 url.SchemeIs(chrome::kChromeUIScheme) || | 47 url.SchemeIs(chrome::kChromeUIScheme) || |
45 url.SchemeIs(chrome::kExtensionScheme); | 48 url.SchemeIs(chrome::kExtensionScheme); |
46 } | 49 } |
47 | 50 |
48 typedef linked_ptr<content_settings::DefaultProviderInterface> | 51 typedef linked_ptr<content_settings::DefaultProviderInterface> |
49 DefaultContentSettingsProviderPtr; | 52 DefaultContentSettingsProviderPtr; |
50 typedef std::vector<DefaultContentSettingsProviderPtr>::iterator | 53 typedef std::vector<DefaultContentSettingsProviderPtr>::iterator |
51 DefaultProviderIterator; | 54 DefaultProviderIterator; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 ContentSettings output(CONTENT_SETTING_DEFAULT); | 180 ContentSettings output(CONTENT_SETTING_DEFAULT); |
178 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) | 181 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) |
179 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); | 182 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); |
180 return output; | 183 return output; |
181 } | 184 } |
182 | 185 |
183 ContentSetting HostContentSettingsMap::GetCookieContentSetting( | 186 ContentSetting HostContentSettingsMap::GetCookieContentSetting( |
184 const GURL& url, | 187 const GURL& url, |
185 const GURL& first_party_url, | 188 const GURL& first_party_url, |
186 bool setting_cookie) const { | 189 bool setting_cookie) const { |
187 if (ShouldAllowAllContent(first_party_url)) | 190 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) |
188 return CONTENT_SETTING_ALLOW; | 191 return CONTENT_SETTING_ALLOW; |
189 | 192 |
190 // First get any host-specific settings. | 193 // First get any host-specific settings. |
191 ContentSetting setting = GetNonDefaultContentSetting(url, | 194 ContentSetting setting = GetNonDefaultContentSetting(url, |
192 first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 195 first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
193 | 196 |
194 // If no explicit exception has been made and third-party cookies are blocked | 197 // If no explicit exception has been made and third-party cookies are blocked |
195 // by default, apply that rule. | 198 // by default, apply that rule. |
196 if (setting == CONTENT_SETTING_DEFAULT && BlockThirdPartyCookies()) { | 199 if (setting == CONTENT_SETTING_DEFAULT && BlockThirdPartyCookies()) { |
197 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( | 200 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 if (setting == CONTENT_SETTING_DEFAULT) | 241 if (setting == CONTENT_SETTING_DEFAULT) |
239 return GetDefaultContentSetting(content_type); | 242 return GetDefaultContentSetting(content_type); |
240 return setting; | 243 return setting; |
241 } | 244 } |
242 | 245 |
243 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( | 246 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( |
244 const GURL& primary_url, | 247 const GURL& primary_url, |
245 const GURL& secondary_url, | 248 const GURL& secondary_url, |
246 ContentSettingsType content_type, | 249 ContentSettingsType content_type, |
247 const std::string& resource_identifier) const { | 250 const std::string& resource_identifier) const { |
248 if (ShouldAllowAllContent(secondary_url)) | 251 if (ShouldAllowAllContent(secondary_url, content_type)) |
249 return CONTENT_SETTING_ALLOW; | 252 return CONTENT_SETTING_ALLOW; |
250 | 253 |
251 // Iterate through the list of providers and break when the first non default | 254 // Iterate through the list of providers and break when the first non default |
252 // setting is found. | 255 // setting is found. |
253 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); | 256 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); |
254 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 257 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
255 provider != content_settings_providers_.end(); | 258 provider != content_settings_providers_.end(); |
256 ++provider) { | 259 ++provider) { |
257 provided_setting = (*provider)->GetContentSetting( | 260 provided_setting = (*provider)->GetContentSetting( |
258 primary_url, secondary_url, content_type, resource_identifier); | 261 primary_url, secondary_url, content_type, resource_identifier); |
(...skipping 18 matching lines...) Expand all Loading... |
277 j != CONTENT_SETTINGS_TYPE_PLUGINS) { | 280 j != CONTENT_SETTINGS_TYPE_PLUGINS) { |
278 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); | 281 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); |
279 } | 282 } |
280 } | 283 } |
281 return output; | 284 return output; |
282 } | 285 } |
283 | 286 |
284 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( | 287 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( |
285 const GURL& primary_url, | 288 const GURL& primary_url, |
286 const GURL& secondary_url) const { | 289 const GURL& secondary_url) const { |
287 if (ShouldAllowAllContent(secondary_url)) | |
288 return ContentSettings(CONTENT_SETTING_ALLOW); | |
289 | |
290 ContentSettings output(CONTENT_SETTING_DEFAULT); | 290 ContentSettings output(CONTENT_SETTING_DEFAULT); |
291 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { | 291 for (int j = 0; j < CONTENT_SETTINGS_NUM_TYPES; ++j) { |
292 output.settings[j] = GetNonDefaultContentSetting( | 292 output.settings[j] = GetNonDefaultContentSetting( |
293 primary_url, | 293 primary_url, |
294 secondary_url, | 294 secondary_url, |
295 ContentSettingsType(j), | 295 ContentSettingsType(j), |
296 ""); | 296 ""); |
297 } | 297 } |
298 return output; | 298 return output; |
299 } | 299 } |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, | 543 SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_COOKIES, |
544 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? | 544 (cookie_behavior == net::StaticCookiePolicy::BLOCK_ALL_COOKIES) ? |
545 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); | 545 CONTENT_SETTING_BLOCK : CONTENT_SETTING_ALLOW); |
546 } | 546 } |
547 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { | 547 if (!prefs_->HasPrefPath(prefs::kBlockThirdPartyCookies)) { |
548 SetBlockThirdPartyCookies(cookie_behavior == | 548 SetBlockThirdPartyCookies(cookie_behavior == |
549 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); | 549 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
550 } | 550 } |
551 } | 551 } |
552 } | 552 } |
OLD | NEW |