fix: explicitly call GetNativeNSView() on macOS (#46733)
* fix: explicitly call GetNativeNSView() on macOS * chore: move macOS impl to a .mm file This is needed in order to access gfx::NativeView::GetNativeNSView()
This commit is contained in:
parent
686ae47696
commit
c7b0bdab7e
6 changed files with 62 additions and 4 deletions
|
@ -125,6 +125,7 @@ filenames = {
|
||||||
"shell/browser/animation_util.h",
|
"shell/browser/animation_util.h",
|
||||||
"shell/browser/animation_util_mac.mm",
|
"shell/browser/animation_util_mac.mm",
|
||||||
"shell/browser/api/electron_api_app_mac.mm",
|
"shell/browser/api/electron_api_app_mac.mm",
|
||||||
|
"shell/browser/api/electron_api_base_window_mac.mm",
|
||||||
"shell/browser/api/electron_api_menu_mac.h",
|
"shell/browser/api/electron_api_menu_mac.h",
|
||||||
"shell/browser/api/electron_api_menu_mac.mm",
|
"shell/browser/api/electron_api_menu_mac.mm",
|
||||||
"shell/browser/api/electron_api_native_theme_mac.mm",
|
"shell/browser/api/electron_api_native_theme_mac.mm",
|
||||||
|
|
|
@ -70,6 +70,7 @@ namespace electron::api {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
#if !BUILDFLAG(IS_MAC)
|
||||||
// Converts binary data to Buffer.
|
// Converts binary data to Buffer.
|
||||||
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||||
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
||||||
|
@ -78,6 +79,7 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||||
else
|
else
|
||||||
return buffer.ToLocalChecked();
|
return buffer.ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] constexpr std::array<int, 2U> ToArray(const gfx::Size size) {
|
[[nodiscard]] constexpr std::array<int, 2U> ToArray(const gfx::Size size) {
|
||||||
return {size.width(), size.height()};
|
return {size.width(), size.height()};
|
||||||
|
@ -778,6 +780,7 @@ std::string BaseWindow::GetMediaSourceId() const {
|
||||||
return window_->GetDesktopMediaID().ToString();
|
return window_->GetDesktopMediaID().ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !BUILDFLAG(IS_MAC)
|
||||||
v8::Local<v8::Value> BaseWindow::GetNativeWindowHandle() {
|
v8::Local<v8::Value> BaseWindow::GetNativeWindowHandle() {
|
||||||
// TODO(MarshallOfSound): Replace once
|
// TODO(MarshallOfSound): Replace once
|
||||||
// https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has
|
// https://chromium-review.googlesource.com/c/chromium/src/+/1253094/ has
|
||||||
|
@ -785,6 +788,7 @@ v8::Local<v8::Value> BaseWindow::GetNativeWindowHandle() {
|
||||||
NativeWindowHandle handle = window_->GetNativeWindowHandle();
|
NativeWindowHandle handle = window_->GetNativeWindowHandle();
|
||||||
return ToBuffer(isolate(), &handle, sizeof(handle));
|
return ToBuffer(isolate(), &handle, sizeof(handle));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void BaseWindow::SetProgressBar(double progress, gin_helper::Arguments* args) {
|
void BaseWindow::SetProgressBar(double progress, gin_helper::Arguments* args) {
|
||||||
gin_helper::Dictionary options;
|
gin_helper::Dictionary options;
|
||||||
|
|
32
shell/browser/api/electron_api_base_window_mac.mm
Normal file
32
shell/browser/api/electron_api_base_window_mac.mm
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright (c) 2025 Microsoft, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "shell/browser/api/electron_api_base_window.h"
|
||||||
|
|
||||||
|
#include "electron/buildflags/buildflags.h"
|
||||||
|
#include "shell/browser/api/electron_api_view.h"
|
||||||
|
#include "shell/browser/native_window.h"
|
||||||
|
#include "shell/common/node_includes.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Converts binary data to Buffer.
|
||||||
|
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||||
|
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
||||||
|
if (buffer.IsEmpty())
|
||||||
|
return v8::Null(isolate);
|
||||||
|
else
|
||||||
|
return buffer.ToLocalChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
namespace electron::api {
|
||||||
|
|
||||||
|
v8::Local<v8::Value> BaseWindow::GetNativeWindowHandle() {
|
||||||
|
NSView* handle = window_->GetNativeWindowHandle().GetNativeNSView();
|
||||||
|
return ToBuffer(isolate(), &handle, sizeof(handle));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace electron::api
|
|
@ -3743,15 +3743,17 @@ void WebContents::SetDevToolsWebContents(const WebContents* devtools) {
|
||||||
inspectable_web_contents_->SetDevToolsWebContents(devtools->web_contents());
|
inspectable_web_contents_->SetDevToolsWebContents(devtools->web_contents());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !BUILDFLAG(IS_MAC)
|
||||||
v8::Local<v8::Value> WebContents::GetNativeView(v8::Isolate* isolate) const {
|
v8::Local<v8::Value> WebContents::GetNativeView(v8::Isolate* isolate) const {
|
||||||
gfx::NativeView ptr = web_contents()->GetNativeView();
|
gfx::NativeView ptr = web_contents()->GetNativeView();
|
||||||
auto buffer = node::Buffer::Copy(isolate, reinterpret_cast<char*>(&ptr),
|
auto buffer =
|
||||||
sizeof(gfx::NativeView));
|
node::Buffer::Copy(isolate, reinterpret_cast<char*>(&ptr), sizeof(ptr));
|
||||||
if (buffer.IsEmpty())
|
if (buffer.IsEmpty())
|
||||||
return v8::Null(isolate);
|
return v8::Null(isolate);
|
||||||
else
|
else
|
||||||
return buffer.ToLocalChecked();
|
return buffer.ToLocalChecked();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
v8::Local<v8::Value> WebContents::DevToolsWebContents(v8::Isolate* isolate) {
|
v8::Local<v8::Value> WebContents::DevToolsWebContents(v8::Isolate* isolate) {
|
||||||
if (devtools_web_contents_.IsEmpty())
|
if (devtools_web_contents_.IsEmpty())
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "shell/browser/api/electron_api_web_contents.h"
|
#include "shell/browser/api/electron_api_web_contents.h"
|
||||||
#include "shell/browser/ui/cocoa/event_dispatching_window.h"
|
#include "shell/browser/ui/cocoa/event_dispatching_window.h"
|
||||||
#include "shell/browser/web_contents_preferences.h"
|
#include "shell/browser/web_contents_preferences.h"
|
||||||
|
#include "shell/common/node_includes.h"
|
||||||
#include "ui/base/cocoa/command_dispatcher.h"
|
#include "ui/base/cocoa/command_dispatcher.h"
|
||||||
#include "ui/base/cocoa/nsmenu_additions.h"
|
#include "ui/base/cocoa/nsmenu_additions.h"
|
||||||
#include "ui/base/cocoa/nsmenuitem_additions.h"
|
#include "ui/base/cocoa/nsmenuitem_additions.h"
|
||||||
|
@ -92,4 +93,22 @@ bool WebContents::PlatformHandleKeyboardEvent(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Converts binary data to Buffer.
|
||||||
|
v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
|
||||||
|
auto buffer = node::Buffer::Copy(isolate, static_cast<char*>(val), size);
|
||||||
|
if (buffer.IsEmpty())
|
||||||
|
return v8::Null(isolate);
|
||||||
|
else
|
||||||
|
return buffer.ToLocalChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
v8::Local<v8::Value> WebContents::GetNativeView(v8::Isolate* isolate) const {
|
||||||
|
NSView* handle = web_contents()->GetNativeView().GetNativeNSView();
|
||||||
|
return ToBuffer(isolate, &handle, sizeof(handle));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace electron::api
|
} // namespace electron::api
|
||||||
|
|
|
@ -58,9 +58,9 @@ class BrowserView;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if BUILDFLAG(IS_MAC)
|
#if BUILDFLAG(IS_MAC)
|
||||||
typedef gfx::NativeView NativeWindowHandle;
|
using NativeWindowHandle = gfx::NativeView;
|
||||||
#else
|
#else
|
||||||
typedef gfx::AcceleratedWidget NativeWindowHandle;
|
using NativeWindowHandle = gfx::AcceleratedWidget;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class NativeWindow : public base::SupportsUserData,
|
class NativeWindow : public base::SupportsUserData,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue