mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-21 16:58:58 +00:00
LibWeb: Implement last 2 remaining FIXME's on TrustedTypePolicyFactory
emptyHTML is used to avoid having to create a no-op policy while emptyScript is used to detect if the browser supports the spec natively.
This commit is contained in:
parent
4f9eb78b9d
commit
af933c2721
Notes:
github-actions[bot]
2025-09-01 15:21:17 +00:00
Author: https://github.com/tete17
Commit: af933c2721
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5828
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/Lubrsi ✅
3 changed files with 33 additions and 9 deletions
|
@ -31,11 +31,6 @@ namespace Web::TrustedTypes {
|
|||
|
||||
GC_DEFINE_ALLOCATOR(TrustedTypePolicyFactory);
|
||||
|
||||
GC::Ref<TrustedTypePolicyFactory> TrustedTypePolicyFactory::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.create<TrustedTypePolicyFactory>(realm);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicyfactory-getattributetype
|
||||
Optional<Utf16String> TrustedTypePolicyFactory::get_attribute_type(Utf16String const& tag_name, Utf16String& attribute, Optional<Utf16String> element_ns, Optional<Utf16String> attr_ns)
|
||||
{
|
||||
|
@ -153,6 +148,8 @@ void TrustedTypePolicyFactory::visit_edges(Visitor& visitor)
|
|||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_default_policy);
|
||||
visitor.visit(m_empty_html);
|
||||
visitor.visit(m_empty_script);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicyfactory-createpolicy
|
||||
|
@ -187,6 +184,26 @@ bool TrustedTypePolicyFactory::is_script_url(JS::Value value)
|
|||
return value.is_object() && is<TrustedScriptURL>(value.as_object());
|
||||
}
|
||||
|
||||
GC::Ref<TrustedHTML const> TrustedTypePolicyFactory::empty_html()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
if (!m_empty_html)
|
||||
m_empty_html = realm.create<TrustedHTML>(realm, ""_utf16);
|
||||
|
||||
return GC::Ref { *m_empty_html };
|
||||
}
|
||||
|
||||
GC::Ref<TrustedScript const> TrustedTypePolicyFactory::empty_script()
|
||||
{
|
||||
auto& realm = this->realm();
|
||||
|
||||
if (!m_empty_script)
|
||||
m_empty_script = realm.create<TrustedScript>(realm, ""_utf16);
|
||||
|
||||
return GC::Ref { *m_empty_script };
|
||||
}
|
||||
|
||||
// https://w3c.github.io/trusted-types/dist/spec/#create-trusted-type-policy-algorithm
|
||||
WebIDL::ExceptionOr<GC::Ref<TrustedTypePolicy>> TrustedTypePolicyFactory::create_a_trusted_type_policy(Utf16String const& policy_name, TrustedTypePolicyOptions const& options, JS::Object& global)
|
||||
{
|
||||
|
|
|
@ -19,8 +19,6 @@ class TrustedTypePolicyFactory final : public Bindings::PlatformObject {
|
|||
GC_DECLARE_ALLOCATOR(TrustedTypePolicyFactory);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static GC::Ref<TrustedTypePolicyFactory> create(JS::Realm&);
|
||||
|
||||
virtual ~TrustedTypePolicyFactory() override { }
|
||||
|
||||
WebIDL::ExceptionOr<GC::Ref<TrustedTypePolicy>> create_policy(Utf16String const&, TrustedTypePolicyOptions const&);
|
||||
|
@ -29,6 +27,9 @@ public:
|
|||
bool is_script(JS::Value);
|
||||
bool is_script_url(JS::Value);
|
||||
|
||||
GC::Ref<TrustedHTML const> empty_html();
|
||||
GC::Ref<TrustedScript const> empty_script();
|
||||
|
||||
Optional<Utf16String> get_attribute_type(Utf16String const& tag_name, Utf16String& attribute, Optional<Utf16String> element_ns, Optional<Utf16String> attr_ns);
|
||||
Optional<Utf16String> get_property_type(Utf16String const& tag_name, Utf16String const& property, Optional<Utf16String> element_ns);
|
||||
|
||||
|
@ -51,6 +52,12 @@ private:
|
|||
|
||||
// https://w3c.github.io/trusted-types/dist/spec/#trustedtypepolicyfactory-default-policy
|
||||
GC::Ptr<TrustedTypePolicy> m_default_policy;
|
||||
|
||||
// https://www.w3.org/TR/trusted-types/#dom-trustedtypepolicyfactory-emptyhtml
|
||||
GC::Ptr<TrustedHTML const> m_empty_html;
|
||||
|
||||
// https://www.w3.org/TR/trusted-types/#dom-trustedtypepolicyfactory-emptyscript
|
||||
GC::Ptr<TrustedScript const> m_empty_script;
|
||||
};
|
||||
|
||||
struct TrustedTypeData {
|
||||
|
|
|
@ -8,8 +8,8 @@ interface TrustedTypePolicyFactory {
|
|||
boolean isHTML(any value);
|
||||
boolean isScript(any value);
|
||||
boolean isScriptURL(any value);
|
||||
[FIXME] readonly attribute TrustedHTML emptyHTML;
|
||||
[FIXME] readonly attribute TrustedScript emptyScript;
|
||||
readonly attribute TrustedHTML emptyHTML;
|
||||
readonly attribute TrustedScript emptyScript;
|
||||
Utf16DOMString? getAttributeType(
|
||||
Utf16DOMString tagName,
|
||||
Utf16DOMString attribute,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue