2014-10-31 11:17:05 -07:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 17:49:37 +08:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-14 15:36:48 +08:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#ifndef SHELL_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
|
|
|
|
#define SHELL_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
|
2013-04-14 15:36:48 +08:00
|
|
|
|
2018-09-12 19:25:56 -05:00
|
|
|
#include <memory>
|
2014-03-16 09:13:06 +08:00
|
|
|
#include <string>
|
2013-11-22 14:23:19 +08:00
|
|
|
#include <vector>
|
|
|
|
|
2018-02-22 16:52:08 +09:00
|
|
|
#include "base/cancelable_callback.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/api/atom_api_top_level_window.h"
|
|
|
|
#include "shell/browser/api/atom_api_web_contents.h"
|
2014-04-22 23:07:21 +08:00
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
namespace electron {
|
2013-04-14 15:36:48 +08:00
|
|
|
|
2013-04-16 00:25:08 +08:00
|
|
|
namespace api {
|
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
class BrowserWindow : public TopLevelWindow,
|
2018-02-22 17:07:08 +09:00
|
|
|
public content::RenderWidgetHost::InputEventObserver,
|
2018-02-22 14:52:04 +09:00
|
|
|
public content::WebContentsObserver,
|
2018-04-14 11:04:23 +09:00
|
|
|
public ExtendedWebContentsObserver {
|
2013-04-16 00:25:08 +08:00
|
|
|
public:
|
2016-08-02 15:15:40 +09:00
|
|
|
static mate::WrappableBase* New(mate::Arguments* args);
|
2013-04-16 00:25:08 +08:00
|
|
|
|
2014-04-22 23:07:21 +08:00
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 18:08:12 +09:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2013-04-16 00:25:08 +08:00
|
|
|
|
2015-10-01 13:45:59 +08:00
|
|
|
// Returns the BrowserWindow object from |native_window|.
|
|
|
|
static v8::Local<v8::Value> From(v8::Isolate* isolate,
|
|
|
|
NativeWindow* native_window);
|
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
base::WeakPtr<BrowserWindow> GetWeakPtr() {
|
|
|
|
return weak_factory_.GetWeakPtr();
|
|
|
|
}
|
2017-02-16 10:58:02 -08:00
|
|
|
|
2013-04-16 00:25:08 +08:00
|
|
|
protected:
|
2018-02-22 12:49:17 +09:00
|
|
|
BrowserWindow(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> wrapper,
|
|
|
|
const mate::Dictionary& options);
|
|
|
|
~BrowserWindow() override;
|
2013-04-16 00:25:08 +08:00
|
|
|
|
2018-02-22 17:07:08 +09:00
|
|
|
// content::RenderWidgetHost::InputEventObserver:
|
|
|
|
void OnInputEvent(const blink::WebInputEvent& event) override;
|
|
|
|
|
2018-02-22 14:59:39 +09:00
|
|
|
// content::WebContentsObserver:
|
2018-02-22 17:07:08 +09:00
|
|
|
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
|
|
|
content::RenderViewHost* new_host) override;
|
2018-02-22 15:04:32 +09:00
|
|
|
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
2018-02-22 14:59:39 +09:00
|
|
|
void DidFirstVisuallyNonEmptyPaint() override;
|
2018-02-22 16:52:08 +09:00
|
|
|
void BeforeUnloadDialogCancelled() override;
|
2018-04-11 20:53:16 +05:30
|
|
|
void OnRendererUnresponsive(content::RenderProcessHost*) override;
|
2018-02-22 14:59:39 +09:00
|
|
|
|
2018-02-22 15:57:03 +09:00
|
|
|
// ExtendedWebContentsObserver:
|
2018-02-22 16:52:08 +09:00
|
|
|
void OnCloseContents() override;
|
2018-02-22 15:57:03 +09:00
|
|
|
void OnRendererResponsive() override;
|
2019-06-03 10:43:04 -07:00
|
|
|
void OnDraggableRegionsUpdated(
|
|
|
|
const std::vector<mojom::DraggableRegionPtr>& regions) override;
|
2018-02-22 15:57:03 +09:00
|
|
|
|
2014-11-25 12:43:25 +08:00
|
|
|
// NativeWindowObserver:
|
2018-03-06 12:03:12 +09:00
|
|
|
void RequestPreferredWidth(int* width) override;
|
2018-02-22 16:15:21 +09:00
|
|
|
void OnCloseButtonClicked(bool* prevent_default) override;
|
2018-04-14 11:04:23 +09:00
|
|
|
|
|
|
|
// TopLevelWindow:
|
2014-10-27 16:58:35 +08:00
|
|
|
void OnWindowClosed() override;
|
|
|
|
void OnWindowBlur() override;
|
|
|
|
void OnWindowFocus() override;
|
2015-05-09 21:25:10 +05:30
|
|
|
void OnWindowResize() override;
|
2018-06-18 09:48:20 +02:00
|
|
|
void OnWindowLeaveFullScreen() override;
|
2018-04-14 11:04:23 +09:00
|
|
|
void Focus() override;
|
|
|
|
void Blur() override;
|
|
|
|
void SetBackgroundColor(const std::string& color_name) override;
|
|
|
|
void SetBrowserView(v8::Local<v8::Value> value) override;
|
2018-12-22 04:49:26 +03:00
|
|
|
void AddBrowserView(v8::Local<v8::Value> value) override;
|
|
|
|
void RemoveBrowserView(v8::Local<v8::Value> value) override;
|
|
|
|
void ResetBrowserViews() override;
|
2018-07-30 03:29:18 +02:00
|
|
|
void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value) override;
|
2019-09-05 10:56:06 -07:00
|
|
|
void OnWindowShow() override;
|
|
|
|
void OnWindowHide() override;
|
2018-02-22 14:59:39 +09:00
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
// BrowserWindow APIs.
|
2014-04-22 23:07:21 +08:00
|
|
|
void FocusOnWebView();
|
|
|
|
void BlurWebView();
|
|
|
|
bool IsWebViewFocused();
|
2018-04-14 11:04:23 +09:00
|
|
|
v8::Local<v8::Value> GetWebContents(v8::Isolate* isolate);
|
2016-05-20 22:22:15 +09:00
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
private:
|
2018-07-10 10:43:42 +09:00
|
|
|
#if defined(OS_MACOSX)
|
2018-10-19 15:50:30 +02:00
|
|
|
void OverrideNSWindowContentView(InspectableWebContents* iwc);
|
2018-07-10 10:43:42 +09:00
|
|
|
#endif
|
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
// Helpers.
|
2016-06-17 16:57:03 +09:00
|
|
|
|
2018-02-22 15:26:04 +09:00
|
|
|
// Called when the window needs to update its draggable region.
|
2019-06-03 10:43:04 -07:00
|
|
|
void UpdateDraggableRegions(
|
|
|
|
const std::vector<mojom::DraggableRegionPtr>& regions);
|
2018-02-22 15:26:04 +09:00
|
|
|
|
2018-03-06 14:44:36 +09:00
|
|
|
// Convert draggable regions in raw format to SkRegion format.
|
|
|
|
std::unique_ptr<SkRegion> DraggableRegionsToSkRegion(
|
2019-06-03 10:43:04 -07:00
|
|
|
const std::vector<mojom::DraggableRegionPtr>& regions);
|
2018-03-06 14:44:36 +09:00
|
|
|
|
2018-02-22 16:52:08 +09:00
|
|
|
// Schedule a notification unresponsive event.
|
|
|
|
void ScheduleUnresponsiveEvent(int ms);
|
|
|
|
|
|
|
|
// Dispatch unresponsive event to observers.
|
|
|
|
void NotifyWindowUnresponsive();
|
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
// Cleanup our WebContents observers.
|
|
|
|
void Cleanup();
|
2018-03-06 14:44:36 +09:00
|
|
|
|
2018-02-22 16:52:08 +09:00
|
|
|
// Closure that would be called when window is unresponsive when closing,
|
|
|
|
// it should be cancelled when we can prove that the window is responsive.
|
2018-02-23 09:15:13 +09:00
|
|
|
base::CancelableClosure window_unresponsive_closure_;
|
2018-02-22 16:52:08 +09:00
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
#if defined(OS_MACOSX)
|
2019-06-03 10:43:04 -07:00
|
|
|
std::vector<mojom::DraggableRegionPtr> draggable_regions_;
|
2018-04-14 11:04:23 +09:00
|
|
|
#endif
|
2013-04-18 15:09:53 +08:00
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
v8::Global<v8::Value> web_contents_;
|
2019-06-14 04:44:36 +02:00
|
|
|
base::WeakPtr<api::WebContents> api_web_contents_;
|
2015-06-25 11:07:23 +08:00
|
|
|
|
2018-02-22 14:59:39 +09:00
|
|
|
base::WeakPtrFactory<BrowserWindow> weak_factory_;
|
|
|
|
|
2018-02-22 12:49:17 +09:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(BrowserWindow);
|
2013-04-16 00:25:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 14:23:04 -07:00
|
|
|
} // namespace electron
|
2013-04-14 15:36:48 +08:00
|
|
|
|
2019-06-19 13:56:58 -07:00
|
|
|
#endif // SHELL_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
|