Commit Graph

2351 Commits

Author SHA1 Message Date
MacDue
23d8d217ed LibWeb: Ignore setting zero, negative, or non-finite CRC2D.lineWidths
This is part of the spec but was missed. This fixes a crash on:
https://www.kevs3d.co.uk/dev/phoria/test1d.html
2024-05-06 17:33:04 +02:00
Andreas Kling
493a04d5fe LibJS: Add PropertyLookupPhase enum to distinguish Object [[Get]] calls
We can now tell the difference between an own property access and a
subsequent (automatic) prototype chain access.

This will be used to implement caching of prototype chain accesses.
2024-05-04 21:42:59 +02:00
Andreas Kling
3945e1a82a LibJS: Make JS::Cell a Weakable
This makes things easier downstream of Cell, and is preparation for
using weak pointers in prototype chain property caches.
2024-05-04 21:42:59 +02:00
Timothy Flynn
2d4d16ac37 LibWeb: Remove exceptional return types from infallible stream IDL 2024-04-30 08:14:12 +02:00
Shannon Booth
bad44f8fc9 LibWeb: Remove Bindings/Forward.h from LibWeb/Forward.h
This was resulting in a whole lot of rebuilding whenever a new IDL
interface was added.

Instead, just directly include the prototype in every C++ file which
needs it. While we only really need a forward declaration in each cpp
file; including the full prototype header (which itself only includes
LibJS/Object.h, which is already transitively brought in by
PlatformObject) - it seems like a small price to pay compared to what
feels like a full rebuild of LibWeb whenever a new IDL file is added.

Given all of these includes are only needed for the ::initialize
method, there is probably a smart way of avoiding this problem
altogether. I've considered both using some macro trickery or generating
these functions somehow instead.
2024-04-27 18:29:35 -04:00
Aliaksandr Kalenik
b1205f0aa1 LibWeb: Skip unnecessary sample corner and blit corner commands
Before this change we were recording and executing sample/blit commands
for each painting phase, even if there are no painting commands
in-between sample and blit that produce result visible on a canvas.

This change adds an optimization pass that goes through recorded
painting commands list and marks sample and blit commands that could
be skipped.

Reduces sample and blit corners executing from 17% to 8% on Discord.
2024-04-27 21:06:16 +02:00
Shannon Booth
d27b70ae24 LibWeb: Add HTML event 'complete' 2024-04-27 07:11:02 +02:00
Timothy Flynn
1ffda6a805 LibWeb: Propagate OOM in Body::fully_read() through its error callback
Fetched bodies can be on the order of gigabytes, so rather than crashing
when we hit OOM here, we can simply invoke the error callback with a DOM
exception. We use "UnknownError" here as the spec directly supports this
for OOM errors:

    UnknownError: The operation failed for an unknown transient reason
                  (e.g. out of memory).

This is still an ad-hoc implementation. We should be using streams, and
we do have the AOs available to do so. But they need to be massaged to
be compatible with callers of Body::fully_read. And once we do use
streams, this function will become infallible - so making it infallible
here is at least a step in the right direction.
2024-04-27 07:08:14 +02:00
Timothy Flynn
c79f46fe6f LibWeb: Remove OOM propagation from Fetch::Infrastructure::Headers 2024-04-27 07:08:14 +02:00
Andreas Kling
ff9ae5ff40 LibWeb: Bring document & browsing context creation in line with spec
We had drifted away from the spec steps a little bit here. This patch
brings us back in line and knocks off some FIXMEs in the process.
2024-04-26 20:01:58 +02:00
Andreas Kling
a5c62b953f LibWeb: Take care of some FIXMEs in auxiliary browsing context creation 2024-04-26 20:01:58 +02:00
Andreas Kling
0ebfc0a4c4 LibWeb: Move event handling & cursor from BrowsingContext to Navigable
This was a long standing FIXME since the introduction of navigables.
2024-04-26 20:01:58 +02:00
Andreas Kling
9cd4a65071 LibWeb: Move TraversableNavigable::m_page up to Navigable
This will allow anyone who has a Navigable to reach the Page.
2024-04-26 20:01:58 +02:00
Timothy Flynn
13422b5116 LibWeb: Remove OOM error propagation from HTMLMediaElement (and friends) 2024-04-26 12:21:57 -04:00
Timothy Flynn
dd16ea87c3 LibWeb: Make HTMLMediaElement::set_decoder_error infallible
This used to propagate an OOM error, but that was removed, and this
method can no longer throw.
2024-04-26 12:21:57 -04:00
MINAqwq
7c54a32870 LibWeb: Set decoder error when decoding fails 2024-04-26 11:48:48 -04:00
Andreas Kling
a4625e3943 LibWeb: Only react to link element attribute changes when BC connected
Link elements that aren't "browsing-context connected" should not
trigger a resource fetch when their attributes change.

This fixes an issue where we'd waste time by loading every style sheet
twice! :^)
2024-04-26 10:40:43 +02:00
Timothy Flynn
f6407276f7 LibWeb: Stop the video decoder thread when the video element is GC'd
Otherwise, the thread will continue to run and access the media data
buffer, which will have been freed.

The test here is a bit strange, but the issue would only consistently
repro after several GC runs.
2024-04-26 09:49:11 +02:00
Timothy Flynn
f13ccb9a61 LibWeb: Add missing call to Base::finalize() in HTMLMediaElement 2024-04-26 09:49:11 +02:00
Aliaksandr Kalenik
988c8451d4 LibWeb: Skip HTMLLinkElement resource fetching for documents without BC
Fixes crashing after following steps:
1. Open https://github.com/SerenityOS/serenity
2. Click on "Pull requests" tab

The problem was `navigable` null pointer dereferencing in
`decode_favicon()`. But navigable is null because the document was
created by `parseFromString()` DOMParser API.

With this change we skip fetching initiated by HTMLLinkElement if
document does not have a browsing context:
- Favicon is not displayed for such documents so no need to fetch.
- Stylesheets fetching won't affect such document because style or
  layout does not run for them.
2024-04-25 09:31:01 +02:00
Andreas Kling
4c921e17b7 LibWeb: Allocate dataset lazily for HTML/SVG/MathML elements
Most elements never need a dataset object, so we can avoid creating lots
of objects by making them lazy.
2024-04-25 09:30:30 +02:00
Timothy Flynn
ec492a1a08 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There are a couple of weird cases where clang-format now thinks that a
pointer access in an initializer list, e.g. `m_member(ptr->foo)`, is a
lambda return statement, and it puts spaces around the `->`.
2024-04-24 16:50:01 -04:00
Andreas Kling
f60d82eb85 LibWeb: Make HTML::Environment a GC-allocated type
The only subclass was already GC-allocated, so let's hoist the JS::Cell
inheritance up one level. This ends up simplifying a bit of rather
dubious looking code where we were previously slicing ESOs.
2024-04-24 17:04:43 +02:00
Bastiaan van der Plaat
7fa45c5fdf LibWeb: Add map element areas property 2024-04-24 15:23:45 +02:00
Bastiaan van der Plaat
3e507102ea LibWeb: Add datalist element options property 2024-04-24 15:23:45 +02:00
Aliaksandr Kalenik
55154b6c68 LibWeb: Use SafeFunction for completion steps in "populate SHE"
...to visit GC-allocated objects captured by this callback.
2024-04-24 10:22:29 +02:00
Aliaksandr Kalenik
64ad536dbb LibWeb: Create HeapFunction for after_document_populated
...to make it visited by SafeFunction callback of deferred_invoke().

Fixes use-after-free ASAN error that happens if you try to reload the
page.
2024-04-24 10:22:29 +02:00
Andrew Kaster
651e78fedb LibWeb: Convert callers of ImageCodecPlugin to the async API
The HTMLLinkElement caller is a bit hairy, so we shove an await() in
there temporarily. This is sure to cause fun times for anyone debugging
task/microtask execution order.
2024-04-23 12:32:04 -06:00
Andreas Kling
184368285c LibWeb: Fix GC leaks in Fetch::Infrastructure::Body::fully_read()
By making this function accept the success and error steps as
HeapFunction rather than SafeFunction, we break a bunch of strong
GC cycles.
2024-04-23 12:50:40 +02:00
Aliaksandr Kalenik
376427380e LibWeb: Make NavigationParams be GC-allocated
Fixes GC-leak caused by using JS::Handle for navigable.
2024-04-22 17:10:11 +02:00
Andreas Kling
8e56367092 LibWeb: Allow moving StyleSheets between documents without falling apart
We have to unregister link element stylesheets from the old document's
StyleSheetList when moving them into a new document.

This makes it possible to load GitHub contributor graphs. :^)
2024-04-22 06:43:05 +02:00
Andreas Kling
d94a6d8873 LibWeb: Avoid creating tons of temporary FlyStrings in HTMLParser 2024-04-21 19:32:49 +02:00
Andreas Kling
990f8e10a5 LibWeb: Avoid redundant UTF-8 validation in HTML tokenizer 2024-04-21 19:32:49 +02:00
Aliaksandr Kalenik
3c33e1eba9 LibWeb: Make ChangingNavigableContinuationState be GC-allocated
This struct is captured by `after_document_populated` callback so making
it be GC-allocated results in more understandable GC-graph.
2024-04-21 16:44:05 +02:00
Aliaksandr Kalenik
2f345c4ab5 LibWeb: Use HeapFunction for update_document callback 2024-04-21 16:44:05 +02:00
Aliaksandr Kalenik
3b3816e683 LibWeb: Remove changing_navigable_continuation capture in callback
Capturing a struct that owns bunch of JS::Handle makes it very hard to
understand what keeps these handles alive in the GC-graph.

Instead let's capture only members of a struct used in the callback.
2024-04-21 16:44:05 +02:00
Andreas Kling
4db1712f90 LibJS+LibWeb: Make Console, ConsoleClient & subclasses GC-allocated
These objects had confusing ownership semantics. Let's just throw them
all on the GC heap and stop worrying about it.
2024-04-21 09:12:25 +02:00
Kenneth Myhra
a3661fd7f2 LibWeb: Let queue_global_task() take a JS::HeapFunction
Changes the signature of queue_global_task() from AK:Function to
JS::HeapFunction to be more clear to the user of the function that this
is what it uses internally.
2024-04-20 18:11:01 +02:00
Aliaksandr Kalenik
d3cfe35fbd LibWeb: Do not destroy document until whole subtree completed unloading
Fixes crashing when "unload" event handler tries to access active
document that has already been destroyed.
2024-04-20 10:22:14 +02:00
Andrew Kaster
5e1d678bae Ladybird+Userland: Remove use of unnecessary fd passing socket concept
Now that LibIPC is using SCM_RIGHTS properly, we can go back to only
having one socket laying around when needing to transfer fds to peers.
2024-04-19 16:38:55 -04:00
Andrew Kaster
cb87725ec8 LibIPC+LibWeb: Transfer IPC::Files using sendmsg/recvmsg directly
This refactor eliminates the need for a second "fd passing socket" on
Lagom, as it uses SCM_RIGHTS in the expected fashion, to send fds along
with the data of our Unix socket message.
2024-04-19 16:38:55 -04:00
Andrew Kaster
6d4ba21832 LibIPC+Userland: Make IPC::File always own its file descriptor
Add factory functions to distinguish between when the owner of the File
wants to transfer ownership to the new IPC object (adopt) or to send a
copy of the same fd to the IPC peer (clone).

This behavior is more intuitive than the previous behavior. Previously,
an IPC::File would default to a shallow clone of the file descriptor,
only *actually* calling dup(2) for the fd when encoding or it into an
IPC MessageBuffer. Now the dup(2) for the fd is explicit in the clone_fd
factory function.
2024-04-19 06:34:07 -04:00
Andrew Kaster
26ce8ad40f LibWeb: Stop leaking socket fds when sending them over IPC
The implicit constructor for IPC::File does not take ownership of the
file, which is surprising.
2024-04-19 06:34:07 -04:00
PGHales
ded344aa2c LibWeb/DOM: Rename link_color to normal_link_color 2024-04-19 10:58:45 +02:00
Aliaksandr Kalenik
d876f32e5d LibWeb: Skip creating a navigable for <object> not connected to document
Navigation should not run for <object> element until it is inserted into
a document. Spec deoes not seem to explicitely say that, but that
matches other browsers behavior.

Fixes hanging after reloading in Acid3 test.
2024-04-18 08:09:51 +00:00
Aliaksandr Kalenik
68440ed02d LibWeb: Destroy associated navigable when <object> is removed from DOM 2024-04-18 08:09:51 +00:00
Andreas Kling
1cb5385a29 LibCore: Stop obsessing about tiny OOMs in Core::Timer
Work towards #20405
2024-04-17 07:16:52 +02:00
Tim Ledbetter
4a3497e9cd LibWeb: Support loading alternative style sheets
Alternative style sheets are now fetched and are applied to the
document if they are explicitly enabled by removing the disabled
attribute.
2024-04-17 07:12:44 +02:00
Aliaksandr Kalenik
890da021c4 LibWeb: Abort ongoing navigation before firing next navigation event
I haven't found this being mentioned in the current spec, but that is
what chromium (atm the only other Navigation API implementer) does.

Fixes crashing when location.hash is changed subsequently more than once
using JS.
2024-04-16 19:51:56 +02:00
Aliaksandr Kalenik
9f4b922f1c LibWeb: Look into nested session histories to find max history step
Fixes bug when "navigate forward" button in UI is disabled after
performing following steps:
1. Load page with an iframe (top step = 0, iframe step = 0)
2. Navigate iframe to different document (top step = 0, iframe step = 1)
3. Navigate back from browser UI (top step = 0, iframe step = 0)

No test because change is only observable from browser UI.
2024-04-16 05:59:19 -07:00