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

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: fixes, test 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
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
951 // If this is a stale back/forward (due to a recent navigation the browser
952 // didn't know about), ignore it. Only check if swapped in because if the
953 // frame is swapped out, it won't commit before asking the browser.
954 bool is_history_navigation = params.commit_params.page_state.IsValid();
955 if (!render_view_->is_swapped_out() && is_history_navigation &&
956 render_view_->history_list_offset_ !=
957 params.current_history_list_offset) {
958 return;
959 }
960
950 bool is_reload = 961 bool is_reload =
951 RenderViewImpl::IsReload(params.common_params.navigation_type); 962 RenderViewImpl::IsReload(params.common_params.navigation_type);
952 WebURLRequest::CachePolicy cache_policy = 963 WebURLRequest::CachePolicy cache_policy =
953 WebURLRequest::UseProtocolCachePolicy; 964 WebURLRequest::UseProtocolCachePolicy;
954 if (!RenderFrameImpl::PrepareRenderViewForNavigation( 965 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
955 params.common_params.url, params.common_params.navigation_type, 966 params.common_params.url, params.common_params.navigation_type,
956 params.commit_params.page_state, true, params.pending_history_list_offset, 967 params.commit_params.page_state, params.page_id, &is_reload,
957 params.page_id, &is_reload, &cache_policy)) { 968 &cache_policy)) {
958 return; 969 return;
959 } 970 }
960 971
961 int pending_history_list_offset = params.pending_history_list_offset; 972 render_view_->history_list_offset_ = params.current_history_list_offset;
962 int current_history_list_offset = params.current_history_list_offset; 973 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) { 974 if (params.should_clear_history_list) {
965 CHECK_EQ(pending_history_list_offset, -1); 975 CHECK_EQ(-1, render_view_->history_list_offset_);
966 CHECK_EQ(current_history_list_offset, -1); 976 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 } 977 }
980 978
981 GetContentClient()->SetActiveURL(params.common_params.url); 979 GetContentClient()->SetActiveURL(params.common_params.url);
982 980
983 WebFrame* frame = frame_; 981 WebFrame* frame = frame_;
984 if (!params.frame_to_navigate.empty()) { 982 if (!params.frame_to_navigate.empty()) {
985 // TODO(nasko): Move this lookup to the browser process. 983 // TODO(nasko): Move this lookup to the browser process.
986 frame = render_view_->webview()->findFrameByName( 984 frame = render_view_->webview()->findFrameByName(
987 WebString::fromUTF8(params.frame_to_navigate)); 985 WebString::fromUTF8(params.frame_to_navigate));
988 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate; 986 CHECK(frame) << "Invalid frame name passed: " << params.frame_to_navigate;
(...skipping 17 matching lines...) Expand all
1006 bool reload_original_url = 1004 bool reload_original_url =
1007 (params.common_params.navigation_type == 1005 (params.common_params.navigation_type ==
1008 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL); 1006 FrameMsg_Navigate_Type::RELOAD_ORIGINAL_REQUEST_URL);
1009 bool ignore_cache = (params.common_params.navigation_type == 1007 bool ignore_cache = (params.common_params.navigation_type ==
1010 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE); 1008 FrameMsg_Navigate_Type::RELOAD_IGNORING_CACHE);
1011 1009
1012 if (reload_original_url) 1010 if (reload_original_url)
1013 frame->reloadWithOverrideURL(params.common_params.url, true); 1011 frame->reloadWithOverrideURL(params.common_params.url, true);
1014 else 1012 else
1015 frame->reload(ignore_cache); 1013 frame->reload(ignore_cache);
1016 } else if (params.commit_params.page_state.IsValid()) { 1014 } else if (is_history_navigation) {
1017 // We must know the page ID of the page we are navigating back to. 1015 // We must know the page ID of the page we are navigating back to.
1018 DCHECK_NE(params.page_id, -1); 1016 DCHECK_NE(params.page_id, -1);
1019 scoped_ptr<HistoryEntry> entry = 1017 scoped_ptr<HistoryEntry> entry =
1020 PageStateToHistoryEntry(params.commit_params.page_state); 1018 PageStateToHistoryEntry(params.commit_params.page_state);
1021 if (entry) { 1019 if (entry) {
1022 // Ensure we didn't save the swapped out URL in UpdateState, since the 1020 // Ensure we didn't save the swapped out URL in UpdateState, since the
1023 // browser should never be telling us to navigate to swappedout://. 1021 // browser should never be telling us to navigate to swappedout://.
1024 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL)); 1022 CHECK(entry->root().urlString() != WebString::fromUTF8(kSwappedOutURL));
1025 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy); 1023 render_view_->history_controller()->GoToEntry(entry.Pass(), cache_policy);
1026 } 1024 }
(...skipping 1318 matching lines...) Expand 10 before | Expand all | Expand 10 after
2345 render_view_->webview()->resetScrollAndScaleState(); 2343 render_view_->webview()->resetScrollAndScaleState();
2346 internal_data->set_must_reset_scroll_and_scale_state(false); 2344 internal_data->set_must_reset_scroll_and_scale_state(false);
2347 } 2345 }
2348 internal_data->set_use_error_page(false); 2346 internal_data->set_use_error_page(false);
2349 2347
2350 bool is_new_navigation = commit_type == blink::WebStandardCommit; 2348 bool is_new_navigation = commit_type == blink::WebStandardCommit;
2351 if (is_new_navigation) { 2349 if (is_new_navigation) {
2352 // We bump our Page ID to correspond with the new session history entry. 2350 // We bump our Page ID to correspond with the new session history entry.
2353 render_view_->page_id_ = render_view_->next_page_id_++; 2351 render_view_->page_id_ = render_view_->next_page_id_++;
2354 2352
2355 // Don't update history_page_ids_ (etc) for kSwappedOutURL, since 2353 // 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 2354 // 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 2355 // never come back to kSwappedOutURL. Note that we have to call
2358 // UpdateSessionHistory and update page_id_ even in this case, so that 2356 // 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 2357 // 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. 2358 // state update to the wrong entry when we swap back in.
2361 if (GetLoadingUrl() != GURL(kSwappedOutURL)) { 2359 if (GetLoadingUrl() != GURL(kSwappedOutURL)) {
2362 // Advance our offset in session history, applying the length limit. 2360 // Advance our offset in session history, applying the length limit.
2363 // There is now no forward history. 2361 // There is now no forward history.
2364 render_view_->history_list_offset_++; 2362 render_view_->history_list_offset_++;
2365 if (render_view_->history_list_offset_ >= kMaxSessionHistoryEntries) 2363 if (render_view_->history_list_offset_ >= kMaxSessionHistoryEntries)
2366 render_view_->history_list_offset_ = kMaxSessionHistoryEntries - 1; 2364 render_view_->history_list_offset_ = kMaxSessionHistoryEntries - 1;
2367 render_view_->history_list_length_ = 2365 render_view_->history_list_length_ =
2368 render_view_->history_list_offset_ + 1; 2366 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 } 2367 }
2374 } else { 2368 } else {
2375 // Inspect the navigation_state on this frame to see if the navigation 2369 // Inspect the navigation_state on this frame to see if the navigation
2376 // corresponds to a session history navigation... Note: |frame| may or 2370 // corresponds to a session history navigation... Note: |frame| may or
2377 // may not be the toplevel frame, but for the case of capturing session 2371 // 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 2372 // 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 2373 // we've seen this commit before so that only capture session history once
2380 // per navigation. 2374 // per navigation.
2381 // 2375 //
2382 // Note that we need to check if the page ID changed. In the case of a 2376 // 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 2377 // reload, the page ID doesn't change, and UpdateSessionHistory gets the
2384 // previous URL and the current page ID, which would be wrong. 2378 // previous URL and the current page ID, which would be wrong.
2385 if (navigation_state->pending_page_id() != -1 && 2379 if (navigation_state->pending_page_id() != -1 &&
2386 navigation_state->pending_page_id() != render_view_->page_id_ && 2380 navigation_state->pending_page_id() != render_view_->page_id_ &&
2387 !navigation_state->request_committed()) { 2381 !navigation_state->request_committed()) {
2388 // This is a successful session history navigation! 2382 // This is a successful session history navigation!
2389 render_view_->page_id_ = navigation_state->pending_page_id(); 2383 render_view_->page_id_ = navigation_state->pending_page_id();
2390 2384
2391 render_view_->history_list_offset_ = 2385 render_view_->history_list_offset_ =
2392 navigation_state->pending_history_list_offset(); 2386 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 } 2387 }
2402 } 2388 }
2403 2389
2404 bool sent = Send( 2390 bool sent = Send(
2405 new FrameHostMsg_DidAssignPageId(routing_id_, render_view_->page_id_)); 2391 new FrameHostMsg_DidAssignPageId(routing_id_, render_view_->page_id_));
2406 CHECK(sent); // http://crbug.com/407376 2392 CHECK(sent); // http://crbug.com/407376
2407 2393
2408 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_, 2394 FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_,
2409 DidCommitProvisionalLoad(frame, is_new_navigation)); 2395 DidCommitProvisionalLoad(frame, is_new_navigation));
2410 FOR_EACH_OBSERVER(RenderFrameObserver, observers_, 2396 FOR_EACH_OBSERVER(RenderFrameObserver, observers_,
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after
3681 const GURL& stream_url, 3667 const GURL& stream_url,
3682 const CommonNavigationParams& common_params, 3668 const CommonNavigationParams& common_params,
3683 const CommitNavigationParams& commit_params) { 3669 const CommitNavigationParams& commit_params) {
3684 CHECK(CommandLine::ForCurrentProcess()->HasSwitch( 3670 CHECK(CommandLine::ForCurrentProcess()->HasSwitch(
3685 switches::kEnableBrowserSideNavigation)); 3671 switches::kEnableBrowserSideNavigation));
3686 bool is_reload = false; 3672 bool is_reload = false;
3687 WebURLRequest::CachePolicy cache_policy = 3673 WebURLRequest::CachePolicy cache_policy =
3688 WebURLRequest::UseProtocolCachePolicy; 3674 WebURLRequest::UseProtocolCachePolicy;
3689 if (!RenderFrameImpl::PrepareRenderViewForNavigation( 3675 if (!RenderFrameImpl::PrepareRenderViewForNavigation(
3690 common_params.url, common_params.navigation_type, 3676 common_params.url, common_params.navigation_type,
3691 commit_params.page_state, false, -1, -1, &is_reload, &cache_policy)) { 3677 commit_params.page_state, -1, &is_reload, &cache_policy)) {
3692 return; 3678 return;
3693 } 3679 }
3694 3680
3695 GetContentClient()->SetActiveURL(common_params.url); 3681 GetContentClient()->SetActiveURL(common_params.url);
3696 3682
3697 // Create a WebURLRequest that blink can use to get access to the body of the 3683 // 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 3684 // response through a stream in the browser. Blink will then commit the
3699 // navigation. 3685 // navigation.
3700 // TODO(clamy): Have the navigation commit directly, without going through 3686 // TODO(clamy): Have the navigation commit directly, without going through
3701 // loading a WebURLRequest. 3687 // loading a WebURLRequest.
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
4103 #else 4089 #else
4104 return scoped_ptr<MediaStreamRendererFactory>( 4090 return scoped_ptr<MediaStreamRendererFactory>(
4105 static_cast<MediaStreamRendererFactory*>(NULL)); 4091 static_cast<MediaStreamRendererFactory*>(NULL));
4106 #endif 4092 #endif
4107 } 4093 }
4108 4094
4109 bool RenderFrameImpl::PrepareRenderViewForNavigation( 4095 bool RenderFrameImpl::PrepareRenderViewForNavigation(
4110 const GURL& url, 4096 const GURL& url,
4111 FrameMsg_Navigate_Type::Value navigate_type, 4097 FrameMsg_Navigate_Type::Value navigate_type,
4112 const PageState& state, 4098 const PageState& state,
4113 bool check_history,
4114 int pending_history_list_offset,
4115 int32 page_id, 4099 int32 page_id,
4116 bool* is_reload, 4100 bool* is_reload,
4117 WebURLRequest::CachePolicy* cache_policy) { 4101 WebURLRequest::CachePolicy* cache_policy) {
4118 MaybeHandleDebugURL(url); 4102 MaybeHandleDebugURL(url);
4119 if (!render_view_->webview()) 4103 if (!render_view_->webview())
4120 return false; 4104 return false;
4121 4105
4122 FOR_EACH_OBSERVER( 4106 FOR_EACH_OBSERVER(
4123 RenderViewObserver, render_view_->observers_, Navigate(url)); 4107 RenderViewObserver, render_view_->observers_, Navigate(url));
4124 4108
4125 // If this is a stale back/forward (due to a recent navigation the browser
4126 // didn't know about), ignore it.
4127 if (check_history && render_view_->IsBackForwardToStaleEntry(
4128 state, pending_history_list_offset, page_id, *is_reload))
4129 return false;
4130
4131 if (!is_swapped_out_ || frame_->parent()) 4109 if (!is_swapped_out_ || frame_->parent())
4132 return true; 4110 return true;
4133 4111
4134 // This is a swapped out main frame, so swap the renderer back in. 4112 // 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 4113 // 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. 4114 // reset the visibility state before navigating to the new URL.
4137 render_view_->webview()->setVisibilityState( 4115 render_view_->webview()->setVisibilityState(
4138 render_view_->visibilityState(), false); 4116 render_view_->visibilityState(), false);
4139 4117
4140 // If this is an attempt to reload while we are swapped out, we should not 4118 // If this is an attempt to reload while we are swapped out, we should not
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
4242 4220
4243 #if defined(ENABLE_BROWSER_CDMS) 4221 #if defined(ENABLE_BROWSER_CDMS)
4244 RendererCdmManager* RenderFrameImpl::GetCdmManager() { 4222 RendererCdmManager* RenderFrameImpl::GetCdmManager() {
4245 if (!cdm_manager_) 4223 if (!cdm_manager_)
4246 cdm_manager_ = new RendererCdmManager(this); 4224 cdm_manager_ = new RendererCdmManager(this);
4247 return cdm_manager_; 4225 return cdm_manager_;
4248 } 4226 }
4249 #endif // defined(ENABLE_BROWSER_CDMS) 4227 #endif // defined(ENABLE_BROWSER_CDMS)
4250 4228
4251 } // namespace content 4229 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698