mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 21:05:07 +00:00
LibWeb: Update Location::replace()
to use navigables
This commit is contained in:
parent
acff244335
commit
d45f2a4952
4 changed files with 15 additions and 16 deletions
|
@ -372,11 +372,21 @@ void Location::reload() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/history.html#dom-location-replace
|
// 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());
|
// 1. If this's relevant Document is null, then return.
|
||||||
// FIXME: This needs spec compliance work.
|
if (!relevant_document())
|
||||||
window.did_call_location_replace({}, url.to_deprecated_string());
|
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
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-assign
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
WebIDL::ExceptionOr<String> hash() const;
|
WebIDL::ExceptionOr<String> hash() const;
|
||||||
WebIDL::ExceptionOr<void> set_hash(String const&);
|
WebIDL::ExceptionOr<void> set_hash(String const&);
|
||||||
|
|
||||||
void replace(String const& url) const;
|
WebIDL::ExceptionOr<void> replace(String const& url);
|
||||||
void reload() const;
|
void reload() const;
|
||||||
WebIDL::ExceptionOr<void> assign(String const& url);
|
WebIDL::ExceptionOr<void> assign(String const& url);
|
||||||
|
|
||||||
|
|
|
@ -421,15 +421,6 @@ WebIDL::ExceptionOr<JS::GCPtr<WindowProxy>> Window::open_impl(StringView url, St
|
||||||
return target_browsing_context->window_proxy();
|
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)
|
bool Window::dispatch_event(DOM::Event& event)
|
||||||
{
|
{
|
||||||
return DOM::EventDispatcher::dispatch(*this, event, true);
|
return DOM::EventDispatcher::dispatch(*this, event, true);
|
||||||
|
|
|
@ -95,8 +95,6 @@ public:
|
||||||
WebIDL::ExceptionOr<JS::GCPtr<WindowProxy>> open_impl(StringView url, StringView target, StringView features);
|
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(); }
|
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* current_event() { return m_current_event.ptr(); }
|
||||||
DOM::Event const* current_event() const { return m_current_event.ptr(); }
|
DOM::Event const* current_event() const { return m_current_event.ptr(); }
|
||||||
void set_current_event(DOM::Event* event);
|
void set_current_event(DOM::Event* event);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue