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" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 void Cancel(); | 233 void Cancel(); |
234 void SetDefersLoading(bool value); | 234 void SetDefersLoading(bool value); |
235 void DidChangePriority(WebURLRequest::Priority new_priority, | 235 void DidChangePriority(WebURLRequest::Priority new_priority, |
236 int intra_priority_value); | 236 int intra_priority_value); |
237 void Start(const WebURLRequest& request, | 237 void Start(const WebURLRequest& request, |
238 SyncLoadResponse* sync_load_response); | 238 SyncLoadResponse* sync_load_response); |
239 | 239 |
240 // RequestPeer methods: | 240 // RequestPeer methods: |
241 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; | 241 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; |
242 virtual bool OnReceivedRedirect( | 242 virtual bool OnReceivedRedirect(const GURL& new_url, |
243 const GURL& new_url, | 243 const GURL& new_first_party_for_cookies, |
244 const ResourceResponseInfo& info, | 244 const ResourceResponseInfo& info) OVERRIDE; |
245 bool* has_new_first_party_for_cookies, | |
246 GURL* new_first_party_for_cookies) OVERRIDE; | |
247 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; | 245 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; |
248 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; | 246 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; |
249 virtual void OnReceivedData(const char* data, | 247 virtual void OnReceivedData(const char* data, |
250 int data_length, | 248 int data_length, |
251 int encoded_data_length) OVERRIDE; | 249 int encoded_data_length) OVERRIDE; |
252 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; | 250 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; |
253 virtual void OnCompletedRequest( | 251 virtual void OnCompletedRequest( |
254 int error_code, | 252 int error_code, |
255 bool was_ignored_by_handler, | 253 bool was_ignored_by_handler, |
256 bool stale_copy_in_cache, | 254 bool stale_copy_in_cache, |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 } | 465 } |
468 } | 466 } |
469 | 467 |
470 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { | 468 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { |
471 if (client_) | 469 if (client_) |
472 client_->didSendData(loader_, position, size); | 470 client_->didSendData(loader_, position, size); |
473 } | 471 } |
474 | 472 |
475 bool WebURLLoaderImpl::Context::OnReceivedRedirect( | 473 bool WebURLLoaderImpl::Context::OnReceivedRedirect( |
476 const GURL& new_url, | 474 const GURL& new_url, |
477 const ResourceResponseInfo& info, | 475 const GURL& new_first_party_for_cookies, |
478 bool* has_new_first_party_for_cookies, | 476 const ResourceResponseInfo& info) { |
479 GURL* new_first_party_for_cookies) { | |
480 if (!client_) | 477 if (!client_) |
481 return false; | 478 return false; |
482 | 479 |
483 WebURLResponse response; | 480 WebURLResponse response; |
484 response.initialize(); | 481 response.initialize(); |
485 PopulateURLResponse(request_.url(), info, &response); | 482 PopulateURLResponse(request_.url(), info, &response); |
486 | 483 |
487 // TODO(darin): We lack sufficient information to construct the actual | 484 // TODO(darin): We lack sufficient information to construct the actual |
488 // request that resulted from the redirect. | 485 // request that resulted from the redirect. |
489 WebURLRequest new_request(new_url); | 486 WebURLRequest new_request(new_url); |
490 new_request.setFirstPartyForCookies(request_.firstPartyForCookies()); | 487 new_request.setFirstPartyForCookies(new_first_party_for_cookies); |
491 new_request.setDownloadToFile(request_.downloadToFile()); | 488 new_request.setDownloadToFile(request_.downloadToFile()); |
492 | 489 |
493 WebString referrer_string = WebString::fromUTF8("Referer"); | 490 WebString referrer_string = WebString::fromUTF8("Referer"); |
494 WebString referrer = WebSecurityPolicy::generateReferrerHeader( | 491 WebString referrer = WebSecurityPolicy::generateReferrerHeader( |
495 referrer_policy_, | 492 referrer_policy_, |
496 new_url, | 493 new_url, |
497 request_.httpHeaderField(referrer_string)); | 494 request_.httpHeaderField(referrer_string)); |
498 if (!referrer.isEmpty()) | 495 if (!referrer.isEmpty()) |
499 new_request.setHTTPReferrer(referrer, referrer_policy_); | 496 new_request.setHTTPReferrer(referrer, referrer_policy_); |
500 | 497 |
501 std::string method = request_.httpMethod().utf8(); | 498 std::string method = request_.httpMethod().utf8(); |
502 std::string new_method = net::URLRequest::ComputeMethodForRedirect( | 499 std::string new_method = net::URLRequest::ComputeMethodForRedirect( |
503 method, response.httpStatusCode()); | 500 method, response.httpStatusCode()); |
504 new_request.setHTTPMethod(WebString::fromUTF8(new_method)); | 501 new_request.setHTTPMethod(WebString::fromUTF8(new_method)); |
505 if (new_method == method) | 502 if (new_method == method) |
506 new_request.setHTTPBody(request_.httpBody()); | 503 new_request.setHTTPBody(request_.httpBody()); |
507 | 504 |
508 client_->willSendRequest(loader_, new_request, response); | 505 client_->willSendRequest(loader_, new_request, response); |
509 request_ = new_request; | 506 request_ = new_request; |
510 *has_new_first_party_for_cookies = true; | |
511 *new_first_party_for_cookies = request_.firstPartyForCookies(); | |
512 | 507 |
513 // Only follow the redirect if WebKit left the URL unmodified. | 508 // Only follow the redirect if WebKit left the URL unmodified. |
514 if (new_url == GURL(new_request.url())) | 509 if (new_url == GURL(new_request.url())) { |
| 510 // First-party cookie logic moved from DocumentLoader in Blink to |
| 511 // CrossSiteResourceHandler in the browser. Assert that Blink didn't try to |
| 512 // change it to something else. |
| 513 DCHECK_EQ(new_first_party_for_cookies.spec(), |
| 514 request_.firstPartyForCookies().string().utf8()); |
515 return true; | 515 return true; |
| 516 } |
516 | 517 |
517 // We assume that WebKit only changes the URL to suppress a redirect, and we | 518 // We assume that WebKit only changes the URL to suppress a redirect, and we |
518 // assume that it does so by setting it to be invalid. | 519 // assume that it does so by setting it to be invalid. |
519 DCHECK(!new_request.url().isValid()); | 520 DCHECK(!new_request.url().isValid()); |
520 return false; | 521 return false; |
521 } | 522 } |
522 | 523 |
523 void WebURLLoaderImpl::Context::OnReceivedResponse( | 524 void WebURLLoaderImpl::Context::OnReceivedResponse( |
524 const ResourceResponseInfo& info) { | 525 const ResourceResponseInfo& info) { |
525 if (!client_) | 526 if (!client_) |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 void WebURLLoaderImpl::setDefersLoading(bool value) { | 870 void WebURLLoaderImpl::setDefersLoading(bool value) { |
870 context_->SetDefersLoading(value); | 871 context_->SetDefersLoading(value); |
871 } | 872 } |
872 | 873 |
873 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, | 874 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, |
874 int intra_priority_value) { | 875 int intra_priority_value) { |
875 context_->DidChangePriority(new_priority, intra_priority_value); | 876 context_->DidChangePriority(new_priority, intra_priority_value); |
876 } | 877 } |
877 | 878 |
878 } // namespace content | 879 } // namespace content |
OLD | NEW |