1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 01:07:34 +00:00

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.
This commit is contained in:
Andreas Kling 2022-10-15 23:12:05 +02:00
parent 3c548adf9c
commit 24510b0845
2 changed files with 13 additions and 13 deletions

View file

@ -41,6 +41,7 @@
#include <LibWeb/HTML/Storage.h> #include <LibWeb/HTML/Storage.h>
#include <LibWeb/HTML/Timer.h> #include <LibWeb/HTML/Timer.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
#include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/HighResolutionTime/Performance.h> #include <LibWeb/HighResolutionTime/Performance.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h> #include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Layout/InitialContainingBlock.h> #include <LibWeb/Layout/InitialContainingBlock.h>
@ -554,10 +555,10 @@ JS::NonnullGCPtr<HTML::Storage> Window::session_storage()
} }
// https://html.spec.whatwg.org/multipage/browsers.html#dom-parent // 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. // 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. // 2. If current is null, then return null.
if (!current) if (!current)
@ -566,16 +567,14 @@ Window* Window::parent()
// 3. If current is a child browsing context of another browsing context parent, // 3. If current is a child browsing context of another browsing context parent,
// then return parent's WindowProxy object. // then return parent's WindowProxy object.
if (current->parent()) { if (current->parent()) {
VERIFY(current->parent()->active_document()); return current->parent()->window_proxy();
return &current->parent()->active_document()->window();
} }
// 4. Assert: current is a top-level browsing context. // 4. Assert: current is a top-level browsing context.
VERIFY(current->is_top_level()); VERIFY(current->is_top_level());
// FIXME: 5. Return current's WindowProxy object. // 5. Return current's WindowProxy object.
VERIFY(current->active_document()); return current->window_proxy();
return &current->active_document()->window();
} }
// https://html.spec.whatwg.org/multipage/web-messaging.html#window-post-message-steps // 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* impl = TRY(impl_from(vm));
auto* this_browsing_context = impl->associated_document().browsing_context(); // 1. If this Window object's browsing context is null, then return null.
if (!this_browsing_context) auto* browsing_context = impl->browsing_context();
if (!browsing_context)
return JS::js_null(); return JS::js_null();
VERIFY(this_browsing_context->top_level_browsing_context().active_document()); // 2. Return this Window object's browsing context's top-level browsing context's WindowProxy object.
auto& top_window = this_browsing_context->top_level_browsing_context().active_document()->window(); return browsing_context->top_level_browsing_context().window_proxy();
return &top_window;
} }
JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter) JS_DEFINE_NATIVE_FUNCTION(Window::parent_getter)

View file

@ -105,7 +105,8 @@ public:
JS::NonnullGCPtr<HTML::Storage> local_storage(); JS::NonnullGCPtr<HTML::Storage> local_storage();
JS::NonnullGCPtr<HTML::Storage> session_storage(); JS::NonnullGCPtr<HTML::Storage> session_storage();
Window* parent(); // https://html.spec.whatwg.org/multipage/browsers.html#dom-parent
WindowProxy* parent();
WebIDL::ExceptionOr<void> post_message_impl(JS::Value, String const& target_origin); WebIDL::ExceptionOr<void> post_message_impl(JS::Value, String const& target_origin);