Commit graph

929 commits

Author SHA1 Message Date
Timothy Flynn
f6f31fe215 LibWeb: Remove ability to override MessagePort's primary interface
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This hack no longer has any users.
2025-07-18 10:09:02 -04:00
Timothy Flynn
d471b52b0e LibWeb: Assume structured deserialization creates the correct type
Most locations already make this assumption, but we had a few that would
silently ignore data mismatches. Let's just always assume the type is
correct for now. If a bad actor has a hold of our transport socket, it's
probably better to crash WebContent than to continue on with incorrect
data.

In the future, maybe we will want to throw an exception instead.
2025-07-18 10:09:02 -04:00
Timothy Flynn
ed71db45e7 LibWeb: Move array buffer/view serializers above their users
Now that these serializers are internal to StructuredSerialize.cpp,
let's put them above Serializer so they don't have to be forward-
declared and explicitly instantiated.
2025-07-18 10:09:02 -04:00
Timothy Flynn
64abc6101d LibWeb+WebWorker: Use IPC mechanics for structured serialization
Our structured serialization implementation had its own bespoke encoder
and decoder to serialize JS values. It also used a u32 buffer under the
hood, which made using its structures a bit awkward. We had previously
worked around its data structures in transferable streams, which nested
transfers of MessagePort instances. We basically had to add hooks into
the MessagePort to route to the correct transfer receiving steps, and
we could not invoke the correct AOs directly as the spec dictates.

We now use IPC mechanics to encode and decode data. This works because,
although we are encoding JS values, we are only ultimately encoding
primitive and basic AK types. The resulting data structures actually
enforce that we implement transferable streams exactly as the spec is
worded (I had planned to do that in a separate commit, but the fallout
of this patch actually required that change).
2025-07-18 10:09:02 -04:00
Timothy Flynn
7fad8c333d LibWeb: Use forward-declarations of structured serialized types
This reduces the rebuilt targets when touching StructuredSerialize.h
from ~1200 to ~400. The remaining are due to generated IPC headers.
2025-07-18 10:09:02 -04:00
Timothy Flynn
20c6005341 LibWeb: Use TemporaryExecutionContext in structured deserialization
No need to manually prepare / clean up a context. We also previously
would not have done the clean up steps if structured deserialization
threw an exception.
2025-07-18 10:09:02 -04:00
Timothy Flynn
b1cfc96609 LibWeb: Don't check is_object in every serialization branch
Instead of every branch being of the form:

    if (value.is_object() && is<SomeType>(value.as_object()) {
        auto& some_type = static_cast<SomeType&>(value.as_object());
    }

Let's extract the `is_object` check to an outer branch, and use `as_if`
to check the type.

No functional change, but this makes a future change simpler to review.
2025-07-18 10:09:02 -04:00
Sam Atkins
6b53454b68 LibWeb/SVG: Move path data into Path.{h,cpp}
More things need this than just the `<path>` element, so let's avoid
having to include `SVGPathElement.h` in places that don't need it.

Minor changes at the same time:
- Wrap it in a Path class
- Specify underlying type for PathInstructionType
- Make a couple of free functions into methods
- Give PathInstruction an operator==

No functionality changes.
2025-07-17 13:59:23 -04:00
Aliaksandr Kalenik
1bf4d3391e LibWeb: Use GC::Ptr for BrowsingContext pointer saved in Document
Likely we forgot to update `WeakPtr` to `GC::Ptr` after converting
`BrowsingContext` to GC-allocated object.
2025-07-17 15:55:30 +01:00
Sam Atkins
b7b504cf2d LibWeb: Remove XML-derived attribute name validation from DOMStringMap
Corresponds to 841fcfdb2c
2025-07-17 13:54:01 +02:00
Andreas Kling
03256a2543 LibWeb: Add "parallel queue" and allow it as fetch task destination
Note that it's not actually executing tasks in parallel, it's still
throwing them on the HTML event loop task queue, each with its own
unique task source.

This makes our fetch implementation a lot more robust when HTTP caching
is enabled, and you can now click links on https://terminal.shop/
without hitting TODO assertions in fetch.
2025-07-17 00:13:39 +02:00
Callum Law
6a9c8d7767 LibWeb: Don't resolve colors with unresolved components
`CSSColorValue`s which have unresolved `calc` components should be able
to be resolved. Previously we would always resolve them but with
incorrect values.

This is useful as we will now be able to now whether we should serialize
colors in their normalized form or not.

Slight regression in that we now serialize (RGB, HSL and HWB) colors
with components that rely on compute-time information as an empty
string, but that will be fixed in the next commit.
2025-07-16 13:05:33 +01:00
Sam Atkins
511e282002 LibWeb/HTML: Return CSSStyleProperties from getComputedStyle()
Corresponds to 94fdd8ab1e
2025-07-16 09:50:30 +02:00
Aliaksandr Kalenik
52e9dcd911 LibWeb: Assign new m_viewport_size before resizing backing store
Fixes bug when `resize_backing_stores_if_needed()` picks up previous
viewport size for allocation of new backing stores.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/5336
2025-07-15 18:39:01 -04:00
Sam Atkins
632ce9523b LibWeb/CSS: Add :unchecked pseudo-class
This just got added to the Selectors spec:

b78c97c19d

It's thus missing from the HTML spec and WPT, but I figured it was
simple enough to add.
2025-07-15 21:27:44 +02:00
Luke Wilde
d08d6b08d3 LibWeb: Use enum for serialization and reimplement interface exposure
Our currently implementation of structured serialization has a design
flaw, where if the serialized/transferred type was not used in the
destination realm, it would not be seen as exposed and thus we would
not re-create the type on the other side.

This is very common, for example, transferring a MessagePort to a just
inserted iframe, or the just inserted iframe transferring a MessagePort
to it's parent. This is what Google reCAPTCHA does.

This flaw occurred due to relying on lazily populated HashMaps of
constructors, namespaces and interfaces. This commit changes it so that
per-type "is exposed" implementations are generated.

Since it no longer relies on interface name strings, this commit
changes serializable types to indicate their type with an enum,
in line with how transferrable types indicate their type.

This makes Google reCAPTCHA work on https://www.google.com/recaptcha/api2/demo
It currently doesn't work on non-Google origins due to a separate
same-origin policy bug.
2025-07-15 09:20:02 -04:00
Luke Wilde
d6b9bd306c LibWeb: Don't read from MessagePort transport if it's not entangled
If the MessagePort is not entangled, then m_transport is null, meaning
it's not valid to read from the transport.

This fixes the cross-piping streams WPT crash test crashing in the
upcoming commit.
2025-07-15 09:20:02 -04:00
Shannon Booth
9054ff29f0 LibWeb/CSS: Parse the ::slotted pseudo-element 2025-07-15 13:54:17 +01:00
Ryan Liptak
6da1dfa8f2 LibWeb/HTML: Improve data structure of named character reference data
Introduces a few ad-hoc modifications to the DAFSA aimed to increase
performance while keeping the data size small.

- The 'first layer' of nodes is extracted out and replaced with a lookup
  table. This turns the search for the first character from O(n) to O
  (1), and doesn't increase the data size because all first characters
  in the set of named character references have the
  values 'a'-'z'/'A'-'Z', so a lookup array of exactly 52 elements can
  be used. The lookup table stores the cumulative "number" fields that
  would be calculated by a linear scan that matches a given node, thus
  allowing the unique index to be built-up as normal with a O(1) search
  instead of a linear scan.
- The 'second layer' of nodes is also extracted out and searches of the
  second layer are done using a bit field of 52 bits (the set bits of
  the bit field depend on the first character's value), where each set
  bit corresponds to one of 'a'-'z'/'A'-'Z' (similar to the first
  layer, the second layer can only contain ASCII alphabetic
  characters). The bit field is then re-used (along with an offset) to
  get the index into the array of second layer nodes. This technique
  ultimately allows for storing the minimum number of nodes in the
  second layer, and therefore only increasing the size of the data by
  the size of the 'first to second layer link' info which is 52 * 8 =
  416 bytes.
- After the second layer, the rest of the data is stored using a
  mostly-normal DAFSA, but there are still a few differences:
   - The "number" field is cumulative, in the same way that the
     first/second layer store a cumulative "number" field. This cuts
     down slightly on the amount of work done during the search of a
     list of children, and we can get away with it because the
     cumulative "number" fields of the remaining nodes in the DAFSA
     (after the first and second layer nodes were extracted out) happens
     to require few enough bits that we can store the cumulative version
     while staying under our 32-bit budget.
   - Instead of storing a 'last sibling' flag to denote the end of a
     list of children, the length of each node's list of children is
     stored. Again, this is mostly done just because there are enough
     bits available to do so while keeping the DAFSA node within 32
     bits.
   - Note: Together, these modifications open up the possibility of
     using a binary search instead of a linear search over the
     children, but due to the consistently small lengths of the lists
     of children in the remaining DAFSA, a linear search actually seems
     to be the better option.

The new data size is 24,724 bytes, up from 24,412 bytes (+312, -104 from
the 52 first layer nodes going from 4-bytes to 2-bytes, and +416 from
the addition of the 'first to second layer link' data).

In terms of raw matching speed (outside the context of the tokenizer),
this provides about a 1.72x speedup.

In very named-character-reference-heavy tokenizer benchmarks, this
provides about a 1.05x speedup (the effect of named character reference
matching speed is diluted when benchmarking the tokenizer).

Additionally, fixes the size of the named character reference data when
targeting Windows.
2025-07-14 09:43:08 +02:00
Aliaksandr Kalenik
4f9aca4302 LibWeb: Skip backing store allocation for traversables created for SVG
Recently, we moved the backing store manager into Navigable, which means
we now try to allocate a backing store for all navigables, including
those corresponding to SVG image documents. This change disables that
behavior for all navigables except top-level non-SVG traversables,
because otherwise it causes issues when we stop repainting: the browser
process was notified about an allocated backing stores that does not
correspond to the page, and then all subsequent repaints are ignored
until the window is resized.
2025-07-13 00:06:30 +02:00
Aliaksandr Kalenik
410e82c9fd LibWeb: Rearrange code such that a lot less files include Command.h
Some checks failed
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Build Dev Container Image / build (push) Has been cancelled
With this change number of recompiled files after modification of
`Command.h` goes down from >1000 to <100.
2025-07-11 17:37:27 +02:00
Jelle Raaijmakers
c99a467cdb LibWeb: Do not crash when navigating to mailto: links
We forgot to implement a couple of "otherwise," statements from the
"populating a session history entry" spec. While we're here, let's
update the spec copy where relevant.
2025-07-10 22:43:30 +02:00
Jelle Raaijmakers
d822b96786 LibWeb: Remove setting the Skia backend context in Navigable
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This is unused. The backend context is also referenced in the Skia
player, which we move to the rendering thread.
2025-07-10 15:27:58 +02:00
Andrew Kaster
3040ca4311 LibWeb: Remove noisy debug messages from HTMLParser 2025-07-09 16:26:49 -06:00
Luke Wilde
0cff47828d LibWeb/CSP: Implement the script-src directive 2025-07-09 15:52:54 -06:00
Luke Wilde
2368641de5 LibWeb: Track if element was created from token with dupe attributes
This is required for CSP to ignore the nonce attribute to prevent
duplicate attributes hijacking the attribute.

See https://w3c.github.io/webappsec-csp/#security-nonce-hijacking
2025-07-09 15:52:54 -06:00
Lucien Fiorini
635adc8aa7 LibWeb/SVG: Implement resolution for a subset of SVG filters 2025-07-09 18:07:12 +01:00
Veeti Paananen
c3e470569e LibWeb: Preserve File last modified timestamp in FormData copies
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
+1 WPT pass
2025-07-09 10:20:52 +01:00
Veeti Paananen
c834c594ac LibWeb: Set correct content and document types in DOMParser
It appears this was removed by accident in an earlier commit, regressing
the included WPT test.
2025-07-09 20:10:11 +12:00
Sam Atkins
5c365884dd LibWeb/HTML: Update HTMLScriptElement.idl to match current spec
Corresponds to e21d9ff0d6

As far as I can tell, none of the rest of this change requires
modifications on our end.
2025-07-08 17:08:39 +01:00
Sam Atkins
0cfa243baa LibWeb/HTML: Update "create policy container from fetch response" spec
Corresponds to 83cc45b9c5
2025-07-08 17:08:39 +01:00
Sam Atkins
0d34f70d95 LibWeb/HTML: Queue a task to resolve createImageBitmap
Corresponds to e288a0efe5
2025-07-08 17:08:39 +01:00
Sam Atkins
df2b2d2c14 LibWeb/HTML: Fix return value checking for unload cancellation
Corresponds to 4467ddf323
2025-07-08 17:08:39 +01:00
Sam Atkins
91e8a19391 LibWeb: Always set [[ErrorToRethrow]] for import validation errors
Corresponds to f6fb04a11f
2025-07-08 17:08:39 +01:00
Sam Atkins
4e854ca44a LibWeb/HTML: Provide a fallback for validation anchor
Corresponds to daa3016b40

Also import a related test.
2025-07-08 17:08:39 +01:00
Sam Atkins
da8a29376f LibWeb: Use ThrowCompletion AO to create throw completions
Corresponds to 4989b3457f
2025-07-08 17:08:39 +01:00
Sam Atkins
b05fe0127b LibWeb/HTML: Allow more characters in custom element names
Corresponds to 78d2678789

And import a related test.
2025-07-08 17:08:39 +01:00
Sam Atkins
af17f38bbf LibWeb/HTML: Implement and use "optional value"
Corresponds to f3444c23ff

Also import a test.
2025-07-08 17:08:39 +01:00
Sam Atkins
22cc36eeaa LibWeb/HTML: Replace "zero" with "0" in some places
Corresponds to 706b986010
2025-07-08 17:08:39 +01:00
Sam Atkins
e74afec9c5 LibWeb: Capitalize "No Popover state" consistently
Corresponds partly to 8035a256bf
2025-07-08 17:08:39 +01:00
Shannon Booth
d5e41f1f72 LibWeb: Handle null namespace in prefix map serializing XML
A "namespace prefix map", see:

https://w3c.github.io/DOM-Parsing/#the-namespace-prefix-map

Is meant to also hold null namespaces:

> where namespaceURI values are the map's unique keys
> (which can include the null value representing no namespace)

Which we previously neglected. This resulted in a crash for
the updated WPT test.
2025-07-07 20:24:47 +01:00
edvwib
8ca956e6f1 LibWeb: Implement 'no-validate state' concept 2025-07-07 20:12:11 +01:00
Shannon Booth
9e3a476890 LibWeb: Abort ongoing navigations when firing certain navigate events
Implements specification change:

335d7f4

Which fixes a crash in the imported test.
2025-07-06 21:43:56 +02:00
Timothy Flynn
5baa85cbee LibWeb: Add missing ValueInlines include to CanvasSettings.cpp
This missing include is causing an error in distribution builds.
2025-07-06 08:16:01 -04:00
Tim Ledbetter
66ca4496c3 LibWeb: Set Document origin for DOMParser created documents
Previously, a crash would occur when accessing the origin of a document
created with DOMParser.
2025-07-06 13:39:45 +12:00
Shannon Booth
1b8a77f98c LibWeb/HTML: Avoid potential overflow of index for DOMStringList
The included WPT test passes through -1 which ends up modolo'ing
to u32 max at the IDL conversion layer, resulting in an unsigned
overflow when checking bounds.
2025-07-05 12:28:37 +01:00
Sam Atkins
b6ffea8990 LibWeb: Give Element a CustomStateSet, exposed by ElementInternals 2025-07-04 18:10:28 +01:00
Sam Atkins
e63d81b36e LibWeb: Add CustomStateSet IDL type 2025-07-04 18:10:28 +01:00
Tim Ledbetter
5413716802 LibWeb: Don't crash when setting offscreen canvas size to 0
Previously, this would crash because `Gfx::Bitmap` can't have a zero
size.
2025-07-04 16:10:38 +01:00
Aliaksandr Kalenik
c18314b942 LibWeb+LibGfx: Replace BackingStore with PaintingSurface
Now, when Skia backend context is available by the time backing stores
are allocated, there is no need to have a separate BackingStore class.

This allows us to get rid of BackingStore -> PaintingSurface cache.
2025-07-04 16:12:47 +02:00