Page MenuHomePhabricator

Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug
ClosedPublic

Authored by fredw on Nov 5 2024, 11:11 AM.
Referenced Files
Unknown Object (File)
Nov 13 2025, 4:47 PM
Unknown Object (File)
Nov 13 2025, 4:47 PM
Unknown Object (File)
Nov 13 2025, 4:47 PM
Unknown Object (File)
Nov 13 2025, 4:47 PM
Unknown Object (File)
Nov 13 2025, 4:47 PM
Unknown Object (File)
Nov 13 2025, 4:47 PM
Unknown Object (File)
Nov 8 2025, 12:15 PM
Unknown Object (File)
Nov 8 2025, 12:15 PM

Diff Detail

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
dom/security/trusted-types/TrustedTypeUtils.cpp
494

This looks weird. Use of std::pair should be limited basically to some generic data structures.

dom/security/trusted-types/TrustedTypeUtils.h
68

Could we use some proper simple struct for this. std::pair really should be used in some generic data structures. .first and .second are meaningless to the reader.

testing/web-platform/meta/trusted-types/modify-attributes-in-callback.html.ini
5 โ†—(On Diff #941082)

Why do these two tests fail?

This revision now requires changes to proceed.Nov 6 2024, 9:55 PM
fredw updated this revision to Diff 943429.
fredw retitled this revision from Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug to WIP: Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug.

rebase

fredw added inline comments.
dom/base/Element.cpp
1691

Should I open a follow-up bug to remove this here and in the old SetAttribute?

dom/security/trusted-types/TrustedTypeUtils.cpp
494

no longer necessary now that the expected type is passed as a template parameter.

dom/security/trusted-types/TrustedTypeUtils.h
68

no longer necessary now that the expected type is passed as a template parameter.

fredw requested review of this revision.Nov 12 2024, 5:13 PM
fredw updated this revision to Diff 943665.
fredw retitled this revision from WIP: Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug to Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug.
fredw marked 2 inline comments as done.
fredw updated this revision to Diff 944063.
fredw retitled this revision from Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug to WIP: Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug.

fix warning message for unused captures in lambdas

fredw updated this revision to Diff 944076.
fredw marked 2 inline comments as done.
dom/base/Element.cpp
1691

Removed.

dom/security/trusted-types/TrustedTypeUtils.cpp
476

Ack.

478

I rewrote the code as suggested, but still need to do some profiling.

testing/web-platform/meta/trusted-types/modify-attributes-in-callback.html.ini
5 โ†—(On Diff #941082)

I haven't debugged yet, but it seems this is similar issue as in WebKit/Chromium: https://issues.chromium.org/issues/333739948

Basically the Trusted type callback is editing the attribute list while the attribute is set, so depending on the internal structure used to represent the attribute list, that may result in the wrong modification happening.

Will try to investigate more Firefox's case.

fredw updated this revision to Diff 944086.

Code analysis found 3 defects in diff 944086:

  • 1 defect found by clang-format
  • 2 defects found by clang-format (Mozlint)
WARNING: Found 3 defects (warning level) that can be dismissed.

You can run this analysis locally with:

  • ./mach lint --warnings --outgoing
  • ./mach clang-format -p dom/base/Element.cpp

For your convenience, here is a patch that fixes all the clang-format defects (use it in your repository with hg import or git apply -p0).


If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 944086.

fredw requested review of this revision.Nov 13 2024, 8:43 AM
fredw updated this revision to Diff 944099.
fredw retitled this revision from WIP: Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug to Bug 1925468 - Implement Trusted Type support for setAttribute/setAttributeNS. r=smaug.

Code analysis found 3 defects in diff 944099:

  • 1 defect found by clang-format
  • 2 defects found by clang-format (Mozlint)
WARNING: Found 3 defects (warning level) that can be dismissed.

You can run this analysis locally with:

  • ./mach clang-format -p dom/base/Element.cpp
  • ./mach lint --warnings --outgoing

For your convenience, here is a patch that fixes all the clang-format defects (use it in your repository with hg import or git apply -p0).


If you see a problem in this automated review, please report it here.

You can view these defects in the Diff Detail section of Phabricator diff 944099.

fredw updated this revision to Diff 944170.
smaug requested changes to this revision.Nov 13 2024, 4:01 PM
smaug added inline comments.
dom/base/Element.cpp
1719

This feels too slow, indeed, and this is very hot code.
Not sure which benchmark would show the issue. Perhaps one would need to write a small microbenchmark.

But we should be able to optimize this by using nsMutationGuard, and it's Mutated() method. Only take the slow code path if DOM was mutated.

This revision now requires changes to proceed.Nov 13 2024, 4:01 PM
fredw added inline comments.
dom/base/Element.cpp
1719

OK I've done that change.

fredw requested review of this revision.Nov 13 2024, 6:27 PM
fredw updated this revision to Diff 944551.
fredw marked an inline comment as done.
smaug added a project: testing-approved.

r+, but could you do some profiling. With and without the pref enabled, set some random attributes and share profiles here? Just to ensure we aren't missing anything obvious.
And perhaps push also to try and run at least Speedometer3 on Win11
./mach try perf --rebuild 20 --show-all
and select speedometer3 shippable firefox win11
(don't select hw-ref, but other win11)

This should land only once we have some perf numbers because this is so performance critical

dom/security/trusted-types/TrustedTypeUtils.cpp
457

aNewValue

This revision is now accepted and ready to land.Nov 13 2024, 10:14 PM
fredw added inline comments.
dom/security/trusted-types/TrustedTypeUtils.cpp
478

Will do some profiling & perf testing today.

dom/base/Element.cpp
1719

It seems I didn't reply about the "benchmark". I think this code is executed when modifying the value of an already attached attribute, as it is done in https://bug1925468.bmoattachments.org/attachment.cgi?id=9437631 ; i didn't try without my mutation guard, but the profiles with that change looks good. I think the slow path would only be executed if the trusted type call back performed some DOM mutation. Probably this can be optimized further, but it seems good enough to me as that does not sound a very frequent case in practice (i.e. a callback sanitizing the input).

r+, but could you do some profiling. With and without the pref enabled, set some random attributes and share profiles here? Just to ensure we aren't missing anything obvious.
And perhaps push also to try and run at least Speedometer3 on Win11
./mach try perf --rebuild 20 --show-all
and select speedometer3 shippable firefox win11
(don't select hw-ref, but other win11)

This should land only once we have some perf numbers because this is so performance critical

OK, I've sent this there. Profiling & try job looks good. let's wait for the speedometer3 result:
Profiling: https://bugzilla.mozilla.org/show_bug.cgi?id=1925468#c7
Try job and performance: https://bugzilla.mozilla.org/show_bug.cgi?id=1925468#c8

rebase on top of c845f32071817c81069390d3ba4f06b0ee270c20

rebase on top of 0f913e6025c10ac90a6f492c27155b8dd78730b5

rebase on top of 0f913e6025c10ac90a6f492c27155b8dd78730b5

This revision is now accepted and ready to land.Nov 27 2024, 12:12 PM