Skip to content

Truly independent web browser

LibWeb: Keep the blob URL store per agent

Andreas Klingbf1c38dc6638
diff --git a/Libraries/LibWeb/FileAPI/BlobURLStore.cpp b/Libraries/LibWeb/FileAPI/BlobURLStore.cpp
index 51fa5583eac..ae07f8119a2 100644
--- a/Libraries/LibWeb/FileAPI/BlobURLStore.cpp
+++ b/Libraries/LibWeb/FileAPI/BlobURLStore.cpp
@@ -6,7 +6,6 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <AK/NeverDestroyed.h>
#include <AK/Utf16StringBuilder.h>
#include <LibGC/ConservativeHashMap.h>
#include <LibURL/Origin.h>
@@ -24,12 +23,21 @@
namespace Web::FileAPI {
// https://w3c.github.io/FileAPI/#BlobURLStore
-// NB: Only the entries this process created. The browser process keeps every process's entries, and is asked for
-// them by blob_url_entry_in_the_user_agent_store().
+// NB: Only the entries this agent created, in its own heap. The browser process keeps every agent's entries, and is
+// asked for them by blob_url_entry_in_the_user_agent_store().
+static thread_local GC::ConservativeHashMap<Utf16String, BlobURLEntry>* s_blob_url_store;
+
static GC::ConservativeHashMap<Utf16String, BlobURLEntry>& blob_url_store()
{
- static NeverDestroyed<GC::ConservativeHashMap<Utf16String, BlobURLEntry>> store;
- return *store;
+ if (!s_blob_url_store)
+ s_blob_url_store = new GC::ConservativeHashMap<Utf16String, BlobURLEntry>;
+ return *s_blob_url_store;
+}
+
+void forget_blob_url_store_of_this_agent()
+{
+ delete s_blob_url_store;
+ s_blob_url_store = nullptr;
}
// The entry as the user agent's blob URL store has it: a Blob's bytes in shared memory, and the environment's origin.
diff --git a/Libraries/LibWeb/FileAPI/BlobURLStore.h b/Libraries/LibWeb/FileAPI/BlobURLStore.h
index caae5128abf..2715c828c40 100644
--- a/Libraries/LibWeb/FileAPI/BlobURLStore.h
+++ b/Libraries/LibWeb/FileAPI/BlobURLStore.h
@@ -40,6 +40,9 @@ Optional<BlobURLEntry const&> local_blob_url_entry(URL::URL const&);
void run_unloading_cleanup_steps(GC::Ref<DOM::Document>);
+// The store is tied to the heap of the agent that goes away.
+void forget_blob_url_store_of_this_agent();
+
// The steps of run_unloading_cleanup_steps() after the first, which a worker that closes runs for its own environment.
WEB_API void remove_entries_of_environment(HTML::EnvironmentSettingsObject&, Page&);