From 5c424edcca5bb893c48c0876bd35a45dd4243945 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:19:50 -0500 Subject: [PATCH] refactor: `NativeWindow::Create()` returns a unique_ptr (#43605) refactor: NativeWindow::Create() returns a unique_ptr Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/api/electron_api_base_window.cc | 4 ++-- shell/browser/native_window.h | 5 +++-- shell/browser/native_window_mac.mm | 7 ++++--- shell/browser/native_window_views.cc | 7 ++++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index 1882c211fe82..ab2214bfa694 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -96,8 +96,8 @@ BaseWindow::BaseWindow(v8::Isolate* isolate, } // Creates NativeWindow. - window_.reset(NativeWindow::Create( - options, parent.IsEmpty() ? nullptr : parent->window_.get())); + window_ = NativeWindow::Create( + options, parent.IsEmpty() ? nullptr : parent->window_.get()); window_->AddObserver(this); SetContentView(View::Create(isolate)); diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index c563fac6fed4..43ff73e774c0 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -72,8 +72,9 @@ class NativeWindow : public base::SupportsUserData, // Create window with existing WebContents, the caller is responsible for // managing the window's live. - static NativeWindow* Create(const gin_helper::Dictionary& options, - NativeWindow* parent = nullptr); + static std::unique_ptr Create( + const gin_helper::Dictionary& options, + NativeWindow* parent = nullptr); void InitFromOptions(const gin_helper::Dictionary& options); diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index 774c2d8f2be4..a7ec8a2bfef3 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1805,9 +1805,10 @@ std::optional NativeWindowMac::GetWindowControlsOverlayRect() { } // static -NativeWindow* NativeWindow::Create(const gin_helper::Dictionary& options, - NativeWindow* parent) { - return new NativeWindowMac(options, parent); +std::unique_ptr NativeWindow::Create( + const gin_helper::Dictionary& options, + NativeWindow* parent) { + return std::make_unique(options, parent); } } // namespace electron diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index 8428c1013d09..e74bc7ec0c66 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1787,9 +1787,10 @@ void NativeWindowViews::MoveBehindTaskBarIfNeeded() { } // static -NativeWindow* NativeWindow::Create(const gin_helper::Dictionary& options, - NativeWindow* parent) { - return new NativeWindowViews(options, parent); +std::unique_ptr NativeWindow::Create( + const gin_helper::Dictionary& options, + NativeWindow* parent) { + return std::make_unique(options, parent); } } // namespace electron