Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2944)

Unified Diff: chrome/browser/net/chrome_url_request_context.cc

Issue 556095: Changes to support new cookie policy.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | chrome/browser/net/cookie_policy_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/net/chrome_url_request_context.cc
===================================================================
--- chrome/browser/net/chrome_url_request_context.cc (revision 37613)
+++ chrome/browser/net/chrome_url_request_context.cc (working copy)
@@ -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 @@
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 @@
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 @@
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 @@
delete ftp_transaction_factory_;
delete http_transaction_factory_;
+
+ cookie_policy_ = NULL;
}
FilePath ChromeURLRequestContext::GetPathForExtension(const std::string& id) {
@@ -758,10 +751,55 @@
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 @@
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 @@
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 @@
// 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 @@
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_);
« no previous file with comments | « chrome/browser/net/chrome_url_request_context.h ('k') | chrome/browser/net/cookie_policy_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698