Truly independent web browser
LibWeb+WebWorker: Serialize a stand-in with the global it was taken from
Luke Wilde2668ecca245a
diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cppindex 42aa55c1b1d..abaceef0013 100644--- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp+++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp@@ -23,6 +23,7 @@#include <LibWeb/HTML/DedicatedWorkerGlobalScope.h>#include <LibWeb/HTML/PolicyContainers.h>#include <LibWeb/HTML/Scripting/Agent.h>+#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>#include <LibWeb/HTML/Scripting/Environments.h>#include <LibWeb/HTML/Scripting/ExceptionReporter.h>#include <LibWeb/HTML/Scripting/WindowEnvironmentSettingsObject.h>@@ -707,6 +708,8 @@ bool is_non_secure_context(Environment const& environment)SerializedEnvironmentSettingsObject EnvironmentSettingsObject::serialize(){auto serialized_global = [this]() -> SerializedGlobal {+ if (auto const* snapshot = as_if<EnvironmentSettingsSnapshot>(*this))+ return snapshot->serialized_global();bool relevant_settings_object_is_secure_context = is_secure_context(*this);auto relevant_settings_object_policy_container = policy_container()->serialize();auto& global = global_object();diff --git a/Services/WebWorker/WorkerHost.cpp b/Services/WebWorker/WorkerHost.cppindex f508bf9d6c9..47f89381f94 100644--- a/Services/WebWorker/WorkerHost.cpp+++ b/Services/WebWorker/WorkerHost.cpp@@ -123,14 +123,6 @@ void WorkerHost::run(GC::Ref<Web::Page> page, Web::HTML::TransferDataEncoder mes// IMPLEMENTATION DEFINED: We need an object to represent the fetch response's clientauto outside_settings = GC::Heap::the().allocate<Web::HTML::EnvironmentSettingsSnapshot>(inside_settings->realm_execution_context().copy(), outside_settings_snapshot);- // HACK: The environment settings object used for the worker script fetch should have a Window as its global scope,- // but the EnvironmentSettingsSnapshot used here has a WorkerGlobalScope (we don't have access to a Window).- // This causes the Referrer-Policy spec's "determine request's referrer" algorithm to read the ESO's creation- // URL, whereas it would normally read the document's URL. To hack around this, we overwrite the creation URL- // (which is only used in the initial worker script fetch).- if (auto const* window = outside_settings_snapshot.global.get_pointer<Web::HTML::SerializedWindow>())- outside_settings->creation_url = window->associated_document.url;-// AD-HOC: Outside settings' global object is in the owner's process, so the violations of its policies, such as by// the worker script fetch, are reported to the owner.outside_settings->set_report_violation(GC::create_function(GC::Heap::the(), [page](u64 policy_index, String effective_directive, URL::URL resource) {