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:
parent
9efde9577a
commit
e248e2ffc8
2 changed files with 22 additions and 1 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "base/message_loop.h"
|
||||||
#include "base/utf_string_conversions.h"
|
#include "base/utf_string_conversions.h"
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "brightray/browser/inspectable_web_contents.h"
|
#include "brightray/browser/inspectable_web_contents.h"
|
||||||
|
@ -39,6 +40,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||||
base::DictionaryValue* options)
|
base::DictionaryValue* options)
|
||||||
: content::WebContentsObserver(web_contents),
|
: content::WebContentsObserver(web_contents),
|
||||||
is_closed_(false),
|
is_closed_(false),
|
||||||
|
not_responding_(false),
|
||||||
inspectable_web_contents_(
|
inspectable_web_contents_(
|
||||||
brightray::InspectableWebContents::Create(web_contents)) {
|
brightray::InspectableWebContents::Create(web_contents)) {
|
||||||
web_contents->SetDelegate(this);
|
web_contents->SetDelegate(this);
|
||||||
|
@ -275,10 +277,16 @@ bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::RendererUnresponsive(content::WebContents* source) {
|
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) {
|
void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||||
|
not_responding_ = false;
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,6 +305,13 @@ void NativeWindow::RenderViewGone(base::TerminationStatus status) {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererCrashed());
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererCrashed());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::RendererUnresponsiveDelayed() {
|
||||||
|
if (not_responding_)
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||||
|
observers_,
|
||||||
|
OnRendererUnresponsive());
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindow::Observe(int type,
|
void NativeWindow::Observe(int type,
|
||||||
const content::NotificationSource& source,
|
const content::NotificationSource& source,
|
||||||
const content::NotificationDetails& details) {
|
const content::NotificationDetails& details) {
|
||||||
|
|
|
@ -163,6 +163,8 @@ class NativeWindow : public content::WebContentsDelegate,
|
||||||
const content::NotificationDetails& details) OVERRIDE;
|
const content::NotificationDetails& details) OVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void RendererUnresponsiveDelayed();
|
||||||
|
|
||||||
void OnRendererMessage(const std::string& channel,
|
void OnRendererMessage(const std::string& channel,
|
||||||
const base::ListValue& args);
|
const base::ListValue& args);
|
||||||
|
|
||||||
|
@ -176,8 +178,12 @@ class NativeWindow : public content::WebContentsDelegate,
|
||||||
// Observers of this window.
|
// Observers of this window.
|
||||||
ObserverList<NativeWindowObserver> observers_;
|
ObserverList<NativeWindowObserver> observers_;
|
||||||
|
|
||||||
|
// The windows has been closed.
|
||||||
bool is_closed_;
|
bool is_closed_;
|
||||||
|
|
||||||
|
// The window is not responding.
|
||||||
|
bool not_responding_;
|
||||||
|
|
||||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||||
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue