Add a helper function `JsonWebKey::set_key_ops` for setting JsonWebKey
key_ops attribute to a given list of key usages. This task is very
common in export key operation of different cryptographic algorithms.
Adding this helper function helps simplify our code.
Testing: Refactoring. Existing tests suffice.
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Companion of #41428, which added helper functions to handle JsonWebKey
common decoding tasks.
This patch adds a helper function `JsonWebKey::encode_string_field` to
handle common base64url encoding tasks across multiple algorithms.
Testing: Refactoring. Existing tests suffice.
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This PR adds support for using new JSContext/CurrentRealm to promise and
adds some more helpers that will ease migration to new context model.
Second commit has another demo.
Testing: Covered by WPT
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@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 replaces a couple calls to `Iterator::fold` with
`Iterator::sum`.
Testing: No tests, this is a small cleanup PR.
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
`malloc_size_of` depends on `tendril` having the `encoding_rs` feature
turned on, but this was only turned on transitively via `html5ever` and
`script`/ `script_bindings` `tendril` dependencies. This change makes it
so that `malloc_size_of` depends directly on `tendril` and moves this
dependency to the root `Cargo.toml`.
Testing: This just fixes a particular build configuration.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Moves the concept of databases closer to the 3.0 spec, by implementing
the delete functionality, and the method returning current databases to
script.
Testing: WPT tests with new passes
Fixes: The "Implement databases deletion and `databases`" item of
https://github.com/servo/servo/issues/40983
---------
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Add placeholder implementation of DOM `VisualViewport` according to the
spec https://drafts.csswg.org/cssom-view/#visualviewport. This is the
first step of implementing the interface and syncing it with the
`PinchZoom` struct that we had in the `Embedder`.
Since this interface's is not accurate and couldn't fulfill it's
purpose, it would be gated behind a preference
`dom_visual_viewport_enabled` and would be open after the interface had
been integrated with `PinchZoom`, viewport resizing, and viewport
scroll.
Testing: Existing WPT Test.
Part of: #41341
---------
Signed-off-by: Jo Steven Novaryo <steven.novaryo@gmail.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>
This change reworks the logic for finding font fallbacks to make it
simpler. I was involved with writing the code for `FontGroupFamily` and
`FontGroupFamilyMember` and I still struggle a bit with understanding
it, so I've chosen to do this. In addition, the change is in preparation
for more flexible font fallback (#41426).
The main changes here are:
1. Move the logic for creating a new descriptor with variations into
the Font constructor.
2. Add some more general methods to `FontGroupFamily` such as a
template iterator.
3. Use `OnceLock` to avoid a convoluted code structure because of
mutability and also having boolean "loaded" members. This is what
`OnceLock` and `OnceCell` are for!
4. Rename `FontGroupFamilyMember` to `FontGroupFamilyTemplate` to
stress that it is one template of a particular `FontGroupFamily`.
Testing: This should not change behavior so is covered by existing WPT
tests.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
When the original display of an absolutely positioned element changes,
the static position can be affected. However, the static position is
only used when both insets in the same axis are `auto`.
Therefore, this patch avoids dirtying the box tree when both axes have a
non-auto inset.
Testing: Not needed, this should have no observable behavior change
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Add several helper functions to JsonWebKey to handle common base64url
decoding tasks across multiple algorithms. Those helper functions
include:
- `JsonWebKey::decode_optional_string_field`: decode optional field
- `JsonWebKey::decode_required_string_field`: decode required field
- `JsonWebKey::decode_primes_from_oth_field`: decode oth field to primes
These help simplify our code for importing keys in JsonWebKey format.
Testing: Refactoring. Existing tests suffice.
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Fill in the error messages across
`script/dom/subtlecrypto/aes_operations.rs` that were still left as
`None`.
Testing: No tests added as these are just error messages.
Addressing: #40756
---------
Signed-off-by: PaulTreitel <paul.treitel@gmail.com>
Put the Gamepad API and its supporting infrastructure behind a `gamepad`
feature flag. This allows embedders to opt-out of gamepad support at
compile time to save on binary size and reduce dependencies.
Testing:
1. `./mach build -d` (Gamepad enabled by default)
2. `cargo build -p servoshell --no-default-features --features
"libservo/clipboard,js_jit,max_log_level,webgpu"` (Gamepad Disabled)
3. `cargo build -p servoshell --features "gamepad,webxr,..."` (Gamepad &
WebXR Enabled)
Fixes: #40897
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
This PR adds an initial `site_data` API to `SiteDataManager`, allowing
embedders to obtain a unified list of sites that have associated site
data.
The implementation introduces supporting infrastructure across storage
and
`SiteDataManager` layers, including a small helper for obtaining
WebStorage
origins and initial support for filtering by storage type. At this
stage,
sites correspond directly to origins, future work will extend this to
higher
level grouping (e.g. domain or eTLD+1).
Testing: Added a new integration test covering site data behavior across
localStorage and sessionStorage.
---------
Signed-off-by: Jan Varga <jvarga@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>
Implement clone_body_stream_for_dom_body to follow
https://fetch.spec.whatwg.org/#concept-body-clone, teeing the
ReadableStream and wiring the branched streams back into the original
and cloned bodies.
Use clone_body_stream_for_dom_body in Request::clone_from and
Response::Clone so their body cloning follows the Fetch spec algorithms
for request/response cloning, including the shared body stream.
Testing: more WPT test should pass.
Fixes: #36503
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
Another step towards being spec-compatible. Right now
we can't destroy an unsalvagable document during unloading,
as that breaks all kinds of tests. Before that, we need
to update various machinery to handle destroying correctly.
The first one is a top-level navigable, which explicitly
destroys a document after it is unloaded.
Part of #31973
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
For all upcoming and already-processed deferred fetches, we now
implement a quota. We don't support policy headers yet to configure the
quota, hence we use the default quota. That's why we have some tests
failing again.
It involves computing which document to compute the quota for, as well
as computing total length of requests. Additionally, the DevTools
computation for headers now uses the same logic for headers as deferred
fetches.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Servo currently completely ignores `<meta charset>` tags. When we find
one with an encoding that is incompatible to the current one, then we
should reload the page and start over with the new encoding. A common
optimization that has even made its way into the specification is to
wait for a few bytes to arrive and inspect them for `meta` tags, so the
browser is able to use the correct encoding from the very beginng.
In practice, I've run into problems with our WPT harness when reloading
the page after `meta` tags. Therefore, this change implement the
optimization first, so we never have to reload when running WPT. I've
implemented prescanning in a way where we wait for 1024 bytes to arrive
or for one second to pass, whichever one happens first.
This causes a large number of web platform tests to flip around. I've
looked at most of the new failures and I believe they're reasonable.
Testing: New tests start to pass.
Part of https://github.com/servo/servo/issues/6414
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
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>
For some dictionaries in SubtleCrypto interface, we store the hash field
of `HashAlgorithmIdentifier` type as a `SubtleKeyAlgorithm`. The
conversion to `SubtleKeyAlgorithm` is unnecessary. Moreover,
`SubtleKeyAlgorithm` is not supposed to be used there.
This patch fixes it by simply storing them as the normalized algorithm
given by Step 10.1.3 of normalization [1], for those hash field of
`HashAlgorithmIdentifier` type.
[1]
https://w3c.github.io/webcrypto/#algorithm-normalization-normalize-an-algorithm
Testing: Refactoring. Existing tests suffice.
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
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>
Uses bloom filters in `MatchingContext` to make selector matching more
efficient. This seems to improve Speedometer score a bit.
Testing: no new test for that small optimization.
Signed-off-by: webbeef <me@webbeef.org>
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>
dblclick on text inputs was being dispatched to an internal element used
for the input, not to the <input> itself. As a result, page scripts
listening for dblclick on the input never received the event.
Testing: tested manually.
Fixes: #41303
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
All the new nodes will be `adopt`-ed inside the respective calls to
`Node::insert` anyways.
Testing: Hopefully no regressions?
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
I added error handling for handle_open_db but I also added it to
SqliteEngine::new and handle_sync_operation because we also open db
there, so I am not sure about these two.
part of #40983
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
Route console messages through the embedding API instead of printing
directly, giving embedders control over console output handling.
Testing: Should be covered by exsisting tests
Fixes: #41145
Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Finish adding RSA-OAEP support to WebCrypto API, by implementing the
encrypt and decrypt operations of RSA-OAEP.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41113
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Fix hashchange only queue when fragment actually changes
Testing: tested it manually for now.
Fixes: #41304
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
This is the first part of preparation for implementing the keepalive
flag for requests. It requires implementation of the concept of a task
group, which we already sort of have with `DocumentLoader`. Therefore,
we currently already cancel any loads, which should be updated to
ignored kept-alive requests.
However, termination also requires storing of deferred fetches, which
are also kept-alive. Therefore, to distinguish the two, we need to store
them separately as stated with the TODO.
In a follow-up, we can then skip canceling keep-alive requests for both
`navigator.sendBeacon` (which aren't deferred) and `fetchLater` (which
are deferred).
Part of #41230
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
add error messages for `encrypt_aes_ctr`, `encrypt_aes_cbc`, and
`decrypt_aes_cbc`
Related issue: #40756
For some of the messages I just used the `fmt::Display` of `UnpadError`,
but maybe these messages should be more specific?
---------
Signed-off-by: César Pedraza <cpedraza@unal.edu.co>
Finish adding RSA-PSS support to WebCrypto API, by implementing the sign
and verify operations of RSA-PSS.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41113
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Finish adding RSASSA-PKCS1-v1_5 support to WebCrypto API, by
implementing the sign and verify operations of RSASSA-PKCS1-v1_5.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41113
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
lot of RefCell already borrowed crashes are because of code like this:
```
if let Some(index) = self
.array
.borrow()
.iter()
.position(|p| &**p == r_p)
{
self.array.borrow_mut().remove(index);
}
```
this will always panic whenever the position() finds an index, because
the immutable borrow from borrow() is still alive when we call
borrow_mut().
Fix by ensuring the borrow is dropped before taking a mutable borrow (by
computing the index in a separate scope / temporary), then remove
safely.
Testing: added crash test.
Fixes: #41260
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
The import and export key operations of RSA algorithms have been
implemented. We actually don't need some helper functions for
RsaOtherPrimesInfo in JsonWebKey, for those operations. This patch
removes those unused helper functions.
Testing: Existing tests suffices.
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>