diff options
45 files changed, 336 insertions, 204 deletions
diff --git a/chrome/browser/net/chrome_fraudulent_certificate_reporter.cc b/chrome/browser/net/chrome_fraudulent_certificate_reporter.cc index 505e54f..efea4b5 100644 --- a/chrome/browser/net/chrome_fraudulent_certificate_reporter.cc +++ b/chrome/browser/net/chrome_fraudulent_certificate_reporter.cc @@ -60,7 +60,7 @@ scoped_ptr<net::URLRequest> ChromeFraudulentCertificateReporter::CreateURLRequest( net::URLRequestContext* context) { scoped_ptr<net::URLRequest> request = - context->CreateRequest(upload_url_, net::DEFAULT_PRIORITY, this); + context->CreateRequest(upload_url_, net::DEFAULT_PRIORITY, this, NULL); request->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); return request.Pass(); diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc index eca301c..5672d45 100644 --- a/chrome/browser/net/connection_tester.cc +++ b/chrome/browser/net/connection_tester.cc @@ -412,7 +412,7 @@ void ConnectionTester::TestRunner::ProxyConfigServiceCreated( } // Fetch a request using the experimental context. request_ = request_context_->CreateRequest( - experiment.url, net::DEFAULT_PRIORITY, this); + experiment.url, net::DEFAULT_PRIORITY, this, NULL); request_->Start(); } diff --git a/chrome/browser/net/http_pipelining_compatibility_client.cc b/chrome/browser/net/http_pipelining_compatibility_client.cc index 407211b..3f2ee54 100644 --- a/chrome/browser/net/http_pipelining_compatibility_client.cc +++ b/chrome/browser/net/http_pipelining_compatibility_client.cc @@ -93,7 +93,8 @@ Request::Request(int request_id, url_request_(url_request_context->CreateRequest(GURL(base_url + info.filename), net::DEFAULT_PRIORITY, - this)), + this, + NULL)), info_(info), response_code_(0) { url_request_->SetLoadFlags(net::LOAD_BYPASS_CACHE | diff --git a/chrome/browser/plugins/plugin_installer.cc b/chrome/browser/plugins/plugin_installer.cc index 76b00e3..e9322a9 100644 --- a/chrome/browser/plugins/plugin_installer.cc +++ b/chrome/browser/plugins/plugin_installer.cc @@ -47,7 +47,7 @@ void BeginDownload( ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get(); scoped_ptr<net::URLRequest> request( resource_context->GetRequestContext()->CreateRequest( - url, net::DEFAULT_PRIORITY, NULL)); + url, net::DEFAULT_PRIORITY, NULL, NULL)); content::DownloadInterruptReason error = rdh->BeginDownload( request.Pass(), content::Referrer(), diff --git a/chrome/browser/ssl/ssl_client_certificate_selector_test.cc b/chrome/browser/ssl/ssl_client_certificate_selector_test.cc index f0a0918..d0318c6 100644 --- a/chrome/browser/ssl/ssl_client_certificate_selector_test.cc +++ b/chrome/browser/ssl/ssl_client_certificate_selector_test.cc @@ -98,6 +98,6 @@ SSLClientCertificateSelectorTestBase::MakeURLRequest( net::URLRequestContextGetter* context_getter) { scoped_ptr<net::URLRequest> request = context_getter->GetURLRequestContext()->CreateRequest( - GURL("https://example"), net::DEFAULT_PRIORITY, NULL); + GURL("https://example"), net::DEFAULT_PRIORITY, NULL, NULL); return request.Pass(); } diff --git a/chrome/browser/ui/views/ssl_client_certificate_selector_browsertest.cc b/chrome/browser/ui/views/ssl_client_certificate_selector_browsertest.cc index 3c61796..c677b8b 100644 --- a/chrome/browser/ui/views/ssl_client_certificate_selector_browsertest.cc +++ b/chrome/browser/ui/views/ssl_client_certificate_selector_browsertest.cc @@ -113,7 +113,7 @@ class SSLClientCertificateSelectorTest : public InProcessBrowserTest { scoped_ptr<net::URLRequest> MakeURLRequest( net::URLRequestContextGetter* context_getter) { return context_getter->GetURLRequestContext()->CreateRequest( - GURL("https://example"), net::DEFAULT_PRIORITY, NULL); + GURL("https://example"), net::DEFAULT_PRIORITY, NULL, NULL); } base::WaitableEvent io_loop_finished_event_; diff --git a/content/browser/download/download_manager_impl.cc b/content/browser/download/download_manager_impl.cc index b3a461f..1705678 100644 --- a/content/browser/download/download_manager_impl.cc +++ b/content/browser/download/download_manager_impl.cc @@ -56,7 +56,7 @@ void BeginDownload(scoped_ptr<DownloadUrlParameters> params, // we must down cast. RDHI is the only subclass of RDH as of 2012 May 4. scoped_ptr<net::URLRequest> request( params->resource_context()->GetRequestContext()->CreateRequest( - params->url(), net::DEFAULT_PRIORITY, NULL)); + params->url(), net::DEFAULT_PRIORITY, NULL, NULL)); request->SetLoadFlags(request->load_flags() | params->load_flags()); request->set_method(params->method()); if (!params->post_body().empty()) { diff --git a/content/browser/fileapi/blob_url_request_job_unittest.cc b/content/browser/fileapi/blob_url_request_job_unittest.cc index 29c0e8f..dd1ad1a 100644 --- a/content/browser/fileapi/blob_url_request_job_unittest.cc +++ b/content/browser/fileapi/blob_url_request_job_unittest.cc @@ -248,7 +248,7 @@ class BlobURLRequestJobTest : public testing::Test { void TestRequest(const std::string& method, const net::HttpRequestHeaders& extra_headers) { request_ = url_request_context_.CreateRequest( - GURL("blob:blah"), net::DEFAULT_PRIORITY, &url_request_delegate_); + GURL("blob:blah"), net::DEFAULT_PRIORITY, &url_request_delegate_, NULL); request_->set_method(method); if (!extra_headers.IsEmpty()) request_->SetExtraRequestHeaders(extra_headers); diff --git a/content/browser/fileapi/file_system_dir_url_request_job_unittest.cc b/content/browser/fileapi/file_system_dir_url_request_job_unittest.cc index 46b4bb1..e17157f 100644 --- a/content/browser/fileapi/file_system_dir_url_request_job_unittest.cc +++ b/content/browser/fileapi/file_system_dir_url_request_job_unittest.cc @@ -88,7 +88,7 @@ class FileSystemDirURLRequestJobTest : public testing::Test { delegate_.reset(new net::TestDelegate()); delegate_->set_quit_on_redirect(true); request_ = empty_context_.CreateRequest( - url, net::DEFAULT_PRIORITY, delegate_.get()); + url, net::DEFAULT_PRIORITY, delegate_.get(), NULL); job_ = new fileapi::FileSystemDirURLRequestJob( request_.get(), NULL, file_system_context); diff --git a/content/browser/fileapi/file_system_url_request_job_unittest.cc b/content/browser/fileapi/file_system_url_request_job_unittest.cc index 7fe55f6..2ddaef6 100644 --- a/content/browser/fileapi/file_system_url_request_job_unittest.cc +++ b/content/browser/fileapi/file_system_url_request_job_unittest.cc @@ -105,7 +105,7 @@ class FileSystemURLRequestJobTest : public testing::Test { delegate_->set_quit_on_complete(true); delegate_->set_quit_on_redirect(true); request_ = empty_context_.CreateRequest( - url, net::DEFAULT_PRIORITY, delegate_.get()); + url, net::DEFAULT_PRIORITY, delegate_.get(), NULL); if (headers) request_->SetExtraRequestHeaders(*headers); ASSERT_TRUE(!job_); diff --git a/content/browser/fileapi/file_writer_delegate_unittest.cc b/content/browser/fileapi/file_writer_delegate_unittest.cc index 88700d2..9f1e22d 100644 --- a/content/browser/fileapi/file_writer_delegate_unittest.cc +++ b/content/browser/fileapi/file_writer_delegate_unittest.cc @@ -137,7 +137,7 @@ class FileWriterDelegateTest : public PlatformTest { file_writer_delegate_.reset( CreateWriterDelegate(test_file_path, offset, allowed_growth)); request_ = empty_context_.CreateRequest( - blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get()); + blob_url, net::DEFAULT_PRIORITY, file_writer_delegate_.get(), NULL); } static net::URLRequest::ProtocolFactory Factory; @@ -334,7 +334,7 @@ TEST_F(FileWriterDelegateTest, WriteSuccessWithoutQuotaLimitConcurrent) { // Credate another FileWriterDelegate for concurrent write. file_writer_delegate2.reset(CreateWriterDelegate("test2", 0, kint64max)); request2 = empty_context_.CreateRequest( - kBlobURL2, net::DEFAULT_PRIORITY, file_writer_delegate2.get()); + kBlobURL2, net::DEFAULT_PRIORITY, file_writer_delegate2.get(), NULL); Result result, result2; ASSERT_EQ(0, usage()); diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc index 94899d5..0058a24 100644 --- a/content/browser/loader/resource_dispatcher_host_impl.cc +++ b/content/browser/loader/resource_dispatcher_host_impl.cc @@ -1056,9 +1056,12 @@ void ResourceDispatcherHostImpl::BeginRequest( } // Construct the request. + net::CookieStore* cookie_store = + GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( + child_id); scoped_ptr<net::URLRequest> new_request; new_request = request_context->CreateRequest( - request_data.url, request_data.priority, NULL); + request_data.url, request_data.priority, NULL, cookie_store); new_request->set_method(request_data.method); new_request->set_first_party_for_cookies( @@ -1359,8 +1362,13 @@ void ResourceDispatcherHostImpl::BeginSaveFile( return; } + net::CookieStore* cookie_store = + GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( + child_id); scoped_ptr<net::URLRequest> request( - request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL)); + request_context->CreateRequest(url, net::DEFAULT_PRIORITY, NULL, + cookie_store)); + request->set_method("GET"); SetReferrerForRequest(request.get(), referrer); diff --git a/content/browser/loader/resource_scheduler_unittest.cc b/content/browser/loader/resource_scheduler_unittest.cc index d248b4a..2408e3a 100644 --- a/content/browser/loader/resource_scheduler_unittest.cc +++ b/content/browser/loader/resource_scheduler_unittest.cc @@ -139,7 +139,7 @@ class ResourceSchedulerTest : public testing::Test { net::RequestPriority priority, int route_id) { scoped_ptr<net::URLRequest> url_request( - context_.CreateRequest(GURL(url), priority, NULL)); + context_.CreateRequest(GURL(url), priority, NULL, NULL)); ResourceRequestInfoImpl* info = new ResourceRequestInfoImpl( PROCESS_TYPE_RENDERER, // process_type kChildId, // child_id diff --git a/content/browser/renderer_host/render_message_filter.cc b/content/browser/renderer_host/render_message_filter.cc index 16a305d..0aa002b 100644 --- a/content/browser/renderer_host/render_message_filter.cc +++ b/content/browser/renderer_host/render_message_filter.cc @@ -583,9 +583,9 @@ void RenderMessageFilter::OnSetCookie(int render_frame_id, if (GetContentClient()->browser()->AllowSetCookie( url, first_party_for_cookies, cookie, resource_context_, render_process_id_, render_frame_id, &options)) { - net::URLRequestContext* context = GetRequestContextForURL(url); + net::CookieStore* cookie_store = GetCookieStoreForURL(url); // Pass a null callback since we don't care about when the 'set' completes. - context->cookie_store()->SetCookieWithOptionsAsync( + cookie_store->SetCookieWithOptionsAsync( url, cookie, options, net::CookieMonster::SetCookiesCallback()); } } @@ -607,9 +607,8 @@ void RenderMessageFilter::OnGetCookies(int render_frame_id, base::strlcpy(url_buf, url.spec().c_str(), arraysize(url_buf)); base::debug::Alias(url_buf); - net::URLRequestContext* context = GetRequestContextForURL(url); - net::CookieMonster* cookie_monster = - context->cookie_store()->GetCookieMonster(); + net::CookieStore* cookie_store = GetCookieStoreForURL(url); + net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); cookie_monster->GetAllCookiesForURLAsync( url, base::Bind(&RenderMessageFilter::CheckPolicyForCookies, this, render_frame_id, url, first_party_for_cookies, @@ -635,9 +634,8 @@ void RenderMessageFilter::OnGetRawCookies( // We check policy here to avoid sending back cookies that would not normally // be applied to outbound requests for the given URL. Since this cookie info // is visible in the developer tools, it is helpful to make it match reality. - net::URLRequestContext* context = GetRequestContextForURL(url); - net::CookieMonster* cookie_monster = - context->cookie_store()->GetCookieMonster(); + net::CookieStore* cookie_store = GetCookieStoreForURL(url); + net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); cookie_monster->GetAllCookiesForURLAsync( url, base::Bind(&RenderMessageFilter::SendGetRawCookiesResponse, this, reply_msg)); @@ -650,8 +648,8 @@ void RenderMessageFilter::OnDeleteCookie(const GURL& url, if (!policy->CanAccessCookiesForOrigin(render_process_id_, url)) return; - net::URLRequestContext* context = GetRequestContextForURL(url); - context->cookie_store()->DeleteCookieAsync(url, cookie_name, base::Closure()); + net::CookieStore* cookie_store = GetCookieStoreForURL(url); + cookie_store->DeleteCookieAsync(url, cookie_name, base::Closure()); } void RenderMessageFilter::OnCookiesEnabled( @@ -885,9 +883,17 @@ void RenderMessageFilter::OnDownloadUrl(const IPC::Message& message, const base::string16& suggested_name) { scoped_ptr<DownloadSaveInfo> save_info(new DownloadSaveInfo()); save_info->suggested_name = suggested_name; + + // There may be a special cookie store that we could use for this download, + // rather than the default one. Since this feature is generally only used for + // proper render views, and not downloads, we do not need to retrieve the + // special cookie store here, but just initialize the request to use the + // default cookie store. + // TODO(tburkard): retrieve the appropriate special cookie store, if this + // is ever to be used for downloads as well. scoped_ptr<net::URLRequest> request( resource_context_->GetRequestContext()->CreateRequest( - url, net::DEFAULT_PRIORITY, NULL)); + url, net::DEFAULT_PRIORITY, NULL, NULL)); RecordDownloadSource(INITIATED_BY_RENDERER); resource_dispatcher_host_->BeginDownload( request.Pass(), @@ -920,17 +926,30 @@ void RenderMessageFilter::OnAllocateSharedMemory( buffer_size, PeerHandle(), handle); } -net::URLRequestContext* RenderMessageFilter::GetRequestContextForURL( +net::CookieStore* RenderMessageFilter::GetCookieStoreForURL( const GURL& url) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); net::URLRequestContext* context = GetContentClient()->browser()->OverrideRequestContextForURL( url, resource_context_); - if (!context) - context = request_context_->GetURLRequestContext(); - return context; + // If we should use a special URLRequestContext rather than the default one, + // return the cookie store of that special URLRequestContext. + if (context) + return context->cookie_store(); + + // Otherwise, if there is a special cookie store to be used for this process, + // return that cookie store. + net::CookieStore* cookie_store = + GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( + render_process_id_); + if (cookie_store) + return cookie_store; + + // Otherwise, return the cookie store of the default request context used + // for this renderer. + return request_context_->GetURLRequestContext()->cookie_store(); } #if defined(OS_POSIX) && !defined(TOOLKIT_GTK) && !defined(OS_ANDROID) @@ -1053,14 +1072,14 @@ void RenderMessageFilter::CheckPolicyForCookies( const GURL& first_party_for_cookies, IPC::Message* reply_msg, const net::CookieList& cookie_list) { - net::URLRequestContext* context = GetRequestContextForURL(url); + net::CookieStore* cookie_store = GetCookieStoreForURL(url); // Check the policy for get cookies, and pass cookie_list to the // TabSpecificContentSetting for logging purpose. if (GetContentClient()->browser()->AllowGetCookie( url, first_party_for_cookies, cookie_list, resource_context_, render_process_id_, render_frame_id)) { // Gets the cookies from cookie store if allowed. - context->cookie_store()->GetCookiesWithOptionsAsync( + cookie_store->GetCookiesWithOptionsAsync( url, net::CookieOptions(), base::Bind(&RenderMessageFilter::SendGetCookiesResponse, this, reply_msg)); diff --git a/content/browser/renderer_host/render_message_filter.h b/content/browser/renderer_host/render_message_filter.h index d23d9b7..b87b962 100644 --- a/content/browser/renderer_host/render_message_filter.h +++ b/content/browser/renderer_host/render_message_filter.h @@ -62,6 +62,7 @@ struct MediaLogEvent; } namespace net { +class CookieStore; class KeygenHandler; class URLRequestContext; class URLRequestContextGetter; @@ -108,10 +109,10 @@ class RenderMessageFilter : public BrowserMessageFilter { int render_process_id() const { return render_process_id_; } - // Returns the correct net::URLRequestContext depending on what type of url is + // Returns the correct net::CookieStore depending on what type of url is // given. // Only call on the IO thread. - net::URLRequestContext* GetRequestContextForURL(const GURL& url); + net::CookieStore* GetCookieStoreForURL(const GURL& url); private: friend class BrowserThread; diff --git a/content/browser/renderer_host/socket_stream_dispatcher_host.cc b/content/browser/renderer_host/socket_stream_dispatcher_host.cc index 5c5e2b8a..ca622f1 100644 --- a/content/browser/renderer_host/socket_stream_dispatcher_host.cc +++ b/content/browser/renderer_host/socket_stream_dispatcher_host.cc @@ -224,7 +224,8 @@ void SocketStreamDispatcherHost::OnConnect(int render_frame_id, // Note that the SocketStreamHost is responsible for checking that |url| // is valid. SocketStreamHost* socket_stream_host = - new SocketStreamHost(this, render_frame_id, socket_id); + new SocketStreamHost(this, render_process_id_, render_frame_id, + socket_id); hosts_.AddWithID(socket_stream_host, socket_id); socket_stream_host->Connect(url, GetURLRequestContext()); DVLOG(2) << "SocketStreamDispatcherHost::OnConnect -> " << socket_id; diff --git a/content/browser/renderer_host/socket_stream_host.cc b/content/browser/renderer_host/socket_stream_host.cc index f09f2f3..364b8d0 100644 --- a/content/browser/renderer_host/socket_stream_host.cc +++ b/content/browser/renderer_host/socket_stream_host.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "content/common/socket_stream.h" +#include "content/public/browser/content_browser_client.h" #include "net/socket_stream/socket_stream_job.h" #include "net/url_request/url_request_context.h" @@ -28,9 +29,11 @@ class SocketStreamId : public net::SocketStream::UserData { SocketStreamHost::SocketStreamHost( net::SocketStream::Delegate* delegate, + int child_id, int render_frame_id, int socket_id) : delegate_(delegate), + child_id_(child_id), render_frame_id_(render_frame_id), socket_id_(socket_id) { DCHECK_NE(socket_id_, kNoSocketId); @@ -51,7 +54,7 @@ int SocketStreamHost::SocketIdFromSocketStream( SocketStreamHost::~SocketStreamHost() { VLOG(1) << "SocketStreamHost destructed socket_id=" << socket_id_; - job_->set_context(NULL); + job_->DetachContext(); job_->DetachDelegate(); } @@ -60,8 +63,10 @@ void SocketStreamHost::Connect(const GURL& url, VLOG(1) << "SocketStreamHost::Connect url=" << url; job_ = net::SocketStreamJob::CreateSocketStreamJob( url, delegate_, request_context->transport_security_state(), - request_context->ssl_config_service()); - job_->set_context(request_context); + request_context->ssl_config_service(), + request_context, + GetContentClient()->browser()->OverrideCookieStoreForRenderProcess( + child_id_)); job_->SetUserData(kSocketIdKey, new SocketStreamId(socket_id_)); job_->Connect(); } diff --git a/content/browser/renderer_host/socket_stream_host.h b/content/browser/renderer_host/socket_stream_host.h index eb9b719..da4716c 100644 --- a/content/browser/renderer_host/socket_stream_host.h +++ b/content/browser/renderer_host/socket_stream_host.h @@ -29,6 +29,7 @@ namespace content { class SocketStreamHost { public: SocketStreamHost(net::SocketStream::Delegate* delegate, + int child_id, int render_frame_id, int socket_id); ~SocketStreamHost(); @@ -66,6 +67,7 @@ class SocketStreamHost { private: net::SocketStream::Delegate* delegate_; + int child_id_; int render_frame_id_; int socket_id_; diff --git a/content/browser/streams/stream_url_request_job_unittest.cc b/content/browser/streams/stream_url_request_job_unittest.cc index 9caf684..035a588 100644 --- a/content/browser/streams/stream_url_request_job_unittest.cc +++ b/content/browser/streams/stream_url_request_job_unittest.cc @@ -76,7 +76,7 @@ class StreamURLRequestJobTest : public testing::Test { const std::string& expected_response) { net::TestDelegate delegate; request_ = url_request_context_.CreateRequest( - url, net::DEFAULT_PRIORITY, &delegate); + url, net::DEFAULT_PRIORITY, &delegate, NULL); request_->set_method(method); if (!extra_headers.IsEmpty()) request_->SetExtraRequestHeaders(extra_headers); @@ -134,7 +134,7 @@ TEST_F(StreamURLRequestJobTest, TestGetLargeStreamRequest) { TEST_F(StreamURLRequestJobTest, TestGetNonExistentStreamRequest) { net::TestDelegate delegate; request_ = url_request_context_.CreateRequest( - kStreamURL, net::DEFAULT_PRIORITY, &delegate); + kStreamURL, net::DEFAULT_PRIORITY, &delegate, NULL); request_->set_method("GET"); request_->Start(); diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc index 4d2c80b..169ca96 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -310,4 +310,9 @@ bool ContentBrowserClient::IsPluginAllowedToUseDevChannelAPIs() { return false; } +net::CookieStore* ContentBrowserClient::OverrideCookieStoreForRenderProcess( + int render_process_id) { + return NULL; +} + } // namespace content diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index 18c837b..e3e8250 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -50,6 +50,7 @@ class ImageSkia; namespace net { class CookieOptions; +class CookieStore; class HttpNetworkSession; class NetLog; class SSLCertRequestInfo; @@ -625,6 +626,12 @@ class CONTENT_EXPORT ContentBrowserClient { // Returns true if dev channel APIs are available for plugins. virtual bool IsPluginAllowedToUseDevChannelAPIs(); + + // Returns a special cookie store to use for a given render process, or NULL + // if the default cookie store should be used + // This is called on the IO thread. + virtual net::CookieStore* OverrideCookieStoreForRenderProcess( + int render_process_id_); }; } // namespace content diff --git a/net/proxy/proxy_script_fetcher_impl.cc b/net/proxy/proxy_script_fetcher_impl.cc index 705bbbf..0887d8c 100644 --- a/net/proxy/proxy_script_fetcher_impl.cc +++ b/net/proxy/proxy_script_fetcher_impl.cc @@ -135,7 +135,7 @@ int ProxyScriptFetcherImpl::Fetch( } cur_request_ = - url_request_context_->CreateRequest(url, DEFAULT_PRIORITY, this); + url_request_context_->CreateRequest(url, DEFAULT_PRIORITY, this, NULL); cur_request_->set_method("GET"); // Make sure that the PAC script is downloaded using a direct connection, diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 1682ddc..5aacd4a 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -87,11 +87,13 @@ void SocketStream::ResponseHeaders::Realloc(size_t new_size) { SocketStream::ResponseHeaders::~ResponseHeaders() { data_ = NULL; } -SocketStream::SocketStream(const GURL& url, Delegate* delegate) +SocketStream::SocketStream(const GURL& url, Delegate* delegate, + URLRequestContext* context, + CookieStore* cookie_store) : delegate_(delegate), url_(url), max_pending_send_allowed_(kMaxPendingSendAllowed), - context_(NULL), + context_(context), next_state_(STATE_NONE), factory_(ClientSocketFactory::GetDefaultFactory()), proxy_mode_(kDirectConnection), @@ -108,12 +110,24 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate) waiting_for_write_completion_(false), closing_(false), server_closed_(false), - metrics_(new SocketStreamMetrics(url)) { + metrics_(new SocketStreamMetrics(url)), + cookie_store_(cookie_store) { DCHECK(base::MessageLoop::current()) << "The current base::MessageLoop must exist"; DCHECK(base::MessageLoopForIO::IsCurrent()) << "The current base::MessageLoop must be TYPE_IO"; DCHECK(delegate_); + + if (context_) { + if (!cookie_store_) + cookie_store_ = context_->cookie_store(); + + net_log_ = BoundNetLog::Make( + context->net_log(), + NetLog::SOURCE_SOCKET_STREAM); + + net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); + } } SocketStream::UserData* SocketStream::GetUserData( @@ -132,28 +146,20 @@ bool SocketStream::is_secure() const { return url_.SchemeIs("wss"); } -void SocketStream::set_context(URLRequestContext* context) { - const URLRequestContext* prev_context = context_; - - context_ = context; - - if (prev_context != context) { - if (prev_context && pac_request_) { - prev_context->proxy_service()->CancelPacRequest(pac_request_); - pac_request_ = NULL; - } +void SocketStream::DetachContext() { + if (!context_) + return; - net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE); - net_log_ = BoundNetLog(); + if (pac_request_) { + context_->proxy_service()->CancelPacRequest(pac_request_); + pac_request_ = NULL; + } - if (context) { - net_log_ = BoundNetLog::Make( - context->net_log(), - NetLog::SOURCE_SOCKET_STREAM); + net_log_.EndEvent(NetLog::TYPE_REQUEST_ALIVE); + net_log_ = BoundNetLog(); - net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); - } - } + context_ = NULL; + cookie_store_ = NULL; } void SocketStream::CheckPrivacyMode() { @@ -318,7 +324,7 @@ void SocketStream::ContinueDespiteError() { } SocketStream::~SocketStream() { - set_context(NULL); + DetachContext(); DCHECK(!delegate_); DCHECK(!pac_request_); } @@ -1342,4 +1348,8 @@ int SocketStream::HandleCertificateError(int result) { return ERR_IO_PENDING; } +CookieStore* SocketStream::cookie_store() const { + return cookie_store_; +} + } // namespace net diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index b86f20a..cfc764d 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -19,6 +19,7 @@ #include "net/base/net_export.h" #include "net/base/net_log.h" #include "net/base/privacy_mode.h" +#include "net/cookies/cookie_store.h" #include "net/proxy/proxy_service.h" #include "net/ssl/ssl_config_service.h" #include "net/url_request/url_request.h" @@ -114,7 +115,8 @@ class NET_EXPORT SocketStream virtual ~Delegate() {} }; - SocketStream(const GURL& url, Delegate* delegate); + SocketStream(const GURL& url, Delegate* delegate, URLRequestContext* context, + CookieStore* cookie_store); // The user data allows the clients to associate data with this job. // Multiple user data values can be stored under different keys. @@ -130,9 +132,6 @@ class NET_EXPORT SocketStream int max_pending_send_allowed() const { return max_pending_send_allowed_; } URLRequestContext* context() { return context_; } - // There're some asynchronous operations and members that are constructed from - // |context|. Be careful when you use this for the second time or more. - void set_context(URLRequestContext* context); const SSLConfig& server_ssl_config() const { return server_ssl_config_; } PrivacyMode privacy_mode() const { return privacy_mode_; } @@ -162,6 +161,9 @@ class NET_EXPORT SocketStream // back. virtual void DetachDelegate(); + // Detach the context. + virtual void DetachContext(); + const ProxyServer& proxy_server() const; // Sets an alternative ClientSocketFactory. Doesn't take ownership of @@ -180,6 +182,8 @@ class NET_EXPORT SocketStream // actions on alert dialog or browser cached such kinds of user actions. void ContinueDespiteError(); + CookieStore* cookie_store() const; + protected: friend class base::RefCountedThreadSafe<SocketStream>; virtual ~SocketStream(); @@ -389,6 +393,9 @@ class NET_EXPORT SocketStream scoped_ptr<SocketStreamMetrics> metrics_; + // Cookie store to use for this socket stream. + scoped_refptr<CookieStore> cookie_store_; + DISALLOW_COPY_AND_ASSIGN(SocketStream); }; diff --git a/net/socket_stream/socket_stream_job.cc b/net/socket_stream/socket_stream_job.cc index 9c13a8f..f2de823 100644 --- a/net/socket_stream/socket_stream_job.cc +++ b/net/socket_stream/socket_stream_job.cc @@ -24,7 +24,9 @@ SocketStreamJob* SocketStreamJob::CreateSocketStreamJob( const GURL& url, SocketStream::Delegate* delegate, TransportSecurityState* sts, - SSLConfigService* ssl) { + SSLConfigService* ssl, + URLRequestContext* context, + CookieStore* cookie_store) { GURL socket_url(url); TransportSecurityState::DomainState domain_state; if (url.scheme() == "ws" && sts && sts->GetDomainState( @@ -36,7 +38,8 @@ SocketStreamJob* SocketStreamJob::CreateSocketStreamJob( url_parse::Component(0, strlen(kNewScheme))); socket_url = url.ReplaceComponents(replacements); } - return SocketStreamJobManager::GetInstance()->CreateJob(socket_url, delegate); + return SocketStreamJobManager::GetInstance()->CreateJob( + socket_url, delegate, context, cookie_store); } SocketStreamJob::SocketStreamJob() {} @@ -82,6 +85,11 @@ void SocketStreamJob::DetachDelegate() { socket_->DetachDelegate(); } +void SocketStreamJob::DetachContext() { + if (socket_.get()) + socket_->DetachContext(); +} + SocketStreamJob::~SocketStreamJob() {} } // namespace net diff --git a/net/socket_stream/socket_stream_job.h b/net/socket_stream/socket_stream_job.h index d12e73a..9fc27d9 100644 --- a/net/socket_stream/socket_stream_job.h +++ b/net/socket_stream/socket_stream_job.h @@ -15,6 +15,7 @@ class GURL; namespace net { +class CookieStore; class SSLConfigService; class SSLInfo; class TransportSecurityState; @@ -30,7 +31,9 @@ class NET_EXPORT SocketStreamJob public: // Callback function implemented by protocol handlers to create new jobs. typedef SocketStreamJob* (ProtocolFactory)(const GURL& url, - SocketStream::Delegate* delegate); + SocketStream::Delegate* delegate, + URLRequestContext* context, + CookieStore* cookie_store); static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, ProtocolFactory* factory); @@ -39,7 +42,9 @@ class NET_EXPORT SocketStreamJob const GURL& url, SocketStream::Delegate* delegate, TransportSecurityState* sts, - SSLConfigService* ssl); + SSLConfigService* ssl, + URLRequestContext* context, + CookieStore* cookie_store); SocketStreamJob(); void InitSocketStream(SocketStream* socket) { @@ -52,9 +57,8 @@ class NET_EXPORT SocketStreamJob URLRequestContext* context() const { return socket_.get() ? socket_->context() : 0; } - void set_context(URLRequestContext* context) { - if (socket_.get()) - socket_->set_context(context); + CookieStore* cookie_store() const { + return socket_.get() ? socket_->cookie_store() : 0; } virtual void Connect(); @@ -73,6 +77,8 @@ class NET_EXPORT SocketStreamJob virtual void DetachDelegate(); + virtual void DetachContext(); + protected: friend class WebSocketJobTest; friend class base::RefCountedThreadSafe<SocketStreamJob>; diff --git a/net/socket_stream/socket_stream_job_manager.cc b/net/socket_stream/socket_stream_job_manager.cc index 7f66a4a..6418be4 100644 --- a/net/socket_stream/socket_stream_job_manager.cc +++ b/net/socket_stream/socket_stream_job_manager.cc @@ -20,12 +20,14 @@ SocketStreamJobManager* SocketStreamJobManager::GetInstance() { } SocketStreamJob* SocketStreamJobManager::CreateJob( - const GURL& url, SocketStream::Delegate* delegate) const { + const GURL& url, SocketStream::Delegate* delegate, + URLRequestContext* context, CookieStore* cookie_store) 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)); + job->InitSocketStream(new SocketStream(url, delegate, context, + cookie_store)); return job; } @@ -34,12 +36,12 @@ SocketStreamJob* SocketStreamJobManager::CreateJob( base::AutoLock locked(lock_); FactoryMap::const_iterator found = factories_.find(scheme); if (found != factories_.end()) { - SocketStreamJob* job = found->second(url, delegate); + SocketStreamJob* job = found->second(url, delegate, context, cookie_store); if (job) return job; } SocketStreamJob* job = new SocketStreamJob(); - job->InitSocketStream(new SocketStream(url, delegate)); + job->InitSocketStream(new SocketStream(url, delegate, context, cookie_store)); return job; } diff --git a/net/socket_stream/socket_stream_job_manager.h b/net/socket_stream/socket_stream_job_manager.h index aa0cd40..2363fb5 100644 --- a/net/socket_stream/socket_stream_job_manager.h +++ b/net/socket_stream/socket_stream_job_manager.h @@ -22,7 +22,8 @@ class SocketStreamJobManager { static SocketStreamJobManager* GetInstance(); SocketStreamJob* CreateJob( - const GURL& url, SocketStream::Delegate* delegate) const; + const GURL& url, SocketStream::Delegate* delegate, + URLRequestContext* context, CookieStore* cookie_store) const; SocketStreamJob::ProtocolFactory* RegisterProtocolFactory( const std::string& scheme, SocketStreamJob::ProtocolFactory* factory); diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index 4a6a9e2..069f92e 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -318,7 +318,7 @@ class SocketStreamTest : public PlatformTest { virtual void DoCloseFlushPendingWriteTestWithSetContextNull( SocketStreamEvent* event) { - event->socket->set_context(NULL); + event->socket->DetachContext(); // handshake response received. for (size_t i = 0; i < messages_.size(); i++) { std::vector<char> frame; @@ -400,9 +400,8 @@ TEST_F(SocketStreamTest, CloseFlushPendingWrite) { TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - - socket_stream->set_context(&context); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); MockWrite data_writes[] = { MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), @@ -453,16 +452,16 @@ TEST_F(SocketStreamTest, ResolveFailure) { scoped_ptr<SocketStreamEventRecorder> delegate( new SocketStreamEventRecorder(test_callback.callback())); - scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - // Make resolver fail. TestURLRequestContext context; scoped_ptr<MockHostResolver> mock_host_resolver( new MockHostResolver()); mock_host_resolver->rules()->AddSimulatedFailure("example.com"); context.set_host_resolver(mock_host_resolver.get()); - socket_stream->set_context(&context); + + scoped_refptr<SocketStream> socket_stream( + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); // No read/write on socket is expected. StaticSocketDataProvider data_provider(NULL, 0, NULL, 0); @@ -493,9 +492,8 @@ TEST_F(SocketStreamTest, ExceedMaxPendingSendAllowed) { TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - - socket_stream->set_context(&context); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); DelayedSocketData data_provider(1, NULL, 0, NULL, 0); @@ -566,12 +564,12 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { &SocketStreamEventRecorder::DoRestartWithAuth, base::Unretained(delegate.get()))); - scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - TestURLRequestContextWithProxy context("myproxy:70"); - socket_stream->set_context(&context); + scoped_refptr<SocketStream> socket_stream( + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); + socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); @@ -618,9 +616,6 @@ TEST_F(SocketStreamTest, BasicAuthProxyWithAuthCache) { delegate->SetOnConnected(base::Bind(&SocketStreamEventRecorder::DoClose, base::Unretained(delegate.get()))); - scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - TestURLRequestContextWithProxy context("myproxy:70"); HttpAuthCache* auth_cache = context.http_transaction_factory()->GetSession()->http_auth_cache(); @@ -632,7 +627,10 @@ TEST_F(SocketStreamTest, BasicAuthProxyWithAuthCache) { ASCIIToUTF16("bar")), "/"); - socket_stream->set_context(&context); + scoped_refptr<SocketStream> socket_stream( + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); + socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); @@ -675,9 +673,6 @@ TEST_F(SocketStreamTest, WSSBasicAuthProxyWithAuthCache) { delegate->SetOnConnected(base::Bind(&SocketStreamEventRecorder::DoClose, base::Unretained(delegate.get()))); - scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("wss://example.com/demo"), delegate.get())); - TestURLRequestContextWithProxy context("myproxy:70"); HttpAuthCache* auth_cache = context.http_transaction_factory()->GetSession()->http_auth_cache(); @@ -689,7 +684,10 @@ TEST_F(SocketStreamTest, WSSBasicAuthProxyWithAuthCache) { ASCIIToUTF16("bar")), "/"); - socket_stream->set_context(&context); + scoped_refptr<SocketStream> socket_stream( + new SocketStream(GURL("wss://example.com/demo"), delegate.get(), + &context, NULL)); + socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); @@ -721,9 +719,8 @@ TEST_F(SocketStreamTest, IOPending) { TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - - socket_stream->set_context(&context); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); MockWrite data_writes[] = { MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), @@ -783,9 +780,8 @@ TEST_F(SocketStreamTest, SwitchToSpdy) { TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - - socket_stream->set_context(&context); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); socket_stream->Connect(); @@ -811,9 +807,8 @@ TEST_F(SocketStreamTest, SwitchAfterPending) { TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - - socket_stream->set_context(&context); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); socket_stream->Connect(); io_test_callback_.WaitForResult(); @@ -865,9 +860,9 @@ TEST_F(SocketStreamTest, SecureProxyConnectError) { base::Unretained(delegate.get()))); scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); - socket_stream->set_context(&context); socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); @@ -916,9 +911,9 @@ TEST_F(SocketStreamTest, SecureProxyConnect) { base::Unretained(delegate.get()))); scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); - socket_stream->set_context(&context); socket_stream->SetClientSocketFactory(&mock_socket_factory); socket_stream->Connect(); @@ -948,9 +943,8 @@ TEST_F(SocketStreamTest, BeforeConnectFailed) { context.set_network_delegate(&network_delegate); scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); - - socket_stream->set_context(&context); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); socket_stream->Connect(); @@ -981,8 +975,8 @@ TEST_F(SocketStreamTest, OnErrorDetachDelegate) { TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://localhost:9998/echo"), delegate)); - socket_stream->set_context(&context); + new SocketStream(GURL("ws://localhost:9998/echo"), delegate, + &context, NULL)); socket_stream->SetClientSocketFactory(&mock_socket_factory); delegate->set_socket_stream(socket_stream); // The delegate pointer will become invalid during the test. Set it to NULL to @@ -1001,7 +995,8 @@ TEST_F(SocketStreamTest, NullContextSocketStreamShouldNotCrash) { new SocketStreamEventRecorder(test_callback.callback())); TestURLRequestContext context; scoped_refptr<SocketStream> socket_stream( - new SocketStream(GURL("ws://example.com/demo"), delegate.get())); + new SocketStream(GURL("ws://example.com/demo"), delegate.get(), + &context, NULL)); delegate->SetOnStartOpenConnection(base::Bind( &SocketStreamTest::DoIOPending, base::Unretained(this))); delegate->SetOnConnected(base::Bind( @@ -1010,8 +1005,6 @@ TEST_F(SocketStreamTest, NullContextSocketStreamShouldNotCrash) { &SocketStreamTest::DoCloseFlushPendingWriteTestWithSetContextNull, base::Unretained(this))); - socket_stream->set_context(&context); - MockWrite data_writes[] = { MockWrite(SocketStreamTest::kWebSocketHandshakeRequest), }; diff --git a/net/url_request/url_fetcher_core.cc b/net/url_request/url_fetcher_core.cc index eea2e81..eb45ecf 100644 --- a/net/url_request/url_fetcher_core.cc +++ b/net/url_request/url_fetcher_core.cc @@ -507,7 +507,7 @@ void URLFetcherCore::StartURLRequest() { g_registry.Get().AddURLFetcherCore(this); current_response_bytes_ = 0; request_ = request_context_getter_->GetURLRequestContext()->CreateRequest( - original_url_, DEFAULT_PRIORITY, this); + original_url_, DEFAULT_PRIORITY, this, NULL); request_->set_stack_trace(stack_trace_); int flags = request_->load_flags() | load_flags_; if (!g_interception_enabled) diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 531e8e8..e2be4c2 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -209,38 +209,17 @@ URLRequest::URLRequest(const GURL& url, RequestPriority priority, Delegate* delegate, const URLRequestContext* context) - : context_(context), - network_delegate_(context->network_delegate()), - net_log_(BoundNetLog::Make(context->net_log(), - NetLog::SOURCE_URL_REQUEST)), - url_chain_(1, url), - method_("GET"), - referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), - load_flags_(LOAD_NORMAL), - delegate_(delegate), - is_pending_(false), - is_redirecting_(false), - redirect_limit_(kMaxRedirects), - priority_(priority), - identifier_(GenerateURLRequestIdentifier()), - calling_delegate_(false), - use_blocked_by_as_load_param_(false), - before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, - base::Unretained(this))), - has_notified_completion_(false), - received_response_content_length_(0), - creation_time_(base::TimeTicks::Now()), - notified_before_network_start_(false) { - SIMPLE_STATS_COUNTER("URLRequestCount"); - - // Sanity check out environment. - DCHECK(base::MessageLoop::current()) - << "The current base::MessageLoop must exist"; - - CHECK(context); - context->url_requests()->insert(this); + : identifier_(GenerateURLRequestIdentifier()) { + Init(url, priority, delegate, context, NULL); +} - net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); +URLRequest::URLRequest(const GURL& url, + RequestPriority priority, + Delegate* delegate, + const URLRequestContext* context, + CookieStore* cookie_store) + : identifier_(GenerateURLRequestIdentifier()) { + Init(url, priority, delegate, context, cookie_store); } URLRequest::~URLRequest() { @@ -284,6 +263,47 @@ void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { interceptor); } +void URLRequest::Init(const GURL& url, + RequestPriority priority, + Delegate* delegate, + const URLRequestContext* context, + CookieStore* cookie_store) { + context_ = context; + network_delegate_ = context->network_delegate(); + net_log_ = BoundNetLog::Make(context->net_log(), NetLog::SOURCE_URL_REQUEST); + url_chain_.push_back(url); + method_ = "GET"; + referrer_policy_ = CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE; + load_flags_ = LOAD_NORMAL; + delegate_ = delegate; + is_pending_ = false; + is_redirecting_ = false; + redirect_limit_ = kMaxRedirects; + priority_ = priority; + calling_delegate_ = false; + use_blocked_by_as_load_param_ =false; + before_request_callback_ = base::Bind(&URLRequest::BeforeRequestComplete, + base::Unretained(this)); + has_notified_completion_ = false; + received_response_content_length_ = 0; + creation_time_ = base::TimeTicks::Now(); + notified_before_network_start_ = false; + + SIMPLE_STATS_COUNTER("URLRequestCount"); + + // Sanity check out environment. + DCHECK(base::MessageLoop::current()) + << "The current base::MessageLoop must exist"; + + CHECK(context); + context->url_requests()->insert(this); + cookie_store_ = cookie_store; + if (cookie_store_ == NULL) + cookie_store_ = context->cookie_store(); + + net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); +} + void URLRequest::EnableChunkedUpload() { DCHECK(!upload_data_stream_ || upload_data_stream_->is_chunked()); if (!upload_data_stream_) { diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index 7c8e1a9..f4e8c40 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -25,6 +25,7 @@ #include "net/base/request_priority.h" #include "net/base/upload_progress.h" #include "net/cookies/canonical_cookie.h" +#include "net/cookies/cookie_store.h" #include "net/http/http_request_headers.h" #include "net/http/http_response_info.h" #include "net/url_request/url_request_status.h" @@ -291,11 +292,20 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), virtual ~Delegate() {} }; + // TODO(tburkard): we should get rid of this constructor, and have each + // creator of a URLRequest specifically list the cookie store to be used. + // For now, this constructor will use the cookie store in |context|. URLRequest(const GURL& url, RequestPriority priority, Delegate* delegate, const URLRequestContext* context); + URLRequest(const GURL& url, + RequestPriority priority, + Delegate* delegate, + const URLRequestContext* context, + CookieStore* cookie_store); + // If destroyed after Start() has been called but while IO is pending, // then the request will be effectively canceled and the delegate // will not have any more of its methods called. @@ -691,6 +701,8 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), // Allow the URLRequestJob class to set our status too void set_status(const URLRequestStatus& value) { status_ = value; } + CookieStore* cookie_store() const { return cookie_store_; } + // Allow the URLRequestJob to redirect this request. Returns OK if // successful, otherwise an error code is returned. int Redirect(const GURL& location, int http_status_code); @@ -730,6 +742,15 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), static void RegisterRequestInterceptor(Interceptor* interceptor); static void UnregisterRequestInterceptor(Interceptor* interceptor); + // Initializes the URLRequest. Code shared between the two constructors. + // TODO(tburkard): This can ultimately be folded into a single constructor + // again. + void Init(const GURL& url, + RequestPriority priotity, + Delegate* delegate, + const URLRequestContext* context, + CookieStore* cookie_store); + // Resumes or blocks a request paused by the NetworkDelegate::OnBeforeRequest // handler. If |blocked| is true, the request is blocked and an error page is // returned indicating so. This should only be called after Start is called @@ -895,6 +916,9 @@ class NET_EXPORT URLRequest : NON_EXPORTED_BASE(public base::NonThreadSafe), // Keeps track of whether or not OnBeforeNetworkStart has been called yet. bool notified_before_network_start_; + // The cookie store to be used for this request. + scoped_refptr<CookieStore> cookie_store_; + DISALLOW_COPY_AND_ASSIGN(URLRequest); }; diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc index 3542b16..d6a4d2f 100644 --- a/net/url_request/url_request_context.cc +++ b/net/url_request/url_request_context.cc @@ -73,8 +73,10 @@ const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams( scoped_ptr<URLRequest> URLRequestContext::CreateRequest( const GURL& url, RequestPriority priority, - URLRequest::Delegate* delegate) const { - return scoped_ptr<URLRequest>(new URLRequest(url, priority, delegate, this)); + URLRequest::Delegate* delegate, + CookieStore* cookie_store) const { + return scoped_ptr<URLRequest>( + new URLRequest(url, priority, delegate, this, cookie_store)); } void URLRequestContext::set_cookie_store(CookieStore* cookie_store) { diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index 5bb5b51..a05c9ae 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -58,9 +58,13 @@ class NET_EXPORT URLRequestContext // May return NULL if this context doesn't have an associated network session. const HttpNetworkSession::Params* GetNetworkSessionParams() const; + // Creates a URLRequest. |cookie_store| optionally specifies a cookie store + // to be used rather than the one represented by the context, or NULL + // otherwise. scoped_ptr<URLRequest> CreateRequest(const GURL& url, RequestPriority priority, - URLRequest::Delegate* delegate) const; + URLRequest::Delegate* delegate, + CookieStore* cookie_store) const; NetLog* net_log() const { return net_log_; diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 82ef633..044e5f0 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -539,7 +539,7 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() { if (!request_) return; - CookieStore* cookie_store = request_->context()->cookie_store(); + CookieStore* cookie_store = GetCookieStore(); if (cookie_store && !(request_info_.load_flags & LOAD_DO_NOT_SEND_COOKIES)) { net::CookieMonster* cookie_monster = cookie_store->GetCookieMonster(); if (cookie_monster) { @@ -558,7 +558,7 @@ void URLRequestHttpJob::AddCookieHeaderAndStart() { void URLRequestHttpJob::DoLoadCookies() { CookieOptions options; options.set_include_httponly(); - request_->context()->cookie_store()->GetCookiesWithOptionsAsync( + GetCookieStore()->GetCookiesWithOptionsAsync( request_->url(), options, base::Bind(&URLRequestHttpJob::OnCookiesLoaded, weak_factory_.GetWeakPtr())); @@ -638,8 +638,7 @@ void URLRequestHttpJob::SaveNextCookie() { new SharedBoolean(true); if (!(request_info_.load_flags & LOAD_DO_NOT_SAVE_COOKIES) && - request_->context()->cookie_store() && - response_cookies_.size() > 0) { + GetCookieStore() && response_cookies_.size() > 0) { CookieOptions options; options.set_include_httponly(); options.set_server_time(response_date_); @@ -657,7 +656,7 @@ void URLRequestHttpJob::SaveNextCookie() { if (CanSetCookie( response_cookies_[response_cookies_save_index_], &options)) { callback_pending->data = true; - request_->context()->cookie_store()->SetCookieWithOptionsAsync( + GetCookieStore()->SetCookieWithOptionsAsync( request_->url(), response_cookies_[response_cookies_save_index_], options, callback); } diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index 78f704a..c4b34c2 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -286,6 +286,12 @@ bool URLRequestJob::CanEnablePrivacyMode() const { return request_->CanEnablePrivacyMode(); } +CookieStore* URLRequestJob::GetCookieStore() const { + DCHECK(request_); + + return request_->cookie_store(); +} + void URLRequestJob::NotifyBeforeNetworkStart(bool* defer) { if (!request_) return; diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h index 3194ef6..9bb763e 100644 --- a/net/url_request/url_request_job.h +++ b/net/url_request/url_request_job.h @@ -26,6 +26,7 @@ namespace net { class AuthChallengeInfo; class AuthCredentials; class CookieOptions; +class CookieStore; class Filter; class HttpRequestHeaders; class HttpResponseInfo; @@ -238,6 +239,9 @@ class NET_EXPORT URLRequestJob // Delegates to URLRequest::Delegate. bool CanEnablePrivacyMode() const; + // Returns the cookie store to be used for the request. + CookieStore* GetCookieStore() const; + // Notifies the job that the network is about to be used. void NotifyBeforeNetworkStart(bool* defer); diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc index b0f5be8..63e65a4 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -36,9 +36,10 @@ const char* const kSetCookieHeaders[] = { }; net::SocketStreamJob* WebSocketJobFactory( - const GURL& url, net::SocketStream::Delegate* delegate) { + const GURL& url, net::SocketStream::Delegate* delegate, + net::URLRequestContext* context, net::CookieStore* cookie_store) { net::WebSocketJob* job = new net::WebSocketJob(delegate); - job->InitSocketStream(new net::SocketStream(url, job)); + job->InitSocketStream(new net::SocketStream(url, job, context, cookie_store)); return job; } @@ -370,11 +371,11 @@ void WebSocketJob::AddCookieHeaderAndSend() { if (socket_.get() && delegate_ && state_ == CONNECTING) { handshake_request_->RemoveHeaders(kCookieHeaders, arraysize(kCookieHeaders)); - if (allow && socket_->context()->cookie_store()) { + if (allow && socket_->cookie_store()) { // Add cookies, including HttpOnly cookies. CookieOptions cookie_options; cookie_options.set_include_httponly(); - socket_->context()->cookie_store()->GetCookiesWithOptionsAsync( + socket_->cookie_store()->GetCookiesWithOptionsAsync( GetURLForCookies(), cookie_options, base::Bind(&WebSocketJob::LoadCookieCallback, weak_ptr_factory_.GetWeakPtr())); @@ -505,7 +506,7 @@ void WebSocketJob::SaveNextCookie() { callback_pending_ = false; save_next_cookie_running_ = true; - if (socket_->context()->cookie_store()) { + if (socket_->cookie_store()) { GURL url_for_cookies = GetURLForCookies(); CookieOptions options; @@ -526,7 +527,7 @@ void WebSocketJob::SaveNextCookie() { continue; callback_pending_ = true; - socket_->context()->cookie_store()->SetCookieWithOptionsAsync( + socket_->cookie_store()->SetCookieWithOptionsAsync( url_for_cookies, cookie, options, base::Bind(&WebSocketJob::OnCookieSaved, weak_ptr_factory_.GetWeakPtr())); diff --git a/net/websockets/websocket_job_test.cc b/net/websockets/websocket_job_test.cc index 31bd9d6..3d7d424 100644 --- a/net/websockets/websocket_job_test.cc +++ b/net/websockets/websocket_job_test.cc @@ -41,8 +41,9 @@ namespace { class MockSocketStream : public SocketStream { public: - MockSocketStream(const GURL& url, SocketStream::Delegate* delegate) - : SocketStream(url, delegate) {} + MockSocketStream(const GURL& url, SocketStream::Delegate* delegate, + URLRequestContext* context, CookieStore* cookie_store) + : SocketStream(url, delegate, context, cookie_store) {} virtual void Connect() OVERRIDE {} virtual bool SendData(const char* data, int len) OVERRIDE { @@ -364,7 +365,8 @@ class WebSocketJobTest : public PlatformTest, websocket_ = new WebSocketJob(delegate); if (stream_type == STREAM_MOCK_SOCKET) - socket_ = new MockSocketStream(url, websocket_.get()); + socket_ = new MockSocketStream(url, websocket_.get(), context_.get(), + NULL); if (stream_type == STREAM_SOCKET || stream_type == STREAM_SPDY_WEBSOCKET) { if (stream_type == STREAM_SPDY_WEBSOCKET) { @@ -380,7 +382,7 @@ class WebSocketJobTest : public PlatformTest, host_resolver_.reset(new MockHostResolver); context_->set_host_resolver(host_resolver_.get()); - socket_ = new SocketStream(url, websocket_.get()); + socket_ = new SocketStream(url, websocket_.get(), context_.get(), NULL); socket_factory_.reset(new MockClientSocketFactory); DCHECK(data_.get()); socket_factory_->AddSocketDataProvider(data_.get()); @@ -388,7 +390,6 @@ class WebSocketJobTest : public PlatformTest, } websocket_->InitSocketStream(socket_.get()); - websocket_->set_context(context_.get()); // MockHostResolver resolves all hosts to 127.0.0.1; however, when we create // a WebSocketJob purely to block another one in a throttling test, we don't // perform a real connect. In that case, the following address is used @@ -738,14 +739,14 @@ void WebSocketJobTest::TestHSTSUpgrade() { scoped_refptr<SocketStreamJob> job = SocketStreamJob::CreateSocketStreamJob( url, &delegate, context_->transport_security_state(), - context_->ssl_config_service()); + context_->ssl_config_service(), NULL, NULL); EXPECT_TRUE(GetSocket(job.get())->is_secure()); job->DetachDelegate(); url = GURL("ws://donotupgrademe.com/"); job = SocketStreamJob::CreateSocketStreamJob( url, &delegate, context_->transport_security_state(), - context_->ssl_config_service()); + context_->ssl_config_service(), NULL, NULL); EXPECT_FALSE(GetSocket(job.get())->is_secure()); job->DetachDelegate(); } diff --git a/net/websockets/websocket_throttle_test.cc b/net/websockets/websocket_throttle_test.cc index 14237b9..7b33883 100644 --- a/net/websockets/websocket_throttle_test.cc +++ b/net/websockets/websocket_throttle_test.cc @@ -73,8 +73,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { addr.push_back(MakeAddr(1, 2, 3, 6)); scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s1( - new SocketStream(GURL("ws://host1/"), w1.get())); - s1->set_context(&context); + new SocketStream(GURL("ws://host1/"), w1.get(), &context, NULL)); w1->InitSocketStream(s1.get()); WebSocketThrottleTest::MockSocketStreamConnect(s1.get(), addr); @@ -94,8 +93,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { addr.push_back(MakeAddr(1, 2, 3, 4)); scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s2( - new SocketStream(GURL("ws://host2/"), w2.get())); - s2->set_context(&context); + new SocketStream(GURL("ws://host2/"), w2.get(), &context, NULL)); w2->InitSocketStream(s2.get()); WebSocketThrottleTest::MockSocketStreamConnect(s2.get(), addr); @@ -115,8 +113,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { addr.push_back(MakeAddr(1, 2, 3, 5)); scoped_refptr<WebSocketJob> w3(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s3( - new SocketStream(GURL("ws://host3/"), w3.get())); - s3->set_context(&context); + new SocketStream(GURL("ws://host3/"), w3.get(), &context, NULL)); w3->InitSocketStream(s3.get()); WebSocketThrottleTest::MockSocketStreamConnect(s3.get(), addr); @@ -136,8 +133,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { addr.push_back(MakeAddr(1, 2, 3, 6)); scoped_refptr<WebSocketJob> w4(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s4( - new SocketStream(GURL("ws://host4/"), w4.get())); - s4->set_context(&context); + new SocketStream(GURL("ws://host4/"), w4.get(), &context, NULL)); w4->InitSocketStream(s4.get()); WebSocketThrottleTest::MockSocketStreamConnect(s4.get(), addr); @@ -156,8 +152,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { addr.push_back(MakeAddr(1, 2, 3, 6)); scoped_refptr<WebSocketJob> w5(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s5( - new SocketStream(GURL("ws://host5/"), w5.get())); - s5->set_context(&context); + new SocketStream(GURL("ws://host5/"), w5.get(), &context, NULL)); w5->InitSocketStream(s5.get()); WebSocketThrottleTest::MockSocketStreamConnect(s5.get(), addr); @@ -176,8 +171,7 @@ TEST_F(WebSocketThrottleTest, Throttle) { addr.push_back(MakeAddr(1, 2, 3, 6)); scoped_refptr<WebSocketJob> w6(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s6( - new SocketStream(GURL("ws://host6/"), w6.get())); - s6->set_context(&context); + new SocketStream(GURL("ws://host6/"), w6.get(), &context, NULL)); w6->InitSocketStream(s6.get()); WebSocketThrottleTest::MockSocketStreamConnect(s6.get(), addr); @@ -289,8 +283,7 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDuplicateAddress) { addr.push_back(MakeAddr(127, 0, 0, 1)); scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s1( - new SocketStream(GURL("ws://localhost/"), w1.get())); - s1->set_context(&context); + new SocketStream(GURL("ws://localhost/"), w1.get(), &context, NULL)); w1->InitSocketStream(s1.get()); WebSocketThrottleTest::MockSocketStreamConnect(s1.get(), addr); @@ -318,8 +311,7 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) { // socket1: 127.0.0.1:80 scoped_refptr<WebSocketJob> w1(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s1( - new SocketStream(GURL("ws://localhost:80/"), w1.get())); - s1->set_context(&context); + new SocketStream(GURL("ws://localhost:80/"), w1.get(), &context, NULL)); w1->InitSocketStream(s1.get()); MockSocketStreamConnect(s1.get(), AddressList::CreateFromIPAddress(localhost, 80)); @@ -332,8 +324,7 @@ TEST_F(WebSocketThrottleTest, NoThrottleForDistinctPort) { // socket2: 127.0.0.1:81 scoped_refptr<WebSocketJob> w2(new WebSocketJob(&delegate)); scoped_refptr<SocketStream> s2( - new SocketStream(GURL("ws://localhost:81/"), w2.get())); - s2->set_context(&context); + new SocketStream(GURL("ws://localhost:81/"), w2.get(), &context, NULL)); w2->InitSocketStream(s2.get()); MockSocketStreamConnect(s2.get(), AddressList::CreateFromIPAddress(localhost, 81)); diff --git a/remoting/host/token_validator_factory_impl.cc b/remoting/host/token_validator_factory_impl.cc index 9468d58..0d7906a 100644 --- a/remoting/host/token_validator_factory_impl.cc +++ b/remoting/host/token_validator_factory_impl.cc @@ -82,7 +82,7 @@ void TokenValidatorImpl::StartValidateRequest(const std::string& token) { request_ = request_context_getter_->GetURLRequestContext()->CreateRequest( third_party_auth_config_.token_validation_url, net::DEFAULT_PRIORITY, - this); + this, NULL); request_->SetExtraRequestHeaderByName( net::HttpRequestHeaders::kContentType, "application/x-www-form-urlencoded", true); diff --git a/webkit/browser/appcache/appcache_storage_impl_unittest.cc b/webkit/browser/appcache/appcache_storage_impl_unittest.cc index 7eba545..8a4d5d7 100644 --- a/webkit/browser/appcache/appcache_storage_impl_unittest.cc +++ b/webkit/browser/appcache/appcache_storage_impl_unittest.cc @@ -1746,7 +1746,7 @@ class AppCacheStorageImplTest : public testing::Test { AppCacheHost* host2 = backend_->GetHost(2); GURL manifest_url = MockHttpServer::GetMockUrl("manifest"); request_ = service()->request_context()->CreateRequest( - manifest_url, net::DEFAULT_PRIORITY, NULL); + manifest_url, net::DEFAULT_PRIORITY, NULL, NULL); AppCacheInterceptor::SetExtraRequestInfo( request_.get(), service_.get(), backend_->process_id(), host2->host_id(), diff --git a/webkit/browser/appcache/appcache_update_job.cc b/webkit/browser/appcache/appcache_update_job.cc index 03bb909..253aee7 100644 --- a/webkit/browser/appcache/appcache_update_job.cc +++ b/webkit/browser/appcache/appcache_update_job.cc @@ -112,7 +112,7 @@ AppCacheUpdateJob::URLFetcher::URLFetcher(const GURL& url, retry_503_attempts_(0), buffer_(new net::IOBuffer(kBufferSize)), request_(job->service_->request_context() - ->CreateRequest(url, net::DEFAULT_PRIORITY, this)), + ->CreateRequest(url, net::DEFAULT_PRIORITY, this, NULL)), result_(UPDATE_OK) {} AppCacheUpdateJob::URLFetcher::~URLFetcher() { @@ -314,7 +314,7 @@ bool AppCacheUpdateJob::URLFetcher::MaybeRetryRequest() { ++retry_503_attempts_; result_ = UPDATE_OK; request_ = job_->service_->request_context()->CreateRequest( - url_, net::DEFAULT_PRIORITY, this); + url_, net::DEFAULT_PRIORITY, this, NULL); Start(); return true; } diff --git a/webkit/browser/appcache/appcache_url_request_job_unittest.cc b/webkit/browser/appcache/appcache_url_request_job_unittest.cc index 3f9675a..a6e6027 100644 --- a/webkit/browser/appcache/appcache_url_request_job_unittest.cc +++ b/webkit/browser/appcache/appcache_url_request_job_unittest.cc @@ -448,7 +448,8 @@ class AppCacheURLRequestJobTest : public testing::Test { AppCacheStorage* storage = service_->storage(); request_ = empty_context_.CreateRequest(GURL("http://blah/"), net::DEFAULT_PRIORITY, - url_request_delegate_.get()); + url_request_delegate_.get(), + NULL); // Setup to create an AppCacheURLRequestJob with orders to deliver // a network response. @@ -483,7 +484,8 @@ class AppCacheURLRequestJobTest : public testing::Test { AppCacheStorage* storage = service_->storage(); request_ = empty_context_.CreateRequest(GURL("http://blah/"), net::DEFAULT_PRIORITY, - url_request_delegate_.get()); + url_request_delegate_.get(), + NULL); // Setup to create an AppCacheURLRequestJob with orders to deliver // a network response. @@ -533,7 +535,8 @@ class AppCacheURLRequestJobTest : public testing::Test { AppCacheStorage* storage = service_->storage(); request_ = empty_context_.CreateRequest(GURL("http://blah/"), net::DEFAULT_PRIORITY, - url_request_delegate_.get()); + url_request_delegate_.get(), + NULL); // Setup to create an AppCacheURLRequestJob with orders to deliver // a network response. @@ -647,7 +650,8 @@ class AppCacheURLRequestJobTest : public testing::Test { AppCacheStorage* storage = service_->storage(); request_ = empty_context_.CreateRequest(GURL("http://blah/"), net::DEFAULT_PRIORITY, - url_request_delegate_.get()); + url_request_delegate_.get(), + NULL); // Request a range, the 3 middle chars out of 'Hello' net::HttpRequestHeaders extra_headers; diff --git a/webkit/browser/blob/blob_url_request_job_factory.cc b/webkit/browser/blob/blob_url_request_job_factory.cc index f36e0a5..73efe4c 100644 --- a/webkit/browser/blob/blob_url_request_job_factory.cc +++ b/webkit/browser/blob/blob_url_request_job_factory.cc @@ -35,7 +35,7 @@ scoped_ptr<net::URLRequest> BlobProtocolHandler::CreateBlobRequest( net::URLRequest::Delegate* request_delegate) { const GURL kBlobUrl("blob://see_user_data/"); scoped_ptr<net::URLRequest> request = request_context->CreateRequest( - kBlobUrl, net::DEFAULT_PRIORITY, request_delegate); + kBlobUrl, net::DEFAULT_PRIORITY, request_delegate, NULL); SetRequestedBlobDataHandle(request.get(), blob_data_handle.Pass()); return request.Pass(); } |