From e248e2ffc8e15073434b3fb62799eeb9a3063257 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 23 Jul 2013 15:29:56 +0800 Subject: [PATCH] Delay the unresponsive message for a second, fixes #42. It could happen that a window became responsive immediately after the unresponsive message is sent (for example, the window was blocked by showing a save as dialog), by delaying sending the unresponsive message for a second, we can give the window a chance to whether it's really unresponsive or not. --- browser/native_window.cc | 17 ++++++++++++++++- browser/native_window.h | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/browser/native_window.cc b/browser/native_window.cc index b7bed1717961..391e64719996 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -6,6 +6,7 @@ #include +#include "base/message_loop.h" #include "base/utf_string_conversions.h" #include "base/values.h" #include "brightray/browser/inspectable_web_contents.h" @@ -39,6 +40,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, base::DictionaryValue* options) : content::WebContentsObserver(web_contents), is_closed_(false), + not_responding_(false), inspectable_web_contents_( brightray::InspectableWebContents::Create(web_contents)) { web_contents->SetDelegate(this); @@ -275,10 +277,16 @@ bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const { } void NativeWindow::RendererUnresponsive(content::WebContents* source) { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererUnresponsive()); + not_responding_ = true; + base::MessageLoop::current()->PostDelayedTask( + FROM_HERE, + base::Bind(&NativeWindow::RendererUnresponsiveDelayed, + base::Unretained(this)), + base::TimeDelta::FromSeconds(1)); } void NativeWindow::RendererResponsive(content::WebContents* source) { + not_responding_ = false; FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive()); } @@ -297,6 +305,13 @@ void NativeWindow::RenderViewGone(base::TerminationStatus status) { FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererCrashed()); } +void NativeWindow::RendererUnresponsiveDelayed() { + if (not_responding_) + FOR_EACH_OBSERVER(NativeWindowObserver, + observers_, + OnRendererUnresponsive()); +} + void NativeWindow::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { diff --git a/browser/native_window.h b/browser/native_window.h index c6a6c8401d26..762920cfd082 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -163,6 +163,8 @@ class NativeWindow : public content::WebContentsDelegate, const content::NotificationDetails& details) OVERRIDE; private: + void RendererUnresponsiveDelayed(); + void OnRendererMessage(const std::string& channel, const base::ListValue& args); @@ -176,8 +178,12 @@ class NativeWindow : public content::WebContentsDelegate, // Observers of this window. ObserverList observers_; + // The windows has been closed. bool is_closed_; + // The window is not responding. + bool not_responding_; + scoped_ptr dialog_manager_; scoped_ptr inspectable_web_contents_;