diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-12 15:51:23 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-12 15:51:23 +0000 |
commit | 9025016cccf554e56096e0ba220cb6e38e9c57ce (patch) | |
tree | 830d15fa74ef752e787c3984eb23aee4c3bdc32c /net | |
parent | d91aaac40c25cbd3f289453191539834e5e97427 (diff) | |
download | chromium_src-9025016cccf554e56096e0ba220cb6e38e9c57ce.zip chromium_src-9025016cccf554e56096e0ba220cb6e38e9c57ce.tar.gz chromium_src-9025016cccf554e56096e0ba220cb6e38e9c57ce.tar.bz2 |
Get rid of net::CookiePolicy, now that all code that uses it (except WebSocketJob, which appears to be unused and which I updated in this cl) is switched over to use ContentBrowserClient.
BUG=76793
Review URL: http://codereview.chromium.org/6973011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85136 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/cookie_policy.h | 48 | ||||
-rw-r--r-- | net/base/static_cookie_policy.h | 18 | ||||
-rw-r--r-- | net/net.gyp | 1 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.h | 16 | ||||
-rw-r--r-- | net/url_request/url_request_context.cc | 2 | ||||
-rw-r--r-- | net/url_request/url_request_context.h | 9 | ||||
-rw-r--r-- | net/url_request/url_request_context_storage.cc | 6 | ||||
-rw-r--r-- | net/url_request/url_request_context_storage.h | 3 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.cc | 56 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.h | 2 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 1 | ||||
-rw-r--r-- | net/websockets/websocket_job.cc | 46 | ||||
-rw-r--r-- | net/websockets/websocket_job.h | 2 | ||||
-rw-r--r-- | net/websockets/websocket_job_unittest.cc | 56 |
14 files changed, 74 insertions, 192 deletions
diff --git a/net/base/cookie_policy.h b/net/base/cookie_policy.h deleted file mode 100644 index 59ec7ef..0000000 --- a/net/base/cookie_policy.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_BASE_COOKIE_POLICY_H_ -#define NET_BASE_COOKIE_POLICY_H_ -#pragma once - -#include <string> - -#include "net/base/completion_callback.h" - -class GURL; - -namespace net { - -// Alternative success codes for CookiePolicy::Can{Get,Set}Cookie(s). -enum { - OK_FOR_SESSION_ONLY = 1, // The cookie may be set but not persisted. -}; - -class CookiePolicy { - public: - virtual ~CookiePolicy() {} - - // Determines if the URL's cookies may be read. - // - // Returns: - // OK - if allowed to read cookies - // ERR_ACCESS_DENIED - if not allowed to read cookies - virtual int CanGetCookies(const GURL& url, - const GURL& first_party_for_cookies) const = 0; - - // Determines if the URL's cookies may be written. - // - // Returns: - // OK - if allowed to write cookies - // OK_FOR_SESSION_ONLY - if allowed to write cookies, but forces them to - // be stored as session cookies - // ERR_ACCESS_DENIED - if not allowed to write cookies - virtual int CanSetCookie(const GURL& url, - const GURL& first_party_for_cookies, - const std::string& cookie_line) const = 0; -}; - -} // namespace net - -#endif // NET_BASE_COOKIE_POLICY_H_ diff --git a/net/base/static_cookie_policy.h b/net/base/static_cookie_policy.h index 77a62e8..12a78cd 100644 --- a/net/base/static_cookie_policy.h +++ b/net/base/static_cookie_policy.h @@ -9,7 +9,6 @@ #include <string> #include "base/basictypes.h" -#include "net/base/cookie_policy.h" class GURL; @@ -17,11 +16,7 @@ namespace net { // The StaticCookiePolicy class implements a static cookie policy that supports // three modes: allow all, deny all, or block third-party cookies. -// -// NOTE: This CookiePolicy implementation always completes synchronously. The -// callback parameter will be ignored if specified. Just pass NULL. -// -class StaticCookiePolicy : public CookiePolicy { +class StaticCookiePolicy { public: // Do not change the order of these types as they are persisted in // preferences. @@ -49,18 +44,15 @@ class StaticCookiePolicy : public CookiePolicy { void set_type(Type type) { type_ = type; } Type type() const { return type_; } - // CookiePolicy methods: - // Consults the user's third-party cookie blocking preferences to determine // whether the URL's cookies can be read. - virtual int CanGetCookies(const GURL& url, - const GURL& first_party_for_cookies) const; + int CanGetCookies(const GURL& url, const GURL& first_party_for_cookies) const; // Consults the user's third-party cookie blocking preferences to determine // whether the URL's cookies can be set. - virtual int CanSetCookie(const GURL& url, - const GURL& first_party_for_cookies, - const std::string& cookie_line) const; + int CanSetCookie(const GURL& url, + const GURL& first_party_for_cookies, + const std::string& cookie_line) const; private: Type type_; diff --git a/net/net.gyp b/net/net.gyp index 8eb2b65..cca149e 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -58,7 +58,6 @@ 'base/cookie_monster.cc', 'base/cookie_monster.h', 'base/cookie_options.h', - 'base/cookie_policy.h', 'base/cookie_store.cc', 'base/cookie_store.h', 'base/crypto_module.h', diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 08d840c..b41777f 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -32,6 +32,7 @@ namespace net { class AuthChallengeInfo; class ClientSocketFactory; +class CookieOptions; class HostResolver; class HttpAuthHandlerFactory; class SSLConfigService; @@ -95,6 +96,21 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { // This is only for error reporting to the delegate. // |error| is net::Error. virtual void OnError(const SocketStream* socket, int error) {} + + // Called when reading cookies to allow the delegate to block access to the + // cookie. + virtual bool CanGetCookies(SocketStream* socket, const GURL& url) { + return true; + } + + // Called when a cookie is set to allow the delegate to block access to the + // cookie. + virtual bool CanSetCookie(SocketStream* request, + const GURL& url, + const std::string& cookie_line, + CookieOptions* options) { + return true; + } }; SocketStream(const GURL& url, Delegate* delegate); diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc index 7e02641..c197ebe 100644 --- a/net/url_request/url_request_context.cc +++ b/net/url_request/url_request_context.cc @@ -21,7 +21,6 @@ URLRequestContext::URLRequestContext() dns_cert_checker_(NULL), http_auth_handler_factory_(NULL), network_delegate_(NULL), - cookie_policy_(NULL), transport_security_state_(NULL), http_transaction_factory_(NULL), ftp_transaction_factory_(NULL) { @@ -40,7 +39,6 @@ void URLRequestContext::CopyFrom(URLRequestContext* other) { set_ssl_config_service(other->ssl_config_service()); set_network_delegate(other->network_delegate()); set_cookie_store(other->cookie_store()); - set_cookie_policy(other->cookie_policy()); set_transport_security_state(other->transport_security_state()); // FTPAuthCache is unique per context. set_accept_language(other->accept_language()); diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index ae09f4d..bc74459 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -21,7 +21,6 @@ namespace net { class CertVerifier; -class CookiePolicy; class CookieStore; class DnsCertProvenanceChecker; class DnsRRResolver; @@ -133,13 +132,6 @@ class URLRequestContext CookieStore* cookie_store() const { return cookie_store_.get(); } void set_cookie_store(CookieStore* cookie_store); - // Gets the cookie policy for this context (may be null, in which case - // cookies are allowed). - CookiePolicy* cookie_policy() const { return cookie_policy_; } - void set_cookie_policy(CookiePolicy* cookie_policy) { - cookie_policy_ = cookie_policy; - } - TransportSecurityState* transport_security_state() const { return transport_security_state_; } @@ -206,7 +198,6 @@ class URLRequestContext scoped_refptr<SSLConfigService> ssl_config_service_; NetworkDelegate* network_delegate_; scoped_refptr<CookieStore> cookie_store_; - CookiePolicy* cookie_policy_; scoped_refptr<TransportSecurityState> transport_security_state_; FtpAuthCache ftp_auth_cache_; std::string accept_language_; diff --git a/net/url_request/url_request_context_storage.cc b/net/url_request/url_request_context_storage.cc index c2b9be7..d54614a 100644 --- a/net/url_request/url_request_context_storage.cc +++ b/net/url_request/url_request_context_storage.cc @@ -6,7 +6,6 @@ #include "base/logging.h" #include "net/base/cert_verifier.h" -#include "net/base/cookie_policy.h" #include "net/base/cookie_store.h" #include "net/base/dnsrr_resolver.h" #include "net/base/host_resolver.h" @@ -82,11 +81,6 @@ void URLRequestContextStorage::set_cookie_store(CookieStore* cookie_store) { cookie_store_ = cookie_store; } -void URLRequestContextStorage::set_cookie_policy(CookiePolicy* cookie_policy) { - context_->set_cookie_policy(cookie_policy); - cookie_policy_.reset(cookie_policy); -} - void URLRequestContextStorage::set_transport_security_state( TransportSecurityState* transport_security_state) { context_->set_transport_security_state(transport_security_state); diff --git a/net/url_request/url_request_context_storage.h b/net/url_request/url_request_context_storage.h index 5397981..ccb042e 100644 --- a/net/url_request/url_request_context_storage.h +++ b/net/url_request/url_request_context_storage.h @@ -13,7 +13,6 @@ namespace net { class CertVerifier; -class CookiePolicy; class CookieStore; class DnsCertProvenanceChecker; class DnsRRResolver; @@ -52,7 +51,6 @@ class URLRequestContextStorage { void set_ssl_config_service(SSLConfigService* ssl_config_service); void set_network_delegate(NetworkDelegate* network_delegate); void set_cookie_store(CookieStore* cookie_store); - void set_cookie_policy(CookiePolicy* cookie_policy); void set_transport_security_state( TransportSecurityState* transport_security_state); void set_http_transaction_factory( @@ -78,7 +76,6 @@ class URLRequestContextStorage { scoped_refptr<SSLConfigService> ssl_config_service_; scoped_ptr<NetworkDelegate> network_delegate_; scoped_refptr<CookieStore> cookie_store_; - scoped_ptr<CookiePolicy> cookie_policy_; scoped_refptr<TransportSecurityState> transport_security_state_; scoped_ptr<HttpTransactionFactory> http_transaction_factory_; diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index e6b07e8c..55f6028 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -437,7 +437,23 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() { allow = false; } - OnCanGetCookiesCompleted(allow); + if (request_->context()->cookie_store() && allow) { + CookieOptions options; + options.set_include_httponly(); + std::string cookies = + request_->context()->cookie_store()->GetCookiesWithOptions( + request_->url(), options); + if (!cookies.empty()) { + request_info_.extra_headers.SetHeader( + HttpRequestHeaders::kCookie, cookies); + } + } + // We may have been canceled within CanGetCookies. + if (GetStatus().is_success()) { + StartTransaction(); + } else { + NotifyCanceled(); + } } void URLRequestHttpJob::SaveCookiesAndNotifyHeadersComplete() { @@ -484,7 +500,13 @@ void URLRequestHttpJob::SaveNextCookie() { } } - OnCanSetCookieCompleted(); + response_cookies_save_index_++; + // We may have been canceled within OnSetCookie. + if (GetStatus().is_success()) { + SaveNextCookie(); + } else { + NotifyCanceled(); + } } void URLRequestHttpJob::FetchResponseCookies( @@ -588,36 +610,6 @@ void URLRequestHttpJob::ProcessStrictTransportSecurityHeader() { } } -void URLRequestHttpJob::OnCanGetCookiesCompleted(bool allow) { - if (request_->context()->cookie_store() && allow) { - CookieOptions options; - options.set_include_httponly(); - std::string cookies = - request_->context()->cookie_store()->GetCookiesWithOptions( - request_->url(), options); - if (!cookies.empty()) { - request_info_.extra_headers.SetHeader( - HttpRequestHeaders::kCookie, cookies); - } - } - // We may have been canceled within CanGetCookies. - if (GetStatus().is_success()) { - StartTransaction(); - } else { - NotifyCanceled(); - } -} - -void URLRequestHttpJob::OnCanSetCookieCompleted() { - response_cookies_save_index_++; - // We may have been canceled within OnSetCookie. - if (GetStatus().is_success()) { - SaveNextCookie(); - } else { - NotifyCanceled(); - } -} - void URLRequestHttpJob::OnStartCompleted(int result) { RecordTimer(); diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h index 960db8e..9620457 100644 --- a/net/url_request/url_request_http_job.h +++ b/net/url_request/url_request_http_job.h @@ -53,8 +53,6 @@ class URLRequestHttpJob : public URLRequestJob { // Process the Strict-Transport-Security header, if one exists. void ProcessStrictTransportSecurityHeader(); - void OnCanGetCookiesCompleted(bool allow); - void OnCanSetCookieCompleted(); void OnStartCompleted(int result); void OnReadCompleted(int result); diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index ba6de05..31bea3b 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -23,7 +23,6 @@ #include "base/stringprintf.h" #include "base/utf_string_conversions.h" #include "net/base/cookie_monster.h" -#include "net/base/cookie_policy.h" #include "net/base/load_flags.h" #include "net/base/mock_host_resolver.h" #include "net/base/net_errors.h" diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc index d0d3910..95060c6 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -11,7 +11,6 @@ #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" #include "net/base/net_log.h" -#include "net/base/cookie_policy.h" #include "net/base/cookie_store.h" #include "net/base/io_buffer.h" #include "net/http/http_util.h" @@ -279,22 +278,14 @@ bool WebSocketJob::SendHandshakeRequest(const char* data, int len) { } void WebSocketJob::AddCookieHeaderAndSend() { - int policy = OK; - if (socket_->context()->cookie_policy()) { - GURL url_for_cookies = GetURLForCookies(); - policy = socket_->context()->cookie_policy()->CanGetCookies( - url_for_cookies, - url_for_cookies); - } - DCHECK_NE(ERR_IO_PENDING, policy); - OnCanGetCookiesCompleted(policy); -} + bool allow = true; + if (delegate_ && !delegate_->CanGetCookies(socket_, GetURLForCookies())) + allow = false; -void WebSocketJob::OnCanGetCookiesCompleted(int policy) { if (socket_ && delegate_ && state_ == CONNECTING) { handshake_request_->RemoveHeaders( kCookieHeaders, arraysize(kCookieHeaders)); - if (policy == OK) { + if (allow) { // Add cookies, including HttpOnly cookies. if (socket_->context()->cookie_store()) { CookieOptions cookie_options; @@ -407,31 +398,18 @@ void WebSocketJob::SaveNextCookie() { return; } - int policy = OK; - if (socket_->context()->cookie_policy()) { - GURL url_for_cookies = GetURLForCookies(); - policy = socket_->context()->cookie_policy()->CanSetCookie( - url_for_cookies, - url_for_cookies, - response_cookies_[response_cookies_save_index_]); - } - - DCHECK_NE(ERR_IO_PENDING, policy); - OnCanSetCookieCompleted(policy); -} + bool allow = true; + CookieOptions options; + GURL url = GetURLForCookies(); + std::string cookie = response_cookies_[response_cookies_save_index_]; + if (delegate_ && !delegate_->CanSetCookie(socket_, url, cookie, &options)) + allow = false; -void WebSocketJob::OnCanSetCookieCompleted(int policy) { if (socket_ && delegate_ && state_ == CONNECTING) { - if ((policy == OK || policy == OK_FOR_SESSION_ONLY) && - socket_->context()->cookie_store()) { - CookieOptions options; + if (allow && socket_->context()->cookie_store()) { options.set_include_httponly(); - if (policy == OK_FOR_SESSION_ONLY) - options.set_force_session(); - GURL url_for_cookies = GetURLForCookies(); socket_->context()->cookie_store()->SetCookieWithOptions( - url_for_cookies, response_cookies_[response_cookies_save_index_], - options); + url, cookie, options); } response_cookies_save_index_++; SaveNextCookie(); diff --git a/net/websockets/websocket_job.h b/net/websockets/websocket_job.h index 1de1c1d..ae527ce 100644 --- a/net/websockets/websocket_job.h +++ b/net/websockets/websocket_job.h @@ -75,14 +75,12 @@ class WebSocketJob : public SocketStreamJob, public SocketStream::Delegate { bool SendHandshakeRequest(const char* data, int len); void AddCookieHeaderAndSend(); - void OnCanGetCookiesCompleted(int policy); void OnSentHandshakeRequest(SocketStream* socket, int amount_sent); void OnReceivedHandshakeResponse( SocketStream* socket, const char* data, int len); void SaveCookiesAndNotifyHeaderComplete(); void SaveNextCookie(); - void OnCanSetCookieCompleted(int policy); GURL GetURLForCookies() const; diff --git a/net/websockets/websocket_job_unittest.cc b/net/websockets/websocket_job_unittest.cc index 0a77bc3..e8f629a 100644 --- a/net/websockets/websocket_job_unittest.cc +++ b/net/websockets/websocket_job_unittest.cc @@ -9,7 +9,6 @@ #include "base/string_split.h" #include "base/string_util.h" #include "googleurl/src/gurl.h" -#include "net/base/cookie_policy.h" #include "net/base/cookie_store.h" #include "net/base/net_errors.h" #include "net/base/sys_addrinfo.h" @@ -54,7 +53,10 @@ class MockSocketStream : public SocketStream { class MockSocketStreamDelegate : public SocketStream::Delegate { public: MockSocketStreamDelegate() - : amount_sent_(0) {} + : amount_sent_(0), allow_all_cookies_(true) {} + void set_allow_all_cookies(bool allow_all_cookies) { + allow_all_cookies_ = allow_all_cookies; + } virtual ~MockSocketStreamDelegate() {} virtual void OnConnected(SocketStream* socket, int max_pending_send_allowed) { @@ -68,12 +70,22 @@ class MockSocketStreamDelegate : public SocketStream::Delegate { } virtual void OnClose(SocketStream* socket) { } + virtual bool CanGetCookies(SocketStream* socket, const GURL& url) { + return allow_all_cookies_; + } + virtual bool CanSetCookie(SocketStream* request, + const GURL& url, + const std::string& cookie_line, + CookieOptions* options) { + return allow_all_cookies_; + } size_t amount_sent() const { return amount_sent_; } const std::string& received_data() const { return received_data_; } private: int amount_sent_; + bool allow_all_cookies_; std::string received_data_; }; @@ -123,40 +135,10 @@ class MockCookieStore : public CookieStore { std::vector<Entry> entries_; }; -class MockCookiePolicy : public CookiePolicy { - public: - MockCookiePolicy() : allow_all_cookies_(true) {} - virtual ~MockCookiePolicy() {} - - void set_allow_all_cookies(bool allow_all_cookies) { - allow_all_cookies_ = allow_all_cookies; - } - - virtual int CanGetCookies(const GURL& url, - const GURL& first_party_for_cookies) const { - if (allow_all_cookies_) - return OK; - return ERR_ACCESS_DENIED; - } - - virtual int CanSetCookie(const GURL& url, - const GURL& first_party_for_cookies, - const std::string& cookie_line) const { - if (allow_all_cookies_) - return OK; - return ERR_ACCESS_DENIED; - } - - private: - bool allow_all_cookies_; -}; - class MockURLRequestContext : public URLRequestContext { public: - MockURLRequestContext(CookieStore* cookie_store, - CookiePolicy* cookie_policy) { + explicit MockURLRequestContext(CookieStore* cookie_store) { set_cookie_store(cookie_store); - set_cookie_policy(cookie_policy); transport_security_state_ = new TransportSecurityState(std::string()); set_transport_security_state(transport_security_state_.get()); TransportSecurityState::DomainState state; @@ -175,13 +157,10 @@ class WebSocketJobTest : public PlatformTest { public: virtual void SetUp() { cookie_store_ = new MockCookieStore; - cookie_policy_.reset(new MockCookiePolicy); - context_ = new MockURLRequestContext( - cookie_store_.get(), cookie_policy_.get()); + context_ = new MockURLRequestContext(cookie_store_.get()); } virtual void TearDown() { cookie_store_ = NULL; - cookie_policy_.reset(); context_ = NULL; websocket_ = NULL; socket_ = NULL; @@ -222,7 +201,6 @@ class WebSocketJobTest : public PlatformTest { } scoped_refptr<MockCookieStore> cookie_store_; - scoped_ptr<MockCookiePolicy> cookie_policy_; scoped_refptr<MockURLRequestContext> context_; scoped_refptr<WebSocketJob> websocket_; scoped_refptr<MockSocketStream> socket_; @@ -429,9 +407,9 @@ TEST_F(WebSocketJobTest, HandshakeWithCookieButNotAllowed) { cookie_options.set_include_httponly(); cookie_store_->SetCookieWithOptions( cookieUrl, "CR-test-httponly=1", cookie_options); - cookie_policy_->set_allow_all_cookies(false); MockSocketStreamDelegate delegate; + delegate.set_allow_all_cookies(false); InitWebSocketJob(url, &delegate); static const char* kHandshakeRequestMessage = |