Commit Graph

278 Commits

Author SHA1 Message Date
Andreas Kling
53d0dd4a2e LibJS+LibWeb: Use new Cell::Visitor helpers to avoid manual iteration 2024-04-16 07:40:01 +02:00
Tim Ledbetter
c6f070d29e LibWeb/Fetch: Don't crash when a fetch request times out
Previously, calling fetch with a signal object provided by
`AbortSignal.timeout()` would cause a crash when the signal timed out.

We now push a `TemporaryExecutionContext` to the stack when we invoke
the signal's abort steps, as an execution context is required when
calling native functions.
2024-04-14 13:36:25 +02:00
Matthew Olsson
31341b280a LibWeb: Add calls to JS_{DECLARE,DEFINE}_ALLOCATOR() 2024-04-09 09:13:06 +02:00
Shannon Booth
70e2f51674 LibWeb: Prefer GCPtr<T> over Optional<NonnullGCPtr<T>> 2024-04-07 18:01:05 +02:00
Andreas Kling
2ef37c0b06 LibWeb: Make EventLoop, TaskQueue, and Task GC-allocated
...and use HeapFunction instead of SafeFunction for task steps.

Since there is only one EventLoop per process, it lives as a global
handle in the VM custom data.

This makes it much easier to reason about lifetimes of tasks, task
steps, and random stuff captured by them.
2024-04-05 08:14:19 +02:00
Timothy Flynn
683c08744a Userland: Avoid some conversions from rvalue strings to StringView
These are all actually fine, there is no UAF here. But once e.g.
`ByteString::view() &&` is deleted, these instances won't compile.
2024-04-04 11:23:21 +02:00
0x4261756D
a005aae497 LibJS: Add missing Base::visit_edges() in FetchAlgorithms and Navigable
These are empty calls since `Base` is JS::Cell  but they *are* missing
and LibJSGCVerifier complains otherwise.
2024-04-04 07:50:13 +02:00
Timothy Flynn
69b5d7c0e6 LibWeb: Avoid UAF when encoding a fetch request body via URLSearchParams 2024-04-03 17:14:01 -04:00
Andreas Kling
a9842ebe48 LibWeb: Use JS::HeapFunction in Fetch::Fetching::PendingResponse
This fixes a long-standing realm leak.
2024-04-03 18:14:33 +02:00
Timothy Flynn
d74059580c LibWeb: Return the correct substring when parsing an HTTP quoted string
We were off-by-one when returning the result of parsing a quoted string
in Web::Fetch::Infrastructure::collect_an_http_quoted_string. Instead of
backtracking the lexer and consuming the backtracked string, do a simple
substring operation.
2024-03-26 19:19:13 +00:00
Tim Ledbetter
17e64cf08b LibWeb/Fetch: Replace usages of AbortSignal::follow() in Fetch::Request
Since the introduction of `AbortSignal::any()`, the specification says
`AbortSignal::create_dependent_abort_signal()` should be used where
`AbortSignal::follow` was previously.
2024-03-26 11:42:40 +01:00
Timothy Flynn
74377618b1 LibWeb: Process Base64 data URLs with the forgiving Base64 algorithm 2024-03-25 08:13:27 +01:00
Timothy Flynn
24ecf31ff5 LibURL+LibWeb: Move data URL processing to LibWeb's fetch infrastructure
This is a fetching AO and is only used by LibWeb in the context of fetch
tasks. Move it to LibWeb with other fetch methods.

The main reason for this is that it requires the use of other LibWeb AOs
such as the forgiving Base64 decoder and MIME sniffing. These AOs aren't
available within LibURL.
2024-03-25 08:13:27 +01:00
Timothy Flynn
7b3ddd5e15 LibWeb: Track fetching-related tasks in FetchController for cancellation
The HTMLMediaElement, for example, contains spec text which states any
ongoing fetch process must be "stopped". The spec does not indicate how
to do this, so our implementation is rather ad-hoc.

Our current implementation may cause a crash in places that assume one
of the fetch algorithms that we set to null is *not* null. For example:

    if (fetch_params.process_response) {
        queue_fetch_task([]() {
            fetch_params.process_response();
        };
    }

If the fetch process is stopped after queuing the fetch task, but not
before the fetch task is run, we will crash when running this fetch
algorithm.

We now track queued fetch tasks on the fetch controller. When the fetch
process is stopped, we cancel any such pending task.

It is a little bit awkward maintaining a fetch task ID. Ideally, we
could use the underlying task ID throughout. But we do not have access
to the underlying task nor its ID when the task is running, at which
point we need some ID to remove from the pending task list.
2024-03-23 13:45:35 +01:00
Shannon Booth
e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00
Andreas Kling
c0d7f748ed LibWeb: Avoid FlyString lookups when setting IDL interface prototypes
This commit introduces a WEB_SET_PROTOTYPE_FOR_INTERFACE macro that
caches the interface name in a local static FlyString. This means that
we only pay for FlyString-from-literal lookup once per browser lifetime
instead of every time the interface is instantiated.
2024-03-16 16:35:54 +01:00
Timothy Flynn
7681772b9f LibWeb: Log failed Fetch responses when WEB_FETCH_DEBUG is enabled
We do the same for successful responses. Very useful for debugging
issues on live websites.
2024-03-14 10:10:33 +01:00
Sam Atkins
4bdb7dba8c LibWeb: Add and use a helper to reject a promise with an exception 2024-03-08 14:14:57 -05:00
Andrew Kaster
c79bac70f4 LibWeb: Consistently use the EmptyString state of ReferrerPolicy
We previously used an empty optional to denote that a ReferrerPolicy is
in the default empty string state. However, later additions added an
explicit EmptyString state. This patch moves all users to the explicit
state, and stops using `Optional<ReferrerPolicy>` everywhere except for
when an option not being passed from JavaScript has meaning.
2024-03-06 07:19:10 +01:00
Shannon Booth
9ce8189f21 Everywhere: Use unqualified AK::URL
Now possible in LibWeb now that there is no longer a Web::URL.
2024-02-25 08:54:31 +01:00
Shannon Booth
f9e5b43b7a LibWeb: Rename URL platform object to DOMURL
Along with putting functions in the URL namespace into a DOMURL
namespace.

This is done as LibWeb is in an awkward situation where it needs
two URL classes. AK::URL is the general purpose URL class which
is all that is needed in 95% of cases. URL in the Web namespace
is needed predominantly for interfacing with the javascript
interfaces.

Because of two URLs in the same namespace, AK::URL has had to be
used throughout LibWeb. If we move AK::URL into a URL namespace,
this becomes more painful - where ::URL::URL is required to
specify the constructor (and something like
::URL::create_with_url_or_path in other places).

To fix this problem - rename the class in LibWeb implementing the
URL IDL interface to DOMURL, along with moving the other Web URL
related classes into this DOMURL folder.

One could argue that this name also makes the situation a little
more clear in LibWeb for why these two URL classes need be used
in the first place.
2024-02-25 08:54:31 +01:00
Timothy Flynn
66959bcc09 LibWeb: Use the stream teeing methods for cloning Fetch response bodies 2024-01-29 07:21:59 +01:00
Shannon Booth
5f484d200a LibWeb: Port Stream algorithms from JS::SafeFunction to JS::HeapFunction 2024-01-27 21:40:25 -05:00
Timothy Flynn
9272d185ad LibWeb: Implement a slightly better ad-hoc Body::clone method
Just creating a stream on the JS heap isn't enough, as we will later
crash when trying to read from that stream as it hasn't been properly
initialized. Instead, until we have teeing implemented (which is a
rather huge part of the Streams spec), create streams using proper AOs
that do initialize the stream.
2024-01-27 16:01:56 +01:00
Timothy Flynn
85b8971a80 Ladybird+LibWeb+WebContent: Port the did_request_cookie IPC to String 2024-01-26 20:22:39 +01:00
Timothy Flynn
09124fc3a5 LibWeb: Set up the Fetch response's body with the appropriate stream 2024-01-25 21:34:03 +01:00
Timothy Flynn
2b22402c6a LibWeb: Correctly categorize Fetch responses as network errors
The condition here is flipped. From the spec:

     A network error is a response whose ... body is null ...
2024-01-18 23:10:56 +01:00
Bastiaan van der Plaat
05c0640474 Ladybird+LibWeb: Add about scheme support for internal pages 2024-01-13 13:41:09 -05:00
Andreas Kling
89da988da1 LibWeb: Honor User-Agent spoofing in Fetch headers
This makes spoofing consistent between legacy ResourceLoader loads,
Fetch loads, and the JavaScript `navigator` APIs.
2023-12-27 11:43:14 +01:00
Timothy Flynn
e511a264fe LibWeb: Implement ad-hoc steps to allow LibWeb to load resource:// URLs
The resource:// scheme is used for Core::Resource files. Currently, any
users of resource:// URLs in Ladybird must manually create the Resource
and extract its data. This will allow for passing the resource:// URL
along for LibWeb to handle.
2023-12-24 14:09:23 +01:00
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Andreas Kling
9793d69d4f LibWeb: Make HTML::Window::page() return a Page& 2023-12-15 22:04:46 +01:00
Andreas Kling
7c95ebc302 LibWeb: Make Document::page() return a Page&
Now that Document always has a Page, and always keeps it alive, we can
make this return a Page&, exposing various unnecessary null checks.
2023-12-15 22:04:46 +01:00
Shannon Booth
96af80acd1 LibWeb: Port Intrinsics from DeprecatedString 2023-11-28 17:15:27 -05:00
Shannon Booth
04c094343f LibWeb+Meta: Add wrapper for the BufferSource/ArrayBufferView IDL types
These wrappers will make it much easier to do various operations on the
different ArrayBuffer-related classes in LibWeb compared to the current
solution, which is to just accept a Handle<Object> everywhere (and use
"any" in the *.idl files).

Co-Authored-By: Matthew Olsson <mattco@serenityos.org>
2023-11-24 08:43:35 +01:00
Andreas Kling
bfd354492e LibWeb: Put most LibWeb GC objects in type-specific heap blocks
With this change, we now have ~1200 CellAllocators across both LibJS and
LibWeb in a normal WebContent instance.

This gives us a minimum heap size of 4.7 MiB in the scenario where we
only have one cell allocated per type. Of course, in practice there will
be many more of each type, so the effective overhead is quite a bit
smaller than that in practice.

I left a few types unconverted to this mechanism because I got tired of
doing this. :^)
2023-11-19 22:00:48 +01:00
Andrew Kaster
d7d84ee931 LibWeb: Ensure a Web::Page is associated with local Worker LoadRequests
This is a hack on top of a hack because Workers don't *really* need to
have a Web::Page at all, but the ResourceLoader infra that should be
going away soon ™️ is not quite ready to axe that requirement for
cookies.
2023-11-15 12:56:33 +01:00
Matthew Olsson
1a94241f58 IDL: Add missing #imports 2023-11-11 08:51:51 +01:00
networkException
d1c1218d42 LibWeb/Fetch: Implement changes to priority
This patch updates the priority member of fetch requests to be
an enum. The implementation defined struct previously named Priority
has been renamed to InternalPriority in line with the spec.
2023-10-31 18:09:14 +01:00
Bastiaan van der Plaat
169d24ae2e LibWeb: Add comments and missing items of various IDL files 2023-10-25 19:45:41 +02:00
Aliaksandr Kalenik
5d885e9047 LibWeb/Fetch: Align is_network_error() with the latest specification 2023-10-03 09:41:56 +02:00
Aliaksandr Kalenik
084cb4350e LibWeb/Fetch: Include body and headers in Response for failed requests
Fixes https://github.com/SerenityOS/serenity/issues/21290
2023-10-03 09:41:56 +02:00
Aliaksandr Kalenik
b9e0ad4358 LibWeb: Make ResourceLoader pass body and headers in error callback
Pass body and headers of a failed request to callback so caller can
process them.
2023-10-03 09:41:56 +02:00
Aliaksandr Kalenik
ac5c4705fd LibWeb: Do not use JS::Handle for captures of AbortSignal callbacks
There is no need to use JS::Handle for captures because AbortSignal
will visit them anyway because it uses JS::HeapFunction to store the
callback.
2023-09-26 21:25:54 +02:00
Aliaksandr Kalenik
baf37af09c LibWeb: Use JS::HeapFunction for callbacks in FetchController
If a function that captures a GC-allocated object is owned by another
GC-allocated object, it is more preferable to use JS::HeapFunction.
This is because JS::HeapFunction is visited, unlike introducing a new
heap root as JS::SafeFunction does.
2023-09-25 21:14:53 +02:00
Timothy Flynn
54d1f4e234 LibJS: Stop propagating small OOM errors from the Error object 2023-09-09 13:03:25 -04:00
Shannon Booth
41928c2902 LibWeb: Port DOMException interface from DeprecatedString to String 2023-09-06 11:44:45 -04:00
Aliaksandr Kalenik
5951a93f51 LibWeb: Remove GC allocations in FetchAlgorithms constructor
We should not GC allocate in the constructors of GC-allocated objects
because a new allocation might trigger garbage collection, which in
turn might access not fully initialized objects.
2023-09-03 18:52:31 +02:00
Shannon Booth
d4a890080d LibWeb: Switch IDL from UseNewAKString to UseDeprecatedAKString
NewAKString is effectively the default for any new IDL interface, so
let's mark this as the default behavior. It also makes it much easier to
figure out whatever interfaces are still left to port over to new AK
String.
2023-09-02 19:23:41 +01:00