浏览代码

LibWeb/HTML: Port Window.frameElement to IDL

Linus Groh 2 年之前
父节点
当前提交
efa48142d2

+ 25 - 28
Userland/Libraries/LibWeb/HTML/Window.cpp

@@ -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));

+ 1 - 2
Userland/Libraries/LibWeb/HTML/Window.h

@@ -146,6 +146,7 @@ public:
     u32 length() const;
     JS::GCPtr<WindowProxy const> top() const;
     JS::GCPtr<WindowProxy const> parent() const;
+    JS::GCPtr<DOM::Element const> frame_element() const;
 
     JS::NonnullGCPtr<Navigator> 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);

+ 1 - 0
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;