diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 21:54:55 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-13 21:54:55 +0000 |
commit | 2581e577597dd0f435ae1e6fe918df912bb98248 (patch) | |
tree | 5d1edc9fe3d12eb1d7da8d8361bc57e5ad4dc397 | |
parent | dec173b814e09f0633bdfefad7e1d89c50fa4919 (diff) | |
download | chromium_src-2581e577597dd0f435ae1e6fe918df912bb98248.zip chromium_src-2581e577597dd0f435ae1e6fe918df912bb98248.tar.gz chromium_src-2581e577597dd0f435ae1e6fe918df912bb98248.tar.bz2 |
Propagate the "first party for cookies" from WebKit to the network stack
when we follow a redirect, because WebKit's
MainResourceLoader::willSendRequest method may change the "first party for
cookies" URL of the resource request.
R=abarth
BUG=25133
TEST=In Options menu, change cookie policy to "Accept cookies only from
sites I visit" and then follow the instructions in issue 25133 comment 20.
Review URL: http://codereview.chromium.org/385024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31951 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.cc | 16 | ||||
-rw-r--r-- | chrome/browser/renderer_host/resource_dispatcher_host.h | 10 | ||||
-rw-r--r-- | chrome/browser/renderer_host/safe_browsing_resource_handler.cc | 6 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 5 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher.cc | 7 | ||||
-rw-r--r-- | chrome/common/resource_dispatcher_unittest.cc | 8 | ||||
-rw-r--r-- | chrome/common/security_filter_peer.cc | 3 | ||||
-rw-r--r-- | chrome/common/security_filter_peer.h | 3 | ||||
-rw-r--r-- | chrome/plugin/chrome_plugin_host.cc | 4 | ||||
-rw-r--r-- | net/url_request/url_request.cc | 1 | ||||
-rw-r--r-- | net/url_request/url_request.h | 2 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source.cc | 4 | ||||
-rw-r--r-- | webkit/glue/media/buffered_data_source.h | 3 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.cc | 4 | ||||
-rw-r--r-- | webkit/glue/media/simple_data_source.h | 3 | ||||
-rw-r--r-- | webkit/glue/resource_loader_bridge.h | 15 | ||||
-rw-r--r-- | webkit/glue/weburlloader_impl.cc | 12 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_resource_loader_bridge.cc | 11 |
18 files changed, 82 insertions, 35 deletions
diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.cc b/chrome/browser/renderer_host/resource_dispatcher_host.cc index 35ba9be..7c192ec 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.cc +++ b/chrome/browser/renderer_host/resource_dispatcher_host.cc @@ -62,7 +62,6 @@ #if defined(OS_POSIX) #include "chrome/common/temp_scaffolding_stubs.h" #elif defined(OS_WIN) -#include "chrome/browser/renderer_host/render_view_host_delegate.h" #include "chrome/browser/safe_browsing/safe_browsing_service.h" #endif @@ -657,8 +656,11 @@ void ResourceDispatcherHost::OnCancelRequest(int request_id) { CancelRequest(receiver_->id(), request_id, true, true); } -void ResourceDispatcherHost::OnFollowRedirect(int request_id) { - FollowDeferredRedirect(receiver_->id(), request_id); +void ResourceDispatcherHost::OnFollowRedirect( + int request_id, + const GURL& new_first_party_for_cookies) { + FollowDeferredRedirect(receiver_->id(), request_id, + new_first_party_for_cookies); } void ResourceDispatcherHost::OnClosePageACK( @@ -829,8 +831,10 @@ void ResourceDispatcherHost::CancelRequest(int child_id, CancelRequest(child_id, request_id, from_renderer, true); } -void ResourceDispatcherHost::FollowDeferredRedirect(int child_id, - int request_id) { +void ResourceDispatcherHost::FollowDeferredRedirect( + int child_id, + int request_id, + const GURL& new_first_party_for_cookies) { PendingRequestList::iterator i = pending_requests_.find( GlobalRequestID(child_id, request_id)); if (i == pending_requests_.end()) { @@ -838,6 +842,8 @@ void ResourceDispatcherHost::FollowDeferredRedirect(int child_id, return; } + if (!new_first_party_for_cookies.is_empty()) + i->second->set_first_party_for_cookies(new_first_party_for_cookies); i->second->FollowDeferredRedirect(); } diff --git a/chrome/browser/renderer_host/resource_dispatcher_host.h b/chrome/browser/renderer_host/resource_dispatcher_host.h index c354b0a..9796e80 100644 --- a/chrome/browser/renderer_host/resource_dispatcher_host.h +++ b/chrome/browser/renderer_host/resource_dispatcher_host.h @@ -142,8 +142,13 @@ class ResourceDispatcherHost : public URLRequest::Delegate { bool from_renderer); // Follows a deferred redirect for the given request. + // new_first_party_for_cookies, if non-empty, is the new cookie policy URL + // for the redirected URL. Pass an empty, invalid URL as + // new_first_party_for_cookies to indicate that the cookie policy URL + // doesn't need changing. void FollowDeferredRedirect(int process_unique_id, - int request_id); + int request_id, + const GURL& new_first_party_for_cookies); // Returns true if it's ok to send the data. If there are already too many // data messages pending, it pauses the request and returns false. In this @@ -400,7 +405,8 @@ class ResourceDispatcherHost : public URLRequest::Delegate { void OnDataReceivedACK(int request_id); void OnUploadProgressACK(int request_id); void OnCancelRequest(int request_id); - void OnFollowRedirect(int request_id); + void OnFollowRedirect(int request_id, + const GURL& new_first_party_for_cookies); // Returns true if the message passed in is a resource related message. static bool IsResourceDispatcherHostMessage(const IPC::Message&); diff --git a/chrome/browser/renderer_host/safe_browsing_resource_handler.cc b/chrome/browser/renderer_host/safe_browsing_resource_handler.cc index e33e796..ad3105d 100644 --- a/chrome/browser/renderer_host/safe_browsing_resource_handler.cc +++ b/chrome/browser/renderer_host/safe_browsing_resource_handler.cc @@ -241,8 +241,10 @@ void SafeBrowsingResourceHandler::ResumeRedirect() { bool defer = false; next_handler_->OnRequestRedirected(redirect_id_, redirect_url_, redirect_response_, &defer); - if (!defer) - rdh_->FollowDeferredRedirect(render_process_host_id_, redirect_id_); + if (!defer) { + rdh_->FollowDeferredRedirect(render_process_host_id_, redirect_id_, + GURL()); + } redirect_response_ = NULL; redirect_id_ = -1; diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 866d9aa..3240bf63 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -1054,8 +1054,9 @@ IPC_BEGIN_MESSAGES(ViewHost) // Follows a redirect that occured for the resource request with the ID given // as the parameter. - IPC_MESSAGE_ROUTED1(ViewHostMsg_FollowRedirect, - int /* request_id */) + IPC_MESSAGE_ROUTED2(ViewHostMsg_FollowRedirect, + int /* request_id */, + GURL /* new_first_party_for_cookies */) // Makes a synchronous resource request via the browser. IPC_SYNC_MESSAGE_ROUTED2_1(ViewHostMsg_SyncLoad, diff --git a/chrome/common/resource_dispatcher.cc b/chrome/common/resource_dispatcher.cc index 36c66a9..ed0365a 100644 --- a/chrome/common/resource_dispatcher.cc +++ b/chrome/common/resource_dispatcher.cc @@ -421,9 +421,12 @@ void ResourceDispatcher::OnReceivedRedirect( RESOURCE_LOG("Dispatching redirect for " << request_info.peer->GetURLForDebugging().possibly_invalid_spec()); - if (request_info.peer->OnReceivedRedirect(new_url, info)) { + GURL new_first_party_for_cookies; + if (request_info.peer->OnReceivedRedirect(new_url, info, + &new_first_party_for_cookies)) { message_sender()->Send( - new ViewHostMsg_FollowRedirect(message.routing_id(), request_id)); + new ViewHostMsg_FollowRedirect(message.routing_id(), request_id, + new_first_party_for_cookies)); } else { CancelPendingRequest(message.routing_id(), request_id); } diff --git a/chrome/common/resource_dispatcher_unittest.cc b/chrome/common/resource_dispatcher_unittest.cc index b8503ce..1652ad9 100644 --- a/chrome/common/resource_dispatcher_unittest.cc +++ b/chrome/common/resource_dispatcher_unittest.cc @@ -34,7 +34,9 @@ class TestRequestCallback : public ResourceLoaderBridge::Peer { virtual bool OnReceivedRedirect( const GURL& new_url, - const ResourceLoaderBridge::ResponseInfo& info) { + const ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies) { + *new_first_party_for_cookies = GURL(); return true; } @@ -243,7 +245,9 @@ class DeferredResourceLoadingTest : public ResourceDispatcherTest, virtual bool OnReceivedRedirect( const GURL& new_url, - const ResourceLoaderBridge::ResponseInfo& info) { + const ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies) { + *new_first_party_for_cookies = GURL(); return true; } diff --git a/chrome/common/security_filter_peer.cc b/chrome/common/security_filter_peer.cc index 2f21385..6b2b427 100644 --- a/chrome/common/security_filter_peer.cc +++ b/chrome/common/security_filter_peer.cc @@ -106,7 +106,8 @@ void SecurityFilterPeer::OnUploadProgress(uint64 position, uint64 size) { bool SecurityFilterPeer::OnReceivedRedirect( const GURL& new_url, - const webkit_glue::ResourceLoaderBridge::ResponseInfo& info) { + const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies) { NOTREACHED(); return false; } diff --git a/chrome/common/security_filter_peer.h b/chrome/common/security_filter_peer.h index 5594376..3bd4fcf 100644 --- a/chrome/common/security_filter_peer.h +++ b/chrome/common/security_filter_peer.h @@ -41,7 +41,8 @@ class SecurityFilterPeer : public webkit_glue::ResourceLoaderBridge::Peer { virtual void OnUploadProgress(uint64 position, uint64 size); virtual bool OnReceivedRedirect( const GURL& new_url, - const webkit_glue::ResourceLoaderBridge::ResponseInfo& info); + const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies); virtual void OnReceivedResponse( const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); diff --git a/chrome/plugin/chrome_plugin_host.cc b/chrome/plugin/chrome_plugin_host.cc index 6c3e71a..23f0e5b 100644 --- a/chrome/plugin/chrome_plugin_host.cc +++ b/chrome/plugin/chrome_plugin_host.cc @@ -68,9 +68,11 @@ class PluginRequestHandlerProxy virtual bool OnReceivedRedirect( const GURL& new_url, - const ResourceLoaderBridge::ResponseInfo& info) { + const ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies) { plugin_->functions().response_funcs->received_redirect( cprequest_.get(), new_url.spec().c_str()); + *new_first_party_for_cookies = GURL(); return true; } diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 9577a4a..6aa2574 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -223,7 +223,6 @@ bool URLRequest::IsHandledURL(const GURL& url) { void URLRequest::set_first_party_for_cookies( const GURL& first_party_for_cookies) { - DCHECK(!is_pending_); first_party_for_cookies_ = first_party_for_cookies; } diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index f64c694..d342b7d 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -258,6 +258,8 @@ class URLRequest { const GURL& first_party_for_cookies() const { return first_party_for_cookies_; } + // This method may be called before Start() or FollowDeferredRedirect() is + // called. void set_first_party_for_cookies(const GURL& first_party_for_cookies); // The request method, as an uppercase string. "GET" is the default value. diff --git a/webkit/glue/media/buffered_data_source.cc b/webkit/glue/media/buffered_data_source.cc index 48df614..3d2c73f 100644 --- a/webkit/glue/media/buffered_data_source.cc +++ b/webkit/glue/media/buffered_data_source.cc @@ -230,11 +230,13 @@ int64 BufferedResourceLoader::GetBufferedLastBytePosition() { // webkit_glue::ResourceLoaderBridge::Peer implementations bool BufferedResourceLoader::OnReceivedRedirect( const GURL& new_url, - const webkit_glue::ResourceLoaderBridge::ResponseInfo& info) { + const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies) { DCHECK(bridge_.get()); // Save the new URL. url_ = new_url; + *new_first_party_for_cookies = GURL(); // The load may have been stopped and |start_callback| is destroyed. // In this case we shouldn't do anything. diff --git a/webkit/glue/media/buffered_data_source.h b/webkit/glue/media/buffered_data_source.h index bbab6d6..627f84d 100644 --- a/webkit/glue/media/buffered_data_source.h +++ b/webkit/glue/media/buffered_data_source.h @@ -109,7 +109,8 @@ class BufferedResourceLoader : virtual void OnUploadProgress(uint64 position, uint64 size) {} virtual bool OnReceivedRedirect( const GURL& new_url, - const webkit_glue::ResourceLoaderBridge::ResponseInfo& info); + const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies); virtual void OnReceivedResponse( const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); diff --git a/webkit/glue/media/simple_data_source.cc b/webkit/glue/media/simple_data_source.cc index 0a4c11e..ed2a594 100644 --- a/webkit/glue/media/simple_data_source.cc +++ b/webkit/glue/media/simple_data_source.cc @@ -122,8 +122,10 @@ void SimpleDataSource::OnUploadProgress(uint64 position, uint64 size) {} bool SimpleDataSource::OnReceivedRedirect( const GURL& new_url, - const webkit_glue::ResourceLoaderBridge::ResponseInfo& info) { + const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies) { SetURL(new_url); + *new_first_party_for_cookies = GURL(); return true; } diff --git a/webkit/glue/media/simple_data_source.h b/webkit/glue/media/simple_data_source.h index c578aa5..3aac41b 100644 --- a/webkit/glue/media/simple_data_source.h +++ b/webkit/glue/media/simple_data_source.h @@ -55,7 +55,8 @@ class SimpleDataSource : public media::DataSource, virtual void OnUploadProgress(uint64 position, uint64 size); virtual bool OnReceivedRedirect( const GURL& new_url, - const webkit_glue::ResourceLoaderBridge::ResponseInfo& info); + const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies); virtual void OnReceivedResponse( const webkit_glue::ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); diff --git a/webkit/glue/resource_loader_bridge.h b/webkit/glue/resource_loader_bridge.h index 8393a9f..48f5129 100644 --- a/webkit/glue/resource_loader_bridge.h +++ b/webkit/glue/resource_loader_bridge.h @@ -14,8 +14,8 @@ // In turn, the bridge's owner on the WebKit end will implement the Peer // interface, which we will use to communicate notifications back. -#ifndef RESOURCE_LOADER_BRIDGE_H_ -#define RESOURCE_LOADER_BRIDGE_H_ +#ifndef WEBKIT_GLUE_RESOURCE_LOADER_BRIDGE_H_ +#define WEBKIT_GLUE_RESOURCE_LOADER_BRIDGE_H_ #include "build/build_config.h" #if defined(OS_POSIX) @@ -110,9 +110,14 @@ class ResourceLoaderBridge { // Called when a redirect occurs. The implementation may return false to // suppress the redirect. The given ResponseInfo provides complete // information about the redirect, and new_url is the URL that will be - // loaded if this method returns true. + // loaded if this method returns true. If this method returns true, it + // stores in *new_first_party_for_cookies the new URL that should be + // consulted for the third-party cookie blocking policy. If the cookie + // policy URL doesn't need changing, it stores an empty, invalid URL in + // *new_first_party_for_cookies. virtual bool OnReceivedRedirect(const GURL& new_url, - const ResponseInfo& info) = 0; + const ResponseInfo& info, + GURL* new_first_party_for_cookies) = 0; // Called when response headers are available (after all redirects have // been followed). |content_filtered| is set to true if the contents is @@ -232,4 +237,4 @@ class ResourceLoaderBridge { } // namespace webkit_glue -#endif // RESOURCE_LOADER_BRIDGE_ +#endif // WEBKIT_GLUE_RESOURCE_LOADER_BRIDGE_H_ diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc index 7fd8a22..7683014 100644 --- a/webkit/glue/weburlloader_impl.cc +++ b/webkit/glue/weburlloader_impl.cc @@ -185,7 +185,7 @@ void PopulateURLResponse( } } -} // namespace +} // namespace // WebURLLoaderImpl::Context -------------------------------------------------- @@ -209,7 +209,9 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>, // ResourceLoaderBridge::Peer methods: virtual void OnUploadProgress(uint64 position, uint64 size); virtual bool OnReceivedRedirect( - const GURL& new_url, const ResourceLoaderBridge::ResponseInfo& info); + const GURL& new_url, + const ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies); virtual void OnReceivedResponse( const ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); virtual void OnReceivedData(const char* data, int len); @@ -388,7 +390,8 @@ void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { bool WebURLLoaderImpl::Context::OnReceivedRedirect( const GURL& new_url, - const ResourceLoaderBridge::ResponseInfo& info) { + const ResourceLoaderBridge::ResponseInfo& info, + GURL* new_first_party_for_cookies) { if (!client_) return false; @@ -403,8 +406,9 @@ bool WebURLLoaderImpl::Context::OnReceivedRedirect( if (response.httpStatusCode() == 307) new_request.setHTTPMethod(request_.httpMethod()); - request_ = new_request; client_->willSendRequest(loader_, new_request, response); + request_ = new_request; + *new_first_party_for_cookies = request_.firstPartyForCookies(); // Only follow the redirect if WebKit left the URL unmodified. if (new_url == GURL(new_request.url())) diff --git a/webkit/tools/test_shell/simple_resource_loader_bridge.cc b/webkit/tools/test_shell/simple_resource_loader_bridge.cc index b041921..65f1640 100644 --- a/webkit/tools/test_shell/simple_resource_loader_bridge.cc +++ b/webkit/tools/test_shell/simple_resource_loader_bridge.cc @@ -153,9 +153,12 @@ class RequestProxy : public URLRequest::Delegate, void NotifyReceivedRedirect(const GURL& new_url, const ResourceLoaderBridge::ResponseInfo& info) { - if (peer_ && peer_->OnReceivedRedirect(new_url, info)) { + GURL new_first_party_for_cookies; + if (peer_ && peer_->OnReceivedRedirect(new_url, info, + &new_first_party_for_cookies)) { io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( - this, &RequestProxy::AsyncFollowDeferredRedirect)); + this, &RequestProxy::AsyncFollowDeferredRedirect, + new_first_party_for_cookies)); } else { Cancel(); } @@ -238,11 +241,13 @@ class RequestProxy : public URLRequest::Delegate, Done(); } - void AsyncFollowDeferredRedirect() { + void AsyncFollowDeferredRedirect(const GURL& new_first_party_for_cookies) { // This can be null in cases where the request is already done. if (!request_.get()) return; + if (!new_first_party_for_cookies.is_empty()) + request_->set_first_party_for_cookies(new_first_party_for_cookies); request_->FollowDeferredRedirect(); } |