Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: content/browser/frame_host/navigator_impl.cc

Issue 1661423002: Solidify Entry discarding logic (NavigationHandle keeps its ID) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix check that's invalid when base url has invalid url. Added TODO Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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, pending_entry ? pending_entry->GetUniqueID() : 0));
159 } 160 }
160 161
161 void NavigatorImpl::DidFailProvisionalLoadWithError( 162 void NavigatorImpl::DidFailProvisionalLoadWithError(
162 RenderFrameHostImpl* render_frame_host, 163 RenderFrameHostImpl* render_frame_host,
163 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) { 164 const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) {
164 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() 165 VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec()
165 << ", error_code: " << params.error_code 166 << ", error_code: " << params.error_code
166 << ", error_description: " << params.error_description 167 << ", error_description: " << params.error_description
167 << ", showing_repost_interstitial: " << 168 << ", showing_repost_interstitial: " <<
168 params.showing_repost_interstitial 169 params.showing_repost_interstitial
(...skipping 19 matching lines...) Expand all
188 // commits of the interstitial page. 189 // commits of the interstitial page.
189 FrameTreeNode* root = 190 FrameTreeNode* root =
190 render_frame_host->frame_tree_node()->frame_tree()->root(); 191 render_frame_host->frame_tree_node()->frame_tree()->root();
191 if (root->render_manager()->interstitial_page() != NULL) { 192 if (root->render_manager()->interstitial_page() != NULL) {
192 LOG(WARNING) << "Discarding message during interstitial."; 193 LOG(WARNING) << "Discarding message during interstitial.";
193 return; 194 return;
194 } 195 }
195 196
196 // We used to cancel the pending renderer here for cross-site downloads. 197 // 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 198 // 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 199 // looks for this WebContents based on a render ID. Instead, we just
199 // leave the pending renderer around until the next navigation event 200 // leave the pending renderer around until the next navigation event
200 // (Navigate, DidNavigate, etc), which will clean it up properly. 201 // (Navigate, DidNavigate, etc), which will clean it up properly.
201 // 202 //
202 // TODO(creis): Find a way to cancel any pending RFH here. 203 // TODO(creis): Find a way to cancel any pending RFH here.
203 } 204 }
204 205
205 // We usually clear the pending entry when it fails, so that an arbitrary URL 206 // 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 207 // pending entry has been replaced by another navigation. If
207 // the pending entry isn't visible (e.g., renderer-initiated navigations) to 208 // |DiscardPendingEntry| is called in this case, then the completely valid
208 // prevent URL spoofs for in-page navigations that don't go through 209 // entry for the new navigation would be discarded. See crbug.com/513742. To
209 // DidStartProvisionalLoadForFrame. 210 // catch this case, the current pending entry is compared against the current
210 // 211 // 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 212 NavigationHandleImpl* handle = render_frame_host->navigation_handle();
212 // initial navigation of an unmodified blank tab. We also allow the delegate 213 NavigationEntry* pending_entry = controller_->GetPendingEntry();
213 // to say when it's safe to leave aborted URLs in the omnibox, to let the user 214 bool pending_matches_fail_msg =
214 // edit the URL and try again. This may be useful in cases that the committed 215 handle && pending_entry &&
215 // page cannot be attacker-controlled. In these cases, we still allow the 216 handle->pending_nav_entry_id() == pending_entry->GetUniqueID();
216 // view to clear the pending entry and typed URL if the user requests 217 if (pending_matches_fail_msg) {
217 // (e.g., hitting Escape with focus in the address bar). 218 // We usually clear the pending entry when it fails, so that an arbitrary
218 // 219 // 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. 220 // when the pending entry isn't visible (e.g., renderer-initiated
220 bool should_preserve_entry = controller_->IsUnmodifiedBlankTab() || 221 // navigations) to prevent URL spoofs for in-page navigations that don't go
221 delegate_->ShouldPreserveAbortedURLs(); 222 // through DidStartProvisionalLoadForFrame.
222 if (controller_->GetPendingEntry() != controller_->GetVisibleEntry() || 223 //
223 !should_preserve_entry) { 224 // However, we do preserve the pending entry in some cases, such as on the
224 controller_->DiscardPendingEntry(true); 225 // initial navigation of an unmodified blank tab. We also allow the
226 // delegate to say when it's safe to leave aborted URLs in the omnibox, to
227 // let the user edit the URL and try again. This may be useful in cases
228 // that the committed page cannot be attacker-controlled. In these cases,
229 // we still allow the view to clear the pending entry and typed URL if the
230 // user requests (e.g., hitting Escape with focus in the address bar).
231 //
232 // Note: don't touch the transient entry, since an interstitial may exist.
233 bool should_preserve_entry = controller_->IsUnmodifiedBlankTab() ||
234 delegate_->ShouldPreserveAbortedURLs();
235 if (pending_entry != controller_->GetVisibleEntry() ||
236 !should_preserve_entry) {
237 controller_->DiscardPendingEntry(true);
225 238
226 // Also force the UI to refresh. 239 // Also force the UI to refresh.
227 controller_->delegate()->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); 240 controller_->delegate()->NotifyNavigationStateChanged(
241 INVALIDATE_TYPE_URL);
242 }
228 } 243 }
229 244
230 if (delegate_) 245 if (delegate_)
231 delegate_->DidFailProvisionalLoadWithError(render_frame_host, params); 246 delegate_->DidFailProvisionalLoadWithError(render_frame_host, params);
232 } 247 }
233 248
234 void NavigatorImpl::DidFailLoadWithError( 249 void NavigatorImpl::DidFailLoadWithError(
235 RenderFrameHostImpl* render_frame_host, 250 RenderFrameHostImpl* render_frame_host,
236 const GURL& url, 251 const GURL& url,
237 int error_code, 252 int error_code,
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 } 818 }
804 819
805 // In all other cases the current navigation, if any, is canceled and a new 820 // In all other cases the current navigation, if any, is canceled and a new
806 // NavigationRequest is created for the node. 821 // NavigationRequest is created for the node.
807 frame_tree_node->CreatedNavigationRequest( 822 frame_tree_node->CreatedNavigationRequest(
808 NavigationRequest::CreateRendererInitiated( 823 NavigationRequest::CreateRendererInitiated(
809 frame_tree_node, common_params, begin_params, body, 824 frame_tree_node, common_params, begin_params, body,
810 controller_->GetLastCommittedEntryIndex(), 825 controller_->GetLastCommittedEntryIndex(),
811 controller_->GetEntryCount())); 826 controller_->GetEntryCount()));
812 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); 827 NavigationRequest* navigation_request = frame_tree_node->navigation_request();
813 navigation_request->CreateNavigationHandle();
814
815 if (frame_tree_node->IsMainFrame()) { 828 if (frame_tree_node->IsMainFrame()) {
816 // Renderer-initiated main-frame navigations that need to swap processes 829 // Renderer-initiated main-frame navigations that need to swap processes
817 // will go to the browser via a OpenURL call, and then be handled by the 830 // will go to the browser via a OpenURL call, and then be handled by the
818 // same code path as browser-initiated navigations. For renderer-initiated 831 // same code path as browser-initiated navigations. For renderer-initiated
819 // main frame navigation that start via a BeginNavigation IPC, the 832 // main frame navigation that start via a BeginNavigation IPC, the
820 // RenderFrameHost will not be swapped. Therefore it is safe to call 833 // RenderFrameHost will not be swapped. Therefore it is safe to call
821 // DidStartMainFrameNavigation with the SiteInstance from the current 834 // DidStartMainFrameNavigation with the SiteInstance from the current
822 // RenderFrameHost. 835 // RenderFrameHost.
823 DidStartMainFrameNavigation( 836 DidStartMainFrameNavigation(
824 common_params.url, 837 common_params.url,
825 frame_tree_node->current_frame_host()->GetSiteInstance()); 838 frame_tree_node->current_frame_host()->GetSiteInstance());
826 navigation_data_.reset(); 839 navigation_data_.reset();
827 } 840 }
828 841
842 // For main frames, NavigationHandle will be created after the call to
843 // |DidStartMainFrameNavigation|, so it receives the most up to date pending
844 // entry from the NavigationController.
845 NavigationEntry* pending_entry = controller_->GetPendingEntry();
846 navigation_request->CreateNavigationHandle(
847 pending_entry ? pending_entry->GetUniqueID() : 0);
829 navigation_request->BeginNavigation(); 848 navigation_request->BeginNavigation();
830 } 849 }
831 850
832 // PlzNavigate 851 // PlzNavigate
833 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node, 852 void NavigatorImpl::CommitNavigation(FrameTreeNode* frame_tree_node,
834 ResourceResponse* response, 853 ResourceResponse* response,
835 scoped_ptr<StreamHandle> body) { 854 scoped_ptr<StreamHandle> body) {
836 CHECK(IsBrowserSideNavigationEnabled()); 855 CHECK(IsBrowserSideNavigationEnabled());
837 856
838 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); 857 NavigationRequest* navigation_request = frame_tree_node->navigation_request();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 bool should_dispatch_beforeunload = 991 bool should_dispatch_beforeunload =
973 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload(); 992 frame_tree_node->current_frame_host()->ShouldDispatchBeforeUnload();
974 FrameMsg_Navigate_Type::Value navigation_type = 993 FrameMsg_Navigate_Type::Value navigation_type =
975 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type); 994 GetNavigationType(controller_->GetBrowserContext(), entry, reload_type);
976 frame_tree_node->CreatedNavigationRequest( 995 frame_tree_node->CreatedNavigationRequest(
977 NavigationRequest::CreateBrowserInitiated( 996 NavigationRequest::CreateBrowserInitiated(
978 frame_tree_node, dest_url, dest_referrer, frame_entry, entry, 997 frame_tree_node, dest_url, dest_referrer, frame_entry, entry,
979 navigation_type, lofi_state, is_same_document_history_load, 998 navigation_type, lofi_state, is_same_document_history_load,
980 navigation_start, controller_)); 999 navigation_start, controller_));
981 NavigationRequest* navigation_request = frame_tree_node->navigation_request(); 1000 NavigationRequest* navigation_request = frame_tree_node->navigation_request();
982 navigation_request->CreateNavigationHandle(); 1001 navigation_request->CreateNavigationHandle(entry.GetUniqueID());
983 1002
984 // Have the current renderer execute its beforeunload event if needed. If it 1003 // Have the current renderer execute its beforeunload event if needed. If it
985 // is not needed (when beforeunload dispatch is not needed or this navigation 1004 // is not needed (when beforeunload dispatch is not needed or this navigation
986 // is synchronous and same-site) then NavigationRequest::BeginNavigation 1005 // is synchronous and same-site) then NavigationRequest::BeginNavigation
987 // should be directly called instead. 1006 // should be directly called instead.
988 if (should_dispatch_beforeunload && 1007 if (should_dispatch_beforeunload &&
989 ShouldMakeNetworkRequestForURL( 1008 ShouldMakeNetworkRequestForURL(
990 navigation_request->common_params().url)) { 1009 navigation_request->common_params().url)) {
991 navigation_request->SetWaitingForRendererResponse(); 1010 navigation_request->SetWaitingForRendererResponse();
992 frame_tree_node->current_frame_host()->DispatchBeforeUnload(true); 1011 frame_tree_node->current_frame_host()->DispatchBeforeUnload(true);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 entry->set_should_replace_entry(pending_entry->should_replace_entry()); 1095 entry->set_should_replace_entry(pending_entry->should_replace_entry());
1077 entry->SetRedirectChain(pending_entry->GetRedirectChain()); 1096 entry->SetRedirectChain(pending_entry->GetRedirectChain());
1078 } 1097 }
1079 controller_->SetPendingEntry(std::move(entry)); 1098 controller_->SetPendingEntry(std::move(entry));
1080 if (delegate_) 1099 if (delegate_)
1081 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL); 1100 delegate_->NotifyChangedNavigationState(content::INVALIDATE_TYPE_URL);
1082 } 1101 }
1083 } 1102 }
1084 1103
1085 } // namespace content 1104 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_request.cc ('k') | content/browser/frame_host/render_frame_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698