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
|
|
|
#include "atom/browser/api/atom_api_browser_window.h"
|
2017-09-02 16:15:46 +00:00
|
|
|
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
#include "atom/browser/api/atom_api_browser_view.h"
|
2015-06-04 07:32:33 +00:00
|
|
|
#include "atom/browser/api/atom_api_menu.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
#include "atom/browser/api/atom_api_web_contents.h"
|
2014-10-30 13:32:35 +00:00
|
|
|
#include "atom/browser/browser.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
#include "atom/browser/native_window.h"
|
2017-07-10 22:45:48 +00:00
|
|
|
#include "atom/browser/web_contents_preferences.h"
|
2015-08-07 10:10:19 +00:00
|
|
|
#include "atom/common/native_mate_converters/callback.h"
|
2016-11-12 16:21:31 +00:00
|
|
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
2014-10-24 04:48:52 +00:00
|
|
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
2015-01-15 01:51:54 +00:00
|
|
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
2015-02-07 01:00:26 +00:00
|
|
|
#include "atom/common/native_mate_converters/image_converter.h"
|
2015-02-11 01:14:26 +00:00
|
|
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
2017-09-16 15:18:05 +00:00
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
2015-09-04 16:51:14 +00:00
|
|
|
#include "atom/common/options_switches.h"
|
2016-07-27 16:24:58 +00:00
|
|
|
#include "base/command_line.h"
|
2016-11-30 07:30:03 +00:00
|
|
|
#include "base/threading/thread_task_runner_handle.h"
|
2013-04-23 09:21:34 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2016-07-27 16:24:58 +00:00
|
|
|
#include "content/public/common/content_switches.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
#include "native_mate/constructor.h"
|
|
|
|
#include "native_mate/dictionary.h"
|
2015-05-01 10:50:53 +00:00
|
|
|
#include "ui/gfx/geometry/rect.h"
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2018-02-06 18:34:27 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
|
|
|
#include "atom/browser/native_window_views.h"
|
|
|
|
#endif
|
|
|
|
|
2016-05-20 13:22:15 +00:00
|
|
|
#if defined(OS_WIN)
|
2015-08-06 03:10:34 +00:00
|
|
|
#include "atom/browser/ui/win/taskbar_host.h"
|
2016-11-12 16:59:57 +00:00
|
|
|
#include "ui/base/win/shell.h"
|
2015-08-06 03:10:34 +00:00
|
|
|
#endif
|
|
|
|
|
2016-09-06 08:24:37 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
|
|
|
|
2015-08-06 03:10:34 +00:00
|
|
|
#if defined(OS_WIN)
|
2015-08-02 03:11:29 +00:00
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template<>
|
2015-08-06 03:10:34 +00:00
|
|
|
struct Converter<atom::TaskbarHost::ThumbarButton> {
|
2015-08-02 03:11:29 +00:00
|
|
|
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
|
2015-08-06 03:10:34 +00:00
|
|
|
atom::TaskbarHost::ThumbarButton* out) {
|
2015-08-02 03:11:29 +00:00
|
|
|
mate::Dictionary dict;
|
|
|
|
if (!ConvertFromV8(isolate, val, &dict))
|
|
|
|
return false;
|
|
|
|
dict.Get("click", &(out->clicked_callback));
|
|
|
|
dict.Get("tooltip", &(out->tooltip));
|
|
|
|
dict.Get("flags", &out->flags);
|
|
|
|
return dict.Get("icon", &(out->icon));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mate
|
2015-08-06 03:10:34 +00:00
|
|
|
#endif
|
2015-08-02 03:11:29 +00:00
|
|
|
|
2013-04-14 07:36:48 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
namespace api {
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
namespace {
|
|
|
|
|
2015-11-10 16:26:46 +00:00
|
|
|
// Converts binary data to Buffer.
|
2015-10-29 02:53:48 +00:00
|
|
|
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
2016-02-07 09:20:38 +00:00
|
|
|
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
2015-10-29 02:53:48 +00:00
|
|
|
if (buffer.IsEmpty())
|
|
|
|
return v8::Null(isolate);
|
|
|
|
else
|
|
|
|
return buffer.ToLocalChecked();
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> wrapper,
|
2018-02-22 05:59:39 +00:00
|
|
|
const mate::Dictionary& options)
|
|
|
|
: weak_factory_(this) {
|
2016-08-16 00:13:18 +00:00
|
|
|
mate::Handle<class WebContents> web_contents;
|
|
|
|
|
2017-07-10 22:45:48 +00:00
|
|
|
// Use options.webPreferences in WebContents.
|
|
|
|
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
|
|
|
options.Get(options::kWebPreferences, &web_preferences);
|
2016-08-16 00:13:18 +00:00
|
|
|
|
2017-07-10 22:45:48 +00:00
|
|
|
// Copy the backgroundColor to webContents.
|
|
|
|
v8::Local<v8::Value> value;
|
|
|
|
if (options.Get(options::kBackgroundColor, &value))
|
|
|
|
web_preferences.Set(options::kBackgroundColor, value);
|
|
|
|
|
|
|
|
v8::Local<v8::Value> transparent;
|
|
|
|
if (options.Get("transparent", &transparent))
|
|
|
|
web_preferences.Set("transparent", transparent);
|
2016-08-16 00:13:18 +00:00
|
|
|
|
2017-06-26 09:13:05 +00:00
|
|
|
#if defined(ENABLE_OSR)
|
2017-07-10 22:45:48 +00:00
|
|
|
// Offscreen windows are always created frameless.
|
|
|
|
bool offscreen;
|
|
|
|
if (web_preferences.Get("offscreen", &offscreen) && offscreen) {
|
|
|
|
auto window_options = const_cast<mate::Dictionary&>(options);
|
|
|
|
window_options.Set(options::kFrame, false);
|
|
|
|
}
|
2017-06-26 09:13:05 +00:00
|
|
|
#endif
|
2016-12-20 22:43:52 +00:00
|
|
|
|
2018-02-12 19:46:29 +00:00
|
|
|
if (options.Get("webContents", &web_contents) && !web_contents.IsEmpty()) {
|
2017-07-11 00:04:07 +00:00
|
|
|
// Set webPreferences from options if using an existing webContents.
|
|
|
|
// These preferences will be used when the webContent launches new
|
|
|
|
// render processes.
|
2017-07-10 22:45:48 +00:00
|
|
|
auto* existing_preferences =
|
|
|
|
WebContentsPreferences::FromWebContents(web_contents->web_contents());
|
|
|
|
base::DictionaryValue web_preferences_dict;
|
2017-07-11 00:04:07 +00:00
|
|
|
if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(),
|
|
|
|
&web_preferences_dict)) {
|
|
|
|
existing_preferences->web_preferences()->Clear();
|
|
|
|
existing_preferences->Merge(web_preferences_dict);
|
|
|
|
}
|
|
|
|
|
2017-07-10 22:45:48 +00:00
|
|
|
} else {
|
2016-08-16 00:13:18 +00:00
|
|
|
// Creates the WebContents used by BrowserWindow.
|
|
|
|
web_contents = WebContents::Create(isolate, web_preferences);
|
|
|
|
}
|
2016-08-15 23:58:07 +00:00
|
|
|
|
|
|
|
Init(isolate, wrapper, options, web_contents);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Init(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::Object> wrapper,
|
|
|
|
const mate::Dictionary& options,
|
|
|
|
mate::Handle<class WebContents> web_contents) {
|
2015-06-25 01:47:57 +00:00
|
|
|
web_contents_.Reset(isolate, web_contents.ToV8());
|
2015-06-25 03:07:23 +00:00
|
|
|
api_web_contents_ = web_contents.get();
|
2018-02-22 05:52:04 +00:00
|
|
|
Observe(web_contents->web_contents());
|
2015-06-25 01:47:57 +00:00
|
|
|
|
2015-09-22 13:56:56 +00:00
|
|
|
// Keep a copy of the options for later use.
|
2016-04-25 01:19:25 +00:00
|
|
|
mate::Dictionary(isolate, web_contents->GetWrapper()).Set(
|
2015-09-22 13:56:56 +00:00
|
|
|
"browserWindowOptions", options);
|
|
|
|
|
2016-06-19 03:06:08 +00:00
|
|
|
// The parent window.
|
2018-02-22 03:49:17 +00:00
|
|
|
mate::Handle<BrowserWindow> parent;
|
2018-02-12 19:46:29 +00:00
|
|
|
if (options.Get("parent", &parent) && !parent.IsEmpty())
|
2016-06-19 03:06:08 +00:00
|
|
|
parent_window_.Reset(isolate, parent.ToV8());
|
|
|
|
|
2015-06-25 01:47:57 +00:00
|
|
|
// Creates BrowserWindow.
|
2016-06-19 03:06:08 +00:00
|
|
|
window_.reset(NativeWindow::Create(
|
|
|
|
web_contents->managed_web_contents(),
|
|
|
|
options,
|
|
|
|
parent.IsEmpty() ? nullptr : parent->window_.get()));
|
2015-06-25 01:47:57 +00:00
|
|
|
web_contents->SetOwnerWindow(window_.get());
|
2017-11-13 07:13:54 +00:00
|
|
|
window_->set_is_offscreen_dummy(api_web_contents_->IsOffScreen());
|
2016-05-20 10:46:05 +00:00
|
|
|
|
2016-05-20 13:22:15 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2016-05-20 10:46:05 +00:00
|
|
|
// Sets the window icon.
|
|
|
|
mate::Handle<NativeImage> icon;
|
2018-02-12 19:46:29 +00:00
|
|
|
if (options.Get(options::kIcon, &icon) && !icon.IsEmpty())
|
2016-05-20 13:22:15 +00:00
|
|
|
SetIcon(icon);
|
2016-05-20 10:46:05 +00:00
|
|
|
#endif
|
2016-07-02 07:16:47 +00:00
|
|
|
|
|
|
|
window_->InitFromOptions(options);
|
|
|
|
window_->AddObserver(this);
|
2016-08-02 06:15:40 +00:00
|
|
|
|
|
|
|
InitWith(isolate, wrapper);
|
2016-07-02 07:16:47 +00:00
|
|
|
AttachAsUserData(window_.get());
|
2016-08-02 06:15:40 +00:00
|
|
|
|
|
|
|
// We can only append this window to parent window's child windows after this
|
|
|
|
// window's JS wrapper gets initialized.
|
|
|
|
if (!parent.IsEmpty())
|
|
|
|
parent->child_windows_.Set(isolate, ID(), wrapper);
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
BrowserWindow::~BrowserWindow() {
|
2015-12-03 07:38:43 +00:00
|
|
|
if (!window_->IsClosed())
|
|
|
|
window_->CloseContents(nullptr);
|
2015-12-04 03:35:04 +00:00
|
|
|
|
|
|
|
// Destroy the native window in next tick because the native code might be
|
|
|
|
// iterating all windows.
|
2016-11-30 07:30:03 +00:00
|
|
|
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release());
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 05:59:39 +00:00
|
|
|
void BrowserWindow::DidFirstVisuallyNonEmptyPaint() {
|
|
|
|
if (window_->IsVisible())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// When there is a non-empty first paint, resize the RenderWidget to force
|
|
|
|
// Chromium to draw.
|
|
|
|
const auto view = web_contents()->GetRenderWidgetHostView();
|
|
|
|
view->Show();
|
|
|
|
view->SetSize(window_->GetContentSize());
|
|
|
|
|
|
|
|
// Emit the ReadyToShow event in next tick in case of pending drawing work.
|
|
|
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
base::Bind([](base::WeakPtr<BrowserWindow> self) {
|
|
|
|
self->Emit("ready-to-show");
|
|
|
|
}, GetWeakPtr()));
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::WillCloseWindow(bool* prevent_default) {
|
2013-05-02 10:19:07 +00:00
|
|
|
*prevent_default = Emit("close");
|
2013-05-01 15:28:01 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::WillDestroyNativeObject() {
|
2016-06-19 06:47:27 +00:00
|
|
|
// Close all child windows before closing current window.
|
|
|
|
v8::Locker locker(isolate());
|
|
|
|
v8::HandleScope handle_scope(isolate());
|
|
|
|
for (v8::Local<v8::Value> value : child_windows_.Values(isolate())) {
|
2018-02-22 03:49:17 +00:00
|
|
|
mate::Handle<BrowserWindow> child;
|
2018-02-12 19:46:29 +00:00
|
|
|
if (mate::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty())
|
2016-06-19 06:47:27 +00:00
|
|
|
child->window_->CloseImmediately();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowClosed() {
|
2017-04-03 20:03:51 +00:00
|
|
|
api_web_contents_->DestroyWebContents(true /* async */);
|
2015-06-25 03:07:23 +00:00
|
|
|
|
2015-06-24 09:58:12 +00:00
|
|
|
RemoveFromWeakMap();
|
2014-04-23 01:53:38 +00:00
|
|
|
window_->RemoveObserver(this);
|
2015-06-27 09:01:20 +00:00
|
|
|
|
2015-12-03 07:38:43 +00:00
|
|
|
// 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();
|
|
|
|
|
2015-06-27 09:01:20 +00:00
|
|
|
Emit("closed");
|
2015-09-17 03:30:17 +00:00
|
|
|
|
2016-06-17 07:57:03 +00:00
|
|
|
RemoveFromParentChildWindows();
|
|
|
|
|
2017-06-21 23:21:28 +00:00
|
|
|
ResetBrowserView();
|
|
|
|
|
2015-12-03 07:38:43 +00:00
|
|
|
// Destroy the native class when window is closed.
|
2016-11-30 07:30:03 +00:00
|
|
|
base::ThreadTaskRunnerHandle::Get()->PostTask(
|
|
|
|
FROM_HERE, GetDestroyClosure());
|
2013-04-18 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowEndSession() {
|
2017-04-24 17:16:11 +00:00
|
|
|
Emit("session-end");
|
2017-04-21 20:45:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowBlur() {
|
2013-05-24 09:58:39 +00:00
|
|
|
Emit("blur");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowFocus() {
|
2014-05-21 17:46:13 +00:00
|
|
|
Emit("focus");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowShow() {
|
2016-03-08 17:36:41 +00:00
|
|
|
Emit("show");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowHide() {
|
2016-03-08 17:36:41 +00:00
|
|
|
Emit("hide");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowMaximize() {
|
2014-11-25 04:43:25 +00:00
|
|
|
Emit("maximize");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowUnmaximize() {
|
2014-11-25 04:43:25 +00:00
|
|
|
Emit("unmaximize");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowMinimize() {
|
2014-11-25 04:43:25 +00:00
|
|
|
Emit("minimize");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowRestore() {
|
2014-11-25 04:43:25 +00:00
|
|
|
Emit("restore");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowResize() {
|
2015-05-09 18:03:16 +00:00
|
|
|
Emit("resize");
|
2015-05-09 15:55:10 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowMove() {
|
2015-05-09 18:03:16 +00:00
|
|
|
Emit("move");
|
2015-05-09 15:55:10 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowMoved() {
|
2015-05-20 08:37:13 +00:00
|
|
|
Emit("moved");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowEnterFullScreen() {
|
2014-11-25 04:43:25 +00:00
|
|
|
Emit("enter-full-screen");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowLeaveFullScreen() {
|
2014-11-25 04:43:25 +00:00
|
|
|
Emit("leave-full-screen");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowScrollTouchBegin() {
|
2016-01-22 00:31:09 +00:00
|
|
|
Emit("scroll-touch-begin");
|
2016-01-21 17:40:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowScrollTouchEnd() {
|
2016-01-22 00:31:09 +00:00
|
|
|
Emit("scroll-touch-end");
|
2016-01-21 17:40:21 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowScrollTouchEdge() {
|
2016-09-17 14:29:32 +00:00
|
|
|
Emit("scroll-touch-edge");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowSwipe(const std::string& direction) {
|
2016-03-23 15:20:11 +00:00
|
|
|
Emit("swipe", direction);
|
2016-03-18 15:20:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowSheetBegin() {
|
2017-04-20 17:31:25 +00:00
|
|
|
Emit("sheet-begin");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowSheetEnd() {
|
2017-04-20 17:31:25 +00:00
|
|
|
Emit("sheet-end");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowEnterHtmlFullScreen() {
|
2015-05-16 21:01:30 +00:00
|
|
|
Emit("enter-html-full-screen");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowLeaveHtmlFullScreen() {
|
2015-05-16 21:01:30 +00:00
|
|
|
Emit("leave-html-full-screen");
|
|
|
|
}
|
|
|
|
|
2018-02-22 05:52:04 +00:00
|
|
|
void BrowserWindow::OnWindowUnresponsive() {
|
2013-06-06 11:45:48 +00:00
|
|
|
Emit("unresponsive");
|
|
|
|
}
|
|
|
|
|
2018-02-22 05:52:04 +00:00
|
|
|
void BrowserWindow::OnWindowResponsive() {
|
2013-06-06 11:45:48 +00:00
|
|
|
Emit("responsive");
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnExecuteWindowsCommand(const std::string& command_name) {
|
2015-06-25 16:25:55 +00:00
|
|
|
Emit("app-command", command_name);
|
2015-06-18 00:31:50 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnTouchBarItemResult(const std::string& item_id,
|
2017-02-28 23:37:15 +00:00
|
|
|
const base::DictionaryValue& details) {
|
|
|
|
Emit("-touch-bar-interaction", item_id, details);
|
2016-11-27 05:57:01 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnNewWindowForTab() {
|
2017-06-11 08:19:01 +00:00
|
|
|
Emit("new-window-for-tab");
|
|
|
|
}
|
|
|
|
|
2015-10-27 01:12:01 +00:00
|
|
|
#if defined(OS_WIN)
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::OnWindowMessage(UINT message,
|
|
|
|
WPARAM w_param,
|
|
|
|
LPARAM l_param) {
|
2015-10-27 12:00:08 +00:00
|
|
|
if (IsWindowMessageHooked(message)) {
|
2015-10-29 01:00:44 +00:00
|
|
|
messages_callback_map_[message].Run(
|
2015-10-29 02:53:48 +00:00
|
|
|
ToBuffer(isolate(), static_cast<void*>(&w_param), sizeof(WPARAM)),
|
|
|
|
ToBuffer(isolate(), static_cast<void*>(&l_param), sizeof(LPARAM)));
|
2015-10-27 12:00:08 +00:00
|
|
|
}
|
2015-10-27 01:12:01 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
// static
|
2018-02-22 03:49:17 +00:00
|
|
|
mate::WrappableBase* BrowserWindow::New(mate::Arguments* args) {
|
2015-03-26 03:34:41 +00:00
|
|
|
if (!Browser::Get()->is_ready()) {
|
2016-08-02 06:15:40 +00:00
|
|
|
args->ThrowError("Cannot create BrowserWindow before app is ready");
|
2014-10-30 13:32:35 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2015-11-21 04:22:19 +00:00
|
|
|
|
|
|
|
if (args->Length() > 1) {
|
|
|
|
args->ThrowError();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
mate::Dictionary options;
|
|
|
|
if (!(args->Length() == 1 && args->GetNext(&options))) {
|
2016-08-02 06:15:40 +00:00
|
|
|
options = mate::Dictionary::CreateEmpty(args->isolate());
|
2015-11-21 04:22:19 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
return new BrowserWindow(args->isolate(), args->GetThis(), options);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Close() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Close();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Focus() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Focus(true);
|
2013-05-16 14:56:52 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Blur() {
|
2016-03-11 05:45:51 +00:00
|
|
|
window_->Focus(false);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsFocused() {
|
2014-04-22 15:07:21 +00:00
|
|
|
return window_->IsFocused();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Show() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Show();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::ShowInactive() {
|
2016-06-20 05:49:24 +00:00
|
|
|
// This method doesn't make sense for modal window..
|
|
|
|
if (IsModal())
|
|
|
|
return;
|
|
|
|
|
2014-10-17 14:51:20 +00:00
|
|
|
window_->ShowInactive();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Hide() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Hide();
|
2013-10-03 00:27:59 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsVisible() {
|
2014-04-22 15:07:21 +00:00
|
|
|
return window_->IsVisible();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsEnabled() {
|
2016-06-17 08:38:44 +00:00
|
|
|
return window_->IsEnabled();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetEnabled(bool enable) {
|
2018-02-06 13:21:53 +00:00
|
|
|
window_->SetEnabled(enable);
|
2018-02-05 19:49:59 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Maximize() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Maximize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Unmaximize() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Unmaximize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsMaximized() {
|
2014-05-14 21:58:49 +00:00
|
|
|
return window_->IsMaximized();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Minimize() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Minimize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Restore() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Restore();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsMinimized() {
|
2014-07-26 05:58:26 +00:00
|
|
|
return window_->IsMinimized();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetFullScreen(bool fullscreen) {
|
2014-11-25 06:34:14 +00:00
|
|
|
window_->SetFullScreen(fullscreen);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsFullscreen() {
|
2014-04-22 15:07:21 +00:00
|
|
|
return window_->IsFullscreen();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetBounds(const gfx::Rect& bounds, mate::Arguments* args) {
|
2016-01-15 04:54:12 +00:00
|
|
|
bool animate = false;
|
2016-01-15 16:31:31 +00:00
|
|
|
args->GetNext(&animate);
|
|
|
|
window_->SetBounds(bounds, animate);
|
2015-05-01 10:50:53 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
gfx::Rect BrowserWindow::GetBounds() {
|
2015-05-01 10:50:53 +00:00
|
|
|
return window_->GetBounds();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetContentBounds(const gfx::Rect& bounds,
|
|
|
|
mate::Arguments* args) {
|
2016-08-04 19:02:24 +00:00
|
|
|
bool animate = false;
|
|
|
|
args->GetNext(&animate);
|
|
|
|
window_->SetContentBounds(bounds, animate);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
gfx::Rect BrowserWindow::GetContentBounds() {
|
2016-07-29 01:19:17 +00:00
|
|
|
return window_->GetContentBounds();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetSize(int width, int height, mate::Arguments* args) {
|
2016-01-15 04:54:12 +00:00
|
|
|
bool animate = false;
|
2016-01-15 16:31:31 +00:00
|
|
|
args->GetNext(&animate);
|
2016-01-15 04:54:12 +00:00
|
|
|
window_->SetSize(gfx::Size(width, height), animate);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
std::vector<int> BrowserWindow::GetSize() {
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetContentSize(int width, int height,
|
|
|
|
mate::Arguments* args) {
|
2016-01-15 04:54:12 +00:00
|
|
|
bool animate = false;
|
2016-01-15 16:31:31 +00:00
|
|
|
args->GetNext(&animate);
|
2016-01-15 04:54:12 +00:00
|
|
|
window_->SetContentSize(gfx::Size(width, height), animate);
|
2014-05-15 08:05:35 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
std::vector<int> BrowserWindow::GetContentSize() {
|
2014-05-15 07:30:04 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetContentSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetMinimumSize(int width, int height) {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->SetMinimumSize(gfx::Size(width, height));
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
std::vector<int> BrowserWindow::GetMinimumSize() {
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetMinimumSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetMaximumSize(int width, int height) {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->SetMaximumSize(gfx::Size(width, height));
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
std::vector<int> BrowserWindow::GetMaximumSize() {
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetMaximumSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetSheetOffset(double offsetY, mate::Arguments* args) {
|
2016-05-20 03:19:08 +00:00
|
|
|
double offsetX = 0.0;
|
|
|
|
args->GetNext(&offsetX);
|
|
|
|
window_->SetSheetOffset(offsetX, offsetY);
|
2016-04-19 05:45:38 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetResizable(bool resizable) {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->SetResizable(resizable);
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsResizable() {
|
2014-04-22 15:07:21 +00:00
|
|
|
return window_->IsResizable();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetMovable(bool movable) {
|
2016-01-18 22:46:35 +00:00
|
|
|
window_->SetMovable(movable);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsMovable() {
|
2016-01-18 22:46:35 +00:00
|
|
|
return window_->IsMovable();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetMinimizable(bool minimizable) {
|
2016-01-18 22:46:35 +00:00
|
|
|
window_->SetMinimizable(minimizable);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsMinimizable() {
|
2016-01-18 22:46:35 +00:00
|
|
|
return window_->IsMinimizable();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetMaximizable(bool maximizable) {
|
2016-01-22 21:24:33 +00:00
|
|
|
window_->SetMaximizable(maximizable);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsMaximizable() {
|
2016-01-22 21:24:33 +00:00
|
|
|
return window_->IsMaximizable();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetFullScreenable(bool fullscreenable) {
|
2016-01-23 07:47:37 +00:00
|
|
|
window_->SetFullScreenable(fullscreenable);
|
2016-01-22 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsFullScreenable() {
|
2016-01-23 07:47:37 +00:00
|
|
|
return window_->IsFullScreenable();
|
2016-01-22 21:24:33 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetClosable(bool closable) {
|
2016-01-18 22:46:35 +00:00
|
|
|
window_->SetClosable(closable);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsClosable() {
|
2016-01-18 22:46:35 +00:00
|
|
|
return window_->IsClosable();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetAlwaysOnTop(bool top, mate::Arguments* args) {
|
2016-09-22 02:49:06 +00:00
|
|
|
std::string level = "floating";
|
2017-01-24 04:36:09 +00:00
|
|
|
int relativeLevel = 0;
|
2017-01-25 04:08:08 +00:00
|
|
|
std::string error;
|
|
|
|
|
2016-09-21 17:35:59 +00:00
|
|
|
args->GetNext(&level);
|
2017-01-24 04:36:09 +00:00
|
|
|
args->GetNext(&relativeLevel);
|
2017-01-25 04:08:08 +00:00
|
|
|
|
|
|
|
window_->SetAlwaysOnTop(top, level, relativeLevel, &error);
|
|
|
|
|
|
|
|
if (!error.empty()) {
|
|
|
|
args->ThrowError(error);
|
|
|
|
}
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsAlwaysOnTop() {
|
2014-04-22 15:07:21 +00:00
|
|
|
return window_->IsAlwaysOnTop();
|
2013-05-10 12:34:05 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::Center() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->Center();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetPosition(int x, int y, mate::Arguments* args) {
|
2016-01-15 04:54:12 +00:00
|
|
|
bool animate = false;
|
2016-01-15 16:31:31 +00:00
|
|
|
args->GetNext(&animate);
|
2016-01-15 04:54:12 +00:00
|
|
|
window_->SetPosition(gfx::Point(x, y), animate);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
std::vector<int> BrowserWindow::GetPosition() {
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Point pos = window_->GetPosition();
|
|
|
|
result[0] = pos.x();
|
|
|
|
result[1] = pos.y();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetTitle(const std::string& title) {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->SetTitle(title);
|
2013-04-18 06:30:05 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
std::string BrowserWindow::GetTitle() {
|
2014-04-22 15:07:21 +00:00
|
|
|
return window_->GetTitle();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::FlashFrame(bool flash) {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->FlashFrame(flash);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetSkipTaskbar(bool skip) {
|
2014-06-16 02:29:51 +00:00
|
|
|
window_->SetSkipTaskbar(skip);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetSimpleFullScreen(bool simple_fullscreen) {
|
2017-08-13 06:28:33 +00:00
|
|
|
window_->SetSimpleFullScreen(simple_fullscreen);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsSimpleFullScreen() {
|
2017-08-13 06:28:33 +00:00
|
|
|
return window_->IsSimpleFullScreen();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetKiosk(bool kiosk) {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->SetKiosk(kiosk);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsKiosk() {
|
2014-04-22 15:07:21 +00:00
|
|
|
return window_->IsKiosk();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetBackgroundColor(const std::string& color_name) {
|
2015-10-23 03:35:33 +00:00
|
|
|
window_->SetBackgroundColor(color_name);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetHasShadow(bool has_shadow) {
|
2016-01-23 00:15:49 +00:00
|
|
|
window_->SetHasShadow(has_shadow);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::HasShadow() {
|
2016-01-23 00:15:49 +00:00
|
|
|
return window_->HasShadow();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetOpacity(const double opacity) {
|
2017-09-29 02:26:02 +00:00
|
|
|
window_->SetOpacity(opacity);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
double BrowserWindow::GetOpacity() {
|
2017-10-02 15:08:10 +00:00
|
|
|
return window_->GetOpacity();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::FocusOnWebView() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->FocusOnWebView();
|
2013-05-24 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::BlurWebView() {
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->BlurWebView();
|
2013-08-16 04:56:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsWebViewFocused() {
|
2014-04-22 15:07:21 +00:00
|
|
|
return window_->IsWebViewFocused();
|
|
|
|
}
|
2013-11-22 06:23:19 +00:00
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetRepresentedFilename(const std::string& filename) {
|
2014-08-21 13:00:49 +00:00
|
|
|
window_->SetRepresentedFilename(filename);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
std::string BrowserWindow::GetRepresentedFilename() {
|
2014-08-21 13:00:49 +00:00
|
|
|
return window_->GetRepresentedFilename();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetDocumentEdited(bool edited) {
|
2014-08-21 13:00:49 +00:00
|
|
|
window_->SetDocumentEdited(edited);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsDocumentEdited() {
|
2014-08-21 13:00:49 +00:00
|
|
|
return window_->IsDocumentEdited();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetIgnoreMouseEvents(bool ignore, mate::Arguments* args) {
|
2017-08-14 18:21:00 +00:00
|
|
|
mate::Dictionary options;
|
|
|
|
bool forward = false;
|
|
|
|
args->GetNext(&options) && options.Get("forward", &forward);
|
|
|
|
return window_->SetIgnoreMouseEvents(ignore, forward);
|
2015-12-06 02:14:54 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetContentProtection(bool enable) {
|
2016-06-22 08:40:01 +00:00
|
|
|
return window_->SetContentProtection(enable);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetFocusable(bool focusable) {
|
2016-06-13 08:10:28 +00:00
|
|
|
return window_->SetFocusable(focusable);
|
2016-06-12 18:20:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetProgressBar(double progress, mate::Arguments* args) {
|
2016-08-08 22:44:48 +00:00
|
|
|
mate::Dictionary options;
|
|
|
|
std::string mode;
|
2016-08-09 23:05:44 +00:00
|
|
|
NativeWindow::ProgressState state = NativeWindow::PROGRESS_NORMAL;
|
|
|
|
|
2016-08-08 22:44:48 +00:00
|
|
|
args->GetNext(&options) && options.Get("mode", &mode);
|
|
|
|
|
2016-08-09 23:05:44 +00:00
|
|
|
if (mode == "error") {
|
|
|
|
state = NativeWindow::PROGRESS_ERROR;
|
|
|
|
} else if (mode == "paused") {
|
|
|
|
state = NativeWindow::PROGRESS_PAUSED;
|
|
|
|
} else if (mode == "indeterminate") {
|
|
|
|
state = NativeWindow::PROGRESS_INDETERMINATE;
|
|
|
|
} else if (mode == "none") {
|
|
|
|
state = NativeWindow::PROGRESS_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_->SetProgressBar(progress, state);
|
2014-09-17 01:42:47 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetOverlayIcon(const gfx::Image& overlay,
|
2015-02-11 01:14:26 +00:00
|
|
|
const std::string& description) {
|
2015-02-07 01:07:29 +00:00
|
|
|
window_->SetOverlayIcon(overlay, description);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::SetThumbarButtons(mate::Arguments* args) {
|
2015-08-06 03:10:34 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
std::vector<TaskbarHost::ThumbarButton> buttons;
|
|
|
|
if (!args->GetNext(&buttons)) {
|
|
|
|
args->ThrowError();
|
2015-08-06 04:44:07 +00:00
|
|
|
return false;
|
2015-08-06 03:10:34 +00:00
|
|
|
}
|
|
|
|
auto window = static_cast<NativeWindowViews*>(window_.get());
|
2015-08-06 04:44:07 +00:00
|
|
|
return window->taskbar_host().SetThumbarButtons(
|
2016-08-12 15:55:42 +00:00
|
|
|
window_->GetAcceleratedWidget(), buttons);
|
2015-08-06 04:44:07 +00:00
|
|
|
#else
|
|
|
|
return false;
|
2015-08-06 03:10:34 +00:00
|
|
|
#endif
|
2015-08-02 03:11:29 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {
|
2015-06-24 11:51:11 +00:00
|
|
|
mate::Handle<Menu> menu;
|
|
|
|
if (value->IsObject() &&
|
|
|
|
mate::V8ToString(value->ToObject()->GetConstructorName()) == "Menu" &&
|
2018-02-12 19:46:29 +00:00
|
|
|
mate::ConvertFromV8(isolate, value, &menu) && !menu.IsEmpty()) {
|
2015-06-24 11:51:11 +00:00
|
|
|
menu_.Reset(isolate, menu.ToV8());
|
|
|
|
window_->SetMenu(menu->model());
|
|
|
|
} else if (value->IsNull()) {
|
|
|
|
menu_.Reset();
|
|
|
|
window_->SetMenu(nullptr);
|
|
|
|
} else {
|
|
|
|
isolate->ThrowException(v8::Exception::TypeError(
|
|
|
|
mate::StringToV8(isolate, "Invalid Menu")));
|
|
|
|
}
|
2015-06-04 07:32:33 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetAutoHideMenuBar(bool auto_hide) {
|
2014-11-12 12:31:55 +00:00
|
|
|
window_->SetAutoHideMenuBar(auto_hide);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsMenuBarAutoHide() {
|
2014-11-12 12:31:55 +00:00
|
|
|
return window_->IsMenuBarAutoHide();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetMenuBarVisibility(bool visible) {
|
2014-11-12 12:31:55 +00:00
|
|
|
window_->SetMenuBarVisibility(visible);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsMenuBarVisible() {
|
2014-11-12 12:31:55 +00:00
|
|
|
return window_->IsMenuBarVisible();
|
|
|
|
}
|
|
|
|
|
2015-10-27 12:00:08 +00:00
|
|
|
#if defined(OS_WIN)
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::HookWindowMessage(UINT message,
|
2015-10-27 12:00:08 +00:00
|
|
|
const MessageCallback& callback) {
|
|
|
|
messages_callback_map_[message] = callback;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::UnhookWindowMessage(UINT message) {
|
2015-10-27 12:00:08 +00:00
|
|
|
if (!ContainsKey(messages_callback_map_, message))
|
|
|
|
return;
|
|
|
|
|
|
|
|
messages_callback_map_.erase(message);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsWindowMessageHooked(UINT message) {
|
2015-10-27 12:00:08 +00:00
|
|
|
return ContainsKey(messages_callback_map_, message);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::UnhookAllWindowMessages() {
|
2015-10-27 12:00:08 +00:00
|
|
|
messages_callback_map_.clear();
|
|
|
|
}
|
2016-07-14 20:27:16 +00:00
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::SetThumbnailClip(const gfx::Rect& region) {
|
2016-07-14 20:27:16 +00:00
|
|
|
auto window = static_cast<NativeWindowViews*>(window_.get());
|
|
|
|
return window->taskbar_host().SetThumbnailClip(
|
|
|
|
window_->GetAcceleratedWidget(), region);
|
|
|
|
}
|
2016-08-07 17:23:42 +00:00
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::SetThumbnailToolTip(const std::string& tooltip) {
|
2016-08-07 17:23:42 +00:00
|
|
|
auto window = static_cast<NativeWindowViews*>(window_.get());
|
|
|
|
return window->taskbar_host().SetThumbnailToolTip(
|
|
|
|
window_->GetAcceleratedWidget(), tooltip);
|
|
|
|
}
|
2016-11-12 16:21:31 +00:00
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetAppDetails(const mate::Dictionary& options) {
|
2016-11-12 16:21:31 +00:00
|
|
|
base::string16 app_id;
|
|
|
|
base::FilePath app_icon_path;
|
2016-11-28 22:26:30 +00:00
|
|
|
int app_icon_index = 0;
|
2016-11-12 16:21:31 +00:00
|
|
|
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);
|
|
|
|
|
|
|
|
ui::win::SetAppDetailsForWindow(
|
|
|
|
app_id, app_icon_path, app_icon_index,
|
|
|
|
relaunch_command, relaunch_display_name,
|
|
|
|
window_->GetAcceleratedWidget());
|
|
|
|
}
|
2015-10-27 12:00:08 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-20 13:22:15 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetIcon(mate::Handle<NativeImage> icon) {
|
2016-05-20 13:22:15 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
static_cast<NativeWindowViews*>(window_.get())->SetIcon(
|
2016-05-30 00:46:42 +00:00
|
|
|
icon->GetHICON(GetSystemMetrics(SM_CXSMICON)),
|
|
|
|
icon->GetHICON(GetSystemMetrics(SM_CXICON)));
|
2016-05-20 13:22:15 +00:00
|
|
|
#elif defined(USE_X11)
|
|
|
|
static_cast<NativeWindowViews*>(window_.get())->SetIcon(
|
|
|
|
icon->image().AsImageSkia());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetAspectRatio(double aspect_ratio, mate::Arguments* args) {
|
2015-07-23 02:14:02 +00:00
|
|
|
gfx::Size extra_size;
|
|
|
|
args->GetNext(&extra_size);
|
|
|
|
window_->SetAspectRatio(aspect_ratio, extra_size);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::PreviewFile(const std::string& path,
|
|
|
|
mate::Arguments* args) {
|
2016-10-26 00:47:22 +00:00
|
|
|
std::string display_name;
|
2016-10-26 00:55:34 +00:00
|
|
|
if (!args->GetNext(&display_name))
|
2016-10-26 00:47:22 +00:00
|
|
|
display_name = path;
|
|
|
|
window_->PreviewFile(path, display_name);
|
2016-10-12 01:08:01 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::CloseFilePreview() {
|
2016-11-21 18:30:13 +00:00
|
|
|
window_->CloseFilePreview();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetParentWindow(v8::Local<v8::Value> value,
|
2016-06-17 07:57:03 +00:00
|
|
|
mate::Arguments* args) {
|
2016-06-20 05:49:24 +00:00
|
|
|
if (IsModal()) {
|
|
|
|
args->ThrowError("Can not be called for modal window");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
mate::Handle<BrowserWindow> parent;
|
2018-02-12 19:46:29 +00:00
|
|
|
if (value->IsNull() || value->IsUndefined()) {
|
2016-06-17 07:57:03 +00:00
|
|
|
RemoveFromParentChildWindows();
|
|
|
|
parent_window_.Reset();
|
|
|
|
window_->SetParentWindow(nullptr);
|
|
|
|
} else if (mate::ConvertFromV8(isolate(), value, &parent)) {
|
2016-06-17 07:09:43 +00:00
|
|
|
parent_window_.Reset(isolate(), value);
|
2016-06-17 07:57:03 +00:00
|
|
|
window_->SetParentWindow(parent->window_.get());
|
|
|
|
parent->child_windows_.Set(isolate(), ID(), GetWrapper());
|
2016-06-17 07:09:43 +00:00
|
|
|
} else {
|
|
|
|
args->ThrowError("Must pass BrowserWindow instance or null");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
v8::Local<v8::Value> BrowserWindow::GetParentWindow() const {
|
2016-06-17 07:09:43 +00:00
|
|
|
if (parent_window_.IsEmpty())
|
|
|
|
return v8::Null(isolate());
|
|
|
|
else
|
|
|
|
return v8::Local<v8::Value>::New(isolate(), parent_window_);
|
2016-06-17 06:28:43 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
std::vector<v8::Local<v8::Object>> BrowserWindow::GetChildWindows() const {
|
2016-06-17 07:57:03 +00:00
|
|
|
return child_windows_.Values(isolate());
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
v8::Local<v8::Value> BrowserWindow::GetBrowserView() const {
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
if (browser_view_.IsEmpty()) {
|
|
|
|
return v8::Null(isolate());
|
|
|
|
}
|
|
|
|
|
|
|
|
return v8::Local<v8::Value>::New(isolate(), browser_view_);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetBrowserView(v8::Local<v8::Value> value) {
|
2017-06-21 23:21:28 +00:00
|
|
|
ResetBrowserView();
|
|
|
|
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
mate::Handle<BrowserView> browser_view;
|
2018-02-12 19:46:29 +00:00
|
|
|
if (value->IsNull() || value->IsUndefined()) {
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
window_->SetBrowserView(nullptr);
|
|
|
|
} else if (mate::ConvertFromV8(isolate(), value, &browser_view)) {
|
|
|
|
window_->SetBrowserView(browser_view->view());
|
2017-06-21 23:21:28 +00:00
|
|
|
browser_view->web_contents()->SetOwnerWindow(window_.get());
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
browser_view_.Reset(isolate(), value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::ResetBrowserView() {
|
2017-06-21 23:21:28 +00:00
|
|
|
if (browser_view_.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mate::Handle<BrowserView> browser_view;
|
2018-02-12 19:46:29 +00:00
|
|
|
if (mate::ConvertFromV8(isolate(), GetBrowserView(), &browser_view)
|
|
|
|
&& !browser_view.IsEmpty()) {
|
2017-06-21 23:21:28 +00:00
|
|
|
browser_view->web_contents()->SetOwnerWindow(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
browser_view_.Reset();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsModal() const {
|
2016-06-20 05:49:24 +00:00
|
|
|
return window_->is_modal();
|
2016-06-18 13:53:41 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
v8::Local<v8::Value> BrowserWindow::GetNativeWindowHandle() {
|
2016-01-07 20:38:35 +00:00
|
|
|
gfx::AcceleratedWidget handle = window_->GetAcceleratedWidget();
|
2016-01-11 05:43:24 +00:00
|
|
|
return ToBuffer(
|
|
|
|
isolate(), static_cast<void*>(&handle), sizeof(gfx::AcceleratedWidget));
|
2016-01-07 20:38:35 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetVisibleOnAllWorkspaces(bool visible) {
|
2015-03-26 06:18:37 +00:00
|
|
|
return window_->SetVisibleOnAllWorkspaces(visible);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
bool BrowserWindow::IsVisibleOnAllWorkspaces() {
|
2015-03-26 06:18:37 +00:00
|
|
|
return window_->IsVisibleOnAllWorkspaces();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetAutoHideCursor(bool auto_hide) {
|
2016-11-28 19:38:40 +00:00
|
|
|
window_->SetAutoHideCursor(auto_hide);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SelectPreviousTab() {
|
2017-08-21 04:46:10 +00:00
|
|
|
window_->SelectPreviousTab();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SelectNextTab() {
|
2017-08-21 04:46:10 +00:00
|
|
|
window_->SelectNextTab();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::MergeAllWindows() {
|
2017-08-21 04:46:10 +00:00
|
|
|
window_->MergeAllWindows();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::MoveTabToNewWindow() {
|
2017-08-21 04:46:10 +00:00
|
|
|
window_->MoveTabToNewWindow();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::ToggleTabBar() {
|
2017-08-21 04:46:10 +00:00
|
|
|
window_->ToggleTabBar();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::AddTabbedWindow(NativeWindow* window) {
|
2017-09-13 19:15:14 +00:00
|
|
|
window_->AddTabbedWindow(window);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetVibrancy(mate::Arguments* args) {
|
2016-11-10 10:59:25 +00:00
|
|
|
std::string type;
|
2016-11-07 20:22:41 +00:00
|
|
|
|
2016-11-10 19:36:21 +00:00
|
|
|
args->GetNext(&type);
|
|
|
|
window_->SetVibrancy(type);
|
2016-11-07 20:22:41 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetTouchBar(
|
|
|
|
const std::vector<mate::PersistentDictionary>& items) {
|
2017-03-01 00:14:02 +00:00
|
|
|
window_->SetTouchBar(items);
|
2016-11-27 05:57:01 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::RefreshTouchBarItem(const std::string& item_id) {
|
2017-03-01 00:08:12 +00:00
|
|
|
window_->RefreshTouchBarItem(item_id);
|
2016-12-16 06:24:51 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::SetEscapeTouchBarItem(
|
|
|
|
const mate::PersistentDictionary& item) {
|
2017-03-27 00:22:52 +00:00
|
|
|
window_->SetEscapeTouchBarItem(item);
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
int32_t BrowserWindow::ID() const {
|
2015-06-24 08:37:48 +00:00
|
|
|
return weak_map_id();
|
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
v8::Local<v8::Value> BrowserWindow::WebContents(v8::Isolate* isolate) {
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
if (web_contents_.IsEmpty()) {
|
2015-06-24 11:04:08 +00:00
|
|
|
return v8::Null(isolate);
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return v8::Local<v8::Value>::New(isolate, web_contents_);
|
2014-04-24 08:45:25 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::RemoveFromParentChildWindows() {
|
2016-06-17 07:57:03 +00:00
|
|
|
if (parent_window_.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
mate::Handle<BrowserWindow> parent;
|
2018-02-12 19:46:29 +00:00
|
|
|
if (!mate::ConvertFromV8(isolate(), GetParentWindow(), &parent)
|
|
|
|
|| parent.IsEmpty()) {
|
2016-06-18 00:42:18 +00:00
|
|
|
return;
|
2018-02-12 19:46:29 +00:00
|
|
|
}
|
2016-06-18 00:42:18 +00:00
|
|
|
|
|
|
|
parent->child_windows_.Remove(ID());
|
2016-06-17 07:57:03 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
// static
|
2018-02-22 03:49:17 +00:00
|
|
|
void BrowserWindow::BuildPrototype(v8::Isolate* isolate,
|
|
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
2016-08-02 10:28:12 +00:00
|
|
|
prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
|
2016-08-02 09:08:12 +00:00
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
2015-12-03 07:38:43 +00:00
|
|
|
.MakeDestroyable()
|
2018-02-22 03:49:17 +00:00
|
|
|
.SetMethod("close", &BrowserWindow::Close)
|
|
|
|
.SetMethod("focus", &BrowserWindow::Focus)
|
|
|
|
.SetMethod("blur", &BrowserWindow::Blur)
|
|
|
|
.SetMethod("isFocused", &BrowserWindow::IsFocused)
|
|
|
|
.SetMethod("show", &BrowserWindow::Show)
|
|
|
|
.SetMethod("showInactive", &BrowserWindow::ShowInactive)
|
|
|
|
.SetMethod("hide", &BrowserWindow::Hide)
|
|
|
|
.SetMethod("isVisible", &BrowserWindow::IsVisible)
|
|
|
|
.SetMethod("isEnabled", &BrowserWindow::IsEnabled)
|
|
|
|
.SetMethod("setEnabled", & BrowserWindow::SetEnabled)
|
|
|
|
.SetMethod("maximize", &BrowserWindow::Maximize)
|
|
|
|
.SetMethod("unmaximize", &BrowserWindow::Unmaximize)
|
|
|
|
.SetMethod("isMaximized", &BrowserWindow::IsMaximized)
|
|
|
|
.SetMethod("minimize", &BrowserWindow::Minimize)
|
|
|
|
.SetMethod("restore", &BrowserWindow::Restore)
|
|
|
|
.SetMethod("isMinimized", &BrowserWindow::IsMinimized)
|
|
|
|
.SetMethod("setFullScreen", &BrowserWindow::SetFullScreen)
|
|
|
|
.SetMethod("isFullScreen", &BrowserWindow::IsFullscreen)
|
|
|
|
.SetMethod("setAspectRatio", &BrowserWindow::SetAspectRatio)
|
|
|
|
.SetMethod("previewFile", &BrowserWindow::PreviewFile)
|
|
|
|
.SetMethod("closeFilePreview", &BrowserWindow::CloseFilePreview)
|
2016-06-20 06:44:50 +00:00
|
|
|
#if !defined(OS_WIN)
|
2018-02-22 03:49:17 +00:00
|
|
|
.SetMethod("setParentWindow", &BrowserWindow::SetParentWindow)
|
2016-06-20 06:44:50 +00:00
|
|
|
#endif
|
2018-02-22 03:49:17 +00:00
|
|
|
.SetMethod("getParentWindow", &BrowserWindow::GetParentWindow)
|
|
|
|
.SetMethod("getChildWindows", &BrowserWindow::GetChildWindows)
|
|
|
|
.SetMethod("getBrowserView", &BrowserWindow::GetBrowserView)
|
|
|
|
.SetMethod("setBrowserView", &BrowserWindow::SetBrowserView)
|
|
|
|
.SetMethod("isModal", &BrowserWindow::IsModal)
|
|
|
|
.SetMethod("getNativeWindowHandle", &BrowserWindow::GetNativeWindowHandle)
|
|
|
|
.SetMethod("getBounds", &BrowserWindow::GetBounds)
|
|
|
|
.SetMethod("setBounds", &BrowserWindow::SetBounds)
|
|
|
|
.SetMethod("getSize", &BrowserWindow::GetSize)
|
|
|
|
.SetMethod("setSize", &BrowserWindow::SetSize)
|
|
|
|
.SetMethod("getContentBounds", &BrowserWindow::GetContentBounds)
|
|
|
|
.SetMethod("setContentBounds", &BrowserWindow::SetContentBounds)
|
|
|
|
.SetMethod("getContentSize", &BrowserWindow::GetContentSize)
|
|
|
|
.SetMethod("setContentSize", &BrowserWindow::SetContentSize)
|
|
|
|
.SetMethod("setMinimumSize", &BrowserWindow::SetMinimumSize)
|
|
|
|
.SetMethod("getMinimumSize", &BrowserWindow::GetMinimumSize)
|
|
|
|
.SetMethod("setMaximumSize", &BrowserWindow::SetMaximumSize)
|
|
|
|
.SetMethod("getMaximumSize", &BrowserWindow::GetMaximumSize)
|
|
|
|
.SetMethod("setSheetOffset", &BrowserWindow::SetSheetOffset)
|
|
|
|
.SetMethod("setResizable", &BrowserWindow::SetResizable)
|
|
|
|
.SetMethod("isResizable", &BrowserWindow::IsResizable)
|
|
|
|
.SetMethod("setMovable", &BrowserWindow::SetMovable)
|
|
|
|
.SetMethod("isMovable", &BrowserWindow::IsMovable)
|
|
|
|
.SetMethod("setMinimizable", &BrowserWindow::SetMinimizable)
|
|
|
|
.SetMethod("isMinimizable", &BrowserWindow::IsMinimizable)
|
|
|
|
.SetMethod("setMaximizable", &BrowserWindow::SetMaximizable)
|
|
|
|
.SetMethod("isMaximizable", &BrowserWindow::IsMaximizable)
|
|
|
|
.SetMethod("setFullScreenable", &BrowserWindow::SetFullScreenable)
|
|
|
|
.SetMethod("isFullScreenable", &BrowserWindow::IsFullScreenable)
|
|
|
|
.SetMethod("setClosable", &BrowserWindow::SetClosable)
|
|
|
|
.SetMethod("isClosable", &BrowserWindow::IsClosable)
|
|
|
|
.SetMethod("setAlwaysOnTop", &BrowserWindow::SetAlwaysOnTop)
|
|
|
|
.SetMethod("isAlwaysOnTop", &BrowserWindow::IsAlwaysOnTop)
|
|
|
|
.SetMethod("center", &BrowserWindow::Center)
|
|
|
|
.SetMethod("setPosition", &BrowserWindow::SetPosition)
|
|
|
|
.SetMethod("getPosition", &BrowserWindow::GetPosition)
|
|
|
|
.SetMethod("setTitle", &BrowserWindow::SetTitle)
|
|
|
|
.SetMethod("getTitle", &BrowserWindow::GetTitle)
|
|
|
|
.SetMethod("flashFrame", &BrowserWindow::FlashFrame)
|
|
|
|
.SetMethod("setSkipTaskbar", &BrowserWindow::SetSkipTaskbar)
|
|
|
|
.SetMethod("setSimpleFullScreen", &BrowserWindow::SetSimpleFullScreen)
|
|
|
|
.SetMethod("isSimpleFullScreen", &BrowserWindow::IsSimpleFullScreen)
|
|
|
|
.SetMethod("setKiosk", &BrowserWindow::SetKiosk)
|
|
|
|
.SetMethod("isKiosk", &BrowserWindow::IsKiosk)
|
|
|
|
.SetMethod("setBackgroundColor", &BrowserWindow::SetBackgroundColor)
|
|
|
|
.SetMethod("setHasShadow", &BrowserWindow::SetHasShadow)
|
|
|
|
.SetMethod("hasShadow", &BrowserWindow::HasShadow)
|
|
|
|
.SetMethod("setOpacity", &BrowserWindow::SetOpacity)
|
|
|
|
.SetMethod("getOpacity", &BrowserWindow::GetOpacity)
|
|
|
|
.SetMethod("setRepresentedFilename",
|
|
|
|
&BrowserWindow::SetRepresentedFilename)
|
|
|
|
.SetMethod("getRepresentedFilename",
|
|
|
|
&BrowserWindow::GetRepresentedFilename)
|
|
|
|
.SetMethod("setDocumentEdited", &BrowserWindow::SetDocumentEdited)
|
|
|
|
.SetMethod("isDocumentEdited", &BrowserWindow::IsDocumentEdited)
|
|
|
|
.SetMethod("setIgnoreMouseEvents", &BrowserWindow::SetIgnoreMouseEvents)
|
|
|
|
.SetMethod("setContentProtection", &BrowserWindow::SetContentProtection)
|
|
|
|
.SetMethod("setFocusable", &BrowserWindow::SetFocusable)
|
|
|
|
.SetMethod("focusOnWebView", &BrowserWindow::FocusOnWebView)
|
|
|
|
.SetMethod("blurWebView", &BrowserWindow::BlurWebView)
|
|
|
|
.SetMethod("isWebViewFocused", &BrowserWindow::IsWebViewFocused)
|
|
|
|
.SetMethod("setProgressBar", &BrowserWindow::SetProgressBar)
|
|
|
|
.SetMethod("setOverlayIcon", &BrowserWindow::SetOverlayIcon)
|
|
|
|
.SetMethod("setThumbarButtons", &BrowserWindow::SetThumbarButtons)
|
|
|
|
.SetMethod("setMenu", &BrowserWindow::SetMenu)
|
|
|
|
.SetMethod("setAutoHideMenuBar", &BrowserWindow::SetAutoHideMenuBar)
|
|
|
|
.SetMethod("isMenuBarAutoHide", &BrowserWindow::IsMenuBarAutoHide)
|
|
|
|
.SetMethod("setMenuBarVisibility", &BrowserWindow::SetMenuBarVisibility)
|
|
|
|
.SetMethod("isMenuBarVisible", &BrowserWindow::IsMenuBarVisible)
|
2015-03-26 06:18:37 +00:00
|
|
|
.SetMethod("setVisibleOnAllWorkspaces",
|
2018-02-22 03:49:17 +00:00
|
|
|
&BrowserWindow::SetVisibleOnAllWorkspaces)
|
2015-03-26 06:18:37 +00:00
|
|
|
.SetMethod("isVisibleOnAllWorkspaces",
|
2018-02-22 03:49:17 +00:00
|
|
|
&BrowserWindow::IsVisibleOnAllWorkspaces)
|
2016-11-28 19:38:40 +00:00
|
|
|
#if defined(OS_MACOSX)
|
2018-02-22 03:49:17 +00:00
|
|
|
.SetMethod("setAutoHideCursor", &BrowserWindow::SetAutoHideCursor)
|
|
|
|
.SetMethod("mergeAllWindows", &BrowserWindow::MergeAllWindows)
|
|
|
|
.SetMethod("selectPreviousTab", &BrowserWindow::SelectPreviousTab)
|
|
|
|
.SetMethod("selectNextTab", &BrowserWindow::SelectNextTab)
|
|
|
|
.SetMethod("moveTabToNewWindow", &BrowserWindow::MoveTabToNewWindow)
|
|
|
|
.SetMethod("toggleTabBar", &BrowserWindow::ToggleTabBar)
|
|
|
|
.SetMethod("addTabbedWindow", &BrowserWindow::AddTabbedWindow)
|
2016-11-28 19:38:40 +00:00
|
|
|
#endif
|
2018-02-22 03:49:17 +00:00
|
|
|
.SetMethod("setVibrancy", &BrowserWindow::SetVibrancy)
|
|
|
|
.SetMethod("_setTouchBarItems", &BrowserWindow::SetTouchBar)
|
|
|
|
.SetMethod("_refreshTouchBarItem", &BrowserWindow::RefreshTouchBarItem)
|
|
|
|
.SetMethod("_setEscapeTouchBarItem",
|
|
|
|
&BrowserWindow::SetEscapeTouchBarItem)
|
2015-10-27 12:00:08 +00:00
|
|
|
#if defined(OS_WIN)
|
2018-02-22 03:49:17 +00:00
|
|
|
.SetMethod("hookWindowMessage", &BrowserWindow::HookWindowMessage)
|
|
|
|
.SetMethod("isWindowMessageHooked",
|
|
|
|
&BrowserWindow::IsWindowMessageHooked)
|
|
|
|
.SetMethod("unhookWindowMessage", &BrowserWindow::UnhookWindowMessage)
|
|
|
|
.SetMethod("unhookAllWindowMessages",
|
|
|
|
&BrowserWindow::UnhookAllWindowMessages)
|
|
|
|
.SetMethod("setThumbnailClip", &BrowserWindow::SetThumbnailClip)
|
|
|
|
.SetMethod("setThumbnailToolTip", &BrowserWindow::SetThumbnailToolTip)
|
|
|
|
.SetMethod("setAppDetails", &BrowserWindow::SetAppDetails)
|
2015-10-27 12:00:08 +00:00
|
|
|
#endif
|
2016-05-20 13:22:15 +00:00
|
|
|
#if defined(TOOLKIT_VIEWS)
|
2018-02-22 03:49:17 +00:00
|
|
|
.SetMethod("setIcon", &BrowserWindow::SetIcon)
|
2014-12-18 23:40:35 +00:00
|
|
|
#endif
|
2018-02-22 03:49:17 +00:00
|
|
|
.SetProperty("id", &BrowserWindow::ID)
|
|
|
|
.SetProperty("webContents", &BrowserWindow::WebContents);
|
2013-04-18 16:06:10 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 05:45:59 +00:00
|
|
|
// static
|
2018-02-22 03:49:17 +00:00
|
|
|
v8::Local<v8::Value> BrowserWindow::From(v8::Isolate* isolate,
|
|
|
|
NativeWindow* native_window) {
|
2015-10-01 05:45:59 +00:00
|
|
|
auto existing = TrackableObject::FromWrappedClass(isolate, native_window);
|
|
|
|
if (existing)
|
2016-04-25 01:19:25 +00:00
|
|
|
return existing->GetWrapper();
|
2015-10-01 05:45:59 +00:00
|
|
|
else
|
|
|
|
return v8::Null(isolate);
|
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace api
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace atom
|
2013-04-18 07:09:53 +00:00
|
|
|
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
namespace {
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2018-02-22 03:49:17 +00:00
|
|
|
using atom::api::BrowserWindow;
|
2015-06-24 08:37:48 +00:00
|
|
|
|
2015-05-22 11:11:22 +00:00
|
|
|
void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
|
|
|
v8::Local<v8::Context> context, void* priv) {
|
2014-06-29 12:48:44 +00:00
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2018-02-22 03:49:17 +00:00
|
|
|
BrowserWindow::SetConstructor(isolate, base::Bind(&BrowserWindow::New));
|
2016-08-02 08:02:04 +00:00
|
|
|
|
2016-08-02 08:20:58 +00:00
|
|
|
mate::Dictionary browser_window(
|
2018-02-22 03:49:17 +00:00
|
|
|
isolate, BrowserWindow::GetConstructor(isolate)->GetFunction());
|
|
|
|
browser_window.SetMethod(
|
|
|
|
"fromId",
|
|
|
|
&mate::TrackableObject<BrowserWindow>::FromWeakMapID);
|
|
|
|
browser_window.SetMethod(
|
|
|
|
"getAllWindows",
|
|
|
|
&mate::TrackableObject<BrowserWindow>::GetAll);
|
2015-06-24 08:37:48 +00:00
|
|
|
|
2014-06-28 11:49:55 +00:00
|
|
|
mate::Dictionary dict(isolate, exports);
|
2015-06-24 08:37:48 +00:00
|
|
|
dict.Set("BrowserWindow", browser_window);
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2014-06-29 12:48:44 +00:00
|
|
|
NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_window, Initialize)
|