From 146ce284dede67968b57eb84d6b14fde8786667e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 May 2014 11:26:13 +0800 Subject: [PATCH 1/4] Do not override pending unresponsive counter. --- atom/browser/native_window.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index f7f069ac27f..e8877ff737b 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -457,8 +457,12 @@ bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const { void NativeWindow::RendererUnresponsive(content::WebContents* source) { // Schedule the unresponsive shortly later, since we may receive the - // responsive event soon. - // This could happen after the whole application had blocked for a while. + // responsive event soon. This could happen after the whole application had + // blocked for a while. + // Also notice that when closing this event would be ignored because we have + // explicity started a close timeout counter. This is on purpose because we + // don't want the unresponsive event to be sent too early when user is closing + // the window. ScheduleUnresponsiveEvent(50); } @@ -556,6 +560,9 @@ void NativeWindow::DevToolsAppendToFile(const std::string& url, } void NativeWindow::ScheduleUnresponsiveEvent(int ms) { + if (!window_unresposive_closure_.IsCancelled()) + return; + window_unresposive_closure_.Reset( base::Bind(&NativeWindow::NotifyWindowUnresponsive, weak_factory_.GetWeakPtr())); From a070f0fdb6be5d22d1dcc434570bb5edbb770c73 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 May 2014 11:40:48 +0800 Subject: [PATCH 2/4] Only cancel unresponsive event when window close is cancelled. --- atom/browser/native_window.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index e8877ff737b..4e5038f51b6 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -404,11 +404,12 @@ void NativeWindow::BeforeUnloadFired(content::WebContents* tab, bool* proceed_to_fire_unload) { *proceed_to_fire_unload = proceed; - if (!proceed) + if (!proceed) { WindowList::WindowCloseCancelled(this); - // When the "beforeunload" callback is fired the window is certainly live. - window_unresposive_closure_.Cancel(); + // Cancel unresponsive event when window close is cancelled. + window_unresposive_closure_.Cancel(); + } } void NativeWindow::RequestToLockMouse(content::WebContents* web_contents, From 3e6df19eff74d346d9d23df129100246fc394818 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 May 2014 12:08:15 +0800 Subject: [PATCH 3/4] Do not send "unresponsive" when window is closed. --- atom/browser/native_window.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 4e5038f51b6..3e24f6aa136 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -576,7 +576,7 @@ void NativeWindow::ScheduleUnresponsiveEvent(int ms) { void NativeWindow::NotifyWindowUnresponsive() { window_unresposive_closure_.Cancel(); - if (!HasModalDialog()) + if (!is_closed_ && !HasModalDialog()) FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererUnresponsive()); From 77d6bb2c3f82c785dbe6a43b7c9c753aa90aba1b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 9 May 2014 12:10:37 +0800 Subject: [PATCH 4/4] Bring the close timeout back to 5s. --- atom/browser/native_window.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 3e24f6aa136..558778029e5 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -313,11 +313,11 @@ void NativeWindow::CloseWebContents() { } // Assume the window is not responding if it doesn't cancel the close and is - // not closed in 10s, in this way we can quickly show the unresponsive + // not closed in 5s, in this way we can quickly show the unresponsive // dialog when the window is busy executing some script withouth waiting for // the unresponsive timeout. if (window_unresposive_closure_.IsCancelled()) - ScheduleUnresponsiveEvent(10000); + ScheduleUnresponsiveEvent(5000); if (web_contents->NeedToFireBeforeUnload()) web_contents->GetRenderViewHost()->FirePageBeforeUnload(false);