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

Side by Side Diff: content/browser/frame_host/navigation_request.cc

Issue 2549373004: PlzNavigate: Call NavigationHandle::WillProcessResponse for 204/205s (Closed)
Patch Set: Fixed test issue Created 4 years 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 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 #include "content/browser/frame_host/navigation_request.h" 5 #include "content/browser/frame_host/navigation_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "content/browser/appcache/appcache_navigation_handle.h" 9 #include "content/browser/appcache/appcache_navigation_handle.h"
10 #include "content/browser/appcache/chrome_appcache_service.h" 10 #include "content/browser/appcache/chrome_appcache_service.h"
(...skipping 20 matching lines...) Expand all
31 #include "content/public/browser/navigation_data.h" 31 #include "content/public/browser/navigation_data.h"
32 #include "content/public/browser/navigation_ui_data.h" 32 #include "content/public/browser/navigation_ui_data.h"
33 #include "content/public/browser/storage_partition.h" 33 #include "content/public/browser/storage_partition.h"
34 #include "content/public/browser/stream_handle.h" 34 #include "content/public/browser/stream_handle.h"
35 #include "content/public/common/appcache_info.h" 35 #include "content/public/common/appcache_info.h"
36 #include "content/public/common/content_client.h" 36 #include "content/public/common/content_client.h"
37 #include "content/public/common/request_context_type.h" 37 #include "content/public/common/request_context_type.h"
38 #include "content/public/common/resource_response.h" 38 #include "content/public/common/resource_response.h"
39 #include "content/public/common/url_constants.h" 39 #include "content/public/common/url_constants.h"
40 #include "net/base/load_flags.h" 40 #include "net/base/load_flags.h"
41 #include "net/base/net_errors.h"
41 #include "net/base/url_util.h" 42 #include "net/base/url_util.h"
42 #include "net/http/http_request_headers.h" 43 #include "net/http/http_request_headers.h"
43 #include "net/url_request/redirect_info.h" 44 #include "net/url_request/redirect_info.h"
44 #include "third_party/WebKit/public/web/WebSandboxFlags.h" 45 #include "third_party/WebKit/public/web/WebSandboxFlags.h"
45 46
46 namespace content { 47 namespace content {
47 48
48 namespace { 49 namespace {
49 50
50 // Returns the net load flags to use based on the navigation type. 51 // Returns the net load flags to use based on the navigation type.
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 const NavigationEntryImpl* entry) 276 const NavigationEntryImpl* entry)
276 : frame_tree_node_(frame_tree_node), 277 : frame_tree_node_(frame_tree_node),
277 common_params_(common_params), 278 common_params_(common_params),
278 begin_params_(begin_params), 279 begin_params_(begin_params),
279 request_params_(request_params), 280 request_params_(request_params),
280 browser_initiated_(browser_initiated), 281 browser_initiated_(browser_initiated),
281 state_(NOT_STARTED), 282 state_(NOT_STARTED),
282 restore_type_(RestoreType::NONE), 283 restore_type_(RestoreType::NONE),
283 is_view_source_(false), 284 is_view_source_(false),
284 bindings_(NavigationEntryImpl::kInvalidBindings), 285 bindings_(NavigationEntryImpl::kInvalidBindings),
286 response_should_be_rendered_(true),
285 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { 287 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) {
286 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); 288 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr));
287 if (browser_initiated) { 289 if (browser_initiated) {
288 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); 290 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node);
289 if (frame_entry) { 291 if (frame_entry) {
290 source_site_instance_ = frame_entry->source_site_instance(); 292 source_site_instance_ = frame_entry->source_site_instance();
291 dest_site_instance_ = frame_entry->site_instance(); 293 dest_site_instance_ = frame_entry->site_instance();
292 } 294 }
293 295
294 restore_type_ = entry->restore_type(); 296 restore_type_ = entry->restore_type();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 430
429 void NavigationRequest::OnResponseStarted( 431 void NavigationRequest::OnResponseStarted(
430 const scoped_refptr<ResourceResponse>& response, 432 const scoped_refptr<ResourceResponse>& response,
431 std::unique_ptr<StreamHandle> body, 433 std::unique_ptr<StreamHandle> body,
432 const SSLStatus& ssl_status, 434 const SSLStatus& ssl_status,
433 std::unique_ptr<NavigationData> navigation_data, 435 std::unique_ptr<NavigationData> navigation_data,
434 const GlobalRequestID& request_id, 436 const GlobalRequestID& request_id,
435 bool is_download, 437 bool is_download,
436 bool is_stream) { 438 bool is_stream) {
437 DCHECK(state_ == STARTED); 439 DCHECK(state_ == STARTED);
440 DCHECK(response);
438 state_ = RESPONSE_STARTED; 441 state_ = RESPONSE_STARTED;
439 442
440 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not 443 // Check if the response should be sent to a renderer.
441 // commit; they leave the frame showing the previous page. 444 response_should_be_rendered_ =
442 DCHECK(response); 445 !is_download && (!response->head.headers.get() ||
443 if (response->head.headers.get() && 446 (response->head.headers->response_code() != 204 &&
444 (response->head.headers->response_code() == 204 || 447 response->head.headers->response_code() != 205));
445 response->head.headers->response_code() == 205)) { 448
446 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( 449 // Response that will not commit should be marked as aborted in the
447 navigation_handle_.get()); 450 // NavigationHandle.
448 frame_tree_node_->ResetNavigationRequest(false); 451 if (!response_should_be_rendered_)
449 return; 452 navigation_handle_->set_net_error_code(net::ERR_ABORTED);
450 }
451 453
452 // Update the service worker params of the request params. 454 // Update the service worker params of the request params.
453 bool did_create_service_worker_host = 455 bool did_create_service_worker_host =
454 navigation_handle_->service_worker_handle() && 456 navigation_handle_->service_worker_handle() &&
455 navigation_handle_->service_worker_handle() 457 navigation_handle_->service_worker_handle()
456 ->service_worker_provider_host_id() != 458 ->service_worker_provider_host_id() !=
457 kInvalidServiceWorkerProviderId; 459 kInvalidServiceWorkerProviderId;
458 request_params_.service_worker_provider_id = 460 request_params_.service_worker_provider_id =
459 did_create_service_worker_host 461 did_create_service_worker_host
460 ? navigation_handle_->service_worker_handle() 462 ? navigation_handle_->service_worker_handle()
461 ->service_worker_provider_host_id() 463 ->service_worker_provider_host_id()
462 : kInvalidServiceWorkerProviderId; 464 : kInvalidServiceWorkerProviderId;
463 465
464 request_params_.appcache_host_id = 466 request_params_.appcache_host_id =
465 navigation_handle_->appcache_handle() 467 navigation_handle_->appcache_handle()
466 ? navigation_handle_->appcache_handle()->appcache_host_id() 468 ? navigation_handle_->appcache_handle()->appcache_host_id()
467 : kAppCacheNoHostId; 469 : kAppCacheNoHostId;
468 470
469 // Update the lofi state of the request. 471 // Update the lofi state of the request.
470 if (response->head.is_using_lofi) 472 if (response->head.is_using_lofi)
471 common_params_.lofi_state = LOFI_ON; 473 common_params_.lofi_state = LOFI_ON;
472 else 474 else
473 common_params_.lofi_state = LOFI_OFF; 475 common_params_.lofi_state = LOFI_OFF;
474 476
475 // Select an appropriate renderer to commit the navigation. 477 // Select an appropriate renderer to commit the navigation.
476 RenderFrameHostImpl* render_frame_host = 478 RenderFrameHostImpl* render_frame_host = nullptr;
477 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); 479 if (response_should_be_rendered_) {
478 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, 480 render_frame_host =
479 common_params_.url); 481 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this);
482 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(
483 render_frame_host, common_params_.url);
484 }
485 DCHECK(render_frame_host || !response_should_be_rendered_);
480 486
481 // For renderer-initiated navigations that are set to commit in a different 487 // For renderer-initiated navigations that are set to commit in a different
482 // renderer, allow the embedder to cancel the transfer. 488 // renderer, allow the embedder to cancel the transfer.
483 if (!browser_initiated_ && 489 if (!browser_initiated_ && render_frame_host &&
484 render_frame_host != frame_tree_node_->current_frame_host() && 490 render_frame_host != frame_tree_node_->current_frame_host() &&
485 !frame_tree_node_->navigator()->GetDelegate()->ShouldTransferNavigation( 491 !frame_tree_node_->navigator()->GetDelegate()->ShouldTransferNavigation(
486 frame_tree_node_->IsMainFrame())) { 492 frame_tree_node_->IsMainFrame())) {
487 frame_tree_node_->ResetNavigationRequest(false); 493 frame_tree_node_->ResetNavigationRequest(false);
488 return; 494 return;
489 } 495 }
490 496
491 if (navigation_data) 497 if (navigation_data)
492 navigation_handle_->set_navigation_data(std::move(navigation_data)); 498 navigation_handle_->set_navigation_data(std::move(navigation_data));
493 499
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 return; 640 return;
635 } 641 }
636 642
637 loader_->FollowRedirect(); 643 loader_->FollowRedirect();
638 } 644 }
639 645
640 void NavigationRequest::OnWillProcessResponseChecksComplete( 646 void NavigationRequest::OnWillProcessResponseChecksComplete(
641 NavigationThrottle::ThrottleCheckResult result) { 647 NavigationThrottle::ThrottleCheckResult result) {
642 DCHECK(result != NavigationThrottle::DEFER); 648 DCHECK(result != NavigationThrottle::DEFER);
643 649
644 // Abort the request if needed. This will destroy the NavigationRequest. 650 // Abort the request if needed. This includes requests that were blocked by
651 // NavigationThrottles and requests that should not commit (e.g. downloads,
652 // 204/205s). This will destroy the NavigationRequest.
645 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 653 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
646 result == NavigationThrottle::CANCEL) { 654 result == NavigationThrottle::CANCEL || !response_should_be_rendered_) {
647 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 655 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
656 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded(
657 navigation_handle_.get());
648 frame_tree_node_->ResetNavigationRequest(false); 658 frame_tree_node_->ResetNavigationRequest(false);
649 return; 659 return;
650 } 660 }
651 661
652 if (result == NavigationThrottle::BLOCK_RESPONSE) { 662 if (result == NavigationThrottle::BLOCK_RESPONSE) {
653 OnRequestFailed(false, net::ERR_BLOCKED_BY_RESPONSE); 663 OnRequestFailed(false, net::ERR_BLOCKED_BY_RESPONSE);
654 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has 664 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
655 // destroyed the NavigationRequest. 665 // destroyed the NavigationRequest.
656 return; 666 return;
657 } 667 }
(...skipping 24 matching lines...) Expand all
682 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); 692 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture);
683 693
684 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 694 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
685 common_params_, request_params_, 695 common_params_, request_params_,
686 is_view_source_); 696 is_view_source_);
687 697
688 frame_tree_node_->ResetNavigationRequest(true); 698 frame_tree_node_->ResetNavigationRequest(true);
689 } 699 }
690 700
691 } // namespace content 701 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698