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.
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
#ifndef ATOM_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
|
|
|
|
#define ATOM_BROWSER_API_ATOM_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-04-14 02:04:23 +00:00
|
|
|
#include "atom/browser/api/atom_api_top_level_window.h"
|
2018-02-22 06:57:03 +00:00
|
|
|
#include "atom/browser/api/atom_api_web_contents.h"
|
2018-02-22 07:52:08 +00:00
|
|
|
#include "base/cancelable_callback.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
|
2013-04-14 07:36:48 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
namespace api {
|
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
class BrowserWindow : public TopLevelWindow,
|
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:
|
2016-08-02 06:15:40 +00:00
|
|
|
static mate::WrappableBase* New(mate::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:
|
2018-02-22 03:49:17 +00:00
|
|
|
BrowserWindow(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> wrapper,
|
|
|
|
const mate::Dictionary& options);
|
|
|
|
~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;
|
2018-02-22 07:52:08 +00:00
|
|
|
void BeforeUnloadDialogCancelled() override;
|
2018-04-11 15:23:16 +00:00
|
|
|
void OnRendererUnresponsive(content::RenderProcessHost*) override;
|
2018-02-22 06:26:04 +00:00
|
|
|
bool OnMessageReceived(const IPC::Message& message,
|
|
|
|
content::RenderFrameHost* rfh) 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;
|
2018-02-22 06:57:03 +00:00
|
|
|
void OnRendererResponsive() override;
|
|
|
|
|
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;
|
2018-04-14 02:04:23 +00:00
|
|
|
|
|
|
|
// TopLevelWindow:
|
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-07-30 01:29:18 +00:00
|
|
|
void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value) 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:
|
2018-07-10 01:43:42 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2018-07-16 01:20:35 +00:00
|
|
|
void OverrideNSWindowContentView(brightray::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.
|
2018-04-18 01:44:10 +00:00
|
|
|
void UpdateDraggableRegions(content::RenderFrameHost* rfh,
|
|
|
|
const std::vector<DraggableRegion>& 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(
|
|
|
|
const std::vector<DraggableRegion>& regions);
|
|
|
|
|
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
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
std::vector<DraggableRegion> draggable_regions_;
|
|
|
|
#endif
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
v8::Global<v8::Value> web_contents_;
|
2015-06-25 03:07:23 +00:00
|
|
|
api::WebContents* api_web_contents_;
|
|
|
|
|
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
|
|
|
|
|
2013-04-14 07:36:48 +00:00
|
|
|
} // namespace atom
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
#endif // ATOM_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
|