Skip to content

Commit

Permalink
LibWeb: Update Navigable::navigate() to the current state of the spec
Browse files Browse the repository at this point in the history
A few parameters and step renumberings have happened since we first
implemented this algorithm.
  • Loading branch information
ADKaster authored and kalenikaliaksandr committed Aug 29, 2023
1 parent cf1f14f commit 6cfe19e
Show file tree
Hide file tree
Showing 3 changed files with 293 additions and 111 deletions.
15 changes: 14 additions & 1 deletion Userland/Libraries/LibWeb/HTML/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <LibWeb/DOM/Document.h>
#include <LibWeb/HTML/CrossOrigin/AbstractOperations.h>
#include <LibWeb/HTML/Location.h>
#include <LibWeb/HTML/Navigation.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/WebIDL/DOMException.h>

Expand Down Expand Up @@ -58,6 +59,18 @@ JS::GCPtr<DOM::Document> Location::relevant_document() const
return browsing_context ? browsing_context->active_document() : nullptr;
}

static Bindings::NavigationHistoryBehavior to_navigation_history_behavior(HistoryHandlingBehavior b)
{
switch (b) {
case HistoryHandlingBehavior::Push:
return Bindings::NavigationHistoryBehavior::Push;
case HistoryHandlingBehavior::Replace:
return Bindings::NavigationHistoryBehavior::Replace;
default:
return Bindings::NavigationHistoryBehavior::Auto;
}
}

// https://html.spec.whatwg.org/multipage/nav-history-apis.html#location-object-navigate
WebIDL::ExceptionOr<void> Location::navigate(AK::URL url, HistoryHandlingBehavior history_handling)
{
Expand All @@ -73,7 +86,7 @@ WebIDL::ExceptionOr<void> Location::navigate(AK::URL url, HistoryHandlingBehavio
}

// 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));
TRY(navigable->navigate(url, source_document, {}, nullptr, true, to_navigation_history_behavior(history_handling)));

return {};
}
Expand Down
Loading

0 comments on commit 6cfe19e

Please sign in to comment.