fix: nullptr check when closing windows (#22948)
This commit is contained in:
parent
a7469f82ac
commit
54f8c4e6a3
1 changed files with 25 additions and 7 deletions
|
@ -10,6 +10,18 @@
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
#include "shell/browser/window_list_observer.h"
|
#include "shell/browser/window_list_observer.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
template <typename T>
|
||||||
|
std::vector<base::WeakPtr<T>> ConvertToWeakPtrVector(std::vector<T*> raw_ptrs) {
|
||||||
|
std::vector<base::WeakPtr<T>> converted_to_weak;
|
||||||
|
converted_to_weak.reserve(raw_ptrs.size());
|
||||||
|
for (auto* raw_ptr : raw_ptrs) {
|
||||||
|
converted_to_weak.push_back(raw_ptr->GetWeakPtr());
|
||||||
|
}
|
||||||
|
return converted_to_weak;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -80,20 +92,26 @@ void WindowList::RemoveObserver(WindowListObserver* observer) {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void WindowList::CloseAllWindows() {
|
void WindowList::CloseAllWindows() {
|
||||||
WindowVector windows = GetInstance()->windows_;
|
std::vector<base::WeakPtr<NativeWindow>> weak_windows =
|
||||||
|
ConvertToWeakPtrVector(GetInstance()->windows_);
|
||||||
#if defined(OS_MACOSX)
|
#if defined(OS_MACOSX)
|
||||||
std::reverse(windows.begin(), windows.end());
|
std::reverse(weak_windows.begin(), weak_windows.end());
|
||||||
#endif
|
#endif
|
||||||
for (auto* const& window : windows)
|
for (const auto& window : weak_windows) {
|
||||||
if (!window->IsClosed())
|
if (window && !window->IsClosed())
|
||||||
window->Close();
|
window->Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
void WindowList::DestroyAllWindows() {
|
void WindowList::DestroyAllWindows() {
|
||||||
WindowVector windows = GetInstance()->windows_;
|
std::vector<base::WeakPtr<NativeWindow>> weak_windows =
|
||||||
for (auto* const& window : windows)
|
ConvertToWeakPtrVector(GetInstance()->windows_);
|
||||||
window->CloseImmediately(); // e.g. Destroy()
|
|
||||||
|
for (const auto& window : weak_windows) {
|
||||||
|
if (window)
|
||||||
|
window->CloseImmediately();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WindowList::WindowList() = default;
|
WindowList::WindowList() = default;
|
||||||
|
|
Loading…
Reference in a new issue