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

Side by Side Diff: content/renderer/render_frame_impl.cc

Issue 743803002: Avoid stale navigation requests without excessive page id knowledge in the renderer process. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: charlie's fixes Created 6 years 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
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_view_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/render_frame_impl.h" 5 #include "content/renderer/render_frame_impl.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 #endif 940 #endif
941 IPC_END_MESSAGE_MAP() 941 IPC_END_MESSAGE_MAP()
942 942
943 return handled; 943 return handled;
944 } 944 }
945 945
946 void RenderFrameImpl::OnNavigate(const FrameMsg_Navigate_Params& params) { 946 void RenderFrameImpl::OnNavigate(const FrameMsg_Navigate_Params& params) {
947 TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate", 947 TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate",
948 "id", routing_id_, 948 "id", routing_id_,
949 "url", params.common_params.url.possibly_invalid_spec()); 949 "url", params.common_params.url.possibly_invalid_spec());
950
950 bool is_reload = 951 bool is_reload =
951 RenderViewImpl::IsReload(params.common_params.navigation_type); 952 RenderViewImpl::IsReload(params.common_params.navigation_type);
953 bool is_history_navigation = params.commit_params.page_state.IsValid();
952 WebURLRequest::CachePolicy cache_policy = 954 WebURLRequest::CachePolicy cache_policy =
953 WebURLRequest::UseProtocolCachePolicy; 955 WebURLRequest::UseProtocolCachePolicy;
954 if (!RenderFrameImpl::PrepareRenderViewForNavigation( 956 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
955 params.common_params.url, params.common_params.navigation_type, 957 params.common_params.url, params.common_params.navigation_type,
956 params.commit_params.page_state, true, params.pending_history_list_offset, 958 params.commit_params.page_state, is_history_navigation,
957 params.page_id, &is_reload, &cache_policy)) { 959 params.current_history_list_offset, params.page_id, &is_reload,
960 &cache_policy)) {
958 return; 961 return;
959 } 962 }
960 963
961 int pending_history_list_offset = params.pending_history_list_offset; 964 render_view_->history_list_offset_ = params.current_history_list_offset;
962 int current_history_list_offset = params.current_history_list_offset; 965 render_view_->history_list_length_ = params.current_history_list_length;
963 int current_history_list_length = params.current_history_list_length;
964 if (params.should_clear_history_list) { 966 if (params.should_clear_history_list) {
965 CHECK_EQ(pending_history_list_offset, -1); 967 CHECK_EQ(-1, render_view_->history_list_offset_);
966 CHECK_EQ(current_history_list_offset, -1); 968 CHECK_EQ(0, render_view_->history_list_length_);
967 CHECK_EQ(current_history_list_length, 0);
968 }
969 render_view_->history_list_offset_ = current_history_list_offset;
970 render_view_->history_list_length_ = current_history_list_length;
971 if (render_view_->history_list_length_ >= 0) {
972 render_view_->history_page_ids_.resize(
973 render_view_->history_list_length_, -1);
974 }
975 if (pending_history_list_offset >= 0 &&
976 pending_history_list_offset < render_view_->history_list_length_) {
977 render_view_->history_page_ids_[pending_history_list_offset] =
978 params.page_id;
979 } 969 }
980 970
981 GetContentClient()->SetActiveURL(params.common_params.url); 971 GetContentClient()->SetActiveURL(params.common_params.url);
982 972
983 WebFrame* frame = frame_; 973 WebFrame* frame = frame_;
984 if (!params.frame_to_navigate.empty()) { 974 if (!params.frame_to_navigate.empty()) {
985 // TODO(nasko): Move this lookup to the browser process. 975 // TODO(nasko): Move this lookup to the browser process.
986 frame = render_view_->webview()->findFrameByName( 976 frame = render_view_->webview()->findFrameByName(
987 WebString::fromUTF8(params.frame_to_navigate)); 977 WebString::fromUTF8(params.frame_to_navigate));
988 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; 978 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate;
(...skipping 17 matching lines...) Expand all
1006 bool reload_original_url = 996 bool reload_original_url =
1007 (params.common_params.navigation_type == 997 (params.common_params.navigation_type ==
1008 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); 998 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
1009 bool ignore_cache = (params.common_params.navigation_type == 999 bool ignore_cache = (params.common_params.navigation_type ==
1010 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); 1000 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
1011 1001
1012 if (reload_original_url) 1002 if (reload_original_url)
1013 frame->reloadWithOverrideURL(params.common_params.url, true); 1003 frame->reloadWithOverrideURL(params.common_params.url, true);
1014 else 1004 else
1015 frame->reload(ignore_cache); 1005 frame->reload(ignore_cache);
1016 } else if (params.commit_params.page_state.IsValid()) { 1006 } else if (is_history_navigation) {
1017 // We must know the page ID of the page we are navigating back to. 1007 // We must know the page ID of the page we are navigating back to.
1018 DCHECK_NE(params.page_id, -1); 1008 DCHECK_NE(params.page_id, -1);
1019 scoped_ptr<HistoryEntry> entry = 1009 scoped_ptr<HistoryEntry> entry =
1020 PageStateToHistoryEntry(params.commit_params.page_state); 1010 PageStateToHistoryEntry(params.commit_params.page_state);
1021 if (entry) { 1011 if (entry) {
1022 // Ensure we didn't save the swapped out URL in UpdateState, since the 1012 // Ensure we didn't save the swapped out URL in UpdateState, since the
1023 // browser should never be telling us to navigate to swappedout://. 1013 // browser should never be telling us to navigate to swappedout://.
1024 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); 1014 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL));
1025 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy); 1015 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy);
1026 } 1016 }
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 render_view_->webview()->resetScrollAndScaleState(); 2335 render_view_->webview()->resetScrollAndScaleState();
2346 internal_data->set_must_reset_scroll_and_scale_state(false); 2336 internal_data->set_must_reset_scroll_and_scale_state(false);
2347 } 2337 }
2348 internal_data->set_use_error_page(false); 2338 internal_data->set_use_error_page(false);
2349 2339
2350 bool is_new_navigation = commit_type == blink::WebStandardCommit; 2340 bool is_new_navigation = commit_type == blink::WebStandardCommit;
2351 if (is_new_navigation) { 2341 if (is_new_navigation) {
2352 // We bump our Page ID to correspond with the new session history entry. 2342 // We bump our Page ID to correspond with the new session history entry.
2353 render_view_->page_id_ = render_view_->next_page_id_++; 2343 render_view_->page_id_ = render_view_->next_page_id_++;
2354 2344
2355 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since 2345 // Don't update history list values for kSwappedOutURL, since
2356 // we don't want to forget the entry that was there, and since we will 2346 // we don't want to forget the entry that was there, and since we will
2357 // never come back to kSwappedOutURL. Note that we have to call 2347 // never come back to kSwappedOutURL. Note that we have to call
2358 // UpdateSessionHistory and update page_id_ even in this case, so that 2348 // UpdateSessionHistory and update page_id_ even in this case, so that
2359 // the current entry gets a state update and so that we don't send a 2349 // the current entry gets a state update and so that we don't send a
2360 // state update to the wrong entry when we swap back in. 2350 // state update to the wrong entry when we swap back in.
2361 if (GetLoadingUrl() != GURL(kSwappedOutURL)) { 2351 if (GetLoadingUrl() != GURL(kSwappedOutURL)) {
2362 // Advance our offset in session history, applying the length limit. 2352 // Advance our offset in session history, applying the length limit.
2363 // There is now no forward history. 2353 // There is now no forward history.
2364 render_view_->history_list_offset_++; 2354 render_view_->history_list_offset_++;
2365 if (render_view_->history_list_offset_ >= kMaxSessionHistoryEntries) 2355 if (render_view_->history_list_offset_ >= kMaxSessionHistoryEntries)
2366 render_view_->history_list_offset_ = kMaxSessionHistoryEntries - 1; 2356 render_view_->history_list_offset_ = kMaxSessionHistoryEntries - 1;
2367 render_view_->history_list_length_ = 2357 render_view_->history_list_length_ =
2368 render_view_->history_list_offset_ + 1; 2358 render_view_->history_list_offset_ + 1;
2369 render_view_->history_page_ids_.resize(
2370 render_view_->history_list_length_, -1);
2371 render_view_->history_page_ids_[render_view_->history_list_offset_] =
2372 render_view_->page_id_;
2373 } 2359 }
2374 } else { 2360 } else {
2375 // Inspect the navigation_state on this frame to see if the navigation 2361 // Inspect the navigation_state on this frame to see if the navigation
2376 // corresponds to a session history navigation... Note: |frame| may or 2362 // corresponds to a session history navigation... Note: |frame| may or
2377 // may not be the toplevel frame, but for the case of capturing session 2363 // may not be the toplevel frame, but for the case of capturing session
2378 // history, the first committed frame suffices. We keep track of whether 2364 // history, the first committed frame suffices. We keep track of whether
2379 // we've seen this commit before so that only capture session history once 2365 // we've seen this commit before so that only capture session history once
2380 // per navigation. 2366 // per navigation.
2381 // 2367 //
2382 // Note that we need to check if the page ID changed. In the case of a 2368 // Note that we need to check if the page ID changed. In the case of a
2383 // reload, the page ID doesn't change, and UpdateSessionHistory gets the 2369 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2384 // previous URL and the current page ID, which would be wrong. 2370 // previous URL and the current page ID, which would be wrong.
2385 if (navigation_state->pending_page_id() != -1 && 2371 if (navigation_state->pending_page_id() != -1 &&
2386 navigation_state->pending_page_id() != render_view_->page_id_ && 2372 navigation_state->pending_page_id() != render_view_->page_id_ &&
2387 !navigation_state->request_committed()) { 2373 !navigation_state->request_committed()) {
2388 // This is a successful session history navigation! 2374 // This is a successful session history navigation!
2389 render_view_->page_id_ = navigation_state->pending_page_id(); 2375 render_view_->page_id_ = navigation_state->pending_page_id();
2390 2376
2391 render_view_->history_list_offset_ = 2377 render_view_->history_list_offset_ =
2392 navigation_state->pending_history_list_offset(); 2378 navigation_state->pending_history_list_offset();
2393
2394 // If the history list is valid, our list of page IDs should be correct.
2395 DCHECK(render_view_->history_list_length_ <= 0 ||
2396 render_view_->history_list_offset_ < 0 ||
2397 render_view_->history_list_offset_ >=
2398 render_view_->history_list_length_ ||
2399 render_view_->history_page_ids_[render_view_->history_list_offset_]
2400 == render_view_->page_id_);
2401 } 2379 }
2402 } 2380 }
2403 2381
2404 bool sent = Send( 2382 bool sent = Send(
2405 new FrameHostMsg_DidAssignPageId(routing_id_, render_view_->page_id_)); 2383 new FrameHostMsg_DidAssignPageId(routing_id_, render_view_->page_id_));
2406 CHECK(sent); // http://crbug.com/407376 2384 CHECK(sent); // http://crbug.com/407376
2407 2385
2408 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_, 2386 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_,
2409 DidCommitProvisionalLoad(frame, is_new_navigation)); 2387 DidCommitProvisionalLoad(frame, is_new_navigation));
2410 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, 2388 FOR_EACH_OBSERVER(RenderFrameObserver, observers_,
(...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after
3677 3655
3678 // PlzNavigate 3656 // PlzNavigate
3679 void RenderFrameImpl::OnCommitNavigation( 3657 void RenderFrameImpl::OnCommitNavigation(
3680 const ResourceResponseHead& response, 3658 const ResourceResponseHead& response,
3681 const GURL& stream_url, 3659 const GURL& stream_url,
3682 const CommonNavigationParams& common_params, 3660 const CommonNavigationParams& common_params,
3683 const CommitNavigationParams& commit_params) { 3661 const CommitNavigationParams& commit_params) {
3684 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( 3662 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
3685 switches::kEnableBrowserSideNavigation)); 3663 switches::kEnableBrowserSideNavigation));
3686 bool is_reload = false; 3664 bool is_reload = false;
3665 bool is_history_navigation = commit_params.page_state.IsValid();
3687 WebURLRequest::CachePolicy cache_policy = 3666 WebURLRequest::CachePolicy cache_policy =
3688 WebURLRequest::UseProtocolCachePolicy; 3667 WebURLRequest::UseProtocolCachePolicy;
3689 if (!RenderFrameImpl::PrepareRenderViewForNavigation( 3668 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
3690 common_params.url, common_params.navigation_type, 3669 common_params.url, common_params.navigation_type,
3691 commit_params.page_state, false, -1, -1, &is_reload, &cache_policy)) { 3670 commit_params.page_state, is_history_navigation,
3671 -999 /* current_history_list_offset */, -1,
3672 &is_reload, &cache_policy)) {
3692 return; 3673 return;
3693 } 3674 }
3694 3675
3695 GetContentClient()->SetActiveURL(common_params.url); 3676 GetContentClient()->SetActiveURL(common_params.url);
3696 3677
3697 // Create a WebURLRequest that blink can use to get access to the body of the 3678 // Create a WebURLRequest that blink can use to get access to the body of the
3698 // response through a stream in the browser. Blink will then commit the 3679 // response through a stream in the browser. Blink will then commit the
3699 // navigation. 3680 // navigation.
3700 // TODO(clamy): Have the navigation commit directly, without going through 3681 // TODO(clamy): Have the navigation commit directly, without going through
3701 // loading a WebURLRequest. 3682 // loading a WebURLRequest.
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 #else 4084 #else
4104 return scoped_ptr<MediaStreamRendererFactory>( 4085 return scoped_ptr<MediaStreamRendererFactory>(
4105 static_cast<MediaStreamRendererFactory*>(NULL)); 4086 static_cast<MediaStreamRendererFactory*>(NULL));
4106 #endif 4087 #endif
4107 } 4088 }
4108 4089
4109 bool RenderFrameImpl::PrepareRenderViewForNavigation( 4090 bool RenderFrameImpl::PrepareRenderViewForNavigation(
4110 const GURL& url, 4091 const GURL& url,
4111 FrameMsg_Navigate_Type::Value navigate_type, 4092 FrameMsg_Navigate_Type::Value navigate_type,
4112 const PageState& state, 4093 const PageState& state,
4113 bool check_history, 4094 bool is_history_navigation,
4114 int pending_history_list_offset, 4095 int current_history_list_offset,
4115 int32 page_id, 4096 int32 page_id,
4116 bool* is_reload, 4097 bool* is_reload,
4117 WebURLRequest::CachePolicy* cache_policy) { 4098 WebURLRequest::CachePolicy* cache_policy) {
4118 MaybeHandleDebugURL(url); 4099 MaybeHandleDebugURL(url);
4119 if (!render_view_->webview()) 4100 if (!render_view_->webview())
4120 return false; 4101 return false;
4121 4102
4122 FOR_EACH_OBSERVER( 4103 FOR_EACH_OBSERVER(
4123 RenderViewObserver, render_view_->observers_, Navigate(url)); 4104 RenderViewObserver, render_view_->observers_, Navigate(url));
4124 4105
4125 // If this is a stale back/forward (due to a recent navigation the browser 4106 // If this is a stale back/forward (due to a recent navigation the browser
4126 // didn't know about), ignore it. 4107 // didn't know about), ignore it. Only check if swapped in because if the
4127 if (check_history && render_view_->IsBackForwardToStaleEntry( 4108 // frame is swapped out, it won't commit before asking the browser. The value
4128 state, pending_history_list_offset, page_id, *is_reload)) 4109 // -999 is a special bogus current_history_list_offset that disables the stale
Charlie Reis 2014/12/05 22:51:15 Can we just leave the old check_history bool inste
Avi (use Gerrit) 2014/12/08 22:06:03 Done.
4110 // navigation detection; TODO(clamy): hook that up and remove it.
4111 if (!render_view_->is_swapped_out() && is_history_navigation &&
4112 current_history_list_offset != -999 &&
4113 render_view_->history_list_offset_ != current_history_list_offset) {
4129 return false; 4114 return false;
4115 }
4130 4116
4131 if (!is_swapped_out_ || frame_->parent()) 4117 if (!is_swapped_out_ || frame_->parent())
4132 return true; 4118 return true;
4133 4119
4134 // This is a swapped out main frame, so swap the renderer back in. 4120 // This is a swapped out main frame, so swap the renderer back in.
4135 // We marked the view as hidden when swapping the view out, so be sure to 4121 // We marked the view as hidden when swapping the view out, so be sure to
4136 // reset the visibility state before navigating to the new URL. 4122 // reset the visibility state before navigating to the new URL.
4137 render_view_->webview()->setVisibilityState( 4123 render_view_->webview()->setVisibilityState(
4138 render_view_->visibilityState(), false); 4124 render_view_->visibilityState(), false);
4139 4125
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
4242 4228
4243 #if defined(ENABLE_BROWSER_CDMS) 4229 #if defined(ENABLE_BROWSER_CDMS)
4244 RendererCdmManager* RenderFrameImpl::GetCdmManager() { 4230 RendererCdmManager* RenderFrameImpl::GetCdmManager() {
4245 if (!cdm_manager_) 4231 if (!cdm_manager_)
4246 cdm_manager_ = new RendererCdmManager(this); 4232 cdm_manager_ = new RendererCdmManager(this);
4247 return cdm_manager_; 4233 return cdm_manager_;
4248 } 4234 }
4249 #endif // defined(ENABLE_BROWSER_CDMS) 4235 #endif // defined(ENABLE_BROWSER_CDMS)
4250 4236
4251 } // namespace content 4237 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_frame_impl.h ('k') | content/renderer/render_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698