diff --git a/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp b/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp index fdc119592fb..4abf8d57fc3 100644 --- a/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp @@ -1,6 +1,7 @@ /* * Copyright (c) 2023, Tim Flynn * Copyright (c) 2024, Andreas Kling + * Copyright (c) 2024, Shannon Booth * * SPDX-License-Identifier: BSD-2-Clause */ @@ -106,4 +107,20 @@ void run_unloading_cleanup_steps(JS::NonnullGCPtr document) }); } +// https://w3c.github.io/FileAPI/#blob-url-resolve +Optional resolve_a_blob_url(URL::URL const& url) +{ + // 1. Assert: url’s scheme is "blob". + VERIFY(url.scheme() == "blob"sv); + + // 2. Let store be the user agent’s blob URL store. + auto& store = blob_url_store(); + + // 3. Let url string be the result of serializing url with the exclude fragment flag set. + auto url_string = MUST(String::from_byte_string(url.serialize(URL::ExcludeFragment::Yes))); + + // 4. If store[url string] exists, return store[url string]; otherwise return failure. + return store.get(url_string); +} + } diff --git a/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.h b/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.h index 13f39c824c2..7e3664e20f5 100644 --- a/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.h +++ b/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.h @@ -10,6 +10,7 @@ #include #include #include +#include #include namespace Web::FileAPI { @@ -27,6 +28,7 @@ BlobURLStore& blob_url_store(); ErrorOr generate_new_blob_url(); ErrorOr add_entry_to_blob_url_store(JS::NonnullGCPtr object); ErrorOr remove_entry_from_blob_url_store(StringView url); +Optional resolve_a_blob_url(URL::URL const&); void run_unloading_cleanup_steps(JS::NonnullGCPtr);