1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 16:05:06 +00:00

LibWeb: Update Location::replace() to use navigables

This commit is contained in:
Aliaksandr Kalenik 2023-08-22 18:49:28 +02:00 committed by Andreas Kling
parent acff244335
commit d45f2a4952
4 changed files with 15 additions and 16 deletions

View file

@ -372,11 +372,21 @@ void Location::reload() const
}
// https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
void Location::replace(String const& url) const
WebIDL::ExceptionOr<void> Location::replace(String const& url)
{
auto& window = verify_cast<HTML::Window>(HTML::current_global_object());
// FIXME: This needs spec compliance work.
window.did_call_location_replace({}, url.to_deprecated_string());
// 1. If this's relevant Document is null, then return.
if (!relevant_document())
return {};
// 2. Parse url relative to the entry settings object. If that failed, throw a "SyntaxError" DOMException.
auto replace_url = entry_settings_object().parse_url(url);
if (!replace_url.is_valid())
return WebIDL::SyntaxError::create(realm(), MUST(String::formatted("Invalid URL '{}'", url)));
// 3. Location-object navigate this to the resulting URL record given "replace".
TRY(navigate(replace_url, HistoryHandlingBehavior::Replace));
return {};
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-assign

View file

@ -49,7 +49,7 @@ public:
WebIDL::ExceptionOr<String> hash() const;
WebIDL::ExceptionOr<void> set_hash(String const&);
void replace(String const& url) const;
WebIDL::ExceptionOr<void> replace(String const& url);
void reload() const;
WebIDL::ExceptionOr<void> assign(String const& url);

View file

@ -421,15 +421,6 @@ WebIDL::ExceptionOr<JS::GCPtr<WindowProxy>> Window::open_impl(StringView url, St
return target_browsing_context->window_proxy();
}
void Window::did_call_location_replace(Badge<Location>, DeprecatedString url)
{
auto* browsing_context = associated_document().browsing_context();
if (!browsing_context)
return;
auto new_url = associated_document().parse_url(url);
browsing_context->loader().load(move(new_url), FrameLoader::Type::Navigation);
}
bool Window::dispatch_event(DOM::Event& event)
{
return DOM::EventDispatcher::dispatch(*this, event, true);

View file

@ -95,8 +95,6 @@ public:
WebIDL::ExceptionOr<JS::GCPtr<WindowProxy>> open_impl(StringView url, StringView target, StringView features);
bool has_animation_frame_callbacks() const { return m_animation_frame_callback_driver.has_callbacks(); }
void did_call_location_replace(Badge<Location>, DeprecatedString url);
DOM::Event* current_event() { return m_current_event.ptr(); }
DOM::Event const* current_event() const { return m_current_event.ptr(); }
void set_current_event(DOM::Event* event);