summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net/chrome_url_request_context.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/net/chrome_url_request_context.cc')
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc77
1 files changed, 52 insertions, 25 deletions
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index 7963742..dee0d62 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -22,6 +22,7 @@
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h"
+#include "net/base/static_cookie_policy.h"
#include "net/ftp/ftp_network_layer.h"
#include "net/http/http_cache.h"
#include "net/http/http_network_layer.h"
@@ -544,15 +545,6 @@ void ChromeURLRequestContextGetter::Observe(
this,
&ChromeURLRequestContextGetter::OnAcceptLanguageChange,
accept_language));
- } else if (*pref_name_in == prefs::kCookieBehavior) {
- net::CookiePolicy::Type policy_type = net::CookiePolicy::FromInt(
- prefs_->GetInteger(prefs::kCookieBehavior));
- ChromeThread::PostTask(
- ChromeThread::IO, FROM_HERE,
- NewRunnableMethod(
- this,
- &ChromeURLRequestContextGetter::OnCookiePolicyChange,
- policy_type));
} else if (*pref_name_in == prefs::kDefaultCharset) {
std::string default_charset =
WideToASCII(prefs->GetString(prefs::kDefaultCharset));
@@ -596,11 +588,6 @@ void ChromeURLRequestContextGetter::OnAcceptLanguageChange(
GetIOContext()->OnAcceptLanguageChange(accept_language);
}
-void ChromeURLRequestContextGetter::OnCookiePolicyChange(
- net::CookiePolicy::Type type) {
- GetIOContext()->OnCookiePolicyChange(type);
-}
-
void ChromeURLRequestContextGetter::OnDefaultCharsetChange(
const std::string& default_charset) {
GetIOContext()->OnDefaultCharsetChange(default_charset);
@@ -620,12 +607,16 @@ void ChromeURLRequestContextGetter::GetCookieStoreAsyncHelper(
ChromeURLRequestContext::ChromeURLRequestContext() {
CheckCurrentlyOnIOThread();
+
+ cookie_policy_ = this; // We implement CookiePolicy
+
url_request_tracker()->SetGraveyardFilter(
&ChromeURLRequestContext::ShouldTrackRequest);
}
ChromeURLRequestContext::~ChromeURLRequestContext() {
CheckCurrentlyOnIOThread();
+
if (appcache_service_.get() && appcache_service_->request_context() == this)
appcache_service_->set_request_context(NULL);
@@ -650,6 +641,8 @@ ChromeURLRequestContext::~ChromeURLRequestContext() {
delete ftp_transaction_factory_;
delete http_transaction_factory_;
+
+ cookie_policy_ = NULL;
}
FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) {
@@ -758,10 +751,55 @@ void ChromeURLRequestContext::OnUnloadedExtension(const std::string& id) {
extension_info_.erase(iter);
}
+bool ChromeURLRequestContext::AreCookiesEnabled() const {
+ ContentSetting setting =
+ host_content_settings_map_->GetDefaultContentSetting(
+ CONTENT_SETTINGS_TYPE_COOKIES);
+ return setting != CONTENT_SETTING_BLOCK;
+}
+
+bool ChromeURLRequestContext::CanGetCookies(const GURL& url,
+ const GURL& first_party) {
+ if (host_content_settings_map_->BlockThirdPartyCookies()) {
+ net::StaticCookiePolicy policy(
+ net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
+ if (!policy.CanGetCookies(url, first_party))
+ return false;
+ }
+
+ ContentSetting setting = host_content_settings_map_->GetContentSetting(
+ url.host(), CONTENT_SETTINGS_TYPE_COOKIES);
+ if (setting == CONTENT_SETTING_BLOCK)
+ return false;
+
+ // TODO(darin): Implement CONTENT_SETTING_ASK
+ return true;
+}
+
+bool ChromeURLRequestContext::CanSetCookie(const GURL& url,
+ const GURL& first_party) {
+ if (host_content_settings_map_->BlockThirdPartyCookies()) {
+ net::StaticCookiePolicy policy(
+ net::StaticCookiePolicy::BLOCK_THIRD_PARTY_COOKIES);
+ if (!policy.CanSetCookie(url, first_party))
+ return false;
+ }
+
+ ContentSetting setting = host_content_settings_map_->GetContentSetting(
+ url.host(), CONTENT_SETTINGS_TYPE_COOKIES);
+ if (setting == CONTENT_SETTING_BLOCK)
+ return false;
+
+ // TODO(darin): Implement CONTENT_SETTING_ASK
+ return true;
+}
+
ChromeURLRequestContext::ChromeURLRequestContext(
ChromeURLRequestContext* other) {
CheckCurrentlyOnIOThread();
+ cookie_policy_ = this; // We implement CookiePolicy
+
// Set URLRequestContext members
host_resolver_ = other->host_resolver_;
proxy_service_ = other->proxy_service_;
@@ -769,7 +807,6 @@ ChromeURLRequestContext::ChromeURLRequestContext(
http_transaction_factory_ = other->http_transaction_factory_;
ftp_transaction_factory_ = other->ftp_transaction_factory_;
cookie_store_ = other->cookie_store_;
- cookie_policy_.set_type(other->cookie_policy_.type());
transport_security_state_ = other->transport_security_state_;
accept_language_ = other->accept_language_;
accept_charset_ = other->accept_charset_;
@@ -793,12 +830,6 @@ void ChromeURLRequestContext::OnAcceptLanguageChange(
net::HttpUtil::GenerateAcceptLanguageHeader(accept_language);
}
-void ChromeURLRequestContext::OnCookiePolicyChange(
- net::CookiePolicy::Type type) {
- CheckCurrentlyOnIOThread();
- cookie_policy_.set_type(type);
-}
-
void ChromeURLRequestContext::OnDefaultCharsetChange(
const std::string& default_charset) {
CheckCurrentlyOnIOThread();
@@ -850,9 +881,6 @@ ChromeURLRequestContextFactory::ChromeURLRequestContextFactory(Profile* profile)
// net_util::GetSuggestedFilename is unlikely to be taken.
referrer_charset_ = default_charset;
- cookie_policy_type_ = net::CookiePolicy::FromInt(
- prefs->GetInteger(prefs::kCookieBehavior));
-
host_content_settings_map_ = profile->GetHostContentSettingsMap();
host_zoom_map_ = profile->GetHostZoomMap();
@@ -898,7 +926,6 @@ void ChromeURLRequestContextFactory::ApplyProfileParametersToContext(
context->set_accept_language(accept_language_);
context->set_accept_charset(accept_charset_);
context->set_referrer_charset(referrer_charset_);
- context->set_cookie_policy_type(cookie_policy_type_);
context->set_extension_info(extension_info_);
context->set_user_script_dir_path(user_script_dir_path_);
context->set_host_content_settings_map(host_content_settings_map_);