mirror of
https://github.com/RGBCube/serenity
synced 2025-06-30 05:32:07 +00:00
LibWeb: Forbid sharing image requests across documents
This change addresses the bug where images unable to load when the reload button in the UI is clicked repeatedly. Before this fix, it was possible to use SharedImageRequests across multiple documents. However, when the document that initiated the request is gone, tasks scheduled on the event loop remain in the fetching state because the originating document is no longer active. Furthermore, another reason to prohibit the sharing of image requests across documents is that the "Origin" header in an image request is dependent on the document.
This commit is contained in:
parent
c2eaa0eb1c
commit
8ebb4e8047
4 changed files with 24 additions and 12 deletions
|
@ -18,36 +18,36 @@
|
|||
|
||||
namespace Web::HTML {
|
||||
|
||||
static HashMap<AK::URL, SharedImageRequest*>& shared_image_requests()
|
||||
{
|
||||
static HashMap<AK::URL, SharedImageRequest*> requests;
|
||||
return requests;
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<SharedImageRequest> SharedImageRequest::get_or_create(JS::Realm& realm, Page& page, AK::URL const& url)
|
||||
{
|
||||
if (auto it = shared_image_requests().find(url); it != shared_image_requests().end())
|
||||
auto document = Bindings::host_defined_environment_settings_object(realm).responsible_document();
|
||||
VERIFY(document);
|
||||
auto& shared_image_requests = document->shared_image_requests();
|
||||
if (auto it = shared_image_requests.find(url); it != shared_image_requests.end())
|
||||
return *it->value;
|
||||
auto request = realm.heap().allocate<SharedImageRequest>(realm, page, url);
|
||||
shared_image_requests().set(url, request);
|
||||
auto request = realm.heap().allocate<SharedImageRequest>(realm, page, url, *document);
|
||||
shared_image_requests.set(url, request);
|
||||
return request;
|
||||
}
|
||||
|
||||
SharedImageRequest::SharedImageRequest(Page& page, AK::URL url)
|
||||
SharedImageRequest::SharedImageRequest(Page& page, AK::URL url, JS::NonnullGCPtr<DOM::Document> document)
|
||||
: m_page(page)
|
||||
, m_url(move(url))
|
||||
, m_document(document)
|
||||
{
|
||||
}
|
||||
|
||||
SharedImageRequest::~SharedImageRequest()
|
||||
{
|
||||
shared_image_requests().remove(m_url);
|
||||
auto& shared_image_requests = m_document->shared_image_requests();
|
||||
shared_image_requests.remove(m_url);
|
||||
}
|
||||
|
||||
void SharedImageRequest::visit_edges(JS::Cell::Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_fetch_controller);
|
||||
visitor.visit(m_document);
|
||||
for (auto& callback : m_callbacks) {
|
||||
visitor.visit(callback.on_finish);
|
||||
visitor.visit(callback.on_fail);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue