From 53eb9af42fbbe9292d8fe3675b0b1403cef76e60 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sun, 5 May 2024 20:39:13 +1200 Subject: [PATCH] LibWeb: Use URL's 'blob URL entry' for blob fetches Performing a lookup in the blob URL registry does not work in the case of a web worker - as the registry is not shared between processes. However - the URL itself passed to a worker has the blob attached to it, which we can pull out of the URL on a fetch. --- Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index e95ea4b828..03cabdeea3 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -731,10 +731,8 @@ WebIDL::ExceptionOr> scheme_fetch(JS::Realm& r } // -> "blob" else if (request->current_url().scheme() == "blob"sv) { - auto const& store = FileAPI::blob_url_store(); - // 1. Let blobURLEntry be request’s current URL’s blob URL entry. - auto blob_url_entry = store.get(TRY_OR_THROW_OOM(vm, request->current_url().to_string())); + auto const& blob_url_entry = request->current_url().blob_url_entry(); // 2. If request’s method is not `GET`, blobURLEntry is null, or blobURLEntry’s object is not a Blob object, // then return a network error. [FILEAPI] @@ -745,7 +743,7 @@ WebIDL::ExceptionOr> scheme_fetch(JS::Realm& r } // 3. Let blob be blobURLEntry’s object. - auto const& blob = blob_url_entry->object; + auto const blob = FileAPI::Blob::create(realm, blob_url_entry.value().byte_buffer, blob_url_entry.value().type); // 4. Let response be a new response. auto response = Infrastructure::Response::create(vm); @@ -762,7 +760,7 @@ WebIDL::ExceptionOr> scheme_fetch(JS::Realm& r // 8. If request’s header list does not contain `Range`: if (!request->header_list()->contains("Range"sv.bytes())) { // 1. Let bodyWithType be the result of safely extracting blob. - auto body_with_type = TRY(safely_extract_body(realm, blob)); + auto body_with_type = TRY(safely_extract_body(realm, blob->bytes())); // 2. Set response’s status message to `OK`. response->set_status_message(MUST(ByteBuffer::copy("OK"sv.bytes())));