Do not use flags to mark whether the window is unresponsive.
It's error prone.
This commit is contained in:
parent
d6d1604623
commit
bfe8928ab1
2 changed files with 22 additions and 22 deletions
|
@ -44,7 +44,6 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
|||
: content::WebContentsObserver(web_contents),
|
||||
has_frame_(true),
|
||||
is_closed_(false),
|
||||
not_responding_(false),
|
||||
weak_factory_(this),
|
||||
inspectable_web_contents_(
|
||||
brightray::InspectableWebContents::Create(web_contents)) {
|
||||
|
@ -226,7 +225,16 @@ void NativeWindow::CloseWebContents() {
|
|||
// 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 (window_unresposive_closure_.IsCancelled()) {
|
||||
window_unresposive_closure_.Reset(
|
||||
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())
|
||||
web_contents->GetRenderViewHost()->FirePageBeforeUnload(false);
|
||||
|
@ -286,7 +294,7 @@ void NativeWindow::BeforeUnloadFired(content::WebContents* tab,
|
|||
WindowList::WindowCloseCancelled(this);
|
||||
|
||||
// When the "beforeunload" callback is fired the window is certainly live.
|
||||
not_responding_ = false;
|
||||
window_unresposive_closure_.Cancel();
|
||||
}
|
||||
|
||||
void NativeWindow::RequestToLockMouse(content::WebContents* web_contents,
|
||||
|
@ -331,7 +339,7 @@ void NativeWindow::CloseContents(content::WebContents* source) {
|
|||
NotifyWindowClosed();
|
||||
|
||||
// Do not sent "unresponsive" event after window is closed.
|
||||
not_responding_ = false;
|
||||
window_unresposive_closure_.Cancel();
|
||||
}
|
||||
|
||||
bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
|
||||
|
@ -340,16 +348,15 @@ bool NativeWindow::IsPopupOrPanel(const content::WebContents* source) const {
|
|||
}
|
||||
|
||||
void NativeWindow::RendererUnresponsive(content::WebContents* source) {
|
||||
not_responding_ = true;
|
||||
base::MessageLoop::current()->PostDelayedTask(
|
||||
FROM_HERE,
|
||||
base::Bind(&NativeWindow::RendererUnresponsiveDelayed,
|
||||
weak_factory_.GetWeakPtr()),
|
||||
base::TimeDelta::FromMilliseconds(500));
|
||||
LOG(ERROR) << "NativeWindow::RendererUnresponsive";
|
||||
window_unresposive_closure_.Cancel();
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||
observers_,
|
||||
OnRendererUnresponsive());
|
||||
}
|
||||
|
||||
void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||
not_responding_ = false;
|
||||
window_unresposive_closure_.Cancel();
|
||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
||||
}
|
||||
|
||||
|
@ -371,13 +378,6 @@ 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) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#define ATOM_BROWSER_NATIVE_WINDOW_H_
|
||||
|
||||
#include "base/basictypes.h"
|
||||
#include "base/cancelable_callback.h"
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/memory/scoped_ptr.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
|
@ -192,8 +193,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
|||
gfx::Image icon_;
|
||||
|
||||
private:
|
||||
void RendererUnresponsiveDelayed();
|
||||
|
||||
// Called when CapturePage has done.
|
||||
void OnCapturePageDone(const CapturePageCallback& callback,
|
||||
bool succeed,
|
||||
|
@ -215,8 +214,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
|||
// The windows has been closed.
|
||||
bool is_closed_;
|
||||
|
||||
// The window is not responding.
|
||||
bool not_responding_;
|
||||
// Closure that would be called when window is unresponsive when closing,
|
||||
// it should be cancelled when we can prove that the window is responsive.
|
||||
base::CancelableClosure window_unresposive_closure_;
|
||||
|
||||
base::WeakPtrFactory<NativeWindow> weak_factory_;
|
||||
|
||||
|
|
Loading…
Reference in a new issue