diff options
author | Linus Groh <mail@linusgroh.de> | 2022-03-05 00:17:47 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-05 10:24:53 +0100 |
commit | 7fb9f431eab6d59583c19c32e4dbb540ad094d56 (patch) | |
tree | 16af68e5cba44b3bdf2856f2403607b4e48a7ba3 /Userland/Libraries/LibWeb/Bindings | |
parent | da8525279e5a86c60451aa7c66ca5fd9eea43702 (diff) | |
download | serenity-7fb9f431eab6d59583c19c32e4dbb540ad094d56.zip |
LibWeb: Add LocationObject::url()
https://html.spec.whatwg.org/multipage/history.html#concept-location-url
> A Location object has an associated url, which is this Location
> object's relevant Document's URL, if this Location object's relevant
> Document is non-null, and about:blank otherwise.
Diffstat (limited to 'Userland/Libraries/LibWeb/Bindings')
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/LocationObject.cpp | 9 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Bindings/LocationObject.h | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index 7f08327e5e..8e32bef5e8 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -56,6 +56,15 @@ DOM::Document const* LocationObject::relevant_document() const return browsing_context ? browsing_context->active_document() : nullptr; } +// https://html.spec.whatwg.org/multipage/history.html#concept-location-url +AK::URL LocationObject::url() const +{ + // A Location object has an associated url, which is this Location object's relevant Document's URL, + // if this Location object's relevant Document is non-null, and about:blank otherwise. + auto const* relevant_document = this->relevant_document(); + return relevant_document ? relevant_document->url() : "about:blank"sv; +} + // https://html.spec.whatwg.org/multipage/history.html#dom-location-href JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter) { diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.h b/Userland/Libraries/LibWeb/Bindings/LocationObject.h index 9f7282d942..18a16e1a8d 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.h +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.h @@ -7,6 +7,7 @@ #pragma once +#include <AK/URL.h> #include <LibJS/Runtime/Completion.h> #include <LibJS/Runtime/Object.h> #include <LibWeb/Forward.h> @@ -31,6 +32,7 @@ public: private: DOM::Document const* relevant_document() const; + AK::URL url() const; JS_DECLARE_NATIVE_FUNCTION(reload); JS_DECLARE_NATIVE_FUNCTION(replace); |