From 7cdbd59e9247ad28d7e1bf05ce2bff225d0eafc2 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 23 Sep 2023 23:04:24 +0200 Subject: [PATCH] LibWeb: Update session history when `History` entry is pushed/replaced With this change `shared_history_push_replace_state()` starts to actually add/replace session history entry. --- .../navigation/history-pushstate-iframe.txt | 0 .../expected/navigation/history-pushstate.txt | 1 + .../navigation/history-pushstate-iframe.html | 20 ++++++++++++++++ .../input/navigation/history-pushstate.html | 23 +++++++++++++++++++ Userland/Libraries/LibWeb/HTML/History.cpp | 17 +++++++------- Userland/Libraries/LibWeb/HTML/History.h | 7 ++---- 6 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/navigation/history-pushstate-iframe.txt create mode 100644 Tests/LibWeb/Text/expected/navigation/history-pushstate.txt create mode 100644 Tests/LibWeb/Text/input/navigation/history-pushstate-iframe.html create mode 100644 Tests/LibWeb/Text/input/navigation/history-pushstate.html diff --git a/Tests/LibWeb/Text/expected/navigation/history-pushstate-iframe.txt b/Tests/LibWeb/Text/expected/navigation/history-pushstate-iframe.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Tests/LibWeb/Text/expected/navigation/history-pushstate.txt b/Tests/LibWeb/Text/expected/navigation/history-pushstate.txt new file mode 100644 index 0000000000..e60fd8b747 --- /dev/null +++ b/Tests/LibWeb/Text/expected/navigation/history-pushstate.txt @@ -0,0 +1 @@ + history object length has changed by 1 \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/navigation/history-pushstate-iframe.html b/Tests/LibWeb/Text/input/navigation/history-pushstate-iframe.html new file mode 100644 index 0000000000..ae62b21d47 --- /dev/null +++ b/Tests/LibWeb/Text/input/navigation/history-pushstate-iframe.html @@ -0,0 +1,20 @@ + + diff --git a/Tests/LibWeb/Text/input/navigation/history-pushstate.html b/Tests/LibWeb/Text/input/navigation/history-pushstate.html new file mode 100644 index 0000000000..60a12d1654 --- /dev/null +++ b/Tests/LibWeb/Text/input/navigation/history-pushstate.html @@ -0,0 +1,23 @@ + + + diff --git a/Userland/Libraries/LibWeb/HTML/History.cpp b/Userland/Libraries/LibWeb/HTML/History.cpp index b221b746fa..ed38535464 100644 --- a/Userland/Libraries/LibWeb/HTML/History.cpp +++ b/Userland/Libraries/LibWeb/HTML/History.cpp @@ -38,17 +38,17 @@ void History::visit_edges(Cell::Visitor& visitor) } // https://html.spec.whatwg.org/multipage/history.html#dom-history-pushstate +// The pushState(data, unused, url) method steps are to run the shared history push/replace state steps given this, data, url, and "push". WebIDL::ExceptionOr History::push_state(JS::Value data, String const&, Optional const& url) { - // NOTE: The second parameter of this function is intentionally unused. - return shared_history_push_replace_state(data, url, IsPush::Yes); + return shared_history_push_replace_state(data, url, HistoryHandlingBehavior::Push); } // https://html.spec.whatwg.org/multipage/history.html#dom-history-replacestate +// The replaceState(data, unused, url) method steps are to run the shared history push/replace state steps given this, data, url, and "replace". WebIDL::ExceptionOr History::replace_state(JS::Value data, String const&, Optional const& url) { - // NOTE: The second parameter of this function is intentionally unused. - return shared_history_push_replace_state(data, url, IsPush::No); + return shared_history_push_replace_state(data, url, HistoryHandlingBehavior::Replace); } // https://html.spec.whatwg.org/multipage/history.html#dom-history-length @@ -145,7 +145,7 @@ bool can_have_its_url_rewritten(DOM::Document const& document, AK::URL const& ta } // https://html.spec.whatwg.org/multipage/history.html#shared-history-push/replace-state-steps -WebIDL::ExceptionOr History::shared_history_push_replace_state(JS::Value value, Optional const& url, IsPush) +WebIDL::ExceptionOr History::shared_history_push_replace_state(JS::Value value, Optional const& url, HistoryHandlingBehavior history_handling) { // 1. Let document be history's associated Document. auto& document = m_associated_document; @@ -188,10 +188,11 @@ WebIDL::ExceptionOr History::shared_history_push_replace_state(JS::Value v /// with navigationType set to historyHandling, isSameDocument set to true, destinationURL set to newURL, // and classicHistoryAPIState set to serializedData. // FIXME: 9. If continue is false, then return. - // FIXME: 10. Run the URL and history update steps given document and newURL, with serializedData set to - // serializedData and historyHandling set to historyHandling. - dbgln("FIXME: Implement shared_history_push_replace_state."); + // 10. Run the URL and history update steps given document and newURL, with serializedData set to + // serializedData and historyHandling set to historyHandling. + perform_url_and_history_update_steps(document, new_url, history_handling); + return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/History.h b/Userland/Libraries/LibWeb/HTML/History.h index 481ac94f30..699f64e4ec 100644 --- a/Userland/Libraries/LibWeb/HTML/History.h +++ b/Userland/Libraries/LibWeb/HTML/History.h @@ -8,6 +8,7 @@ #pragma once #include +#include #include namespace Web::HTML { @@ -36,11 +37,7 @@ private: virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; - enum class IsPush { - No, - Yes, - }; - WebIDL::ExceptionOr shared_history_push_replace_state(JS::Value data, Optional const& url, IsPush is_push); + WebIDL::ExceptionOr shared_history_push_replace_state(JS::Value data, Optional const& url, HistoryHandlingBehavior); JS::NonnullGCPtr m_associated_document; };