| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. | 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. |
| 6 | 6 |
| 7 #include "content/child/web_url_loader_impl.h" | 7 #include "content/child/web_url_loader_impl.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/child/ftp_directory_listing_response_delegate.h" | 15 #include "content/child/ftp_directory_listing_response_delegate.h" |
| 16 #include "content/child/multipart_response_delegate.h" | 16 #include "content/child/multipart_response_delegate.h" |
| 17 #include "content/child/request_extra_data.h" | 17 #include "content/child/request_extra_data.h" |
| 18 #include "content/child/request_info.h" | 18 #include "content/child/request_info.h" |
| 19 #include "content/child/resource_dispatcher.h" | 19 #include "content/child/resource_dispatcher.h" |
| 20 #include "content/child/sync_load_response.h" | 20 #include "content/child/sync_load_response.h" |
| 21 #include "content/common/resource_request_body.h" | 21 #include "content/common/resource_request_body.h" |
| 22 #include "content/public/child/request_peer.h" | 22 #include "content/public/child/request_peer.h" |
| 23 #include "net/base/data_url.h" | 23 #include "net/base/data_url.h" |
| 24 #include "net/base/filename_util.h" | 24 #include "net/base/filename_util.h" |
| 25 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
| 26 #include "net/base/mime_util.h" | 26 #include "net/base/mime_util.h" |
| 27 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
| 28 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
| 29 #include "net/http/http_util.h" | 29 #include "net/http/http_util.h" |
| 30 #include "net/url_request/url_request.h" | 30 #include "net/url_request/redirect_info.h" |
| 31 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | 31 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
| 32 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" | 32 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" |
| 33 #include "third_party/WebKit/public/platform/WebURL.h" | 33 #include "third_party/WebKit/public/platform/WebURL.h" |
| 34 #include "third_party/WebKit/public/platform/WebURLError.h" | 34 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 35 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" | 35 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" |
| 36 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | 36 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" |
| 37 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 37 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 38 #include "third_party/WebKit/public/platform/WebURLResponse.h" | 38 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 39 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 39 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 40 #include "webkit/child/resource_loader_bridge.h" | 40 #include "webkit/child/resource_loader_bridge.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 void SetDefersLoading(bool value); | 216 void SetDefersLoading(bool value); |
| 217 void DidChangePriority(WebURLRequest::Priority new_priority, | 217 void DidChangePriority(WebURLRequest::Priority new_priority, |
| 218 int intra_priority_value); | 218 int intra_priority_value); |
| 219 bool AttachThreadedDataReceiver( | 219 bool AttachThreadedDataReceiver( |
| 220 blink::WebThreadedDataReceiver* threaded_data_receiver); | 220 blink::WebThreadedDataReceiver* threaded_data_receiver); |
| 221 void Start(const WebURLRequest& request, | 221 void Start(const WebURLRequest& request, |
| 222 SyncLoadResponse* sync_load_response); | 222 SyncLoadResponse* sync_load_response); |
| 223 | 223 |
| 224 // RequestPeer methods: | 224 // RequestPeer methods: |
| 225 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; | 225 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; |
| 226 virtual bool OnReceivedRedirect(const GURL& new_url, | 226 virtual bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, |
| 227 const GURL& new_first_party_for_cookies, | |
| 228 const ResourceResponseInfo& info) OVERRIDE; | 227 const ResourceResponseInfo& info) OVERRIDE; |
| 229 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; | 228 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; |
| 230 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; | 229 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; |
| 231 virtual void OnReceivedData(const char* data, | 230 virtual void OnReceivedData(const char* data, |
| 232 int data_length, | 231 int data_length, |
| 233 int encoded_data_length) OVERRIDE; | 232 int encoded_data_length) OVERRIDE; |
| 234 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; | 233 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; |
| 235 virtual void OnCompletedRequest( | 234 virtual void OnCompletedRequest( |
| 236 int error_code, | 235 int error_code, |
| 237 bool was_ignored_by_handler, | 236 bool was_ignored_by_handler, |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 if (!bridge_->Start(this)) | 462 if (!bridge_->Start(this)) |
| 464 bridge_.reset(); | 463 bridge_.reset(); |
| 465 } | 464 } |
| 466 | 465 |
| 467 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { | 466 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { |
| 468 if (client_) | 467 if (client_) |
| 469 client_->didSendData(loader_, position, size); | 468 client_->didSendData(loader_, position, size); |
| 470 } | 469 } |
| 471 | 470 |
| 472 bool WebURLLoaderImpl::Context::OnReceivedRedirect( | 471 bool WebURLLoaderImpl::Context::OnReceivedRedirect( |
| 473 const GURL& new_url, | 472 const net::RedirectInfo& redirect_info, |
| 474 const GURL& new_first_party_for_cookies, | |
| 475 const ResourceResponseInfo& info) { | 473 const ResourceResponseInfo& info) { |
| 476 if (!client_) | 474 if (!client_) |
| 477 return false; | 475 return false; |
| 478 | 476 |
| 479 WebURLResponse response; | 477 WebURLResponse response; |
| 480 response.initialize(); | 478 response.initialize(); |
| 481 PopulateURLResponse(request_.url(), info, &response); | 479 PopulateURLResponse(request_.url(), info, &response); |
| 482 | 480 |
| 483 // TODO(darin): We lack sufficient information to construct the actual | 481 // TODO(darin): We lack sufficient information to construct the actual |
| 484 // request that resulted from the redirect. | 482 // request that resulted from the redirect. |
| 485 WebURLRequest new_request(new_url); | 483 WebURLRequest new_request(redirect_info.new_url); |
| 486 new_request.setFirstPartyForCookies(new_first_party_for_cookies); | 484 new_request.setFirstPartyForCookies( |
| 485 redirect_info.new_first_party_for_cookies); |
| 487 new_request.setDownloadToFile(request_.downloadToFile()); | 486 new_request.setDownloadToFile(request_.downloadToFile()); |
| 488 | 487 |
| 489 WebString referrer_string = WebString::fromUTF8("Referer"); | 488 new_request.setHTTPReferrer(WebString::fromUTF8(redirect_info.new_referrer), |
| 490 WebString referrer = WebSecurityPolicy::generateReferrerHeader( | 489 referrer_policy_); |
| 491 referrer_policy_, | |
| 492 new_url, | |
| 493 request_.httpHeaderField(referrer_string)); | |
| 494 if (!referrer.isEmpty()) | |
| 495 new_request.setHTTPReferrer(referrer, referrer_policy_); | |
| 496 | 490 |
| 497 std::string method = request_.httpMethod().utf8(); | 491 std::string old_method = request_.httpMethod().utf8(); |
| 498 std::string new_method = net::URLRequest::ComputeMethodForRedirect( | 492 new_request.setHTTPMethod(WebString::fromUTF8(redirect_info.new_method)); |
| 499 method, response.httpStatusCode()); | 493 if (redirect_info.new_method == old_method) |
| 500 new_request.setHTTPMethod(WebString::fromUTF8(new_method)); | |
| 501 if (new_method == method) | |
| 502 new_request.setHTTPBody(request_.httpBody()); | 494 new_request.setHTTPBody(request_.httpBody()); |
| 503 | 495 |
| 504 // Protect from deletion during call to willSendRequest. | 496 // Protect from deletion during call to willSendRequest. |
| 505 scoped_refptr<Context> protect(this); | 497 scoped_refptr<Context> protect(this); |
| 506 | 498 |
| 507 client_->willSendRequest(loader_, new_request, response); | 499 client_->willSendRequest(loader_, new_request, response); |
| 508 request_ = new_request; | 500 request_ = new_request; |
| 509 | 501 |
| 510 // Only follow the redirect if WebKit left the URL unmodified. | 502 // Only follow the redirect if WebKit left the URL unmodified. |
| 511 if (new_url == GURL(new_request.url())) { | 503 if (redirect_info.new_url == GURL(new_request.url())) { |
| 512 // First-party cookie logic moved from DocumentLoader in Blink to | 504 // First-party cookie logic moved from DocumentLoader in Blink to |
| 513 // CrossSiteResourceHandler in the browser. Assert that Blink didn't try to | 505 // net::URLRequest in the browser. Assert that Blink didn't try to change it |
| 514 // change it to something else. | 506 // to something else. |
| 515 DCHECK_EQ(new_first_party_for_cookies.spec(), | 507 DCHECK_EQ(redirect_info.new_first_party_for_cookies.spec(), |
| 516 request_.firstPartyForCookies().string().utf8()); | 508 request_.firstPartyForCookies().string().utf8()); |
| 517 return true; | 509 return true; |
| 518 } | 510 } |
| 519 | 511 |
| 520 // We assume that WebKit only changes the URL to suppress a redirect, and we | 512 // We assume that WebKit only changes the URL to suppress a redirect, and we |
| 521 // assume that it does so by setting it to be invalid. | 513 // assume that it does so by setting it to be invalid. |
| 522 DCHECK(!new_request.url().isValid()); | 514 DCHECK(!new_request.url().isValid()); |
| 523 return false; | 515 return false; |
| 524 } | 516 } |
| 525 | 517 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 int intra_priority_value) { | 879 int intra_priority_value) { |
| 888 context_->DidChangePriority(new_priority, intra_priority_value); | 880 context_->DidChangePriority(new_priority, intra_priority_value); |
| 889 } | 881 } |
| 890 | 882 |
| 891 bool WebURLLoaderImpl::attachThreadedDataReceiver( | 883 bool WebURLLoaderImpl::attachThreadedDataReceiver( |
| 892 blink::WebThreadedDataReceiver* threaded_data_receiver) { | 884 blink::WebThreadedDataReceiver* threaded_data_receiver) { |
| 893 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 885 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
| 894 } | 886 } |
| 895 | 887 |
| 896 } // namespace content | 888 } // namespace content |
| OLD | NEW |