OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/navigator_impl.h" | 5 #include "content/browser/frame_host/navigator_impl.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 return; | 145 return; |
146 } | 146 } |
147 | 147 |
148 // This ensures that notifications about the end of the previous | 148 // This ensures that notifications about the end of the previous |
149 // navigation are sent before notifications about the start of the | 149 // navigation are sent before notifications about the start of the |
150 // new navigation. | 150 // new navigation. |
151 render_frame_host->SetNavigationHandle(scoped_ptr<NavigationHandleImpl>()); | 151 render_frame_host->SetNavigationHandle(scoped_ptr<NavigationHandleImpl>()); |
152 } | 152 } |
153 | 153 |
154 render_frame_host->SetNavigationHandle(NavigationHandleImpl::Create( | 154 render_frame_host->SetNavigationHandle(NavigationHandleImpl::Create( |
155 validated_url, render_frame_host->frame_tree_node(), navigation_start)); | 155 validated_url, render_frame_host->frame_tree_node(), navigation_start, |
156 controller_->GetPendingEntry())); | |
156 } | 157 } |
157 | 158 |
158 void NavigatorImpl::DidFailProvisionalLoadWithError( | 159 void NavigatorImpl::DidFailProvisionalLoadWithError( |
159 RenderFrameHostImpl* render_frame_host, | 160 RenderFrameHostImpl* render_frame_host, |
160 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) { | 161 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) { |
161 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() | 162 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() |
162 << ", error_code: " << params.error_code | 163 << ", error_code: " << params.error_code |
163 << ", error_description: " << params.error_description | 164 << ", error_description: " << params.error_description |
164 << ", showing_repost_interstitial: " << | 165 << ", showing_repost_interstitial: " << |
165 params.showing_repost_interstitial | 166 params.showing_repost_interstitial |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 // | 208 // |
208 // However, we do preserve the pending entry in some cases, such as on the | 209 // However, we do preserve the pending entry in some cases, such as on the |
209 // initial navigation of an unmodified blank tab. We also allow the delegate | 210 // initial navigation of an unmodified blank tab. We also allow the delegate |
210 // to say when it's safe to leave aborted URLs in the omnibox, to let the user | 211 // to say when it's safe to leave aborted URLs in the omnibox, to let the user |
211 // edit the URL and try again. This may be useful in cases that the committed | 212 // edit the URL and try again. This may be useful in cases that the committed |
212 // page cannot be attacker-controlled. In these cases, we still allow the | 213 // page cannot be attacker-controlled. In these cases, we still allow the |
213 // view to clear the pending entry and typed URL if the user requests | 214 // view to clear the pending entry and typed URL if the user requests |
214 // (e.g., hitting Escape with focus in the address bar). | 215 // (e.g., hitting Escape with focus in the address bar). |
215 // | 216 // |
216 // Note: don't touch the transient entry, since an interstitial may exist. | 217 // Note: don't touch the transient entry, since an interstitial may exist. |
218 NavigationHandleImpl* handle = render_frame_host->navigation_handle(); | |
219 NavigationEntry* pending = controller_->GetPendingEntry(); | |
Charlie Reis
2016/02/05 19:36:12
nit: pending_entry
Charlie Harrison
2016/02/05 23:10:24
Done.
| |
220 bool pending_matches_fail = | |
Charlie Reis
2016/02/05 19:36:12
nit: pending_entry_matches_fail_msg
Charlie Harrison
2016/02/05 23:10:23
Done.
| |
221 handle && pending && handle->get_entry_id() == pending->GetUniqueID(); | |
217 bool should_preserve_entry = controller_->IsUnmodifiedBlankTab() || | 222 bool should_preserve_entry = controller_->IsUnmodifiedBlankTab() || |
218 delegate_->ShouldPreserveAbortedURLs(); | 223 delegate_->ShouldPreserveAbortedURLs(); |
219 if (controller_->GetPendingEntry() != controller_->GetVisibleEntry() || | 224 if ((pending != controller_->GetVisibleEntry() || !should_preserve_entry) && |
220 !should_preserve_entry) { | 225 pending_matches_fail) { |
Charlie Reis
2016/02/05 19:36:12
This is really hard to follow. (It was already re
Charlie Harrison
2016/02/05 23:10:23
SGTM. My projections show that by next year, this
| |
221 controller_->DiscardPendingEntry(true); | 226 controller_->DiscardPendingEntry(true); |
222 | 227 |
223 // Also force the UI to refresh. | 228 // Also force the UI to refresh. |
224 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); | 229 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
225 } | 230 } |
226 | 231 |
227 if (delegate_) | 232 if (delegate_) |
228 delegate_->DidFailProvisionalLoadWithError(render_frame_host, params); | 233 delegate_->DidFailProvisionalLoadWithError(render_frame_host, params); |
229 } | 234 } |
230 | 235 |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 } | 771 } |
767 | 772 |
768 // In all other cases the current navigation, if any, is canceled and a new | 773 // In all other cases the current navigation, if any, is canceled and a new |
769 // NavigationRequest is created for the node. | 774 // NavigationRequest is created for the node. |
770 frame_tree_node->CreatedNavigationRequest( | 775 frame_tree_node->CreatedNavigationRequest( |
771 NavigationRequest::CreateRendererInitiated( | 776 NavigationRequest::CreateRendererInitiated( |
772 frame_tree_node, common_params, begin_params, body, | 777 frame_tree_node, common_params, begin_params, body, |
773 controller_->GetLastCommittedEntryIndex(), | 778 controller_->GetLastCommittedEntryIndex(), |
774 controller_->GetEntryCount())); | 779 controller_->GetEntryCount())); |
775 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 780 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
776 navigation_request->CreateNavigationHandle(); | |
777 | |
778 if (frame_tree_node->IsMainFrame()) { | 781 if (frame_tree_node->IsMainFrame()) { |
779 // Renderer-initiated main-frame navigations that need to swap processes | 782 // Renderer-initiated main-frame navigations that need to swap processes |
780 // will go to the browser via a OpenURL call, and then be handled by the | 783 // will go to the browser via a OpenURL call, and then be handled by the |
781 // same code path as browser-initiated navigations. For renderer-initiated | 784 // same code path as browser-initiated navigations. For renderer-initiated |
782 // main frame navigation that start via a BeginNavigation IPC, the | 785 // main frame navigation that start via a BeginNavigation IPC, the |
783 // RenderFrameHost will not be swapped. Therefore it is safe to call | 786 // RenderFrameHost will not be swapped. Therefore it is safe to call |
784 // DidStartMainFrameNavigation with the SiteInstance from the current | 787 // DidStartMainFrameNavigation with the SiteInstance from the current |
785 // RenderFrameHost. | 788 // RenderFrameHost. |
786 DidStartMainFrameNavigation( | 789 DidStartMainFrameNavigation( |
787 common_params.url, | 790 common_params.url, |
788 frame_tree_node->current_frame_host()->GetSiteInstance()); | 791 frame_tree_node->current_frame_host()->GetSiteInstance()); |
789 navigation_data_.reset(); | 792 navigation_data_.reset(); |
790 } | 793 } |
791 | 794 |
795 navigation_request->CreateNavigationHandle(controller_->GetPendingEntry()); | |
Charlie Reis
2016/02/05 19:36:12
nit: Comment about why this must be after DidStart
Charlie Harrison
2016/02/05 23:10:23
Done.
| |
796 | |
792 navigation_request->BeginNavigation(); | 797 navigation_request->BeginNavigation(); |
793 } | 798 } |
794 | 799 |
795 // PlzNavigate | 800 // PlzNavigate |
796 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, | 801 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, |
797 ResourceResponse* response, | 802 ResourceResponse* response, |
798 scoped_ptr<StreamHandle> body) { | 803 scoped_ptr<StreamHandle> body) { |
799 CHECK(IsBrowserSideNavigationEnabled()); | 804 CHECK(IsBrowserSideNavigationEnabled()); |
800 | 805 |
801 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 806 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 bool should_dispatch_beforeunload = | 939 bool should_dispatch_beforeunload = |
935 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload(); | 940 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload(); |
936 FrameMsg_Navigate_Type::Value navigation_type = | 941 FrameMsg_Navigate_Type::Value navigation_type = |
937 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); | 942 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
938 frame_tree_node->CreatedNavigationRequest( | 943 frame_tree_node->CreatedNavigationRequest( |
939 NavigationRequest::CreateBrowserInitiated( | 944 NavigationRequest::CreateBrowserInitiated( |
940 frame_tree_node, dest_url, dest_referrer, frame_entry, entry, | 945 frame_tree_node, dest_url, dest_referrer, frame_entry, entry, |
941 navigation_type, is_same_document_history_load, navigation_start, | 946 navigation_type, is_same_document_history_load, navigation_start, |
942 controller_)); | 947 controller_)); |
943 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 948 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
944 navigation_request->CreateNavigationHandle(); | 949 navigation_request->CreateNavigationHandle(controller_->GetVisibleEntry()); |
Charlie Reis
2016/02/05 19:36:12
Shouldn't this be GetPendingEntry()? GetVisibleEn
Charlie Harrison
2016/02/05 23:10:23
Yes. Good catch. In fact, here we can use the Navi
| |
945 | 950 |
946 // Have the current renderer execute its beforeunload event if needed. If it | 951 // Have the current renderer execute its beforeunload event if needed. If it |
947 // is not needed (when beforeunload dispatch is not needed or this navigation | 952 // is not needed (when beforeunload dispatch is not needed or this navigation |
948 // is synchronous and same-site) then NavigationRequest::BeginNavigation | 953 // is synchronous and same-site) then NavigationRequest::BeginNavigation |
949 // should be directly called instead. | 954 // should be directly called instead. |
950 if (should_dispatch_beforeunload && | 955 if (should_dispatch_beforeunload && |
951 ShouldMakeNetworkRequestForURL( | 956 ShouldMakeNetworkRequestForURL( |
952 navigation_request->common_params().url)) { | 957 navigation_request->common_params().url)) { |
953 navigation_request->SetWaitingForRendererResponse(); | 958 navigation_request->SetWaitingForRendererResponse(); |
954 frame_tree_node->current_frame_host()->DispatchBeforeUnload(true); | 959 frame_tree_node->current_frame_host()->DispatchBeforeUnload(true); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1038 entry->set_should_replace_entry(pending_entry->should_replace_entry()); | 1043 entry->set_should_replace_entry(pending_entry->should_replace_entry()); |
1039 entry->SetRedirectChain(pending_entry->GetRedirectChain()); | 1044 entry->SetRedirectChain(pending_entry->GetRedirectChain()); |
1040 } | 1045 } |
1041 controller_->SetPendingEntry(std::move(entry)); | 1046 controller_->SetPendingEntry(std::move(entry)); |
1042 if (delegate_) | 1047 if (delegate_) |
1043 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); | 1048 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); |
1044 } | 1049 } |
1045 } | 1050 } |
1046 | 1051 |
1047 } // namespace content | 1052 } // namespace content |
OLD | NEW |