From a3124e887363d92f9c3a6c8f3438312f91ecb75e Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 22 Feb 2018 15:48:53 +0900 Subject: [PATCH] Use observer to provide OnRendererUnresponsive --- atom/browser/api/atom_api_web_contents.cc | 2 -- atom/browser/api/atom_api_web_contents.h | 7 +++++++ atom/browser/native_window.cc | 22 +++++++++++----------- atom/browser/native_window.h | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index f44bb96ad0c5..591418d6ce28 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -636,8 +636,6 @@ void WebContents::RendererUnresponsive( content::WebContents* source, const content::WebContentsUnresponsiveState& unresponsive_state) { Emit("unresponsive"); - if ((type_ == BROWSER_WINDOW || type_ == OFF_SCREEN) && owner_window()) - owner_window()->RendererUnresponsive(source); } void WebContents::RendererResponsive(content::WebContents* source) { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 16f23210557c..620f1045bb09 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -49,6 +49,13 @@ class WebViewGuestDelegate; namespace api { +// Certain events are only in WebContentsDelegate, provide our own Observer to +// dispatch those events. +class ExtendedWebContentsObserver { + virtual void OnRendererResponsive() {} +}; + +// Wrapper around the content::WebContents. class WebContents : public mate::TrackableObject, public CommonWebContentsDelegate, public content::WebContentsObserver { diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 90bf766777ba..5407fd4f537b 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -474,17 +474,6 @@ void NativeWindow::CloseContents(content::WebContents* source) { window_unresposive_closure_.Cancel(); } -void NativeWindow::RendererUnresponsive(content::WebContents* source) { - // Schedule the unresponsive shortly later, since we may receive the - // responsive event soon. This could happen after the whole application had - // blocked for a while. - // Also notice that when closing this event would be ignored because we have - // explicitly started a close timeout counter. This is on purpose because we - // don't want the unresponsive event to be sent too early when user is closing - // the window. - ScheduleUnresponsiveEvent(50); -} - void NativeWindow::RendererResponsive(content::WebContents* source) { window_unresposive_closure_.Cancel(); for (NativeWindowObserver& observer : observers_) @@ -659,6 +648,17 @@ void NativeWindow::BeforeUnloadDialogCancelled() { window_unresposive_closure_.Cancel(); } +void NativeWindow::OnRendererUnresponsive(content::RenderWidgetHost*) { + // Schedule the unresponsive shortly later, since we may receive the + // responsive event soon. This could happen after the whole application had + // blocked for a while. + // Also notice that when closing this event would be ignored because we have + // explicitly started a close timeout counter. This is on purpose because we + // don't want the unresponsive event to be sent too early when user is closing + // the window. + ScheduleUnresponsiveEvent(50); +} + void NativeWindow::ScheduleUnresponsiveEvent(int ms) { if (!window_unresposive_closure_.IsCancelled()) return; diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 858b259b57ce..9ec55440aa78 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -235,7 +235,6 @@ class NativeWindow : public base::SupportsUserData, // Methods called by the WebContents. virtual void CloseContents(content::WebContents* source); - virtual void RendererUnresponsive(content::WebContents* source); virtual void RendererResponsive(content::WebContents* source); virtual void HandleKeyboardEvent( content::WebContents*, @@ -317,6 +316,7 @@ class NativeWindow : public base::SupportsUserData, // content::WebContentsObserver: void BeforeUnloadDialogCancelled() override; + void OnRendererUnresponsive(content::RenderWidgetHost*) override; private: // Schedule a notification unresponsive event.