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>
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: #39162Fixes: #39221
... and likely many more.
---------
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
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>
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>
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>
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>
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>
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: #20721Closes: #22478
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: mandreyel <mandreyel@protonmail.com>
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>
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>
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>
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>
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>
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>
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>
We parse the `parameter` field of the `algorithm` AlgorithmIdentifier
field of `spki` and `pkcs8` of ECDH keys as an object identifier.
However, according to WebCrypto API specification, we should parse it as
an `ECParameters` ASN.1 type defined in [RFC5480].
```plaintext
ECParameters ::= CHOICE {
namedCurve OBJECT IDENTIFIER
-- implicitCurve NULL
-- specifiedCurve SpecifiedECDomain
}
```
Although our current implementation works fine since `ECParameters` is
defined as a `CHOICE` type with an object identifier as the only option,
it is technically incorrect. This patch fixes this mistake.
Testing: No behavioral change. Existing tests suffice.
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
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>
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>
Instead of using a task source for SpiderMonkey runtime callbacks, use a
`ScriptEventLoopSender`. Task sources are associated with a particular
Pipeline, but the runtime callback is run indepenently of any particular
Pipeline and could theoretically happen when no Pipeline exists at all.
This reduces the dependency of the `ScriptThread` on the existence of
the first Pipeline.
Testing: This should not change observable behavior, so is covered by
existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
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>
Have more of the code follow the same path calling
`ScriptThread::spawn_pipeline`. Somewhat tricky was that the `origin` of
the new Pipeline was being determined in several different places, but
all in a consistent way for different types of page loads. This change
makes it is so that the origin is always determined in the same place.
This change is preparation for splitting out the creation of a new
`ScriptThread` and the spawning of its first pipeline.
Testing: This should not change observable behavior, so is covered by
existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Finish adding ECDSA support to WebCrypto API. This patch implements sign
operation of ECDSA, using ECDSA implementation from the crates `ecdsa`
for the operation, `p256`, `p384`, `p521`, and `elliptic_curve` for the
key, and `sha1`, `sha2` and `digest` for digesting messages.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #39060
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
`preceding::` needs to yield all preceding nodes, excluding ancestors.
`following::` needs to yield all following nodes, excluding descendants.
Both `Node::preceding_nodes` and `Node::following_nodes` (which we're
currently using) don't quite match these requirements, so we have to
engineer some xpath-specific iterators.
Testing: New tests start to pass
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
XML and HTML serialization routines relied on a single, shared
implementation of the `markup5ever::Serialize` trait for the DOM Node
type.
These changes introduce the HtmlSerialize type to make it possible to
support XML serialization and fix other issues.
Testing: It does not change any behavior and it builds.
Fixes: #40552
---------
Signed-off-by: Rodion Borovyk <rodion.borovyk@gmail.com>
Adds an optional error message to HierarchyRequestError
Testing: refactor
Fixes: one item in #39053
---------
Signed-off-by: Austin Willis <austinwillis8@gmail.com>
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>
The result of an xpath query can depend on whether or not the document
is a HTMLDocument. We should always use the document that
`document.evaluate` was called on. Instead, we were using the document
of the relevant window. This makes a difference when a script creates a
document and calls `document.evaluate` on that.
Testing: New tests start to pass
---------
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Add context menu options for images, links, and editable text areas. In
addition add the ability to show menu options that are disabled. This
also improves the visual style of the context menu in egui as part of
supporting disabled options.
Testing: This has been manually tested, but we could we should be able
to
easily add unit tests when enriching the API with information about the
active element under context menus.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
HTMLStyleElement was creating stylesheets using the URI of the document,
ignoring `<base>`.
To avoid having to create the UrlExtraData twice (or clone it), this
inlines the `stylesheetcontents_create_callback`.
Testing: 2 WPT are now passing
Fixes: #40550
Signed-off-by: Oriol Brufau <obrufau@igalia.com>
Continue on adding ECDSA support to WebCrypto API. This patch implements
verify operation of ECDSA, using ECDSA implementation from the crates
`ecdsa` for the operation, `p256`, `p384`, `p521`, and `elliptic_curve`
for the key, and `sha1`, `sha2` and `digest` for digesting messages.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #39060
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Continue on adding ECDSA support to WebCrypto API. This patch implements
generate key operation of ECDSA, using ECDSA implementation from the
crates `p256`, `p384`, `p521` and `elliptic_curve`.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #39060
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This implements character set restrictions both for the DOM API and when
getting cookies from http/ws headers. This is a local workaround for
https://github.com/rwf2/cookie-rs/issues/243
We still fail some tests because hyper errors out when parsing headers
with %x1 characters.
This patch also makes a minor change to
'ServoCookie::from_cookie_string()' to avoid some string cloning when
possible.
Testing: wpt tests expectations are updated
Signed-off-by: webbeef <me@webbeef.org>
Some methods for USVString were not needed as they could lead to
inefficient usage
(like in CookieStoreMethod) it is better to remove them. Fixed two
methods that take the String
directly instead of copying it.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: No testing necessary as the functionality stays the same.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Continue on adding ECDSA support to WebCrypto API. This patch implements
export key operation of ECDSA, using ECDSA implementation from the
crates `p256`, `p384`, `p521` and `elliptic_curve`.
Testing:
- Pass some WPT tests that were expected to fail.
- The new FAIL expectations are added to
`wrapKey_unwrapKey.https.any.js.ini`, which require the
not-yet-implemented sign/verify operations of ECDSA and RSA-OAEP. These
tests were skipped by WPT when the export key operation of ECDSA had not
been implemented at the time.
Fixes: Part of #39060
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Add missing description for steps of legacy <audio> constructor with a
small refactoring, avoiding unnecessary `upcast` from `HTMLAudioElement`
to `Element`.
See https://html.spec.whatwg.org/multipage/media.html#dom-audio
Testing: No expected changes in tests (added steps description).
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
`UnprivilegedPipelineContent` contains all of the data necessary to
create a new `ScriptThread` with an initial `Pipeline` in a new
process. This change reuses the `InitialScriptState` and
`InitialPipelineState` structs inside `UnprivilegedPipelineContent` and
renames it to `NewScriptEventLoopProcessInfo` to clarify what it does.
In addition, `InitialScriptState` also repeated much of the data of
`NewPipelineInfo`, which is now deduplicated and passed separately to
the `ScriptThreadFactory`.
The overall goal here is to make `ScriptThread` and `Pipeline` creation
separate. A `ScriptThread` contains many `Pipeline`s which come and go,
so it should not depend on a single creation `Pipeline`. This is the
first step toward doing that.
Some inputs to `ScriptThreadFactory` differ based on whether the new
`ScriptThread` is created in a new process or not. This change makes it
so that these input are passed as extra arguments.
Finally these changes have revealed a couple members of data structures
that aren't used. These have been removed.
Testing: This is just a refactor and shouldn't change behavior so is
covered by existing tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
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>
Start adding ECDSA support to WebCrypto API. This patch implements
import key operation of ECDSA, using ECDSA implementation from the
crates `p256`, `p384`, `p521` and `elliptic_curve`.
Testing:
- Pass some WPT tests that were expected to fail.
- Remaining failed tests in `ec_importKey.https.any.js.ini` require the
not-yet-implemented export key operation of ECDSA.
- The new FAIL expectations are added to `ecdsa.https.any.js.ini`, which
require the not-yet-implemented sign/verify operations of ECDSA. These
tests were skipped by WPT because the import key operation had not been
implemented at the time.
Fixes: Part of #39060
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Implement read looping using a read request following the spec.
Testing: current wpt test should pass.
Fixes: #39482
---------
Signed-off-by: Taym Haddadi <haddadi.taym@gmail.com>
Use `InputEvent` for text input and set appropriate values for the
`composed`, `data`, `isComposing`, and `inputType` attributes. Use a
placeholder for `dataTransfer` attribute and `getTargetRanges` function,
as they are only applicable to contenteditable, which isn't implemented.
Testing: I added two tests under `tests/wpt/mozilla/tests/input-events`
based on the similarly named ones for contenteditable under
`tests/wpt/tests/input-events`.
Fixes: https://github.com/servo/servo/issues/36398
---------
Signed-off-by: Excitable Snowball <excitablesnowball@gmail.com>
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>
Adds a wrapper type for vectors that can contain large response bodies
to prevent flooding debug logs with the contents of those bodies.
Testing: Can't test debug log output.
Fixes: #37769
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This is last step toward enabling the default rustc
`unsafe_op_in_unsafe_fn` warning for the script crate. It wraps the
remaining unsafe code in `unsafe {}` and removes the line disabling this
warning from `script`'s `Cargo.toml`. In addition, two variables are
renamed from `v` to something slightly more descriptive.
Testing: This should not change behavior so is covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
The thing that this message does is to spawn a pipeline in a
`ScriptThread`. I believe that the `AttachLayout` name is a relic of a
different time. The corresponding procedure in the `Constellation` is
already called `Pipeline::spawn`.
Testing: This is just a rename, so existing tests should cover this
change.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This PR adds context menu support with clickable menu items in the
Minibrowser. The menu appears on right click and supports basic
navigation actions (Back, Forward, Reload).
Testing: We already have tests for ContextMenu in WebView API test.
Signed-off-by: atbrakhi <atbrakhi@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Finish adding X25519 support to WebCrypto API. This patch implements
derive bits operation of X25519, using X25519 implementation from the
crate `x25519-dalek`.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #39060
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>