From 6f68a40430a7d34b6d695a8b0d3520649c4f4105 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:20:09 -0500 Subject: [PATCH] refactor: `NativeWindow::Create()` returns a unique_ptr (#43607) 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 91030ed49194..f67923ef1a17 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -98,8 +98,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 51d0c3303ac7..ffa971dc7f2c 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -71,8 +71,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 625ffcf61271..6ac5805750cf 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1814,9 +1814,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 2e43d44d7b64..03b644df144b 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -1789,9 +1789,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