Truly independent web browser
LibWeb: Resolve a blob request's URL entry at fetch start
Luke Wilde782cc90bc5cb
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cppindex 1b6d157bafb..227e47afbfd 100644--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp@@ -308,6 +308,14 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:if (auto const* buffer = request.body().get_pointer<ByteBuffer>())request.set_body(Infrastructure::byte_sequence_as_body(realm, buffer->bytes()));+ // AD-HOC: The blob URL entry of request’s URL is resolved here, when the fetch starts, so that scheme fetch needs no+ // page. It is the entry of request’s current URL there, since no redirect leads to a blob URL.+ if (request.url().scheme() == "blob"sv) {+ auto& page = Bindings::principal_host_defined_page(realm);+ auto blob_url_entry = FileAPI::blob_url_entry_in_the_user_agent_store(page, request.url());+ fetch_params->set_blob_url_entry(move(blob_url_entry));+ }+auto* client_window = request.client() ? HTML::window_from_global_object(request.client()->global_object()) : nullptr;// 10. If all of the following conditions are true:@@ -1317,7 +1325,7 @@ GC::Ref<PendingResponse> scheme_fetch(JS::Realm& realm, Infrastructure::FetchPar// -> "blob"else if (request->current_url().scheme() == "blob"sv) {// 1. Let blobURLEntry be request’s current URL’s blob URL entry.- auto blob_url_entry = FileAPI::blob_url_entry_in_the_user_agent_store(Bindings::principal_host_defined_page(realm), request->current_url());+ auto const& blob_url_entry = fetch_params.blob_url_entry();// 2. If request’s method is not `GET` or blobURLEntry is null, then return a network error. [FILEAPI]if (request->method() != "GET"sv || !blob_url_entry.has_value())diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cppindex be358ef0d54..95f76a4710a 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.cpp@@ -31,6 +31,7 @@ FetchParams::FetchParams(FetchParams const& params), m_timing_info(params.m_timing_info), m_preloaded_response_candidate(params.m_preloaded_response_candidate), m_has_response_body_transfer_lease(params.m_has_response_body_transfer_lease)+ , m_blob_url_entry(params.m_blob_url_entry){}diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.hindex 614a8970031..386e94d889c 100644--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchParams.h@@ -16,6 +16,7 @@#include <LibWeb/Fetch/Infrastructure/FetchTimingInfo.h>#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>#include <LibWeb/Fetch/Infrastructure/Task.h>+#include <LibWebCommon/FileAPI/SerializedBlobURLEntry.h>namespace Web::Fetch::Infrastructure {@@ -59,6 +60,9 @@ public:[[nodiscard]] bool has_response_body_transfer_lease() const { return m_has_response_body_transfer_lease; }void set_has_response_body_transfer_lease(bool value) { m_has_response_body_transfer_lease = value; }+ [[nodiscard]] Optional<FileAPI::SerializedBlobURLEntry> const& blob_url_entry() const { return m_blob_url_entry; }+ void set_blob_url_entry(Optional<FileAPI::SerializedBlobURLEntry> blob_url_entry) { m_blob_url_entry = move(blob_url_entry); }+private:FetchParams(GC::Ref<Request>, GC::Ref<FetchAlgorithms const>, GC::Ref<FetchController>, NonnullRefPtr<FetchTimingInfo>);FetchParams(FetchParams const&);@@ -115,6 +119,9 @@ private:// Non-spec process integration: a navigation response is retained while the UI process selects its document host.bool m_has_response_body_transfer_lease { false };++ // The blob URL entry of the request's URL, when that is a blob: URL, as it was when the fetch started.+ Optional<FileAPI::SerializedBlobURLEntry> m_blob_url_entry;};}