diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 78740683b0f..1e1f75fc143 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -292,16 +292,8 @@ void NativeWindow::CloseWebContents() { // dialog when the window is busy executing some script withouth waiting for // the unresponsive timeout. if (!Browser::Get()->is_quiting() && - window_unresposive_closure_.IsCancelled()) { - window_unresposive_closure_.Reset( - base::Bind(&NativeWindow::RendererUnresponsive, - weak_factory_.GetWeakPtr(), - web_contents)); - base::MessageLoop::current()->PostDelayedTask( - FROM_HERE, - window_unresposive_closure_.callback(), - base::TimeDelta::FromMilliseconds(500)); - } + window_unresposive_closure_.IsCancelled()) + ScheduleUnresponsiveEvent(500); if (web_contents->NeedToFireBeforeUnload()) web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); @@ -446,12 +438,10 @@ bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const { } void NativeWindow::RendererUnresponsive(content::WebContents* source) { - window_unresposive_closure_.Cancel(); - - if (!HasModalDialog()) - FOR_EACH_OBSERVER(NativeWindowObserver, - observers_, - OnRendererUnresponsive()); + // 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. + ScheduleUnresponsiveEvent(50); } void NativeWindow::RendererResponsive(content::WebContents* source) { @@ -524,6 +514,25 @@ bool NativeWindow::DevToolsShow(std::string* dock_side) { return false; } +void NativeWindow::ScheduleUnresponsiveEvent(int ms) { + window_unresposive_closure_.Reset( + base::Bind(&NativeWindow::NotifyWindowUnresponsive, + weak_factory_.GetWeakPtr())); + base::MessageLoop::current()->PostDelayedTask( + FROM_HERE, + window_unresposive_closure_.callback(), + base::TimeDelta::FromMilliseconds(ms)); +} + +void NativeWindow::NotifyWindowUnresponsive() { + window_unresposive_closure_.Cancel(); + + if (!HasModalDialog()) + FOR_EACH_OBSERVER(NativeWindowObserver, + observers_, + OnRendererUnresponsive()); +} + void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback, bool succeed, const SkBitmap& bitmap) { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 51301dc5af5..c77549cb217 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -248,6 +248,12 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, gfx::Image icon_; private: + // Schedule a notification unresponsive event. + void ScheduleUnresponsiveEvent(int ms); + + // Dispatch unresponsive event to observers. + void NotifyWindowUnresponsive(); + // Called when CapturePage has done. void OnCapturePageDone(const CapturePageCallback& callback, bool succeed,