diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.cpp b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.cpp index 290c2a9ccdd..ae7341bea80 100644 --- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.cpp +++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,22 @@ WebIDL::ExceptionOr> TrustedTypePolicy::create_script(St return trusted_type.get>(); } +// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicy-createscripturl +WebIDL::ExceptionOr> TrustedTypePolicy::create_script_url(String const& input, GC::RootVector const& arguments) +{ + // 1. Returns the result of executing the Create a Trusted Type algorithm, with the following arguments: + // policy + // this value + // trustedTypeName + // "TrustedScriptURL" + // value + // input + // arguments + // arguments + auto const trusted_type = TRY(create_a_trusted_type(TrustedTypeName::TrustedScriptURL, input, arguments)); + return trusted_type.get>(); +} + // https://w3c.github.io/trusted-types/dist/spec/#create-a-trusted-type-algorithm TrustedTypesVariants TrustedTypePolicy::create_a_trusted_type(TrustedTypeName trusted_type_name, String const& value, GC::RootVector const& arguments) { @@ -99,6 +116,8 @@ TrustedTypesVariants TrustedTypePolicy::create_a_trusted_type(TrustedTypeName tr return realm.create(realm, move(data_string)); case TrustedTypeName::TrustedScript: return realm.create(realm, move(data_string)); + case TrustedTypeName::TrustedScriptURL: + return realm.create(realm, move(data_string)); default: VERIFY_NOT_REACHED(); } diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.h b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.h index 016548dd653..5f485a20775 100644 --- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.h +++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.h @@ -14,7 +14,8 @@ namespace Web::TrustedTypes { using TrustedTypesVariants = WebIDL::ExceptionOr, - GC::Root>>; + GC::Root, + GC::Root>>; enum class TrustedTypeName { TrustedHTML, @@ -44,6 +45,7 @@ public: WebIDL::ExceptionOr> create_html(String const&, GC::RootVector const&); WebIDL::ExceptionOr> create_script(String const&, GC::RootVector const&); + WebIDL::ExceptionOr> create_script_url(String const&, GC::RootVector const&); private: explicit TrustedTypePolicy(JS::Realm&, String const&, TrustedTypePolicyOptions const&); diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.idl b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.idl index 3c600836da3..c3d549788bf 100644 --- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.idl +++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicy.idl @@ -1,5 +1,6 @@ #import #import +#import // https://w3c.github.io/trusted-types/dist/spec/#trusted-type-policy [Exposed=(Window,Worker)] @@ -7,7 +8,7 @@ interface TrustedTypePolicy { readonly attribute DOMString name; TrustedHTML createHTML(DOMString input, any... arguments); TrustedScript createScript(DOMString input, any... arguments); - [FIXME] TrustedScriptURL createScriptURL(DOMString input, any... arguments); + TrustedScriptURL createScriptURL(DOMString input, any... arguments); }; // https://w3c.github.io/trusted-types/dist/spec/#trusted-type-policy-options diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.cpp b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.cpp index 5bb38b1ae63..1f9e6399bbb 100644 --- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.cpp +++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -172,6 +173,13 @@ bool TrustedTypePolicyFactory::is_script(JS::Value value) return value.is_object() && is(value.as_object()); } +// https://w3c.github.io/trusted-types/dist/spec/#dom-trustedtypepolicyfactory-isscripturl +bool TrustedTypePolicyFactory::is_script_url(JS::Value value) +{ + // 1. Returns true if value is an instance of TrustedScriptURL and has an associated data value set, false otherwise. + return value.is_object() && is(value.as_object()); +} + // https://w3c.github.io/trusted-types/dist/spec/#create-trusted-type-policy-algorithm WebIDL::ExceptionOr> TrustedTypePolicyFactory::create_a_trusted_type_policy(String const& policy_name, TrustedTypePolicyOptions const& options, JS::Object& global) { diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.h b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.h index 1319cd48499..74d3aadb212 100644 --- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.h +++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.h @@ -27,6 +27,7 @@ public: bool is_html(JS::Value); bool is_script(JS::Value); + bool is_script_url(JS::Value); Optional get_attribute_type(String const& tag_name, String& attribute, Optional element_ns, Optional attr_ns); Optional get_property_type(String const& tag_name, String const& property, Optional element_ns); diff --git a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.idl b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.idl index 614898f6ab1..3663a7ed818 100644 --- a/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.idl +++ b/Libraries/LibWeb/TrustedTypes/TrustedTypePolicyFactory.idl @@ -7,7 +7,7 @@ interface TrustedTypePolicyFactory { DOMString policyName, optional TrustedTypePolicyOptions policyOptions = {}); boolean isHTML(any value); boolean isScript(any value); - [FIXME] boolean isScriptURL(any value); + boolean isScriptURL(any value); [FIXME] readonly attribute TrustedHTML emptyHTML; [FIXME] readonly attribute TrustedScript emptyScript; DOMString? getAttributeType(