@@ -87,7 +87,9 @@ use crate::dom::bindings::codegen::Bindings::WindowBinding::{
8787} ;
8888use crate :: dom:: bindings:: codegen:: UnionTypes :: {
8989 BooleanOrScrollIntoViewOptions , NodeOrString , TrustedHTMLOrNullIsEmptyString ,
90- TrustedHTMLOrString , TrustedScriptURLOrUSVString ,
90+ TrustedHTMLOrString ,
91+ TrustedHTMLOrTrustedScriptOrTrustedScriptURLOrString as TrustedTypeOrString ,
92+ TrustedScriptURLOrUSVString ,
9193} ;
9294use crate :: dom:: bindings:: conversions:: DerivedFrom ;
9395use crate :: dom:: bindings:: domname:: {
@@ -161,6 +163,7 @@ use crate::dom::servoparser::ServoParser;
161163use crate :: dom:: shadowroot:: { IsUserAgentWidget , ShadowRoot } ;
162164use crate :: dom:: text:: Text ;
163165use crate :: dom:: trustedhtml:: TrustedHTML ;
166+ use crate :: dom:: trustedtypepolicyfactory:: TrustedTypePolicyFactory ;
164167use crate :: dom:: validation:: Validatable ;
165168use crate :: dom:: validitystate:: ValidationFlags ;
166169use crate :: dom:: virtualmethods:: { VirtualMethods , vtable_for} ;
@@ -752,7 +755,7 @@ impl Element {
752755
753756 // https://html.spec.whatwg.org/multipage/#translation-mode
754757 pub ( crate ) fn is_translate_enabled ( & self ) -> bool {
755- let name = & html5ever :: local_name!( "translate" ) ;
758+ let name = & local_name ! ( "translate" ) ;
756759 if self . has_attribute ( name) {
757760 match_ignore_ascii_case ! { & * self . get_string_attribute( name) ,
758761 "yes" | "" => return true ,
@@ -3250,17 +3253,39 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
32503253 }
32513254
32523255 /// <https://dom.spec.whatwg.org/#dom-element-setattribute>
3253- fn SetAttribute ( & self , name : DOMString , value : DOMString , can_gc : CanGc ) -> ErrorResult {
3254- // Step 1. If qualifiedName is not a valid attribute local name,
3255- // then throw an "InvalidCharacterError" DOMException.
3256+ fn SetAttribute (
3257+ & self ,
3258+ name : DOMString ,
3259+ value : TrustedTypeOrString ,
3260+ can_gc : CanGc ,
3261+ ) -> ErrorResult {
3262+ // Step 1. If qualifiedName does not match the Name production in XML,
3263+ // then throw an "InvalidCharacterError" DOMException.
32563264 if !is_valid_attribute_local_name ( & name) {
32573265 return Err ( Error :: InvalidCharacter ) ;
32583266 }
32593267
3260- // Step 2.
3268+ // Step 2. If this is in the HTML namespace and its node document is an HTML document,
3269+ // then set qualifiedName to qualifiedName in ASCII lowercase.
32613270 let name = self . parsed_name ( name) ;
32623271
3263- // Step 3-5.
3272+ // Step 3. Let verifiedValue be the result of calling get
3273+ // Trusted Types-compliant attribute value with qualifiedName, null,
3274+ // this, and value. [TRUSTED-TYPES]
3275+ let value = TrustedTypePolicyFactory :: get_trusted_types_compliant_attribute_value (
3276+ self . namespace ( ) ,
3277+ self . local_name ( ) ,
3278+ & name,
3279+ None ,
3280+ value,
3281+ & self . owner_global ( ) ,
3282+ can_gc,
3283+ ) ?;
3284+
3285+ // Step 4. Let attribute be the first attribute in this’s attribute list whose qualified name is qualifiedName, and null otherwise.
3286+ // Step 5. If attribute is null, create an attribute whose local name is qualifiedName, value is verifiedValue, and node document
3287+ // is this’s node document, then append this attribute to this, and then return.
3288+ // Step 6. Change attribute to verifiedValue.
32643289 let value = self . parse_attribute ( & ns ! ( ) , & name, value) ;
32653290 self . set_first_matching_attribute (
32663291 name. clone ( ) ,
@@ -3279,20 +3304,29 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
32793304 & self ,
32803305 namespace : Option < DOMString > ,
32813306 qualified_name : DOMString ,
3282- value : DOMString ,
3307+ value : TrustedTypeOrString ,
32833308 can_gc : CanGc ,
32843309 ) -> ErrorResult {
3285- // Step 1. Let (namespace, prefix, localName) be the result of validating and
3286- // extracting namespace and qualifiedName given "element".
3287- let context = domname:: Context :: Element ;
3310+ // Step 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
32883311 let ( namespace, prefix, local_name) =
3289- domname:: validate_and_extract ( namespace, & qualified_name, context) ?;
3290- let qualified_name = LocalName :: from ( qualified_name) ;
3312+ domname:: validate_and_extract ( namespace, & qualified_name, domname:: Context :: Element ) ?;
3313+ // Step 2. Let verifiedValue be the result of calling get
3314+ // Trusted Types-compliant attribute value with localName, namespace, element, and value. [TRUSTED-TYPES]
3315+ let value = TrustedTypePolicyFactory :: get_trusted_types_compliant_attribute_value (
3316+ self . namespace ( ) ,
3317+ self . local_name ( ) ,
3318+ & local_name,
3319+ Some ( & namespace) ,
3320+ value,
3321+ & self . owner_global ( ) ,
3322+ can_gc,
3323+ ) ?;
3324+ // Step 3. Set an attribute value for this using localName, verifiedValue, and also prefix and namespace.
32913325 let value = self . parse_attribute ( & namespace, & local_name, value) ;
32923326 self . set_first_matching_attribute (
32933327 local_name. clone ( ) ,
32943328 value,
3295- qualified_name,
3329+ LocalName :: from ( qualified_name) ,
32963330 namespace. clone ( ) ,
32973331 prefix,
32983332 |attr| * attr. local_name ( ) == local_name && * attr. namespace ( ) == namespace,
0 commit comments