Commit Graph

55 Commits

Author SHA1 Message Date
Martin Robinson
9c9d9c863f Rename compositing and compositing_traits to paint and paint_api (#42066)
This change finishes the big rename associated with the old
`compositing` crates. Long ago, these crates managed a compositor, like
you might find in a traditional web engine. These days, compositing is
done in WebRender so the name has stopped making much sense. Various
structs inside the crates have already been renamed and this is the
final big change necessary for the rename

Testing: This is just a rename so existing tests should cover it.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2026-01-24 09:17:35 +00:00
Laurent Belmonte
0dc28296e0 script: Some failed requests should record resource timing entries (#41804)
Some failed requests should record resource timing entries

Testing: ./mach test-wpt
tests/wpt/tests/resource-timing/entries-for-network-errors.sub.https.html
Fixes: https://github.com/servo/servo/issues/41667

---------

Signed-off-by: bellau <laurent.belmonte@gmail.com>
2026-01-14 13:20:12 +00:00
WaterWhisperer
2a759ed6de Replace allow(crown::unrooted_must_root) with expect(crown::unrooted_must_root) (#41815)
Testing: `./mach build -d --use-crown` with no warnings
Fixes: #41761

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2026-01-10 08:05:49 +00:00
Tim van der Lippe
e2d62531f5 script: Consolidate global initialization for fetch requests (#41663)
Rather than having each callside specifying the relevant
information from the GlobalScope, do this via a trait instead.
This would have saved us quite a bit of test debugging
since we would often forget to set relevant information
from the global context for a request.

Now, in the future when we need additional information from
the globalscope for a request, we only need to update this
method to make that happen.

Previously it would also sometimes use `document`, but
calling the relevant information on either `document` or
`globalscope` doesn't matter, since the `globalscope`
defers to the value from the `document` anyways.

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-01-07 13:22:03 +00:00
Tim van der Lippe
d44c38998c net: Keep track of size of keep-alive records (#41457)
These keep-alive records live on the `CoreResourceManager` since the vec
of records must be modified by the fetch thread. The script thread
sometimes
requires this information as well, which is why it can send a message to
obtain the total size.

The keep-alive records must be tracked per global. That's why all code
needs
to specify the `pipeline_id`. Requests optionally have this field, which
is why
the code expects it to be present. The relevant information is added to
the
navigator request to ensure it can compute it.

Fixes #41230

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2026-01-05 18:22:58 +00:00
aquaThirsty
d808cc15d0 change #[allow]s to #[expect]s (#41635)
Changed most #[allow]s to #[expect]s, mainly for
clippy::too_many_arguments

Removed unfulfilled expectations

This is my first opensource contribution, so please let me know if
anything should
be done differently.

Testing: Refactor
Part of: #40838

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: TimurBora <timurborisov5561@gmail.com>
Co-authored-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
2026-01-03 10:54:27 +00:00
Narfinger
15aa6ee8c0 Base: Rename IpcSharedMemory to GenericSharedMemory (#41198)
In the future, servo components should depend on the generic channels in
base instead of IpcChannels to correctly optimize for multiprocess vs
non-multiprocess mode.
This reexports IpcSharedMemory as GenericSharedMemory in GenericChannel
and changes all dependencies on it.

Currently this is only a type/name change and does not change
functionality. But in the future we would want want to use non-ipc
things for the data.

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>

Testing: This changes types and does not need testing.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-12-31 13:07:59 +00:00
Tim van der Lippe
0de7b23a7b script: Initialize all requests with clients (#41584)
In preparation for adding preload support for all requests, we need to
add relevant client information to all these entrypoints. Additionally,
for links we now also set the referrer correctly and initialize
documents. All of which are required to start loading preload
information when processing requests.

Part of #35035

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2025-12-30 13:10:29 +00:00
Tim van der Lippe
d8bf293828 script: Remove Drop implementation of FetchCanceller (#41384)
Instead, we now explicitly call `.terminate()` and introduce relevant
methods to FetchCanceller.

Follow-up from review in #41345

---------

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Tim van der Lippe <TimvdLippe@users.noreply.github.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
2025-12-19 08:31:09 +00:00
Tim van der Lippe
3ac02bc6ac script: Mark fetch-later requests as keep-alive (#41345)
This implements the required plumbing for the keep-alive flag on
requests. The flag already exists on the request object, but now also
exists on the builder itself.

The flag is then passed into a canceller. While we could make canceller
optional, in many cases it isn't and would require a whole lot more
changes. To follow the spec more closely, opted to put the keep_alive
flag on the canceller as well.

Note that this doesn't pass any extra fetch-later tests since we are not
correctly unloading iframe documents. That will be fixed in a follow-up
PR.

Part of #41230

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-12-18 19:49:13 +00:00
Martin Robinson
824f551f03 Rename IOCompositor to Paint (#41176)
For a long time, the "Compositor" hasn't done any compositing. This is
handled by WebRender. In addition the "Compositor" does many other
tasks. This change renames `IOCompositor` to `Paint`.

`Paint` is Servo's paint subsystem and contains multiple `Painter`s.
This change does not rename the crate; that will be done in a
followup change.

Testing: This just renames types and updates comments, so no new tests
are necessary.

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-12-10 15:09:49 +00:00
Andrei Volykhin
807979b40a script: Decouple ownership of the media element from IPC router callback (#41131)
Added new invocation struct `HTMLMediaElementEventHandler` that allows
to decouple ownership of the `HTMLMediaElement` from the IPC router
callback (break cyclic reference dependency) by replacing a `Trusted`
wrapper with more suitable `WeakRef`.
Note that `WeakRef` is not thread-safe and MUST be rooted and/or deleted
on the script thread.
    
Testing: Regressions in the following tests caused by overly aggressive
GC on document activity change to `Inactive` and will be follow up in
https://github.com/servo/servo/issues/41138
-
html/semantics/embedded-content/media-elements/autoplay-allowed-by-feature-policy.https.sub.html
-
html/semantics/embedded-content/media-elements/autoplay-default-feature-policy.https.sub.html
-
html/semantics/embedded-content/media-elements/autoplay-disabled-by-feature-policy.https.sub.html

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

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-12-10 14:41:42 +00:00
Taym Haddadi
d10d481016 Guard MediaElementAudioSourceNode against closed contexts and add crash test (#41092)
Guard MediaElementAudioSourceNode against closed contexts and add crash
test

Testing: Added crash test.
Fixes: #41083

---------

Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
2025-12-06 16:39:36 +00:00
Anonmiraj
b207be05d9 change some allows to expects (#41040)
Changed some allow to expects and removed the unfulfilled expectations.

Testing: Refactor
Part of: #40383

Signed-off-by: anonmiraj <nabilmalek48@gmail.com>
2025-12-05 07:23:32 +00:00
Andrei Volykhin
9a1d86cc88 html: Change the play state of the media player if the old is opposite (#41027)
It's important to check the media player's `paused` state to avoid
unnecessary changes to its internal state (via `play`, `pause`),
including configuration the `playback rate` and `volume` properties.

Depends on https://github.com/servo/media/pull/467

Testing: The expected test results are unchanged because it is the
implicit performance improvements of the media stack, with the exception
of the following test, which is affected by the `playback rate` state
caching mechanism (the `seek` position is not overridden for default
playback rate (1.0)).
- html/semantics/embedded-content/media-elements/preserves-pitch.html

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4762

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-12-04 12:19:48 +00:00
Andrei Volykhin
d539ac8cf3 html: Track the script/UA initiated media seek request (#40981)
The low-level media `seek` request could be initiated by script (DOM
method call or setting of an IDL attribute), by the user agent (seeking
data) or by the media engine itself (e.g. gst_play_set_rate()).
And to distinguish between them we will use the latest seek position (in
seconds) to be able abort processing the `seek` algorithm steps (13-17)
for a `seek` request initiated by the media engine.

See https://html.spec.whatwg.org/multipage/#dom-media-seek

If the `seeking` is in progress, any callback which affects the current
playback position (`position changed`, `end of the playback`) shouldn't
be processed (event marshalling over IPC router is non-state
conditional).

Testing: Regression in the following test causes by gstreamer issue when
the `gst_play_set_rate()` overrides the latest seek requested position
unconditionally and the user agent receives the `seek completion` event
with the unexpected seek position (0.5+ instead of 0.0).
- html/semantics/embedded-content/media-elements/preserves-pitch.html

See https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4762

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

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-12-02 11:27:21 +00:00
Andrei Volykhin
155dc71a65 script: Fire the video resize event in the expected order (#40940)
Queuing a media element task given the media element to fire an event
named `resize` at the media element shoud be done:
- upon the initial `metadata` event from the media engine

https://html.spec.whatwg.org/multipage/#loading-the-media-resource:event-media-resize
- whenever the video dimensions are changed (readyState is not
`HAVE_NOTHING`)

https://html.spec.whatwg.org/multipage/#the-video-element:event-media-resize

See https://html.spec.whatwg.org/multipage/#event-media-resize

Testing: Added new test to confirm `resize` event ordering
-
html/semantics/embedded-content/media-elements/event_order_durationchange_resize_loadedmetadata.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-12-01 08:17:35 +00:00
Andrei Volykhin
a516b74ffa html: Update the media player state without delays (#40898)
Currently the sequence order of the DOM method calls and the media
player API calls is mismatched because some media player operations (*)
posted to media task with delayed processing (while should be processed
immediately).
- DOM (script): pause -> seek -> play
- Media: seek -> pause* -> play*

Also the associated queued media events can be fired and processed by
script somehow (e.g. by calling `seek` in event listener handler) even
before the calling of the media player `play/pause` API.

To handle it the application will try to update media state (by calling
media player API) on each DOM `play, pause` method calls and on some
`ready state` changes with checking if the media element can be
potencially playing.

See https://html.spec.whatwg.org/multipage/#potentially-playing

Testing: No expected testing results changes because there are
unexpected `seek completion` signals from the media engine with invalid
time positions which are affecting passing test score (by masking false
positive results).
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4762

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-27 20:06:40 +00:00
Andrei Volykhin
87e8e1ac50 html: Add new media tracks when receiving the initial media metadata event (#40917)
The new audio/video tracks should be added to the media element from the
initial `metadata` event from the media engine because there are
possibility of the multiple `metadata` events without any associated
`media track` state changes and previously the application added new
tracks into lists unconditionally.

The registered issue to handle possible dynamic `media track` state
changes from the media engine gracefully.
https://github.com/servo/media/issues/473

Testing: Improvements in the following tests
-
html/semantics/embedded-content/the-video-element/video_size_preserved_after_ended.html

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

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-27 07:45:59 +00:00
Andrei Volykhin
a5a475cfd8 html: Fix handling of the media playback EnoughData event (#40881)
The media engine signals with the `PlayerEvent::EnoughData` event that
the media source has enough data and the application should stop pushing
more data to avoid excessive buffer queueing and wait
`PlayerEvent::NeedData` event to continue.

Note that the source buffer size - MAX_SRC_QUEUE_SIZE (50MB).

This event is reflecting the state of the media source so the
application shouldn't change the media element ready state somehow.

Testing: No expected testing results changes

Fixes (partially): https://github.com/servo/servo/issues/40740

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-25 16:14:26 +00:00
Andrei Volykhin
2937300a9e html: Update MediaSession setPositionState method (#40793)
The MediaSession `setPositionState` method should only update the
position state and propagate it to the platform media session UI
controller and shouldn't change somehow the properties of the media
element directly (duration, playback rate or position).
    
See
https://w3c.github.io/mediasession/#dom-mediasession-setpositionstate
    
Testing: Improvements in the following tests
- /mediasession/positionstate.html
    
The media session UI functionality is implemented for Android and didn't
test due lack of testing sample.

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-24 16:47:36 +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
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
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
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
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
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
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
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
Andrei Volykhin
c19641e3fe html: Add <media> current and official playback positions (#40609)
Follow the HTML specification and split the previous `playback position`
to `current playback position` (a time on the media timeline) and
`official playbac position` (an approximation of the current playback
position that is kept stable while scripts are running) which must be
set to `the current playback position` any time the user agent provides
a stable state.

See https://html.spec.whatwg.org/multipage/#current-playback-position
See https://html.spec.whatwg.org/multipage/#official-playback-position

Note that at this point, there are no difference between the `current`
and `official` playback positions (as the time on the media timeline),
except the `seek` case.

Testing: Improvements in the following tests
-
html/semantics/embedded-content/media-elements/seeking/seek-to-max-value.htm
-
html/semantics/embedded-content/media-elements/seeking/seek-to-negative-time.htm

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

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-13 11:42:41 +00:00
Andrei Volykhin
6bb012b76b html: Add <media> internal ended_playback method (#40603)
Following the HTML specification, a new internal method,
`ended_playback`, has been added to differentiate it from the `ended`
attribute:
- `ended_playback`: playback has ended for the `forward/backward`
directions
- `ended` attribute: playback has ended for the `forward` direction

See https://html.spec.whatwg.org/multipage/#ended-playback

Added descriptions for the steps of the `Play`, `Pause`,
`internal_play_steps` (new), `internal_pause_steps`,
`notify_about_playing`, `change_ready_state` methods.

Testing: No expected changes in test results.

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-13 08:32:52 +00:00
Andrei Volykhin
59526928af html: Remove canGC argument from <media> internal seek method (#40587)
The `seek` method isn't explicitly exposed in the API, but is called
from various places (`currentTime`, `fastSeek`, by the `media metadata`
event) and doesn't itself create new DOM objects, so the `canGC`
argument can be omitted.

It was previously required because calling the `Seekable` method creates
a new `TimeRanges` object, but it will now be replaced by the internal
`seekable` method to avoid interaction with the JavaScript engine (and
potential garbage collector).

The `earlyest possible position` method has been changed to match the
specification and use `seekable` instead of `played`. See
https://html.spec.whatwg.org/multipage/#earliest-possible-position

Testing: No expected changes in tests

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-12 18:44:15 +00:00
Andrei Volykhin
4d938368cb bump(deps): bump servo-media from 5b788a9 to 8aca9f7 (#40563)
Updated the `PlayerEvent::PositionChanged/SeekDone` events to support
precise position timestamps (u64 -> f64).
    
Also set precise time value (seconds with fractional part) for the
HTMLMediaElement `duration` from media metadata to sync with
`PlayerEvent` changes.

servo-media:
- Pass precise position timestamp within PlayerEvent
(https://github.com/servo/media/pull/460)

Testing: No expected changes in test results

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-12 15:43:34 +00:00
Martin Robinson
bfde51c0db script: Have FetchResponseListener::process_response_eof consume the listener (#40556)
The goal of this change is to prevent having to copy so much data out of
listeners when a fetch completes, which will be particularly important
for off-the-main thread parsing of CSS (see #22478). This change has
pros and cons:

Pros:
- This makes the design of the `FetchResponseListener` a great deal
simpler.
They no longer individually store a dummy `ResourceFetchTiming` that is
   only replaced right before `process_response_eof`.
 - The creation of the `Arc<Mutex<FetchResponseListener>>` in the
   `NetworkListener` is abstracted away from clients and now they just
   pass the `FetchResponseListener` to the fetch methods in the global.

Cons:
 - Now each `FetchResponseListener` must explicitly call `submit_timing`
   instead of having the `NetworkListener` do it. This is arguably a bit
   easier to follow in the code.
 - Since the internal data of the `NetworkListener` is now an
   `Arc<Mutex<Option<FetchResponseListener>>>`, when the fetching code
   needs to share state with the `NetworkListener` it either needs to
   share an `Option` or some sort of internal state. In one case I've
   stored the `Option` and in another case, I've stored a new inner
   shared value.

Testing: This should not change observable behavior and is thus covered
by existing tests.
Fixes: #22550

---------

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-11 22:30:40 +00:00
Andrei Volykhin
9efe79065e dom: Add the attribute mutation reason (#40527)
For some specific cases (one of them see below) where are requirement to
identify the reason of the attribute mutation (by whom/why it was
changed - by cloning, parser or directly), so the following `reason`
parameter was added to `AttributeMutation::Set` option.

Note that for the HTMLMediaElement the internal `muted` state should be
set to true when the element is created and the element has a `muted`
content attribute specified (should be done once on the first attribute
mutation caused by parser or cloning).

See https://html.spec.whatwg.org/multipage/#dom-media-muted

Testing: Improvements in the following tests
-
html/semantics/embedded-content/media-elements/user-interface/muted.html

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-10 10:09:03 +00:00
Andrei Volykhin
c67ef13d7c html: Render media controls without ready state precondition (#40456)
Follow the specification and allow to render media controls (expose a
user interface to the user) without any HTMLMediaElement `readyState`
precondition.

The media controls be shown for the following examples without specified
media source (e.g. without `src` attribute).
```
<audio controls></audio>
<video controls>/<video>
```

See https://html.spec.whatwg.org/multipage/media.html#user-interface

For media controls UI don't define root `div` element's style `width`
property from the video natural size (`videoWidth/Height` IDL attributes
which return `0` if `readyState` is `HAVE_NOTHING`).

When the `media` element is adopted between different documents need
adopt the media controls id, so media controls UI
will keep access to the whilelist of media controls identifiers via
`document.servoGetMediaControls(id)` API.

Testing: Improvements in the following tests
-
html/rendering/replaced-elements/embedded-content-rendering-rules/audio-controls-00*
-
html/semantics/the-button-element/command-and-commandfor/on-audio-behavior.tentative.html
-
html/semantics/the-button-element/command-and-commandfor/on-audio-invalid-behavior.tentative.html
Note that `Invoker Commands` API is not yet supported so these `command
and commandfor` tests should fail, but due to previous bug with delayed
media controls shown up. The invoker `onClick` function send actions
with mouse events
(move/up/down) to the test driver at the position of the button element
(via getBoundingClientRect), but before test driver
will handle these actions the mediadata is received and media controls
are shown up with "play" button at this position.
So the media control "play" button is clicked instead of the button, and
it triggers media element `pause` state change.
  See https://open-ui.org/components/invokers.explainer/

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-08 19:57:59 +00:00
WaterWhisperer
401165f154 script: Add message to IndexSizeError (#40463)
Adding an optional message to be attached to a IndexSizeError.

The enum definition of IndexSize is now `IndexSize(Option<String>)`.
Future PRs should probably add more appropriate messages to some of the
`IndexSize(None)`s.

Testing: Just a refactor
Fixes: Partially #39053

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-11-07 01:08:00 +00:00
Martin Robinson
8f6edca4dd net: Simplify FetchResponseListener and move it to script (#40461)
`FetchReponseListener` has traditionally lived in `net` even though it
is only used in `script` currently. Because of the two way dependency,
it has also use a lot of templating to implement something pretty basic
(call methods on a trait object).

This change moves the trait to `script` and removes several levels of
templating, making the code quite a bit shorter and easier to
understand.

This change is preparation for fixing #22550 and implementing
off-the-main-thread CSS parsing.

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

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
2025-11-06 14:44:01 +00:00
WaterWhisperer
158bf97e30 script/dom/: Change some #[allow]s to #[expect]s (#40454)
Removes some unneeded lints, especially `#[allow(unsafe_code)]`.

Testing: Refactor
Part of: #40383

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-11-06 11:06:03 +00:00
Andrei Volykhin
66c990e373 html: Support releasing of <media> underlying resources and frames (#40316)
The HTMLMediaElement should stop playback of any previously playing
media resource on running media element loading algorithm or before
attempt to load next source child.

This step will reset media player (including release of the underlying
media resources and media frames from the video renderer).

The closure for marshalling the incoming GLPLayer messages from ROUTER
("router-proxy") thread to script thread will use
`Weak<MediaFrameRenderer>` instead of `Trusted<HTMLMediaElement>` to
break circular references dependency (decouple ownership).

The media frame renderer will track the media player id to be able
ignore async locking render call with new frame after playback of any
previously playing media was stopped.

Testing: No WPT test expectation changes

Fixes (partially): https://github.com/servo/servo/issues/40243
Fixes (partially): https://github.com/servo/servo/issues/40265
Fixes: https://github.com/servo/servo/issues/37173

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-11-05 08:52:43 +00:00
Simon Wülker
c4ae451612 Turn all commented links before functions into doccomments (#40331)
Servo has a lot of comments like this:
```rust
// https://example-spec.com/#do-the-thing
fn do_the_thing() {}
```
and I keep turning these into doc comments whenever I'm working close to
one of them. Doing so allows me to hover over a function call in an IDE
and open its specification without having to jump to the function
definition first. This change fixes all of these comments at once.

This was done using `find components -name '*.rs' -exec perl -i -0777
-pe 's|^([ \t]*)// (https?://.*)\n\1(fn )|\1/// <$2>\n\1$3|mg' {} +`.

Note that these comments should be doc comments even within trait `impl`
blocks, because rustdoc will use them as fallback documentation when the
method definition on the trait does not have documentation.

Testing: Comments only, no testing required
Preparation for https://github.com/servo/servo/pull/39552

---------

Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
2025-11-01 05:32:45 +00:00
WaterWhisperer
32c0c41d11 script: Move performance DOM interfaces to script/dom/performance/ (#40262)
Moves interfaces defined by the performance spec to the
`script/dom/performance/` module from `script/dom/`.

Testing: Just a refactor shouldn't need any testing
Fixes: Partially #38901

Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
2025-10-29 11:41:52 +00:00
TIN TUN AUNG
db3ccd9917 Media: Change of Volume of video tag should passed to player (#40203)
When changing the 'volume' attribute of media element, should also call
`set_volume()` api of underlying player if it is valid value.

Testing: No Test is required, as this should not affect any WPT Test
Fixes: N/A

---------

Signed-off-by: rayguo17 <rayguo17@gmail.com>
Signed-off-by: TIN TUN AUNG <62133983+rayguo17@users.noreply.github.com>
Co-authored-by: Euclid Ye <yezhizhenjiakang@gmail.com>
2025-10-27 04:19:56 +00:00
Yerkebulan Tulibergenov
1f6c4f0180 add CanGc as argument to methods in HTMLMediaElement (#40179)
add CanGc as argument to methods in HTMLMediaElement

Testing: These changes do not require tests because they are a refactor.
Addresses part of https://github.com/servo/servo/issues/34573

Signed-off-by: Yerkebulan Tulibergenov <yerkebulan@gmail.com>
2025-10-26 07:48:57 +00:00
Andrei Volykhin
f214511102 html: Enhance media network and decoding error handling (#39899)
The 'media' element has multiple media data processing steps for media
source loading and requires properly handling any media network and
decoding errors between different components:
- element (resource selection algorithm)
- fetch context/listener (async response)
- media backend (async playback events)

The fetch listener will stop processing any actions (response/chunk/eof)
in case if current fetch request was cancelled (due to a
network/decoding error or it was aborted by user).

Also send EOS event to media backend ONLY once the entire media resource
has been fetched so media pipeline will not generate decoding (playback)
error for fetched empty sources (eg. "about:blank" or "data:,").

See
https://html.spec.whatwg.org/multipage/#media-data-processing-steps-list

Testing: No changes in WPT test expectations

Fixes: https://github.com/servo/servo/issues/39759 ("about:blank")
Fixes: https://github.com/servo/servo/issues/38980 ("data:,")

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-10-23 08:04:39 +00:00
Domenico Rizzo
26ec583802 script: Add CanGc to Seekable method in HtmlMediaElement (#40033)
Refactored Seekable and Seek method in HtmlMediaElement, adding CanGC
argument on all its calls.

Testing: No tests needed
Fixes: #39944

---------

Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
2025-10-21 21:21:33 +00:00
Narfinger
423800eec4 Script: Lazily transform the DOMString into Rust String instead of immediately. (#39509)
This implements LazyDOMString (from now on DOMString) as outlined in
https://github.com/servo/servo/issues/39479.
Constructing from a *mut JSString we keep the in a
RootedTraceableBox<Heap<*mut JSString>> and transform
the string into a rust string if necessary via the `make_rust_string`
method.
Methods used in script are implemented on this string. Currently we
transform the string at all times.
But in the future more efficient implementations are possible.

We implement the safety critical sections in a separate module
DOMStringInner which allows simple constructors, `make_rust_string` and
the `bytes` method.
This method returns the new type `EncodedBytes` which contains the
reference to the underlying string in either format.

Testing: WPT tests still seem to work, so this should test this
functionality.

---------

Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
2025-10-09 18:18:03 +00:00
Andrei Volykhin
7d811f1d2a html: Support selecting <media> element source from children (#39717)
Follow the HTML implemetation and support selection of the 'media'
element loading source from 'source' children elements with validation
processing over their 'media/src/type' attributes.

See https://html.spec.whatwg.org/multipage/#concept-media-load-algorithm

To handle loading with multiple 'source' children was introduced source
children pointer to track the remaining unprocessed 'source' elements
after the resource selection algorithm was invoked.

Testing: Changes in the following tests
with improvements:
-
html/semantics/embedded-content/media-elements/loading-the-media-resource/*
- webgl/tests/conformance/textures/misc/texture-video-transparent.html

with regressions (after enabled 'source' type attribute validation):
- content-security-policy/media-src/media-src*
- mixed-content/gen/top\*audio|video-tag*
- resource-timing/initiator-type/*

Fixes: https://github.com/servo/servo/issues/21481
Fixes: https://github.com/servo/servo/issues/34127

Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
2025-10-09 17:56:11 +00:00
Tim van der Lippe
6a0f9d1bcb Define conditional_malloc_size_of for all Rc (#39660)
This updates all Rc that were ignored for malloc_size_of to use
conditional_malloc_size_of, unless the type in the Rc itself doesn't
support malloc_size.

Regular expressions used to search for all occurrences:

```
ignore_malloc_size_of = "Rc.*"
ignore_malloc_size_of = "Arc.*"
```

There are a couple left since they have nested Rc, which I don't know
how to fix.

To be able to define these, several new implementations were added to
`malloc_size_of/lib.rs` as well as
`HashMapTracedValues`.

Testing: if it compiles, it's safe

Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
2025-10-05 15:12:16 +00:00