mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-05 18:02:54 +00:00
LibWeb: Make PolicyContainer GC allocated
This is required to store Content Security Policies, as their Directives are implemented as subclasses with overridden virtual functions. Thus, they cannot be stored as generic Directive classes, as it'll lose the ability to call overridden functions when they are copied.
This commit is contained in:
parent
2e27ffab6c
commit
cae0ab2139
Notes:
github-actions[bot]
2025-02-21 12:55:13 +00:00
Author: https://github.com/Lubrsi
Commit: cae0ab2139
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3627
Reviewed-by: https://github.com/AtkinsSJ ✅
43 changed files with 381 additions and 130 deletions
|
@ -1,12 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2025, Luke Wilde <luke@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibIPC/Forward.h>
|
||||
#include <LibGC/CellAllocator.h>
|
||||
#include <LibJS/Heap/Cell.h>
|
||||
#include <LibURL/Forward.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/HTML/EmbedderPolicy.h>
|
||||
#include <LibWeb/ReferrerPolicy/ReferrerPolicy.h>
|
||||
|
||||
|
@ -14,7 +18,13 @@ namespace Web::HTML {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/origin.html#policy-container
|
||||
// A policy container is a struct containing policies that apply to a Document, a WorkerGlobalScope, or a WorkletGlobalScope. It has the following items:
|
||||
struct PolicyContainer {
|
||||
struct PolicyContainer : public JS::Cell {
|
||||
GC_CELL(PolicyContainer, JS::Cell)
|
||||
GC_DECLARE_ALLOCATOR(PolicyContainer);
|
||||
|
||||
public:
|
||||
virtual ~PolicyContainer() = default;
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/origin.html#policy-container-csp-list
|
||||
// FIXME: A CSP list, which is a CSP list. It is initially empty.
|
||||
|
||||
|
@ -25,14 +35,17 @@ struct PolicyContainer {
|
|||
// https://html.spec.whatwg.org/multipage/origin.html#policy-container-referrer-policy
|
||||
// A referrer policy, which is a referrer policy. It is initially the default referrer policy.
|
||||
ReferrerPolicy::ReferrerPolicy referrer_policy { ReferrerPolicy::DEFAULT_REFERRER_POLICY };
|
||||
|
||||
[[nodiscard]] GC::Ref<PolicyContainer> clone(JS::Realm&) const;
|
||||
[[nodiscard]] SerializedPolicyContainer serialize() const;
|
||||
|
||||
private:
|
||||
PolicyContainer(JS::Realm&);
|
||||
};
|
||||
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/browsers.html#requires-storing-the-policy-container-in-history
|
||||
[[nodiscard]] bool url_requires_storing_the_policy_container_in_history(URL::URL const& url);
|
||||
|
||||
namespace IPC {
|
||||
template<>
|
||||
ErrorOr<void> encode(IPC::Encoder&, Web::HTML::PolicyContainer const&);
|
||||
[[nodiscard]] GC::Ref<PolicyContainer> create_a_policy_container_from_serialized_policy_container(JS::Realm&, SerializedPolicyContainer const&);
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::HTML::PolicyContainer> decode(IPC::Decoder&);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue