mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
* chore: Bump 78.0.3894.0 * chore: bump chromium to 32e0bab929213da1019992bf31d29 (master) (#19488) * chore: bump chromium to cbeb16cf544f79c1990f1eae4d4fe (master) (#19610) Co-authored-by: Erick Zhao <erickzhao@github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> Co-authored-by Micha Hanselmann <DeerMichel@github.com> * chore: bump chromium to 62327c655093c821aa0fcfc6db53f5fd943e08c7 (master) (#19792) * chore: bump chromium in DEPS to f3bf493731e868e1f5f48e7e1adc02ea5eccfbbd * chore: bump chromium in DEPS to 4db0c87d4aa6f27ffa0b5fc77d20e10047962484 * chore: bump chromium in DEPS to d933a504c264dc8fe85267f47aef3588531875b5 * chore: bump chromium in DEPS to 34afdb68980f581ae911b85b727bc17e126cf5f9 * update disable-redraw-lock.patch https://chromium-review.googlesource.com/c/chromium/src/+/1600387 * update desktop_media_list.patch https://chromium-review.googlesource.com/c/chromium/src/+/1729156 * update notification_provenance.patch https://chromium-review.googlesource.com/c/chromium/src/+/1742779 * update printing.patch https://chromium-review.googlesource.com/c/chromium/src/+/1646772 * update verbose_generate_bpad_syms.patch https://chromium-review.googlesource.com/c/chromium/src/+/1745986 * update patch metadata * remove printing_compositor manifests https://chromium-review.googlesource.com/c/chromium/src/+/1742734 * update for URLLoaderFactoryType enum https://chromium-review.googlesource.com/c/chromium/src/+/1754716 * remove gin string16 converter https://chromium-review.googlesource.com/c/chromium/src/+/1750093 * ClearCompositorFrame() has been removed https://chromium-review.googlesource.com/c/chromium/src/+/1746301 * message_loop -> message_loop_current https://chromium-review.googlesource.com/c/chromium/src/+/1738552 * include resource_response header * pdf compositor no longer uses service manager https://chromium-review.googlesource.com/c/chromium/src/+/1742734 * chore: bump chromium in DEPS to 00d5933101d8d8dc9546eadbe7ee1b41077e6db1 * pane focus fns aren't pure virtual anymore https://chromium-review.googlesource.com/c/chromium/src/+/1708767 * fix: make std::hash value-non-const broken by https://chromium-review.googlesource.com/c/chromium/src/+/1711202 * update swiftshader in zip_manifests https://swiftshader-review.googlesource.com/c/SwiftShader/+/34911 * address feedback from @deepak1556 * don't enable kLegacyWindowsDWriteFontFallback https://chromium-review.googlesource.com/c/chromium/src/+/1753006 * chore: bump chromium in DEPS to 84497314005e1968da06804f8fde539d9872310e * update printing.patch remove bottom diff owing to https://chromium-review.googlesource.com/c/chromium/src/+/1678182 and update for https://chromium-review.googlesource.com/c/chromium/src/+/1678182 * convert CookieChangeListener to new Mojo types https://chromium-review.googlesource.com/c/chromium/src/+/1753371 * rename ui::ClipboardType -> ui::ClipboardBuffer https://chromium-review.googlesource.com/c/chromium/src/+/1758730 * logging::LoggingSettings log_file -> log_file_path https://chromium-review.googlesource.com/c/chromium/src/+/1699477 * roll DEPS to latest lkgr * fix: override GetFontLookupTableCacheDir() When Chromium goes to use its fallback font table creation code paths, it creates the cache directory it uses by calling GetFontLookupTableCacheDir() with a path that doesn't exist in Electron. To ensure that a legitimate file path is created, we need to override it with Electron's DIR_USER_DATA so it doesn't use chrome::DIR_USER_DATA. * chore: bump chromium in DEPS to 6758a0879931bc4df630a80a36c82d7855ae3155 * update pthread_fchdir patch https://chromium-review.googlesource.com/c/chromium/src/+/1759149 * update printing patch * update cookie usage and fn signatures https://chromium-review.googlesource.com/c/chromium/src/+/1758437 * chore: bump chromium in DEPS to bdaca97e1cc27fb977e56f30f74cdb906da9527e * remove fix_make_std_hash_value-non-const.patch https://chromium-review.googlesource.com/c/chromium/src/+/1762335 * Convert enum to enum class for FocusManager::FocusChangeReason https://chromium-review.googlesource.com/c/chromium/src/+/1767281 * roll DEPS to latest lkgr * update dom_storage_limits.patch https://chromium-review.googlesource.com/c/chromium/src/+/1767556 * chore: remove pre network service classes from shell/browser/net (#19644) * refactor: rm IOThread class * chore: rm expose-net-observer-api.patch * chore: rm unused shell/browser/net/ classes * chore: mv CertVerifierClient to separate header * chore: rm url_request_context_getter references * chore: update patches * Require task posters to specify an explicit destination https://chromium-review.googlesource.com/c/chromium/src/+/1769080 * chore: Revert "Cleanup: Remove Menu Subtitles/Sublabels" * chore: Bump chromium 78.0.3896.0 * build: add checkout_openxr=False to DEPS Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1745502 * chore: update patches * Convert TrustedURLLoaderHeaderClient and TrustedHeaderClient to new mojo types https://chromium-review.googlesource.com/c/chromium/src/+/1767298 https://chromium-review.googlesource.com/c/chromium/src/+/1768841 * skia: more rect api simplifications https://skia-review.googlesource.com/c/skia/+/237038 * iwyu * test: fix clearAuthCache test (#20015) * fix: nws13n: make ses.setUserAgent work (#20014) * refactor tests to better control window creation * fix: nws13n: make ses.setUserAgent work * chore: update v8 patches * Add enterprise policy for renderer CIG. https://chromium-review.googlesource.com/c/chromium/src/+/1758589 * Convert enum to enum class for Wigdet::FrameType https://chromium-review.googlesource.com/c/chromium/src/+/1767292 * [JJI] Convert to use string16 for data from JavaScript/Java https://chromium-review.googlesource.com/c/chromium/src/+/1750093 * chore: Bump chromium 78.0.3896.6
489 lines
16 KiB
C++
489 lines
16 KiB
C++
// Copyright (c) 2013 GitHub, Inc.
|
|
// Use of this source code is governed by the MIT license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/api/atom_api_browser_window.h"
|
|
|
|
#include <memory>
|
|
|
|
#include "base/threading/thread_task_runner_handle.h"
|
|
#include "content/browser/renderer_host/render_widget_host_impl.h" // nogncheck
|
|
#include "content/browser/renderer_host/render_widget_host_owner_delegate.h" // nogncheck
|
|
#include "content/public/browser/render_process_host.h"
|
|
#include "content/public/browser/render_view_host.h"
|
|
#include "gin/converter.h"
|
|
#include "native_mate/dictionary.h"
|
|
#include "shell/browser/browser.h"
|
|
#include "shell/browser/unresponsive_suppressor.h"
|
|
#include "shell/browser/web_contents_preferences.h"
|
|
#include "shell/browser/window_list.h"
|
|
#include "shell/common/api/constructor.h"
|
|
#include "shell/common/color_util.h"
|
|
#include "shell/common/native_mate_converters/callback.h"
|
|
#include "shell/common/native_mate_converters/value_converter.h"
|
|
#include "shell/common/node_includes.h"
|
|
#include "shell/common/options_switches.h"
|
|
#include "ui/gl/gpu_switching_manager.h"
|
|
|
|
namespace electron {
|
|
|
|
namespace api {
|
|
|
|
BrowserWindow::BrowserWindow(v8::Isolate* isolate,
|
|
v8::Local<v8::Object> wrapper,
|
|
const mate::Dictionary& options)
|
|
: TopLevelWindow(isolate, options), weak_factory_(this) {
|
|
mate::Handle<class WebContents> web_contents;
|
|
|
|
// Use options.webPreferences in WebContents.
|
|
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
|
|
options.Get(options::kWebPreferences, &web_preferences);
|
|
|
|
// 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);
|
|
|
|
if (options.Get("webContents", &web_contents) && !web_contents.IsEmpty()) {
|
|
// Set webPreferences from options if using an existing webContents.
|
|
// These preferences will be used when the webContent launches new
|
|
// render processes.
|
|
auto* existing_preferences =
|
|
WebContentsPreferences::From(web_contents->web_contents());
|
|
base::DictionaryValue web_preferences_dict;
|
|
if (mate::ConvertFromV8(isolate, web_preferences.GetHandle(),
|
|
&web_preferences_dict)) {
|
|
existing_preferences->Clear();
|
|
existing_preferences->Merge(web_preferences_dict);
|
|
}
|
|
} else {
|
|
// Creates the WebContents used by BrowserWindow.
|
|
web_contents = WebContents::Create(isolate, web_preferences);
|
|
}
|
|
|
|
web_contents_.Reset(isolate, web_contents.ToV8());
|
|
api_web_contents_ = web_contents->GetWeakPtr();
|
|
api_web_contents_->AddObserver(this);
|
|
Observe(api_web_contents_->web_contents());
|
|
|
|
// Keep a copy of the options for later use.
|
|
mate::Dictionary(isolate, web_contents->GetWrapper())
|
|
.Set("browserWindowOptions", options);
|
|
|
|
// Associate with BrowserWindow.
|
|
web_contents->SetOwnerWindow(window());
|
|
|
|
auto* host = web_contents->web_contents()->GetRenderViewHost();
|
|
if (host)
|
|
host->GetWidget()->AddInputEventObserver(this);
|
|
|
|
InitWith(isolate, wrapper);
|
|
|
|
#if defined(OS_MACOSX)
|
|
OverrideNSWindowContentView(web_contents->managed_web_contents());
|
|
#endif
|
|
|
|
// Init window after everything has been setup.
|
|
window()->InitFromOptions(options);
|
|
}
|
|
|
|
BrowserWindow::~BrowserWindow() {
|
|
// FIXME This is a hack rather than a proper fix preventing shutdown crashes.
|
|
if (api_web_contents_)
|
|
api_web_contents_->RemoveObserver(this);
|
|
// Note that the OnWindowClosed will not be called after the destructor runs,
|
|
// since the window object is managed by the TopLevelWindow class.
|
|
if (web_contents())
|
|
Cleanup();
|
|
}
|
|
|
|
void BrowserWindow::OnInputEvent(const blink::WebInputEvent& event) {
|
|
switch (event.GetType()) {
|
|
case blink::WebInputEvent::kGestureScrollBegin:
|
|
case blink::WebInputEvent::kGestureScrollUpdate:
|
|
case blink::WebInputEvent::kGestureScrollEnd:
|
|
Emit("scroll-touch-edge");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void BrowserWindow::RenderViewHostChanged(content::RenderViewHost* old_host,
|
|
content::RenderViewHost* new_host) {
|
|
if (old_host)
|
|
old_host->GetWidget()->RemoveInputEventObserver(this);
|
|
if (new_host)
|
|
new_host->GetWidget()->AddInputEventObserver(this);
|
|
}
|
|
|
|
void BrowserWindow::RenderViewCreated(
|
|
content::RenderViewHost* render_view_host) {
|
|
if (!window()->transparent())
|
|
return;
|
|
|
|
content::RenderWidgetHostImpl* impl = content::RenderWidgetHostImpl::FromID(
|
|
render_view_host->GetProcess()->GetID(),
|
|
render_view_host->GetRoutingID());
|
|
if (impl)
|
|
impl->owner_delegate()->SetBackgroundOpaque(false);
|
|
}
|
|
|
|
void BrowserWindow::DidFirstVisuallyNonEmptyPaint() {
|
|
if (window()->IsVisible())
|
|
return;
|
|
|
|
// When there is a non-empty first paint, resize the RenderWidget to force
|
|
// Chromium to draw.
|
|
auto* const 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::BindOnce(
|
|
[](base::WeakPtr<BrowserWindow> self) {
|
|
if (self)
|
|
self->Emit("ready-to-show");
|
|
},
|
|
GetWeakPtr()));
|
|
}
|
|
|
|
void BrowserWindow::BeforeUnloadDialogCancelled() {
|
|
WindowList::WindowCloseCancelled(window());
|
|
// Cancel unresponsive event when window close is cancelled.
|
|
window_unresponsive_closure_.Cancel();
|
|
}
|
|
|
|
void BrowserWindow::OnRendererUnresponsive(content::RenderProcessHost*) {
|
|
// Schedule the unresponsive shortly later, since we may receive the
|
|
// responsive event soon. This could happen after the whole application had
|
|
// blocked for a while.
|
|
// Also notice that when closing this event would be ignored because we have
|
|
// explicitly started a close timeout counter. This is on purpose because we
|
|
// don't want the unresponsive event to be sent too early when user is closing
|
|
// the window.
|
|
ScheduleUnresponsiveEvent(50);
|
|
}
|
|
|
|
void BrowserWindow::OnCloseContents() {
|
|
// On some machines it may happen that the window gets destroyed for twice,
|
|
// checking web_contents() can effectively guard against that.
|
|
// https://github.com/electron/electron/issues/16202.
|
|
//
|
|
// TODO(zcbenz): We should find out the root cause and improve the closing
|
|
// procedure of BrowserWindow.
|
|
if (!web_contents())
|
|
return;
|
|
|
|
// 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())) {
|
|
mate::Handle<BrowserWindow> child;
|
|
if (mate::ConvertFromV8(isolate(), value, &child) && !child.IsEmpty())
|
|
child->window()->CloseImmediately();
|
|
}
|
|
|
|
// When the web contents is gone, close the window immediately, but the
|
|
// memory will not be freed until you call delete.
|
|
// In this way, it would be safe to manage windows via smart pointers. If you
|
|
// want to free memory when the window is closed, you can do deleting by
|
|
// overriding the OnWindowClosed method in the observer.
|
|
window()->CloseImmediately();
|
|
|
|
// Do not sent "unresponsive" event after window is closed.
|
|
window_unresponsive_closure_.Cancel();
|
|
}
|
|
|
|
void BrowserWindow::OnRendererResponsive() {
|
|
window_unresponsive_closure_.Cancel();
|
|
Emit("responsive");
|
|
}
|
|
|
|
void BrowserWindow::OnDraggableRegionsUpdated(
|
|
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
|
UpdateDraggableRegions(regions);
|
|
}
|
|
|
|
void BrowserWindow::RequestPreferredWidth(int* width) {
|
|
*width = web_contents()->GetPreferredSize().width();
|
|
}
|
|
|
|
void BrowserWindow::OnCloseButtonClicked(bool* prevent_default) {
|
|
// When user tries to close the window by clicking the close button, we do
|
|
// not close the window immediately, instead we try to close the web page
|
|
// first, and when the web page is closed the window will also be closed.
|
|
*prevent_default = true;
|
|
|
|
// Assume the window is not responding if it doesn't cancel the close and is
|
|
// not closed in 5s, in this way we can quickly show the unresponsive
|
|
// dialog when the window is busy executing some script withouth waiting for
|
|
// the unresponsive timeout.
|
|
if (window_unresponsive_closure_.IsCancelled())
|
|
ScheduleUnresponsiveEvent(5000);
|
|
|
|
if (!web_contents())
|
|
// Already closed by renderer
|
|
return;
|
|
|
|
if (web_contents()->NeedToFireBeforeUnload())
|
|
web_contents()->DispatchBeforeUnload(false /* auto_cancel */);
|
|
else
|
|
web_contents()->Close();
|
|
}
|
|
|
|
void BrowserWindow::OnWindowClosed() {
|
|
Cleanup();
|
|
TopLevelWindow::OnWindowClosed();
|
|
}
|
|
|
|
void BrowserWindow::OnWindowBlur() {
|
|
web_contents()->StoreFocus();
|
|
#if defined(OS_MACOSX)
|
|
auto* rwhv = web_contents()->GetRenderWidgetHostView();
|
|
if (rwhv)
|
|
rwhv->SetActive(false);
|
|
#endif
|
|
|
|
TopLevelWindow::OnWindowBlur();
|
|
}
|
|
|
|
void BrowserWindow::OnWindowFocus() {
|
|
web_contents()->RestoreFocus();
|
|
#if defined(OS_MACOSX)
|
|
auto* rwhv = web_contents()->GetRenderWidgetHostView();
|
|
if (rwhv)
|
|
rwhv->SetActive(true);
|
|
#else
|
|
if (!api_web_contents_->IsDevToolsOpened())
|
|
web_contents()->Focus();
|
|
#endif
|
|
|
|
TopLevelWindow::OnWindowFocus();
|
|
}
|
|
|
|
void BrowserWindow::OnWindowResize() {
|
|
#if defined(OS_MACOSX)
|
|
if (!draggable_regions_.empty())
|
|
UpdateDraggableRegions(draggable_regions_);
|
|
#endif
|
|
TopLevelWindow::OnWindowResize();
|
|
}
|
|
|
|
void BrowserWindow::OnWindowLeaveFullScreen() {
|
|
TopLevelWindow::OnWindowLeaveFullScreen();
|
|
#if defined(OS_MACOSX)
|
|
if (web_contents()->IsFullscreenForCurrentTab())
|
|
web_contents()->ExitFullscreen(true);
|
|
#endif
|
|
}
|
|
|
|
void BrowserWindow::Focus() {
|
|
if (api_web_contents_->IsOffScreen())
|
|
FocusOnWebView();
|
|
else
|
|
TopLevelWindow::Focus();
|
|
}
|
|
|
|
void BrowserWindow::Blur() {
|
|
if (api_web_contents_->IsOffScreen())
|
|
BlurWebView();
|
|
else
|
|
TopLevelWindow::Blur();
|
|
}
|
|
|
|
void BrowserWindow::SetBackgroundColor(const std::string& color_name) {
|
|
TopLevelWindow::SetBackgroundColor(color_name);
|
|
auto* view = web_contents()->GetRenderWidgetHostView();
|
|
if (view)
|
|
view->SetBackgroundColor(ParseHexColor(color_name));
|
|
// Also update the web preferences object otherwise the view will be reset on
|
|
// the next load URL call
|
|
if (api_web_contents_) {
|
|
auto* web_preferences =
|
|
WebContentsPreferences::From(api_web_contents_->web_contents());
|
|
if (web_preferences) {
|
|
web_preferences->preference()->SetStringKey(options::kBackgroundColor,
|
|
color_name);
|
|
}
|
|
}
|
|
}
|
|
|
|
void BrowserWindow::SetBrowserView(v8::Local<v8::Value> value) {
|
|
TopLevelWindow::ResetBrowserViews();
|
|
TopLevelWindow::AddBrowserView(value);
|
|
#if defined(OS_MACOSX)
|
|
UpdateDraggableRegions(draggable_regions_);
|
|
#endif
|
|
}
|
|
|
|
void BrowserWindow::AddBrowserView(v8::Local<v8::Value> value) {
|
|
TopLevelWindow::AddBrowserView(value);
|
|
#if defined(OS_MACOSX)
|
|
UpdateDraggableRegions(draggable_regions_);
|
|
#endif
|
|
}
|
|
|
|
void BrowserWindow::RemoveBrowserView(v8::Local<v8::Value> value) {
|
|
TopLevelWindow::RemoveBrowserView(value);
|
|
#if defined(OS_MACOSX)
|
|
UpdateDraggableRegions(draggable_regions_);
|
|
#endif
|
|
}
|
|
|
|
void BrowserWindow::ResetBrowserViews() {
|
|
TopLevelWindow::ResetBrowserViews();
|
|
#if defined(OS_MACOSX)
|
|
UpdateDraggableRegions(draggable_regions_);
|
|
#endif
|
|
}
|
|
|
|
void BrowserWindow::SetVibrancy(v8::Isolate* isolate,
|
|
v8::Local<v8::Value> value) {
|
|
std::string type = gin::V8ToString(isolate, value);
|
|
|
|
auto* render_view_host = web_contents()->GetRenderViewHost();
|
|
if (render_view_host) {
|
|
auto* impl = content::RenderWidgetHostImpl::FromID(
|
|
render_view_host->GetProcess()->GetID(),
|
|
render_view_host->GetRoutingID());
|
|
if (impl)
|
|
impl->owner_delegate()->SetBackgroundOpaque(
|
|
type.empty() ? !window_->transparent() : false);
|
|
}
|
|
|
|
TopLevelWindow::SetVibrancy(isolate, value);
|
|
}
|
|
|
|
void BrowserWindow::FocusOnWebView() {
|
|
web_contents()->GetRenderViewHost()->GetWidget()->Focus();
|
|
}
|
|
|
|
void BrowserWindow::BlurWebView() {
|
|
web_contents()->GetRenderViewHost()->GetWidget()->Blur();
|
|
}
|
|
|
|
bool BrowserWindow::IsWebViewFocused() {
|
|
auto* host_view = web_contents()->GetRenderViewHost()->GetWidget()->GetView();
|
|
return host_view && host_view->HasFocus();
|
|
}
|
|
|
|
v8::Local<v8::Value> BrowserWindow::GetWebContents(v8::Isolate* isolate) {
|
|
if (web_contents_.IsEmpty())
|
|
return v8::Null(isolate);
|
|
return v8::Local<v8::Value>::New(isolate, web_contents_);
|
|
}
|
|
|
|
// Convert draggable regions in raw format to SkRegion format.
|
|
std::unique_ptr<SkRegion> BrowserWindow::DraggableRegionsToSkRegion(
|
|
const std::vector<mojom::DraggableRegionPtr>& regions) {
|
|
auto sk_region = std::make_unique<SkRegion>();
|
|
for (const auto& region : regions) {
|
|
sk_region->op(
|
|
{region->bounds.x(), region->bounds.y(), region->bounds.right(),
|
|
region->bounds.bottom()},
|
|
region->draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
|
|
}
|
|
return sk_region;
|
|
}
|
|
|
|
void BrowserWindow::ScheduleUnresponsiveEvent(int ms) {
|
|
if (!window_unresponsive_closure_.IsCancelled())
|
|
return;
|
|
|
|
window_unresponsive_closure_.Reset(base::BindRepeating(
|
|
&BrowserWindow::NotifyWindowUnresponsive, GetWeakPtr()));
|
|
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
|
|
FROM_HERE, window_unresponsive_closure_.callback(),
|
|
base::TimeDelta::FromMilliseconds(ms));
|
|
}
|
|
|
|
void BrowserWindow::NotifyWindowUnresponsive() {
|
|
window_unresponsive_closure_.Cancel();
|
|
if (!window_->IsClosed() && window_->IsEnabled() &&
|
|
!IsUnresponsiveEventSuppressed()) {
|
|
Emit("unresponsive");
|
|
}
|
|
}
|
|
|
|
void BrowserWindow::Cleanup() {
|
|
auto* host = web_contents()->GetRenderViewHost();
|
|
if (host)
|
|
host->GetWidget()->RemoveInputEventObserver(this);
|
|
|
|
// Destroy WebContents asynchronously unless app is shutting down,
|
|
// because destroy() might be called inside WebContents's event handler.
|
|
api_web_contents_->DestroyWebContents(!Browser::Get()->is_shutting_down());
|
|
Observe(nullptr);
|
|
}
|
|
|
|
// static
|
|
mate::WrappableBase* BrowserWindow::New(mate::Arguments* args) {
|
|
if (!Browser::Get()->is_ready()) {
|
|
args->ThrowError("Cannot create BrowserWindow before app is ready");
|
|
return nullptr;
|
|
}
|
|
|
|
if (args->Length() > 1) {
|
|
args->ThrowError();
|
|
return nullptr;
|
|
}
|
|
|
|
mate::Dictionary options;
|
|
if (!(args->Length() == 1 && args->GetNext(&options))) {
|
|
options = mate::Dictionary::CreateEmpty(args->isolate());
|
|
}
|
|
|
|
return new BrowserWindow(args->isolate(), args->GetThis(), options);
|
|
}
|
|
|
|
// static
|
|
void BrowserWindow::BuildPrototype(v8::Isolate* isolate,
|
|
v8::Local<v8::FunctionTemplate> prototype) {
|
|
prototype->SetClassName(mate::StringToV8(isolate, "BrowserWindow"));
|
|
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate())
|
|
.SetMethod("focusOnWebView", &BrowserWindow::FocusOnWebView)
|
|
.SetMethod("blurWebView", &BrowserWindow::BlurWebView)
|
|
.SetMethod("isWebViewFocused", &BrowserWindow::IsWebViewFocused)
|
|
.SetProperty("webContents", &BrowserWindow::GetWebContents);
|
|
}
|
|
|
|
// static
|
|
v8::Local<v8::Value> BrowserWindow::From(v8::Isolate* isolate,
|
|
NativeWindow* native_window) {
|
|
auto* existing = TrackableObject::FromWrappedClass(isolate, native_window);
|
|
if (existing)
|
|
return existing->GetWrapper();
|
|
else
|
|
return v8::Null(isolate);
|
|
}
|
|
|
|
} // namespace api
|
|
|
|
} // namespace electron
|
|
|
|
namespace {
|
|
|
|
using electron::api::BrowserWindow;
|
|
using electron::api::TopLevelWindow;
|
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
v8::Local<v8::Value> unused,
|
|
v8::Local<v8::Context> context,
|
|
void* priv) {
|
|
v8::Isolate* isolate = context->GetIsolate();
|
|
mate::Dictionary dict(isolate, exports);
|
|
dict.Set("BrowserWindow",
|
|
mate::CreateConstructor<BrowserWindow>(
|
|
isolate, base::BindRepeating(&BrowserWindow::New)));
|
|
}
|
|
|
|
} // namespace
|
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(atom_browser_window, Initialize)
|