@@ -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 ,
@@ -3155,17 +3158,39 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
31553158 }
31563159
31573160 /// <https://dom.spec.whatwg.org/#dom-element-setattribute>
3158- fn SetAttribute ( & self , name : DOMString , value : DOMString , can_gc : CanGc ) -> ErrorResult {
3159- // Step 1. If qualifiedName is not a valid attribute local name,
3160- // then throw an "InvalidCharacterError" DOMException.
3161+ fn SetAttribute (
3162+ & self ,
3163+ name : DOMString ,
3164+ value : TrustedTypeOrString ,
3165+ can_gc : CanGc ,
3166+ ) -> ErrorResult {
3167+ // Step 1. If qualifiedName does not match the Name production in XML,
3168+ // then throw an "InvalidCharacterError" DOMException.
31613169 if !is_valid_attribute_local_name ( & name) {
31623170 return Err ( Error :: InvalidCharacter ) ;
31633171 }
31643172
3165- // Step 2.
3173+ // Step 2. If this is in the HTML namespace and its node document is an HTML document,
3174+ // then set qualifiedName to qualifiedName in ASCII lowercase.
31663175 let name = self . parsed_name ( name) ;
31673176
3168- // Step 3-5.
3177+ // Step 3. Let verifiedValue be the result of calling get
3178+ // Trusted Types-compliant attribute value with qualifiedName, null,
3179+ // this, and value. [TRUSTED-TYPES]
3180+ let value = TrustedTypePolicyFactory :: get_trusted_types_compliant_attribute_value (
3181+ self . namespace ( ) ,
3182+ self . local_name ( ) ,
3183+ & name,
3184+ None ,
3185+ value,
3186+ & self . owner_global ( ) ,
3187+ can_gc,
3188+ ) ?;
3189+
3190+ // Step 4. Let attribute be the first attribute in this’s attribute list whose qualified name is qualifiedName, and null otherwise.
3191+ // Step 5. If attribute is null, create an attribute whose local name is qualifiedName, value is verifiedValue, and node document
3192+ // is this’s node document, then append this attribute to this, and then return.
3193+ // Step 6. Change attribute to verifiedValue.
31693194 let value = self . parse_attribute ( & ns ! ( ) , & name, value) ;
31703195 self . set_first_matching_attribute (
31713196 name. clone ( ) ,
@@ -3184,20 +3209,29 @@ impl ElementMethods<crate::DomTypeHolder> for Element {
31843209 & self ,
31853210 namespace : Option < DOMString > ,
31863211 qualified_name : DOMString ,
3187- value : DOMString ,
3212+ value : TrustedTypeOrString ,
31883213 can_gc : CanGc ,
31893214 ) -> ErrorResult {
3190- // Step 1. Let (namespace, prefix, localName) be the result of validating and
3191- // extracting namespace and qualifiedName given "element".
3192- let context = domname:: Context :: Element ;
3215+ // Step 1. Let namespace, prefix, and localName be the result of passing namespace and qualifiedName to validate and extract.
31933216 let ( namespace, prefix, local_name) =
3194- domname:: validate_and_extract ( namespace, & qualified_name, context) ?;
3195- let qualified_name = LocalName :: from ( qualified_name) ;
3217+ domname:: validate_and_extract ( namespace, & qualified_name, domname:: Context :: Element ) ?;
3218+ // Step 2. Let verifiedValue be the result of calling get
3219+ // Trusted Types-compliant attribute value with localName, namespace, element, and value. [TRUSTED-TYPES]
3220+ let value = TrustedTypePolicyFactory :: get_trusted_types_compliant_attribute_value (
3221+ self . namespace ( ) ,
3222+ self . local_name ( ) ,
3223+ & local_name,
3224+ Some ( & namespace) ,
3225+ value,
3226+ & self . owner_global ( ) ,
3227+ can_gc,
3228+ ) ?;
3229+ // Step 3. Set an attribute value for this using localName, verifiedValue, and also prefix and namespace.
31963230 let value = self . parse_attribute ( & namespace, & local_name, value) ;
31973231 self . set_first_matching_attribute (
31983232 local_name. clone ( ) ,
31993233 value,
3200- qualified_name,
3234+ LocalName :: from ( qualified_name) ,
32013235 namespace. clone ( ) ,
32023236 prefix,
32033237 |attr| * attr. local_name ( ) == local_name && * attr. namespace ( ) == namespace,
0 commit comments