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 speculative_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 (speculative_render_process_host_id_ != | |
177 ChildProcessHost::kInvalidUniqueID) { | |
178 RenderProcessHost* process = | |
179 RenderProcessHost::FromID(speculative_render_process_host_id_); | |
180 if (process) { | |
181 RenderProcessHostImpl::RemoveExpectedNavigationToSite( | |
182 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | |
183 process, site_url_); | |
184 } | |
185 } | |
186 | |
169 // Transfer requests that have not matched up with another navigation request | 187 // 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 | 188 // 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. | 189 // the RDHI, so they do not get cancelled when frames are destroyed. |
172 if (is_transferring()) { | 190 if (is_transferring()) { |
173 BrowserThread::PostTask( | 191 BrowserThread::PostTask( |
174 BrowserThread::IO, FROM_HERE, | 192 BrowserThread::IO, FROM_HERE, |
175 base::Bind(&NotifyAbandonedTransferNavigation, GetGlobalRequestID())); | 193 base::Bind(&NotifyAbandonedTransferNavigation, GetGlobalRequestID())); |
176 } | 194 } |
177 | 195 |
178 if (!IsRendererDebugURL(url_)) | 196 if (!IsRendererDebugURL(url_)) |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 scoped_refptr<net::HttpResponseHeaders> response_headers, | 602 scoped_refptr<net::HttpResponseHeaders> response_headers, |
585 net::HttpResponseInfo::ConnectionInfo connection_info, | 603 net::HttpResponseInfo::ConnectionInfo connection_info, |
586 const ThrottleChecksFinishedCallback& callback) { | 604 const ThrottleChecksFinishedCallback& callback) { |
587 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, | 605 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, |
588 "WillRedirectRequest", "url", | 606 "WillRedirectRequest", "url", |
589 new_url.possibly_invalid_spec()); | 607 new_url.possibly_invalid_spec()); |
590 | 608 |
591 // Update the navigation parameters. | 609 // Update the navigation parameters. |
592 url_ = new_url; | 610 url_ = new_url; |
593 method_ = new_method; | 611 method_ = new_method; |
612 UpdateSiteURL(); | |
594 | 613 |
595 if (!(transition_ & ui::PAGE_TRANSITION_CLIENT_REDIRECT)) { | 614 if (!(transition_ & ui::PAGE_TRANSITION_CLIENT_REDIRECT)) { |
596 sanitized_referrer_.url = new_referrer_url; | 615 sanitized_referrer_.url = new_referrer_url; |
597 sanitized_referrer_ = | 616 sanitized_referrer_ = |
598 Referrer::SanitizeForRequest(url_, sanitized_referrer_); | 617 Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
599 } | 618 } |
600 | 619 |
601 is_external_protocol_ = new_is_external_protocol; | 620 is_external_protocol_ = new_is_external_protocol; |
602 response_headers_ = response_headers; | 621 response_headers_ = response_headers; |
603 connection_info_ = connection_info; | 622 connection_info_ = connection_info; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 | 693 |
675 void NavigationHandleImpl::ReadyToCommitNavigation( | 694 void NavigationHandleImpl::ReadyToCommitNavigation( |
676 RenderFrameHostImpl* render_frame_host) { | 695 RenderFrameHostImpl* render_frame_host) { |
677 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 696 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
678 "ReadyToCommitNavigation"); | 697 "ReadyToCommitNavigation"); |
679 | 698 |
680 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 699 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
681 render_frame_host_ = render_frame_host; | 700 render_frame_host_ = render_frame_host; |
682 state_ = READY_TO_COMMIT; | 701 state_ = READY_TO_COMMIT; |
683 | 702 |
703 if (IsBrowserSideNavigationEnabled()) | |
704 SetSpeculativeProcess(render_frame_host->GetProcess()); | |
Charlie Reis
2017/05/23 07:29:13
Naming nit: This RFH/process isn't speculative any
clamy
2017/05/23 13:41:15
Done.
| |
705 | |
684 if (!IsRendererDebugURL(url_) && !IsSameDocument()) | 706 if (!IsRendererDebugURL(url_) && !IsSameDocument()) |
685 GetDelegate()->ReadyToCommitNavigation(this); | 707 GetDelegate()->ReadyToCommitNavigation(this); |
686 } | 708 } |
687 | 709 |
688 void NavigationHandleImpl::DidCommitNavigation( | 710 void NavigationHandleImpl::DidCommitNavigation( |
689 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 711 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
690 bool navigation_entry_committed, | 712 bool navigation_entry_committed, |
691 bool did_replace_entry, | 713 bool did_replace_entry, |
692 const GURL& previous_url, | 714 const GURL& previous_url, |
693 NavigationType navigation_type, | 715 NavigationType navigation_type, |
(...skipping 25 matching lines...) Expand all Loading... | |
719 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 741 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
720 "DidCommitNavigation: error page"); | 742 "DidCommitNavigation: error page"); |
721 state_ = DID_COMMIT_ERROR_PAGE; | 743 state_ = DID_COMMIT_ERROR_PAGE; |
722 } else { | 744 } else { |
723 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 745 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
724 "DidCommitNavigation"); | 746 "DidCommitNavigation"); |
725 state_ = DID_COMMIT; | 747 state_ = DID_COMMIT; |
726 } | 748 } |
727 } | 749 } |
728 | 750 |
751 void NavigationHandleImpl::SetSpeculativeProcess( | |
752 RenderProcessHost* speculative_process) { | |
753 if (speculative_process && | |
754 speculative_process->GetID() == speculative_render_process_host_id_) { | |
755 // This |speculative_process| has already been informed of the navigation, | |
756 // no need to update it again. | |
757 return; | |
758 } | |
759 | |
760 // If a RenderProcessHost was expecting this navigation to commit, have it | |
761 // stop tracking this site. | |
762 RenderProcessHost* old_process = | |
763 RenderProcessHost::FromID(speculative_render_process_host_id_); | |
764 if (old_process) { | |
765 RenderProcessHostImpl::RemoveExpectedNavigationToSite( | |
766 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | |
767 old_process, site_url_); | |
768 } | |
769 | |
770 if (speculative_process == nullptr) { | |
771 speculative_render_process_host_id_ = ChildProcessHost::kInvalidUniqueID; | |
772 return; | |
773 } | |
774 | |
775 // Keep track of the speculative RenderProcessHost and tell it to expect a | |
776 // navigation to |site_url_|. | |
777 speculative_render_process_host_id_ = speculative_process->GetID(); | |
778 RenderProcessHostImpl::AddExpectedNavigationToSite( | |
779 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | |
780 speculative_process, site_url_); | |
781 } | |
782 | |
729 void NavigationHandleImpl::Transfer() { | 783 void NavigationHandleImpl::Transfer() { |
730 DCHECK(!IsBrowserSideNavigationEnabled()); | 784 DCHECK(!IsBrowserSideNavigationEnabled()); |
731 // This is an actual transfer. Inform the NavigationResourceThrottle. This | 785 // This is an actual transfer. Inform the NavigationResourceThrottle. This |
732 // will allow to mark the URLRequest as transferring. When it is marked as | 786 // 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 | 787 // transferring, the URLRequest can no longer be cancelled by its original |
734 // RenderFrame. Instead it will persist until being picked up by the transfer | 788 // RenderFrame. Instead it will persist until being picked up by the transfer |
735 // RenderFrame, even if the original RenderFrame is destroyed. | 789 // RenderFrame, even if the original RenderFrame is destroyed. |
736 // Note: |transfer_callback_| can be null in unit tests. | 790 // Note: |transfer_callback_| can be null in unit tests. |
737 if (!transfer_callback_.is_null()) | 791 if (!transfer_callback_.is_null()) |
738 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, transfer_callback_); | 792 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()) { | 1100 node = node->parent()) { |
1047 if (node->current_url().EqualsIgnoringRef(url_)) { | 1101 if (node->current_url().EqualsIgnoringRef(url_)) { |
1048 if (found_self_reference) | 1102 if (found_self_reference) |
1049 return true; | 1103 return true; |
1050 found_self_reference = true; | 1104 found_self_reference = true; |
1051 } | 1105 } |
1052 } | 1106 } |
1053 return false; | 1107 return false; |
1054 } | 1108 } |
1055 | 1109 |
1110 void NavigationHandleImpl::UpdateSiteURL() { | |
1111 GURL new_site_url = SiteInstance::GetSiteForURL( | |
1112 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | |
1113 url_); | |
1114 if (new_site_url == site_url_) | |
1115 return; | |
1116 | |
1117 // When redirecting cross-site, stop telling the speculative | |
1118 // RenderProcessHost to expect a navigation commit. | |
1119 SetSpeculativeProcess(nullptr); | |
1120 site_url_ = new_site_url; | |
1121 } | |
1122 | |
1056 } // namespace content | 1123 } // namespace content |
OLD | NEW |