Commit 2ee9c7db authored by Avi Drissman's avatar Avi Drissman

Keep a copy of page id in RenderViewHost.

Note that this copy may not be completely in sync with the renderer’s copy. That’s OK.

BUG=407376
TEST=no visible change
R=creis@chromium.org, nasko@chromium.org

Review URL: https://codereview.chromium.org/551443002

Cr-Commit-Position: refs/heads/master@{#293771}
parent cc21ae46
...@@ -1003,7 +1003,7 @@ TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { ...@@ -1003,7 +1003,7 @@ TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) {
const GURL kExistingURL("http://foo/eh"); const GURL kExistingURL("http://foo/eh");
controller.LoadURL(kExistingURL, content::Referrer(), controller.LoadURL(kExistingURL, content::Referrer(),
content::PAGE_TRANSITION_TYPED, std::string()); content::PAGE_TRANSITION_TYPED, std::string());
main_test_rfh()->SendNavigate(0, kExistingURL); main_test_rfh()->SendNavigate(1, kExistingURL);
EXPECT_EQ(1U, navigation_entry_committed_counter_); EXPECT_EQ(1U, navigation_entry_committed_counter_);
navigation_entry_committed_counter_ = 0; navigation_entry_committed_counter_ = 0;
...@@ -1031,7 +1031,7 @@ TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { ...@@ -1031,7 +1031,7 @@ TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) {
const GURL kRedirectURL("http://foo/see"); const GURL kRedirectURL("http://foo/see");
main_test_rfh()->OnMessageReceived( main_test_rfh()->OnMessageReceived(
FrameHostMsg_DidRedirectProvisionalLoad(0, // routing_id FrameHostMsg_DidRedirectProvisionalLoad(0, // routing_id
-1, // pending page_id 1, // pending page_id
kNewURL, // old url kNewURL, // old url
kRedirectURL)); // new url kRedirectURL)); // new url
......
...@@ -346,7 +346,7 @@ bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { ...@@ -346,7 +346,7 @@ bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) {
IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError, IPC_MESSAGE_HANDLER(FrameHostMsg_DidFailLoadWithError,
OnDidFailLoadWithError) OnDidFailLoadWithError)
IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad, IPC_MESSAGE_HANDLER_GENERIC(FrameHostMsg_DidCommitProvisionalLoad,
OnNavigate(msg)) OnDidCommitProvisionalLoad(msg))
IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL) IPC_MESSAGE_HANDLER(FrameHostMsg_OpenURL, OnOpenURL)
IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted, IPC_MESSAGE_HANDLER(FrameHostMsg_DocumentOnLoadCompleted,
OnDocumentOnLoadCompleted) OnDocumentOnLoadCompleted)
...@@ -362,6 +362,7 @@ bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) { ...@@ -362,6 +362,7 @@ bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) {
IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument, IPC_MESSAGE_HANDLER(FrameHostMsg_DidAccessInitialDocument,
OnDidAccessInitialDocument) OnDidAccessInitialDocument)
IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener) IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisownOpener, OnDidDisownOpener)
IPC_MESSAGE_HANDLER(FrameHostMsg_DidAssignPageId, OnDidAssignPageId)
IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle) IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateTitle, OnUpdateTitle)
IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding) IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateEncoding, OnUpdateEncoding)
IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation, IPC_MESSAGE_HANDLER(FrameHostMsg_BeginNavigation,
...@@ -588,7 +589,7 @@ void RenderFrameHostImpl::OnDidRedirectProvisionalLoad( ...@@ -588,7 +589,7 @@ void RenderFrameHostImpl::OnDidRedirectProvisionalLoad(
// level frame. If the user explicitly requests a subframe navigation, we will // level frame. If the user explicitly requests a subframe navigation, we will
// get a new page_id because we need to create a new navigation entry for that // get a new page_id because we need to create a new navigation entry for that
// action. // action.
void RenderFrameHostImpl::OnNavigate(const IPC::Message& msg) { void RenderFrameHostImpl::OnDidCommitProvisionalLoad(const IPC::Message& msg) {
// Read the parameters out of the IPC message directly to avoid making another // Read the parameters out of the IPC message directly to avoid making another
// copy when we filter the URLs. // copy when we filter the URLs.
PickleIterator iter(msg); PickleIterator iter(msg);
...@@ -596,7 +597,7 @@ void RenderFrameHostImpl::OnNavigate(const IPC::Message& msg) { ...@@ -596,7 +597,7 @@ void RenderFrameHostImpl::OnNavigate(const IPC::Message& msg) {
if (!IPC::ParamTraits<FrameHostMsg_DidCommitProvisionalLoad_Params>:: if (!IPC::ParamTraits<FrameHostMsg_DidCommitProvisionalLoad_Params>::
Read(&msg, &iter, &validated_params)) Read(&msg, &iter, &validated_params))
return; return;
TRACE_EVENT1("navigation", "RenderFrameHostImpl::OnNavigate", TRACE_EVENT1("navigation", "RenderFrameHostImpl::OnDidCommitProvisionalLoad",
"url", validated_params.url.possibly_invalid_spec()); "url", validated_params.url.possibly_invalid_spec());
// If we're waiting for a cross-site beforeunload ack from this renderer and // If we're waiting for a cross-site beforeunload ack from this renderer and
...@@ -745,13 +746,13 @@ void RenderFrameHostImpl::OnBeforeUnloadACK( ...@@ -745,13 +746,13 @@ void RenderFrameHostImpl::OnBeforeUnloadACK(
render_view_host_->decrement_in_flight_event_count(); render_view_host_->decrement_in_flight_event_count();
render_view_host_->StopHangMonitorTimeout(); render_view_host_->StopHangMonitorTimeout();
// If this renderer navigated while the beforeunload request was in flight, we // If this renderer navigated while the beforeunload request was in flight, we
// may have cleared this state in OnNavigate, in which case we can ignore // may have cleared this state in OnDidCommitProvisionalLoad, in which case we
// this message. // can ignore this message.
// However renderer might also be swapped out but we still want to proceed // However renderer might also be swapped out but we still want to proceed
// with navigation, otherwise it would block future navigations. This can // with navigation, otherwise it would block future navigations. This can
// happen when pending cross-site navigation is canceled by a second one just // happen when pending cross-site navigation is canceled by a second one just
// before OnNavigate while current RVH is waiting for commit but second // before OnDidCommitProvisionalLoad while current RVH is waiting for commit
// navigation is started from the beginning. // but second navigation is started from the beginning.
if (!render_view_host_->is_waiting_for_beforeunload_ack_) { if (!render_view_host_->is_waiting_for_beforeunload_ack_) {
return; return;
} }
...@@ -928,6 +929,12 @@ void RenderFrameHostImpl::OnDidDisownOpener() { ...@@ -928,6 +929,12 @@ void RenderFrameHostImpl::OnDidDisownOpener() {
delegate_->DidDisownOpener(this); delegate_->DidDisownOpener(this);
} }
void RenderFrameHostImpl::OnDidAssignPageId(int32 page_id) {
// Update the RVH's current page ID so that future IPCs from the renderer
// correspond to the new page.
render_view_host_->page_id_ = page_id;
}
void RenderFrameHostImpl::OnUpdateTitle( void RenderFrameHostImpl::OnUpdateTitle(
int32 page_id, int32 page_id,
const base::string16& title, const base::string16& title,
......
...@@ -323,7 +323,7 @@ class CONTENT_EXPORT RenderFrameHostImpl ...@@ -323,7 +323,7 @@ class CONTENT_EXPORT RenderFrameHostImpl
void OnDidRedirectProvisionalLoad(int32 page_id, void OnDidRedirectProvisionalLoad(int32 page_id,
const GURL& source_url, const GURL& source_url,
const GURL& target_url); const GURL& target_url);
void OnNavigate(const IPC::Message& msg); void OnDidCommitProvisionalLoad(const IPC::Message& msg);
void OnBeforeUnloadACK( void OnBeforeUnloadACK(
bool proceed, bool proceed,
const base::TimeTicks& renderer_before_unload_start_time, const base::TimeTicks& renderer_before_unload_start_time,
...@@ -351,6 +351,7 @@ class CONTENT_EXPORT RenderFrameHostImpl ...@@ -351,6 +351,7 @@ class CONTENT_EXPORT RenderFrameHostImpl
size_t end_offset); size_t end_offset);
void OnDidAccessInitialDocument(); void OnDidAccessInitialDocument();
void OnDidDisownOpener(); void OnDidDisownOpener();
void OnDidAssignPageId(int32 page_id);
void OnUpdateTitle(int32 page_id, void OnUpdateTitle(int32 page_id,
const base::string16& title, const base::string16& title,
blink::WebTextDirection title_direction); blink::WebTextDirection title_direction);
......
...@@ -184,6 +184,7 @@ RenderViewHostImpl::RenderViewHostImpl( ...@@ -184,6 +184,7 @@ RenderViewHostImpl::RenderViewHostImpl(
instance_(static_cast<SiteInstanceImpl*>(instance)), instance_(static_cast<SiteInstanceImpl*>(instance)),
waiting_for_drag_context_response_(false), waiting_for_drag_context_response_(false),
enabled_bindings_(0), enabled_bindings_(0),
page_id_(-1),
main_frame_routing_id_(main_frame_routing_id), main_frame_routing_id_(main_frame_routing_id),
run_modal_reply_msg_(NULL), run_modal_reply_msg_(NULL),
run_modal_opener_id_(MSG_ROUTING_NONE), run_modal_opener_id_(MSG_ROUTING_NONE),
......
...@@ -466,6 +466,10 @@ class CONTENT_EXPORT RenderViewHostImpl ...@@ -466,6 +466,10 @@ class CONTENT_EXPORT RenderViewHostImpl
// See BindingsPolicy for details. // See BindingsPolicy for details.
int enabled_bindings_; int enabled_bindings_;
// The most recent page ID we've heard from the renderer process. This is
// used as context when other session history related IPCs arrive.
// TODO(creis): Allocate this in WebContents/NavigationController instead.
int32 page_id_;
// The current state of this RVH. // The current state of this RVH.
// TODO(nasko): Move to RenderFrameHost, as this is per-frame state. // TODO(nasko): Move to RenderFrameHost, as this is per-frame state.
......
...@@ -214,12 +214,12 @@ TEST_F(RenderViewHostTest, MessageWithBadHistoryItemFiles) { ...@@ -214,12 +214,12 @@ TEST_F(RenderViewHostTest, MessageWithBadHistoryItemFiles) {
EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path)); EXPECT_TRUE(PathService::Get(base::DIR_TEMP, &file_path));
file_path = file_path.AppendASCII("foo"); file_path = file_path.AppendASCII("foo");
EXPECT_EQ(0, process()->bad_msg_count()); EXPECT_EQ(0, process()->bad_msg_count());
test_rvh()->TestOnUpdateStateWithFile(process()->GetID(), file_path); test_rvh()->TestOnUpdateStateWithFile(-1, file_path);
EXPECT_EQ(1, process()->bad_msg_count()); EXPECT_EQ(1, process()->bad_msg_count());
ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile(
process()->GetID(), file_path); process()->GetID(), file_path);
test_rvh()->TestOnUpdateStateWithFile(process()->GetID(), file_path); test_rvh()->TestOnUpdateStateWithFile(-1, file_path);
EXPECT_EQ(1, process()->bad_msg_count()); EXPECT_EQ(1, process()->bad_msg_count());
} }
......
...@@ -580,6 +580,10 @@ IPC_MESSAGE_ROUTED0(FrameHostMsg_DidAccessInitialDocument) ...@@ -580,6 +580,10 @@ IPC_MESSAGE_ROUTED0(FrameHostMsg_DidAccessInitialDocument)
// the window. Sent for top-level frames. // the window. Sent for top-level frames.
IPC_MESSAGE_ROUTED0(FrameHostMsg_DidDisownOpener) IPC_MESSAGE_ROUTED0(FrameHostMsg_DidDisownOpener)
// Notifies the browser that a page id was assigned.
IPC_MESSAGE_ROUTED1(FrameHostMsg_DidAssignPageId,
int32 /* page_id */)
// Changes the title for the page in the UI when the page is navigated or the // Changes the title for the page in the UI when the page is navigated or the
// title changes. Sent for top-level frames. // title changes. Sent for top-level frames.
IPC_MESSAGE_ROUTED3(FrameHostMsg_UpdateTitle, IPC_MESSAGE_ROUTED3(FrameHostMsg_UpdateTitle,
......
...@@ -2236,6 +2236,8 @@ void RenderFrameImpl::didCommitProvisionalLoad( ...@@ -2236,6 +2236,8 @@ void RenderFrameImpl::didCommitProvisionalLoad(
} }
} }
Send(new FrameHostMsg_DidAssignPageId(routing_id_, render_view_->page_id_));
FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_, FOR_EACH_OBSERVER(RenderViewObserver, render_view_->observers_,
DidCommitProvisionalLoad(frame, is_new_navigation)); DidCommitProvisionalLoad(frame, is_new_navigation));
FOR_EACH_OBSERVER(RenderFrameObserver, observers_, FOR_EACH_OBSERVER(RenderFrameObserver, observers_,
......
...@@ -111,7 +111,7 @@ void TestRenderFrameHost::SendNavigateWithFile( ...@@ -111,7 +111,7 @@ void TestRenderFrameHost::SendNavigateWithFile(
void TestRenderFrameHost::SendNavigateWithParams( void TestRenderFrameHost::SendNavigateWithParams(
FrameHostMsg_DidCommitProvisionalLoad_Params* params) { FrameHostMsg_DidCommitProvisionalLoad_Params* params) {
FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params); FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), *params);
OnNavigate(msg); OnDidCommitProvisionalLoad(msg);
} }
void TestRenderFrameHost::SendNavigateWithRedirects( void TestRenderFrameHost::SendNavigateWithRedirects(
...@@ -163,7 +163,7 @@ void TestRenderFrameHost::SendNavigateWithParameters( ...@@ -163,7 +163,7 @@ void TestRenderFrameHost::SendNavigateWithParameters(
file_path_for_history_item); file_path_for_history_item);
FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), params); FrameHostMsg_DidCommitProvisionalLoad msg(GetRoutingID(), params);
OnNavigate(msg); OnDidCommitProvisionalLoad(msg);
} }
void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url) { void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url) {
......
...@@ -350,9 +350,9 @@ void TestRenderViewHost::TestOnStartDragging( ...@@ -350,9 +350,9 @@ void TestRenderViewHost::TestOnStartDragging(
} }
void TestRenderViewHost::TestOnUpdateStateWithFile( void TestRenderViewHost::TestOnUpdateStateWithFile(
int process_id, int page_id,
const base::FilePath& file_path) { const base::FilePath& file_path) {
OnUpdateState(process_id, OnUpdateState(page_id,
PageState::CreateForTesting(GURL("http://www.google.com"), PageState::CreateForTesting(GURL("http://www.google.com"),
false, false,
"data", "data",
......
...@@ -250,7 +250,7 @@ class TestRenderViewHost ...@@ -250,7 +250,7 @@ class TestRenderViewHost
FrameHostMsg_DidCommitProvisionalLoad_Params* params); FrameHostMsg_DidCommitProvisionalLoad_Params* params);
void TestOnUpdateStateWithFile( void TestOnUpdateStateWithFile(
int process_id, const base::FilePath& file_path); int page_id, const base::FilePath& file_path);
void TestOnStartDragging(const DropData& drop_data); void TestOnStartDragging(const DropData& drop_data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment