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.
|
|
|
|
|
2018-02-22 12:49:17 +09:00
|
|
|
#ifndef ATOM_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
|
|
|
|
#define ATOM_BROWSER_API_ATOM_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
|
|
|
#include <vector>
|
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
#include "atom/browser/api/atom_api_top_level_window.h"
|
2018-02-22 15:57:03 +09:00
|
|
|
#include "atom/browser/api/atom_api_web_contents.h"
|
2018-02-22 16:52:08 +09:00
|
|
|
#include "base/cancelable_callback.h"
|
2014-04-22 23:07:21 +08:00
|
|
|
|
2013-04-14 15:36:48 +08:00
|
|
|
namespace atom {
|
|
|
|
|
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 15:26:04 +09:00
|
|
|
bool OnMessageReceived(const IPC::Message& message,
|
|
|
|
content::RenderFrameHost* rfh) 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;
|
|
|
|
|
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-07-30 13:02:32 +10:00
|
|
|
void SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value) 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 13:09:46 +09:00
|
|
|
#if defined(OS_MACOSX)
|
2018-07-16 10:20:35 +09:00
|
|
|
void OverrideNSWindowContentView(brightray::InspectableWebContents* iwc);
|
2018-07-10 13:09:46 +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.
|
2018-04-17 21:44:10 -04:00
|
|
|
void UpdateDraggableRegions(content::RenderFrameHost* rfh,
|
|
|
|
const std::vector<DraggableRegion>& 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(
|
|
|
|
const std::vector<DraggableRegion>& regions);
|
|
|
|
|
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)
|
|
|
|
std::vector<DraggableRegion> draggable_regions_;
|
|
|
|
#endif
|
2013-04-18 15:09:53 +08:00
|
|
|
|
2018-04-14 11:04:23 +09:00
|
|
|
v8::Global<v8::Value> web_contents_;
|
2015-06-25 11:07:23 +08:00
|
|
|
api::WebContents* api_web_contents_;
|
|
|
|
|
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
|
|
|
|
|
2013-04-14 15:36:48 +08:00
|
|
|
} // namespace atom
|
|
|
|
|
2018-02-22 12:49:17 +09:00
|
|
|
#endif // ATOM_BROWSER_API_ATOM_API_BROWSER_WINDOW_H_
|