Chromium Code Reviews| 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" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 #include "content/public/common/url_constants.h" | 36 #include "content/public/common/url_constants.h" |
| 37 #include "net/base/net_errors.h" | 37 #include "net/base/net_errors.h" |
| 38 #include "net/url_request/redirect_info.h" | 38 #include "net/url_request/redirect_info.h" |
| 39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
| 40 #include "url/url_constants.h" | 40 #include "url/url_constants.h" |
| 41 | 41 |
| 42 namespace content { | 42 namespace content { |
| 43 | 43 |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 const int kInvalidRenderProcessHostId = -1; | |
|
Charlie Reis
2017/05/15 03:41:52
We should use ChildProcessHost::kInvalidUniqueID w
clamy
2017/05/16 14:50:45
Done.
| |
| 47 | |
| 46 void UpdateThrottleCheckResult( | 48 void UpdateThrottleCheckResult( |
| 47 NavigationThrottle::ThrottleCheckResult* to_update, | 49 NavigationThrottle::ThrottleCheckResult* to_update, |
| 48 NavigationThrottle::ThrottleCheckResult result) { | 50 NavigationThrottle::ThrottleCheckResult result) { |
| 49 *to_update = result; | 51 *to_update = result; |
| 50 } | 52 } |
| 51 | 53 |
| 52 void NotifyAbandonedTransferNavigation(const GlobalRequestID& id) { | 54 void NotifyAbandonedTransferNavigation(const GlobalRequestID& id) { |
| 53 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 55 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 54 if (ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get()) | 56 if (ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get()) |
| 55 rdh->CancelRequest(id.child_id, id.request_id); | 57 rdh->CancelRequest(id.child_id, id.request_id); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 should_replace_current_entry_(false), | 114 should_replace_current_entry_(false), |
| 113 redirect_chain_(redirect_chain), | 115 redirect_chain_(redirect_chain), |
| 114 is_download_(false), | 116 is_download_(false), |
| 115 is_stream_(false), | 117 is_stream_(false), |
| 116 started_from_context_menu_(started_from_context_menu), | 118 started_from_context_menu_(started_from_context_menu), |
| 117 reload_type_(ReloadType::NONE), | 119 reload_type_(ReloadType::NONE), |
| 118 restore_type_(RestoreType::NONE), | 120 restore_type_(RestoreType::NONE), |
| 119 navigation_type_(NAVIGATION_TYPE_UNKNOWN), | 121 navigation_type_(NAVIGATION_TYPE_UNKNOWN), |
| 120 should_check_main_world_csp_(should_check_main_world_csp), | 122 should_check_main_world_csp_(should_check_main_world_csp), |
| 121 is_form_submission_(is_form_submission), | 123 is_form_submission_(is_form_submission), |
| 124 speculative_render_process_host_id_(kInvalidRenderProcessHostId), | |
| 125 should_inform_process_on_redirects_(false), | |
| 122 weak_factory_(this) { | 126 weak_factory_(this) { |
| 123 TRACE_EVENT_ASYNC_BEGIN2("navigation", "NavigationHandle", this, | 127 TRACE_EVENT_ASYNC_BEGIN2("navigation", "NavigationHandle", this, |
| 124 "frame_tree_node", | 128 "frame_tree_node", |
| 125 frame_tree_node_->frame_tree_node_id(), "url", | 129 frame_tree_node_->frame_tree_node_id(), "url", |
| 126 url_.possibly_invalid_spec()); | 130 url_.possibly_invalid_spec()); |
| 127 DCHECK(!navigation_start.is_null()); | 131 DCHECK(!navigation_start.is_null()); |
| 128 if (redirect_chain_.empty()) | 132 if (redirect_chain_.empty()) |
| 129 redirect_chain_.push_back(url); | 133 redirect_chain_.push_back(url); |
| 130 | 134 |
| 131 starting_site_instance_ = | 135 starting_site_instance_ = |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 159 navigation_start, "Initial URL", url_.spec()); | 163 navigation_start, "Initial URL", url_.spec()); |
| 160 } | 164 } |
| 161 | 165 |
| 162 if (is_same_page_) { | 166 if (is_same_page_) { |
| 163 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 167 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 164 "Same document"); | 168 "Same document"); |
| 165 } | 169 } |
| 166 } | 170 } |
| 167 | 171 |
| 168 NavigationHandleImpl::~NavigationHandleImpl() { | 172 NavigationHandleImpl::~NavigationHandleImpl() { |
| 173 // Inform the RenderProcessHost to no longer expect a navigation. | |
| 174 if (speculative_render_process_host_id_ != kInvalidRenderProcessHostId) { | |
| 175 RenderProcessHost* process = | |
| 176 RenderProcessHost::FromID(speculative_render_process_host_id_); | |
| 177 if (process) { | |
| 178 RenderProcessHostImpl::RemoveExpectedNavigationToSite( | |
| 179 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | |
| 180 process, url_); | |
| 181 } | |
| 182 } | |
| 183 | |
| 169 // Transfer requests that have not matched up with another navigation request | 184 // 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 | 185 // 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. | 186 // the RDHI, so they do not get cancelled when frames are destroyed. |
| 172 if (is_transferring()) { | 187 if (is_transferring()) { |
| 173 BrowserThread::PostTask( | 188 BrowserThread::PostTask( |
| 174 BrowserThread::IO, FROM_HERE, | 189 BrowserThread::IO, FROM_HERE, |
| 175 base::Bind(&NotifyAbandonedTransferNavigation, GetGlobalRequestID())); | 190 base::Bind(&NotifyAbandonedTransferNavigation, GetGlobalRequestID())); |
| 176 } | 191 } |
| 177 | 192 |
| 178 if (!IsRendererDebugURL(url_)) | 193 if (!IsRendererDebugURL(url_)) |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 const std::string& new_method, | 596 const std::string& new_method, |
| 582 const GURL& new_referrer_url, | 597 const GURL& new_referrer_url, |
| 583 bool new_is_external_protocol, | 598 bool new_is_external_protocol, |
| 584 scoped_refptr<net::HttpResponseHeaders> response_headers, | 599 scoped_refptr<net::HttpResponseHeaders> response_headers, |
| 585 net::HttpResponseInfo::ConnectionInfo connection_info, | 600 net::HttpResponseInfo::ConnectionInfo connection_info, |
| 586 const ThrottleChecksFinishedCallback& callback) { | 601 const ThrottleChecksFinishedCallback& callback) { |
| 587 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, | 602 TRACE_EVENT_ASYNC_STEP_INTO1("navigation", "NavigationHandle", this, |
| 588 "WillRedirectRequest", "url", | 603 "WillRedirectRequest", "url", |
| 589 new_url.possibly_invalid_spec()); | 604 new_url.possibly_invalid_spec()); |
| 590 | 605 |
| 606 // Update the speculative process when the redirect is cross-site. | |
| 607 BrowserContext* browser_context = | |
| 608 frame_tree_node_->navigator()->GetController()->GetBrowserContext(); | |
| 609 GURL old_site = SiteInstance::GetSiteForURL(browser_context, url_); | |
| 610 GURL new_site = SiteInstance::GetSiteForURL(browser_context, new_url); | |
| 611 if (speculative_render_process_host_id_ != kInvalidRenderProcessHostId && | |
| 612 old_site != new_site) { | |
| 613 RenderProcessHost* process = | |
| 614 RenderProcessHost::FromID(speculative_render_process_host_id_); | |
| 615 if (process) { | |
| 616 RenderProcessHostImpl::RemoveExpectedNavigationToSite(browser_context, | |
| 617 process, url_); | |
| 618 if (should_inform_process_on_redirects_) { | |
| 619 RenderProcessHostImpl::AddExpectedNavigationToSite(browser_context, | |
| 620 process, new_url); | |
| 621 } else { | |
| 622 speculative_render_process_host_id_ = kInvalidRenderProcessHostId; | |
|
nasko
2017/05/05 05:21:59
Shouldn't speculative_render_process_host_id_ be c
clamy
2017/05/05 15:10:11
Not in renderer-initiated navigations: we match th
Charlie Reis
2017/05/15 03:41:52
Yes, the confusion here is part of my concern. Se
clamy
2017/05/15 15:21:15
The problem with that is that we don't execute RFH
Charlie Reis
2017/05/15 23:46:18
Can you put some more detail on this redirect case
clamy
2017/05/16 14:50:45
I am now tracking the site url and updating it fro
clamy
2017/05/16 14:50:45
Ok I'll update the design doc so we can follow up
| |
| 623 } | |
| 624 } | |
| 625 } | |
| 626 | |
| 591 // Update the navigation parameters. | 627 // Update the navigation parameters. |
| 592 url_ = new_url; | 628 url_ = new_url; |
| 593 method_ = new_method; | 629 method_ = new_method; |
| 594 | 630 |
| 595 if (!(transition_ & ui::PAGE_TRANSITION_CLIENT_REDIRECT)) { | 631 if (!(transition_ & ui::PAGE_TRANSITION_CLIENT_REDIRECT)) { |
| 596 sanitized_referrer_.url = new_referrer_url; | 632 sanitized_referrer_.url = new_referrer_url; |
| 597 sanitized_referrer_ = | 633 sanitized_referrer_ = |
| 598 Referrer::SanitizeForRequest(url_, sanitized_referrer_); | 634 Referrer::SanitizeForRequest(url_, sanitized_referrer_); |
| 599 } | 635 } |
| 600 | 636 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 | 710 |
| 675 void NavigationHandleImpl::ReadyToCommitNavigation( | 711 void NavigationHandleImpl::ReadyToCommitNavigation( |
| 676 RenderFrameHostImpl* render_frame_host) { | 712 RenderFrameHostImpl* render_frame_host) { |
| 677 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 713 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 678 "ReadyToCommitNavigation"); | 714 "ReadyToCommitNavigation"); |
| 679 | 715 |
| 680 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); | 716 DCHECK(!render_frame_host_ || render_frame_host_ == render_frame_host); |
| 681 render_frame_host_ = render_frame_host; | 717 render_frame_host_ = render_frame_host; |
| 682 state_ = READY_TO_COMMIT; | 718 state_ = READY_TO_COMMIT; |
| 683 | 719 |
| 720 if (IsBrowserSideNavigationEnabled()) { | |
| 721 // Update the processes about expected navigations if the speculative | |
| 722 // RenderFrameHost changed. | |
| 723 RenderProcessHost* final_process = render_frame_host->GetProcess(); | |
| 724 bool should_inform_final_process = | |
| 725 speculative_render_process_host_id_ == kInvalidRenderProcessHostId; | |
| 726 | |
| 727 if (speculative_render_process_host_id_ != kInvalidRenderProcessHostId) { | |
|
Charlie Reis
2017/05/15 03:41:52
nit: Redundant with should_inform_final_process
clamy
2017/05/16 14:50:45
I have removed this part in favor of calling SetSp
| |
| 728 RenderProcessHost* process = | |
| 729 RenderProcessHost::FromID(speculative_render_process_host_id_); | |
| 730 should_inform_final_process = final_process != process; | |
| 731 if (process && final_process != process) { | |
| 732 RenderProcessHostImpl::RemoveExpectedNavigationToSite( | |
| 733 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | |
| 734 process, url_); | |
| 735 } | |
| 736 } | |
| 737 | |
| 738 if (should_inform_final_process) { | |
| 739 RenderProcessHostImpl::AddExpectedNavigationToSite( | |
| 740 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | |
| 741 final_process, url_); | |
| 742 speculative_render_process_host_id_ = final_process->GetID(); | |
| 743 } | |
| 744 DCHECK_EQ(speculative_render_process_host_id_, final_process->GetID()); | |
| 745 } | |
| 746 | |
| 684 if (!IsRendererDebugURL(url_) && !IsSameDocument()) | 747 if (!IsRendererDebugURL(url_) && !IsSameDocument()) |
| 685 GetDelegate()->ReadyToCommitNavigation(this); | 748 GetDelegate()->ReadyToCommitNavigation(this); |
| 686 } | 749 } |
| 687 | 750 |
| 688 void NavigationHandleImpl::DidCommitNavigation( | 751 void NavigationHandleImpl::DidCommitNavigation( |
| 689 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, | 752 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, |
| 690 bool navigation_entry_committed, | 753 bool navigation_entry_committed, |
| 691 bool did_replace_entry, | 754 bool did_replace_entry, |
| 692 const GURL& previous_url, | 755 const GURL& previous_url, |
| 693 NavigationType navigation_type, | 756 NavigationType navigation_type, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 719 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 782 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 720 "DidCommitNavigation: error page"); | 783 "DidCommitNavigation: error page"); |
| 721 state_ = DID_COMMIT_ERROR_PAGE; | 784 state_ = DID_COMMIT_ERROR_PAGE; |
| 722 } else { | 785 } else { |
| 723 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, | 786 TRACE_EVENT_ASYNC_STEP_INTO0("navigation", "NavigationHandle", this, |
| 724 "DidCommitNavigation"); | 787 "DidCommitNavigation"); |
| 725 state_ = DID_COMMIT; | 788 state_ = DID_COMMIT; |
| 726 } | 789 } |
| 727 } | 790 } |
| 728 | 791 |
| 792 void NavigationHandleImpl::SetSpeculativeProcessID( | |
| 793 int render_process_host_id, | |
| 794 bool should_inform_on_redirects) { | |
| 795 RenderProcessHost* process = | |
| 796 RenderProcessHost::FromID(render_process_host_id); | |
| 797 if (!process) | |
|
Charlie Reis
2017/05/15 03:41:52
This seems like it should be an error, rather than
clamy
2017/05/16 14:50:45
This function now takes the RenderProcessHost and
| |
| 798 return; | |
| 799 RenderProcessHostImpl::AddExpectedNavigationToSite( | |
| 800 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | |
| 801 process, url_); | |
| 802 speculative_render_process_host_id_ = render_process_host_id; | |
| 803 should_inform_process_on_redirects_ = should_inform_on_redirects; | |
| 804 } | |
| 805 | |
| 729 void NavigationHandleImpl::Transfer() { | 806 void NavigationHandleImpl::Transfer() { |
| 730 DCHECK(!IsBrowserSideNavigationEnabled()); | 807 DCHECK(!IsBrowserSideNavigationEnabled()); |
| 731 // This is an actual transfer. Inform the NavigationResourceThrottle. This | 808 // This is an actual transfer. Inform the NavigationResourceThrottle. This |
| 732 // will allow to mark the URLRequest as transferring. When it is marked as | 809 // 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 | 810 // transferring, the URLRequest can no longer be cancelled by its original |
| 734 // RenderFrame. Instead it will persist until being picked up by the transfer | 811 // RenderFrame. Instead it will persist until being picked up by the transfer |
| 735 // RenderFrame, even if the original RenderFrame is destroyed. | 812 // RenderFrame, even if the original RenderFrame is destroyed. |
| 736 // Note: |transfer_callback_| can be null in unit tests. | 813 // Note: |transfer_callback_| can be null in unit tests. |
| 737 if (!transfer_callback_.is_null()) | 814 if (!transfer_callback_.is_null()) |
| 738 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, transfer_callback_); | 815 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, transfer_callback_); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1047 if (node->current_url().EqualsIgnoringRef(url_)) { | 1124 if (node->current_url().EqualsIgnoringRef(url_)) { |
| 1048 if (found_self_reference) | 1125 if (found_self_reference) |
| 1049 return true; | 1126 return true; |
| 1050 found_self_reference = true; | 1127 found_self_reference = true; |
| 1051 } | 1128 } |
| 1052 } | 1129 } |
| 1053 return false; | 1130 return false; |
| 1054 } | 1131 } |
| 1055 | 1132 |
| 1056 } // namespace content | 1133 } // namespace content |
| OLD | NEW |