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

Side by Side Diff: content/browser/loader/resource_loader.cc

Issue 1905033002: PlzNavigate: Move navigation-level mixed content checks to the browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@console-security-message
Patch Set: Fixed external handling order change for request start and redirects. Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/browser/loader/resource_loader.h" 5 #include "content/browser/loader/resource_loader.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (login_delegate_.get()) 156 if (login_delegate_.get())
157 login_delegate_->OnRequestCancelled(); 157 login_delegate_->OnRequestCancelled();
158 ssl_client_auth_handler_.reset(); 158 ssl_client_auth_handler_.reset();
159 159
160 // Run ResourceHandler destructor before we tear-down the rest of our state 160 // Run ResourceHandler destructor before we tear-down the rest of our state
161 // as the ResourceHandler may want to inspect the URLRequest and other state. 161 // as the ResourceHandler may want to inspect the URLRequest and other state.
162 handler_.reset(); 162 handler_.reset();
163 } 163 }
164 164
165 void ResourceLoader::StartRequest() { 165 void ResourceLoader::StartRequest() {
166 if (delegate_->HandleExternalProtocol(this, request_->url())) {
167 CancelAndIgnore();
168 return;
169 }
170
171 // Give the handler a chance to delay the URLRequest from being started. 166 // Give the handler a chance to delay the URLRequest from being started.
172 bool defer_start = false; 167 bool defer_start = false;
173 if (!handler_->OnWillStart(request_->url(), &defer_start)) { 168 if (!handler_->OnWillStart(request_->url(), &defer_start)) {
174 Cancel(); 169 Cancel();
175 return; 170 return;
176 } 171 }
177 172
178 TRACE_EVENT_WITH_FLOW0("loading", "ResourceLoader::StartRequest", this, 173 TRACE_EVENT_WITH_FLOW0("loading", "ResourceLoader::StartRequest", this,
179 TRACE_EVENT_FLAG_FLOW_OUT); 174 TRACE_EVENT_FLAG_FLOW_OUT);
180 if (defer_start) { 175 if (defer_start) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 DVLOG(1) << "Denied unauthorized request for " 263 DVLOG(1) << "Denied unauthorized request for "
269 << redirect_info.new_url.possibly_invalid_spec(); 264 << redirect_info.new_url.possibly_invalid_spec();
270 265
271 // Tell the renderer that this request was disallowed. 266 // Tell the renderer that this request was disallowed.
272 Cancel(); 267 Cancel();
273 return; 268 return;
274 } 269 }
275 270
276 delegate_->DidReceiveRedirect(this, redirect_info.new_url); 271 delegate_->DidReceiveRedirect(this, redirect_info.new_url);
277 272
278 if (delegate_->HandleExternalProtocol(this, redirect_info.new_url)) {
279 // The request is complete so we can remove it.
280 CancelAndIgnore();
281 return;
282 }
283
284 scoped_refptr<ResourceResponse> response = new ResourceResponse(); 273 scoped_refptr<ResourceResponse> response = new ResourceResponse();
285 PopulateResourceResponse(info, request_.get(), cert_store_, response.get()); 274 PopulateResourceResponse(info, request_.get(), cert_store_, response.get());
286 if (!handler_->OnRequestRedirected(redirect_info, response.get(), defer)) { 275 if (!handler_->OnRequestRedirected(redirect_info, response.get(), defer)) {
287 Cancel(); 276 Cancel();
288 } else if (*defer) { 277 } else if (*defer) {
289 deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed. 278 deferred_stage_ = DEFERRED_REDIRECT; // Follow redirect when resumed.
290 } 279 }
291 } 280 }
292 281
293 void ResourceLoader::OnAuthRequired(net::URLRequest* unused, 282 void ResourceLoader::OnAuthRequired(net::URLRequest* unused,
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 case DEFERRED_NONE: 439 case DEFERRED_NONE:
451 NOTREACHED(); 440 NOTREACHED();
452 break; 441 break;
453 case DEFERRED_START: 442 case DEFERRED_START:
454 StartRequestInternal(); 443 StartRequestInternal();
455 break; 444 break;
456 case DEFERRED_NETWORK_START: 445 case DEFERRED_NETWORK_START:
457 request_->ResumeNetworkStart(); 446 request_->ResumeNetworkStart();
458 break; 447 break;
459 case DEFERRED_REDIRECT: 448 case DEFERRED_REDIRECT:
460 request_->FollowDeferredRedirect(); 449 FollowDeferredRedirectInternal();
461 break; 450 break;
462 case DEFERRED_READ: 451 case DEFERRED_READ:
463 base::ThreadTaskRunnerHandle::Get()->PostTask( 452 base::ThreadTaskRunnerHandle::Get()->PostTask(
464 FROM_HERE, base::Bind(&ResourceLoader::ResumeReading, 453 FROM_HERE, base::Bind(&ResourceLoader::ResumeReading,
465 weak_ptr_factory_.GetWeakPtr())); 454 weak_ptr_factory_.GetWeakPtr()));
466 break; 455 break;
467 case DEFERRED_RESPONSE_COMPLETE: 456 case DEFERRED_RESPONSE_COMPLETE:
468 base::ThreadTaskRunnerHandle::Get()->PostTask( 457 base::ThreadTaskRunnerHandle::Get()->PostTask(
469 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, 458 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted,
470 weak_ptr_factory_.GetWeakPtr())); 459 weak_ptr_factory_.GetWeakPtr()));
471 break; 460 break;
472 case DEFERRED_FINISH: 461 case DEFERRED_FINISH:
473 // Delay self-destruction since we don't know how we were reached. 462 // Delay self-destruction since we don't know how we were reached.
474 base::ThreadTaskRunnerHandle::Get()->PostTask( 463 base::ThreadTaskRunnerHandle::Get()->PostTask(
475 FROM_HERE, base::Bind(&ResourceLoader::CallDidFinishLoading, 464 FROM_HERE, base::Bind(&ResourceLoader::CallDidFinishLoading,
476 weak_ptr_factory_.GetWeakPtr())); 465 weak_ptr_factory_.GetWeakPtr()));
477 break; 466 break;
478 } 467 }
479 } 468 }
480 469
481 void ResourceLoader::Cancel() { 470 void ResourceLoader::Cancel() {
482 CancelRequest(false); 471 CancelRequest(false);
483 } 472 }
484 473
485 void ResourceLoader::StartRequestInternal() { 474 void ResourceLoader::StartRequestInternal() {
475 // At this point any possible deferred start is already over.
486 DCHECK(!request_->is_pending()); 476 DCHECK(!request_->is_pending());
487 477
478 if (delegate_->HandleExternalProtocol(this, request_->url())) {
479 CancelAndIgnore();
480 return;
481 }
482
488 if (!request_->status().is_success()) { 483 if (!request_->status().is_success()) {
489 return; 484 return;
490 } 485 }
491 486
492 started_request_ = true; 487 started_request_ = true;
493 request_->Start(); 488 request_->Start();
494 489
495 delegate_->DidStartRequest(this); 490 delegate_->DidStartRequest(this);
496 } 491 }
497 492
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 if (!was_pending) { 529 if (!was_pending) {
535 // If the request isn't in flight, then we won't get an asynchronous 530 // If the request isn't in flight, then we won't get an asynchronous
536 // notification from the request, so we have to signal ourselves to finish 531 // notification from the request, so we have to signal ourselves to finish
537 // this request. 532 // this request.
538 base::ThreadTaskRunnerHandle::Get()->PostTask( 533 base::ThreadTaskRunnerHandle::Get()->PostTask(
539 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted, 534 FROM_HERE, base::Bind(&ResourceLoader::ResponseCompleted,
540 weak_ptr_factory_.GetWeakPtr())); 535 weak_ptr_factory_.GetWeakPtr()));
541 } 536 }
542 } 537 }
543 538
539 void ResourceLoader::FollowDeferredRedirectInternal() {
540 const GURL& new_url = request_->GetDeferredRedirectUrl();
541 if (delegate_->HandleExternalProtocol(this, new_url)) {
542 // The request is complete so we can remove it.
543 CancelAndIgnore();
544 return;
545 }
546
547 request_->FollowDeferredRedirect();
548 }
549
544 void ResourceLoader::CompleteResponseStarted() { 550 void ResourceLoader::CompleteResponseStarted() {
545 ResourceRequestInfoImpl* info = GetRequestInfo(); 551 ResourceRequestInfoImpl* info = GetRequestInfo();
546 scoped_refptr<ResourceResponse> response = new ResourceResponse(); 552 scoped_refptr<ResourceResponse> response = new ResourceResponse();
547 PopulateResourceResponse(info, request_.get(), cert_store_, response.get()); 553 PopulateResourceResponse(info, request_.get(), cert_store_, response.get());
548 554
549 delegate_->DidReceiveResponse(this); 555 delegate_->DidReceiveResponse(this);
550 556
551 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed. 557 // TODO(darin): Remove ScopedTracker below once crbug.com/475761 is fixed.
552 tracked_objects::ScopedTracker tracking_profile( 558 tracked_objects::ScopedTracker tracking_profile(
553 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()")); 559 FROM_HERE_WITH_EXPLICIT_FUNCTION("475761 OnResponseStarted()"));
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 } 741 }
736 742
737 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX); 743 UMA_HISTOGRAM_ENUMERATION("Net.Prefetch.Pattern", status, STATUS_MAX);
738 } else if (request_->response_info().unused_since_prefetch) { 744 } else if (request_->response_info().unused_since_prefetch) {
739 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time(); 745 TimeDelta total_time = base::TimeTicks::Now() - request_->creation_time();
740 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time); 746 UMA_HISTOGRAM_TIMES("Net.Prefetch.TimeSpentOnPrefetchHit", total_time);
741 } 747 }
742 } 748 }
743 749
744 } // namespace content 750 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698