diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 066e8ff2c2..e581ea0700 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1050,7 +1050,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge Window::parent() const return navigable->window_proxy(); } +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-frameelement +JS::GCPtr Window::frame_element() const +{ + // 1. Let current be this's node navigable. + auto* current = browsing_context(); + + // 2. If current is null, then return null. + if (!current) + return {}; + + // 3. Let container be current's container. + auto* container = current->container(); + + // 4. If container is null, then return null. + if (!container) + return {}; + + // 5. If container's node document's origin is not same origin-domain with the current settings object's origin, then return null. + if (!container->document().origin().is_same_origin_domain(current_settings_object().origin())) + return {}; + + // 6. Return container. + return container; +} + // https://html.spec.whatwg.org/multipage/system-state.html#dom-navigator JS::NonnullGCPtr Window::navigator() const { @@ -1553,33 +1577,6 @@ size_t Window::document_tree_child_browsing_context_count() const return this_browsing_context->document_tree_child_browsing_context_count(); } -// https://html.spec.whatwg.org/multipage/browsers.html#dom-frameelement -JS_DEFINE_NATIVE_FUNCTION(Window::frame_element_getter) -{ - auto* impl = TRY(impl_from(vm)); - - // 1. Let current be this Window object's browsing context. - auto* current = impl->browsing_context(); - - // 2. If current is null, then return null. - if (!current) - return JS::js_null(); - - // 3. Let container be current's container. - auto* container = current->container(); - - // 4. If container is null, then return null. - if (!container) - return JS::js_null(); - - // 5. If container's node document's origin is not same origin-domain with the current settings object's origin, then return null. - if (!container->document().origin().is_same_origin(current_settings_object().origin())) - return JS::js_null(); - - // 6. Return container. - return container; -} - JS_DEFINE_NATIVE_FUNCTION(Window::performance_getter) { auto* impl = TRY(impl_from(vm)); diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 7b58ed8d05..c338175bd0 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -146,6 +146,7 @@ public: u32 length() const; JS::GCPtr top() const; JS::GCPtr parent() const; + JS::GCPtr frame_element() const; JS::NonnullGCPtr navigator() const; @@ -217,8 +218,6 @@ public: CrossOriginPropertyDescriptorMap& cross_origin_property_descriptor_map() { return m_cross_origin_property_descriptor_map; } private: - JS_DECLARE_NATIVE_FUNCTION(frame_element_getter); - JS_DECLARE_NATIVE_FUNCTION(location_setter); JS_DECLARE_NATIVE_FUNCTION(performance_getter); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 209ba19789..f05044c0d6 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -19,6 +19,7 @@ interface Window : EventTarget { [Replaceable] readonly attribute unsigned long length; [LegacyUnforgeable] readonly attribute WindowProxy? top; [Replaceable] readonly attribute WindowProxy? parent; + readonly attribute Element? frameElement; // the user agent readonly attribute Navigator navigator;