2022-07-12 20:42:19 +01:00
/*
* Copyright ( c ) 2022 , Linus Groh < linusg @ serenityos . org >
2024-11-25 14:30:12 +00:00
* Copyright ( c ) 2025 , Luke Wilde < luke @ ladybird . org >
2022-07-12 20:42:19 +01:00
*
* SPDX - License - Identifier : BSD - 2 - Clause
*/
# pragma once
2024-11-25 14:30:12 +00:00
# include <LibGC/CellAllocator.h>
# include <LibJS/Heap/Cell.h>
# include <LibURL/Forward.h>
2025-08-07 22:41:54 +02:00
# include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
2024-11-25 14:30:12 +00:00
# include <LibWeb/Forward.h>
2024-07-08 22:54:49 +01:00
# include <LibWeb/HTML/EmbedderPolicy.h>
2022-10-13 18:23:10 +02:00
# include <LibWeb/ReferrerPolicy/ReferrerPolicy.h>
2022-07-12 20:42:19 +01:00
namespace Web : : HTML {
2025-08-07 22:41:54 +02:00
// https://w3c.github.io/webappsec-subresource-integrity/#integrity-policy
struct IntegrityPolicy {
Vector < String > sources ;
Vector < Fetch : : Infrastructure : : Request : : Destination > blocked_destinations ;
Vector < String > endpoints ;
bool is_empty ( ) const { return sources . is_empty ( ) & & blocked_destinations . is_empty ( ) & & endpoints . is_empty ( ) ; }
} ;
2022-07-12 20:42:19 +01:00
// 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:
2025-04-26 11:35:51 +12:00
struct PolicyContainer : public GC : : Cell {
GC_CELL ( PolicyContainer , GC : : Cell )
2024-11-25 14:30:12 +00:00
GC_DECLARE_ALLOCATOR ( PolicyContainer ) ;
public :
virtual ~ PolicyContainer ( ) = default ;
2022-07-12 20:42:19 +01:00
// https://html.spec.whatwg.org/multipage/origin.html#policy-container-csp-list
2024-11-25 16:17:17 +00:00
// A CSP list, which is a CSP list. It is initially empty.
GC : : Ref < ContentSecurityPolicy : : PolicyList > csp_list ;
2022-07-12 20:42:19 +01:00
// https://html.spec.whatwg.org/multipage/origin.html#policy-container-embedder-policy
2024-07-08 22:54:49 +01:00
// An embedder policy, which is an embedder policy. It is initially a new embedder policy.
EmbedderPolicy embedder_policy { } ;
2022-07-12 20:42:19 +01:00
// https://html.spec.whatwg.org/multipage/origin.html#policy-container-referrer-policy
2022-10-13 18:23:10 +02:00
// A referrer policy, which is a referrer policy. It is initially the default referrer policy.
ReferrerPolicy : : ReferrerPolicy referrer_policy { ReferrerPolicy : : DEFAULT_REFERRER_POLICY } ;
2024-11-25 14:30:12 +00:00
2025-08-07 22:41:54 +02:00
// https://html.spec.whatwg.org/multipage/browsers.html#policy-container-integrity-policy
// An integrity policy, which is an integrity policy, initially a new integrity policy.
IntegrityPolicy integrity_policy { } ;
// https://html.spec.whatwg.org/multipage/browsers.html#policy-container-report-only-integrity-policy
// A report only integrity policy, which is an integrity policy, initially a new integrity policy.
IntegrityPolicy report_only_integrity_policy { } ;
2025-04-26 11:35:51 +12:00
[ [ nodiscard ] ] GC : : Ref < PolicyContainer > clone ( GC : : Heap & ) const ;
2024-11-25 14:30:12 +00:00
[ [ nodiscard ] ] SerializedPolicyContainer serialize ( ) const ;
2024-11-25 16:17:17 +00:00
protected :
virtual void visit_edges ( Cell : : Visitor & ) override ;
2024-11-25 14:30:12 +00:00
private :
2025-04-26 11:35:51 +12:00
PolicyContainer ( GC : : Heap & ) ;
2022-07-12 20:42:19 +01:00
} ;
2024-11-25 14:30:12 +00:00
// 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 ) ;
2024-03-05 09:29:14 -07:00
2024-11-25 17:01:26 +00:00
// https://html.spec.whatwg.org/multipage/browsers.html#creating-a-policy-container-from-a-fetch-response
2025-04-26 11:35:51 +12:00
[ [ nodiscard ] ] GC : : Ref < PolicyContainer > create_a_policy_container_from_a_fetch_response ( GC : : Heap & , GC : : Ref < Fetch : : Infrastructure : : Response const > response , GC : : Ptr < Environment > environment ) ;
2024-11-25 17:01:26 +00:00
2025-04-26 11:35:51 +12:00
[ [ nodiscard ] ] GC : : Ref < PolicyContainer > create_a_policy_container_from_serialized_policy_container ( GC : : Heap & , SerializedPolicyContainer const & ) ;
2024-03-05 09:29:14 -07:00
}