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; | |
45 return url.SchemeIs(chrome::kChromeDevToolsScheme) || | 42 return url.SchemeIs(chrome::kChromeDevToolsScheme) || |
46 url.SchemeIs(chrome::kChromeInternalScheme) || | 43 url.SchemeIs(chrome::kChromeInternalScheme) || |
47 url.SchemeIs(chrome::kChromeUIScheme) || | 44 url.SchemeIs(chrome::kChromeUIScheme) || |
48 url.SchemeIs(chrome::kExtensionScheme); | 45 url.SchemeIs(chrome::kExtensionScheme); |
49 } | 46 } |
50 | 47 |
51 typedef linked_ptr<content_settings::DefaultProviderInterface> | 48 typedef linked_ptr<content_settings::DefaultProviderInterface> |
52 DefaultContentSettingsProviderPtr; | 49 DefaultContentSettingsProviderPtr; |
53 typedef std::vector<DefaultContentSettingsProviderPtr>::iterator | 50 typedef std::vector<DefaultContentSettingsProviderPtr>::iterator |
54 DefaultProviderIterator; | 51 DefaultProviderIterator; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 ContentSettings output(CONTENT_SETTING_DEFAULT); | 177 ContentSettings output(CONTENT_SETTING_DEFAULT); |
181 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) | 178 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) |
182 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); | 179 output.settings[i] = GetDefaultContentSetting(ContentSettingsType(i)); |
183 return output; | 180 return output; |
184 } | 181 } |
185 | 182 |
186 ContentSetting HostContentSettingsMap::GetCookieContentSetting( | 183 ContentSetting HostContentSettingsMap::GetCookieContentSetting( |
187 const GURL& url, | 184 const GURL& url, |
188 const GURL& first_party_url, | 185 const GURL& first_party_url, |
189 bool setting_cookie) const { | 186 bool setting_cookie) const { |
190 if (ShouldAllowAllContent(first_party_url, CONTENT_SETTINGS_TYPE_COOKIES)) | 187 if (ShouldAllowAllContent(first_party_url)) |
191 return CONTENT_SETTING_ALLOW; | 188 return CONTENT_SETTING_ALLOW; |
192 | 189 |
193 // First get any host-specific settings. | 190 // First get any host-specific settings. |
194 ContentSetting setting = GetNonDefaultContentSetting(url, | 191 ContentSetting setting = GetNonDefaultContentSetting(url, |
195 first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 192 first_party_url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
196 | 193 |
197 // If no explicit exception has been made and third-party cookies are blocked | 194 // If no explicit exception has been made and third-party cookies are blocked |
198 // by default, apply that rule. | 195 // by default, apply that rule. |
199 if (setting == CONTENT_SETTING_DEFAULT && BlockThirdPartyCookies()) { | 196 if (setting == CONTENT_SETTING_DEFAULT && BlockThirdPartyCookies()) { |
200 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( | 197 bool strict = CommandLine::ForCurrentProcess()->HasSwitch( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 if (setting == CONTENT_SETTING_DEFAULT) | 238 if (setting == CONTENT_SETTING_DEFAULT) |
242 return GetDefaultContentSetting(content_type); | 239 return GetDefaultContentSetting(content_type); |
243 return setting; | 240 return setting; |
244 } | 241 } |
245 | 242 |
246 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( | 243 ContentSetting HostContentSettingsMap::GetNonDefaultContentSetting( |
247 const GURL& primary_url, | 244 const GURL& primary_url, |
248 const GURL& secondary_url, | 245 const GURL& secondary_url, |
249 ContentSettingsType content_type, | 246 ContentSettingsType content_type, |
250 const std::string& resource_identifier) const { | 247 const std::string& resource_identifier) const { |
251 if (ShouldAllowAllContent(secondary_url, content_type)) | 248 if (ShouldAllowAllContent(secondary_url)) |
252 return CONTENT_SETTING_ALLOW; | 249 return CONTENT_SETTING_ALLOW; |
253 | 250 |
254 // Iterate through the list of providers and break when the first non default | 251 // Iterate through the list of providers and break when the first non default |
255 // setting is found. | 252 // setting is found. |
256 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); | 253 ContentSetting provided_setting(CONTENT_SETTING_DEFAULT); |
257 for (ConstProviderIterator provider = content_settings_providers_.begin(); | 254 for (ConstProviderIterator provider = content_settings_providers_.begin(); |
258 provider != content_settings_providers_.end(); | 255 provider != content_settings_providers_.end(); |
259 ++provider) { | 256 ++provider) { |
260 provided_setting = (*provider)->GetContentSetting( | 257 provided_setting = (*provider)->GetContentSetting( |
261 primary_url, secondary_url, content_type, resource_identifier); | 258 primary_url, secondary_url, content_type, resource_identifier); |
(...skipping 18 matching lines...) Expand all Loading... |
280 j != CONTENT_SETTINGS_TYPE_PLUGINS) { | 277 j != CONTENT_SETTINGS_TYPE_PLUGINS) { |
281 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); | 278 output.settings[j] = GetDefaultContentSetting(ContentSettingsType(j)); |
282 } | 279 } |
283 } | 280 } |
284 return output; | 281 return output; |
285 } | 282 } |
286 | 283 |
287 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( | 284 ContentSettings HostContentSettingsMap::GetNonDefaultContentSettings( |
288 const GURL& primary_url, | 285 const GURL& primary_url, |
289 const GURL& secondary_url) const { | 286 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 |