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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 render_frame_host->navigation_handle()->set_is_transferring(false); | 144 render_frame_host->navigation_handle()->set_is_transferring(false); |
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 NavigationEntry* pending_entry = controller_->GetPendingEntry(); |
154 render_frame_host->SetNavigationHandle(NavigationHandleImpl::Create( | 155 render_frame_host->SetNavigationHandle(NavigationHandleImpl::Create( |
155 validated_url, render_frame_host->frame_tree_node(), | 156 validated_url, render_frame_host->frame_tree_node(), |
156 false, // is_synchronous | 157 false, // is_synchronous |
157 is_iframe_srcdoc, // is_srcdoc | 158 is_iframe_srcdoc, // is_srcdoc |
158 navigation_start)); | 159 navigation_start, |
| 160 pending_entry ? pending_entry->GetUniqueID() : 0)); |
159 } | 161 } |
160 | 162 |
161 void NavigatorImpl::DidFailProvisionalLoadWithError( | 163 void NavigatorImpl::DidFailProvisionalLoadWithError( |
162 RenderFrameHostImpl* render_frame_host, | 164 RenderFrameHostImpl* render_frame_host, |
163 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) { | 165 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) { |
164 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() | 166 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() |
165 << ", error_code: " << params.error_code | 167 << ", error_code: " << params.error_code |
166 << ", error_description: " << params.error_description | 168 << ", error_description: " << params.error_description |
167 << ", showing_repost_interstitial: " << | 169 << ", showing_repost_interstitial: " << |
168 params.showing_repost_interstitial | 170 params.showing_repost_interstitial |
(...skipping 19 matching lines...) Expand all Loading... |
188 // commits of the interstitial page. | 190 // commits of the interstitial page. |
189 FrameTreeNode* root = | 191 FrameTreeNode* root = |
190 render_frame_host->frame_tree_node()->frame_tree()->root(); | 192 render_frame_host->frame_tree_node()->frame_tree()->root(); |
191 if (root->render_manager()->interstitial_page() != NULL) { | 193 if (root->render_manager()->interstitial_page() != NULL) { |
192 LOG(WARNING) << "Discarding message during interstitial."; | 194 LOG(WARNING) << "Discarding message during interstitial."; |
193 return; | 195 return; |
194 } | 196 } |
195 | 197 |
196 // We used to cancel the pending renderer here for cross-site downloads. | 198 // We used to cancel the pending renderer here for cross-site downloads. |
197 // However, it's not safe to do that because the download logic repeatedly | 199 // However, it's not safe to do that because the download logic repeatedly |
198 // looks for this WebContents based on a render ID. Instead, we just | 200 // looks for this WebContents based on a render ID. Instead, we just |
199 // leave the pending renderer around until the next navigation event | 201 // leave the pending renderer around until the next navigation event |
200 // (Navigate, DidNavigate, etc), which will clean it up properly. | 202 // (Navigate, DidNavigate, etc), which will clean it up properly. |
201 // | 203 // |
202 // TODO(creis): Find a way to cancel any pending RFH here. | 204 // TODO(creis): Find a way to cancel any pending RFH here. |
203 } | 205 } |
204 | 206 |
205 // We usually clear the pending entry when it fails, so that an arbitrary URL | 207 // Racy conditions can cause a fail message to arrive after its corresponding |
206 // isn't left visible above a committed page. This must be enforced when | 208 // pending entry has been replaced by another navigation. If |
207 // the pending entry isn't visible (e.g., renderer-initiated navigations) to | 209 // |DiscardPendingEntry| is called in this case, then the completely valid |
208 // prevent URL spoofs for in-page navigations that don't go through | 210 // entry for the new navigation would be discarded. See crbug.com/513742. To |
209 // DidStartProvisionalLoadForFrame. | 211 // catch this case, the current pending entry is compared against the current |
210 // | 212 // navigation handle's entry id, which should correspond to the failed load. |
211 // However, we do preserve the pending entry in some cases, such as on the | 213 NavigationHandleImpl* handle = render_frame_host->navigation_handle(); |
212 // initial navigation of an unmodified blank tab. We also allow the delegate | 214 NavigationEntry* pending_entry = controller_->GetPendingEntry(); |
213 // to say when it's safe to leave aborted URLs in the omnibox, to let the user | 215 bool pending_matches_fail_msg = |
214 // edit the URL and try again. This may be useful in cases that the committed | 216 handle && pending_entry && |
215 // page cannot be attacker-controlled. In these cases, we still allow the | 217 handle->pending_nav_entry_id() == pending_entry->GetUniqueID(); |
216 // view to clear the pending entry and typed URL if the user requests | 218 if (pending_matches_fail_msg) { |
217 // (e.g., hitting Escape with focus in the address bar). | 219 // We usually clear the pending entry when it fails, so that an arbitrary |
218 // | 220 // URL isn't left visible above a committed page. This must be enforced |
219 // Note: don't touch the transient entry, since an interstitial may exist. | 221 // when the pending entry isn't visible (e.g., renderer-initiated |
220 bool should_preserve_entry = controller_->IsUnmodifiedBlankTab() || | 222 // navigations) to prevent URL spoofs for in-page navigations that don't go |
221 delegate_->ShouldPreserveAbortedURLs(); | 223 // through DidStartProvisionalLoadForFrame. |
222 if (controller_->GetPendingEntry() != controller_->GetVisibleEntry() || | 224 // |
223 !should_preserve_entry) { | 225 // However, we do preserve the pending entry in some cases, such as on the |
224 controller_->DiscardPendingEntry(true); | 226 // initial navigation of an unmodified blank tab. We also allow the |
| 227 // delegate to say when it's safe to leave aborted URLs in the omnibox, to |
| 228 // let the user edit the URL and try again. This may be useful in cases |
| 229 // that the committed page cannot be attacker-controlled. In these cases, |
| 230 // we still allow the view to clear the pending entry and typed URL if the |
| 231 // user requests (e.g., hitting Escape with focus in the address bar). |
| 232 // |
| 233 // Note: don't touch the transient entry, since an interstitial may exist. |
| 234 bool should_preserve_entry = controller_->IsUnmodifiedBlankTab() || |
| 235 delegate_->ShouldPreserveAbortedURLs(); |
| 236 if (pending_entry != controller_->GetVisibleEntry() || |
| 237 !should_preserve_entry) { |
| 238 controller_->DiscardPendingEntry(true); |
225 | 239 |
226 // Also force the UI to refresh. | 240 // Also force the UI to refresh. |
227 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); | 241 controller_->delegate()->NotifyNavigationStateChanged( |
| 242 INVALIDATE_TYPE_URL); |
| 243 } |
228 } | 244 } |
229 | 245 |
230 if (delegate_) | 246 if (delegate_) |
231 delegate_->DidFailProvisionalLoadWithError(render_frame_host, params); | 247 delegate_->DidFailProvisionalLoadWithError(render_frame_host, params); |
232 } | 248 } |
233 | 249 |
234 void NavigatorImpl::DidFailLoadWithError( | 250 void NavigatorImpl::DidFailLoadWithError( |
235 RenderFrameHostImpl* render_frame_host, | 251 RenderFrameHostImpl* render_frame_host, |
236 const GURL& url, | 252 const GURL& url, |
237 int error_code, | 253 int error_code, |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 } | 785 } |
770 | 786 |
771 // In all other cases the current navigation, if any, is canceled and a new | 787 // In all other cases the current navigation, if any, is canceled and a new |
772 // NavigationRequest is created for the node. | 788 // NavigationRequest is created for the node. |
773 frame_tree_node->CreatedNavigationRequest( | 789 frame_tree_node->CreatedNavigationRequest( |
774 NavigationRequest::CreateRendererInitiated( | 790 NavigationRequest::CreateRendererInitiated( |
775 frame_tree_node, common_params, begin_params, body, | 791 frame_tree_node, common_params, begin_params, body, |
776 controller_->GetLastCommittedEntryIndex(), | 792 controller_->GetLastCommittedEntryIndex(), |
777 controller_->GetEntryCount())); | 793 controller_->GetEntryCount())); |
778 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 794 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
779 navigation_request->CreateNavigationHandle(); | |
780 | |
781 if (frame_tree_node->IsMainFrame()) { | 795 if (frame_tree_node->IsMainFrame()) { |
782 // Renderer-initiated main-frame navigations that need to swap processes | 796 // Renderer-initiated main-frame navigations that need to swap processes |
783 // will go to the browser via a OpenURL call, and then be handled by the | 797 // will go to the browser via a OpenURL call, and then be handled by the |
784 // same code path as browser-initiated navigations. For renderer-initiated | 798 // same code path as browser-initiated navigations. For renderer-initiated |
785 // main frame navigation that start via a BeginNavigation IPC, the | 799 // main frame navigation that start via a BeginNavigation IPC, the |
786 // RenderFrameHost will not be swapped. Therefore it is safe to call | 800 // RenderFrameHost will not be swapped. Therefore it is safe to call |
787 // DidStartMainFrameNavigation with the SiteInstance from the current | 801 // DidStartMainFrameNavigation with the SiteInstance from the current |
788 // RenderFrameHost. | 802 // RenderFrameHost. |
789 DidStartMainFrameNavigation( | 803 DidStartMainFrameNavigation( |
790 common_params.url, | 804 common_params.url, |
791 frame_tree_node->current_frame_host()->GetSiteInstance()); | 805 frame_tree_node->current_frame_host()->GetSiteInstance()); |
792 navigation_data_.reset(); | 806 navigation_data_.reset(); |
793 } | 807 } |
794 | 808 |
| 809 // The NavigationHandle must be created after the call to |
| 810 // |DidStartMainFrameNavigation|, so it receives the most up to date pending |
| 811 // entry from the NavigationController. The pending entry is guaranteed to be |
| 812 // non null at this point. |
| 813 DCHECK(controller_->GetPendingEntry()); |
| 814 navigation_request->CreateNavigationHandle( |
| 815 controller_->GetPendingEntry()->GetUniqueID()); |
795 navigation_request->BeginNavigation(); | 816 navigation_request->BeginNavigation(); |
796 } | 817 } |
797 | 818 |
798 // PlzNavigate | 819 // PlzNavigate |
799 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, | 820 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, |
800 ResourceResponse* response, | 821 ResourceResponse* response, |
801 scoped_ptr<StreamHandle> body) { | 822 scoped_ptr<StreamHandle> body) { |
802 CHECK(IsBrowserSideNavigationEnabled()); | 823 CHECK(IsBrowserSideNavigationEnabled()); |
803 | 824 |
804 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 825 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 bool should_dispatch_beforeunload = | 958 bool should_dispatch_beforeunload = |
938 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload(); | 959 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload(); |
939 FrameMsg_Navigate_Type::Value navigation_type = | 960 FrameMsg_Navigate_Type::Value navigation_type = |
940 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); | 961 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); |
941 frame_tree_node->CreatedNavigationRequest( | 962 frame_tree_node->CreatedNavigationRequest( |
942 NavigationRequest::CreateBrowserInitiated( | 963 NavigationRequest::CreateBrowserInitiated( |
943 frame_tree_node, dest_url, dest_referrer, frame_entry, entry, | 964 frame_tree_node, dest_url, dest_referrer, frame_entry, entry, |
944 navigation_type, is_same_document_history_load, navigation_start, | 965 navigation_type, is_same_document_history_load, navigation_start, |
945 controller_)); | 966 controller_)); |
946 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); | 967 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); |
947 navigation_request->CreateNavigationHandle(); | 968 navigation_request->CreateNavigationHandle(entry.GetUniqueID()); |
948 | 969 |
949 // Have the current renderer execute its beforeunload event if needed. If it | 970 // Have the current renderer execute its beforeunload event if needed. If it |
950 // is not needed (when beforeunload dispatch is not needed or this navigation | 971 // is not needed (when beforeunload dispatch is not needed or this navigation |
951 // is synchronous and same-site) then NavigationRequest::BeginNavigation | 972 // is synchronous and same-site) then NavigationRequest::BeginNavigation |
952 // should be directly called instead. | 973 // should be directly called instead. |
953 if (should_dispatch_beforeunload && | 974 if (should_dispatch_beforeunload && |
954 ShouldMakeNetworkRequestForURL( | 975 ShouldMakeNetworkRequestForURL( |
955 navigation_request->common_params().url)) { | 976 navigation_request->common_params().url)) { |
956 navigation_request->SetWaitingForRendererResponse(); | 977 navigation_request->SetWaitingForRendererResponse(); |
957 frame_tree_node->current_frame_host()->DispatchBeforeUnload(true); | 978 frame_tree_node->current_frame_host()->DispatchBeforeUnload(true); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 entry->set_should_replace_entry(pending_entry->should_replace_entry()); | 1062 entry->set_should_replace_entry(pending_entry->should_replace_entry()); |
1042 entry->SetRedirectChain(pending_entry->GetRedirectChain()); | 1063 entry->SetRedirectChain(pending_entry->GetRedirectChain()); |
1043 } | 1064 } |
1044 controller_->SetPendingEntry(std::move(entry)); | 1065 controller_->SetPendingEntry(std::move(entry)); |
1045 if (delegate_) | 1066 if (delegate_) |
1046 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); | 1067 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); |
1047 } | 1068 } |
1048 } | 1069 } |
1049 | 1070 |
1050 } // namespace content | 1071 } // namespace content |
OLD | NEW |