Commit graph

1247 commits

Author SHA1 Message Date
Daniel Price
b0c48b961e LibWeb: Check that import map elements are ordered maps (json objects) 2025-11-27 14:15:33 -06:00
Sam Atkins
85478c9215 LibWeb/HTML: Rename popover "invoker"
Lots of renames, no behaviour differences. (Apart from the rename of the
IDL type, which does of course affect JS.)

Corresponds to:
16cb7808da
2025-11-27 16:44:51 +00:00
Timothy Flynn
9375660b64 LibHTTP+LibWeb+RequestServer: Move Fetch's HTTP header infra to LibHTTP
The end goal here is for LibHTTP to be the home of our RFC 9111 (HTTP
caching) implementation. We currently have one implementation in LibWeb
for our in-memory cache and another in RequestServer for our disk cache.

The implementations both largely revolve around interacting with HTTP
headers. But in LibWeb, we are using Fetch's header infra, and in RS we
are using are home-grown header infra from LibHTTP.

So to give these a common denominator, this patch replaces the LibHTTP
implementation with Fetch's infra. Our existing LibHTTP implementation
was not particularly compliant with any spec, so this at least gives us
a standards-based common implementation.

This migration also required moving a handful of other Fetch AOs over
to LibHTTP. (It turns out these AOs were all from the Fetch/Infra/HTTP
folder, so perhaps it makes sense for LibHTTP to be the implementation
of that entire set of facilities.)
2025-11-27 14:57:29 +01:00
Timothy Flynn
3dce6766a3 LibWeb: Extract some CORS and MIME Fetch helpers to their own files
An upcoming commit will migrate the contents of Headers.h/cpp to LibHTTP
for use outside of LibWeb. These CORS and MIME helpers depend on other
LibWeb facilities, however, so they cannot be moved.
2025-11-27 14:57:29 +01:00
Timothy Flynn
0fd80a8f99 LibTextCodec+LibWeb: Move isomorphic coders to LibTextCodec
This will be used outside of LibWeb.
2025-11-27 14:57:29 +01:00
Sam Atkins
936c7f05df LibWeb/HTML: Account for User-Agent not starting with "Mozilla/"
Corresponds to:
a93c6fa9fa
2025-11-27 07:20:32 -05:00
Sam Atkins
37d0741099 LibWeb/HTML: Implement HTMLTemplateElement.content to spec
No real behaviour change - it just means we VERIFY before returning the
value we returned before.
2025-11-27 10:26:13 +00:00
Sam Atkins
a25cb679fb LibWeb/HTML: Update spec text related to template's content
Corresponds to:
aa52274b5a
2025-11-27 10:26:13 +00:00
Timothy Flynn
f675cfe90f LibWeb: Store HTTP methods and headers as ByteString
The spec declares these as a byte sequence, which we then implemented as
a ByteBuffer. This has become pretty awkward to deal with, as evidenced
by the plethora of `MUST(ByteBuffer::copy(...))` and `.bytes()` calls
everywhere inside Fetch. We would then treat the bytes as a string
anyways by wrapping them in StringView everywhere.

We now store these as a ByteString. This is more comfortable to deal
with, and we no longer need to continually copy underlying storage (as
ByteString is ref-counted).

This work is largely preparatory for an upcoming HTTP header refactor.
2025-11-26 09:15:06 -05:00
Prajjwal
50a79c6af8 LibWeb: Change SessionHistoryTraversalQueue to use Promises
If multiple cross-document navigations are queued on
SessionHistoryTraversalQueue, running the next entry before the current
document load is finished may result in a deadlock. If the new document
has a navigable element of its own, it will append steps to SHTQ and
hang in nested spin_until.
This change uses promises to ensure that the current document loads
before the next entry is executed.

Fixes timeouts in the imported tests.

Co-authored-by: Sam Atkins <sam@ladybird.org>
2025-11-26 12:27:12 +01:00
Sam Atkins
8ca4833885 LibWeb/HTML: Update spec text in create_element_for()
No behaviour changes.
2025-11-26 09:52:47 +01:00
Sam Atkins
6e2f8166f4 LibWeb/HTML: Combine duplicate parsing branches
These are combined in the current spec. No behaviour change.
2025-11-26 09:52:47 +01:00
Sam Atkins
6a4ab26b48 LibWeb/HTML: Return early from find_appropriate_place_for_inserting_node
Step 2.(a).5 says to abort, but we were instead carrying on and would
run steps 3 and 4. Those steps would not change the result at all, but
this avoids a little unnecessary work.

I wrapped a couple of comments at 120 columns while I was at it.
2025-11-26 09:52:47 +01:00
Sam Atkins
418e22d65a LibWeb/HTML: Bring hand_in_head in HTML parser more up to date
A couple of spec text changes I noticed, and use `has_attribute()`
instead of manually checking it.
2025-11-26 09:52:47 +01:00
Aliaksandr Kalenik
69cede4a0f AK+LibWeb: Make StringBase::bytes() lvalue-only
Disallow calling `StringBase::bytes()` on temporaries to avoid returning
`ReadonlyBytes` that outlive the underlying string.

With this change, we catch a real UAF:
`load_result.data = maybe_response.release_value().bytes();`
All other updated call sites were already safe, they just needed to use
an intermediate named variable to satisfy the new lvalue-only
requirement.
2025-11-25 13:02:20 -05:00
Aliaksandr Kalenik
4c22c372a4 LibWeb: Avoid full DOM tree traversal in Window::named_objects()
Instead, take advantage of `ElementByIdMap` and
`m_potentially_named_elements` to gather elements with specified name
more efficiently.
2025-11-25 09:16:17 +01:00
Aliaksandr Kalenik
e80d1bcee7 LibWeb: Avoid full DOM tree traversal in supported_property_names()
Instead, take advantage of `ElementByIdMap` and
`m_potentially_named_elements` to gather named elements more
efficiently.
2025-11-25 09:16:17 +01:00
Jelle Raaijmakers
c0939725a2 LibWeb: Change agent's signal_slots into a GC::RootVector
As part of this, also move the constructor out of line so we don't
unnecessarily add transitive includes.
2025-11-24 12:45:22 +00:00
Jelle Raaijmakers
e281e3a274 LibWeb: Move mutation observers from IntrusiveList to GC::RootVector
We need to prevent these mutation observers from being garbage
collected, and since they are only part of SimilarOriginWindowAgent and
themselves as part of the intrusive list, nobody is visiting them.

Make the list of pending mutation observers a GC::RootVector so we keep
them alive until they have been processed in the microtask.

Restores 1400+ WPT subtest passes in `dom/nodes/Element-classlist.html`.
2025-11-24 12:45:22 +00:00
Glenn Skrzypczak
a0dbae02c8 LibWeb/HTML: Ignore form owner if earlier same-ID element isn't a form
Only set form owner when there is no non-form element with the same ID
as the control's form attribute earlier in tree order.
2025-11-24 09:51:50 +01:00
Jelle Raaijmakers
b3c186ce64 LibWeb: Add spec steps to prescan a byte stream algorithm
Fix up the implementation as we go. Also change `ByteBuffer const&` into
`ReadonlyBytes` everywhere, so we don't accidentally copy bytes.
2025-11-21 17:43:08 +01:00
Jelle Raaijmakers
f52632d48a LibWeb: Skip right amount of characters during encoding detection
When detecting an element's opening tag, the spec asks us to skip ahead
to the first whitespace or end chevron character before trying to read
attributes. Instead, we were always skipping 2 positions ahead and then
ignoring all whitespace characters and slashes, which was clearly wrong.

Theoretically this could have caused some weird behaviors if part of the
opening tag matched an expected attribute name, but it's very unlikely
to see that in the wild.
2025-11-21 17:43:08 +01:00
Jelle Raaijmakers
4bcf988e46 LibWeb: Use FlyString attribute name comparisons in encoding detection
Prevent some unnecessary work by performing pointer comparisons.
2025-11-21 17:43:08 +01:00
Jelle Raaijmakers
4ebbbdfef1 LibWeb: Advance position at attribute end quote in encoding detection
This did not cause any immediate issues except generating instances of
`Attr` with useless values which caused some unnecessary work during
encoding detection.
2025-11-21 17:43:08 +01:00
Sam Atkins
6e17503423 LibWeb: Add and remove MutationObservers at specified times
In the current spec, MutationObservers are explicitly added to the
pending mutation observers list, and they are removed when that list is
cleared in the "notify mutation observers" microtask.

This solves some issues with slotchange events.

As noted, we delay actually emptying the list of pending mutation
observers until after we're finished with the "clone", because we can't
actually copy or move the intrusive list. As far as I am aware, this
should not affect behaviour because only one microtask can run at once.
2025-11-21 16:19:57 +01:00
Estefania
8f15565967 LibWeb: Add stub implementation for Navigator.getBattery()
Adds a stub that returns a cached rejected promise with a
not yet implemented error. This converts
battery-status/battery-promise-window.https.html from timeout
to pass. Full implementation still needed.
2025-11-21 10:53:01 +01:00
Aliaksandr Kalenik
0eb28a1a54 LibWeb: Delete unused BufferPolicy from fetch Request
This is no longer needed since all requests are unbuffered.
2025-11-20 06:29:13 -05:00
Aliaksandr Kalenik
f942fef39b LibWeb: Allow microtasks to run if document has been destroyed
187f8c54 made `HTML::Task` runnable for destroyed documents, and this
change aligns microtask behavior with that. This is required for an
upcoming change that switches Fetch to be unbuffered by default. During
navigation, fetching the new document is initiated by the previous
document, which means we need to allow microtasks created in the
previous document's realm to run even after that document has been
destroyed.
2025-11-20 06:29:13 -05:00
Aliaksandr Kalenik
fa46efae48 LibWeb: Exit process_stylesheet_resource if document isn't fully active
This change is required to fix crashing in `link-re-enable-crash.html`
that is going to be introduced by switching to unbuffered fetching.
2025-11-20 06:29:13 -05:00
Jelle Raaijmakers
41eb7251e4 LibWeb: Convert Ladybird notes in spec steps to // NB: ...
We have a couple of ways to designate spec notes and (our) developer
notes in comments, but we never really settled on a single approach. As
a result, we have a bit of a mixed bag of note comments on our hands.

To the extent that I could find them, I changed developer notes to
`// NB: ...` and changed spec notes to `// NOTE: ...`. The rationale for
this is that in most web specs, notes are prefixed by `NOTE: ...` so
this makes it easier to copy paste verbatim. The choice for `NB: ...` is
pretty arbitrary, but it makes it stand out from the regular spec notes
and it was already in wide use in our codebase.
2025-11-18 09:07:37 -05:00
Tim Ledbetter
fdd3975104 LibWeb: Don't run update_the_image_data() algorithm if already started
This ensures that events are not fired if the image source is updated
while it is being fetched.
2025-11-15 12:39:37 +01:00
Psychpsyo
6951ef4ee3 Meta: Validate proper formatting for FIXMEs and AD-HOCs 2025-11-13 15:56:04 +01:00
Psychpsyo
100f37995f Everywhere: Clean up AD-HOC and FIXME comments without colons 2025-11-13 15:56:04 +01:00
Jelle Raaijmakers
3f6cbeb87e LibGfx+LibWeb: Use mipmaps for downscaling images
This changes Gfx::ScalingMode to reflect the three modes of scaling we
support using Skia, which makes it a bit easier to reason about the mode
to select. New is ::BilinearMipmap, which uses linear interpolation
between mipmap levels to produce higher quality downscaled images.

The cubic resampling options Mitchell and its sibling CatmullRom both
produced weird artifacts or resulted in a worse quality than
BilinearMipmap when downscaling. We might not have been using these
correctly, but the new ::BilinearMipmap method seems to mirror what
Chrome uses for downscaled images.
2025-11-12 15:59:01 +01:00
Lorenz A
bd56fdc57b LibWeb: Allow focusable for the first summary child of a detail element 2025-11-12 13:57:05 +01:00
Lorenz A
8ca59e7c7e LibWeb: AnchorElement should be focusable with tabindex 2025-11-12 13:57:05 +01:00
Lorenz A
3bc061d028 LibWeb: Allow all elements with tabindex attribute to be focusable 2025-11-12 13:57:05 +01:00
Tim Ledbetter
154e9db033 LibWeb: Cache the value of Element::lang()
This reduces the time spent in
`SelectorEngine::matches_lang_pseudo_class()` from 1.9% to 0.41% on
https://cloudflare.com
2025-11-12 12:36:16 +01:00
Lorenz A
f8330a2ec5 LibWeb: Do not execute unclosed SVG script tags 2025-11-09 01:43:46 +01:00
Jelle Raaijmakers
02611c9c12 LibWeb: Shave 16 bytes off of each HTMLElement 2025-11-07 16:59:26 +01:00
Luke Wilde
7f7babe735 LibWeb: Remove spin_until from create_navigation_params_by_fetching
This is in similar fashion and reason to e095bf3
2025-11-07 04:08:30 +01:00
Aliaksandr Kalenik
ed9c0c1e09 LibWeb: Don't visit registered NavigationObserver from Navigable
NavigationObserver register itself in Navigable from constructor and
unregister itself from `finalize()`. The problem is that `finalize()`
won't be invoked for as long as NavigationObserver is visited by
Navigable, leading to GC leaks.
2025-11-07 04:08:30 +01:00
Luke Wilde
167de08c81 LibWeb: Remove exception throwing from Fetch
These were only here to manage OOMs, but there's not really any way to
recover from small OOMs in Fetch especially with its async nature.
2025-11-07 04:08:30 +01:00
Daniel Price
3a70a4735a LibWeb: Create an execution context before registering import map
Fixes #6297
2025-11-06 17:07:22 -05:00
Tim Ledbetter
f6f238d15c ImageDecoder+LibWeb: Perform initial alpha conversion in ImageDecoder
This change moves the initial alpha premultiplication step for all
decoded images from WebContent to the ImageDecoder process. This
doesn't reduce the overall amount of work, but it can make sites with a
lot of images more responsive.
2025-11-06 17:56:29 +01:00
Luke Wilde
82bd3d3891 LibWeb: Avoid invoking Trusted Types where avoidable
Prevents observably calling Trusted Types, which can run arbitrary JS,
cause crashes due to use of MUST and allow arbitrary JS to modify
internal elements.
2025-11-06 11:43:06 -05:00
Luke Wilde
fb9406ddcd LibWeb: Make Trusted Types injection sink names more readable
No functional change.
2025-11-06 11:43:06 -05:00
Luke Wilde
d211df8118 LibWeb: Implement Trusted Types for HTMLIFrameElement#srcdoc 2025-11-06 11:43:06 -05:00
Tim Ledbetter
478cf4f42c LibWeb: Explicitly disallow skipping 0 characters in HTML tokenizer
Previously, this caused the source position of an ambiguous ampersand
to be incorrect.
2025-11-06 10:59:54 +01:00
Timothy Flynn
6057719f63 LibWeb: Use fetch to retrieve all HTMLLinkElement resources
HTMLLinkElement is the final user of Resource/ResourceClient (used for
preloads and icons). This ports these link types to use fetch according
to the spec.

Preloads were particularly goofy because they would be stored in the
ResourceLoader's ad-hoc cache. But this cache was never consulted for
organic loads, thus were never used. There is more work to be done to
use these preloads within fetch, but for now they at least are stored
in fetch's HTTP cache for re-use.
2025-11-05 18:27:36 +01:00