diff options
author | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-15 20:49:59 +0000 |
---|---|---|
committer | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-15 20:51:41 +0000 |
commit | cba246463b2bda73877fc53da6d7eff97448d93d (patch) | |
tree | c8a77dfaff426ea06667b3714e4af2d9ed3b7d94 /content/child | |
parent | 7d0a0cac7c1233e6beeaf7ca8092f89f81e950ef (diff) | |
download | chromium_src-cba246463b2bda73877fc53da6d7eff97448d93d.zip chromium_src-cba246463b2bda73877fc53da6d7eff97448d93d.tar.gz chromium_src-cba246463b2bda73877fc53da6d7eff97448d93d.tar.bz2 |
Plumb redirect info out of net, through content, and into child processes.
This saves the logic in PluginURLFetcher and WebURLLoader that has to replicate
the method-munging, referrer-munging, and first-party-URL-munging logic that is
already done in net/.
BUG=384609
Review URL: https://codereview.chromium.org/398903002
Cr-Commit-Position: refs/heads/master@{#290005}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/child')
-rw-r--r-- | content/child/npapi/plugin_url_fetcher.cc | 34 | ||||
-rw-r--r-- | content/child/npapi/plugin_url_fetcher.h | 4 | ||||
-rw-r--r-- | content/child/resource_dispatcher.cc | 9 | ||||
-rw-r--r-- | content/child/resource_dispatcher.h | 7 | ||||
-rw-r--r-- | content/child/resource_dispatcher_unittest.cc | 14 | ||||
-rw-r--r-- | content/child/web_url_loader_impl.cc | 40 | ||||
-rw-r--r-- | content/child/web_url_loader_impl_unittest.cc | 8 |
7 files changed, 50 insertions, 66 deletions
diff --git a/content/child/npapi/plugin_url_fetcher.cc b/content/child/npapi/plugin_url_fetcher.cc index 48c685e..d339033 100644 --- a/content/child/npapi/plugin_url_fetcher.cc +++ b/content/child/npapi/plugin_url_fetcher.cc @@ -23,7 +23,7 @@ #include "net/base/load_flags.h" #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" -#include "net/url_request/url_request.h" +#include "net/url_request/redirect_info.h" #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" #include "third_party/WebKit/public/platform/WebURLResponse.h" #include "webkit/child/resource_loader_bridge.h" @@ -95,7 +95,6 @@ PluginURLFetcher::PluginURLFetcher(PluginStreamUrl* plugin_stream, : plugin_stream_(plugin_stream), url_(url), first_party_for_cookies_(first_party_for_cookies), - method_(method), referrer_(referrer), notify_redirects_(notify_redirects), is_plugin_src_load_(is_plugin_src_load), @@ -191,8 +190,7 @@ void PluginURLFetcher::OnUploadProgress(uint64 position, uint64 size) { } bool PluginURLFetcher::OnReceivedRedirect( - const GURL& new_url, - const GURL& new_first_party_for_cookies, + const net::RedirectInfo& redirect_info, const ResourceResponseInfo& info) { if (!plugin_stream_) return false; @@ -206,42 +204,28 @@ bool PluginURLFetcher::OnReceivedRedirect( // initiated by plug-ins. if (is_plugin_src_load_ && !plugin_stream_->instance()->webplugin()->CheckIfRunInsecureContent( - new_url)) { + redirect_info.new_url)) { plugin_stream_->DidFail(resource_id_); // That will delete |this|. return false; } - // It's unfortunate that this logic of when a redirect's method changes is - // in url_request.cc, but weburlloader_impl.cc and this file have to duplicate - // it instead of passing that information. - int response_code; - if (info.headers) { - response_code = info.headers->response_code(); - } else { - // A redirect may have NULL headers if it came from URLRequestRedirectJob. - // - // TODO(davidben): Get the actual response code from the browser. Either - // fake enough of headers to have a response code or pass it down as part of - // https://crbug.com/384609. - response_code = 307; - } - method_ = net::URLRequest::ComputeMethodForRedirect(method_, response_code); GURL old_url = url_; - url_ = new_url; - first_party_for_cookies_ = new_first_party_for_cookies; + url_ = redirect_info.new_url; + first_party_for_cookies_ = redirect_info.new_first_party_for_cookies; // If the plugin does not participate in url redirect notifications then just // block cross origin 307 POST redirects. if (!notify_redirects_) { - if (response_code == 307 && method_ == "POST" && - old_url.GetOrigin() != new_url.GetOrigin()) { + if (redirect_info.status_code == 307 && + redirect_info.new_method == "POST" && + old_url.GetOrigin() != url_.GetOrigin()) { plugin_stream_->DidFail(resource_id_); // That will delete |this|. return false; } } else { // Pause the request while we ask the plugin what to do about the redirect. bridge_->SetDefersLoading(true); - plugin_stream_->WillSendRequest(url_, response_code); + plugin_stream_->WillSendRequest(url_, redirect_info.status_code); } return true; diff --git a/content/child/npapi/plugin_url_fetcher.h b/content/child/npapi/plugin_url_fetcher.h index b1d7716..8dc53f2 100644 --- a/content/child/npapi/plugin_url_fetcher.h +++ b/content/child/npapi/plugin_url_fetcher.h @@ -56,8 +56,7 @@ class PluginURLFetcher : public RequestPeer { private: // RequestPeer implementation: virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; - virtual bool OnReceivedRedirect(const GURL& new_url, - const GURL& new_first_party_for_cookies, + virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, const ResourceResponseInfo& info) OVERRIDE; virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; @@ -76,7 +75,6 @@ class PluginURLFetcher : public RequestPeer { PluginStreamUrl* plugin_stream_; GURL url_; GURL first_party_for_cookies_; - std::string method_; GURL referrer_; bool notify_redirects_; bool is_plugin_src_load_; diff --git a/content/child/resource_dispatcher.cc b/content/child/resource_dispatcher.cc index 3ca9668..c8fe61a 100644 --- a/content/child/resource_dispatcher.cc +++ b/content/child/resource_dispatcher.cc @@ -499,8 +499,7 @@ void ResourceDispatcher::OnDownloadedData(int request_id, void ResourceDispatcher::OnReceivedRedirect( int request_id, - const GURL& new_url, - const GURL& new_first_party_for_cookies, + const net::RedirectInfo& redirect_info, const ResourceResponseHead& response_head) { TRACE_EVENT0("loader", "ResourceDispatcher::OnReceivedRedirect"); PendingRequestInfo* request_info = GetPendingRequestInfo(request_id); @@ -510,8 +509,8 @@ void ResourceDispatcher::OnReceivedRedirect( ResourceResponseInfo renderer_response_info; ToResourceResponseInfo(*request_info, response_head, &renderer_response_info); - if (request_info->peer->OnReceivedRedirect( - new_url, new_first_party_for_cookies, renderer_response_info)) { + if (request_info->peer->OnReceivedRedirect(redirect_info, + renderer_response_info)) { // Double-check if the request is still around. The call above could // potentially remove it. request_info = GetPendingRequestInfo(request_id); @@ -519,7 +518,7 @@ void ResourceDispatcher::OnReceivedRedirect( return; // We update the response_url here so that we can send it to // SiteIsolationPolicy later when OnReceivedResponse is called. - request_info->response_url = new_url; + request_info->response_url = redirect_info.new_url; request_info->pending_redirect_message.reset( new ResourceHostMsg_FollowRedirect(request_id)); if (!request_info->is_deferred) { diff --git a/content/child/resource_dispatcher.h b/content/child/resource_dispatcher.h index 5fa68e9..ad1c79d 100644 --- a/content/child/resource_dispatcher.h +++ b/content/child/resource_dispatcher.h @@ -28,6 +28,10 @@ namespace blink { class WebThreadedDataReceiver; } +namespace net { +struct RedirectInfo; +} + namespace webkit_glue { class ResourceLoaderBridge; } @@ -156,8 +160,7 @@ class CONTENT_EXPORT ResourceDispatcher : public IPC::Listener { void OnReceivedResponse(int request_id, const ResourceResponseHead&); void OnReceivedCachedMetadata(int request_id, const std::vector<char>& data); void OnReceivedRedirect(int request_id, - const GURL& new_url, - const GURL& new_first_party_for_cookies, + const net::RedirectInfo& redirect_info, const ResourceResponseHead& response_head); void OnSetDataBuffer(int request_id, base::SharedMemoryHandle shm_handle, diff --git a/content/child/resource_dispatcher_unittest.cc b/content/child/resource_dispatcher_unittest.cc index 4e95428..d878e37 100644 --- a/content/child/resource_dispatcher_unittest.cc +++ b/content/child/resource_dispatcher_unittest.cc @@ -59,8 +59,7 @@ class TestRequestPeer : public RequestPeer { virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { } - virtual bool OnReceivedRedirect(const GURL& new_url, - const GURL& new_first_party_for_cookies, + virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, const ResourceResponseInfo& info) OVERRIDE { ++seen_redirects_; if (defer_on_redirect_) @@ -252,9 +251,13 @@ class ResourceDispatcherTest : public testing::Test, public IPC::Sender { std::replace(raw_headers.begin(), raw_headers.end(), '\n', '\0'); head.headers = new net::HttpResponseHeaders(raw_headers); head.error_code = net::OK; + net::RedirectInfo redirect_info; + redirect_info.status_code = 302; + redirect_info.new_method = "GET"; + redirect_info.new_url = GURL(kTestPageUrl); + redirect_info.new_first_party_for_cookies = GURL(kTestPageUrl); EXPECT_EQ(true, dispatcher_.OnMessageReceived( - ResourceMsg_ReceivedRedirect(request_id, GURL(kTestPageUrl), - GURL(kTestPageUrl), head))); + ResourceMsg_ReceivedRedirect(request_id, redirect_info, head))); } void NotifyReceivedResponse(int request_id) { @@ -722,8 +725,7 @@ class TimeConversionTest : public ResourceDispatcherTest, virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE { } - virtual bool OnReceivedRedirect(const GURL& new_url, - const GURL& new_first_party_for_cookies, + virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, const ResourceResponseInfo& info) OVERRIDE { return true; } diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc index 5aba97c..ba560b6 100644 --- a/content/child/web_url_loader_impl.cc +++ b/content/child/web_url_loader_impl.cc @@ -29,7 +29,7 @@ #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" #include "net/http/http_util.h" -#include "net/url_request/url_request.h" +#include "net/url_request/redirect_info.h" #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" #include "third_party/WebKit/public/platform/WebURL.h" @@ -223,8 +223,7 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>, // RequestPeer methods: virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; - virtual bool OnReceivedRedirect(const GURL& new_url, - const GURL& new_first_party_for_cookies, + virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, const ResourceResponseInfo& info) OVERRIDE; virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; @@ -470,8 +469,7 @@ void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { } bool WebURLLoaderImpl::Context::OnReceivedRedirect( - const GURL& new_url, - const GURL& new_first_party_for_cookies, + const net::RedirectInfo& redirect_info, const ResourceResponseInfo& info) { if (!client_) return false; @@ -482,23 +480,17 @@ bool WebURLLoaderImpl::Context::OnReceivedRedirect( // TODO(darin): We lack sufficient information to construct the actual // request that resulted from the redirect. - WebURLRequest new_request(new_url); - new_request.setFirstPartyForCookies(new_first_party_for_cookies); + WebURLRequest new_request(redirect_info.new_url); + new_request.setFirstPartyForCookies( + redirect_info.new_first_party_for_cookies); new_request.setDownloadToFile(request_.downloadToFile()); - WebString referrer_string = WebString::fromUTF8("Referer"); - WebString referrer = WebSecurityPolicy::generateReferrerHeader( - referrer_policy_, - new_url, - request_.httpHeaderField(referrer_string)); - if (!referrer.isEmpty()) - new_request.setHTTPReferrer(referrer, referrer_policy_); - - std::string method = request_.httpMethod().utf8(); - std::string new_method = net::URLRequest::ComputeMethodForRedirect( - method, response.httpStatusCode()); - new_request.setHTTPMethod(WebString::fromUTF8(new_method)); - if (new_method == method) + new_request.setHTTPReferrer(WebString::fromUTF8(redirect_info.new_referrer), + referrer_policy_); + + std::string old_method = request_.httpMethod().utf8(); + new_request.setHTTPMethod(WebString::fromUTF8(redirect_info.new_method)); + if (redirect_info.new_method == old_method) new_request.setHTTPBody(request_.httpBody()); // Protect from deletion during call to willSendRequest. @@ -508,11 +500,11 @@ bool WebURLLoaderImpl::Context::OnReceivedRedirect( request_ = new_request; // Only follow the redirect if WebKit left the URL unmodified. - if (new_url == GURL(new_request.url())) { + if (redirect_info.new_url == GURL(new_request.url())) { // First-party cookie logic moved from DocumentLoader in Blink to - // CrossSiteResourceHandler in the browser. Assert that Blink didn't try to - // change it to something else. - DCHECK_EQ(new_first_party_for_cookies.spec(), + // net::URLRequest in the browser. Assert that Blink didn't try to change it + // to something else. + DCHECK_EQ(redirect_info.new_first_party_for_cookies.spec(), request_.firstPartyForCookies().string().utf8()); return true; } diff --git a/content/child/web_url_loader_impl_unittest.cc b/content/child/web_url_loader_impl_unittest.cc index 81b6779..0adfe08 100644 --- a/content/child/web_url_loader_impl_unittest.cc +++ b/content/child/web_url_loader_impl_unittest.cc @@ -15,6 +15,7 @@ #include "net/base/net_errors.h" #include "net/http/http_response_headers.h" #include "net/http/http_util.h" +#include "net/url_request/redirect_info.h" #include "testing/gtest/include/gtest/gtest.h" #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebURLError.h" @@ -281,7 +282,12 @@ class WebURLLoaderImplTest : public testing::Test { void DoReceiveRedirect() { EXPECT_FALSE(client()->did_receive_redirect()); - peer()->OnReceivedRedirect(GURL(kTestURL), GURL(kTestURL), + net::RedirectInfo redirect_info; + redirect_info.status_code = 302; + redirect_info.new_method = "GET"; + redirect_info.new_url = GURL(kTestURL); + redirect_info.new_first_party_for_cookies = GURL(kTestURL); + peer()->OnReceivedRedirect(redirect_info, content::ResourceResponseInfo()); EXPECT_TRUE(client()->did_receive_redirect()); } |