Commit c9e8cbaf authored by jochen@chromium.org's avatar jochen@chromium.org

When committing a provisional load that didn't change the RVH, still abort pending navigations.

Also, when sending error events for a frame, mark them as failed, so we don't touch them again in the future

BUG=139117
TEST=none


Review URL: https://chromiumcodereview.appspot.com/10834125

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149632 0039d316-1c4b-4281-b951-d872f2087c98
parent 3d0e2262
...@@ -103,10 +103,12 @@ void FrameNavigationState::TrackFrame(FrameID frame_id, ...@@ -103,10 +103,12 @@ void FrameNavigationState::TrackFrame(FrameID frame_id,
} }
void FrameNavigationState::StopTrackingFramesInRVH( void FrameNavigationState::StopTrackingFramesInRVH(
content::RenderViewHost* render_view_host) { content::RenderViewHost* render_view_host,
FrameID id_to_skip) {
for (std::set<FrameID>::iterator frame = frame_ids_.begin(); for (std::set<FrameID>::iterator frame = frame_ids_.begin();
frame != frame_ids_.end();) { frame != frame_ids_.end();) {
if (frame->render_view_host != render_view_host) { if (frame->render_view_host != render_view_host ||
*frame == id_to_skip) {
++frame; ++frame;
continue; continue;
} }
...@@ -182,8 +184,10 @@ bool FrameNavigationState::GetNavigationCompleted(FrameID frame_id) const { ...@@ -182,8 +184,10 @@ bool FrameNavigationState::GetNavigationCompleted(FrameID frame_id) const {
void FrameNavigationState::SetNavigationCommitted(FrameID frame_id) { void FrameNavigationState::SetNavigationCommitted(FrameID frame_id) {
DCHECK(frame_state_map_.find(frame_id) != frame_state_map_.end()); DCHECK(frame_state_map_.find(frame_id) != frame_state_map_.end());
frame_state_map_[frame_id].is_committed = true; frame_state_map_[frame_id].is_committed = true;
if (frame_state_map_[frame_id].is_main_frame) if (frame_state_map_[frame_id].is_main_frame) {
DCHECK_EQ(1u, frame_ids_.size());
main_frame_id_ = frame_id; main_frame_id_ = frame_id;
}
} }
bool FrameNavigationState::GetNavigationCommitted(FrameID frame_id) const { bool FrameNavigationState::GetNavigationCommitted(FrameID frame_id) const {
......
...@@ -57,8 +57,10 @@ class FrameNavigationState { ...@@ -57,8 +57,10 @@ class FrameNavigationState {
bool is_main_frame, bool is_main_frame,
bool is_error_page); bool is_error_page);
// Stops tracking all frames for a given RenderViewHost. // Stops tracking all frames but the frame with |id_to_skip| for a given
void StopTrackingFramesInRVH(content::RenderViewHost* render_view_host); // RenderViewHost.
void StopTrackingFramesInRVH(content::RenderViewHost* render_view_host,
FrameID id_to_skip);
// Update the URL associated with a given frame. // Update the URL associated with a given frame.
void UpdateFrame(FrameID frame_id, const GURL& url); void UpdateFrame(FrameID frame_id, const GURL& url);
......
...@@ -45,7 +45,8 @@ TEST(FrameNavigationStateTest, TrackFrame) { ...@@ -45,7 +45,8 @@ TEST(FrameNavigationStateTest, TrackFrame) {
EXPECT_EQ(frame_id1, navigation_state.GetMainFrameID()); EXPECT_EQ(frame_id1, navigation_state.GetMainFrameID());
// Drop the frames. // Drop the frames.
navigation_state.StopTrackingFramesInRVH(fake_rvh); navigation_state.StopTrackingFramesInRVH(fake_rvh,
FrameNavigationState::FrameID());
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1)); EXPECT_FALSE(navigation_state.CanSendEvents(frame_id1));
EXPECT_FALSE(navigation_state.IsValidFrame(frame_id1)); EXPECT_FALSE(navigation_state.IsValidFrame(frame_id1));
EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2)); EXPECT_FALSE(navigation_state.CanSendEvents(frame_id2));
......
...@@ -317,7 +317,8 @@ void WebNavigationTabObserver::Observe( ...@@ -317,7 +317,8 @@ void WebNavigationTabObserver::Observe(
pending_render_view_host_ = NULL; pending_render_view_host_ = NULL;
else else
return; return;
SendErrorEvents(web_contents(), render_view_host); SendErrorEvents(
web_contents(), render_view_host, FrameNavigationState::FrameID());
break; break;
} }
...@@ -331,8 +332,11 @@ void WebNavigationTabObserver::AboutToNavigateRenderView( ...@@ -331,8 +332,11 @@ void WebNavigationTabObserver::AboutToNavigateRenderView(
if (!render_view_host_) { if (!render_view_host_) {
render_view_host_ = render_view_host; render_view_host_ = render_view_host;
} else if (render_view_host != render_view_host_) { } else if (render_view_host != render_view_host_) {
if (pending_render_view_host_) if (pending_render_view_host_) {
SendErrorEvents(web_contents(), pending_render_view_host_); SendErrorEvents(web_contents(),
pending_render_view_host_,
FrameNavigationState::FrameID());
}
pending_render_view_host_ = render_view_host; pending_render_view_host_ = render_view_host;
} }
} }
...@@ -372,12 +376,15 @@ void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame( ...@@ -372,12 +376,15 @@ void WebNavigationTabObserver::DidCommitProvisionalLoadForFrame(
if (render_view_host != render_view_host_ && if (render_view_host != render_view_host_ &&
render_view_host != pending_render_view_host_) render_view_host != pending_render_view_host_)
return; return;
if (render_view_host != render_view_host_) FrameNavigationState::FrameID frame_id(frame_num, render_view_host);
SendErrorEvents(web_contents(), render_view_host_); FrameNavigationState::FrameID id_to_skip;
if (render_view_host == render_view_host_)
id_to_skip = frame_id;
if (is_main_frame)
SendErrorEvents(web_contents(), render_view_host_, id_to_skip);
render_view_host_ = render_view_host; render_view_host_ = render_view_host;
pending_render_view_host_ = NULL; pending_render_view_host_ = NULL;
FrameNavigationState::FrameID frame_id(frame_num, render_view_host);
if (!navigation_state_.CanSendEvents(frame_id)) if (!navigation_state_.CanSendEvents(frame_id))
return; return;
...@@ -449,8 +456,10 @@ void WebNavigationTabObserver::DidFailProvisionalLoad( ...@@ -449,8 +456,10 @@ void WebNavigationTabObserver::DidFailProvisionalLoad(
web_contents(), render_view_host->GetProcess()->GetID(), validated_url, web_contents(), render_view_host->GetProcess()->GetID(), validated_url,
frame_num, is_main_frame, error_code); frame_num, is_main_frame, error_code);
} }
if (stop_tracking_frames) if (stop_tracking_frames) {
navigation_state_.StopTrackingFramesInRVH(render_view_host); navigation_state_.StopTrackingFramesInRVH(render_view_host,
FrameNavigationState::FrameID());
}
} }
void WebNavigationTabObserver::DocumentLoadedInFrame( void WebNavigationTabObserver::DocumentLoadedInFrame(
...@@ -537,28 +546,31 @@ void WebNavigationTabObserver::DidOpenRequestedURL( ...@@ -537,28 +546,31 @@ void WebNavigationTabObserver::DidOpenRequestedURL(
void WebNavigationTabObserver::WebContentsDestroyed(content::WebContents* tab) { void WebNavigationTabObserver::WebContentsDestroyed(content::WebContents* tab) {
g_tab_observer.Get().erase(tab); g_tab_observer.Get().erase(tab);
registrar_.RemoveAll(); registrar_.RemoveAll();
SendErrorEvents(tab, NULL); SendErrorEvents(tab, NULL, FrameNavigationState::FrameID());
} }
void WebNavigationTabObserver::SendErrorEvents( void WebNavigationTabObserver::SendErrorEvents(
content::WebContents* web_contents, content::WebContents* web_contents,
content::RenderViewHost* render_view_host) { content::RenderViewHost* render_view_host,
FrameNavigationState::FrameID id_to_skip) {
for (FrameNavigationState::const_iterator frame = navigation_state_.begin(); for (FrameNavigationState::const_iterator frame = navigation_state_.begin();
frame != navigation_state_.end(); ++frame) { frame != navigation_state_.end(); ++frame) {
if (!navigation_state_.GetNavigationCompleted(*frame) && if (!navigation_state_.GetNavigationCompleted(*frame) &&
navigation_state_.CanSendEvents(*frame) && navigation_state_.CanSendEvents(*frame) &&
*frame != id_to_skip &&
(!render_view_host || frame->render_view_host == render_view_host)) { (!render_view_host || frame->render_view_host == render_view_host)) {
navigation_state_.SetErrorOccurredInFrame(*frame);
helpers::DispatchOnErrorOccurred( helpers::DispatchOnErrorOccurred(
web_contents, web_contents,
frame->render_view_host->GetProcess()->GetID(), frame->render_view_host->GetProcess()->GetID(),
navigation_state_.GetUrl(*frame), navigation_state_.GetUrl(*frame),
frame->frame_num, frame->frame_num,
navigation_state_.IsMainFrame(*frame), navigation_state_.IsMainFrame(*frame),
net::ERR_ABORTED); net::ERR_ABORTED);
} }
} }
if (render_view_host) if (render_view_host)
navigation_state_.StopTrackingFramesInRVH(render_view_host); navigation_state_.StopTrackingFramesInRVH(render_view_host, id_to_skip);
} }
// See also NavigationController::IsURLInPageNavigation. // See also NavigationController::IsURLInPageNavigation.
......
...@@ -101,9 +101,11 @@ class WebNavigationTabObserver : public content::NotificationObserver, ...@@ -101,9 +101,11 @@ class WebNavigationTabObserver : public content::NotificationObserver,
// Creates and sends onErrorOccurred events for all on-going navigations. If // Creates and sends onErrorOccurred events for all on-going navigations. If
// |render_view_host| is non-NULL, only generates events for frames in this // |render_view_host| is non-NULL, only generates events for frames in this
// render view host. // render view host. If |id_to_skip| is given, no events are sent for that
// frame.
void SendErrorEvents(content::WebContents* web_contents, void SendErrorEvents(content::WebContents* web_contents,
content::RenderViewHost* render_view_host); content::RenderViewHost* render_view_host,
FrameNavigationState::FrameID id_to_skip);
// Tracks the state of the frames we are sending events for. // Tracks the state of the frames we are sending events for.
FrameNavigationState navigation_state_; FrameNavigationState navigation_state_;
......
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