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.
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#ifndef SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|
|
|
|
#define SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2018-09-13 00:25:56 +00:00
|
|
|
#include <memory>
|
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"
|
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
|
|
|
|
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;
|
2018-02-22 06:04:32 +00:00
|
|
|
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
2018-02-22 05:59:39 +00:00
|
|
|
void DidFirstVisuallyNonEmptyPaint() override;
|
2020-09-15 18:48:39 +00:00
|
|
|
void DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
const GURL& validated_url) 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;
|
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;
|
|
|
|
void OnPageTitleUpdated(const base::string16& title,
|
|
|
|
bool explicit_set) 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;
|
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 OnWindowClosed() override;
|
|
|
|
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;
|
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;
|
|
|
|
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)
|
2018-10-19 13:50:30 +00:00
|
|
|
void OverrideNSWindowContentView(InspectableWebContents* iwc);
|
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-03-06 05:44:36 +00:00
|
|
|
// Convert draggable regions in raw format to SkRegion format.
|
|
|
|
std::unique_ptr<SkRegion> DraggableRegionsToSkRegion(
|
2019-06-03 17:43:04 +00:00
|
|
|
const std::vector<mojom::DraggableRegionPtr>& regions);
|
2018-03-06 05:44:36 +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();
|
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
// Cleanup our WebContents observers.
|
|
|
|
void Cleanup();
|
2018-03-06 05:44:36 +00:00
|
|
|
|
2018-02-22 07:52:08 +00: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 00:15:13 +00:00
|
|
|
base::CancelableClosure window_unresponsive_closure_;
|
2018-02-22 07:52:08 +00:00
|
|
|
|
2020-09-15 18:48:39 +00:00
|
|
|
bool did_ready_to_show_fired_ = false;
|
|
|
|
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2019-06-03 17:43:04 +00:00
|
|
|
std::vector<mojom::DraggableRegionPtr> draggable_regions_;
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
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
|
|
|
|
2018-02-22 05:59:39 +00:00
|
|
|
base::WeakPtrFactory<BrowserWindow> weak_factory_;
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(BrowserWindow);
|
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
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
#endif // SHELL_BROWSER_API_ELECTRON_API_BROWSER_WINDOW_H_
|