The tests were performing exact string matching on the contents of the
request body, so this change allows them to match.
Testing: Newly passing tests.
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
`TextInput` internally stores a rope of text content, one segment for
each line. This change separates out the rope into a separate `Rope`
data structure that can be shared with other parts of Servo.
`TextInput` needs to move through text content in a variety of ways,
depending on the keys pressed when interacting with a text area. This
change provides a unified movement API in both `Rope` and in
`TextInput` ensuring that selection is handled consistently (apart from
a few minor quirks [^1]). This simplifies the code an improves
interactive behavior.
[^1]: One of these quirks is that the edit point will move to
directional end of the motion when collapsing a selection, but only when
moving by grapheme or word (and not by line). These quirks existed in an
undocumented way previously and they are preserved with code comments.
Testing: This is covered by existing unit tests (updated for the new
API) and
the WPT suite.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
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>
This implements waiting for pending preloads, where the preload request
is still fetching the result when the second "real" request is started.
It is
implemented by storing responses in the `SharedPreloadedResources`
which is communicated via `PreloadId` send to the `CoreResourceManager`.
Part of #35035
---------
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
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>
Replace NetworkError::Internal with structured enum variants
- Adds
UnsupportedScheme,CorsViolation,ConnectionFailure,Timeout,RedirectError,InvalidMethod,ResourceError,SecurityBlock,MixedContent,CacheError,InvalidPort,
LocalDirectoryError, variants in NetworkError enum.
- Refactored the usage of NetworkError::Internal(String) to use the
appropriate new variant
Testing: Changes does not require test.
Fixes: https://github.com/servo/servo/issues/36434
---------
Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
Signed-off-by: Usman Yahaya Baba <91813795+uthmaniv@users.noreply.github.com>
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Co-authored-by: Tim van der Lippe <tvanderlippe@gmail.com>
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>
DOM APIs for interacting with selection and text in text inputs
`<input type=text>` and `<textarea>` all accept offsets and lengths in
UTF-16 code units. Servo was not converting all of these offsets into
UTF-8 code units. This change makes it so that this conversion is done
more thoroughly and makes it clear when the code is dealing with UTF-8
offsets and UTF-16 offsets.
Helper functions are added for doing this conversion in both directions
as it is necessary. In addition, a `char` iterator is added for
`TextInput` as it is useful for doing this conversion. It will be used
more completely in the future when a `Rope` data structure is extracted
from `TextInput`.
Finally, specification text is added to all of the DOM implementation
touched here.
Testing: This change includes a new WPT crash test as well as a series
of unit
tests to verify conversion between UTF-8 and UTF-16 offsets.
Fixes#36719.
Fixes#20028.
Fixes#39184.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Creates a new `css.rs` module in `components/script` with helper
functions for CSS value parsing.
Callers no longer need to manually specify document URL, quirks mode,
and error reporter.
Testing: `./mach check`
Fixes: #41541
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
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>
Inside `notify_owner_to_finish` we already retrieve the `ModuleTree`
tied to the corresponding `ModuleIdentity`, but we ended up retrieving
it a second time inside of `run_a_module_script` instead of simply
passing it.
Testing: Covered by existing tests, a simple cleanup.
---------
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
This moves the Unicode offset types to the `base` crate and makes them
generally more usable throughout the Servo codebase. In addition, they
are renamed to use Rust naming and to be a bit more consistent:
- `UTF8Bytes` -> `Utf8CodeUnitLength`
- `UTF16CodeUnits` -> `Utf16CodeUnitLength`
There is also a bit more documentation explaining their use.
This is preparation for fixing issues with UTF-16 offsets in editable
text fields.
Testing: This does not change behavior so existing WPT tests should
suffice.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
In Servo, the `:link` and `:any-link` pseudo-classes correctly match
link elements when they are part of a compound selector whose last
simple selector does not start with them (e.g. `a:link` or `:link b`),
but they do not match when the last simple selector starts with `:link`.
The reason for this seems to be that Stylo uses two methods to determine
whether an element is an (unvisited) link: to call the `is_link()`
method on the `selectors::Element` trait, and to check if the element's
state has `ElementState::UNVISITED` set.
In a browser like Servo which does not support visited styles, these two
checks should be equivalent. However, they turn out not to be, because
Servo never actually sets `ElementState::UNVISITED`.
Since per the HTML spec the `:link` selector applies to all `<a>` and
`<area>` elements that have an `href` attribute, this patch fixes this
by setting `ElementState::UNVISITED` on such elements when the `href`
attribute is set, and by unsetting it when it is removed.
Testing: There are two invalidation-related WPT tests about the
`:any-link` selector that now pass with this patch.
Fixes: servo/stylo#282
---------
Signed-off-by: Andreu Botella <andreu@andreubotella.com>
This change moves the `UserContentManager` abstraction from the
`ServoBuilder` to `WebViewBuilder` so that embedders can inject content
for each `WebView` independently. It also adds basic support for runtime
mutations to the `UserContentManager` API. Only adding new scripts is
currently supported, but future changes will add support for both other
mutations such as removal of scripts and addition & removal of
stylesheets. Future changes could also optimize the way mutations are
propagated to `ScriptThread`s by sending just the "delta" rather than
the whole `UserContents` structure for each mutation.
The `UserContentManager` now becomes just a convenient handle for the
embedders to invoke the mutation API while the actual management of the
manager's content is handled by the Constellation. The mutations are
relayed to the constellation via messages. The change also separates the
serialized version containg the user contents into a new `UserContent`
structure so that the API cannot be misused.
Testing: New unit tests have been added for the different scenarios
involving UserContentManager.
---------
Signed-off-by: Mukilan Thiyagarajan <mukilan@igalia.com>
The `substitute_with_local_script` logic has been refactored into a
standalone function to allow reuse in `script_module.rs` when a module
script's source is fetched and decoded.
Testing: Verified manually by running Servo with a local HTTP server and
a module script, confirming that the local file correctly replaces the
remote one when the `--local-script-source` flag is provided.
Fixes: #41433
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
This is checked if the body is a stream, but the payload calculation
needs to be in a follow-up PR.
Part of #38302
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This method now allows you to pass in a custom registry. The registry
isn't used yet for callers, since we don't support scoped registries.
However, as we now pass in the registry to `Node::clone`, we set the
registry when creating elements and cloning them.
As such, various tests start passing where we set the registry. Some
tests started failing, but they rely on scoped registries which we don't
support yet. These tests thus flipped: those that were erroneously
failing are now passing and vice versa.
Part of #34319
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
The specification has a dedicated method for destroying
documents. Parts of that method were scattered around
various parts of Servo machinery.
This patch consolidates these steps and follow the spec.
Additionally, it now correctly unloads iframes when
they are removed from a parent document.
As a result, the fetch-later WPT test now passes, as
it relies on the correct ordering of iframe unloading
to verify the fetch-later requests are sent.
Part of #31973
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
- Use the generic channel for webdriver.
- Implement try_receive_timeout for GenericReceiver.
Testing: WPT should still work.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
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>
Fixes logging in to lichess.org, since our request body now matches what
other browsers send.
Testing: Newly passing WPT tests.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Use the algorithms introduced in #41109 in more places.
Follow more closely the spec when executing classic scripts, introducing
the concepts of rethrowing and muting errors.
Muting errors is not actually implemented, and will be done in a
followup.
Testing: More tests start passing
Fixes#34199Fixes#27260Fixes#15188
---------
Signed-off-by: Gae24 <96017547+Gae24@users.noreply.github.com>
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>
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>
Changed some allow to expects and removed the unfulfilled expectations.
Testing: Refactor
Part of: #40383
Signed-off-by: anonmiraj <nabilmalek48@gmail.com>
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>
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>
When for example changing the hover state of an element, we were
dirtying it with ContentOrHeritage damage, which forced it to be laid
out again.
This was added in #39102 in order to fix#38989, but for the most part
it's no longer needed.
However, we will now dirty when a `<textarea>` or `<input>` which can be
selected gets or loses focus. This is to ensure that the caret or
selections get correctly updated.
Testing: Manually tested that #38989 is not regressing
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
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>
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>
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>
script: add CanGc as argument to methods in HTMLOptionElement
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>
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>
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>
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>
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>
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>
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>
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>