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

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: update 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 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 #endif 941 #endif
942 IPC_END_MESSAGE_MAP() 942 IPC_END_MESSAGE_MAP()
943 943
944 return handled; 944 return handled;
945 } 945 }
946 946
947 void RenderFrameImpl::OnNavigate(const FrameMsg_Navigate_Params& params) { 947 void RenderFrameImpl::OnNavigate(const FrameMsg_Navigate_Params& params) {
948 TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate", 948 TRACE_EVENT2("navigation", "RenderFrameImpl::OnNavigate",
949 "id", routing_id_, 949 "id", routing_id_,
950 "url", params.common_params.url.possibly_invalid_spec()); 950 "url", params.common_params.url.possibly_invalid_spec());
951
951 bool is_reload = 952 bool is_reload =
952 RenderViewImpl::IsReload(params.common_params.navigation_type); 953 RenderViewImpl::IsReload(params.common_params.navigation_type);
954 bool is_history_navigation = params.commit_params.page_state.IsValid();
953 WebURLRequest::CachePolicy cache_policy = 955 WebURLRequest::CachePolicy cache_policy =
954 WebURLRequest::UseProtocolCachePolicy; 956 WebURLRequest::UseProtocolCachePolicy;
955 if (!RenderFrameImpl::PrepareRenderViewForNavigation( 957 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
956 params.common_params.url, params.common_params.navigation_type, 958 params.common_params.url, params.common_params.navigation_type,
957 params.commit_params.page_state, true, params.pending_history_list_offset, 959 params.commit_params.page_state, true, is_history_navigation,
958 params.page_id, &is_reload, &cache_policy)) { 960 params.current_history_list_offset, params.page_id, &is_reload,
961 &cache_policy)) {
959 Send(new FrameHostMsg_DidDropNavigation(routing_id_)); 962 Send(new FrameHostMsg_DidDropNavigation(routing_id_));
960 return; 963 return;
961 } 964 }
962 965
963 int pending_history_list_offset = params.pending_history_list_offset; 966 render_view_->history_list_offset_ = params.current_history_list_offset;
964 int current_history_list_offset = params.current_history_list_offset; 967 render_view_->history_list_length_ = params.current_history_list_length;
965 int current_history_list_length = params.current_history_list_length;
966 if (params.should_clear_history_list) { 968 if (params.should_clear_history_list) {
967 CHECK_EQ(pending_history_list_offset, -1); 969 CHECK_EQ(-1, render_view_->history_list_offset_);
968 CHECK_EQ(current_history_list_offset, -1); 970 CHECK_EQ(0, render_view_->history_list_length_);
969 CHECK_EQ(current_history_list_length, 0);
970 }
971 render_view_->history_list_offset_ = current_history_list_offset;
972 render_view_->history_list_length_ = current_history_list_length;
973 if (render_view_->history_list_length_ >= 0) {
974 render_view_->history_page_ids_.resize(
975 render_view_->history_list_length_, -1);
976 }
977 if (pending_history_list_offset >= 0 &&
978 pending_history_list_offset < render_view_->history_list_length_) {
979 render_view_->history_page_ids_[pending_history_list_offset] =
980 params.page_id;
981 } 971 }
982 972
983 GetContentClient()->SetActiveURL(params.common_params.url); 973 GetContentClient()->SetActiveURL(params.common_params.url);
984 974
985 WebFrame* frame = frame_; 975 WebFrame* frame = frame_;
986 if (!params.frame_to_navigate.empty()) { 976 if (!params.frame_to_navigate.empty()) {
987 // TODO(nasko): Move this lookup to the browser process. 977 // TODO(nasko): Move this lookup to the browser process.
988 frame = render_view_->webview()->findFrameByName( 978 frame = render_view_->webview()->findFrameByName(
989 WebString::fromUTF8(params.frame_to_navigate)); 979 WebString::fromUTF8(params.frame_to_navigate));
990 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; 980 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate;
(...skipping 17 matching lines...) Expand all
1008 bool reload_original_url = 998 bool reload_original_url =
1009 (params.common_params.navigation_type == 999 (params.common_params.navigation_type ==
1010 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); 1000 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
1011 bool ignore_cache = (params.common_params.navigation_type == 1001 bool ignore_cache = (params.common_params.navigation_type ==
1012 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); 1002 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
1013 1003
1014 if (reload_original_url) 1004 if (reload_original_url)
1015 frame->reloadWithOverrideURL(params.common_params.url, true); 1005 frame->reloadWithOverrideURL(params.common_params.url, true);
1016 else 1006 else
1017 frame->reload(ignore_cache); 1007 frame->reload(ignore_cache);
1018 } else if (params.commit_params.page_state.IsValid()) { 1008 } else if (is_history_navigation) {
1019 // We must know the page ID of the page we are navigating back to. 1009 // We must know the page ID of the page we are navigating back to.
1020 DCHECK_NE(params.page_id, -1); 1010 DCHECK_NE(params.page_id, -1);
1021 scoped_ptr<HistoryEntry> entry = 1011 scoped_ptr<HistoryEntry> entry =
1022 PageStateToHistoryEntry(params.commit_params.page_state); 1012 PageStateToHistoryEntry(params.commit_params.page_state);
1023 if (entry) { 1013 if (entry) {
1024 // Ensure we didn't save the swapped out URL in UpdateState, since the 1014 // Ensure we didn't save the swapped out URL in UpdateState, since the
1025 // browser should never be telling us to navigate to swappedout://. 1015 // browser should never be telling us to navigate to swappedout://.
1026 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); 1016 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL));
1027 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy); 1017 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy);
1028 } 1018 }
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 render_view_->webview()->resetScrollAndScaleState(); 2350 render_view_->webview()->resetScrollAndScaleState();
2361 internal_data->set_must_reset_scroll_and_scale_state(false); 2351 internal_data->set_must_reset_scroll_and_scale_state(false);
2362 } 2352 }
2363 internal_data->set_use_error_page(false); 2353 internal_data->set_use_error_page(false);
2364 2354
2365 bool is_new_navigation = commit_type == blink::WebStandardCommit; 2355 bool is_new_navigation = commit_type == blink::WebStandardCommit;
2366 if (is_new_navigation) { 2356 if (is_new_navigation) {
2367 // We bump our Page ID to correspond with the new session history entry. 2357 // We bump our Page ID to correspond with the new session history entry.
2368 render_view_->page_id_ = render_view_->next_page_id_++; 2358 render_view_->page_id_ = render_view_->next_page_id_++;
2369 2359
2370 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since 2360 // Don't update history list values for kSwappedOutURL, since
2371 // we don't want to forget the entry that was there, and since we will 2361 // we don't want to forget the entry that was there, and since we will
2372 // never come back to kSwappedOutURL. Note that we have to call 2362 // never come back to kSwappedOutURL. Note that we have to call
2373 // UpdateSessionHistory and update page_id_ even in this case, so that 2363 // UpdateSessionHistory and update page_id_ even in this case, so that
2374 // the current entry gets a state update and so that we don't send a 2364 // the current entry gets a state update and so that we don't send a
2375 // state update to the wrong entry when we swap back in. 2365 // state update to the wrong entry when we swap back in.
2376 if (GetLoadingUrl() != GURL(kSwappedOutURL)) { 2366 if (GetLoadingUrl() != GURL(kSwappedOutURL)) {
2377 // Advance our offset in session history, applying the length limit. 2367 // Advance our offset in session history, applying the length limit.
2378 // There is now no forward history. 2368 // There is now no forward history.
2379 render_view_->history_list_offset_++; 2369 render_view_->history_list_offset_++;
2380 if (render_view_->history_list_offset_ >= kMaxSessionHistoryEntries) 2370 if (render_view_->history_list_offset_ >= kMaxSessionHistoryEntries)
2381 render_view_->history_list_offset_ = kMaxSessionHistoryEntries - 1; 2371 render_view_->history_list_offset_ = kMaxSessionHistoryEntries - 1;
2382 render_view_->history_list_length_ = 2372 render_view_->history_list_length_ =
2383 render_view_->history_list_offset_ + 1; 2373 render_view_->history_list_offset_ + 1;
2384 render_view_->history_page_ids_.resize(
2385 render_view_->history_list_length_, -1);
2386 render_view_->history_page_ids_[render_view_->history_list_offset_] =
2387 render_view_->page_id_;
2388 } 2374 }
2389 } else { 2375 } else {
2390 // Inspect the navigation_state on this frame to see if the navigation 2376 // Inspect the navigation_state on this frame to see if the navigation
2391 // corresponds to a session history navigation... Note: |frame| may or 2377 // corresponds to a session history navigation... Note: |frame| may or
2392 // may not be the toplevel frame, but for the case of capturing session 2378 // may not be the toplevel frame, but for the case of capturing session
2393 // history, the first committed frame suffices. We keep track of whether 2379 // history, the first committed frame suffices. We keep track of whether
2394 // we've seen this commit before so that only capture session history once 2380 // we've seen this commit before so that only capture session history once
2395 // per navigation. 2381 // per navigation.
2396 // 2382 //
2397 // Note that we need to check if the page ID changed. In the case of a 2383 // Note that we need to check if the page ID changed. In the case of a
2398 // reload, the page ID doesn't change, and UpdateSessionHistory gets the 2384 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2399 // previous URL and the current page ID, which would be wrong. 2385 // previous URL and the current page ID, which would be wrong.
2400 if (navigation_state->pending_page_id() != -1 && 2386 if (navigation_state->pending_page_id() != -1 &&
2401 navigation_state->pending_page_id() != render_view_->page_id_ && 2387 navigation_state->pending_page_id() != render_view_->page_id_ &&
2402 !navigation_state->request_committed()) { 2388 !navigation_state->request_committed()) {
2403 // This is a successful session history navigation! 2389 // This is a successful session history navigation!
2404 render_view_->page_id_ = navigation_state->pending_page_id(); 2390 render_view_->page_id_ = navigation_state->pending_page_id();
2405 2391
2406 render_view_->history_list_offset_ = 2392 render_view_->history_list_offset_ =
2407 navigation_state->pending_history_list_offset(); 2393 navigation_state->pending_history_list_offset();
2408
2409 // If the history list is valid, our list of page IDs should be correct.
2410 DCHECK(render_view_->history_list_length_ <= 0 ||
2411 render_view_->history_list_offset_ < 0 ||
2412 render_view_->history_list_offset_ >=
2413 render_view_->history_list_length_ ||
2414 render_view_->history_page_ids_[render_view_->history_list_offset_]
2415 == render_view_->page_id_);
2416 } 2394 }
2417 } 2395 }
2418 2396
2419 bool sent = Send( 2397 bool sent = Send(
2420 new FrameHostMsg_DidAssignPageId(routing_id_, render_view_->page_id_)); 2398 new FrameHostMsg_DidAssignPageId(routing_id_, render_view_->page_id_));
2421 CHECK(sent); // http://crbug.com/407376 2399 CHECK(sent); // http://crbug.com/407376
2422 2400
2423 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_, 2401 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_,
2424 DidCommitProvisionalLoad(frame, is_new_navigation)); 2402 DidCommitProvisionalLoad(frame, is_new_navigation));
2425 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, 2403 FOR_EACH_OBSERVER(RenderFrameObserver, observers_,
(...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after
3702 3680
3703 // PlzNavigate 3681 // PlzNavigate
3704 void RenderFrameImpl::OnCommitNavigation( 3682 void RenderFrameImpl::OnCommitNavigation(
3705 const ResourceResponseHead& response, 3683 const ResourceResponseHead& response,
3706 const GURL& stream_url, 3684 const GURL& stream_url,
3707 const CommonNavigationParams& common_params, 3685 const CommonNavigationParams& common_params,
3708 const CommitNavigationParams& commit_params) { 3686 const CommitNavigationParams& commit_params) {
3709 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( 3687 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
3710 switches::kEnableBrowserSideNavigation)); 3688 switches::kEnableBrowserSideNavigation));
3711 bool is_reload = false; 3689 bool is_reload = false;
3690 bool is_history_navigation = commit_params.page_state.IsValid();
3712 WebURLRequest::CachePolicy cache_policy = 3691 WebURLRequest::CachePolicy cache_policy =
3713 WebURLRequest::UseProtocolCachePolicy; 3692 WebURLRequest::UseProtocolCachePolicy;
3714 if (!RenderFrameImpl::PrepareRenderViewForNavigation( 3693 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
3715 common_params.url, common_params.navigation_type, 3694 common_params.url, common_params.navigation_type,
3716 commit_params.page_state, false, -1, -1, &is_reload, &cache_policy)) { 3695 commit_params.page_state, false /* check_for_stale_navigation */,
3696 is_history_navigation, -1 /* current_history_list_offset; TODO(clamy)*/,
3697 -1, &is_reload, &cache_policy)) {
3717 return; 3698 return;
3718 } 3699 }
3719 3700
3720 GetContentClient()->SetActiveURL(common_params.url); 3701 GetContentClient()->SetActiveURL(common_params.url);
3721 3702
3722 // Create a WebURLRequest that blink can use to get access to the body of the 3703 // Create a WebURLRequest that blink can use to get access to the body of the
3723 // response through a stream in the browser. Blink will then commit the 3704 // response through a stream in the browser. Blink will then commit the
3724 // navigation. 3705 // navigation.
3725 // TODO(clamy): Have the navigation commit directly, without going through 3706 // TODO(clamy): Have the navigation commit directly, without going through
3726 // loading a WebURLRequest. 3707 // loading a WebURLRequest.
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
4128 #else 4109 #else
4129 return scoped_ptr<MediaStreamRendererFactory>( 4110 return scoped_ptr<MediaStreamRendererFactory>(
4130 static_cast<MediaStreamRendererFactory*>(NULL)); 4111 static_cast<MediaStreamRendererFactory*>(NULL));
4131 #endif 4112 #endif
4132 } 4113 }
4133 4114
4134 bool RenderFrameImpl::PrepareRenderViewForNavigation( 4115 bool RenderFrameImpl::PrepareRenderViewForNavigation(
4135 const GURL& url, 4116 const GURL& url,
4136 FrameMsg_Navigate_Type::Value navigate_type, 4117 FrameMsg_Navigate_Type::Value navigate_type,
4137 const PageState& state, 4118 const PageState& state,
4138 bool check_history, 4119 bool check_for_stale_navigation,
4139 int pending_history_list_offset, 4120 bool is_history_navigation,
4121 int current_history_list_offset,
4140 int32 page_id, 4122 int32 page_id,
4141 bool* is_reload, 4123 bool* is_reload,
4142 WebURLRequest::CachePolicy* cache_policy) { 4124 WebURLRequest::CachePolicy* cache_policy) {
4143 MaybeHandleDebugURL(url); 4125 MaybeHandleDebugURL(url);
4144 if (!render_view_->webview()) 4126 if (!render_view_->webview())
4145 return false; 4127 return false;
4146 4128
4147 FOR_EACH_OBSERVER( 4129 FOR_EACH_OBSERVER(
4148 RenderViewObserver, render_view_->observers_, Navigate(url)); 4130 RenderViewObserver, render_view_->observers_, Navigate(url));
4149 4131
4150 // If this is a stale back/forward (due to a recent navigation the browser 4132 // If this is a stale back/forward (due to a recent navigation the browser
4151 // didn't know about), ignore it. 4133 // didn't know about), ignore it. Only check if swapped in because if the
4152 if (check_history && render_view_->IsBackForwardToStaleEntry( 4134 // frame is swapped out, it won't commit before asking the browser.
4153 state, pending_history_list_offset, page_id, *is_reload)) 4135 // TODO(clamy): remove check_for_stale_navigation
4136 if (check_for_stale_navigation &&
4137 !render_view_->is_swapped_out() && is_history_navigation &&
4138 render_view_->history_list_offset_ != current_history_list_offset) {
4154 return false; 4139 return false;
4140 }
4155 4141
4156 if (!is_swapped_out_ || frame_->parent()) 4142 if (!is_swapped_out_ || frame_->parent())
4157 return true; 4143 return true;
4158 4144
4159 // This is a swapped out main frame, so swap the renderer back in. 4145 // This is a swapped out main frame, so swap the renderer back in.
4160 // We marked the view as hidden when swapping the view out, so be sure to 4146 // We marked the view as hidden when swapping the view out, so be sure to
4161 // reset the visibility state before navigating to the new URL. 4147 // reset the visibility state before navigating to the new URL.
4162 render_view_->webview()->setVisibilityState( 4148 render_view_->webview()->setVisibilityState(
4163 render_view_->visibilityState(), false); 4149 render_view_->visibilityState(), false);
4164 4150
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
4267 4253
4268 #if defined(ENABLE_BROWSER_CDMS) 4254 #if defined(ENABLE_BROWSER_CDMS)
4269 RendererCdmManager* RenderFrameImpl::GetCdmManager() { 4255 RendererCdmManager* RenderFrameImpl::GetCdmManager() {
4270 if (!cdm_manager_) 4256 if (!cdm_manager_)
4271 cdm_manager_ = new RendererCdmManager(this); 4257 cdm_manager_ = new RendererCdmManager(this);
4272 return cdm_manager_; 4258 return cdm_manager_;
4273 } 4259 }
4274 #endif // defined(ENABLE_BROWSER_CDMS) 4260 #endif // defined(ENABLE_BROWSER_CDMS)
4275 4261
4276 } // namespace content 4262 } // 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