2018-04-14 02:04:23 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
#include "shell/browser/api/electron_api_base_window.h"
|
2018-04-14 02:04:23 +00:00
|
|
|
|
|
|
|
#include <string>
|
2019-10-31 07:56:00 +00:00
|
|
|
#include <utility>
|
2018-04-14 02:04:23 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2019-09-06 05:52:54 +00:00
|
|
|
#include "gin/dictionary.h"
|
2020-02-04 20:19:40 +00:00
|
|
|
#include "shell/browser/api/electron_api_browser_view.h"
|
|
|
|
#include "shell/browser/api/electron_api_menu.h"
|
|
|
|
#include "shell/browser/api/electron_api_view.h"
|
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2020-07-28 22:09:56 +00:00
|
|
|
#include "shell/browser/javascript_environment.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/color_util.h"
|
2019-09-06 05:52:54 +00:00
|
|
|
#include "shell/common/gin_converters/callback_converter.h"
|
2019-10-21 07:05:40 +00:00
|
|
|
#include "shell/common/gin_converters/file_path_converter.h"
|
|
|
|
#include "shell/common/gin_converters/gfx_converter.h"
|
2019-09-06 05:52:54 +00:00
|
|
|
#include "shell/common/gin_converters/image_converter.h"
|
2019-10-21 07:05:40 +00:00
|
|
|
#include "shell/common/gin_converters/native_window_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2019-10-21 07:05:40 +00:00
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
|
|
|
#include "shell/common/gin_helper/object_template_builder.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
#include "shell/common/gin_helper/persistent_dictionary.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/common/node_includes.h"
|
|
|
|
#include "shell/common/options_switches.h"
|
2018-04-14 02:04:23 +00:00
|
|
|
|
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/native_window_views.h"
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/ui/win/taskbar_host.h"
|
2018-04-14 02:04:23 +00:00
|
|
|
#include "ui/base/win/shell.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2019-10-21 07:05:40 +00:00
|
|
|
namespace gin {
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
template <>
|
2019-06-19 21:23:04 +00:00
|
|
|
struct Converter<electron::TaskbarHost::ThumbarButton> {
|
2018-04-18 01:55:30 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Handle<v8::Value> val,
|
2019-06-19 21:23:04 +00:00
|
|
|
electron::TaskbarHost::ThumbarButton* out) {
|
2019-09-08 15:10:18 +00:00
|
|
|
gin::Dictionary dict(isolate);
|
2019-09-06 05:52:54 +00:00
|
|
|
if (!gin::ConvertFromV8(isolate, val, &dict))
|
2018-04-14 02:04:23 +00:00
|
|
|
return false;
|
|
|
|
dict.Get("click", &(out->clicked_callback));
|
|
|
|
dict.Get("tooltip", &(out->tooltip));
|
|
|
|
dict.Get("flags", &out->flags);
|
|
|
|
return dict.Get("icon", &(out->icon));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-21 07:05:40 +00:00
|
|
|
} // namespace gin
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-04-14 02:04:23 +00:00
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Converts binary data to Buffer.
|
|
|
|
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
|
|
|
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
|
|
|
if (buffer.IsEmpty())
|
|
|
|
return v8::Null(isolate);
|
|
|
|
else
|
|
|
|
return buffer.ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
BaseWindow::BaseWindow(v8::Isolate* isolate,
|
|
|
|
const gin_helper::Dictionary& options)
|
2018-04-14 02:04:23 +00:00
|
|
|
: weak_factory_(this) {
|
|
|
|
// The parent window.
|
2020-06-29 07:06:20 +00:00
|
|
|
gin::Handle<BaseWindow> parent;
|
2018-04-14 02:04:23 +00:00
|
|
|
if (options.Get("parent", &parent) && !parent.IsEmpty())
|
|
|
|
parent_window_.Reset(isolate, parent.ToV8());
|
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2018-04-14 02:04:23 +00:00
|
|
|
// Offscreen windows are always created frameless.
|
2019-10-21 07:05:40 +00:00
|
|
|
gin_helper::Dictionary web_preferences;
|
2018-04-14 02:04:23 +00:00
|
|
|
bool offscreen;
|
|
|
|
if (options.Get(options::kWebPreferences, &web_preferences) &&
|
2018-05-29 08:09:51 +00:00
|
|
|
web_preferences.Get(options::kOffscreen, &offscreen) && offscreen) {
|
2019-10-21 07:05:40 +00:00
|
|
|
const_cast<gin_helper::Dictionary&>(options).Set(options::kFrame, false);
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Creates NativeWindow.
|
|
|
|
window_.reset(NativeWindow::Create(
|
2018-04-18 01:55:30 +00:00
|
|
|
options, parent.IsEmpty() ? nullptr : parent->window_.get()));
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->AddObserver(this);
|
|
|
|
|
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2020-07-07 21:18:43 +00:00
|
|
|
{
|
|
|
|
v8::TryCatch try_catch(isolate);
|
|
|
|
gin::Handle<NativeImage> icon;
|
|
|
|
if (options.Get(options::kIcon, &icon) && !icon.IsEmpty())
|
|
|
|
SetIcon(icon);
|
|
|
|
if (try_catch.HasCaught())
|
|
|
|
LOG(ERROR) << "Failed to convert NativeImage";
|
|
|
|
}
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
BaseWindow::BaseWindow(gin_helper::Arguments* args,
|
|
|
|
const gin_helper::Dictionary& options)
|
|
|
|
: BaseWindow(args->isolate(), options) {
|
2019-10-15 01:15:23 +00:00
|
|
|
InitWithArgs(args);
|
2018-04-17 07:29:16 +00:00
|
|
|
// Init window after everything has been setup.
|
|
|
|
window()->InitFromOptions(options);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
BaseWindow::~BaseWindow() {
|
2018-04-14 02:04:23 +00:00
|
|
|
if (!window_->IsClosed())
|
|
|
|
window_->CloseImmediately();
|
|
|
|
|
|
|
|
// Destroy the native window in next tick because the native code might be
|
|
|
|
// iterating all windows.
|
|
|
|
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release());
|
2020-02-11 00:37:46 +00:00
|
|
|
|
|
|
|
// Remove global reference so the JS object can be garbage collected.
|
|
|
|
self_ref_.Reset();
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) {
|
2018-04-17 07:18:55 +00:00
|
|
|
AttachAsUserData(window_.get());
|
2020-06-29 07:06:20 +00:00
|
|
|
gin_helper::TrackableObject<BaseWindow>::InitWith(isolate, wrapper);
|
2018-04-17 07:18:55 +00:00
|
|
|
|
|
|
|
// We can only append this window to parent window's child windows after this
|
|
|
|
// window's JS wrapper gets initialized.
|
|
|
|
if (!parent_window_.IsEmpty()) {
|
2020-06-29 07:06:20 +00:00
|
|
|
gin::Handle<BaseWindow> parent;
|
2019-10-21 07:05:40 +00:00
|
|
|
gin::ConvertFromV8(isolate, GetParentWindow(), &parent);
|
2018-04-17 07:18:55 +00:00
|
|
|
DCHECK(!parent.IsEmpty());
|
|
|
|
parent->child_windows_.Set(isolate, weak_map_id(), wrapper);
|
|
|
|
}
|
2020-02-11 00:37:46 +00:00
|
|
|
|
|
|
|
// Reference this object in case it got garbage collected.
|
|
|
|
self_ref_.Reset(isolate, wrapper);
|
2018-04-17 07:18:55 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::WillCloseWindow(bool* prevent_default) {
|
2018-04-19 10:39:17 +00:00
|
|
|
if (Emit("close")) {
|
|
|
|
*prevent_default = true;
|
|
|
|
}
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowClosed() {
|
2018-09-12 18:58:04 +00:00
|
|
|
// Invalidate weak ptrs before the Javascript object is destroyed,
|
|
|
|
// there might be some delayed emit events which shouldn't be
|
|
|
|
// triggered after this.
|
|
|
|
weak_factory_.InvalidateWeakPtrs();
|
|
|
|
|
2018-04-14 02:04:23 +00:00
|
|
|
RemoveFromWeakMap();
|
|
|
|
window_->RemoveObserver(this);
|
|
|
|
|
|
|
|
// We can not call Destroy here because we need to call Emit first, but we
|
|
|
|
// also do not want any method to be used, so just mark as destroyed here.
|
|
|
|
MarkDestroyed();
|
|
|
|
|
|
|
|
Emit("closed");
|
|
|
|
|
|
|
|
RemoveFromParentChildWindows();
|
2020-06-29 07:06:20 +00:00
|
|
|
BaseWindow::ResetBrowserViews();
|
2018-04-14 02:04:23 +00:00
|
|
|
|
|
|
|
// Destroy the native class when window is closed.
|
|
|
|
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, GetDestroyClosure());
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowEndSession() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("session-end");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowBlur() {
|
2018-09-07 18:21:58 +00:00
|
|
|
EmitEventSoon("blur");
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowFocus() {
|
2018-09-07 18:21:58 +00:00
|
|
|
EmitEventSoon("focus");
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowShow() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("show");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowHide() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("hide");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowMaximize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("maximize");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowUnmaximize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("unmaximize");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowMinimize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("minimize");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowRestore() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("restore");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowWillResize(const gfx::Rect& new_bounds,
|
|
|
|
bool* prevent_default) {
|
2018-07-27 09:53:01 +00:00
|
|
|
if (Emit("will-resize", new_bounds)) {
|
|
|
|
*prevent_default = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowResize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("resize");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowWillMove(const gfx::Rect& new_bounds,
|
|
|
|
bool* prevent_default) {
|
2018-08-28 13:44:10 +00:00
|
|
|
if (Emit("will-move", new_bounds)) {
|
|
|
|
*prevent_default = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowMove() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("move");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowMoved() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("moved");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowEnterFullScreen() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("enter-full-screen");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowLeaveFullScreen() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("leave-full-screen");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowScrollTouchBegin() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("scroll-touch-begin");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowScrollTouchEnd() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("scroll-touch-end");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowSwipe(const std::string& direction) {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("swipe", direction);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowRotateGesture(float rotation) {
|
2019-07-23 19:42:26 +00:00
|
|
|
Emit("rotate-gesture", rotation);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowSheetBegin() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("sheet-begin");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowSheetEnd() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("sheet-end");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowEnterHtmlFullScreen() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("enter-html-full-screen");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowLeaveHtmlFullScreen() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("leave-html-full-screen");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowAlwaysOnTopChanged() {
|
2018-10-04 18:02:16 +00:00
|
|
|
Emit("always-on-top-changed", IsAlwaysOnTop());
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnExecuteAppCommand(const std::string& command_name) {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("app-command", command_name);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnTouchBarItemResult(const std::string& item_id,
|
|
|
|
const base::DictionaryValue& details) {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("-touch-bar-interaction", item_id, details);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnNewWindowForTab() {
|
2018-04-14 02:04:23 +00:00
|
|
|
Emit("new-window-for-tab");
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
|
2018-04-14 02:04:23 +00:00
|
|
|
if (IsWindowMessageHooked(message)) {
|
2020-07-28 22:09:56 +00:00
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
v8::Locker locker(isolate);
|
|
|
|
v8::HandleScope scope(isolate);
|
2018-04-14 02:04:23 +00:00
|
|
|
messages_callback_map_[message].Run(
|
2020-07-28 22:09:56 +00:00
|
|
|
ToBuffer(isolate, static_cast<void*>(&w_param), sizeof(WPARAM)),
|
|
|
|
ToBuffer(isolate, static_cast<void*>(&l_param), sizeof(LPARAM)));
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetContentView(gin::Handle<View> view) {
|
2018-12-22 01:49:26 +00:00
|
|
|
ResetBrowserViews();
|
2018-05-08 05:47:26 +00:00
|
|
|
content_view_.Reset(isolate(), view.ToV8());
|
|
|
|
window_->SetContentView(view->view());
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Close() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Close();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Focus() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Focus(true);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Blur() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Focus(false);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsFocused() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsFocused();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Show() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Show();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::ShowInactive() {
|
2018-04-14 02:04:23 +00:00
|
|
|
// This method doesn't make sense for modal window.
|
|
|
|
if (IsModal())
|
|
|
|
return;
|
|
|
|
window_->ShowInactive();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Hide() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Hide();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsVisible() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsVisible();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsEnabled() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsEnabled();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetEnabled(bool enable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetEnabled(enable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Maximize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Maximize();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Unmaximize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Unmaximize();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsMaximized() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsMaximized();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Minimize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Minimize();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Restore() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Restore();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsMinimized() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsMinimized();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetFullScreen(bool fullscreen) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetFullScreen(fullscreen);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsFullscreen() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsFullscreen();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetBounds(const gfx::Rect& bounds,
|
|
|
|
gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
bool animate = false;
|
|
|
|
args->GetNext(&animate);
|
|
|
|
window_->SetBounds(bounds, animate);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
gfx::Rect BaseWindow::GetBounds() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->GetBounds();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsNormal() {
|
2018-08-24 21:33:27 +00:00
|
|
|
return window_->IsNormal();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
gfx::Rect BaseWindow::GetNormalBounds() {
|
2018-08-24 21:33:27 +00:00
|
|
|
return window_->GetNormalBounds();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetContentBounds(const gfx::Rect& bounds,
|
|
|
|
gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
bool animate = false;
|
|
|
|
args->GetNext(&animate);
|
|
|
|
window_->SetContentBounds(bounds, animate);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
gfx::Rect BaseWindow::GetContentBounds() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->GetContentBounds();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetSize(int width, int height, gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
bool animate = false;
|
2018-10-09 17:08:15 +00:00
|
|
|
gfx::Size size = window_->GetMinimumSize();
|
|
|
|
size.SetToMax(gfx::Size(width, height));
|
2018-04-14 02:04:23 +00:00
|
|
|
args->GetNext(&animate);
|
2018-10-09 17:08:15 +00:00
|
|
|
window_->SetSize(size, animate);
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::vector<int> BaseWindow::GetSize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetContentSize(int width,
|
|
|
|
int height,
|
|
|
|
gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
bool animate = false;
|
|
|
|
args->GetNext(&animate);
|
|
|
|
window_->SetContentSize(gfx::Size(width, height), animate);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::vector<int> BaseWindow::GetContentSize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetContentSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetMinimumSize(int width, int height) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetMinimumSize(gfx::Size(width, height));
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::vector<int> BaseWindow::GetMinimumSize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetMinimumSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetMaximumSize(int width, int height) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetMaximumSize(gfx::Size(width, height));
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::vector<int> BaseWindow::GetMaximumSize() {
|
2018-04-14 02:04:23 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetMaximumSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetSheetOffset(double offsetY, gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
double offsetX = 0.0;
|
|
|
|
args->GetNext(&offsetX);
|
|
|
|
window_->SetSheetOffset(offsetX, offsetY);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetResizable(bool resizable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetResizable(resizable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsResizable() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsResizable();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetMovable(bool movable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetMovable(movable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsMovable() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsMovable();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetMinimizable(bool minimizable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetMinimizable(minimizable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsMinimizable() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsMinimizable();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetMaximizable(bool maximizable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetMaximizable(maximizable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsMaximizable() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsMaximizable();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetFullScreenable(bool fullscreenable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetFullScreenable(fullscreenable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsFullScreenable() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsFullScreenable();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetClosable(bool closable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetClosable(closable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsClosable() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsClosable();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetAlwaysOnTop(bool top, gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
std::string level = "floating";
|
|
|
|
int relative_level = 0;
|
|
|
|
args->GetNext(&level);
|
|
|
|
args->GetNext(&relative_level);
|
|
|
|
|
2019-07-24 22:58:51 +00:00
|
|
|
ui::ZOrderLevel z_order =
|
|
|
|
top ? ui::ZOrderLevel::kFloatingWindow : ui::ZOrderLevel::kNormal;
|
2019-10-18 19:57:34 +00:00
|
|
|
window_->SetAlwaysOnTop(z_order, level, relative_level);
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsAlwaysOnTop() {
|
2019-07-24 22:58:51 +00:00
|
|
|
return window_->GetZOrderLevel() != ui::ZOrderLevel::kNormal;
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::Center() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->Center();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetPosition(int x, int y, gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
bool animate = false;
|
|
|
|
args->GetNext(&animate);
|
|
|
|
window_->SetPosition(gfx::Point(x, y), animate);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::vector<int> BaseWindow::GetPosition() {
|
2018-04-14 02:04:23 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Point pos = window_->GetPosition();
|
|
|
|
result[0] = pos.x();
|
|
|
|
result[1] = pos.y();
|
|
|
|
return result;
|
|
|
|
}
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::MoveAbove(const std::string& sourceId,
|
|
|
|
gin_helper::Arguments* args) {
|
2019-08-21 22:16:43 +00:00
|
|
|
#if BUILDFLAG(ENABLE_DESKTOP_CAPTURER)
|
2019-08-15 06:51:15 +00:00
|
|
|
if (!window_->MoveAbove(sourceId))
|
|
|
|
args->ThrowError("Invalid media source id");
|
2019-08-21 22:16:43 +00:00
|
|
|
#else
|
|
|
|
args->ThrowError("enable_desktop_capturer=true to use this feature");
|
|
|
|
#endif
|
2019-08-15 06:51:15 +00:00
|
|
|
}
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::MoveTop() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->MoveTop();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetTitle(const std::string& title) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetTitle(title);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::string BaseWindow::GetTitle() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->GetTitle();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetAccessibleTitle(const std::string& title) {
|
2019-08-27 22:35:34 +00:00
|
|
|
window_->SetAccessibleTitle(title);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::string BaseWindow::GetAccessibleTitle() {
|
2019-08-27 22:35:34 +00:00
|
|
|
return window_->GetAccessibleTitle();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::FlashFrame(bool flash) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->FlashFrame(flash);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetSkipTaskbar(bool skip) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetSkipTaskbar(skip);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetExcludedFromShownWindowsMenu(bool excluded) {
|
2019-03-27 12:10:23 +00:00
|
|
|
window_->SetExcludedFromShownWindowsMenu(excluded);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsExcludedFromShownWindowsMenu() {
|
2019-03-27 12:10:23 +00:00
|
|
|
return window_->IsExcludedFromShownWindowsMenu();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetSimpleFullScreen(bool simple_fullscreen) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetSimpleFullScreen(simple_fullscreen);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsSimpleFullScreen() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsSimpleFullScreen();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetKiosk(bool kiosk) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetKiosk(kiosk);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsKiosk() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsKiosk();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetBackgroundColor(const std::string& color_name) {
|
2018-04-14 02:04:23 +00:00
|
|
|
SkColor color = ParseHexColor(color_name);
|
|
|
|
window_->SetBackgroundColor(color);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::string BaseWindow::GetBackgroundColor() {
|
2019-12-13 16:08:30 +00:00
|
|
|
return ToRGBHex(window_->GetBackgroundColor());
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetHasShadow(bool has_shadow) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetHasShadow(has_shadow);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::HasShadow() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->HasShadow();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetOpacity(const double opacity) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetOpacity(opacity);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
double BaseWindow::GetOpacity() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->GetOpacity();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetShape(const std::vector<gfx::Rect>& rects) {
|
2018-07-30 20:37:40 +00:00
|
|
|
window_->widget()->SetShape(std::make_unique<std::vector<gfx::Rect>>(rects));
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetRepresentedFilename(const std::string& filename) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetRepresentedFilename(filename);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::string BaseWindow::GetRepresentedFilename() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->GetRepresentedFilename();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetDocumentEdited(bool edited) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetDocumentEdited(edited);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsDocumentEdited() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsDocumentEdited();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetIgnoreMouseEvents(bool ignore,
|
|
|
|
gin_helper::Arguments* args) {
|
2019-10-21 07:05:40 +00:00
|
|
|
gin_helper::Dictionary options;
|
2018-04-14 02:04:23 +00:00
|
|
|
bool forward = false;
|
|
|
|
args->GetNext(&options) && options.Get("forward", &forward);
|
|
|
|
return window_->SetIgnoreMouseEvents(ignore, forward);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetContentProtection(bool enable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->SetContentProtection(enable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetFocusable(bool focusable) {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->SetFocusable(focusable);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
|
2019-04-20 17:20:37 +00:00
|
|
|
auto context = isolate->GetCurrentContext();
|
2019-10-25 13:03:28 +00:00
|
|
|
gin::Handle<Menu> menu;
|
2019-04-20 17:20:37 +00:00
|
|
|
v8::Local<v8::Object> object;
|
|
|
|
if (value->IsObject() && value->ToObject(context).ToLocal(&object) &&
|
2019-10-21 07:05:40 +00:00
|
|
|
gin::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
|
2018-04-14 02:04:23 +00:00
|
|
|
menu_.Reset(isolate, menu.ToV8());
|
2020-05-04 15:19:21 +00:00
|
|
|
|
|
|
|
// We only want to update the menu if the menu has a non-zero item count,
|
|
|
|
// or we risk crashes.
|
|
|
|
if (menu->model()->GetItemCount() == 0) {
|
|
|
|
RemoveMenu();
|
|
|
|
} else {
|
|
|
|
window_->SetMenu(menu->model());
|
|
|
|
}
|
2018-04-14 02:04:23 +00:00
|
|
|
} else if (value->IsNull()) {
|
2020-05-04 15:19:21 +00:00
|
|
|
RemoveMenu();
|
2018-04-14 02:04:23 +00:00
|
|
|
} else {
|
2018-04-18 01:55:30 +00:00
|
|
|
isolate->ThrowException(
|
2019-10-21 07:05:40 +00:00
|
|
|
v8::Exception::TypeError(gin::StringToV8(isolate, "Invalid Menu")));
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::RemoveMenu() {
|
2019-01-31 18:58:23 +00:00
|
|
|
menu_.Reset();
|
|
|
|
window_->SetMenu(nullptr);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetParentWindow(v8::Local<v8::Value> value,
|
|
|
|
gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
if (IsModal()) {
|
|
|
|
args->ThrowError("Can not be called for modal window");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
gin::Handle<BaseWindow> parent;
|
2018-04-14 02:04:23 +00:00
|
|
|
if (value->IsNull() || value->IsUndefined()) {
|
|
|
|
RemoveFromParentChildWindows();
|
|
|
|
parent_window_.Reset();
|
|
|
|
window_->SetParentWindow(nullptr);
|
2019-10-25 13:03:28 +00:00
|
|
|
} else if (gin::ConvertFromV8(isolate(), value, &parent)) {
|
2018-12-13 00:05:16 +00:00
|
|
|
RemoveFromParentChildWindows();
|
2018-04-14 02:04:23 +00:00
|
|
|
parent_window_.Reset(isolate(), value);
|
|
|
|
window_->SetParentWindow(parent->window_.get());
|
|
|
|
parent->child_windows_.Set(isolate(), weak_map_id(), GetWrapper());
|
|
|
|
} else {
|
2020-06-29 07:06:20 +00:00
|
|
|
args->ThrowError("Must pass BaseWindow instance or null");
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetBrowserView(v8::Local<v8::Value> value) {
|
2018-12-22 01:49:26 +00:00
|
|
|
ResetBrowserViews();
|
|
|
|
AddBrowserView(value);
|
|
|
|
}
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::AddBrowserView(v8::Local<v8::Value> value) {
|
2019-10-25 13:03:28 +00:00
|
|
|
gin::Handle<BrowserView> browser_view;
|
2018-12-22 01:49:26 +00:00
|
|
|
if (value->IsObject() &&
|
2019-10-21 07:05:40 +00:00
|
|
|
gin::ConvertFromV8(isolate(), value, &browser_view)) {
|
2020-07-09 15:48:39 +00:00
|
|
|
auto get_that_view = browser_views_.find(browser_view->ID());
|
2018-12-22 01:49:26 +00:00
|
|
|
if (get_that_view == browser_views_.end()) {
|
2020-08-27 20:04:06 +00:00
|
|
|
if (browser_view->web_contents()) {
|
|
|
|
window_->AddBrowserView(browser_view->view());
|
2020-08-26 03:04:13 +00:00
|
|
|
browser_view->web_contents()->SetOwnerWindow(window_.get());
|
2020-08-27 20:04:06 +00:00
|
|
|
}
|
2020-07-09 15:48:39 +00:00
|
|
|
browser_views_[browser_view->ID()].Reset(isolate(), value);
|
2018-12-22 01:49:26 +00:00
|
|
|
}
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
|
2019-10-25 13:03:28 +00:00
|
|
|
gin::Handle<BrowserView> browser_view;
|
2018-12-22 01:49:26 +00:00
|
|
|
if (value->IsObject() &&
|
2019-10-21 07:05:40 +00:00
|
|
|
gin::ConvertFromV8(isolate(), value, &browser_view)) {
|
2020-07-09 15:48:39 +00:00
|
|
|
auto get_that_view = browser_views_.find(browser_view->ID());
|
2018-12-22 01:49:26 +00:00
|
|
|
if (get_that_view != browser_views_.end()) {
|
2020-08-27 20:04:06 +00:00
|
|
|
if (browser_view->web_contents()) {
|
|
|
|
window_->RemoveBrowserView(browser_view->view());
|
2020-08-26 03:04:13 +00:00
|
|
|
browser_view->web_contents()->SetOwnerWindow(nullptr);
|
2020-08-27 20:04:06 +00:00
|
|
|
}
|
2018-12-22 01:49:26 +00:00
|
|
|
(*get_that_view).second.Reset(isolate(), value);
|
|
|
|
browser_views_.erase(get_that_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-15 06:51:15 +00:00
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::string BaseWindow::GetMediaSourceId() const {
|
2019-08-15 06:51:15 +00:00
|
|
|
return window_->GetDesktopMediaID().ToString();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
v8::Local<v8::Value> BaseWindow::GetNativeWindowHandle() {
|
2018-11-08 17:03:19 +00:00
|
|
|
// TODO(MarshallOfSound): Replace once
|
|
|
|
// https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has
|
|
|
|
// landed
|
2018-12-11 17:45:55 +00:00
|
|
|
NativeWindowHandle handle = window_->GetNativeWindowHandle();
|
|
|
|
return ToBuffer(isolate(), &handle, sizeof(handle));
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetProgressBar(double progress, gin_helper::Arguments* args) {
|
2019-10-21 07:05:40 +00:00
|
|
|
gin_helper::Dictionary options;
|
2018-04-14 02:04:23 +00:00
|
|
|
std::string mode;
|
|
|
|
args->GetNext(&options) && options.Get("mode", &mode);
|
|
|
|
|
2019-05-03 18:11:41 +00:00
|
|
|
NativeWindow::ProgressState state = NativeWindow::ProgressState::kNormal;
|
2018-04-14 02:04:23 +00:00
|
|
|
if (mode == "error")
|
2019-05-03 18:11:41 +00:00
|
|
|
state = NativeWindow::ProgressState::kError;
|
2018-04-14 02:04:23 +00:00
|
|
|
else if (mode == "paused")
|
2019-05-03 18:11:41 +00:00
|
|
|
state = NativeWindow::ProgressState::kPaused;
|
2018-04-14 02:04:23 +00:00
|
|
|
else if (mode == "indeterminate")
|
2019-05-03 18:11:41 +00:00
|
|
|
state = NativeWindow::ProgressState::kIndeterminate;
|
2018-04-14 02:04:23 +00:00
|
|
|
else if (mode == "none")
|
2019-05-03 18:11:41 +00:00
|
|
|
state = NativeWindow::ProgressState::kNone;
|
2018-04-14 02:04:23 +00:00
|
|
|
|
|
|
|
window_->SetProgressBar(progress, state);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetOverlayIcon(const gfx::Image& overlay,
|
|
|
|
const std::string& description) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetOverlayIcon(overlay, description);
|
|
|
|
}
|
|
|
|
|
2020-08-19 20:31:25 +00:00
|
|
|
void BaseWindow::SetVisibleOnAllWorkspaces(bool visible,
|
|
|
|
gin_helper::Arguments* args) {
|
|
|
|
gin_helper::Dictionary options;
|
|
|
|
bool visibleOnFullScreen = false;
|
|
|
|
args->GetNext(&options) &&
|
|
|
|
options.Get("visibleOnFullScreen", &visibleOnFullScreen);
|
|
|
|
return window_->SetVisibleOnAllWorkspaces(visible, visibleOnFullScreen);
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsVisibleOnAllWorkspaces() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsVisibleOnAllWorkspaces();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetAutoHideCursor(bool auto_hide) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetAutoHideCursor(auto_hide);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetVibrancy(v8::Isolate* isolate, v8::Local<v8::Value> value) {
|
2018-11-29 01:55:03 +00:00
|
|
|
std::string type = gin::V8ToString(isolate, value);
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetVibrancy(type);
|
|
|
|
}
|
|
|
|
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetTrafficLightPosition(const gfx::Point& position) {
|
2020-03-05 22:22:12 +00:00
|
|
|
window_->SetTrafficLightPosition(position);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
gfx::Point BaseWindow::GetTrafficLightPosition() const {
|
2020-03-05 22:22:12 +00:00
|
|
|
return window_->GetTrafficLightPosition();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetTouchBar(
|
2019-10-31 07:56:00 +00:00
|
|
|
std::vector<gin_helper::PersistentDictionary> items) {
|
|
|
|
window_->SetTouchBar(std::move(items));
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::RefreshTouchBarItem(const std::string& item_id) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->RefreshTouchBarItem(item_id);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetEscapeTouchBarItem(gin_helper::PersistentDictionary item) {
|
2019-10-31 07:56:00 +00:00
|
|
|
window_->SetEscapeTouchBarItem(std::move(item));
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SelectPreviousTab() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SelectPreviousTab();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SelectNextTab() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SelectNextTab();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::MergeAllWindows() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->MergeAllWindows();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::MoveTabToNewWindow() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->MoveTabToNewWindow();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::ToggleTabBar() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->ToggleTabBar();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::AddTabbedWindow(NativeWindow* window,
|
|
|
|
gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
if (!window_->AddTabbedWindow(window))
|
|
|
|
args->ThrowError("AddTabbedWindow cannot be called by a window on itself.");
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetWindowButtonVisibility(bool visible,
|
|
|
|
gin_helper::Arguments* args) {
|
2018-07-03 08:20:56 +00:00
|
|
|
if (!window_->SetWindowButtonVisibility(visible)) {
|
|
|
|
args->ThrowError("Not supported for this window");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetAutoHideMenuBar(bool auto_hide) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetAutoHideMenuBar(auto_hide);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsMenuBarAutoHide() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsMenuBarAutoHide();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetMenuBarVisibility(bool visible) {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->SetMenuBarVisibility(visible);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsMenuBarVisible() {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->IsMenuBarVisible();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetAspectRatio(double aspect_ratio,
|
|
|
|
gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
gfx::Size extra_size;
|
|
|
|
args->GetNext(&extra_size);
|
|
|
|
window_->SetAspectRatio(aspect_ratio, extra_size);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::PreviewFile(const std::string& path,
|
|
|
|
gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
std::string display_name;
|
|
|
|
if (!args->GetNext(&display_name))
|
|
|
|
display_name = path;
|
|
|
|
window_->PreviewFile(path, display_name);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::CloseFilePreview() {
|
2018-04-14 02:04:23 +00:00
|
|
|
window_->CloseFilePreview();
|
|
|
|
}
|
|
|
|
|
2020-08-20 20:53:06 +00:00
|
|
|
void BaseWindow::SetGTKDarkThemeEnabled(bool use_dark_theme) {
|
|
|
|
window_->SetGTKDarkThemeEnabled(use_dark_theme);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
v8::Local<v8::Value> BaseWindow::GetContentView() const {
|
2018-05-08 05:47:26 +00:00
|
|
|
if (content_view_.IsEmpty())
|
|
|
|
return v8::Null(isolate());
|
|
|
|
else
|
|
|
|
return v8::Local<v8::Value>::New(isolate(), content_view_);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
v8::Local<v8::Value> BaseWindow::GetParentWindow() const {
|
2018-04-14 02:04:23 +00:00
|
|
|
if (parent_window_.IsEmpty())
|
|
|
|
return v8::Null(isolate());
|
|
|
|
else
|
|
|
|
return v8::Local<v8::Value>::New(isolate(), parent_window_);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::vector<v8::Local<v8::Object>> BaseWindow::GetChildWindows() const {
|
2018-04-14 02:04:23 +00:00
|
|
|
return child_windows_.Values(isolate());
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
v8::Local<v8::Value> BaseWindow::GetBrowserView(
|
2019-10-21 07:05:40 +00:00
|
|
|
gin_helper::Arguments* args) const {
|
2018-12-22 01:49:26 +00:00
|
|
|
if (browser_views_.size() == 0) {
|
|
|
|
return v8::Null(isolate());
|
|
|
|
} else if (browser_views_.size() == 1) {
|
|
|
|
auto first_view = browser_views_.begin();
|
|
|
|
return v8::Local<v8::Value>::New(isolate(), (*first_view).second);
|
|
|
|
} else {
|
|
|
|
args->ThrowError(
|
|
|
|
"BrowserWindow have multiple BrowserViews, "
|
|
|
|
"Use getBrowserViews() instead");
|
2018-04-14 02:04:23 +00:00
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
2018-12-22 01:49:26 +00:00
|
|
|
}
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
std::vector<v8::Local<v8::Value>> BaseWindow::GetBrowserViews() const {
|
2018-12-22 01:49:26 +00:00
|
|
|
std::vector<v8::Local<v8::Value>> ret;
|
|
|
|
|
|
|
|
for (auto const& views_iter : browser_views_) {
|
|
|
|
ret.push_back(v8::Local<v8::Value>::New(isolate(), views_iter.second));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsModal() const {
|
2018-04-14 02:04:23 +00:00
|
|
|
return window_->is_modal();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::SetThumbarButtons(gin_helper::Arguments* args) {
|
2018-04-14 02:04:23 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
std::vector<TaskbarHost::ThumbarButton> buttons;
|
|
|
|
if (!args->GetNext(&buttons)) {
|
|
|
|
args->ThrowError();
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-25 20:30:00 +00:00
|
|
|
auto* window = static_cast<NativeWindowViews*>(window_.get());
|
2018-04-14 02:04:23 +00:00
|
|
|
return window->taskbar_host().SetThumbarButtons(
|
|
|
|
window_->GetAcceleratedWidget(), buttons);
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetIcon(gin::Handle<NativeImage> icon) {
|
2018-04-14 02:04:23 +00:00
|
|
|
#if defined(OS_WIN)
|
2018-04-18 01:55:30 +00:00
|
|
|
static_cast<NativeWindowViews*>(window_.get())
|
|
|
|
->SetIcon(icon->GetHICON(GetSystemMetrics(SM_CXSMICON)),
|
|
|
|
icon->GetHICON(GetSystemMetrics(SM_CXICON)));
|
2018-04-14 02:04:23 +00:00
|
|
|
#elif defined(USE_X11)
|
2018-04-18 01:55:30 +00:00
|
|
|
static_cast<NativeWindowViews*>(window_.get())
|
|
|
|
->SetIcon(icon->image().AsImageSkia());
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::HookWindowMessage(UINT message,
|
|
|
|
const MessageCallback& callback) {
|
2018-04-14 02:04:23 +00:00
|
|
|
messages_callback_map_[message] = callback;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::UnhookWindowMessage(UINT message) {
|
2018-04-14 02:04:23 +00:00
|
|
|
messages_callback_map_.erase(message);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::IsWindowMessageHooked(UINT message) {
|
2019-07-03 01:22:09 +00:00
|
|
|
return base::Contains(messages_callback_map_, message);
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::UnhookAllWindowMessages() {
|
2018-04-14 02:04:23 +00:00
|
|
|
messages_callback_map_.clear();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::SetThumbnailClip(const gfx::Rect& region) {
|
2018-04-14 02:04:23 +00:00
|
|
|
auto* window = static_cast<NativeWindowViews*>(window_.get());
|
|
|
|
return window->taskbar_host().SetThumbnailClip(
|
|
|
|
window_->GetAcceleratedWidget(), region);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
bool BaseWindow::SetThumbnailToolTip(const std::string& tooltip) {
|
2018-04-14 02:04:23 +00:00
|
|
|
auto* window = static_cast<NativeWindowViews*>(window_.get());
|
|
|
|
return window->taskbar_host().SetThumbnailToolTip(
|
|
|
|
window_->GetAcceleratedWidget(), tooltip);
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::SetAppDetails(const gin_helper::Dictionary& options) {
|
2018-04-14 02:04:23 +00:00
|
|
|
base::string16 app_id;
|
|
|
|
base::FilePath app_icon_path;
|
|
|
|
int app_icon_index = 0;
|
|
|
|
base::string16 relaunch_command;
|
|
|
|
base::string16 relaunch_display_name;
|
|
|
|
|
|
|
|
options.Get("appId", &app_id);
|
|
|
|
options.Get("appIconPath", &app_icon_path);
|
|
|
|
options.Get("appIconIndex", &app_icon_index);
|
|
|
|
options.Get("relaunchCommand", &relaunch_command);
|
|
|
|
options.Get("relaunchDisplayName", &relaunch_display_name);
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
ui::win::SetAppDetailsForWindow(app_id, app_icon_path, app_icon_index,
|
|
|
|
relaunch_command, relaunch_display_name,
|
|
|
|
window_->GetAcceleratedWidget());
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
int32_t BaseWindow::GetID() const {
|
2018-04-14 02:04:23 +00:00
|
|
|
return weak_map_id();
|
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::ResetBrowserViews() {
|
2018-12-22 01:49:26 +00:00
|
|
|
for (auto& item : browser_views_) {
|
2019-10-25 13:03:28 +00:00
|
|
|
gin::Handle<BrowserView> browser_view;
|
2019-10-21 07:05:40 +00:00
|
|
|
if (gin::ConvertFromV8(isolate(),
|
|
|
|
v8::Local<v8::Value>::New(isolate(), item.second),
|
|
|
|
&browser_view) &&
|
2018-12-22 01:49:26 +00:00
|
|
|
!browser_view.IsEmpty()) {
|
2020-08-27 20:04:06 +00:00
|
|
|
if (browser_view->web_contents()) {
|
2020-08-26 03:04:13 +00:00
|
|
|
browser_view->web_contents()->SetOwnerWindow(nullptr);
|
2020-08-27 20:04:06 +00:00
|
|
|
window_->RemoveBrowserView(browser_view->view());
|
|
|
|
}
|
2018-12-22 01:49:26 +00:00
|
|
|
}
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2018-12-22 01:49:26 +00:00
|
|
|
item.second.Reset();
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2018-12-22 01:49:26 +00:00
|
|
|
browser_views_.clear();
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::RemoveFromParentChildWindows() {
|
2018-04-14 02:04:23 +00:00
|
|
|
if (parent_window_.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
gin::Handle<BaseWindow> parent;
|
2019-10-21 07:05:40 +00:00
|
|
|
if (!gin::ConvertFromV8(isolate(), GetParentWindow(), &parent) ||
|
2018-04-14 02:04:23 +00:00
|
|
|
parent.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->child_windows_.Remove(weak_map_id());
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2020-06-29 07:06:20 +00:00
|
|
|
gin_helper::WrappableBase* BaseWindow::New(gin_helper::Arguments* args) {
|
2019-10-25 13:03:28 +00:00
|
|
|
gin_helper::Dictionary options =
|
|
|
|
gin::Dictionary::CreateEmpty(args->isolate());
|
2019-07-26 23:18:13 +00:00
|
|
|
args->GetNext(&options);
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
return new BaseWindow(args, options);
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2020-06-29 07:06:20 +00:00
|
|
|
void BaseWindow::BuildPrototype(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
|
|
|
prototype->SetClassName(gin::StringToV8(isolate, "BaseWindow"));
|
2019-09-04 02:14:16 +00:00
|
|
|
gin_helper::Destroyable::MakeDestroyable(isolate, prototype);
|
2019-10-21 07:05:40 +00:00
|
|
|
gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetMethod("setContentView", &BaseWindow::SetContentView)
|
|
|
|
.SetMethod("close", &BaseWindow::Close)
|
|
|
|
.SetMethod("focus", &BaseWindow::Focus)
|
|
|
|
.SetMethod("blur", &BaseWindow::Blur)
|
|
|
|
.SetMethod("isFocused", &BaseWindow::IsFocused)
|
|
|
|
.SetMethod("show", &BaseWindow::Show)
|
|
|
|
.SetMethod("showInactive", &BaseWindow::ShowInactive)
|
|
|
|
.SetMethod("hide", &BaseWindow::Hide)
|
|
|
|
.SetMethod("isVisible", &BaseWindow::IsVisible)
|
|
|
|
.SetMethod("isEnabled", &BaseWindow::IsEnabled)
|
|
|
|
.SetMethod("setEnabled", &BaseWindow::SetEnabled)
|
|
|
|
.SetMethod("maximize", &BaseWindow::Maximize)
|
|
|
|
.SetMethod("unmaximize", &BaseWindow::Unmaximize)
|
|
|
|
.SetMethod("isMaximized", &BaseWindow::IsMaximized)
|
|
|
|
.SetMethod("minimize", &BaseWindow::Minimize)
|
|
|
|
.SetMethod("restore", &BaseWindow::Restore)
|
|
|
|
.SetMethod("isMinimized", &BaseWindow::IsMinimized)
|
|
|
|
.SetMethod("setFullScreen", &BaseWindow::SetFullScreen)
|
|
|
|
.SetMethod("isFullScreen", &BaseWindow::IsFullscreen)
|
|
|
|
.SetMethod("setBounds", &BaseWindow::SetBounds)
|
|
|
|
.SetMethod("getBounds", &BaseWindow::GetBounds)
|
|
|
|
.SetMethod("isNormal", &BaseWindow::IsNormal)
|
|
|
|
.SetMethod("getNormalBounds", &BaseWindow::GetNormalBounds)
|
|
|
|
.SetMethod("setSize", &BaseWindow::SetSize)
|
|
|
|
.SetMethod("getSize", &BaseWindow::GetSize)
|
|
|
|
.SetMethod("setContentBounds", &BaseWindow::SetContentBounds)
|
|
|
|
.SetMethod("getContentBounds", &BaseWindow::GetContentBounds)
|
|
|
|
.SetMethod("setContentSize", &BaseWindow::SetContentSize)
|
|
|
|
.SetMethod("getContentSize", &BaseWindow::GetContentSize)
|
|
|
|
.SetMethod("setMinimumSize", &BaseWindow::SetMinimumSize)
|
|
|
|
.SetMethod("getMinimumSize", &BaseWindow::GetMinimumSize)
|
|
|
|
.SetMethod("setMaximumSize", &BaseWindow::SetMaximumSize)
|
|
|
|
.SetMethod("getMaximumSize", &BaseWindow::GetMaximumSize)
|
|
|
|
.SetMethod("setSheetOffset", &BaseWindow::SetSheetOffset)
|
|
|
|
.SetMethod("moveAbove", &BaseWindow::MoveAbove)
|
|
|
|
.SetMethod("moveTop", &BaseWindow::MoveTop)
|
|
|
|
.SetMethod("setResizable", &BaseWindow::SetResizable)
|
|
|
|
.SetMethod("isResizable", &BaseWindow::IsResizable)
|
|
|
|
.SetMethod("setMovable", &BaseWindow::SetMovable)
|
|
|
|
.SetMethod("isMovable", &BaseWindow::IsMovable)
|
|
|
|
.SetMethod("setMinimizable", &BaseWindow::SetMinimizable)
|
|
|
|
.SetMethod("isMinimizable", &BaseWindow::IsMinimizable)
|
|
|
|
.SetMethod("setMaximizable", &BaseWindow::SetMaximizable)
|
|
|
|
.SetMethod("isMaximizable", &BaseWindow::IsMaximizable)
|
|
|
|
.SetMethod("setFullScreenable", &BaseWindow::SetFullScreenable)
|
|
|
|
.SetMethod("isFullScreenable", &BaseWindow::IsFullScreenable)
|
|
|
|
.SetMethod("setClosable", &BaseWindow::SetClosable)
|
|
|
|
.SetMethod("isClosable", &BaseWindow::IsClosable)
|
|
|
|
.SetMethod("setAlwaysOnTop", &BaseWindow::SetAlwaysOnTop)
|
|
|
|
.SetMethod("isAlwaysOnTop", &BaseWindow::IsAlwaysOnTop)
|
|
|
|
.SetMethod("center", &BaseWindow::Center)
|
|
|
|
.SetMethod("setPosition", &BaseWindow::SetPosition)
|
|
|
|
.SetMethod("getPosition", &BaseWindow::GetPosition)
|
|
|
|
.SetMethod("setTitle", &BaseWindow::SetTitle)
|
|
|
|
.SetMethod("getTitle", &BaseWindow::GetTitle)
|
|
|
|
.SetProperty("accessibleTitle", &BaseWindow::GetAccessibleTitle,
|
|
|
|
&BaseWindow::SetAccessibleTitle)
|
|
|
|
.SetMethod("flashFrame", &BaseWindow::FlashFrame)
|
|
|
|
.SetMethod("setSkipTaskbar", &BaseWindow::SetSkipTaskbar)
|
|
|
|
.SetMethod("setSimpleFullScreen", &BaseWindow::SetSimpleFullScreen)
|
|
|
|
.SetMethod("isSimpleFullScreen", &BaseWindow::IsSimpleFullScreen)
|
|
|
|
.SetMethod("setKiosk", &BaseWindow::SetKiosk)
|
|
|
|
.SetMethod("isKiosk", &BaseWindow::IsKiosk)
|
|
|
|
.SetMethod("setBackgroundColor", &BaseWindow::SetBackgroundColor)
|
|
|
|
.SetMethod("getBackgroundColor", &BaseWindow::GetBackgroundColor)
|
|
|
|
.SetMethod("setHasShadow", &BaseWindow::SetHasShadow)
|
|
|
|
.SetMethod("hasShadow", &BaseWindow::HasShadow)
|
|
|
|
.SetMethod("setOpacity", &BaseWindow::SetOpacity)
|
|
|
|
.SetMethod("getOpacity", &BaseWindow::GetOpacity)
|
|
|
|
.SetMethod("setShape", &BaseWindow::SetShape)
|
|
|
|
.SetMethod("setRepresentedFilename", &BaseWindow::SetRepresentedFilename)
|
|
|
|
.SetMethod("getRepresentedFilename", &BaseWindow::GetRepresentedFilename)
|
|
|
|
.SetMethod("setDocumentEdited", &BaseWindow::SetDocumentEdited)
|
|
|
|
.SetMethod("isDocumentEdited", &BaseWindow::IsDocumentEdited)
|
|
|
|
.SetMethod("setIgnoreMouseEvents", &BaseWindow::SetIgnoreMouseEvents)
|
|
|
|
.SetMethod("setContentProtection", &BaseWindow::SetContentProtection)
|
|
|
|
.SetMethod("setFocusable", &BaseWindow::SetFocusable)
|
|
|
|
.SetMethod("setMenu", &BaseWindow::SetMenu)
|
|
|
|
.SetMethod("removeMenu", &BaseWindow::RemoveMenu)
|
|
|
|
.SetMethod("setParentWindow", &BaseWindow::SetParentWindow)
|
|
|
|
.SetMethod("setBrowserView", &BaseWindow::SetBrowserView)
|
|
|
|
.SetMethod("addBrowserView", &BaseWindow::AddBrowserView)
|
|
|
|
.SetMethod("removeBrowserView", &BaseWindow::RemoveBrowserView)
|
|
|
|
.SetMethod("getMediaSourceId", &BaseWindow::GetMediaSourceId)
|
|
|
|
.SetMethod("getNativeWindowHandle", &BaseWindow::GetNativeWindowHandle)
|
|
|
|
.SetMethod("setProgressBar", &BaseWindow::SetProgressBar)
|
|
|
|
.SetMethod("setOverlayIcon", &BaseWindow::SetOverlayIcon)
|
2018-04-14 02:04:23 +00:00
|
|
|
.SetMethod("setVisibleOnAllWorkspaces",
|
2020-06-29 07:06:20 +00:00
|
|
|
&BaseWindow::SetVisibleOnAllWorkspaces)
|
2018-04-14 02:04:23 +00:00
|
|
|
.SetMethod("isVisibleOnAllWorkspaces",
|
2020-06-29 07:06:20 +00:00
|
|
|
&BaseWindow::IsVisibleOnAllWorkspaces)
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetMethod("setAutoHideCursor", &BaseWindow::SetAutoHideCursor)
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetMethod("setVibrancy", &BaseWindow::SetVibrancy)
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2020-03-05 22:22:12 +00:00
|
|
|
.SetMethod("setTrafficLightPosition",
|
2020-06-29 07:06:20 +00:00
|
|
|
&BaseWindow::SetTrafficLightPosition)
|
2020-03-05 22:22:12 +00:00
|
|
|
.SetMethod("getTrafficLightPosition",
|
2020-06-29 07:06:20 +00:00
|
|
|
&BaseWindow::GetTrafficLightPosition)
|
2020-03-05 22:22:12 +00:00
|
|
|
#endif
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetMethod("_setTouchBarItems", &BaseWindow::SetTouchBar)
|
|
|
|
.SetMethod("_refreshTouchBarItem", &BaseWindow::RefreshTouchBarItem)
|
|
|
|
.SetMethod("_setEscapeTouchBarItem", &BaseWindow::SetEscapeTouchBarItem)
|
2020-08-12 18:33:58 +00:00
|
|
|
#if defined(OS_MAC)
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetMethod("selectPreviousTab", &BaseWindow::SelectPreviousTab)
|
|
|
|
.SetMethod("selectNextTab", &BaseWindow::SelectNextTab)
|
|
|
|
.SetMethod("mergeAllWindows", &BaseWindow::MergeAllWindows)
|
|
|
|
.SetMethod("moveTabToNewWindow", &BaseWindow::MoveTabToNewWindow)
|
|
|
|
.SetMethod("toggleTabBar", &BaseWindow::ToggleTabBar)
|
|
|
|
.SetMethod("addTabbedWindow", &BaseWindow::AddTabbedWindow)
|
2018-07-03 08:20:56 +00:00
|
|
|
.SetMethod("setWindowButtonVisibility",
|
2020-06-29 07:06:20 +00:00
|
|
|
&BaseWindow::SetWindowButtonVisibility)
|
2019-03-27 12:10:23 +00:00
|
|
|
.SetProperty("excludedFromShownWindowsMenu",
|
2020-06-29 07:06:20 +00:00
|
|
|
&BaseWindow::IsExcludedFromShownWindowsMenu,
|
|
|
|
&BaseWindow::SetExcludedFromShownWindowsMenu)
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetMethod("setAutoHideMenuBar", &BaseWindow::SetAutoHideMenuBar)
|
|
|
|
.SetMethod("isMenuBarAutoHide", &BaseWindow::IsMenuBarAutoHide)
|
|
|
|
.SetMethod("setMenuBarVisibility", &BaseWindow::SetMenuBarVisibility)
|
|
|
|
.SetMethod("isMenuBarVisible", &BaseWindow::IsMenuBarVisible)
|
|
|
|
.SetMethod("setAspectRatio", &BaseWindow::SetAspectRatio)
|
|
|
|
.SetMethod("previewFile", &BaseWindow::PreviewFile)
|
|
|
|
.SetMethod("closeFilePreview", &BaseWindow::CloseFilePreview)
|
|
|
|
.SetMethod("getContentView", &BaseWindow::GetContentView)
|
|
|
|
.SetMethod("getParentWindow", &BaseWindow::GetParentWindow)
|
|
|
|
.SetMethod("getChildWindows", &BaseWindow::GetChildWindows)
|
|
|
|
.SetMethod("getBrowserView", &BaseWindow::GetBrowserView)
|
|
|
|
.SetMethod("getBrowserViews", &BaseWindow::GetBrowserViews)
|
|
|
|
.SetMethod("isModal", &BaseWindow::IsModal)
|
|
|
|
.SetMethod("setThumbarButtons", &BaseWindow::SetThumbarButtons)
|
2018-04-14 02:04:23 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetMethod("setIcon", &BaseWindow::SetIcon)
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
|
|
|
#if defined(OS_WIN)
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetMethod("hookWindowMessage", &BaseWindow::HookWindowMessage)
|
|
|
|
.SetMethod("isWindowMessageHooked", &BaseWindow::IsWindowMessageHooked)
|
|
|
|
.SetMethod("unhookWindowMessage", &BaseWindow::UnhookWindowMessage)
|
2018-04-14 02:04:23 +00:00
|
|
|
.SetMethod("unhookAllWindowMessages",
|
2020-06-29 07:06:20 +00:00
|
|
|
&BaseWindow::UnhookAllWindowMessages)
|
|
|
|
.SetMethod("setThumbnailClip", &BaseWindow::SetThumbnailClip)
|
|
|
|
.SetMethod("setThumbnailToolTip", &BaseWindow::SetThumbnailToolTip)
|
|
|
|
.SetMethod("setAppDetails", &BaseWindow::SetAppDetails)
|
2018-04-14 02:04:23 +00:00
|
|
|
#endif
|
2020-06-29 07:06:20 +00:00
|
|
|
.SetProperty("id", &BaseWindow::GetID);
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace api
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2018-04-14 02:04:23 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
using electron::api::BaseWindow;
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
void* priv) {
|
2018-04-14 02:04:23 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2020-06-29 07:06:20 +00:00
|
|
|
BaseWindow::SetConstructor(isolate, base::BindRepeating(&BaseWindow::New));
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2019-10-21 07:05:40 +00:00
|
|
|
gin_helper::Dictionary constructor(isolate,
|
2020-06-29 07:06:20 +00:00
|
|
|
BaseWindow::GetConstructor(isolate)
|
2019-10-21 07:05:40 +00:00
|
|
|
->GetFunction(context)
|
|
|
|
.ToLocalChecked());
|
2020-06-29 07:06:20 +00:00
|
|
|
constructor.SetMethod("fromId", &BaseWindow::FromWeakMapID);
|
|
|
|
constructor.SetMethod("getAllWindows", &BaseWindow::GetAll);
|
2018-04-14 02:04:23 +00:00
|
|
|
|
2019-10-21 07:05:40 +00:00
|
|
|
gin_helper::Dictionary dict(isolate, exports);
|
2020-06-29 07:06:20 +00:00
|
|
|
dict.Set("BaseWindow", constructor);
|
2018-04-14 02:04:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-06-29 07:06:20 +00:00
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_base_window, Initialize)
|