diff options
author | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-01 02:37:13 +0000 |
---|---|---|
committer | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-01 02:37:13 +0000 |
commit | 6a2c3677f12c18bcc1b57c37becd4e1149f0c8e4 (patch) | |
tree | b0c0a2218130e3ceda8d983b768d0b693513a795 /net/socket_stream | |
parent | 260ce69aad6758077a585ebe5f5c040960e506a0 (diff) | |
download | chromium_src-6a2c3677f12c18bcc1b57c37becd4e1149f0c8e4.zip chromium_src-6a2c3677f12c18bcc1b57c37becd4e1149f0c8e4.tar.gz chromium_src-6a2c3677f12c18bcc1b57c37becd4e1149f0c8e4.tar.bz2 |
Support HttpOnly cookie on Web Socket
Web Socket should send "HttpOnly" cookie when handshaking.
In WebKit/WebCore, WebSocketHandshake uses cookieRequestHeaderFieldValue() to
get cookies including HttpOnly cookie. However, Chrome doesn't trunk renderer
process, so we're not allowed to access HttpOnly cookie in WebCore.
Thus, we handle HttpOnly cookies in browser process.
Add SocketStreamJob as interface for protocol specific handling on
SocketStream.
WebSocketJob implements Web Socket specific handling. For now, it handles
cookies in Web Socket. It checks Web Socket handshake request message
from renderer process, and replaces Cookie: header to include HttpOnly cookies.
It also checks Web Socket handshake response message, sets cookies if any,
and strips Set-Cookie: header, so that renderer process couldn't see
Set-Cookie: header.
BUG=35660
TEST=net_unittests and layout_tests passes
Review URL: http://codereview.chromium.org/601077
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40250 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket_stream')
-rw-r--r-- | net/socket_stream/socket_stream.cc | 4 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.h | 21 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_job.cc | 27 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_job.h | 87 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_job_manager.cc | 59 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_job_manager.h | 40 |
6 files changed, 227 insertions, 11 deletions
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 162e7f3..04c68b0 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -39,8 +39,8 @@ void SocketStream::ResponseHeaders::Realloc(size_t new_size) { } SocketStream::SocketStream(const GURL& url, Delegate* delegate) - : url_(url), - delegate_(delegate), + : delegate_(delegate), + url_(url), max_pending_send_allowed_(kMaxPendingSendAllowed), next_state_(STATE_NONE), http_auth_handler_factory_(NULL), diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 5b1ae3e..1334c15 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -101,6 +101,7 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { void SetUserData(const void* key, UserData* data); const GURL& url() const { return url_; } + bool is_secure() const; const AddressList& address_list() const { return addresses_; } Delegate* delegate() const { return delegate_; } int max_pending_send_allowed() const { return max_pending_send_allowed_; } @@ -112,28 +113,28 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { // Opens the connection on the IO thread. // Once the connection is established, calls delegate's OnConnected. - void Connect(); + virtual void Connect(); // Requests to send |len| bytes of |data| on the connection. // Returns true if |data| is buffered in the job. // Returns false if size of buffered data would exceeds // |max_pending_send_allowed_| and |data| is not sent at all. - bool SendData(const char* data, int len); + virtual bool SendData(const char* data, int len); // Requests to close the connection. // Once the connection is closed, calls delegate's OnClose. - void Close(); + virtual void Close(); // Restarts with authentication info. // Should be used for response of OnAuthRequired. - void RestartWithAuth( + virtual void RestartWithAuth( const std::wstring& username, const std::wstring& password); // Detach delegate. Call before delegate is deleted. // Once delegate is detached, close the socket stream and never call delegate // back. - void DetachDelegate(); + virtual void DetachDelegate(); // Sets an alternative HostResolver. For testing purposes only. void SetHostResolver(HostResolver* host_resolver); @@ -142,6 +143,12 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { // |factory|. For testing purposes only. void SetClientSocketFactory(ClientSocketFactory* factory); + protected: + friend class base::RefCountedThreadSafe<SocketStream>; + ~SocketStream(); + + Delegate* delegate_; + private: class RequestHeaders : public IOBuffer { public: @@ -201,8 +208,6 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { typedef std::deque< scoped_refptr<IOBufferWithSize> > PendingDataQueue; friend class RequestTracker<SocketStream>; - friend class base::RefCountedThreadSafe<SocketStream>; - ~SocketStream(); friend class WebSocketThrottleTest; @@ -248,7 +253,6 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { int HandleCertificateError(int result); - bool is_secure() const; SSLConfigService* ssl_config_service() const; ProxyService* proxy_service() const; @@ -258,7 +262,6 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { scoped_refptr<LoadLog> load_log_; GURL url_; - Delegate* delegate_; int max_pending_send_allowed_; scoped_refptr<URLRequestContext> context_; diff --git a/net/socket_stream/socket_stream_job.cc b/net/socket_stream/socket_stream_job.cc new file mode 100644 index 0000000..c8849a5 --- /dev/null +++ b/net/socket_stream/socket_stream_job.cc @@ -0,0 +1,27 @@ +// Copyright (c) 2010 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. + +#include "net/socket_stream/socket_stream_job.h" + +#include "net/socket_stream/socket_stream_job_manager.h" + +namespace net { + +static SocketStreamJobManager* GetJobManager() { + return Singleton<SocketStreamJobManager>::get(); +} + +// static +SocketStreamJob::ProtocolFactory* SocketStreamJob::RegisterProtocolFactory( + const std::string& scheme, ProtocolFactory* factory) { + return GetJobManager()->RegisterProtocolFactory(scheme, factory); +} + +// static +SocketStreamJob* SocketStreamJob::CreateSocketStreamJob( + const GURL& url, SocketStream::Delegate* delegate) { + return GetJobManager()->CreateJob(url, delegate); +} + +} // namespace net diff --git a/net/socket_stream/socket_stream_job.h b/net/socket_stream/socket_stream_job.h new file mode 100644 index 0000000..618620c --- /dev/null +++ b/net/socket_stream/socket_stream_job.h @@ -0,0 +1,87 @@ +// Copyright (c) 2010 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_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ +#define NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ + +#include <string> + +#include "base/ref_counted.h" +#include "net/socket_stream/socket_stream.h" + +class GURL; + +namespace net { + +// SocketStreamJob represents full-duplex communication over SocketStream. +// If a protocol (e.g. WebSocket protocol) needs to inspect/modify data +// over SocketStream, you can implement protocol specific job (e.g. +// WebSocketJob) to do some work on data over SocketStream. +// Registers the protocol specific SocketStreamJob by RegisterProtocolFactory +// and call CreateSocketStreamJob to create SocketStreamJob for the URL. +class SocketStreamJob : public base::RefCountedThreadSafe<SocketStreamJob> { + public: + // Callback function implemented by protocol handlers to create new jobs. + typedef SocketStreamJob* (ProtocolFactory)(const GURL& url, + SocketStream::Delegate* delegate); + + static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, + ProtocolFactory* factory); + + static SocketStreamJob* CreateSocketStreamJob( + const GURL& url, SocketStream::Delegate* delegate); + + SocketStreamJob() {} + void InitSocketStream(SocketStream* socket) { + socket_ = socket; + } + + virtual SocketStream::UserData *GetUserData(const void* key) const { + return socket_->GetUserData(key); + } + virtual void SetUserData(const void* key, SocketStream::UserData* data) { + socket_->SetUserData(key, data); + } + + URLRequestContext* context() const { + return socket_->context(); + } + void set_context(URLRequestContext* context) { + socket_->set_context(context); + } + + virtual void Connect() { + socket_->Connect(); + } + + virtual bool SendData(const char* data, int len) { + return socket_->SendData(data, len); + } + + virtual void Close() { + socket_->Close(); + } + + virtual void RestartWithAuth( + const std::wstring& username, + const std::wstring& password) { + socket_->RestartWithAuth(username, password); + } + + virtual void DetachDelegate() { + socket_->DetachDelegate(); + } + + protected: + friend class base::RefCountedThreadSafe<SocketStreamJob>; + virtual ~SocketStreamJob() {} + + scoped_refptr<SocketStream> socket_; + + DISALLOW_COPY_AND_ASSIGN(SocketStreamJob); +}; + +} // namespace net + +#endif // NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ diff --git a/net/socket_stream/socket_stream_job_manager.cc b/net/socket_stream/socket_stream_job_manager.cc new file mode 100644 index 0000000..7dd0d6b --- /dev/null +++ b/net/socket_stream/socket_stream_job_manager.cc @@ -0,0 +1,59 @@ +// Copyright (c) 2010 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. + +#include "net/socket_stream/socket_stream_job_manager.h" + +namespace net { + +SocketStreamJobManager::SocketStreamJobManager() { +} + +SocketStreamJobManager::~SocketStreamJobManager() { +} + +SocketStreamJob* SocketStreamJobManager::CreateJob( + const GURL& url, SocketStream::Delegate* delegate) const { + // If url is invalid, create plain SocketStreamJob, which will close + // the socket immediately. + if (!url.is_valid()) { + SocketStreamJob* job = new SocketStreamJob(); + job->InitSocketStream(new SocketStream(url, delegate)); + return job; + } + + const std::string& scheme = url.scheme(); // already lowercase + + AutoLock locked(lock_); + FactoryMap::const_iterator found = factories_.find(scheme); + if (found != factories_.end()) { + SocketStreamJob* job = found->second(url, delegate); + if (job) + return job; + } + SocketStreamJob* job = new SocketStreamJob(); + job->InitSocketStream(new SocketStream(url, delegate)); + return job; +} + +SocketStreamJob::ProtocolFactory* +SocketStreamJobManager::RegisterProtocolFactory( + const std::string& scheme, SocketStreamJob::ProtocolFactory* factory) { + AutoLock locked(lock_); + + SocketStreamJob::ProtocolFactory* old_factory; + FactoryMap::iterator found = factories_.find(scheme); + if (found != factories_.end()) { + old_factory = found->second; + } else { + old_factory = NULL; + } + if (factory) { + factories_[scheme] = factory; + } else if (found != factories_.end()) { + factories_.erase(found); + } + return old_factory; +} + +} // namespace net diff --git a/net/socket_stream/socket_stream_job_manager.h b/net/socket_stream/socket_stream_job_manager.h new file mode 100644 index 0000000..17ff833 --- /dev/null +++ b/net/socket_stream/socket_stream_job_manager.h @@ -0,0 +1,40 @@ +// Copyright (c) 2010 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_SOCKET_STREAM_SOCKET_STREAM_JOB_MANAGER_H_ +#define NET_SOCKET_STREAM_SOCKET_STREAM_JOB_MANAGER_H_ + +#include <map> +#include <string> + +#include "net/socket_stream/socket_stream.h" +#include "net/socket_stream/socket_stream_job.h" + +class GURL; + +namespace net { + +class SocketStreamJobManager { + public: + SocketStreamJobManager(); + ~SocketStreamJobManager(); + + SocketStreamJob* CreateJob( + const GURL& url, SocketStream::Delegate* delegate) const; + + SocketStreamJob::ProtocolFactory* RegisterProtocolFactory( + const std::string& scheme, SocketStreamJob::ProtocolFactory* factory); + + private: + typedef std::map<std::string, SocketStreamJob::ProtocolFactory*> FactoryMap; + + mutable Lock lock_; + FactoryMap factories_; + + DISALLOW_COPY_AND_ASSIGN(SocketStreamJobManager); +}; + +} // namespace net + +#endif // NET_SOCKET_STREAM_SOCKET_STREAM_JOB_MANAGER_H_ |