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 419beed88c1937019e7c92813296f66cb8269458..387dd13fd7a17b406a1fccb8651421f82402a76f 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 |
@@ -1469,8 +1472,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 |
@@ -1692,6 +1694,7 @@ void RenderFrameHostImpl::OnRunBeforeUnloadConfirm( |
// shouldn't process input events. |
GetProcess()->SetIgnoreInputEvents(true); |
render_view_host_->GetWidget()->StopHangMonitorTimeout(); |
+ beforeunload_timeout_->Stop(); |
delegate_->RunBeforeUnloadConfirm(this, is_reload, reply_msg); |
} |
@@ -2392,8 +2395,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; |
@@ -2538,13 +2540,10 @@ 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, |
- RendererUnresponsiveType::RENDERER_UNRESPONSIVE_BEFORE_UNLOAD); |
+ beforeunload_timeout_type_ = |
+ RendererUnresponsiveType::RENDERER_UNRESPONSIVE_BEFORE_UNLOAD; |
+ beforeunload_timeout_->Start( |
+ TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS)); |
send_before_unload_start_time_ = base::TimeTicks::Now(); |
Send(new FrameMsg_BeforeUnload(routing_id_, is_reload)); |
} |
@@ -2613,33 +2612,36 @@ void RenderFrameHostImpl::JavaScriptDialogClosed( |
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 executing as part of beforeunload event handling, resume the timeout |
+ // that was suspended when the dialog was shown in OnRunBeforeUnloadConfirm(). |
+ // |
+ // If the user said to leave the current page, they're waiting, so use the |
+ // smaller onbeforeunload timeout. If the user said to stay, use the usual |
+ // hung page timeout, which is longer. |
if (is_before_unload_dialog) { |
- RendererUnresponsiveType type = |
+ beforeunload_timeout_type_ = |
success ? RendererUnresponsiveType::RENDERER_UNRESPONSIVE_BEFORE_UNLOAD |
: RendererUnresponsiveType::RENDERER_UNRESPONSIVE_DIALOG_CLOSED; |
- render_view_host_->GetWidget()->StartHangMonitorTimeout( |
+ beforeunload_timeout_->Start( |
success |
? TimeDelta::FromMilliseconds(RenderViewHostImpl::kUnloadTimeoutMS) |
- : render_view_host_->GetWidget()->hung_renderer_delay(), |
- blink::WebInputEvent::Undefined, type); |
+ : render_view_host_->GetWidget()->hung_renderer_delay()); |
Charlie Reis
2017/03/06 21:10:44
In the new approach where the beforeunload timer i
Avi (use Gerrit)
2017/03/06 22:11:17
We always get a beforeunload ACK, even when the us
Charlie Reis
2017/03/06 23:47:56
Great-- maybe we can use the shorter timeout for b
Avi (use Gerrit)
2017/03/06 23:59:15
Sure!
|
} |
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. |
+ // 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. 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(), |
- RendererUnresponsiveType::RENDERER_UNRESPONSIVE_DIALOG_SUPPRESSED); |
+ UMA_HISTOGRAM_ENUMERATION( |
+ "ChildProcess.HangRendererType", |
+ RendererUnresponsiveType::RENDERER_UNRESPONSIVE_DIALOG_SUPPRESSED, |
+ RendererUnresponsiveType::RENDERER_UNRESPONSIVE_MAX); |
+ |
+ SimulateBeforeUnloadAck(); |
} |
} |
@@ -3464,4 +3466,15 @@ RenderFrameHostImpl::TakeNavigationHandleForCommit( |
entry_id_for_data_nav, false); // started_from_context_menu |
} |
+void RenderFrameHostImpl::BeforeUnloadTimeout() { |
+ if (render_view_host_->GetDelegate()->ShouldIgnoreUnresponsiveRenderer()) |
+ return; |
+ |
+ UMA_HISTOGRAM_ENUMERATION( |
+ "ChildProcess.HangRendererType", beforeunload_timeout_type_, |
dtapuska
2017/03/06 18:23:46
Is this safe? Declaring the histogram twice? The m
Avi (use Gerrit)
2017/03/06 18:27:26
Wait.. you can't do this? I already did this in ht
Avi (use Gerrit)
2017/03/06 18:43:09
Ilya says in chat: "I see. That's fine, in terms
Avi (use Gerrit)
2017/03/06 23:59:15
WebContentsImpl::RendererUnresponsive is a bunch o
|
+ RendererUnresponsiveType::RENDERER_UNRESPONSIVE_MAX); |
+ |
+ SimulateBeforeUnloadAck(); |
+} |
+ |
} // namespace content |