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

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

Issue 2488743003: (Re-)introduce AncestorThrottle to handle 'X-Frame-Options'. (Closed)
Patch Set: Addressed comments (@alexmos #2) Created 3 years, 12 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 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 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
500 render_frame_host, response->head.headers.get(), 500 render_frame_host, response->head.headers.get(),
501 response->head.connection_info, ssl_status, request_id, 501 response->head.connection_info, ssl_status, request_id,
502 common_params_.should_replace_current_entry, is_download, is_stream, 502 common_params_.should_replace_current_entry, is_download, is_stream,
503 base::Closure(), 503 base::Closure(),
504 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete, 504 base::Bind(&NavigationRequest::OnWillProcessResponseChecksComplete,
505 base::Unretained(this))); 505 base::Unretained(this)));
506 } 506 }
507 507
508 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, 508 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache,
509 int net_error) { 509 int net_error) {
510 DCHECK(state_ == STARTED); 510 DCHECK(state_ == STARTED || state_ == RESPONSE_STARTED);
511 state_ = FAILED; 511 state_ = FAILED;
512 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); 512 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error));
513 frame_tree_node_->navigator()->FailedNavigation( 513 frame_tree_node_->navigator()->FailedNavigation(
514 frame_tree_node_, has_stale_copy_in_cache, net_error); 514 frame_tree_node_, has_stale_copy_in_cache, net_error);
515 } 515 }
516 516
517 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { 517 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) {
518 if (frame_tree_node_->IsMainFrame()) { 518 if (frame_tree_node_->IsMainFrame()) {
519 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0( 519 TRACE_EVENT_ASYNC_END_WITH_TIMESTAMP0(
520 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(), 520 "navigation", "Navigation timeToNetworkStack", navigation_handle_.get(),
521 timestamp); 521 timestamp);
522 } 522 }
523 523
524 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, 524 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp,
525 common_params_.url); 525 common_params_.url);
526 } 526 }
527 527
528 void NavigationRequest::OnStartChecksComplete( 528 void NavigationRequest::OnStartChecksComplete(
529 NavigationThrottle::ThrottleCheckResult result) { 529 NavigationThrottle::ThrottleCheckResult result) {
530 CHECK(result != NavigationThrottle::DEFER); 530 DCHECK(result != NavigationThrottle::DEFER);
531 DCHECK(result != NavigationThrottle::BLOCK_RESPONSE);
531 532
532 if (on_start_checks_complete_closure_) 533 if (on_start_checks_complete_closure_)
533 on_start_checks_complete_closure_.Run(); 534 on_start_checks_complete_closure_.Run();
534 535
535 // Abort the request if needed. This will destroy the NavigationRequest. 536 // Abort the request if needed. This will destroy the NavigationRequest.
536 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 537 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
537 result == NavigationThrottle::CANCEL) { 538 result == NavigationThrottle::CANCEL) {
538 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 539 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
539 frame_tree_node_->ResetNavigationRequest(false); 540 frame_tree_node_->ResetNavigationRequest(false);
540 return; 541 return;
541 } 542 }
542 543
543 if (result == NavigationThrottle::BLOCK_REQUEST) { 544 if (result == NavigationThrottle::BLOCK_REQUEST) {
544 OnRequestFailed(false, net::ERR_BLOCKED_BY_CLIENT); 545 OnRequestFailed(false, net::ERR_BLOCKED_BY_CLIENT);
546 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
547 // destroyed the NavigationRequest.
545 return; 548 return;
546 } 549 }
547 550
548 // Use the SiteInstance of the navigating RenderFrameHost to get access to 551 // Use the SiteInstance of the navigating RenderFrameHost to get access to
549 // the StoragePartition. Using the url of the navigation will result in a 552 // the StoragePartition. Using the url of the navigation will result in a
550 // wrong StoragePartition being picked when a WebView is navigating. 553 // wrong StoragePartition being picked when a WebView is navigating.
551 DCHECK_NE(AssociatedSiteInstanceType::NONE, associated_site_instance_type_); 554 DCHECK_NE(AssociatedSiteInstanceType::NONE, associated_site_instance_type_);
552 RenderFrameHostImpl* navigating_frame_host = 555 RenderFrameHostImpl* navigating_frame_host =
553 associated_site_instance_type_ == AssociatedSiteInstanceType::SPECULATIVE 556 associated_site_instance_type_ == AssociatedSiteInstanceType::SPECULATIVE
554 ? frame_tree_node_->render_manager()->speculative_frame_host() 557 ? frame_tree_node_->render_manager()->speculative_frame_host()
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 parent_is_main_frame, IsSecureFrame(frame_tree_node_->parent()), 616 parent_is_main_frame, IsSecureFrame(frame_tree_node_->parent()),
614 frame_tree_node_->frame_tree_node_id(), is_for_guests_only, 617 frame_tree_node_->frame_tree_node_id(), is_for_guests_only,
615 report_raw_headers, navigating_frame_host->GetVisibilityState()), 618 report_raw_headers, navigating_frame_host->GetVisibilityState()),
616 std::move(navigation_ui_data), 619 std::move(navigation_ui_data),
617 navigation_handle_->service_worker_handle(), 620 navigation_handle_->service_worker_handle(),
618 navigation_handle_->appcache_handle(), this); 621 navigation_handle_->appcache_handle(), this);
619 } 622 }
620 623
621 void NavigationRequest::OnRedirectChecksComplete( 624 void NavigationRequest::OnRedirectChecksComplete(
622 NavigationThrottle::ThrottleCheckResult result) { 625 NavigationThrottle::ThrottleCheckResult result) {
623 CHECK(result != NavigationThrottle::DEFER); 626 DCHECK(result != NavigationThrottle::DEFER);
627 DCHECK(result != NavigationThrottle::BLOCK_RESPONSE);
624 628
625 // Abort the request if needed. This will destroy the NavigationRequest. 629 // Abort the request if needed. This will destroy the NavigationRequest.
626 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 630 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
627 result == NavigationThrottle::CANCEL) { 631 result == NavigationThrottle::CANCEL) {
628 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 632 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
629 frame_tree_node_->ResetNavigationRequest(false); 633 frame_tree_node_->ResetNavigationRequest(false);
630 return; 634 return;
631 } 635 }
632 636
633 loader_->FollowRedirect(); 637 loader_->FollowRedirect();
634 } 638 }
635 639
636 void NavigationRequest::OnWillProcessResponseChecksComplete( 640 void NavigationRequest::OnWillProcessResponseChecksComplete(
637 NavigationThrottle::ThrottleCheckResult result) { 641 NavigationThrottle::ThrottleCheckResult result) {
638 CHECK(result != NavigationThrottle::DEFER); 642 DCHECK(result != NavigationThrottle::DEFER);
639 643
640 // Abort the request if needed. This will destroy the NavigationRequest. 644 // Abort the request if needed. This will destroy the NavigationRequest.
641 if (result == NavigationThrottle::CANCEL_AND_IGNORE || 645 if (result == NavigationThrottle::CANCEL_AND_IGNORE ||
642 result == NavigationThrottle::CANCEL) { 646 result == NavigationThrottle::CANCEL) {
643 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. 647 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE.
644 frame_tree_node_->ResetNavigationRequest(false); 648 frame_tree_node_->ResetNavigationRequest(false);
645 return; 649 return;
646 } 650 }
647 651
652 if (result == NavigationThrottle::BLOCK_RESPONSE) {
653 OnRequestFailed(false, net::ERR_BLOCKED_BY_RESPONSE);
654 // DO NOT ADD CODE after this. The previous call to OnRequestFailed has
655 // destroyed the NavigationRequest.
656 return;
657 }
658
648 // Have the processing of the response resume in the network stack. 659 // Have the processing of the response resume in the network stack.
649 loader_->ProceedWithResponse(); 660 loader_->ProceedWithResponse();
650 661
651 CommitNavigation(); 662 CommitNavigation();
652 663
653 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused 664 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused
654 // the destruction of the NavigationRequest. 665 // the destruction of the NavigationRequest.
655 } 666 }
656 667
657 void NavigationRequest::CommitNavigation() { 668 void NavigationRequest::CommitNavigation() {
(...skipping 13 matching lines...) Expand all
671 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture); 682 DCHECK_EQ(request_params_.has_user_gesture, begin_params_.has_user_gesture);
672 683
673 render_frame_host->CommitNavigation(response_.get(), std::move(body_), 684 render_frame_host->CommitNavigation(response_.get(), std::move(body_),
674 common_params_, request_params_, 685 common_params_, request_params_,
675 is_view_source_); 686 is_view_source_);
676 687
677 frame_tree_node_->ResetNavigationRequest(true); 688 frame_tree_node_->ResetNavigationRequest(true);
678 } 689 }
679 690
680 } // namespace content 691 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698