LibWeb: Add TrustedTypePolicy class

It is mostly a skeleton with no actual implementation.
This commit is contained in:
Tete17 2025-07-31 02:03:29 +02:00 committed by Luke Wilde
commit 90bcc16a7b
Notes: github-actions[bot] 2025-08-11 11:23:39 +00:00
8 changed files with 85 additions and 0 deletions

View file

@ -897,6 +897,7 @@ set(SOURCES
SVG/TagNames.cpp SVG/TagNames.cpp
SVG/ViewBox.cpp SVG/ViewBox.cpp
TrustedTypes/TrustedHTML.cpp TrustedTypes/TrustedHTML.cpp
TrustedTypes/TrustedTypePolicy.cpp
TrustedTypes/TrustedTypePolicyFactory.cpp TrustedTypes/TrustedTypePolicyFactory.cpp
UIEvents/CompositionEvent.cpp UIEvents/CompositionEvent.cpp
UIEvents/EventNames.cpp UIEvents/EventNames.cpp

View file

@ -1221,6 +1221,8 @@ ErrorOr<Web::UniqueNodeID> decode(Decoder&);
namespace Web::TrustedTypes { namespace Web::TrustedTypes {
class TrustedHTML; class TrustedHTML;
class TrustedTypePolicy;
class TrustedTypePolicyFactory; class TrustedTypePolicyFactory;
struct TrustedTypePolicyOptions;
} }

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2025, Miguel Sacristán Izcue <miguel_tete17@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/TrustedTypes/TrustedTypePolicy.h>
#include <LibGC/Ptr.h>
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/Bindings/Intrinsics.h>
namespace Web::TrustedTypes {
GC_DEFINE_ALLOCATOR(TrustedTypePolicy);
TrustedTypePolicy::TrustedTypePolicy(JS::Realm& realm)
: PlatformObject(realm)
{
}
void TrustedTypePolicy::initialize(JS::Realm& realm)
{
WEB_SET_PROTOTYPE_FOR_INTERFACE(TrustedTypePolicy);
Base::initialize(realm);
}
}

View file

@ -0,0 +1,33 @@
/*
* Copyright (c) 2025, Miguel Sacristán Izcue <miguel_tete17@hotmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Forward.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Bindings/TrustedTypePolicyPrototype.h>
namespace Web::TrustedTypes {
struct TrustedTypePolicyOptions {
GC::Root<WebIDL::CallbackType> create_html;
GC::Root<WebIDL::CallbackType> create_script;
GC::Root<WebIDL::CallbackType> create_script_url;
};
class TrustedTypePolicy final : public Bindings::PlatformObject {
WEB_PLATFORM_OBJECT(TrustedTypePolicy, Bindings::PlatformObject);
GC_DECLARE_ALLOCATOR(TrustedTypePolicy);
public:
virtual ~TrustedTypePolicy() override = default;
private:
explicit TrustedTypePolicy(JS::Realm&);
virtual void initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,18 @@
// https://w3c.github.io/trusted-types/dist/spec/#trusted-type-policy
[Exposed=(Window,Worker)]
interface TrustedTypePolicy {
[FIXME] readonly attribute DOMString name;
[FIXME] TrustedHTML createHTML(DOMString input, any... arguments);
[FIXME] TrustedScript createScript(DOMString input, any... arguments);
[FIXME] TrustedScriptURL createScriptURL(DOMString input, any... arguments);
};
// https://w3c.github.io/trusted-types/dist/spec/#trusted-type-policy-options
dictionary TrustedTypePolicyOptions {
CreateHTMLCallback createHTML;
CreateScriptCallback createScript;
CreateScriptURLCallback createScriptURL;
};
callback CreateHTMLCallback = DOMString? (DOMString input, any... arguments);
callback CreateScriptCallback = DOMString? (DOMString input, any... arguments);
callback CreateScriptURLCallback = USVString? (DOMString input, any... arguments);

View file

@ -329,6 +329,7 @@ libweb_js_bindings(Streams/WritableStream)
libweb_js_bindings(Streams/WritableStreamDefaultController) libweb_js_bindings(Streams/WritableStreamDefaultController)
libweb_js_bindings(Streams/WritableStreamDefaultWriter) libweb_js_bindings(Streams/WritableStreamDefaultWriter)
libweb_js_bindings(TrustedTypes/TrustedHTML) libweb_js_bindings(TrustedTypes/TrustedHTML)
libweb_js_bindings(TrustedTypes/TrustedTypePolicy)
libweb_js_bindings(TrustedTypes/TrustedTypePolicyFactory) libweb_js_bindings(TrustedTypes/TrustedTypePolicyFactory)
libweb_js_bindings(SVG/SVGAElement) libweb_js_bindings(SVG/SVGAElement)
libweb_js_bindings(SVG/SVGAnimatedEnumeration) libweb_js_bindings(SVG/SVGAnimatedEnumeration)

View file

@ -117,6 +117,7 @@ static bool is_platform_object(Type const& type)
"TextTrack"sv, "TextTrack"sv,
"TimeRanges"sv, "TimeRanges"sv,
"TrustedHTML"sv, "TrustedHTML"sv,
"TrustedTypePolicy"sv,
"TrustedTypePolicyFactory"sv, "TrustedTypePolicyFactory"sv,
"URLSearchParams"sv, "URLSearchParams"sv,
"VTTRegion"sv, "VTTRegion"sv,

View file

@ -433,6 +433,7 @@ TransformStreamDefaultController
TransitionEvent TransitionEvent
TreeWalker TreeWalker
TrustedHTML TrustedHTML
TrustedTypePolicy
TrustedTypePolicyFactory TrustedTypePolicyFactory
TypeError TypeError
UIEvent UIEvent