diff --git a/atom/browser/api/atom_api_browser_window.cc b/atom/browser/api/atom_api_browser_window.cc index c1fc97476d..c9efa64487 100644 --- a/atom/browser/api/atom_api_browser_window.cc +++ b/atom/browser/api/atom_api_browser_window.cc @@ -129,6 +129,7 @@ void BrowserWindow::Init(v8::Isolate* isolate, mate::Handle web_contents) { web_contents_.Reset(isolate, web_contents.ToV8()); api_web_contents_ = web_contents.get(); + Observe(web_contents->web_contents()); // Keep a copy of the options for later use. mate::Dictionary(isolate, web_contents->GetWrapper()).Set( @@ -303,11 +304,11 @@ void BrowserWindow::OnWindowLeaveHtmlFullScreen() { Emit("leave-html-full-screen"); } -void BrowserWindow::OnRendererUnresponsive() { +void BrowserWindow::OnWindowUnresponsive() { Emit("unresponsive"); } -void BrowserWindow::OnRendererResponsive() { +void BrowserWindow::OnWindowResponsive() { Emit("responsive"); } diff --git a/atom/browser/api/atom_api_browser_window.h b/atom/browser/api/atom_api_browser_window.h index 50d77a2492..c1a91d51e8 100644 --- a/atom/browser/api/atom_api_browser_window.h +++ b/atom/browser/api/atom_api_browser_window.h @@ -15,6 +15,7 @@ #include "atom/browser/native_window_observer.h" #include "atom/common/api/atom_api_native_image.h" #include "atom/common/key_weak_map.h" +#include "content/public/browser/web_contents_observer.h" #include "native_mate/handle.h" #include "native_mate/persistent_dictionary.h" #include "ui/gfx/image/image.h" @@ -36,9 +37,8 @@ class NativeWindow; namespace api { -class WebContents; - class BrowserWindow : public mate::TrackableObject, + public content::WebContentsObserver, public NativeWindowObserver { public: static mate::WrappableBase* New(mate::Arguments* args); @@ -87,8 +87,8 @@ class BrowserWindow : public mate::TrackableObject, void OnWindowLeaveFullScreen() override; void OnWindowEnterHtmlFullScreen() override; void OnWindowLeaveHtmlFullScreen() override; - void OnRendererUnresponsive() override; - void OnRendererResponsive() override; + void OnWindowUnresponsive() override; + void OnWindowResponsive() override; void OnExecuteWindowsCommand(const std::string& command_name) override; void OnTouchBarItemResult(const std::string& item_id, const base::DictionaryValue& details) override; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 34778fb643..a34c4648da 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -489,7 +489,7 @@ void NativeWindow::RendererUnresponsive(content::WebContents* source) { void NativeWindow::RendererResponsive(content::WebContents* source) { window_unresposive_closure_.Cancel(); for (NativeWindowObserver& observer : observers_) - observer.OnRendererResponsive(); + observer.OnWindowResponsive(); } void NativeWindow::NotifyWindowClosed() { @@ -727,7 +727,7 @@ void NativeWindow::NotifyWindowUnresponsive() { if (!is_closed_ && !IsUnresponsiveEventSuppressed() && IsEnabled()) { for (NativeWindowObserver& observer : observers_) - observer.OnRendererUnresponsive(); + observer.OnWindowUnresponsive(); } } diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index 9aad030aa3..f21fbcc570 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -86,10 +86,10 @@ class NativeWindowObserver { #endif // Called when renderer is hung. - virtual void OnRendererUnresponsive() {} + virtual void OnWindowUnresponsive() {} // Called when renderer recovers. - virtual void OnRendererResponsive() {} + virtual void OnWindowResponsive() {} // Called on Windows when App Commands arrive (WM_APPCOMMAND) virtual void OnExecuteWindowsCommand(const std::string& command_name) {}