Make sure we append parent->child_windows after InitWith

This commit is contained in:
Cheng Zhao 2018-04-17 16:18:55 +09:00
parent c090dd2f81
commit cfed9fa4b9
2 changed files with 18 additions and 7 deletions

View file

@ -99,13 +99,6 @@ TopLevelWindow::TopLevelWindow(v8::Isolate* isolate,
if (options.Get(options::kIcon, &icon) && !icon.IsEmpty()) if (options.Get(options::kIcon, &icon) && !icon.IsEmpty())
SetIcon(icon); SetIcon(icon);
#endif #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() { TopLevelWindow::~TopLevelWindow() {
@ -117,6 +110,21 @@ TopLevelWindow::~TopLevelWindow() {
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release()); base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, window_.release());
} }
void TopLevelWindow::InitWith(v8::Isolate* isolate,
v8::Local<v8::Object> wrapper) {
AttachAsUserData(window_.get());
mate::TrackableObject<TopLevelWindow>::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<TopLevelWindow> parent;
mate::ConvertFromV8(isolate, GetParentWindow(), &parent);
DCHECK(!parent.IsEmpty());
parent->child_windows_.Set(isolate, weak_map_id(), wrapper);
}
}
void TopLevelWindow::WillCloseWindow(bool* prevent_default) { void TopLevelWindow::WillCloseWindow(bool* prevent_default) {
*prevent_default = Emit("close"); *prevent_default = Emit("close");
} }

View file

@ -40,6 +40,9 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
const mate::Dictionary& options); const mate::Dictionary& options);
~TopLevelWindow() override; ~TopLevelWindow() override;
// TrackableObject:
void InitWith(v8::Isolate* isolate, v8::Local<v8::Object> wrapper) override;
// NativeWindowObserver: // NativeWindowObserver:
void WillCloseWindow(bool* prevent_default) override; void WillCloseWindow(bool* prevent_default) override;
void OnWindowClosed() override; void OnWindowClosed() override;