2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2013-04-14 07:36:48 +00:00
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2014-03-16 01:13:06 +00:00
|
|
|
#include <string>
|
2013-11-22 06:23:19 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-02-22 07:52:08 +00:00
|
|
|
#include "base/cancelable_callback.h"
|
2020-06-29 07:06:20 +00:00
|
|
|
#include "shell/browser/api/electron_api_base_window.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2020-10-27 21:28:43 +00:00
|
|
|
#include "shell/browser/ui/drag_util.h"
|
2019-10-15 01:15:23 +00:00
|
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
namespace api {
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
class BrowserWindow : public BaseWindow,
|
2018-02-22 08:07:08 +00:00
|
|
|
public content::RenderWidgetHost::InputEventObserver,
|
2018-02-22 05:52:04 +00:00
|
|
|
public content::WebContentsObserver,
|
2018-04-14 02:04:23 +00:00
|
|
|
public ExtendedWebContentsObserver {
|
2013-04-15 16:25:08 +00:00
|
|
|
public:
|
2019-12-05 09:46:34 +00:00
|
|
|
static gin_helper::WrappableBase* New(gin_helper::ErrorThrower thrower,
|
|
|
|
gin::Arguments* args);
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
static void BuildPrototype(v8::Isolate* isolate,
|
2016-08-02 09:08:12 +00:00
|
|
|
v8::Local<v8::FunctionTemplate> prototype);
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2015-10-01 05:45:59 +00:00
|
|
|
// Returns the BrowserWindow object from |native_window|.
|
|
|
|
static v8::Local<v8::Value> From(v8::Isolate* isolate,
|
|
|
|
NativeWindow* native_window);
|
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
base::WeakPtr<BrowserWindow> GetWeakPtr() {
|
|
|
|
return weak_factory_.GetWeakPtr();
|
|
|
|
}
|
2017-02-16 18:58:02 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
BrowserWindow(const BrowserWindow&) = delete;
|
|
|
|
BrowserWindow& operator=(const BrowserWindow&) = delete;
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
protected:
|
2019-10-25 13:03:28 +00:00
|
|
|
BrowserWindow(gin::Arguments* args, const gin_helper::Dictionary& options);
|
2018-02-22 03:49:17 +00:00
|
|
|
~BrowserWindow() override;
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2018-02-22 08:07:08 +00:00
|
|
|
// content::RenderWidgetHost::InputEventObserver:
|
|
|
|
void OnInputEvent(const blink::WebInputEvent& event) override;
|
|
|
|
|
2018-02-22 05:59:39 +00:00
|
|
|
// content::WebContentsObserver:
|
2018-02-22 08:07:08 +00:00
|
|
|
void RenderViewHostChanged(content::RenderViewHost* old_host,
|
|
|
|
content::RenderViewHost* new_host) override;
|
2021-03-04 17:27:05 +00:00
|
|
|
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
|
2018-02-22 05:59:39 +00:00
|
|
|
void DidFirstVisuallyNonEmptyPaint() override;
|
2018-02-22 07:52:08 +00:00
|
|
|
void BeforeUnloadDialogCancelled() override;
|
2018-04-11 15:23:16 +00:00
|
|
|
void OnRendererUnresponsive(content::RenderProcessHost*) override;
|
2020-06-01 20:34:34 +00:00
|
|
|
void OnRendererResponsive(
|
|
|
|
content::RenderProcessHost* render_process_host) override;
|
2021-03-15 22:43:25 +00:00
|
|
|
void WebContentsDestroyed() override;
|
2018-02-22 05:59:39 +00:00
|
|
|
|
2018-02-22 06:57:03 +00:00
|
|
|
// ExtendedWebContentsObserver:
|
2018-02-22 07:52:08 +00:00
|
|
|
void OnCloseContents() override;
|
2019-06-03 17:43:04 +00:00
|
|
|
void OnDraggableRegionsUpdated(
|
|
|
|
const std::vector<mojom::DraggableRegionPtr>& regions) override;
|
2020-02-11 00:37:46 +00:00
|
|
|
void OnSetContentBounds(const gfx::Rect& rect) override;
|
|
|
|
void OnActivateContents() override;
|
2021-03-16 16:18:45 +00:00
|
|
|
void OnPageTitleUpdated(const std::u16string& title,
|
2020-02-11 00:37:46 +00:00
|
|
|
bool explicit_set) override;
|
2020-11-09 21:54:04 +00:00
|
|
|
void OnDevToolsResized() override;
|
2018-02-22 06:57:03 +00:00
|
|
|
|
2014-11-25 04:43:25 +00:00
|
|
|
// NativeWindowObserver:
|
2018-03-06 03:03:12 +00:00
|
|
|
void RequestPreferredWidth(int* width) override;
|
2018-02-22 07:15:21 +00:00
|
|
|
void OnCloseButtonClicked(bool* prevent_default) override;
|
2020-06-29 20:15:28 +00:00
|
|
|
void OnWindowIsKeyChanged(bool is_key) override;
|
2021-07-01 19:25:40 +00:00
|
|
|
void UpdateWindowControlsOverlay(const gfx::Rect& bounding_rect) override;
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
// BaseWindow:
|
2014-10-27 08:58:35 +00:00
|
|
|
void OnWindowBlur() override;
|
|
|
|
void OnWindowFocus() override;
|
2015-05-09 15:55:10 +00:00
|
|
|
void OnWindowResize() override;
|
2018-06-18 07:48:20 +00:00
|
|
|
void OnWindowLeaveFullScreen() override;
|
2021-03-15 22:43:25 +00:00
|
|
|
void CloseImmediately() override;
|
2018-04-14 02:04:23 +00: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 01:49:26 +00:00
|
|
|
void AddBrowserView(v8::Local<v8::Value> value) override;
|
|
|
|
void RemoveBrowserView(v8::Local<v8::Value> value) override;
|
2021-02-10 07:23:35 +00:00
|
|
|
void SetTopBrowserView(v8::Local<v8::Value> value,
|
|
|
|
gin_helper::Arguments* args) override;
|
2018-12-22 01:49:26 +00:00
|
|
|
void ResetBrowserViews() override;
|
2018-07-30 01:29:18 +00:00
|
|
|
void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value) override;
|
2019-09-05 17:56:06 +00:00
|
|
|
void OnWindowShow() override;
|
|
|
|
void OnWindowHide() override;
|
2018-02-22 05:59:39 +00:00
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
// BrowserWindow APIs.
|
2014-04-22 15:07:21 +00:00
|
|
|
void FocusOnWebView();
|
|
|
|
void BlurWebView();
|
|
|
|
bool IsWebViewFocused();
|
2018-04-14 02:04:23 +00:00
|
|
|
v8::Local<v8::Value> GetWebContents(v8::Isolate* isolate);
|
2016-05-20 13:22:15 +00:00
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
private:
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2020-11-17 22:15:20 +00:00
|
|
|
void OverrideNSWindowContentView(InspectableWebContentsView* webView);
|
2018-07-10 01:43:42 +00:00
|
|
|
#endif
|
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
// Helpers.
|
2016-06-17 07:57:03 +00:00
|
|
|
|
2018-02-22 06:26:04 +00:00
|
|
|
// Called when the window needs to update its draggable region.
|
2019-06-03 17:43:04 +00:00
|
|
|
void UpdateDraggableRegions(
|
|
|
|
const std::vector<mojom::DraggableRegionPtr>& regions);
|
2018-02-22 06:26:04 +00:00
|
|
|
|
2018-02-22 07:52:08 +00:00
|
|
|
// Schedule a notification unresponsive event.
|
|
|
|
void ScheduleUnresponsiveEvent(int ms);
|
|
|
|
|
|
|
|
// Dispatch unresponsive event to observers.
|
|
|
|
void NotifyWindowUnresponsive();
|
|
|
|
|
|
|
|
// Closure that would be called when window is unresponsive when closing,
|
|
|
|
// it should be cancelled when we can prove that the window is responsive.
|
2021-05-06 22:01:04 +00:00
|
|
|
base::CancelableRepeatingClosure window_unresponsive_closure_;
|
2018-02-22 07:52:08 +00:00
|
|
|
|
2019-06-03 17:43:04 +00:00
|
|
|
std::vector<mojom::DraggableRegionPtr> draggable_regions_;
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
v8::Global<v8::Value> web_contents_;
|
2019-06-14 02:44:36 +00:00
|
|
|
base::WeakPtr<api::WebContents> api_web_contents_;
|
2015-06-25 03:07:23 +00:00
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
base::WeakPtrFactory<BrowserWindow> weak_factory_{this};
|
2013-04-15 16:25:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|