Commit Graph

12342 Commits

Author SHA1 Message Date
Josh Matthews
f2d13a98d9 script: Improve spec-compliance of Performance resource timing entries (#40811)
The current implementation doesn't match the specification and is broken
in a way that makes nytimes.com endlessly attempt to enqueue resource
timing entries, making the page completely unresposive to user input.
This PR makes some surgical changes that fix the NYTimes behaviour and
add some comments to make it easier to further improve the
implementation in the future.

Testing: Various WPT that used to timeout now fail instead.
Fixes: #40808

---------

Signed-off-by: Josh Matthews <josh@joshmatthews.net>
2025-11-22 08:59:07 +00:00
Kingsley Yung
f804216ec4 script: Rename ExportedKey::Raw to ExportedKey::Bytes (#40809)
The enum variant `ExportedKey::Raw(Vec<u8>)` is actually used when a key
is exported in "raw", "spki" or "pkcs8" format. Naming it as `Raw` could
be confusing.

This patch renames `ExportedKey::Raw` to `ExportedKey::Bytes`.

Testing: No behavioral change. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-22 05:36:45 +00:00
webbeef
ab1d762035 chore: Use parking_lot Mutex and RwLock in net/ code (#40805)
Partial fix for https://github.com/servo/servo/issues/40744

Testing: Refactor covered by existing tests.
Fixes:  Contributes to https://github.com/servo/servo/issues/40744

Signed-off-by: webbeef <me@webbeef.org>
2025-11-22 03:51:39 +00:00
Tim van der Lippe
69030f583a libservo: Notify embedder of protocol handler updates (#40653)
This implements step 2 of the web-facing API's.
Now, the embedder receives a notification whether
a webpage wants to register/unregister a protocol
handler. They can't do anything with it yet, that's for a follow-up PR.
But locally testing shows the
following debug log:

```
pid:35180 Requesting to Register for scheme web+test with url https://web-platform.test:8443/html/webappapis/system-state-and-capabilities/the-navigator-object/%s
```

Part of #40615

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-11-21 18:12:00 +00:00
Mukilan Thiyagarajan
90595e3570 compositing: Support per-Painter operations and message handling (#40788)
Currently, only the first `Painter` is used for all operations in the
`Compositor`. This change modifies the compositor API and message
handling to allow routing the operations to the correct `Painter` via a
provided `PainterId` or `WebViewId`.

This change is to enable support for per-`WebView`s `RenderingContext`s.

Testing: This change shouldn't change behavior, so existing WPT tests
should cover it.

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-11-21 13:15:55 +00:00
Jonathan Schwender
e92c310fd6 Add feature to disable JIT support in mozjs at compile-time (#37972)
When the `js_jit` feature is not selected, this reduces the binary size
from 89 to 80 MiB for linux production-stripped.
By default, we still enable JIT, but in scenarios where JIT is not
required or not allowed by the system, the size savings make a feature
worthwhile.
To allow disabling the feature, `servoshell` now depends on libservo
with `no-default-features`, and hence gains explicit default features,
that were previously enabled via libservos default features. To avoid
compile-errors with `--no-default-features`, `vello-cpu` is
unconditionally selected by servoshell (identical to previous behavior).

Testing: The default behavior is unchanged. The HarmonyOS CI job does
test with `--no-default-features`

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-11-21 08:18:31 +00:00
webbeef
cc1dfa7e47 dom: cache preference access in Document (#40775)
They showed up in some profile due to the RwLock access.

Testing: Green wpt tests:
https://github.com/webbeef/servo/actions/runs/19559457895/job/56010036063

Signed-off-by: webbeef <me@webbeef.org>
2025-11-21 06:52:01 +00:00
Oriol Brufau
8b5333b38e layout: Cleanup for replaced elements with widgets (#40769)
This cleans up the changes done in #40578.

In particular, it removes the unnecessary `Contents::ReplacedWithWidget`
since we can handle that with `Contents::Replaced`. It also removes
`IndependentFormattingContextContents::ReplacedWithWidget` in favor of
`IndependentFormattingContextContents::Replaced`, by adding an optional
parameter for the widget.

That ensures that the behavior of replaced elements won't accidentally
diverge dependign on whether they have a widget. For example, #40578
forgot to handle `ReplacedWithWidget` in
`tentative_block_content_size()`.

Additionally, this removes the hardcoded especial behavior for `<video>`
that was added in `ServoThreadSafeLayoutElement::with_pseudo()`.

Testing: Adding a reftest
Fixes: #40708
Fixes: #40770

---------

Signed-off-by: Oriol Brufau <obrufau@igalia.com>
2025-11-20 20:52:39 +00:00
Simon Wülker
8dbe44b33d script: Don't crash when encountering unexpected node types in Range::createContextualFragment (#40762)
The spec says that all node types other than element, text and comment
should be treated as `None`. We were panicking on a few instead.

Testing: This change adds a simple crashtest
Fixes: https://github.com/servo/servo/issues/40719

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-20 19:34:02 +00:00
Simon Wülker
edc0f8ab9a script: Add messages to exceptions thrown in Element::attachShadow (#40768)
Part of https://github.com/servo/servo/issues/40756

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-20 19:21:27 +00:00
Jonathan Schwender
f76ce4c64d Prefer log over (e)println! (#40764)
Switches to log methods over eprintln in cases where it makes sense.
stdout / stderr output may be difficult to view on devices like android
/ ohos, and has no filter options, so we should prefer log methods.
This PR avoids prints, which are controlled by a debugging option.

Testing: Only changes logging, no functional behavior change.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-11-20 15:15:30 +00:00
Kingsley Yung
350cf0bdfd script: Implement SHA-3 in WebCrypto API (#40765)
Implements digest operation of SHA-3, including `SHA3-256`, `SHA3-384`
and `SHA3-512`, using the crate `sha3` for the SHA-3 calculation.

Testing: Pass WPT tests that were expected to fail.
Fixes: Part of #40687

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-20 15:09:13 +00:00
Andrei Volykhin
bc9e8d2949 html: The queued <media> volumechange event should be cancellable (#40763)
Following the HTML specification, on the `volume` or `mute` attrubute
changes the user agent must queue a media element task given the media
element to fire an event named `volumechange` at the media element (the
`generation_id` value will be captured to allow cancel this task -
`media-element-load-algorithm` steps 3-5)

See https://html.spec.whatwg.org/multipage/#event-media-volumechange
See https://html.spec.whatwg.org/multipage/#media-element-load-algorithm

Changed the naming of the `playbackRate` and `defaultPlaybackRate`
members to match Rust naming conventions (`snake_case`).

Testing: Added the `cancellable` subtest to `event_volumechange` test
- html/semantics/embedded-content/media-elements/event_volumechange.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-20 13:41:17 +00:00
eri
c6f4c79814 devtools: Support reloading tab (#40760)
Allows to use the reload button from the top bar of `about:debugging`.

<img width="971" height="43" alt="Top bar of about:debugging showing the
tab, title, buttons for back, forward and reload and url bar"
src="https://github.com/user-attachments/assets/5496fcf1-5ee3-41cc-8fdb-53aad020ea96"
/>

Testing: Manual testing.

Signed-off-by: eri <eri@igalia.com>
2025-11-20 12:19:20 +00:00
Ashwin Naren
e0eb23ce18 script: Finish converting all error message enum variants to Option<String> (#40750)
I used find and replace to finish the job. All this PR does is replace
all `Error::<error_name>` occurrences with `Error::<error_name>(None)`.

Testing: Refactor
Fixes: #39053

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-11-20 06:20:47 +00:00
webbeef
135bc7de36 script: Optimize Node::insert (#40742)
- Change how the static node list is built to prevent a second iteration
of new_nodes
- Memoize some invariants of the parent


Testing: No wpt regressions:
https://github.com/webbeef/servo/actions/runs/19493174678

This improves the `parseFromString()` benchmark by ~7% on my machine.

Signed-off-by: webbeef <me@webbeef.org>
2025-11-20 05:25:53 +00:00
d-kraus
adf840a7c4 script: Add message to Dom exception Error::NotSupported (#40745)
Adding an optional message to Error::NotSupported. Unblocks
https://github.com/servo/servo/issues/39050.

The enum definition of NotSupported is now
`NotSupported(Option<String>)`.

Testing: Just a refactor
Fixes: Partially https://github.com/servo/servo/issues/39053

Signed-off-by: Dennis Kraus <kraus@posteo.de>
2025-11-20 01:31:33 +00:00
Martin Robinson
1a99f74c36 script: Use a WeakRef for references to WebGLRenderingContext (#40725)
Many WebGL objects refer to a `WebGLRenderingContext` and rely on it for
messaging to the `WebGLThread`. This poses a problem, because WebGL
objects often need to send a message to the `WebGLThread` during their
`Drop` implementation. If the `Drop` is triggered as part of garbage
collection, references to the `WebGLRenderingContext` might be invalid,
if they were garbage collected first as part of the same harvest.

This change makes it so that all of these objects store a `WeakRef`
instead of a `Dom<>`. The `WeakRef` is only used if it can be rooted,
otherwise a `ContextLost` error is given. In cases where only messaging
is needed, a cloned `WebGLMsgSender` is used to perform messages
regardless of whether the context is garbage collected or not.

This isn't a replacement for #37622, but should make it easier to
implement as
the `WebGLMsgSender` and the `WeakRef` could be stored in the droppable
portion of the DOM object.

Testing: This fixes a use-after-free issue which is mainly detectable
via ASAN
builds. Since we do not run ASAN on CI, this is a bit hard to create
automated
tests for. I verified that this fixed the issue manually.
Fixes: #40655.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-19 12:29:46 +00:00
Tim van der Lippe
e1b9c02de3 webdriver: implement protocol handler automation mode (#40733)
The tests now start running rather than erroring, but they aren't
working yet as we don't currently use protocol handlers yet. That's for
follow-up PRs, as that requires more plumbing.

Part of #40615

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-11-19 11:53:17 +00:00
Sam
c27f8c565a Use safe JSContext/AutoRealm/CurrentRealm in codegen (#40716)
We replace many places that use `SafeJSContext` with `JSContext` and I
also rewrote `is_platform_object_same_origin` to use new `JSContext`.
Unfortunately using wrappers2 in them causes crashes (in handle code),
so I reverted that part in last commit and will fix handles in mozjs
later.

Testing: Refactor, but it is covered by WPT tests
Part of #40600

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-11-19 05:55:55 +00:00
Taym Haddadi
66a50ad687 Fix RefCell already borrowed panic in HTMLMediaElement::set_audio_renderer (#40729)
Fix RefCell already borrowed panic in
HTMLMediaElement::set_audio_renderer

Testing: new crash test should pass.
Fixes: #40720

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2025-11-19 00:34:15 +00:00
Simon Wülker
c5da05348e script: Don't allocate when retrieving attribute values for layout (#40724)
We end up only calling `.iter` on these `Vec`s anyways.

Testing: No behaviour change intended, regressions are covered by
existing tests

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-18 19:13:26 +00:00
Martin Robinson
f08c6ab38c compositing: Allow WebGL contexts to have different Surfman devices (#40721)
Currently, a single `surfman::Device` is used for all WebGL contexts.
This cannot work when we have multiple rendering contexts. So, extract
the surfman `Connection` and `Adapter` into a per-painter data structure
(`PainterSurfmanDetailsMap`) and store the `Device` directly in the
WebGL context.

This patch also modifies the WebXR traits so that the `Device` doesn't
need to be explictly passed into most methods.

*This is a reland of #40594* with the following changes:

- Do not remove WebGL contexts from the context map before cleaning up
the
    WebXR layers. The layer cleanup process consults the map.
  - When cleanup up layers, be sure to replace the WebXRBridge in the
    WebGLThread data structure.
  - Allow failing to the Device when processing WebXR commands. WebXR
    sometimes tries to access contexts after they have been removed.

Testing: Should be covered by existing tests.

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Mukilan Thiyagarajan <mukilan@igalia.com>
2025-11-18 16:45:24 +00:00
Jonathan Schwender
2028dabd2f profiling: Add abstraction over tracing-rs (#40160)
There are multiple motivating factors for this change:

1. `tracing-rs` can and is commonly used for structured logging, to gain
understanding in what is happening in concurrent code. We would like to
attempt to make a distinction of the performance tracing related usage
and the logging related usage.
2. This reduces boilerplate code. We don't have to feature guard every
span anymore, since the macro will do it for us.
3. This makes it easier to add multiple options for the trace backend
(i.e. exchanging tracing-rs for hitrace on OpenHarmony or System Tracing
in Android), or something entirely custom.
4. This makes it easier to add further compile-time options to control
the amount of tracing. E.g. a future PR could add options to enable
tracing based on environment variables set at compile time. Tracing adds
runtime overhead, even if the runtime switch is disabled, so having more
fine-grained options to partially enabled tracing could be useful.

Testing: Tested manually by building with and without the `tracing`
feature. In CI we also build with the tracing feature in the HarmonyOS
build. We don't have any automated tests for the correctness / presence
of the traced entries.

---------

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
2025-11-18 10:47:56 +00:00
Martin Robinson
ffae4395fe layout: Rebuild the box tree when the quotes attribute changes on a pseudo-element (#40699)
In incremental layout, changes to the `quotes` attribute of a
pseudo-elment can cause the content of the pseudo-element to change so
should cause a box rebuild. This change does that, hopefully fixing
flaky tests.

Testing: This doesn't have any test changes, but should fix the test
situation described in #40419.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-11-18 08:04:07 +00:00
TIN TUN AUNG
6fda77da05 Media: Display User Agent Controls widget for video element. (#40578)
Add Contents::ReplacedWithWidget for video elements with UA control
widget, to allow Traverse into the children of video element during Box
Tree Construction, Generate
IndependentFormattingContextContent::ReplacedWithWidgets, to store both
the `ReplacedContents` and `BlockFormattingContext`. During fragment
tree generation process, first layout the Image Fragment, and then
Layout the Inner Controls BlockFormattingContext. Doing this allow us to
determine the size of Inner Controls widget based on the size of the
Image Fragment. Minor Fix: ::before/::after pseudo elment should be
suppress for replaced element.

Testing: Should show the controls widget for `<video controls></video>`,
and should not affect any existing WPT test. Since how to display UA
widget of Video Element is not defined in the spec, expectedly there has
no existing WPT test that testing this.
Fixes https://github.com/servo/servo/issues/40452
Fixes https://github.com/servo/servo/issues/31414

---------

Signed-off-by: rayguo17 <tin.tun.aung1@huawei.com>
2025-11-18 07:02:13 +00:00
Euclid Ye
1a08cec029 Revert servo/servo#40594 "Allow WebGL contexts to have different Surfman devices" (#40707)
This reverts commit bcbd4a2f19.

There was too many intermittents:
https://github.com/servo/servo/pull/40699#issuecomment-3544170297. Some
PRs fail to merge.

Testing: It still builds. Number of flaky reduced by half.

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-11-18 03:40:03 +00:00
Martin Robinson
8939240ed8 script: Trigger reflow properly for pseudo-elements with content: attr() (#40698)
When a Node with a pseudo-element style that uses `content: attr()`
has one of its attributes mutated, trigger a reflow starting at that
node. This is a crude implementation, because we currently aren't taking
into account what attributes changed, but at least it works.

Testing: This doesn't have any test changes, but should fix the test
situation described in #40419.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
2025-11-17 23:18:41 +00:00
Martin Robinson
5494995e01 libservo: Add ContextMenuElementInformation to for the context menu API (#40607)
This new data structure allows passing more information when popping up
context menus. It's possible in the future that it will be adapted into
a more generic "hit test result" type API ala WebKit, but for now, this
is probably
enough.

Testing: This change includes new API test assertions.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-17 15:53:43 +00:00
Andrei Volykhin
1301dbfcdf html: Run the <media> play seek if loop attribute was set after playback ended (#40688)
The user agent on the `internal play steps` (step 2) must to seek to the
earliest possible position if the playback has ended, but the definition
of the `ended playback` prevents looping when the loop attribute was
added after playback has ended (already registered whatwg html issue).
```
- playback ended (`ended` event)
- loop = true
- play() (no seeking - playback hasn't ended)
```

Currently this edge case if not yet reflected in the HTML specification
so let's do the same as other browsers and ignore the `loop` attribute
for `play` seek.

See https://html.spec.whatwg.org/multipage/#internal-play-steps
See https://github.com/whatwg/html/issues/4487

Testing: Improvements in the following tests
-
html/semantics/embedded-content/media-elements/playing-the-media-resource/loop-from-ended.tentative.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-17 14:41:52 +00:00
Andrei Volykhin
73f8dce99e html: Fire the <media> canplaythrough event in the expected order (#40685)
Follow the HTML specification, queue a media element task to fire
`canplaythrough` event in expected order (after `canplay`) on the
changing the ready state to `HAVE_ENOUGH_DATA` which align the event
ordering for non-autoplay and autoplay media.

See
https://html.spec.whatwg.org/multipage/#ready-states%3Aevent-media-canplaythrough

The associated WPT PR:
https://github.com/web-platform-tests/wpt/pull/56014

Testing: Improvements in the following tests
-
html/semantics/embedded-content/media-elements/ready-states/autoplay.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-17 11:12:11 +00:00
Kingsley Yung
71de70742e script: Fix wrongly matched normalized algorithm in NormalizedAlgorithm::get_key_length (#40686)
In `NormalizedAlgorithm::get_key_length`, we match the wrong enum
variants for HKDF and PBKDF2. Therefore, the function wrongly returns
`NotSupportedError` for them. It causes a few WPT tests fail. This patch
fix it with correct enum variants.

Testing: Pass some WPT tests that were expected to fail.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-17 10:19:41 +00:00
Mukilan Thiyagarajan
bcbd4a2f19 compositing: Allow WebGL contexts to have different Surfman devices (#40594)
Currently, a single `surfman::Device` is used for all WebGL contexts.
This cannot work when we have multiple rendering contexts. So, extract
the surfman `Connection` and `Adapter` into a per-painter data structure
(`PainterSurfmanDetailsMap`) and store the `Device` directly in the
WebGL context.

This patch also modifies the WebXR traits so that the `Device` doesn't
need to be explictly passed into most methods.

Testing: Should be covered by existing tests.

---------

Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
2025-11-17 10:16:31 +00:00
Taym Haddadi
660238a94c Remove #![allow(dead_code)] from readablestreambyobreader (#40675)
#![allow(dead_code)] not needed in readablestreambyobreader(left over
stream re-implementation)

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2025-11-16 15:32:17 +00:00
Tim van der Lippe
8e0c2d5750 Implement WindowOrWorkerGlobalScope::reportError (#40654)
This web API is alternative API to `throw e`, which is why we can reuse
a lot of the existing machinery.

The one testcase that isn't passing yet is because it reports an empty
`TypeError`. The current logic in `ErrorInfo` only retrieves the message
data, but doesn't include the type of the exception. For that, we need
to use `(*report)._base.errorNumber` and map that back to the original
type codes. However, deferring that to a follow-up as that requires some
more work in mozjs.

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-11-16 09:30:16 +00:00
Ashwin Naren
79d96153ca Fix indexeddb intermitency (#40648)
Fixes a major source of intermittency in IndexedDB: the dispatching of
the complete event. This ensures that all requests are processed before
it is fired.

Fixes: #39162
Fixes: #39221
... and likely many more.

---------

Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
2025-11-16 05:51:49 +00:00
Sam
fa12f7a5e5 script: Add cx_no_gc/cx/realm codegen option and demostrate them (#40582)
Companion to https://github.com/servo/mozjs/pull/650

We added 3 new options to bindings.conf, each more powerful then the
previous one, so one should use the least powerful as possible to keep
things flexible:
1 `cx_no_gc` prepends argument `&JSContext`, which allows creating NoGC
tokens and using functions that do not trigger GC.
2. `cx` prepends argument `&mut JSContext`, which allows everything that
previous one allows, but it also allows calling GC triggering functions.
3. `realm` prepends argument `&mut CurrentRealm`, which can be deref_mut
to `&mut JSContext` (so it can do everything that previous can), but it
also ensures that there is current entered realm, which can be used for
creation of InRealm.

next steps: #40600 

reviewable per commit

Testing: It's just refactoring
try run: https://github.com/sagudev/servo/actions/runs/19287700927

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-11-16 04:53:54 +00:00
Sam
2a03c78498 canvas: Clear bitmap without transform (#38286)
We only need to clear the viewport and with wrong transform this will
not do.

Testing: Existing WPT tests

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
2025-11-15 18:35:31 +00:00
Simon Wülker
1d16f6526d script: Don't rely on Attr nodes when communicating with layout (#40657)
When script is looking up an attribute for layout then it only needs to
care about the attribute value. The `Attr` node itself is not required.
If we want to lazily construct attribute nodes in the future
(https://github.com/servo/servo/issues/36697) then we should use `Attr`
as little as possible.

This also ends up simplifying the code by accident.

Testing: No behaviour change intended, regressions are covered by
existing tests.
Part of https://github.com/servo/servo/issues/36697

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-15 17:59:57 +00:00
Martin Robinson
7d9017a97b script: Eliminate duplicate quirks mode origin check in stylesheet loader (#40646)
This was due to the fact that two PRs doing this landed around the same
time. This PR eliminates the duplicate check.

Testing: This should not change behavior so is covered by existing
tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-15 11:41:30 +00:00
Kingsley Yung
1ec01cc25d script: Housekeeping WebIDL dictionaries of WebCrypto API (#40652)
Housekeeping of WebIDL dictionaries of WebCrypto API, including:

- Add/Fix spec links in `SubtleCrypto.webidl` and `CryptoKey.webidl`.
- Sort dictionaries in `subtlecrypto.webidl` based on the spec.
- Sort the `subtle` structs in `subtlecrypto.rs`, based on the spec.
- Reduce unneeded visibility of those `subtle` structs.

Testing: No behavioral change. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-15 10:17:19 +00:00
Kingsley Yung
33443d21aa script: Use hkdf crate for HKDF in WebCrypto (#40650)
We currently use the crate `aws-lc-rs` for HKDF in the WebCrypto API.
When generating output bytes from the output of HKDF-Expand operation
(OKM, Output Key Material), it enforces the requested output length must
match the length of key type (see error condition of `Okm::fill` at
https://docs.rs/aws-lc-rs/1.14.1/aws_lc_rs/hkdf/struct.Okm.html#method.fill).
However, according to the WebCrypto API specification, user should be
allowed to choose the output length
(https://w3c.github.io/webcrypto/#hkdf-operations-derive-bits). The
restriction from `aws-lc-rs` causes several HKDF-related WPT tests to
fail.

This patch switches to use a more flexible crate `hkdf`
(https://crates.io/crates/hkdf) for implementing HKDF in our WebCrypto
API, and allowing variable length output. This helps to make those
HKDF-related WPT tests pass.

Testing: Pass some WPT tests that were expected to fail.

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-15 09:19:11 +00:00
Martin Robinson
d9b183f39b script: Add support for parsing CSS in parallel (#40639)
This change is a rework of #22478, originally authored by @vimpunk.

It adds parsing of CSS in parallel with the main script thread. The
big idea here is that when the transfer of stylesheet bytes is
finished, the actual parsing is pushed to a worker thread from the Stylo
thread pool. This also applies for subsequent loads triggered by
`@import` statements.

The design is quite similar to the previous PR with a few significant
changes:

 - Error handling works properly. The `CSSErrorReporter` is a crossbeam
   `Sender` and a `PipelineId` so it can be trivially cloned and sent to
   the worker thread.
 - Generation checking is done both before and after parsing, in order
   to both remove the race condition and avoid extra work when the
   generations do not match.
- The design is reworked a bit to avoid code duplication, dropping added
   lines from 345 to 160.
 - Now that `process_response_eof` gives up ownership to the
   `FetchResponseListener`, this change avoids all extra copies.

Testing: This shouldn't change observable behavior, so is covered
by existing tests.
Fixes: #20721
Closes: #22478

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: mandreyel <mandreyel@protonmail.com>
2025-11-15 09:10:27 +00:00
WaterWhisperer
28a8918ebd script: Remove unnecessary Trusted wrapper in RemovableDomEventListener (#40649)
Replace `Trusted<EventTarget>` with `Dom<EventTarget>` and add the
appropriate crown attribute.

Testing: `./mach build --use-crown` succeed and no difference in
behaviour when running `./mach test-wpt tests/wpt/tests/dom/abort`
Fixes: #40631

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-11-15 08:27:34 +00:00
Andrei Volykhin
ac0da57bc1 html: Handle new DurationChanged event by <media> (#40644)
A new event `PlayerEvent::DurationChanged` has been added to the media
engine to simplify handling changes in the duration of a media stream
(sometimes the duration could be inaccurate or even determined by the
media engine with significant delay after the initial metadata was
ready).

This new event eliminates the need to check conditions for two
consecutive `MetadataUpdated` events (the initial metadata and the
metadata with the changed duration) during the loading phase.

servo-media:
- Add new `PlayerEvent::DurationChanged` event
(https://github.com/servo/media/pull/461)

Testing: No expected changes in test results

Fixes: https://github.com/servo/servo/issues/40626

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-14 15:14:13 +00:00
Tim van der Lippe
c782da762b Implement protocol handler web API's behind flag (#40616)
This implements the web-facing API's behind a flag, where we further
design the embedding API in a
follow-up PR.

It passes all relevant WPT tests, since the HTML
specification leaves it up to user agents to
determine when to process these protocol handlers.

It also uses `once_cell` to lazily construct the
regex, which is what the CSP crate also uses for
its regexes [1].

Part of #40615

[1]:
db8f2e97fe/src/lib.rs (L1550-L1569)

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-11-14 12:53:33 +00:00
Kingsley Yung
3d56aaa484 script: Flatten nested match arms in NormalizedAlgorithm (#40643)
This patch flattens nested match arms in `NormalizedAlgorithm` to
simplify our code. Moreover, primarily matching the algorithm names,
instead of matching the enum variant types, makes more sense, since some
algorithms share the same enum variant type.

Testing: Refactoring. Existing tests suffice.

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
2025-11-14 10:33:32 +00:00
Martin Robinson
24daacfabe script: Issue resource timing for stylesheets before the "load" event (#40618)
Tests seem to assume that resource timing is available during the "load"
event. Doing so causes some tests to pass and others to fail, which
appear to have been false passes.

This is a preparatory change for asynchronous stylesheet parsing, when
resource timing entires must be added before sending stylesheets to
another thread for parsing.

Testing: This change updates WPT test results.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-14 07:07:37 +00:00
WaterWhisperer
e4b7962854 script: Fix MutationObserver to use Dom instead of DomRoot (#40608)
converts MutationObserver's record_queue and node_list, as well as
RegisteredObserver's observer field, to use Dom<T> instead.

Testing: `./mach build --use-crown` pass locally
Fixes #40602

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-11-13 19:14:30 +00:00
Simon Wülker
a1269e809d Replace calls to ".filter_map()" followed by ".next()" with ".find_map()" (#40612)
The two are semantically equivalent, but `find_map` is more concise.

Testing: Covered by existing tests

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-13 14:53:57 +00:00