fix: explicitly call GetNativeNSView() on macOS (#46750)

* fix: explicitly call GetNativeNSView() on macOS

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* chore: move macOS impl to a .mm file

This is needed in order to access gfx::NativeView::GetNativeNSView()

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2025-04-24 09:53:53 -05:00 committed by GitHub
parent 2629b31c19
commit fc319e0ea3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 62 additions and 4 deletions

View file

@ -6,6 +6,7 @@
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/browser/ui/cocoa/event_dispatching_window.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/nsmenu_additions.h"
#include "ui/base/cocoa/nsmenuitem_additions.h"
@ -92,4 +93,22 @@ bool WebContents::PlatformHandleKeyboardEvent(
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