From dd36a0c12dbcf5fe6e5da7544192312af6a1ba09 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 1 Aug 2023 18:35:04 -0400 Subject: [PATCH] LibWeb: Implement extracting the origin of a blob URL --- Userland/Libraries/LibWeb/URL/URL.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/URL/URL.cpp b/Userland/Libraries/LibWeb/URL/URL.cpp index 74577e7879..076e1ad87f 100644 --- a/Userland/Libraries/LibWeb/URL/URL.cpp +++ b/Userland/Libraries/LibWeb/URL/URL.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace Web::URL { @@ -455,7 +456,24 @@ HTML::Origin url_origin(AK::URL const& url) // 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 + auto url_string = url.to_string().release_value_but_fixme_should_propagate_errors(); + + // 1. If url’s blob URL entry is non-null, then return url’s blob URL entry’s environment’s origin. + if (auto blob_url_entry = FileAPI::blob_url_store().get(url_string); blob_url_entry.has_value()) + return blob_url_entry->environment->origin(); + + // 2. Let pathURL be the result of parsing the result of URL path serializing url. + auto path_url = parse(url.serialize_path()); + + // 3. If pathURL is failure, then return a new opaque origin. + if (!path_url.is_valid()) + return HTML::Origin {}; + + // 4. If pathURL’s scheme is "http", "https", or "file", then return pathURL’s origin. + if (path_url.scheme().is_one_of("http"sv, "https"sv, "file"sv)) + return url_origin(path_url); + + // 5. Return a new opaque origin. return HTML::Origin {}; }