1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:48:11 +00:00

LibWeb/HTML: Port Window.frameElement to IDL

This commit is contained in:
Linus Groh 2023-03-05 21:33:30 +00:00
parent c6353ac8cd
commit efa48142d2
3 changed files with 27 additions and 30 deletions

View file

@ -1050,7 +1050,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
// FIXME: These should be native accessors, not properties
define_native_accessor(realm, "frameElement", frame_element_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "performance", performance_getter, performance_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_accessor(realm, "crypto", crypto_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "screen", screen_getter, screen_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
@ -1256,6 +1255,31 @@ JS::GCPtr<WindowProxy const> Window::parent() const
return navigable->window_proxy();
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-frameelement
JS::GCPtr<DOM::Element const> 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<Navigator> 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));