diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 9e9281f547..9549165a75 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2023, Andreas Kling + * Copyright (c) 2018-2024, Andreas Kling * Copyright (c) 2021-2023, Linus Groh * Copyright (c) 2021-2023, Luke Wilde * Copyright (c) 2021-2023, Sam Atkins @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -2988,6 +2989,8 @@ void Document::run_unloading_cleanup_steps() // 2. Clear window's map of active timers. window->clear_map_of_active_timers(); } + + FileAPI::run_unloading_cleanup_steps(*this); } // https://html.spec.whatwg.org/multipage/document-lifecycle.html#destroy-a-document diff --git a/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp b/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp index 08e2adb9e7..fdc119592f 100644 --- a/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2023, Tim Flynn + * Copyright (c) 2024, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -89,4 +91,19 @@ ErrorOr remove_entry_from_blob_url_store(StringView url) return {}; } +// https://w3c.github.io/FileAPI/#lifeTime +void run_unloading_cleanup_steps(JS::NonnullGCPtr document) +{ + // 1. Let environment be the Document's relevant settings object. + auto& environment = document->relevant_settings_object(); + + // 2. Let store be the user agent’s blob URL store; + auto& store = FileAPI::blob_url_store(); + + // 3. Remove from store any entries for which the value's environment is equal to environment. + store.remove_all_matching([&](auto&, auto& value) { + return value.environment == &environment; + }); +} + } diff --git a/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.h b/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.h index 6e83cd076d..13f39c824c 100644 --- a/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.h +++ b/Userland/Libraries/LibWeb/FileAPI/BlobURLStore.h @@ -28,4 +28,6 @@ ErrorOr generate_new_blob_url(); ErrorOr add_entry_to_blob_url_store(JS::NonnullGCPtr object); ErrorOr remove_entry_from_blob_url_store(StringView url); +void run_unloading_cleanup_steps(JS::NonnullGCPtr); + }