Send the "unresponsive" event if window is not closed in 500ms when closing it.
This commit is contained in:
parent
fd081e162b
commit
a0a5b20ef1
2 changed files with 19 additions and 3 deletions
|
@ -45,6 +45,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||||
has_frame_(true),
|
has_frame_(true),
|
||||||
is_closed_(false),
|
is_closed_(false),
|
||||||
not_responding_(false),
|
not_responding_(false),
|
||||||
|
weak_factory_(this),
|
||||||
inspectable_web_contents_(
|
inspectable_web_contents_(
|
||||||
brightray::InspectableWebContents::Create(web_contents)) {
|
brightray::InspectableWebContents::Create(web_contents)) {
|
||||||
options->GetBoolean(switches::kFrame, &has_frame_);
|
options->GetBoolean(switches::kFrame, &has_frame_);
|
||||||
|
@ -205,7 +206,7 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
|
||||||
rect,
|
rect,
|
||||||
gfx::Size(),
|
gfx::Size(),
|
||||||
base::Bind(&NativeWindow::OnCapturePageDone,
|
base::Bind(&NativeWindow::OnCapturePageDone,
|
||||||
base::Unretained(this),
|
weak_factory_.GetWeakPtr(),
|
||||||
callback));
|
callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,6 +222,12 @@ void NativeWindow::CloseWebContents() {
|
||||||
|
|
||||||
content::WebContents* web_contents(GetWebContents());
|
content::WebContents* web_contents(GetWebContents());
|
||||||
|
|
||||||
|
// Assume the window is not responding if it doesn't cancel the close and is
|
||||||
|
// not closed in 500ms, in this way we can quickly show the unresponsive
|
||||||
|
// dialog when the window is busy executing some script withouth waiting for
|
||||||
|
// the unresponsive timeout.
|
||||||
|
RendererUnresponsive(web_contents);
|
||||||
|
|
||||||
if (web_contents->NeedToFireBeforeUnload())
|
if (web_contents->NeedToFireBeforeUnload())
|
||||||
web_contents->GetRenderViewHost()->FirePageBeforeUnload(false);
|
web_contents->GetRenderViewHost()->FirePageBeforeUnload(false);
|
||||||
else
|
else
|
||||||
|
@ -277,6 +284,9 @@ void NativeWindow::BeforeUnloadFired(content::WebContents* tab,
|
||||||
|
|
||||||
if (!proceed)
|
if (!proceed)
|
||||||
WindowList::WindowCloseCancelled(this);
|
WindowList::WindowCloseCancelled(this);
|
||||||
|
|
||||||
|
// When the "beforeunload" callback is fired the window is certainly live.
|
||||||
|
not_responding_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::RequestToLockMouse(content::WebContents* web_contents,
|
void NativeWindow::RequestToLockMouse(content::WebContents* web_contents,
|
||||||
|
@ -319,6 +329,9 @@ void NativeWindow::CloseContents(content::WebContents* source) {
|
||||||
CloseImmediately();
|
CloseImmediately();
|
||||||
|
|
||||||
NotifyWindowClosed();
|
NotifyWindowClosed();
|
||||||
|
|
||||||
|
// Do not sent "unresponsive" event after window is closed.
|
||||||
|
not_responding_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
|
bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
|
||||||
|
@ -331,8 +344,8 @@ void NativeWindow::RendererUnresponsive(content::WebContents* source) {
|
||||||
base::MessageLoop::current()->PostDelayedTask(
|
base::MessageLoop::current()->PostDelayedTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::Bind(&NativeWindow::RendererUnresponsiveDelayed,
|
base::Bind(&NativeWindow::RendererUnresponsiveDelayed,
|
||||||
base::Unretained(this)),
|
weak_factory_.GetWeakPtr()),
|
||||||
base::TimeDelta::FromSeconds(1));
|
base::TimeDelta::FromMilliseconds(500));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::RendererResponsive(content::WebContents* source) {
|
void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/compiler_specific.h"
|
#include "base/compiler_specific.h"
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
|
#include "base/memory/weak_ptr.h"
|
||||||
#include "base/observer_list.h"
|
#include "base/observer_list.h"
|
||||||
#include "browser/native_window_observer.h"
|
#include "browser/native_window_observer.h"
|
||||||
#include "content/public/browser/notification_registrar.h"
|
#include "content/public/browser/notification_registrar.h"
|
||||||
|
@ -216,6 +217,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
// The window is not responding.
|
// The window is not responding.
|
||||||
bool not_responding_;
|
bool not_responding_;
|
||||||
|
|
||||||
|
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
||||||
|
|
||||||
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