LibWeb: Implement navigate() for Location object

This commit is contained in:
Aliaksandr Kalenik 2023-08-22 18:12:10 +02:00 committed by Andreas Kling
parent 5f21285337
commit 43da0701fc
Notes: sideshowbarker 2024-07-17 02:06:40 +09:00
2 changed files with 22 additions and 0 deletions

View file

@ -58,6 +58,26 @@ JS::GCPtr<DOM::Document> Location::relevant_document() const
return browsing_context ? browsing_context->active_document() : nullptr; return browsing_context ? browsing_context->active_document() : nullptr;
} }
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#location-object-navigate
WebIDL::ExceptionOr<void> Location::navigate(AK::URL url, HistoryHandlingBehavior history_handling)
{
// 1. Let navigable be location's relevant global object's navigable.
auto navigable = verify_cast<HTML::Window>(HTML::relevant_global_object(*this)).navigable();
// 2. Let sourceDocument be the incumbent global object's associated Document.
auto& source_document = verify_cast<HTML::Window>(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<HTML::Window>(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 // https://html.spec.whatwg.org/multipage/history.html#concept-location-url
AK::URL Location::url() const AK::URL Location::url() const
{ {

View file

@ -13,6 +13,7 @@
#include <LibWeb/Bindings/PlatformObject.h> #include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h> #include <LibWeb/Forward.h>
#include <LibWeb/HTML/CrossOrigin/CrossOriginPropertyDescriptorMap.h> #include <LibWeb/HTML/CrossOrigin/CrossOriginPropertyDescriptorMap.h>
#include <LibWeb/HTML/HistoryHandlingBehavior.h>
namespace Web::HTML { namespace Web::HTML {
@ -74,6 +75,7 @@ private:
JS::GCPtr<DOM::Document> relevant_document() const; JS::GCPtr<DOM::Document> relevant_document() const;
AK::URL url() const; AK::URL url() const;
WebIDL::ExceptionOr<void> navigate(AK::URL, HistoryHandlingBehavior = HistoryHandlingBehavior::Default);
// [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap // [[CrossOriginPropertyDescriptorMap]], https://html.spec.whatwg.org/multipage/browsers.html#crossoriginpropertydescriptormap
HTML::CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map; HTML::CrossOriginPropertyDescriptorMap m_cross_origin_property_descriptor_map;