Turn api::Window into a WebContentsObserver

This commit is contained in:
Cheng Zhao 2018-02-22 14:52:04 +09:00
Родитель 47950f7b97
Коммит 0d9a157914
4 изменённых файлов: 11 добавлений и 10 удалений

Просмотреть файл

@ -129,6 +129,7 @@ void BrowserWindow::Init(v8::Isolate* isolate,
mate::Handle<class WebContents> 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");
}

Просмотреть файл

@ -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<BrowserWindow>,
public content::WebContentsObserver,
public NativeWindowObserver {
public:
static mate::WrappableBase* New(mate::Arguments* args);
@ -87,8 +87,8 @@ class BrowserWindow : public mate::TrackableObject<BrowserWindow>,
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;

Просмотреть файл

@ -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();
}
}

Просмотреть файл

@ -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) {}