| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_handle_impl.h" | 5 #include "content/browser/frame_host/navigation_handle_impl.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/browser/appcache/appcache_navigation_handle.h" | 10 #include "content/browser/appcache/appcache_navigation_handle.h" |
| 11 #include "content/browser/appcache/appcache_service_impl.h" | 11 #include "content/browser/appcache/appcache_service_impl.h" |
| 12 #include "content/browser/browsing_data/clear_site_data_throttle.h" | 12 #include "content/browser/browsing_data/clear_site_data_throttle.h" |
| 13 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 14 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 14 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| 15 #include "content/browser/frame_host/ancestor_throttle.h" | 15 #include "content/browser/frame_host/ancestor_throttle.h" |
| 16 #include "content/browser/frame_host/data_url_navigation_throttle.h" | 16 #include "content/browser/frame_host/data_url_navigation_throttle.h" |
| 17 #include "content/browser/frame_host/debug_urls.h" | 17 #include "content/browser/frame_host/debug_urls.h" |
| 18 #include "content/browser/frame_host/form_submission_throttle.h" | 18 #include "content/browser/frame_host/form_submission_throttle.h" |
| 19 #include "content/browser/frame_host/frame_tree_node.h" | 19 #include "content/browser/frame_host/frame_tree_node.h" |
| 20 #include "content/browser/frame_host/mixed_content_navigation_throttle.h" | 20 #include "content/browser/frame_host/mixed_content_navigation_throttle.h" |
| 21 #include "content/browser/frame_host/navigation_controller_impl.h" | 21 #include "content/browser/frame_host/navigation_controller_impl.h" |
| 22 #include "content/browser/frame_host/navigation_entry_impl.h" | 22 #include "content/browser/frame_host/navigation_entry_impl.h" |
| 23 #include "content/browser/frame_host/navigator.h" | 23 #include "content/browser/frame_host/navigator.h" |
| 24 #include "content/browser/frame_host/navigator_delegate.h" | 24 #include "content/browser/frame_host/navigator_delegate.h" |
| 25 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 25 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 26 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 26 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 27 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 27 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
| 28 #include "content/common/child_process_host_impl.h" |
| 28 #include "content/common/frame_messages.h" | 29 #include "content/common/frame_messages.h" |
| 29 #include "content/common/resource_request_body_impl.h" | 30 #include "content/common/resource_request_body_impl.h" |
| 30 #include "content/common/site_isolation_policy.h" | 31 #include "content/common/site_isolation_policy.h" |
| 31 #include "content/public/browser/content_browser_client.h" | 32 #include "content/public/browser/content_browser_client.h" |
| 32 #include "content/public/browser/navigation_ui_data.h" | 33 #include "content/public/browser/navigation_ui_data.h" |
| 33 #include "content/public/browser/site_instance.h" | 34 #include "content/public/browser/site_instance.h" |
| 34 #include "content/public/common/browser_side_navigation_policy.h" | 35 #include "content/public/common/browser_side_navigation_policy.h" |
| 35 #include "content/public/common/content_client.h" | 36 #include "content/public/common/content_client.h" |
| 36 #include "content/public/common/url_constants.h" | 37 #include "content/public/common/url_constants.h" |
| 37 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 should_replace_current_entry_(false), | 113 should_replace_current_entry_(false), |
| 113 redirect_chain_(redirect_chain), | 114 redirect_chain_(redirect_chain), |
| 114 is_download_(false), | 115 is_download_(false), |
| 115 is_stream_(false), | 116 is_stream_(false), |
| 116 started_from_context_menu_(started_from_context_menu), | 117 started_from_context_menu_(started_from_context_menu), |
| 117 reload_type_(ReloadType::NONE), | 118 reload_type_(ReloadType::NONE), |
| 118 restore_type_(RestoreType::NONE), | 119 restore_type_(RestoreType::NONE), |
| 119 navigation_type_(NAVIGATION_TYPE_UNKNOWN), | 120 navigation_type_(NAVIGATION_TYPE_UNKNOWN), |
| 120 should_check_main_world_csp_(should_check_main_world_csp), | 121 should_check_main_world_csp_(should_check_main_world_csp), |
| 121 is_form_submission_(is_form_submission), | 122 is_form_submission_(is_form_submission), |
| 123 expected_render_process_host_id_(ChildProcessHost::kInvalidUniqueID), |
| 122 weak_factory_(this) { | 124 weak_factory_(this) { |
| 123 TRACE_EVENT_ASYNC_BEGIN2("navigation", "NavigationHandle", this, | 125 TRACE_EVENT_ASYNC_BEGIN2("navigation", "NavigationHandle", this, |
| 124 "frame_tree_node", | 126 "frame_tree_node", |
| 125 frame_tree_node_->frame_tree_node_id(), "url", | 127 frame_tree_node_->frame_tree_node_id(), "url", |
| 126 url_.possibly_invalid_spec()); | 128 url_.possibly_invalid_spec()); |
| 127 DCHECK(!navigation_start.is_null()); | 129 DCHECK(!navigation_start.is_null()); |
| 130 |
| 131 site_url_ = SiteInstance::GetSiteForURL( |
| 132 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
| 133 url_); |
| 128 if (redirect_chain_.empty()) | 134 if (redirect_chain_.empty()) |
| 129 redirect_chain_.push_back(url); | 135 redirect_chain_.push_back(url); |
| 130 | 136 |
| 131 starting_site_instance_ = | 137 starting_site_instance_ = |
| 132 frame_tree_node_->current_frame_host()->GetSiteInstance(); | 138 frame_tree_node_->current_frame_host()->GetSiteInstance(); |
| 133 | 139 |
| 134 if (pending_nav_entry_id_) { | 140 if (pending_nav_entry_id_) { |
| 135 NavigationControllerImpl* nav_controller = | 141 NavigationControllerImpl* nav_controller = |
| 136 static_cast<NavigationControllerImpl*>( | 142 static_cast<NavigationControllerImpl*>( |
| 137 frame_tree_node_->navigator()->GetController()); | 143 frame_tree_node_->navigator()->GetController()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 159 navigation_start, "Initial URL", url_.spec()); | 165 navigation_start, "Initial URL", url_.spec()); |
| 160 } | 166 } |
| 161 | 167 |
| 162 if (is_same_page_) { | 168 if (is_same_page_) { |
| 163 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 169 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 164 "Same document"); | 170 "Same document"); |
| 165 } | 171 } |
| 166 } | 172 } |
| 167 | 173 |
| 168 NavigationHandleImpl::~NavigationHandleImpl() { | 174 NavigationHandleImpl::~NavigationHandleImpl() { |
| 175 // Inform the RenderProcessHost to no longer expect a navigation. |
| 176 if (expected_render_process_host_id_ != ChildProcessHost::kInvalidUniqueID) { |
| 177 RenderProcessHost* process = |
| 178 RenderProcessHost::FromID(expected_render_process_host_id_); |
| 179 if (process) { |
| 180 RenderProcessHostImpl::RemoveExpectedNavigationToSite( |
| 181 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
| 182 process, site_url_); |
| 183 } |
| 184 } |
| 185 |
| 169 // Transfer requests that have not matched up with another navigation request | 186 // Transfer requests that have not matched up with another navigation request |
| 170 // from the renderer need to be cleaned up. These are marked as protected in | 187 // from the renderer need to be cleaned up. These are marked as protected in |
| 171 // the RDHI, so they do not get cancelled when frames are destroyed. | 188 // the RDHI, so they do not get cancelled when frames are destroyed. |
| 172 if (is_transferring()) { | 189 if (is_transferring()) { |
| 173 BrowserThread::PostTask( | 190 BrowserThread::PostTask( |
| 174 BrowserThread::IO, FROM_HERE, | 191 BrowserThread::IO, FROM_HERE, |
| 175 base::Bind(&NotifyAbandonedTransferNavigation, GetGlobalRequestID())); | 192 base::Bind(&NotifyAbandonedTransferNavigation, GetGlobalRequestID())); |
| 176 } | 193 } |
| 177 | 194 |
| 178 if (!IsRendererDebugURL(url_)) | 195 if (!IsRendererDebugURL(url_)) |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 scoped_refptr<net::HttpResponseHeaders> response_headers, | 601 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 585 net::HttpResponseInfo::ConnectionInfo connection_info, | 602 net::HttpResponseInfo::ConnectionInfo connection_info, |
| 586 const ThrottleChecksFinishedCallback& callback) { | 603 const ThrottleChecksFinishedCallback& callback) { |
| 587 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, | 604 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, |
| 588 "WillRedirectRequest", "url", | 605 "WillRedirectRequest", "url", |
| 589 new_url.possibly_invalid_spec()); | 606 new_url.possibly_invalid_spec()); |
| 590 | 607 |
| 591 // Update the navigation parameters. | 608 // Update the navigation parameters. |
| 592 url_ = new_url; | 609 url_ = new_url; |
| 593 method_ = new_method; | 610 method_ = new_method; |
| 611 UpdateSiteURL(); |
| 594 | 612 |
| 595 if (!(transition_ & ui::PAGE_TRANSITION_CLIENT_REDIRECT)) { | 613 if (!(transition_ & ui::PAGE_TRANSITION_CLIENT_REDIRECT)) { |
| 596 sanitized_referrer_.url = new_referrer_url; | 614 sanitized_referrer_.url = new_referrer_url; |
| 597 sanitized_referrer_ = | 615 sanitized_referrer_ = |
| 598 Referrer::SanitizeForRequest(url_, sanitized_referrer_); | 616 Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
| 599 } | 617 } |
| 600 | 618 |
| 601 is_external_protocol_ = new_is_external_protocol; | 619 is_external_protocol_ = new_is_external_protocol; |
| 602 response_headers_ = response_headers; | 620 response_headers_ = response_headers; |
| 603 connection_info_ = connection_info; | 621 connection_info_ = connection_info; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 | 692 |
| 675 void NavigationHandleImpl::ReadyToCommitNavigation( | 693 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 676 RenderFrameHostImpl* render_frame_host) { | 694 RenderFrameHostImpl* render_frame_host) { |
| 677 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 695 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 678 "ReadyToCommitNavigation"); | 696 "ReadyToCommitNavigation"); |
| 679 | 697 |
| 680 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 698 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
| 681 render_frame_host_ = render_frame_host; | 699 render_frame_host_ = render_frame_host; |
| 682 state_ = READY_TO_COMMIT; | 700 state_ = READY_TO_COMMIT; |
| 683 | 701 |
| 702 if (IsBrowserSideNavigationEnabled()) |
| 703 SetExpectedProcess(render_frame_host->GetProcess()); |
| 704 |
| 684 if (!IsRendererDebugURL(url_) && !IsSameDocument()) | 705 if (!IsRendererDebugURL(url_) && !IsSameDocument()) |
| 685 GetDelegate()->ReadyToCommitNavigation(this); | 706 GetDelegate()->ReadyToCommitNavigation(this); |
| 686 } | 707 } |
| 687 | 708 |
| 688 void NavigationHandleImpl::DidCommitNavigation( | 709 void NavigationHandleImpl::DidCommitNavigation( |
| 689 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 710 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 690 bool navigation_entry_committed, | 711 bool navigation_entry_committed, |
| 691 bool did_replace_entry, | 712 bool did_replace_entry, |
| 692 const GURL& previous_url, | 713 const GURL& previous_url, |
| 693 NavigationType navigation_type, | 714 NavigationType navigation_type, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 719 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 740 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 720 "DidCommitNavigation: error page"); | 741 "DidCommitNavigation: error page"); |
| 721 state_ = DID_COMMIT_ERROR_PAGE; | 742 state_ = DID_COMMIT_ERROR_PAGE; |
| 722 } else { | 743 } else { |
| 723 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 744 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 724 "DidCommitNavigation"); | 745 "DidCommitNavigation"); |
| 725 state_ = DID_COMMIT; | 746 state_ = DID_COMMIT; |
| 726 } | 747 } |
| 727 } | 748 } |
| 728 | 749 |
| 750 void NavigationHandleImpl::SetExpectedProcess( |
| 751 RenderProcessHost* expected_process) { |
| 752 if (expected_process && |
| 753 expected_process->GetID() == expected_render_process_host_id_) { |
| 754 // This |expected_process| has already been informed of the navigation, |
| 755 // no need to update it again. |
| 756 return; |
| 757 } |
| 758 |
| 759 // If a RenderProcessHost was expecting this navigation to commit, have it |
| 760 // stop tracking this site. |
| 761 RenderProcessHost* old_process = |
| 762 RenderProcessHost::FromID(expected_render_process_host_id_); |
| 763 if (old_process) { |
| 764 RenderProcessHostImpl::RemoveExpectedNavigationToSite( |
| 765 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
| 766 old_process, site_url_); |
| 767 } |
| 768 |
| 769 if (expected_process == nullptr) { |
| 770 expected_render_process_host_id_ = ChildProcessHost::kInvalidUniqueID; |
| 771 return; |
| 772 } |
| 773 |
| 774 // Keep track of the speculative RenderProcessHost and tell it to expect a |
| 775 // navigation to |site_url_|. |
| 776 expected_render_process_host_id_ = expected_process->GetID(); |
| 777 RenderProcessHostImpl::AddExpectedNavigationToSite( |
| 778 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
| 779 expected_process, site_url_); |
| 780 } |
| 781 |
| 729 void NavigationHandleImpl::Transfer() { | 782 void NavigationHandleImpl::Transfer() { |
| 730 DCHECK(!IsBrowserSideNavigationEnabled()); | 783 DCHECK(!IsBrowserSideNavigationEnabled()); |
| 731 // This is an actual transfer. Inform the NavigationResourceThrottle. This | 784 // This is an actual transfer. Inform the NavigationResourceThrottle. This |
| 732 // will allow to mark the URLRequest as transferring. When it is marked as | 785 // will allow to mark the URLRequest as transferring. When it is marked as |
| 733 // transferring, the URLRequest can no longer be cancelled by its original | 786 // transferring, the URLRequest can no longer be cancelled by its original |
| 734 // RenderFrame. Instead it will persist until being picked up by the transfer | 787 // RenderFrame. Instead it will persist until being picked up by the transfer |
| 735 // RenderFrame, even if the original RenderFrame is destroyed. | 788 // RenderFrame, even if the original RenderFrame is destroyed. |
| 736 // Note: |transfer_callback_| can be null in unit tests. | 789 // Note: |transfer_callback_| can be null in unit tests. |
| 737 if (!transfer_callback_.is_null()) | 790 if (!transfer_callback_.is_null()) |
| 738 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, transfer_callback_); | 791 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, transfer_callback_); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 node = node->parent()) { | 1099 node = node->parent()) { |
| 1047 if (node->current_url().EqualsIgnoringRef(url_)) { | 1100 if (node->current_url().EqualsIgnoringRef(url_)) { |
| 1048 if (found_self_reference) | 1101 if (found_self_reference) |
| 1049 return true; | 1102 return true; |
| 1050 found_self_reference = true; | 1103 found_self_reference = true; |
| 1051 } | 1104 } |
| 1052 } | 1105 } |
| 1053 return false; | 1106 return false; |
| 1054 } | 1107 } |
| 1055 | 1108 |
| 1109 void NavigationHandleImpl::UpdateSiteURL() { |
| 1110 GURL new_site_url = SiteInstance::GetSiteForURL( |
| 1111 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
| 1112 url_); |
| 1113 if (new_site_url == site_url_) |
| 1114 return; |
| 1115 |
| 1116 // When redirecting cross-site, stop telling the speculative |
| 1117 // RenderProcessHost to expect a navigation commit. |
| 1118 SetExpectedProcess(nullptr); |
| 1119 site_url_ = new_site_url; |
| 1120 } |
| 1121 |
| 1056 } // namespace content | 1122 } // namespace content |
| OLD | NEW |