Commit graph

8823 commits

Author SHA1 Message Date
Gingeh
5838c73a72 LibWeb: Restrict weird about:foo URIs
This commit:
- Prevents path traversal via the about: scheme
- Prevents loading about:inspector
- Requires about: URIs to be opaque paths
- Prevents crashes with invalid percent encoded paths
2025-03-12 10:41:06 +00:00
Tim Ledbetter
249de20343 LibWeb/CSS: Don't allow negative values in filter functions 2025-03-12 09:06:16 +00:00
Timothy Flynn
fce5d24e5f LibWebView+WebContent: Add a command-line flag to disable site isolation 2025-03-12 02:00:54 +00:00
Timothy Flynn
cbefa797d4 LibDevTools+LibWebView+WebContent: Implement moving DOM nodes
This allows for click-and-dragging DOM nodes in DevTools to move them.
2025-03-11 09:50:51 -04:00
Timothy Flynn
01c44a5c66 LibDevTools+LibWebView+WebContent: Implement getting DOM node inner HTML
This is used by DevTools to copy the inner HTML to the clipboard.
2025-03-11 09:50:51 -04:00
Timothy Flynn
d75eadc3c4 LibDevTools+LibWebView+WebContent: Implement editing DOM node HTML
These commands are used for the "Edit As HTML" feature in DevTools. This
renames our existing HTML getter IPC to indicate that it is for outer
HTML. DevTools will need a separate inner HTML getter.
2025-03-11 09:50:51 -04:00
Timothy Flynn
aca4385daf LibWebView: Create a spare WebContent process
Since cross-site navigation is a pretty frequent task, creating a spare
process is commonplace in other browsers to reduce the overhead of
directing the target site to a new process.

We store this process on the WebView application. If it is unavailable,
we queue a task to create it later.
2025-03-11 12:10:42 +01:00
Timothy Flynn
5810c8073e LibWeb+LibWebView+WebContent: Begin implementing simple site islotation
Site isolation is a common technique to reduce the chance that malicious
sites can access data from other sites. When the user navigates, we now
check if the target site is the same as the current site. If not, we
instruct the UI to perform the navigation in a new WebContent process.

The phrase "site" here is defined as the public suffix of the URL plus
one level. This means that navigating from "www.example.com" to
"sub.example.com" remains in the same process.

There's plenty of room for optimization around this. For example, we can
create a spare WebContent process ahead of time to hot-swap the target
site. We can also create a policy to keep the navigated-from process
around, in case the user quickly navigates back.
2025-03-11 12:10:42 +01:00
Timothy Flynn
a34f7a5bd1 LibURL: Correctly acquire the registrable domain for a URL
We were using the public suffix of the URL's host as its registrable
domain. But the registrable domain is actually the public suffix plus
one additional label.
2025-03-11 12:10:42 +01:00
Shannon Booth
b543523717 LibWeb: Fire slotchange events when a slot is changed 2025-03-10 14:37:26 -04:00
Aliaksandr Kalenik
84ecaaa75c LibWeb: Limit sibling style invalidation by max distance
If an element is affected only by selectors using the direct sibling
combinator `+`, we can calculate the maximum invalidation distance and
use it to limit style invalidation. For example, the selector
`.a + .b + .c` has a maximum invalidation distance of 2, meaning we can
skip invalidating any element affected by this selector if it's more
than two siblings away from the element that triggered the style
invalidation.

This change results in visible performance improvement when hovering
PR list on GitHub.
2025-03-10 18:56:55 +01:00
rmg-x
6a9e637c11 LibWeb/HTML: Remove dbgln() for invalid location_url to reduce spam 2025-03-10 17:15:53 +01:00
InvalidUsernameException
d76f841994 LibWeb: Do not deform bitmaps partially outside the img-box
Instead of trying to manually determine which parts of a bitmap fall
within the box of the `<img>` element, just draw the whole bitmap and
let Skia clip the draw-area to the correct rectangle.

This fixes a bug where the entire bitmap was squashed into the rectangle
of the image box instead of being clipped.

With this change, image rendering is now correct enough to import some
of the WPT tests for object-fit and object-position. To get some good
coverage I have imported all tests for the `<img>` tag. I also wanted to
import a subset of the tests for the `<object>` tag, since those are
passing as well now. Unfortunately, they are flaky for unknown reasons.

This is the second attempt at this bugfix. The prior one was e055927ead
and broke image rendering whenever the page was scrolled. It has
subsequently been reverted in 16b14273d1. Hopefully this time it is not
horribly broken.
2025-03-10 17:14:13 +01:00
InvalidUsernameException
0e1eb4d4a7 LibWeb: Respect scroll position set by script during page load
When setting scroll position during page load we need to consider
whether we actually have a fragment to scroll to. A script may already
have run at that point and may already have set a scroll position.

If there is an actual fragment to scroll to, it is fine to scroll to
that fragment, since it should take precedence. If we don't have a
fragment however, we should not unnecessarily overwrite the scroll
position set by the script back to (0, 0).

Since this problem is caused by a spec bug, I have tested the behavior
in the three major browsers engines. Unfortunately they do not agree
fully with each other. If there is no fragment at all (e.g. `foo.html`),
all browsers will respect the scroll position set by the script. If
there is a fragment (e.g. `foo.html#bar`), all browsers will set the
scroll position to the fragment element and ignore the one set by
script. However, when the fragment is empty (e.g. `foo.html#`), then
Blink and WebKit will set scroll position to the fragment, while Gecko
will set scroll position from script. Since all of this is ad-hoc
behavior anyway, I simply implemented the Blink/WebKit behavior because
of the majority vote for now.

This fixes a regression introduced in 51102254b5.
2025-03-10 17:14:13 +01:00
Tim Ledbetter
53bf0ef225 LibWeb/CSS: Resolve used value for the inline-size property 2025-03-10 13:01:08 +00:00
Tim Ledbetter
1739e2851d LibWeb/CSS: Resolve used value for the block-size property 2025-03-10 13:01:08 +00:00
rmg-x
00aa72c16e LibWeb/Loader: Add filtering_enabled flag in ContentFilter
This allows us to toggle content filtering on or off. Default is set to
true to match current behavior.
2025-03-10 12:30:21 +00:00
Tim Ledbetter
a6efdb1068 LibWeb: Treat CSS at-rule names as case-insensitive 2025-03-10 12:42:57 +01:00
sideshowbarker
4def3fe567 LibWeb: Implement string->number for type=datetime-local input elements 2025-03-10 10:34:01 +00:00
Vishal Biswas
90b303215e LibURL: Add U+005E to path percent encoding list
Passes wpt tests which were failing after
9bc33c39d4.

It also removes ^ from Userinfo set as its included in Path set now
2025-03-10 11:19:36 +01:00
rmg-x
798250d3e2 LibWeb/HTML: Remove unnecessary verification for location_url error
There is a check shortly after this, so there is no need to crash in the
event of an error.
2025-03-10 10:46:28 +01:00
Tim Ledbetter
88d35c547c LibWeb/CSS: Implement the caret-color property 2025-03-09 19:36:29 +01:00
Tim Ledbetter
bf15b7ac12 LibWeb: Treat media query with an invalid media type as invalid 2025-03-09 17:48:36 +00:00
Aliaksandr Kalenik
667cb01b60 LibWeb: Fix layout mode propagation in SVGFormattingContext 2025-03-09 18:40:37 +01:00
Aliaksandr Kalenik
92a3419799 LibWeb: Skip invalidating :first-child and :last-child if possible
There is no need to invalidate siblings affected by these pseudo classes
if invalidation reason is not insertion or removal of tree nodes.
2025-03-09 18:40:37 +01:00
Timothy Flynn
cf69f52d53 LibIPC+Everywhere: Always pass ownership of transferred data to clients
This has been a longstanding ergonomic issue with our IPC compiler. Non-
trivial types were previously passed by const&. So if we wanted to avoid
expensive copies, we would have to const_cast and move the data.

We now pass ownership of all transferred data to the client subclasses.
This allows us to remove const_cast from these methods, and allows us to
avoid some trivial expensive copies that we didn't bother to const_cast.
2025-03-09 11:14:20 -04:00
Timothy Flynn
0f05aac290 LibCore: Mark the lambda in Promise::when_resolved as mutable
This allows the handler passed into this function to also be mutable.
2025-03-09 11:14:20 -04:00
Timothy Flynn
8f6169859d LibWebSocket: Remove meaningless const&& Message constructor
This results in an ambiguity error in an upcoming commit.
2025-03-09 11:14:20 -04:00
Timothy Flynn
5f76324af5 LibDevTools+LibWebView: Take advantage of IPC encoding improvements 2025-03-09 11:14:20 -04:00
Timothy Flynn
62912b985a LibWeb+WebContent: Take advantage of IPC encoding improvements
This removes a couple of places where we were constructing strings or
vectors just to transfer data over IPC. And passes some values by const&
to remove clangd noise.
2025-03-09 11:14:20 -04:00
Timothy Flynn
68947d55d9 LibIPC: Do not require constructing containers when sending IPC messages
For example, consider the following IPC message:

    do_something(u64 page_id, String string, Vector<Data> data) =|

We would previously generate the following C++ method to encode/transfer
this message:

    void do_something(u64 page_id, String string, Vector<Data> data);

This required the caller to either have to copy the non-trivial types or
`move` them in. In some places, this meant we had to construct temporary
vectors just to send an IPC.

This isn't necessary because we weren't holding onto these parameters
anyways. We would construct an IPC::Message subclass with them (which
does require owning types), but then immediate encode the message to
an IPC::MessageBuffer and send it.

We now generate code such that we don't need to construct a Message. We
can simply encode the parameters directly without needing ownership.
This allows us to take view-types to IPC parameters.

So the above example now becomes:

    void do_something(u64, StringView, ReadonlySpan<Data>);
2025-03-09 11:14:20 -04:00
Timothy Flynn
a5b996c079 LibIPC: Add a generic encoder for spans 2025-03-09 11:14:20 -04:00
Timothy Flynn
b090952274 LibIPC: Remove outdated warning about changing IPC encodings
We are no longer constrained by this LibC encoding.
2025-03-09 11:14:20 -04:00
Tim Ledbetter
6178557a07 LibWeb: Implement the HTMLInputElement.list attribute
This returns the `HTMLDataListElement` pointed to by the `list`
content attribute.
2025-03-09 15:10:55 +00:00
Ali Mohammad Pur
5355710481 LibRegex: Don't treat single-jump blocks as noop in the optimizer 2025-03-09 14:37:57 +01:00
Aliaksandr Kalenik
868981a46b LibWeb: Skip animation invalidation for elements nested in display none
Paper over the fact we sometimes fail to cancel animations for elements
nested in display none, and do lots of wasted work.
2025-03-09 00:06:13 +01:00
Aliaksandr Kalenik
268143681e LibWeb: Don't drop layout tree in CSS animation invalidation
It's possible to do a partial tree rebuild instead.
2025-03-09 00:06:13 +01:00
Andreas Kling
067d21b8a4 LibWeb: Don't drop entire layout tree on media query state change
This isn't actually necessary, since we already invalidate style for the
entire document, and the subsequent style update will discover any
additional layout invalidation needed as well.
2025-03-08 20:22:01 +01:00
Andreas Kling
0a300fe59b LibWeb: Update the layout tree when CSS text-transform changes
Because we cache the transformed text string in text nodes affected by
text-transform, we have to actually update the layout tree when this
property value changes.
2025-03-08 20:22:01 +01:00
Andreas Kling
def0bcdfa2 LibWeb: Don't unconditionally relayout on animation/transition changes
If a CSS animation or transition was being used to manipulate a property
that itself does not affect layout, we were still doing a full relayout
whenever any animation or transition related property was changed.

As it turns out, we can just not do that, and we avoid a bunch of
unnecessary layout work on many pages. When a layout-affecting property
is being animated, the animation/transition update code takes care to
invalidate layout as appropriate anyway!

This was very noticeable on GitHub, where moving the mouse cursor
between "Issues" and "Pull requests" would trigger a full relayout every
time. Now that doesn't happen, and it's much more responsive. :^)
2025-03-08 17:32:53 +01:00
Aliaksandr Kalenik
a4463c45b9 LibWeb: Bring back cache of intrinsic sizes across layout runs
12c6ac78e2 with fixed mistake when cache
slot is copied instead of being referenced:
```cpp
auto cache =
    box.cached_intrinsic_sizes().min_content_height.ensure(width);
```
while it should've been:
```cpp
auto& cache =
    box.cached_intrinsic_sizes().min_content_height.ensure(width);
```
2025-03-08 14:52:33 +01:00
Andreas Kling
73a4b176cf Revert "LibWeb: Cache intrinsic sizes across layout runs"
This reverts commit 12c6ac78e2.

Very large performance regression when viewing GitHub repository pages.
2025-03-08 12:08:51 +01:00
Aliaksandr Kalenik
12c6ac78e2 LibWeb: Cache intrinsic sizes across layout runs
This change moves intrinsic sizes cache from
LayoutState, which is local to current layout run,
to layout nodes, so it could be reused between
layout runs. This optimization is possible because
we can guarantee that these measurements will
remain unchanged unless the style of the element
or any of its descendants changes.

For now, invalidation is implemented simply by
resetting cache on whole ancestors chain once we
figured that element needs layout update.
The case when layout is invalidated by DOM's
structural changes is covered by layout tree
invalidation that drops intrinsic sizes cache
along with layout nodes.

I measured improvement on couple websites:
- Mail list on GMail 28ms -> 6ms
- GitHub large code page 47ms -> 36ms
- Discord chat history 15ms -> 8ms
(Time does not include `commit()`)
2025-03-08 11:45:36 +01:00
Andreas Kling
180a58b3d2 LibWeb: Don't drop entire layout tree on <input type=file> update
This was completely unnecessary, and we can just let the internal
DOM tree changes trigger partial layout updates instead.

Noticed we were repeatedly dropping layout trees on ChatGPT and this
was one of the culprits.
2025-03-08 03:37:38 +01:00
Andreas Kling
6c6f9936e2 LibWeb: Avoid more unnecessary relayouts on CharacterData text change
If the CharacterData node has no layout node when we're changing its
text, we don't need to mark the document for relayout.

This is fine, because if the node ends up getting a layout node attached
to it, we'll naturally perform relayout after that anyway.
2025-03-08 03:37:38 +01:00
Andreas Kling
267b84ebb6 LibWeb: Skip flex/grid layout when doing intrinsic sizing for ancestor
We don't need to perform inside layout of flex and grid formatting
contexts when one of their ancestors is undergoing intrinsic size
measurement. This is because the parent formatting context will have
already sized the flex/grid container, and thus inside layout is
completely redundant work.
2025-03-08 03:37:38 +01:00
Andreas Kling
6444fdf5ae LibWeb: Remove unnecessary full layout tree drop in SVGUseElement
This full invalidation was just papering over earlier bugs in the
partial layout tree update code. The DOM mutations that happen here
should be enough to drive the necessary invalidation now.

Note that this is covered by a regression test added with the
invalidation.
2025-03-08 03:37:38 +01:00
Andreas Kling
2abbf99a95 LibWeb: Add opt-in tracing of set_needs_layout() calls with reason 2025-03-08 03:37:38 +01:00
Andreas Kling
415079bc11 LibWeb: Add opt-in tracing of invalidate_layout_tree() calls with reason 2025-03-08 03:37:38 +01:00
Andreas Kling
c333042e63 LibWeb: Add opt-in tracing of update_layout() calls with reason 2025-03-08 03:37:38 +01:00