Turn api::Window into a WebContentsObserver
This commit is contained in:
parent
47950f7b97
commit
0d9a157914
4 changed files with 11 additions and 10 deletions
|
@ -129,6 +129,7 @@ void BrowserWindow::Init(v8::Isolate* isolate,
|
||||||
mate::Handle<class WebContents> web_contents) {
|
mate::Handle<class WebContents> web_contents) {
|
||||||
web_contents_.Reset(isolate, web_contents.ToV8());
|
web_contents_.Reset(isolate, web_contents.ToV8());
|
||||||
api_web_contents_ = web_contents.get();
|
api_web_contents_ = web_contents.get();
|
||||||
|
Observe(web_contents->web_contents());
|
||||||
|
|
||||||
// Keep a copy of the options for later use.
|
// Keep a copy of the options for later use.
|
||||||
mate::Dictionary(isolate, web_contents->GetWrapper()).Set(
|
mate::Dictionary(isolate, web_contents->GetWrapper()).Set(
|
||||||
|
@ -303,11 +304,11 @@ void BrowserWindow::OnWindowLeaveHtmlFullScreen() {
|
||||||
Emit("leave-html-full-screen");
|
Emit("leave-html-full-screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::OnRendererUnresponsive() {
|
void BrowserWindow::OnWindowUnresponsive() {
|
||||||
Emit("unresponsive");
|
Emit("unresponsive");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BrowserWindow::OnRendererResponsive() {
|
void BrowserWindow::OnWindowResponsive() {
|
||||||
Emit("responsive");
|
Emit("responsive");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#include "atom/browser/native_window_observer.h"
|
#include "atom/browser/native_window_observer.h"
|
||||||
#include "atom/common/api/atom_api_native_image.h"
|
#include "atom/common/api/atom_api_native_image.h"
|
||||||
#include "atom/common/key_weak_map.h"
|
#include "atom/common/key_weak_map.h"
|
||||||
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "native_mate/persistent_dictionary.h"
|
#include "native_mate/persistent_dictionary.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
@ -36,9 +37,8 @@ class NativeWindow;
|
||||||
|
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class WebContents;
|
|
||||||
|
|
||||||
class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
||||||
|
public content::WebContentsObserver,
|
||||||
public NativeWindowObserver {
|
public NativeWindowObserver {
|
||||||
public:
|
public:
|
||||||
static mate::WrappableBase* New(mate::Arguments* args);
|
static mate::WrappableBase* New(mate::Arguments* args);
|
||||||
|
@ -87,8 +87,8 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
|
||||||
void OnWindowLeaveFullScreen() override;
|
void OnWindowLeaveFullScreen() override;
|
||||||
void OnWindowEnterHtmlFullScreen() override;
|
void OnWindowEnterHtmlFullScreen() override;
|
||||||
void OnWindowLeaveHtmlFullScreen() override;
|
void OnWindowLeaveHtmlFullScreen() override;
|
||||||
void OnRendererUnresponsive() override;
|
void OnWindowUnresponsive() override;
|
||||||
void OnRendererResponsive() override;
|
void OnWindowResponsive() override;
|
||||||
void OnExecuteWindowsCommand(const std::string& command_name) override;
|
void OnExecuteWindowsCommand(const std::string& command_name) override;
|
||||||
void OnTouchBarItemResult(const std::string& item_id,
|
void OnTouchBarItemResult(const std::string& item_id,
|
||||||
const base::DictionaryValue& details) override;
|
const base::DictionaryValue& details) override;
|
||||||
|
|
|
@ -489,7 +489,7 @@ void NativeWindow::RendererUnresponsive(content::WebContents* source) {
|
||||||
void NativeWindow::RendererResponsive(content::WebContents* source) {
|
void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||||
window_unresposive_closure_.Cancel();
|
window_unresposive_closure_.Cancel();
|
||||||
for (NativeWindowObserver& observer : observers_)
|
for (NativeWindowObserver& observer : observers_)
|
||||||
observer.OnRendererResponsive();
|
observer.OnWindowResponsive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::NotifyWindowClosed() {
|
void NativeWindow::NotifyWindowClosed() {
|
||||||
|
@ -727,7 +727,7 @@ void NativeWindow::NotifyWindowUnresponsive() {
|
||||||
|
|
||||||
if (!is_closed_ && !IsUnresponsiveEventSuppressed() && IsEnabled()) {
|
if (!is_closed_ && !IsUnresponsiveEventSuppressed() && IsEnabled()) {
|
||||||
for (NativeWindowObserver& observer : observers_)
|
for (NativeWindowObserver& observer : observers_)
|
||||||
observer.OnRendererUnresponsive();
|
observer.OnWindowUnresponsive();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,10 +86,10 @@ class NativeWindowObserver {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Called when renderer is hung.
|
// Called when renderer is hung.
|
||||||
virtual void OnRendererUnresponsive() {}
|
virtual void OnWindowUnresponsive() {}
|
||||||
|
|
||||||
// Called when renderer recovers.
|
// Called when renderer recovers.
|
||||||
virtual void OnRendererResponsive() {}
|
virtual void OnWindowResponsive() {}
|
||||||
|
|
||||||
// Called on Windows when App Commands arrive (WM_APPCOMMAND)
|
// Called on Windows when App Commands arrive (WM_APPCOMMAND)
|
||||||
virtual void OnExecuteWindowsCommand(const std::string& command_name) {}
|
virtual void OnExecuteWindowsCommand(const std::string& command_name) {}
|
||||||
|
|
Loading…
Reference in a new issue