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.
|
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|
2013-04-14 15:36:48 +08:00
|
|
|
|
2014-03-16 09:13:06 +08:00
|
|
|
#include <string>
|
2013-11-22 14:23:19 +08:00
|
|
|
|
2018-02-22 16:52:08 +09:00
|
|
|
#include "base/cancelable_callback.h"
|
2020-06-29 16:06:20 +09:00
|
|
|
#include "shell/browser/api/electron_api_base_window.h"
|
2019-06-19 13:46:59 -07:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2020-10-27 14:28:43 -07:00
|
|
|
#include "shell/browser/ui/drag_util.h"
|
2019-10-15 10:15:23 +09:00
|
|
|
#include "shell/common/gin_helper/error_thrower.h"
|
2014-04-22 23:07:21 +08:00
|
|
|
|
2022-06-29 12:55:47 -07:00
|
|
|
namespace electron::api {
|
2013-04-16 00:25:08 +08:00
|
|
|
|
2020-06-29 16:06:20 +09:00
|
|
|
class BrowserWindow : public BaseWindow,
|
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:
|
2019-12-05 18:46:34 +09:00
|
|
|
static gin_helper::WrappableBase* New(gin_helper::ErrorThrower thrower,
|
|
|
|
gin::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
|
|
|
|
2021-11-03 12:41:45 +01:00
|
|
|
// disable copy
|
|
|
|
BrowserWindow(const BrowserWindow&) = delete;
|
|
|
|
BrowserWindow& operator=(const BrowserWindow&) = delete;
|
|
|
|
|
2013-04-16 00:25:08 +08:00
|
|
|
protected:
|
2019-10-25 22:03:28 +09:00
|
|
|
BrowserWindow(gin::Arguments* args, const gin_helper::Dictionary& options);
|
2018-02-22 12:49:17 +09:00
|
|
|
~BrowserWindow() override;
|
2013-04-16 00:25:08 +08:00
|
|
|
|
2018-02-22 14:59:39 +09:00
|
|
|
// content::WebContentsObserver:
|
2018-02-22 16:52:08 +09:00
|
|
|
void BeforeUnloadDialogCancelled() override;
|
2018-04-11 20:53:16 +05:30
|
|
|
void OnRendererUnresponsive(content::RenderProcessHost*) override;
|
2020-06-01 13:34:34 -07:00
|
|
|
void OnRendererResponsive(
|
|
|
|
content::RenderProcessHost* render_process_host) override;
|
2021-03-15 18:43:25 -04:00
|
|
|
void WebContentsDestroyed() override;
|
2018-02-22 14:59:39 +09:00
|
|
|
|
2018-02-22 15:57:03 +09:00
|
|
|
// ExtendedWebContentsObserver:
|
2020-02-11 09:37:46 +09:00
|
|
|
void OnSetContentBounds(const gfx::Rect& rect) override;
|
|
|
|
void OnActivateContents() override;
|
2021-03-16 12:18:45 -04:00
|
|
|
void OnPageTitleUpdated(const std::u16string& title,
|
2020-02-11 09:37:46 +09:00
|
|
|
bool explicit_set) 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;
|
2020-06-29 13:15:28 -07:00
|
|
|
void OnWindowIsKeyChanged(bool is_key) override;
|
2021-07-01 15:25:40 -04:00
|
|
|
void UpdateWindowControlsOverlay(const gfx::Rect& bounding_rect) override;
|
2018-04-14 11:04:23 +09:00
|
|
|
|
2020-06-29 16:06:20 +09:00
|
|
|
// BaseWindow:
|
2014-10-27 16:58:35 +08:00
|
|
|
void OnWindowBlur() override;
|
|
|
|
void OnWindowFocus() override;
|
2018-06-18 09:48:20 +02:00
|
|
|
void OnWindowLeaveFullScreen() override;
|
2021-03-15 18:43:25 -04:00
|
|
|
void CloseImmediately() override;
|
2018-04-14 11:04:23 +09:00
|
|
|
void Focus() override;
|
|
|
|
void Blur() override;
|
|
|
|
void SetBackgroundColor(const std::string& color_name) 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:
|
|
|
|
// Helpers.
|
2016-06-17 16:57:03 +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();
|
|
|
|
|
|
|
|
// 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 15:01:04 -07:00
|
|
|
base::CancelableRepeatingClosure window_unresponsive_closure_;
|
2018-02-22 16:52:08 +09:00
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
v8::Global<v8::Value> web_contents_;
|
2024-04-08 10:30:23 -07:00
|
|
|
v8::Global<v8::Value> web_contents_view_;
|
2019-06-14 04:44:36 +02:00
|
|
|
base::WeakPtr<api::WebContents> api_web_contents_;
|
2015-06-25 11:07:23 +08:00
|
|
|
|
2021-01-26 19:16:21 +01:00
|
|
|
base::WeakPtrFactory<BrowserWindow> weak_factory_{this};
|
2013-04-16 00:25:08 +08:00
|
|
|
};
|
|
|
|
|
2022-06-29 12:55:47 -07:00
|
|
|
} // namespace electron::api
|
2013-04-14 15:36:48 +08:00
|
|
|
|
2021-11-22 08:34:31 +01:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|