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/websockets | |
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/websockets')
-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 |
3 files changed, 29 insertions, 75 deletions
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 = |