Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Side by Side Diff: content/child/web_url_loader_impl.cc

Issue 264613006: Move first-party cookie URL logic to browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DCHECK. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 231
232 void Cancel(); 232 void Cancel();
233 void SetDefersLoading(bool value); 233 void SetDefersLoading(bool value);
234 void DidChangePriority(WebURLRequest::Priority new_priority, 234 void DidChangePriority(WebURLRequest::Priority new_priority,
235 int intra_priority_value); 235 int intra_priority_value);
236 void Start(const WebURLRequest& request, 236 void Start(const WebURLRequest& request,
237 SyncLoadResponse* sync_load_response); 237 SyncLoadResponse* sync_load_response);
238 238
239 // RequestPeer methods: 239 // RequestPeer methods:
240 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; 240 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE;
241 virtual bool OnReceivedRedirect( 241 virtual bool OnReceivedRedirect(const GURL& new_url,
242 const GURL& new_url, 242 const GURL& new_first_party_for_cookies,
243 const ResourceResponseInfo& info, 243 const ResourceResponseInfo& info) OVERRIDE;
244 bool* has_new_first_party_for_cookies,
245 GURL* new_first_party_for_cookies) OVERRIDE;
246 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; 244 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE;
247 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; 245 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE;
248 virtual void OnReceivedData(const char* data, 246 virtual void OnReceivedData(const char* data,
249 int data_length, 247 int data_length,
250 int encoded_data_length) OVERRIDE; 248 int encoded_data_length) OVERRIDE;
251 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; 249 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE;
252 virtual void OnCompletedRequest( 250 virtual void OnCompletedRequest(
253 int error_code, 251 int error_code,
254 bool was_ignored_by_handler, 252 bool was_ignored_by_handler,
255 bool stale_copy_in_cache, 253 bool stale_copy_in_cache,
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 463 }
466 } 464 }
467 465
468 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { 466 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) {
469 if (client_) 467 if (client_)
470 client_->didSendData(loader_, position, size); 468 client_->didSendData(loader_, position, size);
471 } 469 }
472 470
473 bool WebURLLoaderImpl::Context::OnReceivedRedirect( 471 bool WebURLLoaderImpl::Context::OnReceivedRedirect(
474 const GURL& new_url, 472 const GURL& new_url,
475 const ResourceResponseInfo& info, 473 const GURL& new_first_party_for_cookies,
476 bool* has_new_first_party_for_cookies, 474 const ResourceResponseInfo& info) {
477 GURL* new_first_party_for_cookies) {
478 if (!client_) 475 if (!client_)
479 return false; 476 return false;
480 477
481 WebURLResponse response; 478 WebURLResponse response;
482 response.initialize(); 479 response.initialize();
483 PopulateURLResponse(request_.url(), info, &response); 480 PopulateURLResponse(request_.url(), info, &response);
484 481
485 // TODO(darin): We lack sufficient information to construct the actual 482 // TODO(darin): We lack sufficient information to construct the actual
486 // request that resulted from the redirect. 483 // request that resulted from the redirect.
487 WebURLRequest new_request(new_url); 484 WebURLRequest new_request(new_url);
488 new_request.setFirstPartyForCookies(request_.firstPartyForCookies()); 485 new_request.setFirstPartyForCookies(new_first_party_for_cookies);
489 new_request.setDownloadToFile(request_.downloadToFile()); 486 new_request.setDownloadToFile(request_.downloadToFile());
490 487
491 WebString referrer_string = WebString::fromUTF8("Referer"); 488 WebString referrer_string = WebString::fromUTF8("Referer");
492 WebString referrer = WebSecurityPolicy::generateReferrerHeader( 489 WebString referrer = WebSecurityPolicy::generateReferrerHeader(
493 referrer_policy_, 490 referrer_policy_,
494 new_url, 491 new_url,
495 request_.httpHeaderField(referrer_string)); 492 request_.httpHeaderField(referrer_string));
496 if (!referrer.isEmpty()) 493 if (!referrer.isEmpty())
497 new_request.setHTTPReferrer(referrer, referrer_policy_); 494 new_request.setHTTPReferrer(referrer, referrer_policy_);
498 495
499 std::string method = request_.httpMethod().utf8(); 496 std::string method = request_.httpMethod().utf8();
500 std::string new_method = net::URLRequest::ComputeMethodForRedirect( 497 std::string new_method = net::URLRequest::ComputeMethodForRedirect(
501 method, response.httpStatusCode()); 498 method, response.httpStatusCode());
502 new_request.setHTTPMethod(WebString::fromUTF8(new_method)); 499 new_request.setHTTPMethod(WebString::fromUTF8(new_method));
503 if (new_method == method) 500 if (new_method == method)
504 new_request.setHTTPBody(request_.httpBody()); 501 new_request.setHTTPBody(request_.httpBody());
505 502
506 client_->willSendRequest(loader_, new_request, response); 503 client_->willSendRequest(loader_, new_request, response);
507 request_ = new_request; 504 request_ = new_request;
508 *has_new_first_party_for_cookies = true; 505
509 *new_first_party_for_cookies = request_.firstPartyForCookies(); 506 // First-party cookie logic moved from DocumentLoader in Blink to
507 // CrossSiteResourceHandler in the browser. Assert that Blink didn't try to
508 // change it to something else.
509 DCHECK_EQ(new_first_party_for_cookies.spec(),
510 request_.firstPartyForCookies().string().utf8());
davidben 2014/05/09 22:08:04 Had to move this to the conditional below. Turns o
510 511
511 // Only follow the redirect if WebKit left the URL unmodified. 512 // Only follow the redirect if WebKit left the URL unmodified.
512 if (new_url == GURL(new_request.url())) 513 if (new_url == GURL(new_request.url()))
513 return true; 514 return true;
514 515
515 // We assume that WebKit only changes the URL to suppress a redirect, and we 516 // We assume that WebKit only changes the URL to suppress a redirect, and we
516 // assume that it does so by setting it to be invalid. 517 // assume that it does so by setting it to be invalid.
517 DCHECK(!new_request.url().isValid()); 518 DCHECK(!new_request.url().isValid());
518 return false; 519 return false;
519 } 520 }
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 void WebURLLoaderImpl::setDefersLoading(bool value) { 868 void WebURLLoaderImpl::setDefersLoading(bool value) {
868 context_->SetDefersLoading(value); 869 context_->SetDefersLoading(value);
869 } 870 }
870 871
871 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, 872 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority,
872 int intra_priority_value) { 873 int intra_priority_value) {
873 context_->DidChangePriority(new_priority, intra_priority_value); 874 context_->DidChangePriority(new_priority, intra_priority_value);
874 } 875 }
875 876
876 } // namespace content 877 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698