From c42496187be09634eac3a0568c4346e4f4793db7 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sun, 5 Mar 2023 20:21:35 +0000 Subject: [PATCH] LibWeb/HTML: Port Window.history to IDL --- Userland/Libraries/LibWeb/DOM/Document.cpp | 5 +++++ Userland/Libraries/LibWeb/DOM/Document.h | 2 ++ Userland/Libraries/LibWeb/Forward.h | 1 + Userland/Libraries/LibWeb/HTML/Window.cpp | 14 +++++++------- Userland/Libraries/LibWeb/HTML/Window.h | 3 +-- Userland/Libraries/LibWeb/HTML/Window.idl | 1 + 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 97700e6617..5b69601770 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -2068,6 +2068,11 @@ JS::NonnullGCPtr Document::history() return *m_history; } +JS::NonnullGCPtr Document::history() const +{ + return const_cast(this)->history(); +} + // https://html.spec.whatwg.org/multipage/origin.html#dom-document-domain DeprecatedString Document::domain() const { diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index ee287873a8..e2934bf1a3 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2022, Andreas Kling + * Copyright (c) 2021-2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -337,6 +338,7 @@ public: bool is_active() const; JS::NonnullGCPtr history(); + JS::NonnullGCPtr history() const; HTML::Location* location(); diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index fd68b197a6..200c2f61d6 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -249,6 +249,7 @@ class ErrorEvent; class EventHandler; class EventLoop; class FormDataEvent; +class History; class HTMLAnchorElement; class HTMLAreaElement; class HTMLAudioElement; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 561a9c35bf..2a75b43999 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1076,7 +1076,6 @@ WebIDL::ExceptionOr Window::initialize_web_interfaces(Badge Window::location() const return *m_location; } +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-history +JS::NonnullGCPtr Window::history() const +{ + // The history getter steps are to return this's associated Document's history object. + return associated_document().history(); +} + // https://html.spec.whatwg.org/multipage/window-object.html#dom-frames JS::NonnullGCPtr Window::frames() const { @@ -1825,12 +1831,6 @@ JS_DEFINE_NATIVE_FUNCTION(Window::scroll_by) return JS::js_undefined(); } -JS_DEFINE_NATIVE_FUNCTION(Window::history_getter) -{ - auto* impl = TRY(impl_from(vm)); - return impl->associated_document().history(); -} - JS_DEFINE_NATIVE_FUNCTION(Window::screen_left_getter) { auto* impl = TRY(impl_from(vm)); diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 31785872b2..ac7be95a4c 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -143,6 +143,7 @@ public: String name() const; void set_name(String const&); JS::NonnullGCPtr location() const; + JS::NonnullGCPtr history() const; JS::NonnullGCPtr frames() const; @@ -226,8 +227,6 @@ private: JS_DECLARE_NATIVE_FUNCTION(performance_getter); JS_DECLARE_NATIVE_FUNCTION(performance_setter); - JS_DECLARE_NATIVE_FUNCTION(history_getter); - JS_DECLARE_NATIVE_FUNCTION(screen_getter); JS_DECLARE_NATIVE_FUNCTION(screen_setter); diff --git a/Userland/Libraries/LibWeb/HTML/Window.idl b/Userland/Libraries/LibWeb/HTML/Window.idl index 0475c89d2d..8f0def8a5b 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.idl +++ b/Userland/Libraries/LibWeb/HTML/Window.idl @@ -12,6 +12,7 @@ interface Window : EventTarget { [LegacyUnforgeable] readonly attribute Document document; attribute DOMString name; [PutForwards=href, LegacyUnforgeable] readonly attribute Location location; + readonly attribute History history; // other browsing contexts [Replaceable] readonly attribute WindowProxy frames;