Follow-up to #41823.
Now that we always execute JS with callback, we can safely remove the
obsolete sync script handler.
- Rename `ExecuteAsyncScript` to `ExecuteScriptWithCallback`
- Remove `ExecuteScript` related logic.
- Rewrite async callback wrapper to simplify things.
Testing: I expect no change in behaviour. See if WPT tests agree with
it.
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Fix a panic when calling `determine_auto_margins` for nodes without
`.style()`. Now it returns an empty `AutoMargins` (all options set to
`None`), which matches the behaviour in Firefox:
```json
"autoMargins": {}
"autoMargins": {"top": "auto", "bottom": "auto", "left": "auto", "right": "auto"}
```
Refactor `GetLayoutReply` and `ComputedNodeLayout` to take advantage of
serde's flatten feature, making the serialization much cleaner.
Testing: Manual testing with the example provided in the issue.
Fixes: #41743
---------
Signed-off-by: eri <eri@igalia.com>
Reviewable per commit. First commit adds `&mut JSContext` to
`call_default_constructor`. Second commit adds `&mut JSContext` to
Interface, which in unfortunately required many changes (a lot of
passing `&mut JSContext` down).
Testing: Just a refactor, but should be covered by WPT
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This changes routed_promise to use the GenericCallback functionality.
This mostly effected WebGPU but also Clipboard and Memory Reporting.
We also added a GenericCallback::new_blocking() functionality which
produces a callback and a channel
which then can be blocked on. This was used a couple of times in the
code.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: This should not change functionality.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Start adding AES-OCB support to WebCrypto API.
This patch implements the import key operations of AES-OCB, with the
`aes` crate.
Specification:
https://wicg.github.io/webcrypto-modern-algos/#aes-ocb-operations-import-key
Testing:
- Pass some WPT tests that were expected to fail.
- Some new FAIL expectations are added. They were skipped by WPT when
the import key operation of AES-OCB had not been implemented, and
requires other not-yet-implemented operations to pass.
Fixes: Part of #41762
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Add a callback on `WebFontDocumentContext` to create resource timing
entries, this callback is then used to call `submit_timing`, using a
shim listener, as this function requires a listener.
Testing: Using `./mach test-wpt
tests/wpt/tests/preload/preload-resource-match.https.html`
Fixes: #41660
---------
Signed-off-by: lumi <lumi@suwi.moe>
This change makes it so that all form controls are implemented with
shadow DOM, completely removing the legacy text content and selection
code paths for form controls. The motivation for this change is:
- to allow properly hit testing against the text nodes of `<textarea>`
and other widgets. This is important for implementing mouse-based
selection on the page.
- to simplify the way that form controls are implemented in general and
to prepare the way for proper implementations of the user interface of
other controls.
Testing: This should not change observable behavior at the moment,so
should be covered by existing WPT tests.
---------
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Refactors the `CookieStore` to use a separate `DroppableCookieStore`
struct for handling the drop logic.
Testing: No tests added
Fixes: Partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
Fixes a small WPT test and adds spec comments.
Testing: This change causes
`/html/browsers/origin/relaxing-the-same-origin-restriction/document_domain.html`
to start passing.
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This change is reviewable per commits:
In first commit we added `&mut JSContext` to `run_box` (it is very hard
to bring `&mut JSContext` to `remove_script_and_layout_blocker`).
In second commit we pass `&mut JSContext` to `run_once`.
In third commit we added support for accepting `&mut JSContext` in
closures of `task!` macro and lastly we demo new macro invocations (to
ensure they actually compile)
Testing: Just refactor, but should be covered by WPT
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
webxr/webxr-api have the feature flag "ipc". This is required by
important crates such as script and canvas. The only distinction was
made in servo which does not use the IPC for android/ohos but because
servo depends on script, this was essentially useless.
This PR removes the feature flag and cleans up the code related to it.
Testing: Compilation is the test.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
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>
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>
Refactors the WebGLRenderingContext to manage resource cleanup via a
dedicated `DroppableWebGLRenderingContext` struct.
Testing: This task is only a refactor, no tests added
Fixes: partially #26488
Signed-off-by: Domenico Rizzo <domenico.rizzo@gmail.com>
This implements GenericReceiverSet similar to IpcReceiverSet. This
allows us to wait on a group of channels.
IpcReceiverSet was allowed to use IpcReceivers of different type, i.e.,
`IpcReceiver<Foo>` and `IpcReceiver<Bar>` in the same select query. This
changes with GenericReceiverSet to only allow one type, i.e.,
`GenericReceiver<Foo>`. As this functionality was only used in the
CoreResourceThread, we changed the setup slightly for the memory
reporter.
With this we also change the implementation of CoreResourceThread to now
use the GenericReceiverSet.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Testing: New testcases were added to GenericReceiverSet and browsing
works normally.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
1. removed `ScriptThread::get_safe_cx` in favor of `Runtime::cx` (this
intentionally shadows
[RustRuntime::cx](https://doc.servo.org/mozjs/rust/struct.Runtime.html#method.cx),
which is not really safe with all other stuff that happen in servo).
2. passed down cx from `ScriptThread::new` to accommodate those changes
(we also need to pass cx for some other stuff).
3. we create JSContext in workers/worklets, so we can pass all the way
down to
6ccc47f4c9/components/script/dom/workers/workerglobalscope.rs (L1013)
(so we can get &mut JSContext in tasks).
So with this PR, we prepared all entry points of JSContext (or other
should actually be reentering via SM callback or passed down from the
root one in the thread).
Testing: No changes just safety, but it should be covered by WPT
Part of #40600
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
With this we stop exporting ipc-channel in libservo and switch to
GenericChannel/GenericCallback.
Testing: Generic Channels are tested all over the place.
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
Rather than this catch-all (which I copy-pasted from a usage where I
should have introduced a specific enum value), we now should always use
one of the enum values. If one does not exist, then it should be added
as such.
Follow-up for #36434
Testing: it builds
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
`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>
The specification isn't complete here and thus we
were missing WPT coverage. Spec will be updated.
Also, we are correctly throwing the QuotaExceededError with relevant
information, while Chrome sets both
fields to `null`. Therefore, the test now allows for both (since
providing relevant information is good for the developer and recommended
in the spec [1]).
[1]: https://webidl.spec.whatwg.org/#ref-for-quotaexceedederror%E2%91%A2
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.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>
We construct `ScriptThread` in an `Rc` which itself has the given `Weak`
for it. It then can give it to `Window` and other elements in the
future. We currently only use this for the microtask checkpoint function
in `Window`. This is the first step toward eliminating the usage of
thread local storage to access the `ScriptThread`.
Testing: This should not change behavior so is covered by existing
tests.
Fixes: Part of addressing:
https://github.com/servo/servo/issues/37969#issuecomment-3520463442
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
There's no naming conflict, and nowhere else the name NetRequestInit.
All it does is increase confusion.
Testing: No runtime changes.
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
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>
add `is_permanent_failure` method in `NetworkError` and call it from the
`EventSource` instead of the current match against the url's scheme
Testing: `./mach test-wpt tests/wpt/tests/eventsource`
Fixes: #41634
---------
Signed-off-by: WaterWhisperer <waterwhisperer24@qq.com>
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>
XML documents do not use the "determine the encoding" algorithm. As far
as I can tell, it is unspecified how they should determine the encoding
instead. We now check the BOM, `Content-Type` header and prescan for an
xml encoding declaration (but don't inherit encodings from iframes or
attempt to determine the encoding from heuristics).
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>
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>
Start adding ML-DSA support to WebCrypto API.
This patch implements the import key operations of ML-DSA, with `ml-dsa`
crate.
Specification:
https://wicg.github.io/webcrypto-modern-algos/#ml-dsa-operations-import-key
Testing:
- Pass some WPT tests that were expected to fail.
- Some new FAIL expectations are added. They were skipped by WPT when
the import key operations of ML-DSA had not been implemented, and
requires other not-yet-implemented operations to pass.
Fixes: Part of #41626
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
We wrongly use the object identifier of ML-KEM for the `alg` field of
exported ML-KEM key in JWK format. We should use the values specified in
Section 8 of [draft-ietf-jose-pqc-kem-01] (Figure 1) instead.
[draft-ietf-jose-pqc-kem-01] (Figure 1):
https://www.ietf.org/archive/id/draft-ietf-jose-pqc-kem-01.html#direct-table
Testing: WPT currently does not have relevant tests for ML-KEM keys in
JWK format since The JWK format for ML-KEM is not standardized yet. We
strive to remain compliant with the current specification.
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Replace `allow` with `expect` lints for `unused`, `unsafe_code`,
`dead_code`, and `non_upper_case_globals`.
Testing: So far just check it compiled on `x86_64-linux` on NixOS. Need
to use the module `system.fontconfig.enable = true;` I think in my NixOS
config.
Part of: #40383
Searching `allow\(.*\)` for `.rs` files shows the following. for
(total_results:total_files) went from `707:386` to `675:368`, a
reduction of `32:18`.
How many files is too many files per PR? I feel like the 20-30 I have is
too big.
---------
Signed-off-by: Wayne Van Son <waynevanson@gmail.com>
Continue on adding ML-KEM support to WebCrypto API.
Specification: https://wicg.github.io/webcrypto-modern-algos/#ml-kem
This patch implements generate key operation of ML-KEM, with `ml-kem`
crate.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41473
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
Continue on adding ML-KEM support to WebCrypto API.
Specification: https://wicg.github.io/webcrypto-modern-algos/#ml-kem
This patch implements export key operation of ML-KEM, with `ml-kem`
crate.
Testing: Pass some WPT tests that were expected to fail.
Fixes: Part of #41473
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
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>