From acff24433528380b683bb9900ddde30d3249be39 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 22 Aug 2023 18:33:20 +0200 Subject: [PATCH] LibWeb: Use `navigate()` instead of `did_set_location_href` in Location --- Userland/Libraries/LibWeb/HTML/Location.cpp | 13 ++++++------- Userland/Libraries/LibWeb/HTML/Location.h | 2 +- Userland/Libraries/LibWeb/HTML/Window.cpp | 8 -------- Userland/Libraries/LibWeb/HTML/Window.h | 1 - 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/Userland/Libraries/LibWeb/HTML/Location.cpp b/Userland/Libraries/LibWeb/HTML/Location.cpp index c1f000ea60..a181fa59fb 100644 --- a/Userland/Libraries/LibWeb/HTML/Location.cpp +++ b/Userland/Libraries/LibWeb/HTML/Location.cpp @@ -131,7 +131,7 @@ WebIDL::ExceptionOr Location::set_href(String const& new_href) return vm.throw_completion(TRY_OR_THROW_OOM(vm, String::formatted("Invalid URL '{}'", new_href))); // 3. Location-object navigate given the resulting URL record. - window.did_set_location_href({}, href_url); + TRY(navigate(href_url)); return {}; } @@ -350,8 +350,7 @@ WebIDL::ExceptionOr Location::set_hash(String const& value) return {}; // 8. Location-object navigate this to copyURL. - auto& window = verify_cast(HTML::current_global_object()); - window.did_set_location_href({}, copy_url); + TRY(navigate(copy_url)); return {}; } @@ -365,7 +364,7 @@ void Location::reload() const // 2. If document is null, then return. if (!document) return; - + // FIXME: 3. If document's origin is not same origin-domain with the entry settings object's origin, then throw a "SecurityError" DOMException. // 4. Reload document's node navigable. @@ -381,7 +380,7 @@ void Location::replace(String const& url) const } // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-location-assign -WebIDL::ExceptionOr Location::assign(String const& url) const +WebIDL::ExceptionOr Location::assign(String const& url) { // 1. If this's relevant Document is null, then return. auto const relevant_document = this->relevant_document(); @@ -398,8 +397,8 @@ WebIDL::ExceptionOr Location::assign(String const& url) const return WebIDL::SyntaxError::create(realm(), MUST(String::formatted("Invalid URL '{}'", url))); // 4. Location-object navigate this to the resulting URL record. - auto& window = verify_cast(HTML::current_global_object()); - window.did_set_location_href({}, assign_url); + TRY(navigate(assign_url)); + return {}; } diff --git a/Userland/Libraries/LibWeb/HTML/Location.h b/Userland/Libraries/LibWeb/HTML/Location.h index 7e13983b37..909e650ab0 100644 --- a/Userland/Libraries/LibWeb/HTML/Location.h +++ b/Userland/Libraries/LibWeb/HTML/Location.h @@ -51,7 +51,7 @@ public: void replace(String const& url) const; void reload() const; - WebIDL::ExceptionOr assign(String const& url) const; + WebIDL::ExceptionOr assign(String const& url); virtual JS::ThrowCompletionOr internal_get_prototype_of() const override; virtual JS::ThrowCompletionOr internal_set_prototype_of(Object* prototype) override; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 21c38ee51e..03e04311f3 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -421,14 +421,6 @@ WebIDL::ExceptionOr> Window::open_impl(StringView url, St return target_browsing_context->window_proxy(); } -void Window::did_set_location_href(Badge, AK::URL const& new_href) -{ - auto* browsing_context = associated_document().browsing_context(); - if (!browsing_context) - return; - browsing_context->loader().load(new_href, FrameLoader::Type::Navigation); -} - void Window::did_call_location_replace(Badge, DeprecatedString url) { auto* browsing_context = associated_document().browsing_context(); diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index eeb05500fd..efde39c587 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -95,7 +95,6 @@ public: WebIDL::ExceptionOr> open_impl(StringView url, StringView target, StringView features); bool has_animation_frame_callbacks() const { return m_animation_frame_callback_driver.has_callbacks(); } - void did_set_location_href(Badge, AK::URL const& new_href); void did_call_location_replace(Badge, DeprecatedString url); DOM::Event* current_event() { return m_current_event.ptr(); }