From cfed9fa4b9d2476075e9af11afeb9ae02d30d5d3 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 17 Apr 2018 16:18:55 +0900 Subject: [PATCH] Make sure we append parent->child_windows after InitWith --- atom/browser/api/atom_api_top_level_window.cc | 22 +++++++++++++------ atom/browser/api/atom_api_top_level_window.h | 3 +++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/atom_api_top_level_window.cc b/atom/browser/api/atom_api_top_level_window.cc index 735835c87ccf..dd0c06af2c90 100644 --- a/atom/browser/api/atom_api_top_level_window.cc +++ b/atom/browser/api/atom_api_top_level_window.cc @@ -99,13 +99,6 @@ TopLevelWindow::TopLevelWindow(v8::Isolate* isolate, if (options.Get(options::kIcon, &icon) && !icon.IsEmpty()) SetIcon(icon); #endif - - AttachAsUserData(window_.get()); - - // We can only append this window to parent window's child windows after this - // window's JS wrapper gets initialized. - if (!parent.IsEmpty()) - parent->child_windows_.Set(isolate, weak_map_id(), wrapper); } TopLevelWindow::~TopLevelWindow() { @@ -117,6 +110,21 @@ TopLevelWindow::~TopLevelWindow() { base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release()); } +void TopLevelWindow::InitWith(v8::Isolate* isolate, + v8::Local wrapper) { + AttachAsUserData(window_.get()); + mate::TrackableObject::InitWith(isolate, wrapper); + + // We can only append this window to parent window's child windows after this + // window's JS wrapper gets initialized. + if (!parent_window_.IsEmpty()) { + mate::Handle parent; + mate::ConvertFromV8(isolate, GetParentWindow(), &parent); + DCHECK(!parent.IsEmpty()); + parent->child_windows_.Set(isolate, weak_map_id(), wrapper); + } +} + void TopLevelWindow::WillCloseWindow(bool* prevent_default) { *prevent_default = Emit("close"); } diff --git a/atom/browser/api/atom_api_top_level_window.h b/atom/browser/api/atom_api_top_level_window.h index ef140f6e8b27..6082735a8c59 100644 --- a/atom/browser/api/atom_api_top_level_window.h +++ b/atom/browser/api/atom_api_top_level_window.h @@ -40,6 +40,9 @@ class TopLevelWindow : public mate::TrackableObject, const mate::Dictionary& options); ~TopLevelWindow() override; + // TrackableObject: + void InitWith(v8::Isolate* isolate, v8::Local wrapper) override; + // NativeWindowObserver: void WillCloseWindow(bool* prevent_default) override; void OnWindowClosed() override;