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.
This commit is contained in:
Cheng Zhao 2013-07-23 15:29:56 +08:00
Родитель 9efde9577a
Коммит e248e2ffc8
2 изменённых файлов: 22 добавлений и 1 удалений

Просмотреть файл

@ -6,6 +6,7 @@
#include <string>
#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) {

Просмотреть файл

@ -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<NativeWindowObserver> observers_;
// The windows has been closed.
bool is_closed_;
// The window is not responding.
bool not_responding_;
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;