We already store transform in context state, so let's just use this when
querying instead of using IPC to ask canvas paint thread.
Testing: Existing WPT tests
work towards #38022
try run: https://github.com/sagudev/servo/actions/runs/16299182583
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Remove size bound from safe to jsval trait, apply to script/dom, with
the exception of windowproxy.
Second part of https://github.com/servo/servo/issues/37951
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
*Describe the changes that this pull request makes here. This will be
the commit message.*
Testing: *Describe how this pull request is tested or why it doesn't
require tests*
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*
Many object store related operations require the transaction to be
checked: to ensure it is still active, and, if the operation is a write,
that the transaction is not read-only. I've added the
`check_transaction` method to perform these checks.
Additionally `Clear` was still half-implemented, so I went ahead and
implemented that.
---------
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
- Move the 2 hash maps used to manage channels in their own struct.
- The constellation is still in charge of origin checks since it holds
the pipeline information required.
- BroadcastMsg is renamed to BroadcastChannelMsg for consistency.
Testing: covered by existing tests.
Fixes: #38060
Signed-off-by: webbeef <me@webbeef.org>
Add support of the ImageBitmapRenderingContext as "bitmaprenderer"
canvas context mode to RenderingContext/OffscreenRenderingContext
https://html.spec.whatwg.org/multipage/#imagebitmaprenderingcontext
It is initial implementation with public interface API but without
any display presentation support for HTMLCanvasElement.
Testing: Improvements in the following tests:
-
html/canvas/element/manual/imagebitmap/createImageBitmap-origin.sub.html
- html/canvas/offscreen/manual/text/canvas.2d.offscreen*
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer.to.imagebitmap.nocrash.html
- imagebitmap-renderingcontext/*
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
When script thread executes script sent from webdriver, if an alert
appears, webdriver can stop waiting for the script response and process
the next command.
This PR allows script thread to fail to send response for
`ExecuteScript` if the channel is closed.
cc: @xiaochengh
Signed-off-by: batu_hoang <hoang.binh.trong@huawei.com>
Digging into several crashing tests revealed that committing
transactions is a fallible operation. Propagating those errors led to
exposing many new errors caused by the IDBRequest implementation
assuming that all successful responses contained a structured clone. The
end result is a bunch of new test failures that were previously hidden.
Testing: Existing test coverage is sufficient.
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
Introduce a safe wrapper trait for the unsafe `ToJSValConvertible`, and
use it in `script/dom` where the default `T` implementation works.
Part of https://github.com/servo/servo/issues/37951
---------
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
These changes introduce a new kind of task that uses a variation of the
`task!` syntax. Existing `task!` usages create task structs that have a
`Send` bound, which requires the use of `Trusted<T>` to reference a DOM
object T inside of the task closure. The new syntax replaces the `Send`
bound with a `JSTraceable` bound, which requires explicit capture
clauses with types. This looks like:
```rust
task!(ScriptPrepare: {script: DomRoot<HTMLScriptElement>} |script| {
script.prepare(CanGc::note());
}),
```
The capture clauses must list every value that will be referenced from
the closure's environment—these values are moved into fields in the
generated task structure, which allows them to be traced by the GC as
part of a generated JSTraceable implementation. Since the closure itself
is not a `move` closure, any attempts to reference values not explicitly
captured will generate a borrow checker error since the closure requires
the `'static` lifetime.
Testing: Existing WPT tests exercise these code paths. I also attempted
to write incorrect tasks that capture references or use values not
explicitly captured, and the compiler correctly errors out.
Fixes: part of #35517
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
1. Some rounding was wrongly used which can be a source of inaccuracy.
2. Use `window.InnerWidth` instead of `body.ClientWidth` according to
spec.
Testing: Many new passing cases.
Fixes: Part of #38042.
---------
Signed-off-by: Euclid Ye <euclid.ye@huawei.com>
This change aims to reduce the scope of incremental box tree
construction. Previously, when text content changed, the parent node
would always be marked as requiring box tree reconstruction; now, it is
adjusted to only mark the parent node as needing to recollect its box
tree children.
Testing: This should not change observable behavior and is thus covered
by existing WPT tests.
Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
Similar to #37960, previously, `AvailHeight`, `AvailWidth`, `Height`,
`Width` ask compositor for screen metrics. This PR moves the request to
embedder.
This simplifies code, and reduces workload of compositor, which is
busier most of time.
Testing: No behaviour change. Updated some tests. `Width/Height` matches
other browsers.
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
These changes reduce the number of times we need to query layout for the
same information when creating mouse/pointer events.
Testing: No new tests required for maintaining existing behaviour.
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This change allows the compiler to recognize if any read-only operations
are missing an implementation when processing a readonly transaction.
Testing: The existing behaviour is unchanged, so current tests suffice.
The new code is unused and cannot be tested.
Fixes: part of #6963
---------
Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This was a bit confusing at first, but the report-only only
had an effect if it was used in conjunction with the regular
CSP header. This is incorrect, as the report-only header
can be present on its own.
Additionally, there was double-logic for parsing the CSP list
values, since we can only concatenate CSP lists if we have
an initial value, which requires a concrete policy value.
Therefore, abstract that way by looping over both headers and
handling the case where initially it is `None` and, if the
CSP header is not present, still `None` when we parse
the `report-only` header.
Additionally, update a WPT test. It was expecting the image
to load, yet was showing the fail image.
Part of #4577
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
This PR removes existing path(segment) abstractions in favor of
`kurbo::BezPath`, well actually wrapped `kurbo::BezPath`, to ensure
building of valid paths. This allows us better Path2D building in script
and doing all validation and segmentation there and also allows us
remove blocking is_point_in_path on Path2D as we can now do this in
script. Current path is still done on canvas thread side as it will be
harder to move to script (will be done as a follow up), but it now uses
this new path abstraction.
Using kurbo also allows us to ditch our manual svgpath parser with the
one provided by kurbo.
Same code is stolen from: https://github.com/servo/servo/pull/36821.
Testing: Existing WPT tests
Fixes: #37904
wpt run: https://github.com/sagudev/servo/actions/runs/16172191716
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Add Constraint DOMException to handle the name conflict error in
`IDBDatabase::createObjectStore` method.
Testing: `./mach test-wpt tests/wpt/tests/IndexedDB/`, but it seems
there are many test failures even in main branch already ([related
comment](https://github.com/servo/servo/pull/37605#issuecomment-2993889163)).
Fixes: #37571
---------
Signed-off-by: iamlockon <xdddxyyyxzzz123@gmail.com>
Previously, `screenX`, `screenY`, `outerHeight`, `outerWidth`, `moveBy`,
`resizeBy` ask compositor for window rectangle, which then return
"inner" rectangle after consulting Embedder.
This PR
1. removes `GetClientWindowRect` from compositor, and directly let
script ask embedder.
2. add `window_size` to `ScreenGeometry`
3. add a lot of docs to `ScreenGeometry`
Testing: `tests\wpt\mozilla\tests\mozilla\window_resizeTo.html` can now
pass for Headed Window.
Fixes: #37824
---------
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
There is a new default cargo clippy lint, `unsafe_op_in_unsafe_fn`,
which requires unsafe code to be wrapped in unsafe blocks, even inside
functions marked as unsafe. The lint is disabled as much of our code
doesn't fulfill this contract. The thing itself is pretty useful in
order to gradually remove unsafety, so this change starts adding
`unsafe` blocks so we can eventually enable this lint.
Testing: This doesn't change behavior so existings tests should suffice.
Fixes: This is part of #35955.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Console messages on OHOS/Android targets were duplicated.
Originally messages were on the debug level directed to stdout and then
redirected to the logger. https://github.com/servo/servo/pull/37912
changed this behavior recently.
Testing: Tested by looking at the debug log of certain things.
ohos-speedometer for example.
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
The scripted_caller only has information if the context is coming
from a script. If an element fetch listener processes CSP
violations, then this information doesn't exist. Instead, we should
use the global URL and the line number. WPT tests don't appear
to expect a column number, as they are all zero. Not all elements
are updated, as I am not actually sure all of them need it.
The source position remains an Option, since there are also code
paths that don't correspond to element or script sources. Maybe
in the future we can always determine the source position, but
let's take small steps towards that.
Part of #4577
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
Co-authored-by: Josh Matthews <josh@joshmatthews.net>
The iterator produced by Node::inclusive_ancestors roots the items but
rev_version just drop and unroot them right away. This patch makes it
possible to work on the Node references instead to avoid rooting.
*Describe the changes that this pull request makes here. This will be
the commit message.*
Testing: *Describe how this pull request is tested or why it doesn't
require tests*
Fixes: *Link to an issue this pull requests fixes or remove this line if
there is no issue*
Signed-off-by: webbeef <me@webbeef.org>
The cookie-rs library parses the cookie expiry date based on the format
from RFC 2616 (for HTTP/1.1), which is stricter than the format from RFC
6265 (for HTTP cookie).
This patch implements the cookie expiry date algorithm from RFC 6265.
When Cookie::parse fails in parsing the expiry date, we try to parse the
expiry again with this algorithm, to provide extra compatibility with
legacy systems.
Testing: Pass a WPT test that was expected to fail before, and add a
unit test.
Fixes: #36452
---------
Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
A recent update in the spec (https://github.com/whatwg/dom/pull/1079)
introduced new rules for name validation of attribute, element, and
doctype. This PR implements the new name validation rules in
`components/script/dom/bindings/domname.rs`. The old XML name validation
rules are not fully removed because there remains a few usage of it in
`ProcessingInstructions` and `xpath`.
Testing: Covered by WPT tests
Fixes: #37746
---------
Signed-off-by: minghuaw <michael.wu1107@gmail.com>
Signed-off-by: Minghua Wu <michael.wu1107@gmail.com>
Co-authored-by: Xiaocheng Hu <xiaochengh.work@gmail.com>
Improves the implementation of keys to a point where key ranges can be
implemented as well.
Due to me making branching mistakes I'll have to cherry-pick out the
first commit (it's from #37682)
---------
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
Does not yet handle failures of endpoints, which requires us to update
metadata. I don't see that metadata being used anywhere, so I am not
sure if there is WPT coverage for it.
Part of #37238
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
When a style change does not chang the structure of the box tree, it is
possible to skip box tree rebuilding for an element. This change adds
support for reusing old box trees when no element has that type of
damage. In order to make this happen, there needs to be a type of
"empty" `LayoutDamage` that just indicates that a fragment tree layout
is necessary.
This is the first step toward incremental fragment tree layout.
Testing: This should not change observable behavior and thus is covered
by
existing WPT tests. Performance numbers to follow.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Implement internal pseudo element, which would be resolved as a
"Implemented Pseudo Element" within style computation. This is an
concrete element that would has a primary style after the style
computation, but could match and style resolved like an pseudo element.
Therefore, it would have a different behavior compared to how does
`pseudo`s that `ServoLayoutNode` had. Where they would not have a
concrete element behind it. Note that, due to the nature of these pseudo
elements residing inside a UA widget, these pseudo elements would
therefore not be accessible in JavaScript by default.
This kind of element is required in order to implement the [form control
pseudo element](https://drafts.csswg.org/css-forms-1/#pseudo-elements)
like `::placeholder`, `::color-swatch`, `::field-text`, etc.
See [this docs](https://hackmd.io/@ChaKweTiau/BJ3zRdLQlg) for more
details of the implementation.
Then, the implemented pseudo element is utilized to implement style
matching for input `type=text`.
Servo's side of: https://github.com/servo/stylo/pull/212
Testing: No WPT regression.
---------
Signed-off-by: stevennovaryo <steven.novaryo@gmail.com>
During the object (de)serialization steps on structured cloning
https://html.spec.whatwg.org/multipage/#safe-passing-of-structured-data
it is possible to throw a JS exception.
`self.postMessage({ get whatever() { throw customError } }));`
Require to propagate a pending JS exception and not throw the default
"DataCloneError" DOM exception.
Testing: Improvements in the following tests
- html/infrastructure/safe-passing-of-structured-data/*
- html/webappapis/structured-clone/structured-clone.any.js*
- wasm/serialization/arraybuffer/transfer.window.js
- webmessaging/without-ports/026.html
- workers/semantics/structured-clone/dedicated.html
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
The structured cloning with transfer list
https://html.spec.whatwg.org/multipage/#structuredserializewithtransfer
throws a "DataCloneError" DOM expection by default if
serialization/transferral
is not possible, but a platform object can throw a custom excepton on
its serialization/transfer steps.
One example is OffscreenCanvas, which can throw
an "InvalidStateError" exception if the context mode is not none on
transfer steps.
https://html.spec.whatwg.org/multipage/#the-offscreencanvas-interface:transfer-steps
Testing: Improvements in the following tests
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transferrable*
Fixes: #37919
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
This will help us make "update the rendering" a proper task.
Testing: Existing WPT tests.
try run: https://github.com/sagudev/servo/actions/runs/16085256131
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Follow the specification and make OffscreenCanvas objects are
transferable,
but not in case if there are a weak reference to placeholder canvas
element.
To handle it properly need to implement dedicated frame
provider/dispatcher
between canvas element (script thread) and offscreen canvas (dedicated
worker thread).
https://html.spec.whatwg.org/multipage/#the-offscreencanvas-interface:transferable-objects
Testing: Improvements in the following tests
-
html/canvas/element/drawing-images-to-the-canvas/2d.drawImage.detachedcanvas.html
-
html/canvas/offscreen/manual/convert-to-blob/offscreencanvas.convert.to.blob*
-
html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas.transfer*
-
html/infrastructure/safe-passing-of-structured-data/transfer-errors.window.js
Part of #24276
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
The specification moved around lately with how it defines its reports
and report bodies. They became dictionaries, but are currently missing
some fields [1].
Most tests won't be passing yet, since the `Reporting-Endpoints` header
isn't used yet. In fact, the specification leaves it up to the browser
to figure out when to run this task [2]. I am not sure if there some
background scheduling we can do here.
Confirmed with content-security-policy/reporting-api/
report-to-directive-allowed-in-meta.https.sub.html that the callback is
invoked. The test doesn't pass, since
the `describe_scripted_caller` is empty for HTML elements. Thus the
`source_file` is empty, whereas it should be equivalent to the current
document URL.
Part of #37328
Signed-off-by: Tim van der Lippe <tvanderlippe@gmail.com>
[1]: https://github.com/w3c/reporting/issues/286
[2]: https://w3c.github.io/reporting/#report-delivery
Printing using log macro for Android and OhOS, while retaining original
stderr behavior for other platforms.
Fixes: #37877
Signed-off-by: abdelrahman1234567 <boudyalex321@gmail.com>
Before #37703 we were actually doing update rendering of canvases/images
as part of `allow_layout_if_necessary` so let's keep doing that until we
fix this properly as this will be much more involved and we want usable
canvases in the mean time.
Testing: Manual testing + WPT tests
Fixes: #37891
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
The will-navigate message tells the devtools client to expect a
navigation for a browsing context. This makes the network monitor clear
any previous entries and show the requests for the new page that is
loaded. In order to support this correctly, we need to send the
navigation notification from the constellation instead of the script
thread, otherwise we silently ignore navigations triggered by the
browser URL bar.
Testing: Ran servo in devtools mode , now the requests appear for new
loaded page
Fixes: https://github.com/servo/servo/issues/37334
---------
Signed-off-by: Uthman Yahaya Baba <uthmanyahayababa@gmail.com>
This removes assumption about pixel format from backend abstraction to
actual backend implementation. This is important for vello.
Testing: WPT tests
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Follow the HTML speficication and add missing 'transferToImageBitmap'
method to OffscreenCanvas interface.
https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-transfertoimagebitmap
Testing: Improvements in the following tests
- html/canvas/offscreen/compositing/2d.composite.grid*
- html/canvas/offscreen/fill-and-stroke-styles/2d.gradient*
- html/canvas/offscreen/manual/the-offscreen-canvas/offscreencanvas*
- html/canvas/offscreen/reset/2d.reset*
- html/canvas/offscreen/text/2d.text*
Fixes (partially): #34111
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
[RootCause]:Tochdown executes normally, but touchup fails during hittest
and does not send a touchup event to the script, causing the script to
save an incorrect number of active_touch_points. The application
receives an incorrect event.touches.length, causing a logic error and
preventing the carousel from sliding.
[Solution]:
When hit test on compositor fails, we also need to send the
EmbedderToConstellationMessage::ForwardInputEvent message to
constellation. In the script's handle_touch_event, if it exits early, we
also need to update active_touch_points.
Testing:
Fixes: #37763
---------
Signed-off-by: kongbai1996 <1782765876@qq.com>
This pull request introduces changes to the storage subsystem to:
- Isolate sessionStorage per top-level browsing context (WebViewId), in
addition to origin.
- Copy sessionStorage when creating a new auxiliary browsing context
without
noopener, as required by the corresponding spec
These changes bring Servo closer to spec compliance, matching expected
browser
behavior.
Testing: This work affects observable behavior. As a result, some
previously
failing WPT tests now pass. No new tests are added, since the behavior
is
already covered by existing web-platform-tests.
Fixes: #21291
---------
Signed-off-by: Jan Varga <jan.varga@gmail.com>
Dirty roots are never shadow roots, since we use the flat tree for
invalidation. The flat tree does not contain shadow roots.
Reverts https://github.com/servo/servo/pull/35132. When that patch was
submitted we used the DOM tree for invalidation, so it was possible to
encounter shadow roots.
Testing: Covered by
`shadow-dom/untriaged/events/event-dispatch/test-003.html`
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
`Node::dirty` already increments the version. `Node::rev_version`
traverses all ancestors, so it can end up being fairly expensive.
Testing: I'm not sure about WPT coverage but I think this change is
trivial enough to merge without tests.
Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
Follow the HTML speficication and add missing 'convertToBlob' method
to OffscreenCanvas interface.
https://html.spec.whatwg.org/multipage/#dom-offscreencanvas-converttoblob
Testing: Improvements in the following tests
-
html/canvas/offscreen/manual/convert-to-blob/offscreencanvas.convert.to.blob*
-
html/canvas/offscreen/manual/wide-gamut-canvas/2d.color.space.p3.convertToBlobp3.canvas.html
Fixes: #24272
Signed-off-by: Andrei Volykhin <andrei.volykhin@gmail.com>
I introduced snapshot in #36119 to pack raw bytes and metadata together,
now we take the next step and require for user to always specify what
kind of byte data they want when calling `as_bytes` or `to_vec`
(basically joining transform and data). There are also valid usages when
one might require just one property of bytes (textures can generally
handle both RGBA and BGRA). There are also valid usages of using just
raw bytes (when cropping). This PR tries to make such usages more
obvious.
This will make it easier to fix stuff around 2d canvas (we do not want
to assume any bytes properties in abstraction).
Testing: Code is covered by WPT tests.
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
Co-authored-by: Martin Robinson <mrobinson@igalia.com>
This creates a new method in shared/compositing/lib to generate image
keys that are send over the webview. This does not immediately return
the keys but goes over the constellation to receive the keys from the
IOCompositor. To make this more efficient, we now cache the keys in
image_cache in a simple FIFO order. The old blocking method stays intact
for now but got renamed to make the blocking clear.
The blocking calls that are left are in:
- `components/canvas/canvas_data.rs`
- `components/script/dom/htmlmediaelement.rs`
Testing: WPT tests should cover this as this doesn't change any
functionality.
Fixes: Was mentioned in
https://github.com/servo/servo/issues/37161#issuecomment-2915750051 and
part of https://github.com/servo/servo/issues/37086
---------
Signed-off-by: Narfinger <Narfinger@users.noreply.github.com>
Signed-off-by: gterzian <2792687+gterzian@users.noreply.github.com>
Co-authored-by: gterzian <2792687+gterzian@users.noreply.github.com>
This change:
- Adds a new type of LayoutDamage that signifies that a box needs its
children recollected, because one or more of them need to be rebuilt.
- During restyle damage propagation, propagate this new damage upward in
the tree. Then box tree construction should be able to preserve any
still-valid box tree nodes from box slots.
- During BlockLevelBox job finalization, if a box slot is valid and
there is not LayoutDamage to the element, use the old box slot,
ensuring that its fragment cache is invalidated.
Testing: This should not change observable behavior and thus is covered
by existing WPT tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Co-authored-by: coding-joedow <ibluegalaxy_taoj@163.com>