Chromium Code Reviews| Index: content/browser/frame_host/render_frame_host_impl.cc |
| diff --git a/content/browser/frame_host/render_frame_host_impl.cc b/content/browser/frame_host/render_frame_host_impl.cc |
| index 944d444d2d9d16492223aa0b817f738e1876673d..91cf8994d4116fc2013ecfd0102fa21358a2d261 100644 |
| --- a/content/browser/frame_host/render_frame_host_impl.cc |
| +++ b/content/browser/frame_host/render_frame_host_impl.cc |
| @@ -369,6 +369,9 @@ RenderFrameHostImpl::RenderFrameHostImpl(SiteInstance* site_instance, |
| SetUpMojoIfNeeded(); |
| swapout_event_monitor_timeout_.reset(new TimeoutMonitor(base::Bind( |
| &RenderFrameHostImpl::OnSwappedOut, weak_ptr_factory_.GetWeakPtr()))); |
| + beforeunload_timeout_.reset( |
| + new TimeoutMonitor(base::Bind(&RenderFrameHostImpl::BeforeUnloadTimeout, |
| + weak_ptr_factory_.GetWeakPtr()))); |
| if (widget_routing_id != MSG_ROUTING_NONE) { |
| // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, the main |
| @@ -1470,8 +1473,7 @@ void RenderFrameHostImpl::OnBeforeUnloadACK( |
| } |
| // Resets beforeunload waiting state. |
| is_waiting_for_beforeunload_ack_ = false; |
| - render_view_host_->GetWidget()->decrement_in_flight_event_count(); |
| - render_view_host_->GetWidget()->StopHangMonitorTimeout(); |
| + beforeunload_timeout_->Stop(); |
| send_before_unload_start_time_ = base::TimeTicks(); |
| // PlzNavigate: if the ACK is for a navigation, send it to the Navigator to |
| @@ -1693,6 +1695,14 @@ void RenderFrameHostImpl::OnRunBeforeUnloadConfirm( |
| // shouldn't process input events. |
| GetProcess()->SetIgnoreInputEvents(true); |
| render_view_host_->GetWidget()->StopHangMonitorTimeout(); |
| + |
| + // The beforeunload dialog for this frame may have been triggered by a |
| + // browser-side request to this frame or a frame up in the frame hierarchy. |
| + // Stop any timers that are waiting. |
|
Charlie Reis
2017/03/14 17:19:29
Yeah, that sounds right.
Avi (use Gerrit)
2017/03/14 20:52:03
Acknowledged.
|
| + for (RenderFrameHostImpl* frame = this; frame; frame = frame->GetParent()) |
|
Charlie Reis
2017/03/14 17:19:29
nit: This would need braces for a multi-line body,
Avi (use Gerrit)
2017/03/14 20:52:03
Acknowledged.
|
| + if (frame->is_waiting_for_beforeunload_ack_) |
|
Charlie Reis
2017/03/14 17:19:29
Is this check needed? I'm guessing that is_waitin
Avi (use Gerrit)
2017/03/14 20:52:03
If we don't have a dialog up, yes, is_waiting_for_
Avi (use Gerrit)
2017/03/14 20:58:58
FYI, before OldSpice, alerts were serialized in a
|
| + frame->beforeunload_timeout_->Stop(); |
| + |
| delegate_->RunBeforeUnloadConfirm(this, is_reload, reply_msg); |
| } |
| @@ -2393,8 +2403,7 @@ void RenderFrameHostImpl::ResetWaitingState() { |
| // navigations to be ignored in OnDidCommitProvisionalLoad. |
| if (is_waiting_for_beforeunload_ack_) { |
| is_waiting_for_beforeunload_ack_ = false; |
| - render_view_host_->GetWidget()->decrement_in_flight_event_count(); |
| - render_view_host_->GetWidget()->StopHangMonitorTimeout(); |
| + beforeunload_timeout_->Stop(); |
| } |
| send_before_unload_start_time_ = base::TimeTicks(); |
| render_view_host_->is_waiting_for_close_ack_ = false; |
| @@ -2539,12 +2548,8 @@ void RenderFrameHostImpl::DispatchBeforeUnload(bool for_navigation, |
| // reply from the dialog. |
| SimulateBeforeUnloadAck(); |
| } else { |
| - // Increment the in-flight event count, to ensure that input events won't |
| - // cancel the timeout timer. |
| - render_view_host_->GetWidget()->increment_in_flight_event_count(); |
| - render_view_host_->GetWidget()->StartHangMonitorTimeout( |
| - TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS), |
| - blink::WebInputEvent::Undefined); |
| + beforeunload_timeout_->Start( |
| + TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
| send_before_unload_start_time_ = base::TimeTicks::Now(); |
| Send(new FrameMsg_BeforeUnload(routing_id_, is_reload)); |
| } |
| @@ -2609,33 +2614,27 @@ void RenderFrameHostImpl::JavaScriptDialogClosed( |
| IPC::Message* reply_msg, |
| bool success, |
| const base::string16& user_input, |
| - bool is_before_unload_dialog, |
| bool dialog_was_suppressed) { |
| GetProcess()->SetIgnoreInputEvents(false); |
| - // If we are executing as part of beforeunload event handling, we don't |
| - // want to use the regular hung_renderer_delay_ms_ if the user has agreed to |
| - // leave the current page. In this case, use the regular timeout value used |
| - // during the beforeunload handling. |
| - if (is_before_unload_dialog) { |
| - render_view_host_->GetWidget()->StartHangMonitorTimeout( |
| - success |
| - ? TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS) |
| - : render_view_host_->GetWidget()->hung_renderer_delay(), |
| - blink::WebInputEvent::Undefined); |
| - } |
| - |
| SendJavaScriptDialogReply(reply_msg, success, user_input); |
| - // If we are waiting for a beforeunload ack and the user has suppressed |
| - // messages, kill the tab immediately; a page that's spamming alerts in |
| - // onbeforeunload is presumably malicious, so there's no point in continuing |
| - // to run its script and dragging out the process. This must be done after |
| - // sending the reply since RenderView can't close correctly while waiting for |
| - // a response. |
| - if (is_before_unload_dialog && dialog_was_suppressed) { |
| - render_view_host_->GetWidget()->delegate()->RendererUnresponsive( |
| - render_view_host_->GetWidget()); |
| + // If executing as part of beforeunload event handling, there may have been |
| + // timers stopped in this frame or a frame up in the frame hierarchy. Restart |
| + // any timers that were stopped in OnRunBeforeUnloadConfirm(). |
| + for (RenderFrameHostImpl* frame = this; frame; frame = frame->GetParent()) { |
| + if (frame->is_waiting_for_beforeunload_ack_) { |
|
Charlie Reis
2017/03/14 17:19:29
Oh, I guess we can't remove this after all, since
Avi (use Gerrit)
2017/03/14 20:52:03
Yes.
Avi (use Gerrit)
2017/03/14 21:03:14
** this belongs to this thread **
FYI, before Old
Charlie Reis
2017/03/15 17:22:02
Is that true with OOPIFs, though? In my example a
Avi (use Gerrit)
2017/03/15 19:57:38
Yes.
Charlie Reis
2017/03/15 21:34:20
Thanks-- that does explain it. And in particular,
|
| + // If we are waiting for a beforeunload ack and the user has suppressed |
| + // messages, kill the tab immediately. A page that's spamming is |
| + // presumably malicious, so there's no point in continuing to run its |
| + // script and dragging out the process. |
| + if (dialog_was_suppressed) { |
| + frame->SimulateBeforeUnloadAck(); |
| + } else { |
| + frame->beforeunload_timeout_->Start( |
| + TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
| + } |
| + } |
| } |
| } |
| @@ -3462,4 +3461,11 @@ RenderFrameHostImpl::TakeNavigationHandleForCommit( |
| entry_id_for_data_nav, false); // started_from_context_menu |
| } |
| +void RenderFrameHostImpl::BeforeUnloadTimeout() { |
| + if (render_view_host_->GetDelegate()->ShouldIgnoreUnresponsiveRenderer()) |
| + return; |
| + |
| + SimulateBeforeUnloadAck(); |
| +} |
| + |
| } // namespace content |