mirror of
https://github.com/electron/electron.git
synced 2026-02-19 03:14:51 -05:00
refactor: simplify NativeWindow-to-BaseWindow lookup (#49520)
refactor: simplify native window to base window lookup
This commit is contained in:
@@ -111,8 +111,8 @@ BaseWindow::BaseWindow(v8::Isolate* isolate,
|
||||
}
|
||||
|
||||
// Creates NativeWindow.
|
||||
window_ = NativeWindow::Create(
|
||||
options, parent.IsEmpty() ? nullptr : parent->window_.get());
|
||||
NativeWindow* parent_native = parent.IsEmpty() ? nullptr : parent->window();
|
||||
window_ = NativeWindow::Create(GetID(), options, parent_native);
|
||||
window_->AddObserver(this);
|
||||
|
||||
SetContentView(View::Create(isolate));
|
||||
@@ -146,7 +146,6 @@ BaseWindow::~BaseWindow() {
|
||||
}
|
||||
|
||||
void BaseWindow::InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) {
|
||||
AttachAsUserData(window_.get());
|
||||
gin_helper::TrackableObject<BaseWindow>::InitWith(isolate, wrapper);
|
||||
|
||||
// We can only append this window to parent window's child windows after this
|
||||
|
||||
@@ -336,11 +336,12 @@ void BrowserWindow::BuildPrototype(v8::Isolate* isolate,
|
||||
// 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);
|
||||
if (native_window != nullptr) {
|
||||
if (auto* base = FromWeakMapID(isolate, native_window->base_window_id()))
|
||||
return base->GetWrapper();
|
||||
}
|
||||
|
||||
return v8::Null(isolate);
|
||||
}
|
||||
|
||||
} // namespace electron::api
|
||||
|
||||
Reference in New Issue
Block a user