diff --git a/Userland/Libraries/LibWeb/HTML/Location.cpp b/Userland/Libraries/LibWeb/HTML/Location.cpp index 3f0cec88433..714b69414a7 100644 --- a/Userland/Libraries/LibWeb/HTML/Location.cpp +++ b/Userland/Libraries/LibWeb/HTML/Location.cpp @@ -58,6 +58,26 @@ JS::GCPtr Location::relevant_document() const return browsing_context ? browsing_context->active_document() : nullptr; } +// https://html.spec.whatwg.org/multipage/nav-history-apis.html#location-object-navigate +WebIDL::ExceptionOr Location::navigate(AK::URL url, HistoryHandlingBehavior history_handling) +{ + // 1. Let navigable be location's relevant global object's navigable. + auto navigable = verify_cast(HTML::relevant_global_object(*this)).navigable(); + + // 2. Let sourceDocument be the incumbent global object's associated Document. + auto& source_document = verify_cast(incumbent_global_object()).associated_document(); + + // 3. If location's relevant Document is not yet completely loaded, and the incumbent global object does not have transient activation, then set historyHandling to "replace". + if (!relevant_document()->is_completely_loaded() && !verify_cast(incumbent_global_object()).has_transient_activation()) { + history_handling = HistoryHandlingBehavior::Replace; + } + + // 4. Navigate navigable to url using sourceDocument, with exceptionsEnabled set to true and historyHandling set to historyHandling. + TRY(navigable->navigate(url, source_document, {}, nullptr, true, history_handling)); + + return {}; +} + // https://html.spec.whatwg.org/multipage/history.html#concept-location-url AK::URL Location::url() const { diff --git a/Userland/Libraries/LibWeb/HTML/Location.h b/Userland/Libraries/LibWeb/HTML/Location.h index 0704997f198..7e13983b373 100644 --- a/Userland/Libraries/LibWeb/HTML/Location.h +++ b/Userland/Libraries/LibWeb/HTML/Location.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace Web::HTML { @@ -74,6 +75,7 @@ private: JS::GCPtr relevant_document() const; AK::URL url() const; + WebIDL::ExceptionOr navigate(AK::URL, HistoryHandlingBehavior = HistoryHandlingBehavior::Default); // [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap HTML::CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map;