diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index cb6d30caff..1b680335b0 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -106,6 +107,7 @@ void Window::visit_edges(JS::Cell::Visitor& visitor) visitor.visit(m_location); visitor.visit(m_crypto); visitor.visit(m_navigator); + visitor.visit(m_navigation); visitor.visit(m_custom_element_registry); for (auto& plugin_object : m_pdf_viewer_plugin_objects) visitor.visit(plugin_object); @@ -1410,6 +1412,20 @@ JS::NonnullGCPtr Window::crypto() return JS::NonnullGCPtr { *m_crypto }; } +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-navigation +JS::NonnullGCPtr Window::navigation() +{ + // Upon creation of the Window object, its navigation API must be set + // to a new Navigation object created in the Window object's relevant realm. + if (!m_navigation) { + auto& realm = relevant_realm(*this); + m_navigation = heap().allocate(realm, realm); + } + + // The navigation getter steps are to return this's navigation API. + return *m_navigation; +} + // https://html.spec.whatwg.org/multipage/custom-elements.html#dom-window-customelements JS::NonnullGCPtr Window::custom_elements() { diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index dcdbf161f0..1513238e4b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -136,6 +136,7 @@ public: void set_name(String const&); [[nodiscard]] JS::NonnullGCPtr location(); JS::NonnullGCPtr history() const; + JS::NonnullGCPtr navigation(); void focus(); JS::NonnullGCPtr frames() const; @@ -226,6 +227,9 @@ private: JS::GCPtr m_navigator; JS::GCPtr m_location; + // https://html.spec.whatwg.org/multipage/nav-history-apis.html#window-navigation-api + JS::GCPtr m_navigation; + // https://html.spec.whatwg.org/multipage/custom-elements.html#custom-elements-api // Each Window object is associated with a unique instance of a CustomElementRegistry object, allocated when the Window object is created. JS::GCPtr m_custom_element_registry; diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 4d7549cb7d..5fad9dd00b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -8,6 +8,7 @@ #import #import #import +#import #import #import #import @@ -24,6 +25,7 @@ interface Window : EventTarget { attribute DOMString name; [PutForwards=href, LegacyUnforgeable] readonly attribute Location location; readonly attribute History history; + readonly attribute Navigation navigation; readonly attribute CustomElementRegistry customElements; undefined focus();