Delay the unresponsive event shortly.

It could happen that a window became responsive immediately after the
unresponsive message is sent, like after showing a context menu
synchronously.
This commit is contained in:
Cheng Zhao 2014-03-25 18:10:51 +08:00
parent 679959eeb5
commit 7a83b16cc4
2 changed files with 31 additions and 16 deletions

View file

@ -292,16 +292,8 @@ void NativeWindow::CloseWebContents() {
// dialog when the window is busy executing some script withouth waiting for // dialog when the window is busy executing some script withouth waiting for
// the unresponsive timeout. // the unresponsive timeout.
if (!Browser::Get()->is_quiting() && if (!Browser::Get()->is_quiting() &&
window_unresposive_closure_.IsCancelled()) { window_unresposive_closure_.IsCancelled())
window_unresposive_closure_.Reset( ScheduleUnresponsiveEvent(500);
base::Bind(&NativeWindow::RendererUnresponsive,
weak_factory_.GetWeakPtr(),
web_contents));
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
window_unresposive_closure_.callback(),
base::TimeDelta::FromMilliseconds(500));
}
if (web_contents->NeedToFireBeforeUnload()) if (web_contents->NeedToFireBeforeUnload())
web_contents->GetRenderViewHost()->FirePageBeforeUnload(false); web_contents->GetRenderViewHost()->FirePageBeforeUnload(false);
@ -446,12 +438,10 @@ bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
} }
void NativeWindow::RendererUnresponsive(content::WebContents* source) { void NativeWindow::RendererUnresponsive(content::WebContents* source) {
window_unresposive_closure_.Cancel(); // Schedule the unresponsive shortly later, since we may receive the
// responsive event soon.
if (!HasModalDialog()) // This could happen after the whole application had blocked for a while.
FOR_EACH_OBSERVER(NativeWindowObserver, ScheduleUnresponsiveEvent(50);
observers_,
OnRendererUnresponsive());
} }
void NativeWindow::RendererResponsive(content::WebContents* source) { void NativeWindow::RendererResponsive(content::WebContents* source) {
@ -524,6 +514,25 @@ bool NativeWindow::DevToolsShow(std::string* dock_side) {
return false; 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, void NativeWindow::OnCapturePageDone(const CapturePageCallback& callback,
bool succeed, bool succeed,
const SkBitmap& bitmap) { const SkBitmap& bitmap) {

View file

@ -248,6 +248,12 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
gfx::Image icon_; gfx::Image icon_;
private: private:
// Schedule a notification unresponsive event.
void ScheduleUnresponsiveEvent(int ms);
// Dispatch unresponsive event to observers.
void NotifyWindowUnresponsive();
// Called when CapturePage has done. // Called when CapturePage has done.
void OnCapturePageDone(const CapturePageCallback& callback, void OnCapturePageDone(const CapturePageCallback& callback,
bool succeed, bool succeed,