From 24510b0845e50891d70c38c7c0f7270d11913616 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 15 Oct 2022 23:12:05 +0200 Subject: [PATCH] LibWeb: Make window.parent and window.top return WindowProxy These functions were previously ad-hoc and returned the active document's window. They now correctly teturn the browsing context's WindowProxy instead. --- Userland/Libraries/LibWeb/HTML/Window.cpp | 23 +++++++++++------------ Userland/Libraries/LibWeb/HTML/Window.h | 3 ++- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 181116d7b59..088bb284c3a 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -554,10 +555,10 @@ JS::NonnullGCPtr Window::session_storage() } // https://html.spec.whatwg.org/multipage/browsers.html#dom-parent -Window* Window::parent() +WindowProxy* Window::parent() { // 1. Let current be this Window object's browsing context. - auto* current = associated_document().browsing_context(); + auto* current = browsing_context(); // 2. If current is null, then return null. if (!current) @@ -566,16 +567,14 @@ Window* Window::parent() // 3. If current is a child browsing context of another browsing context parent, // then return parent's WindowProxy object. if (current->parent()) { - VERIFY(current->parent()->active_document()); - return ¤t->parent()->active_document()->window(); + return current->parent()->window_proxy(); } // 4. Assert: current is a top-level browsing context. VERIFY(current->is_top_level()); - // FIXME: 5. Return current's WindowProxy object. - VERIFY(current->active_document()); - return ¤t->active_document()->window(); + // 5. Return current's WindowProxy object. + return current->window_proxy(); } // https://html.spec.whatwg.org/multipage/web-messaging.html#window-post-message-steps @@ -1098,13 +1097,13 @@ JS_DEFINE_NATIVE_FUNCTION(Window::top_getter) { auto* impl = TRY(impl_from(vm)); - auto* this_browsing_context = impl->associated_document().browsing_context(); - if (!this_browsing_context) + // 1. If this Window object's browsing context is null, then return null. + auto* browsing_context = impl->browsing_context(); + if (!browsing_context) return JS::js_null(); - VERIFY(this_browsing_context->top_level_browsing_context().active_document()); - auto& top_window = this_browsing_context->top_level_browsing_context().active_document()->window(); - return &top_window; + // 2. Return this Window object's browsing context's top-level browsing context's WindowProxy object. + return browsing_context->top_level_browsing_context().window_proxy(); } JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter) diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index cda069cac45..ddc70c09c08 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -105,7 +105,8 @@ public: JS::NonnullGCPtr local_storage(); JS::NonnullGCPtr session_storage(); - Window* parent(); + // https://html.spec.whatwg.org/multipage/browsers.html#dom-parent + WindowProxy* parent(); WebIDL::ExceptionOr post_message_impl(JS::Value, String const& target_origin);