summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2022-10-13 18:25:00 +0200
committerLinus Groh <mail@linusgroh.de>2022-10-24 22:58:37 +0100
commitc380d2cfdc1709407b77b1854517c47cbac3a137 (patch)
tree22a29374ed7c0e0a09fddf9a6a18b862d7d3c40d
parent93405b4affb141ef97231d26f1f0991c8978efe3 (diff)
downloadserenity-c380d2cfdc1709407b77b1854517c47cbac3a137.zip
LibWeb: Move url_origin() to URL/URL.{cpp,h}
-rw-r--r--Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp27
-rw-r--r--Userland/Libraries/LibWeb/URL/URL.cpp33
-rw-r--r--Userland/Libraries/LibWeb/URL/URL.h2
3 files changed, 37 insertions, 25 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
index c713467031..05c070d5d2 100644
--- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
+++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp
@@ -25,6 +25,7 @@
#include <LibWeb/Layout/InitialContainingBlock.h>
#include <LibWeb/Layout/TextNode.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/URL/URL.h>
namespace Web::HTML {
@@ -39,30 +40,6 @@ static bool url_matches_about_blank(AK::URL const& url)
&& url.host().is_null();
}
-// https://url.spec.whatwg.org/#concept-url-origin
-static HTML::Origin url_origin(AK::URL const& url)
-{
- // FIXME: Move this whole function somewhere better.
-
- if (url.scheme() == "blob"sv) {
- // FIXME: Implement
- return HTML::Origin {};
- }
-
- if (url.scheme().is_one_of("ftp"sv, "http"sv, "https"sv, "ws"sv, "wss"sv)) {
- // Return the tuple origin (url’s scheme, url’s host, url’s port, null).
- return HTML::Origin(url.scheme(), url.host(), url.port().value_or(0));
- }
-
- if (url.scheme() == "file"sv) {
- // Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
- // Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages.
- return HTML::Origin(url.scheme(), String(), 0);
- }
-
- return HTML::Origin {};
-}
-
// https://html.spec.whatwg.org/multipage/browsers.html#determining-the-origin
HTML::Origin determine_the_origin(BrowsingContext const& browsing_context, Optional<AK::URL> url, SandboxingFlagSet sandbox_flags, Optional<HTML::Origin> invocation_origin)
{
@@ -88,7 +65,7 @@ HTML::Origin determine_the_origin(BrowsingContext const& browsing_context, Optio
}
// 5. Return url's origin.
- return url_origin(*url);
+ return URL::url_origin(*url);
}
// https://html.spec.whatwg.org/multipage/browsers.html#creating-a-new-top-level-browsing-context
diff --git a/Userland/Libraries/LibWeb/URL/URL.cpp b/Userland/Libraries/LibWeb/URL/URL.cpp
index 8f742edb63..62f9210f26 100644
--- a/Userland/Libraries/LibWeb/URL/URL.cpp
+++ b/Userland/Libraries/LibWeb/URL/URL.cpp
@@ -307,4 +307,37 @@ void URL::set_hash(String const& hash)
m_url = move(result_url);
}
+// https://url.spec.whatwg.org/#concept-url-origin
+HTML::Origin url_origin(AK::URL const& url)
+{
+ // FIXME: We should probably have an extended version of AK::URL for LibWeb instead of standalone functions like this.
+
+ // The origin of a URL url is the origin returned by running these steps, switching on url’s scheme:
+ // "blob"
+ if (url.scheme() == "blob"sv) {
+ // FIXME: Support 'blob://' URLs
+ return HTML::Origin {};
+ }
+
+ // "ftp"
+ // "http"
+ // "https"
+ // "ws"
+ // "wss"
+ if (url.scheme().is_one_of("ftp"sv, "http"sv, "https"sv, "ws"sv, "wss"sv)) {
+ // Return the tuple origin (url’s scheme, url’s host, url’s port, null).
+ return HTML::Origin(url.scheme(), url.host(), url.port().value_or(0));
+ }
+
+ // "file"
+ if (url.scheme() == "file"sv) {
+ // Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
+ // Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages.
+ return HTML::Origin(url.scheme(), String(), 0);
+ }
+
+ // Return a new opaque origin.
+ return HTML::Origin {};
+}
+
}
diff --git a/Userland/Libraries/LibWeb/URL/URL.h b/Userland/Libraries/LibWeb/URL/URL.h
index 015480d841..44d5add4fd 100644
--- a/Userland/Libraries/LibWeb/URL/URL.h
+++ b/Userland/Libraries/LibWeb/URL/URL.h
@@ -71,4 +71,6 @@ private:
JS::NonnullGCPtr<URLSearchParams> m_query;
};
+HTML::Origin url_origin(AK::URL const&);
+
}