| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/net/chrome_cookie_policy.h" | 5 #include "chrome/browser/net/chrome_cookie_policy.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 8 #include "chrome/browser/browser_list.h" | 9 #include "chrome/browser/browser_list.h" |
| 9 #include "chrome/browser/browser_thread.h" | 10 #include "chrome/browser/browser_thread.h" |
| 10 #include "chrome/browser/content_settings/host_content_settings_map.h" | 11 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 12 #include "chrome/common/chrome_switches.h" |
| 11 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 12 #include "net/base/static_cookie_policy.h" | 14 #include "net/base/static_cookie_policy.h" |
| 13 | 15 |
| 14 // If we queue up more than this number of completions, then switch from ASK to | 16 // If we queue up more than this number of completions, then switch from ASK to |
| 15 // BLOCK. More than this number of requests at once seems like it could be a | 17 // BLOCK. More than this number of requests at once seems like it could be a |
| 16 // sign of trouble anyways. | 18 // sign of trouble anyways. |
| 17 static const size_t kMaxCompletionsPerHost = 10000; | 19 static const size_t kMaxCompletionsPerHost = 10000; |
| 18 | 20 |
| 19 // ---------------------------------------------------------------------------- | 21 // ---------------------------------------------------------------------------- |
| 20 | 22 |
| 21 ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map) | 23 ChromeCookiePolicy::ChromeCookiePolicy(HostContentSettingsMap* map) |
| 22 : host_content_settings_map_(map) { | 24 : host_content_settings_map_(map) { |
| 25 strict_third_party_blocking_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 26 switches::kBlockReadingThirdPartyCookies); |
| 23 } | 27 } |
| 24 | 28 |
| 25 ChromeCookiePolicy::~ChromeCookiePolicy() { | 29 ChromeCookiePolicy::~ChromeCookiePolicy() { |
| 26 DCHECK(host_completions_map_.empty()); | 30 DCHECK(host_completions_map_.empty()); |
| 27 } | 31 } |
| 28 | 32 |
| 29 int ChromeCookiePolicy::CanGetCookies(const GURL& url, | 33 int ChromeCookiePolicy::CanGetCookies(const GURL& url, |
| 30 const GURL& first_party, | 34 const GURL& first_party, |
| 31 net::CompletionCallback* callback) { | 35 net::CompletionCallback* callback) { |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 33 | 37 |
| 34 if (host_content_settings_map_->BlockThirdPartyCookies()) { | 38 if (host_content_settings_map_->BlockThirdPartyCookies()) { |
| 35 net::StaticCookiePolicy policy( | 39 net::StaticCookiePolicy policy(strict_third_party_blocking_ ? |
| 36 net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES); | 40 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : |
| 41 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
| 37 int rv = policy.CanGetCookies(url, first_party, NULL); | 42 int rv = policy.CanGetCookies(url, first_party, NULL); |
| 38 if (rv != net::OK) | 43 if (rv != net::OK) |
| 39 return rv; | 44 return rv; |
| 40 } | 45 } |
| 41 | 46 |
| 42 int policy = CheckPolicy(url); | 47 int policy = CheckPolicy(url); |
| 43 if (policy == net::OK_FOR_SESSION_ONLY) | 48 if (policy == net::OK_FOR_SESSION_ONLY) |
| 44 policy = net::OK; | 49 policy = net::OK; |
| 45 if (policy != net::ERR_IO_PENDING) | 50 if (policy != net::ERR_IO_PENDING) |
| 46 return policy; | 51 return policy; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 62 return policy; | 67 return policy; |
| 63 } | 68 } |
| 64 | 69 |
| 65 int ChromeCookiePolicy::CanSetCookie(const GURL& url, | 70 int ChromeCookiePolicy::CanSetCookie(const GURL& url, |
| 66 const GURL& first_party, | 71 const GURL& first_party, |
| 67 const std::string& cookie_line, | 72 const std::string& cookie_line, |
| 68 net::CompletionCallback* callback) { | 73 net::CompletionCallback* callback) { |
| 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 70 | 75 |
| 71 if (host_content_settings_map_->BlockThirdPartyCookies()) { | 76 if (host_content_settings_map_->BlockThirdPartyCookies()) { |
| 72 net::StaticCookiePolicy policy( | 77 net::StaticCookiePolicy policy(strict_third_party_blocking_ ? |
| 73 net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES); | 78 net::StaticCookiePolicy::BLOCK_ALL_THIRD_PARTY_COOKIES : |
| 79 net::StaticCookiePolicy::BLOCK_SETTING_THIRD_PARTY_COOKIES); |
| 74 int rv = policy.CanSetCookie(url, first_party, cookie_line, NULL); | 80 int rv = policy.CanSetCookie(url, first_party, cookie_line, NULL); |
| 75 if (rv != net::OK) | 81 if (rv != net::OK) |
| 76 return rv; | 82 return rv; |
| 77 } | 83 } |
| 78 | 84 |
| 79 int policy = CheckPolicy(url); | 85 int policy = CheckPolicy(url); |
| 80 if (policy != net::ERR_IO_PENDING) | 86 if (policy != net::ERR_IO_PENDING) |
| 81 return policy; | 87 return policy; |
| 82 | 88 |
| 83 DCHECK(callback); | 89 DCHECK(callback); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 99 url, CONTENT_SETTINGS_TYPE_COOKIES, ""); | 105 url, CONTENT_SETTINGS_TYPE_COOKIES, ""); |
| 100 if (setting == CONTENT_SETTING_BLOCK) | 106 if (setting == CONTENT_SETTING_BLOCK) |
| 101 return net::ERR_ACCESS_DENIED; | 107 return net::ERR_ACCESS_DENIED; |
| 102 if (setting == CONTENT_SETTING_ALLOW) | 108 if (setting == CONTENT_SETTING_ALLOW) |
| 103 return net::OK; | 109 return net::OK; |
| 104 if (setting == CONTENT_SETTING_SESSION_ONLY) | 110 if (setting == CONTENT_SETTING_SESSION_ONLY) |
| 105 return net::OK_FOR_SESSION_ONLY; | 111 return net::OK_FOR_SESSION_ONLY; |
| 106 return net::ERR_IO_PENDING; // Need to prompt. | 112 return net::ERR_IO_PENDING; // Need to prompt. |
| 107 } | 113 } |
| 108 | 114 |
| OLD | NEW |