1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:47:35 +00:00

LibWeb: Ensure a Web::Page is associated with local Worker LoadRequests

This is a hack on top of a hack because Workers don't *really* need to
have a Web::Page at all, but the ResourceLoader infra that should be
going away soon ™️ is not quite ready to axe that requirement for
cookies.
This commit is contained in:
Andrew Kaster 2023-11-09 18:09:21 -07:00 committed by Andreas Kling
parent 5586340cf3
commit d7d84ee931
2 changed files with 6 additions and 1 deletions

View file

@ -36,6 +36,7 @@
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HTML/WorkerGlobalScope.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Loader/LoadRequest.h>
#include <LibWeb/Loader/ResourceLoader.h>
@ -1728,6 +1729,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> nonstandard_resource_load
auto& global_object = realm.global_object();
if (is<HTML::Window>(global_object))
page = static_cast<HTML::Window&>(global_object).page();
else if (is<HTML::WorkerGlobalScope>(global_object))
page = static_cast<HTML::WorkerGlobalScope&>(global_object).page();
// NOTE: Using LoadRequest::create_for_url_on_page here will unconditionally add cookies as long as there's a page available.
// However, it is up to http_network_or_cache_fetch to determine if cookies should be added to the request.

View file

@ -234,8 +234,10 @@ void ResourceLoader::load(LoadRequest& request, SuccessCallback success_callback
if (request.page().has_value())
m_page = request.page().value();
if (!m_page.has_value())
if (!m_page.has_value()) {
log_failure(request, "INTERNAL ERROR: No Page for request");
return;
}
FileRequest file_request(url.serialize_path(), [this, success_callback = move(success_callback), error_callback = move(error_callback), log_success, log_failure, request](ErrorOr<i32> file_or_error) {
--m_pending_loads;