Commit Graph

338 Commits

Author SHA1 Message Date
Timothy Flynn
8d4d01d99a LibWeb: Invent a method to stop an in-progress fetch without errors
The HTMLMediaElement will need to stop fetching processes when its load
algorithm is invoked while a fetch is ongoing. We don't have a way to
really stop the process, due to the way it runs on nested deferred task
invocations. So for now, this swaps the fetch callbacks (e.g. to process
a fetch response) with empty callbacks.
2023-04-20 06:19:41 +02:00
Linus Groh
fd35fc5ba8 LibWeb/Fetch: Fix build error in HeadersIterator::next()
Regressed in d4eaaf9.
2023-04-15 16:49:37 +02:00
MacDue
35612c6a7f AK+Everywhere: Change URL::path() to serialize_path()
This now defaults to serializing the path with percent decoded segments
(which is what all callers expect), but has an option not to. This fixes
`file://` URLs with spaces in their paths.

The name has been changed to serialize_path() path to make it more clear
that this method will generate a new string each call (except for the
cannot_be_a_base_url() case). A few callers have then been updated to
avoid repeatedly calling this function.
2023-04-15 06:37:04 +02:00
Linus Groh
1c165b67ef LibWeb/Streams: Use MUST_OR_THROW_OOM() when creating JS exceptions
This cannot throw unless we OOM.
2023-04-14 16:35:17 +02:00
networkException
9915fa72fb AK+Everywhere: Use Optional for URLParser::parse's base_url parameter 2023-04-11 16:28:20 +02:00
Aliaksandr Kalenik
47f03c3a9a LibWeb/Fetch: Use a basic filtered response for redirect navigations
Match following change in the spec:
8f109835dc
2023-04-09 19:10:45 +02:00
Kenneth Myhra
1120011de4 LibWeb: Add FormData support to XHR
This adds FormData support to XHR so that it can post
multipart/form-data encoded data.
2023-04-05 09:43:52 +01:00
Timothy Flynn
ddb4137ed4 LibWeb: Ensure fetch errors set their response types/codes appropriately
If we fail to set the response type to an error, calling code will think
the fetch was successful. We also should not default to an error code of
200, which would also indicate success.
2023-04-04 22:41:20 +01:00
Andreas Kling
d005b1ad1b LibWeb: Support loading file:// URLs via fetch (through ResourceLoader)
This builds on the existing ad-hoc ResourceLoader code for HTTP fetches
which works for files as well.

This also includes a test that checks that stylesheets loaded with the
"file" URL scheme actually work.
2023-03-22 23:34:32 +00:00
Matthew Olsson
7c0c1c8f49 LibJS+LibWeb: Wrap raw JS::Cell*/& fields in GCPtr/NonnullGCPtr 2023-03-15 08:48:49 +01:00
Andreas Kling
a504ac3e2a Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_case
Let's make it clear that these functions deal with ASCII case only.
2023-03-10 13:15:44 +01:00
Linus Groh
5cc6b1c4db LibWeb/HTML: Port Window.fetch() to IDL 2023-03-07 23:33:34 +00:00
Luke Wilde
b91b67f4f3 LibWeb/Fetch: Actually check if the response is null in recursive fetch
The condition for checking if there was already a response in recursive
fetch was accidentally flipped, always causing a null deref.

This made redirects crash for example.
2023-03-07 18:42:10 +00:00
Luke Wilde
acd5382924 LibWeb/Fetch: Set length synchronously in extract_body
Since we don't currently have streams, we didn't set length anywhere.
However, this is required by XHR's reliance on Fetch to get the total
number of bytes for the progress events.
2023-03-07 11:51:12 +00:00
Luke Wilde
e557602d34 LibWeb: Fully read body if there is one in fetch response handover
Required by XHR's reliance on Fetch.
2023-03-07 11:51:12 +00:00
Luke Wilde
cfbd0bbe0a LibWeb/Fetch: Implement Header's "extract a length" function
Required by XHR's reliance on Fetch.
2023-03-07 11:51:12 +00:00
Luke Wilde
ccdb1bcc4e LibWeb/Fetch: Implement Body's "fully read" function from the spec
Required by XHR's reliance on Fetch.
2023-03-07 11:51:12 +00:00
Luke Wilde
9acc542059 LibWeb: Propagate Realm instead of VM more through Fetch
This makes Fetch rely less on using main_thread_vm().current_realm(),
which relies on the dummy execution context if no JavaScript is
currently running.
2023-03-07 11:51:12 +00:00
Matthew Olsson
c0b2fa74ac LibWeb: Fix a few const-ness issues 2023-03-06 13:05:43 +00:00
Matthew Olsson
70a2ca7fc0 LibJS: Handle both const and non-const Ts in Handle<T>::create()
Again, the const-ness only really involves Heap-internal metadata, so
the callers shouldn't care about mutations here.
2023-03-06 13:05:43 +00:00
Linus Groh
1032ac2453 LibWeb/Fetch: Store Response error message as a String{,View} variant
The majority of error strings are StringView literals, and it seems
silly to require heap-allocating strings for these.

This idea is stolen from a recent change in fd1fbad :^)
2023-03-03 19:50:36 +00:00
Linus Groh
ad4b4046f4 LibWeb/Fetch: Propagate OOM errors from HeaderList::extract_mime_type() 2023-03-03 11:02:21 +00:00
Linus Groh
2d7ce38ee2 LibWeb/MimeSniff: Port MimeType to new String 2023-03-03 11:02:21 +00:00
Linus Groh
fabea2a6a7 LibWeb/MimeSniff: Rename MimeType::from_string() to MimeType::parse()
This matches the spec's "parse a MIME type".
2023-03-03 11:02:21 +00:00
Linus Groh
11023a3c53 LibWeb/Fetch: Port infrastructure to new String 2023-03-03 09:25:34 +00:00
Linus Groh
7f9ddcf420 LibWeb/Fetch: Port JS interfaces to new String
Since BodyInit and Headers are tightly coupled to both Request and
Response, I chose to do all of them at once instead of introducing a
bunch of temporary conversion glue code.
2023-03-03 09:25:34 +00:00
Kenneth Myhra
9da09e4fd3 LibWeb: Port URL and URLSearchParams to new String 2023-03-01 22:44:20 +00:00
Kenneth Myhra
9a5a8d617d LibWeb: Port IDL implementations Blob and File to new String 2023-02-26 00:27:22 +01:00
Kenneth Myhra
3f50025126 LibWeb: Make factory method of Fetch::Response fallible 2023-02-22 09:55:33 +01:00
Kenneth Myhra
54913adf37 LibWeb: Make factory method of Fetch::Request fallible 2023-02-22 09:55:33 +01:00
Kenneth Myhra
a2381a672d LibWeb: Make factory method of Fetch::HeadersIterator fallible 2023-02-22 09:55:33 +01:00
Sam Atkins
2026ea557e LibWeb: Use is_ascii_case_insensitive_match() where the spec says to 2023-02-19 00:46:47 +01:00
Kenneth Myhra
15917146d3 LibWeb: Make factory method of FileAPI::Blob fallible 2023-02-18 00:52:47 +01:00
Timothy Flynn
88814acbd3 LibJS+Everywhere: Convert JS::Error to String
This includes an Error::create overload to create an Error from a UTF-8
StringView. If creating a String from that view fails, the factory will
return an OOM InternalError instead. VM::throw_completion can also make
use of this overload via its perfect forwarding.
2023-02-17 09:14:23 -05:00
networkException
f1dd4f42bc LibWeb: Clarify WebIDL::Promise as an alias for JS::PromiseCapability
This patch adds the WebIDL::Promise type explicitly defined in the
WebIDL spec to be a PromiseCapability Record from ecma262.
2023-02-13 12:11:32 +00:00
Linus Groh
ee68eba0ac LibWeb: Implement Headers.getSetCookie()
This is a normative change in the Fetch spec.
See: https://github.com/whatwg/fetch/commit/e4d3480

This also implements the changes to the 'sort and combine' algorithm,
which now treats "set-cookie" headers differently, and is exposed to JS
via the Headers' iterator.

Passes all 21 WPT tests :^)
http://wpt.live/fetch/api/headers/header-setcookie.any.html
2023-02-11 13:14:26 +00:00
Linus Groh
6bce48e99b LibWeb: Fix UAF in convert_header_names_to_a_sorted_lowercase_set()
We can't keep a span (ReadonlyBytes) to a move()'d ByteBuffer
in the header_names_seen HashTable - copy the original name span instead
which works the same thanks to CaseInsensitiveBytesTraits.

This would sporadically fail the contains() check due to garbage data,
later leading to a VERIFY() crash in the OrderedHashTable append loop.
2023-02-11 13:14:26 +00:00
Luke Wilde
349c126d8d LibWeb/Fetch: Implement CORS preflight
The main things missing is the CORS preflight cache and making
extract_header_list_values properly parse, validate and return split
values for the Access-Control headers.
2023-02-10 22:18:19 +00:00
Luke Wilde
237df9df5c LibWeb: Make extract_header_list_values differentiate parsing failures
Previously, parsing failures and the header not existing made
extract_header_list_values return an empty Optional, making it
impossible to differentiate between the two.

Required for implementing CORS-preflight, where parsing failures for
the headers makes it fail, but not having them doesn't make it fail in
all cases.
2023-02-10 22:18:19 +00:00
Luke Wilde
bf2895365b LibWeb/Fetch: Don't add cookies when creating ResourceLoader request
Using LoadRequest::create_for_url_on_page will unconditionally add
cookies as long as there's a page available. However, it is up to
http_network_or_cache_fetch to determine if cookies should be added to
the request.

This was noticed when implementing CORS-preflight requests, where we
sent cookies in OPTIONS requests.
2023-02-10 22:18:19 +00:00
Timothy Flynn
7955cb14fb LibWeb: Add missing GCPtr.h includes to Fetch headers
These are missing in most Fetch headers, and clangd is (rightfully) very
loud about it on a few of these.
2023-02-10 13:53:45 +00:00
Timothy Flynn
604d5f5bca AK+Everywhere: Do not implicitly copy variables in TRY macros
For example, consider cases where we want to propagate errors only in
specific instances:

    auto result = read_data(); // something like ErrorOr<ByteBuffer>
    if (result.is_error() && result.error().code() != EINTR)
        continue;
    auto bytes = TRY(result);

The TRY invocation will currently copy the byte buffer when the
expression (in this case, just a local variable) is stored into
_temporary_result.

This patch binds the expression to a reference to prevent such copies.
In less trival invocations (such as TRY(some_function()), this will
incur only temporary lifetime extensions, i.e. no functional change.
2023-02-10 09:08:52 +00:00
Timothy Flynn
c3abb1396c LibJS+LibWeb: Convert string view PrimitiveString instances to String
First, this adds an overload of PrimitiveString::create for StringView.
This overload will throw an OOM completion if creating a String fails.
This is not only a bit more convenient, but it also ensures at compile
time that all PrimitiveString::create(string_view) invocations will be
handled as String and OOM-aware.

Next, this wraps all invocations to PrimitiveString::create(string_view)
with MUST_OR_THROW_OOM.

A small PrimitiveString::create(DeprecatedFlyString) overload also had
to be added to disambiguate between the StringView and DeprecatedString
overloads.
2023-02-09 17:13:33 +00:00
Timothy Flynn
b75b7f0c0d LibJS+Everywhere: Propagate Cell::initialize errors from Heap::allocate
Callers that are already in a fallible context will now TRY to allocate
cells. Callers in infallible contexts get a FIXME.
2023-01-29 00:02:45 +00:00
Timothy Flynn
2692db8699 LibJS+Everywhere: Allow Cell::initialize overrides to throw OOM errors
Note that as of this commit, there aren't any such throwers, and the
call site in Heap::allocate will drop exceptions on the floor. This
commit only serves to change the declaration of the overrides, make sure
they return an empty value, and to propagate OOM errors frm their base
initialize invocations.
2023-01-29 00:02:45 +00:00
Linus Groh
6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Timothy Flynn
34574c5ee8 LibJS+LibWeb: Convert empty PrimitiveString invocators to String 2023-01-22 01:03:13 +00:00
Andreas Kling
db27499865 LibWeb: Make sure that fetch() response cookies get saved
We have to provide the Web::Page* in order for cookies to get saved.
2023-01-15 10:53:58 +00:00
Andrew Kaster
f5d253dcfa Everywhere: Fully qualify IsLvalueReference in TRY() macros
If USING_AK_GLOBALLY is not defined, the name IsLvalueReference might
not be available in the global namespace. Follow the pattern established
in LibTest to fully qualify AK types in macros to avoid this problem.
2023-01-15 00:56:31 +00:00
Timothy Flynn
afc0e461e1 AK+Everywhere: Disallow returning a reference from a fallible expression
This will silently make a copy. Rather than masking this behavior, let's
explicitly disallow it.
2023-01-13 18:50:47 -05:00
Timothy Flynn
834202aeb9 LibWeb: Move setting of Web object prototypes to initialize()
This needs to happen before prototype/constructor intitialization can be
made lazy. Otherwise, GC could run during the C++ constructor and try to
collect the object currently being created.
2023-01-10 16:08:14 +01:00
Timothy Flynn
7bd8fd000f LibWeb: Generate dedicated methods to create Web constructors/prototypes
Currently, for each exposed interface, we generate one massive function
to create every Web constructor and prototype. In an effort to lazily
create these instead, this first step is to extract the creation of each
of these into its own method.

First, this generates a forwarding header for all IDL types. This is to
allow callers to remain unchanged without forcing them to include the
(very heavy) generated IDL headers. This header is included by LibWeb's
forwarding header.

Next, this defines a base template method on Web::Bindings::Intrinsics
to create a prototype/constructor pair. Specializations of this template
are now generated in a new .cpp file, IntrinsicDefinitions.cpp. The base
Intrinsics class is updated to use this new method, and will continue to
cache the result.

Last, some WebAssembly classes are updated to use this new mechanism.
They were using some ad hoc cache keys that are now in line with the
generated specializations.

That one massive function is still used to invoke these specializations,
so they are not lazy as of this commit.
2023-01-10 16:08:14 +01:00
Timothy Flynn
115baa7e32 LibJS+Everywhere: Make PrimitiveString and Utf16String fallible
This makes construction of Utf16String fallible in OOM conditions. The
immediate impact is that PrimitiveString must then be fallible as well,
as it may either transcode UTF-8 to UTF-16, or create a UTF-16 string
from ropes.

There are a couple of places where it is very non-trivial to propagate
the error further. A FIXME has been added to those locations.
2023-01-08 12:13:15 +01:00
Timothy Flynn
d8044c5358 LibJS+LibWeb: Move the macro to convert ENOMEM to an exception to LibJS
Move the macro to LibJS and change it to return a throw completion
instead of a WebIDL exception. This will let us use this macro within
LibJS to handle OOM conditions.
2023-01-08 12:13:15 +01:00
Jelle Raaijmakers
25f2e4981c AK: Stop using DeprecatedString in Base64 encoding 2022-12-20 10:34:19 +01:00
Linus Groh
22089436ed LibJS: Convert Heap::allocate{,_without_realm}() to NonnullGCPtr 2022-12-15 06:56:37 -05:00
Linus Groh
2a66fc6cae LibJS: Add make_handle({Nonnull,}GCPtr<T>) overloads 2022-12-15 06:56:37 -05:00
Linus Groh
91b0123eaf LibJS: Convert Array::create{,_from}() to NonnullGCPtr 2022-12-14 09:59:45 +00:00
Linus Groh
ae0606711c LibWeb/Fetch: Remove redundant timingInfo variables
This is an editorial change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/e8b67b0
2022-12-08 15:37:19 +00:00
Linus Groh
a06b97dae0 LibWeb/Fetch: Share validation logic in the Headers class
This is an editorial change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/f435978
2022-12-08 15:37:19 +00:00
Linus Groh
3414a6ba20 LibWeb/Fetch: Remove Authorization header upon cross-origin redirect
This is a change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/9004f4e
2022-12-08 15:37:19 +00:00
Linus Groh
2f1bda3347 LibWeb/Fetch: Tweak wording in some spec comments
This is a change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/223ca89
2022-12-08 15:37:19 +00:00
Linus Groh
a156722744 LibWeb/Fetch: Update spec comment to decode bytes to string
This is a change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/a04d096
2022-12-08 15:37:19 +00:00
Linus Groh
1c9bb2d8b4 LibWeb/Fetch: Refactor forbidden request-headers
This is a change in the Fetch spec.

See:
- https://github.com/whatwg/fetch/commit/92e6c91
- https://github.com/whatwg/xhr/commit/494431a
2022-12-08 15:37:19 +00:00
Linus Groh
011f6a6cb4 LibWeb/Fetch: Use tuple syntax for headers in spec comments
This is an editorial change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/b482186
2022-12-08 15:37:19 +00:00
Linus Groh
525f22d018 LibJS: Replace standalone js_string() with PrimitiveString::create()
Note that js_rope_string() has been folded into this, the old name was
misleading - it would not always create a rope string, only if both
sides are not empty strings. Use a three-argument create() overload
instead.
2022-12-07 16:43:06 +00:00
Linus Groh
57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh
6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Andreas Kling
71067cbc6c LibJS+LibWeb: Make Runtime/AbstractOperations.h not include AST.h
This led to considerable fallout and many files had to be patched with
now-missing include statements.
2022-11-23 16:05:59 +00:00
Andreas Kling
b81816a539 LibJS+LibWeb: Make CyclicModule.h not include AST.h
This led to some fallout as many things in LibJS and LibWeb were pulling
in other things via CyclicModule.h
2022-11-23 16:05:59 +00:00
MacDue
8a5d2be617 Everywhere: Remove unnecessary mutable attributes from lambdas
These lambdas were marked mutable as they captured a Ptr wrapper
class by value, which then only returned const-qualified references
to the value they point from the previous const pointer operators.

Nothing is actually mutating in the lambdas state here, and now
that the Ptr operators don't add extra const qualifiers these
can be removed.
2022-11-19 14:37:31 +00:00
Kenneth Myhra
8f0fdef856 LibWeb: Remove unused type XMLHttpRequestBodyInit 2022-11-11 00:39:12 -07:00
Linus Groh
a2a4ad3b9d LibWeb: Fix typo in BodyInitOrReadableBytes type alias 2022-11-09 22:38:03 +00:00
Nico Weber
d09b5e8484 Everywhere: Clean up "in in" comment typos
Includes fetch editorial update
https://github.com/whatwg/fetch/commit/3cafbdfc39250!
2022-11-08 15:09:08 +00:00
Linus Groh
0aca69853c LibWeb: Add abort algorithm after creating controller in fetch_impl()
This ensures that the controller GCPtr is non-null by the time we
capture a copy of it for the lambda passed to the request signal's
add_abort_algorithm() method. Currently, the VERIFY() would always fail
when aborting the signal. The alternative to this would be adding a cell
setter to Handle, and ensuring that null handles have a HandleImpl as
well; this seems not worth the hassle right now. Thanks to Lubrsi for
catching this!

Co-authored-by: Luke Wilde <lukew@serenityos.org>
2022-11-04 22:35:45 +00:00
Linus Groh
6cd57d4c15 LibWeb: Properly copy method and headers from the input in Request()
We were accidentally copying these from the newly created Request
object's underlying request, to itself. Thanks to Lubrsi for catching
this!

Co-authored-by: Luke Wilde <lukew@serenityos.org>
2022-11-04 22:35:45 +00:00
Linus Groh
216f68c566 LibWeb: Register PendingResponse with a Request to keep it alive
This was an oversight from when I converted PendingResponse and various
other classes from being ref-counted to GC-allocated last minute - no
one takes care to keep all of them alive. Some are on the stack, and
some might be captured in another PendingResponse's JS::SafeFunction,
but ultimately, we need a better solution.
Since a PendingResponse is *always* the result of someone having created
a Request, let's just let that keep a list of each PendingResponse that
has been created for it, and visit them until they are resolved. After
that, they can be GC'd with no complaints.
2022-11-01 20:14:12 +00:00
Linus Groh
a1de15498d LibWeb: Use proper origins in Request::has_redirect_tainted_origin()
URL::url_origin() is a globally available function now, so let's use it!
2022-10-31 18:04:11 +00:00
Linus Groh
acfb546048 LibWeb: Handle currently ignored WebIDL::ExceptionOr<T>s 2022-10-31 14:12:44 +00:00
Linus Groh
1de1d6423b LibWeb: Implement the fetch() method :^)
With so much infrastructure implemented, we can finally add the last
piece of this puzzle - the fetch() method itself!

This contains a few hundred lines of generated code as handling the
RequestInfo and RequestInfo parameter types manually is not feasible,
but we can't use the IDL definition as the Window object is handwritten
code at the moment.
It's neatly tucked away in Bindings/ and will be removed eventually.
2022-10-30 20:10:29 +00:00
Linus Groh
c8d121fa32 LibWeb: Implement most of the 'Fetching' AOs
This implements the following operations from section 4 of the Fetch
spec (https://fetch.spec.whatwg.org/#fetching):

- Fetch
- Main fetch
- Fetch response handover
- Scheme fetch
- HTTP fetch
- HTTP-redirect fetch
- HTTP-network-or-cache fetch (without caching)

It does *not* implement:

- HTTP-network fetch
- CORS-preflight fetch

Instead, we let ResourceLoader handle the actual networking for now,
which isn't ideal, but certainly enough to get enough functionality up
and running for most websites to not complain.
2022-10-30 20:10:29 +00:00
Linus Groh
32e0f0aec8 LibWeb: Require error message for Response::network_error()
There will be a lot of different cases where we'll return an error
response, and having a customized Promise rejection message seems quite
useful.

Note that this has to be distinct from the existing 'status message',
which is required to be empty in those cases.
2022-10-30 20:10:29 +00:00
Linus Groh
caa13bf41d LibWeb: Fix URL parsing in Response::location_url()
We need to use URLParser in order to provide a base URL. This makes it
work for the common case of `Location: /some/path`.
2022-10-30 20:10:29 +00:00
Linus Groh
fd042dce55 LibWeb: Actually extract Location header in Response::location_url() 2022-10-30 20:10:29 +00:00
Linus Groh
455aa34011 LibWeb: Partially implement 'Extract header (list) values' AOs
The header-specific ABNF rules are completely ignored for now, but we
can at least extract a single header value, which at least works for
simple cases like `Location`-based redirects.
2022-10-30 20:10:29 +00:00
Linus Groh
14e722617c LibWeb: Implement 'Queue a fetch task' AO 2022-10-30 20:10:29 +00:00
Linus Groh
6deb5ce9b5 LibWeb: Implement 'Default User-Agent value' AO 2022-10-30 20:10:29 +00:00
Linus Groh
5ee9feb9cf LibWeb: Implement 'Append a request Origin header' AO 2022-10-30 20:10:29 +00:00
Linus Groh
c93e6ea0d9 LibWeb: Implement 'Appropriate network error' AO 2022-10-30 20:10:29 +00:00
Linus Groh
361ab205fa LibWeb: Implement 'CORS check' / 'TAO check' AOs 2022-10-30 20:10:29 +00:00
Linus Groh
5d86eae119 LibWeb: Implement 'fetch params' struct 2022-10-30 20:10:29 +00:00
Linus Groh
ba31547fa0 LibWeb: Implement container class for fetch algorithms 2022-10-30 20:10:29 +00:00
Linus Groh
dd5d3e2f4f LibWeb: Implement 'fetch controller' struct 2022-10-30 20:10:29 +00:00
Linus Groh
fef331a03f LibWeb: Implement 'fetch timing info' struct 2022-10-30 20:10:29 +00:00
Linus Groh
1f8ed8fca7 LibWeb: Implement 'connection timing info' struct 2022-10-30 20:10:29 +00:00
Linus Groh
cc6eaafe6b LibWeb: Implement 'Byte sequence as body' AO 2022-10-30 20:10:29 +00:00
Linus Groh
dcded8d39f LibWeb: Implement 'Safely extract BodyInit' AO 2022-10-30 20:10:29 +00:00
Linus Groh
58ad6de954 LibWeb: Implement 'Should response be blocked due to nosniff?' AO 2022-10-30 20:10:29 +00:00
Linus Groh
7e46150a71 LibWeb: Implement 'Should response be blocked due to its MIME type?' AO 2022-10-30 20:10:29 +00:00
Linus Groh
62228f0870 LibWeb: Implement 'Should request be blocked due to a bad port' AO 2022-10-30 20:10:29 +00:00
Linus Groh
55315d72f7 LibWeb: Explain the use-URL-credentials flag
This is a change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/a388348
2022-10-30 14:51:58 +00:00
Linus Groh
d2deb8fa6d LibWeb: Add has-cross-origin-redirects flag to Fetch::Infra::Response
This is a change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/7c30987
2022-10-30 14:51:58 +00:00
Linus Groh
793a1f5994 LibWeb: Actually define Blob-to-ReadableStream conversion
This is a change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/4cd70cf
2022-10-30 14:48:32 +00:00
Linus Groh
b1968b8bed LibWeb: Make Fetch::Infrastructure::{Request,Response,HeaderList} GC'd
This is the way.

On a more serious note, there's no reason to keep adding ref-counted
classes to LibWeb now that the majority of classes is GC'd - it only
adds the risk of discovering some cycle down the line, and forces us to
use handles as we can't visit().
2022-10-30 11:30:23 +00:00
Linus Groh
6ce08d3f75 LibWeb: Use StringView literals for all WebIDL::SimpleExceptions 2022-10-29 15:48:46 +01:00
Luke Wilde
5cc190ad70 LibWeb: Make Fetch::Request follow abort signals where appropriate 2022-10-26 18:49:41 +01:00
Linus Groh
419eb7ab97 LibWeb: Fix unchecked Variant access in Request::construct_impl()
We need to keep an Infrastructure::Request::BodyType around as we're not
sure what's actually inside, instead accessing Infrastructure::Body
directly.

Co-authored-by: Luke Wilde <lukew@serenityos.org>
2022-10-26 10:36:48 +01:00
Linus Groh
16136f0bdd LibWeb: Fix incorrect peek offset in HeaderList::get_decode_and_split()
We want to look at the current character, not the next one.
2022-10-26 10:36:48 +01:00
Linus Groh
7e7def71c1 LibWeb: Use getters instead of direct member access in Response methods
This fixes the behavior of those methods for FilteredResponse subclasses
as those only override the getter methods, not their private members.
2022-10-24 22:58:37 +01:00
Linus Groh
8f8fcfee1a LibWeb: Also make non-const Response getters virtual
We wouldn't want a filtered response to bypass the overridden methods
based on constness.
2022-10-24 22:58:37 +01:00
Linus Groh
0a186cb460 LibWeb: Handle filtered response in Response::clone() 2022-10-24 22:58:37 +01:00
Linus Groh
e40c8f550f LibWeb: Add non-const variants of Request::{current_,}url() 2022-10-24 22:58:37 +01:00
Linus Groh
9ad6031bca LibWeb: Move internal response in FilteredResponse create() functions 2022-10-24 09:26:16 +01:00
Linus Groh
02a4cba086 LibWeb: Use MUST() for infallible ByteBuffer::copy() invocations
ByteBuffer has an inline capacity of 32 bytes, so when we provide a
string smaller than that, it cannot fail.
2022-10-24 09:26:16 +01:00
Linus Groh
65f5c7adbc LibWeb: Add Fetch::Infrastructure::Header::from_string_pair() helper
This allows us to use this:

```cpp
auto header = TRY_OR_RETURN_OOM(realm,
    Infrastructure::Header::from_string_pair(name, value));
```

Instead of the somewhat unwieldly:

```cpp
auto header = Infrastructure::Header {
    .name = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(name.bytes())),
    .value = TRY_OR_RETURN_OOM(realm, ByteBuffer::copy(value.bytes())),
};
```
2022-10-24 09:26:16 +01:00
Linus Groh
c12c6fd5ea LibWeb: Fix typo in Fetch::Infrastructure::Request::add_range_header() 2022-10-24 09:24:15 +01:00
Linus Groh
950d2fccf0 LibWeb: Remove workaround for nested BodyInit IDL union type 2022-10-21 12:11:24 +02:00
Linus Groh
acc1c2b3cb LibWeb/Fetch: Add "webidentity" destination for FedCM
This is a change in the Fetch spec.

See:
- https://github.com/whatwg/fetch/commit/30d462d
- https://github.com/whatwg/fetch/commit/7487a97
2022-10-15 12:15:31 +02:00
Linus Groh
5995a9fd06 LibWeb/Fetch: Add duplex property to Request
This is a change in the Fetch spec.

See: https://github.com/whatwg/fetch/commit/1fbc40c
2022-10-15 12:15:31 +02:00
Linus Groh
60e9790a40 LibWeb/Fetch: Add support for parsing a single range header value
This is a change in the Fetch spec.

See:
- https://github.com/whatwg/fetch/commit/2d080d7
- https://github.com/whatwg/fetch/commit/a18fb3e
2022-10-15 12:15:31 +02:00
Ben Wiederhake
3aeb57ed09 AK+Everywhere: Fix data corruption due to code-point-to-char conversion
In particular, StringView::contains(char) is often used with a u32
code point. When this is done, the compiler will for some reason allow
data corruption to occur silently.

In fact, this is one of two reasons for the following OSS Fuzz issue:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=49184
This is probably a very old bug.

In the particular case of URLParser, AK::is_url_code_point got confused:
    return /* ... */ || "!$&'()*+,-./:;=?@_~"sv.contains(code_point);
If code_point is a large code point that happens to have the correct
lower bytes, AK::is_url_code_point is then convinced that the given
code point is okay, even if it is actually problematic.

This commit fixes *only* the silent data corruption due to the erroneous
conversion, and does not fully resolve OSS-Fuzz#49184.
2022-10-09 10:37:20 -06:00
Sam Atkins
0823a3c422 BindingsGenerator+LibWeb: Pass a VM to static IDL-based functions
This saves us from having to yoink the VM out of thin air.
2022-10-06 21:45:07 +01:00
Linus Groh
1c12f5c31d LibWeb: Make Fetch::Infrastructure::{Request,Response} ref-counted
With the addition of the 'fetch params' struct, the single ownership
model we had so far falls apart completely.

Additionally, this works nicely for FilteredResponse's internal response
instead of risking a dangling reference.

Replacing the public constructor with a create() function also found a
few instances of a Request being stack-allocated!
2022-10-05 09:14:49 +01:00
Linus Groh
886ca9c7b6 LibWeb: Add missing Request::policy_container() getter and setter 2022-10-05 09:14:49 +01:00
Linus Groh
16d6c62193 LibWeb: Make Fetch::Infrastructure::Request::set_client() take a pointer 2022-10-05 09:14:49 +01:00
Linus Groh
72a752685f LibWeb: Add missing link to Fetch::Infrastructure::Response member 2022-10-05 09:14:49 +01:00
Linus Groh
7b50e96434 LibWeb: Add missing links to Fetch::Infrastructure::Request members 2022-10-05 09:14:49 +01:00
Linus Groh
fc9d587e39 LibJS: Make PromiseCapability GC-allocated
A struct with three raw pointers to other GC'd types is a pretty big
liability, let's just turn this into a Cell itself.
This comes with the additional benefit of being able to capture it in
a lambda effortlessly, without having to create handles for individual
members.
2022-10-02 23:02:27 +01:00
Linus Groh
c2326ec95a LibJS: Move PromiseCapability into its own cpp/h file
This is not strictly connected to PromiseReaction in any way.
Preparation before doing some actual work on it :^)
2022-10-02 23:02:27 +01:00
Andrew Kaster
56b381aac0 LibWeb: Cleanup unecessary uses and includes of HTML::Window
The big global refactor left some stragglers behind for atomicity.

Clean up the rest, and remove a ton of includes of LibWeb/HTML/Window.h
2022-10-01 21:05:32 +01:00
Andrew Kaster
4bb6345b2f LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm
directly to construct Crypto, Encoding, HRT, IntersectionObserver,
NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL,
and XML classes.
2022-10-01 21:05:32 +01:00
Andrew Kaster
4878a18ee7 LibWeb: Remove unecessary dependence on Window from Fetch, XHR, FileAPI
These classes only needed Window to get at its realm. Pass a realm
directly to construct Fetch, XMLHttpRequest and FileAPI classes.
2022-10-01 21:05:32 +01:00
Linus Groh
0b52b883af LibWeb: Implement '5.5. Response class' from the Fetch API :^) 2022-09-27 14:56:17 +01:00
Linus Groh
9fb672e981 LibWeb: Implement '5.4. Request class' from the Fetch API :^) 2022-09-27 14:56:17 +01:00
Linus Groh
5ad6283331 LibWeb: Implement '5.3. Body mixin' from the Fetch API :^)
This will be used to share functionality between Request and Response.
2022-09-27 14:56:17 +01:00
Linus Groh
afe2563e2b LibWeb: Make HeaderList ref-counted
This is needed to eventually share a header list between a Request or
Response object's internal infra request/response and the object's
exposed Header object.
2022-09-27 14:56:17 +01:00
Linus Groh
2d57d47132 LibWeb: Make Fetch::Infrastructure::Request::m_method default to "GET"
ByteBuffer has an inline capacity of 32 bytes, so this isn't fallible
and can be done inline.
2022-09-27 14:56:17 +01:00
Linus Groh
924d7721f0 LibWeb: Stub out Fetch::Infrastructure::Body::fully_read_as_promise() 2022-09-27 14:56:17 +01:00
Linus Groh
a7164f2674 LibWeb: Stub out Fetch::Infrastructure::Body::clone() 2022-09-27 14:56:17 +01:00
Linus Groh
ef5e2eb794 LibWeb: Implement Fetch::Infrastructure::Response::clone() 2022-09-27 14:56:17 +01:00
Linus Groh
b5e8e9b30b LibWeb: Support ReadonlyBytes as argument for extract_body()
This now matches the spec's requirement of "a byte sequence or BodyInit
object object".
2022-09-27 14:56:17 +01:00
Linus Groh
fd52119ca3 LibWeb: Add getters and setters for Fetch::Header's members 2022-09-27 14:56:17 +01:00
Linus Groh
dc6fb43d26 LibWeb: Add referrer policy to Fetch::Infrastructure::Request
The enum is in its own directory and namespace as there's a standalone
spec for it, that will later also house AOs.

- https://w3c.github.io/webappsec-referrer-policy/
- https://www.w3.org/TR/referrer-policy/
2022-09-27 14:56:17 +01:00
Linus Groh
a602a4c780 LibWeb: Heap-allocate returned Fetch::Infrastructure::{Request,Response}
A Request/Response instance should always be heap-allocated and have
clear ownership, so let's also wrap it in a NonnullOwnPtr instead of
putting them on the stack.
2022-09-27 14:56:17 +01:00
Linus Groh
88ee15a497 LibWeb: Mark two Fetch::Infrastructure::Request getters as const 2022-09-27 14:56:17 +01:00
Linus Groh
ad04d7ac9b LibWeb: Move ExceptionOr from DOM/ to WebIDL/
This is a concept fully defined in the Web IDL spec and doesn't belong
in the DOM directory/namespace - not even DOMException, despite the name
:^)
2022-09-25 19:13:31 +01:00
Linus Groh
6480faacb6 LibWeb: Move IDLAbstractOperations from Bindings/ to WebIDL/ 2022-09-24 19:31:39 +01:00
Linus Groh
76ace3629a LibWeb: Make Fetch::Infrastructure::Body::stream() const 2022-09-22 21:01:13 +01:00
Linus Groh
54a987ad45 LibWeb: Update extract_body() to use BodyInit 2022-09-22 21:01:13 +01:00
Linus Groh
8f5620b5d9 LibWeb: Add BodyInit union type 2022-09-22 21:01:13 +01:00
Linus Groh
571f4e3ebb LibWeb: Move extract_body() into Fetch 2022-09-22 21:01:13 +01:00
Linus Groh
f98ce156c4 LibWeb: Remove ReadableStreamDummy in favor of ReadableStream 2022-09-22 21:01:13 +01:00
Linus Groh
1ace80235b LibWeb: Move XMLHttpRequestBodyInit into Fetch
https://fetch.spec.whatwg.org/#typedefdef-xmlhttprequestbodyinit
2022-09-22 21:01:13 +01:00
Linus Groh
edfef8e2f5 Everywhere: Rename WrapperGenerator to BindingsGenerator
This code generator no longer creates JS wrappers for platform objects
in the old sense, instead they're JS objects internally themselves.
Most of what we generate now are prototypes - which can be seen as
bindings for the internal C++ methods implementing getters, setters, and
methods - as well as object constructors, i.e. bindings for the internal
create_with_global_object() method.

Also tweak the naming of various CMake glue code existing around this.
2022-09-21 23:06:08 +01:00
Linus Groh
4270ede7c4 LibWeb: Remove WRAPPER_HACK() macro
We no longer access Bindings::FooWrapper anywhere for a Foo platform
object, so these can be removed :^)
2022-09-21 21:12:24 +01:00
Andreas Kling
010be491a9 LibWeb: Fix e-mail address mishap 2022-09-21 18:42:09 +02:00
Andreas Kling
66f4e2b3b0 LibWeb: Add two more scheme helpers to the Fetch infrastructure 2022-09-21 11:51:18 +02:00
Andreas Kling
9683da4470 LibWeb: Add referrer accessors to Fetch Request 2022-09-20 14:48:07 +02:00
Andreas Kling
497ead37bc LibWeb: Make DOMException GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
96f6c7fae5 LibWeb: Make Headers and HeadersIterator GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
647ac1bdba LibWeb: Make Blob and File GC-allocated 2022-09-06 00:27:09 +02:00
Andreas Kling
6f433c8656 LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocated
This is a monster patch that turns all EventTargets into GC-allocated
PlatformObjects. Their C++ wrapper classes are removed, and the LibJS
garbage collector is now responsible for their lifetimes.

There's a fair amount of hacks and band-aids in this patch, and we'll
have a lot of cleanup to do after this.
2022-09-06 00:27:09 +02:00
Linus Groh
b345a0acca LibJS+LibWeb: Reduce use of GlobalObject as an intermediary
- Prefer VM::current_realm() over GlobalObject::associated_realm()
- Prefer VM::heap() over GlobalObject::heap()
- Prefer Cell::vm() over Cell::global_object()
- Prefer Wrapper::vm() over Wrapper::global_object()
- Inline Realm::global_object() calls used to access intrinsics as they
  will later perform a direct lookup without going through the global
  object
2022-08-23 13:58:30 +01:00
Linus Groh
40a70461a0 LibWeb: Replace GlobalObject with Realm in wrapper functions
Similar to create() in LibJS, wrap() et al. are on a low enough level to
warrant passing a Realm directly instead of relying on the current realm
from the VM, as a wrapper may need to be allocated while no JS is being
executed.
2022-08-23 13:58:30 +01:00
Linus Groh
ccdfa2320c LibJS: Replace GlobalObject with VM in Iterator AOs [Part 7/19] 2022-08-23 13:58:30 +01:00
Linus Groh
f3117d46dc LibJS: Remove GlobalObject from VM::throw_completion()
This is a continuation of the previous five commits.

A first big step into the direction of no longer having to pass a realm
(or currently, a global object) trough layers upon layers of AOs!
Unlike the create() APIs we can safely assume that this is only ever
called when a running execution context and therefore current realm
exists. If not, you can always manually allocate the Error and put it in
a Completion :^)

In the spec, throw exceptions implicitly use the current realm's
intrinsics as well: https://tc39.es/ecma262/#sec-throw-an-exception
2022-08-23 13:58:30 +01:00
Linus Groh
b99cc7d050 LibJS+LibWeb: Replace GlobalObject with Realm in create() functions
This is a continuation of the previous two commits.

As allocating a JS cell already primarily involves a realm instead of a
global object, and we'll need to pass one to the allocate() function
itself eventually (it's bridged via the global object right now), the
create() functions need to receive a realm as well.
The plan is for this to be the highest-level function that actually
receives a realm and passes it around, AOs on an even higher level will
use the "current realm" concept via VM::current_realm() as that's what
the spec assumes; passing around realms (or global objects, for that
matter) on higher AO levels is pointless and unlike for allocating
individual objects, which may happen outside of regular JS execution, we
don't need control over the specific realm that is being used there.
2022-08-23 13:58:30 +01:00
Linus Groh
042dfc7284 LibWeb: Move extract_mime_type() from XMLHttpRequest to HeaderList
Except some minor tweaks, this is a direct copy of Luke's initial
implementation in XMLHttpRequest, now replacing the former.
2022-07-20 18:03:21 +01:00
Linus Groh
69d324d46a LibWeb: Fix accidental (name, name) header in Headers::fill()
This makes two more WPT tests pass here:
http://wpt.live/fetch/api/headers/headers-basic.any.html
2022-07-20 18:03:21 +01:00
Linus Groh
ed49b66f25 LibWeb: Implement '5.1. Headers class' from the Fetch API :^) 2022-07-19 00:27:35 +01:00
Linus Groh
b5ab1f6b4a LibWeb: Implement HeaderList::sort_and_combine() 2022-07-19 00:27:35 +01:00
Linus Groh
bad6ad8861 LibWeb: Implement CaseInsensitiveBytesTraits::equals()
Turns out HashTable::contains() doesn't solely use hash() for equality
checks, so the lack of a proper equals() implementation broke the check
in convert_header_names_to_a_sorted_lowercase_set() and caused duplicate
entries in header_names_set.
2022-07-19 00:27:35 +01:00
Linus Groh
2726fc9c73 LibWeb: Move Fetch infra into the Web::Fetch::Infrastructure namespace
The Fetch spec unfortunately will cause a name clash between the Request
concept and the Request JS object - both cannot live in the Web::Fetch
namespace, and WrapperGenerator generally assumes `Web::<Name>` for
things living in the `<Name>/` subdirectory, so let's instead move infra
code into its own namespace - it already sits in a (sub-)subdirectory
anyway.
2022-07-19 00:27:35 +01:00
Linus Groh
58fda93ea2 LibWeb: Add Blob to Fetch's Body::SourceType variant 2022-07-18 08:11:25 +01:00
Linus Groh
8da3914bdc LibWeb: Add definitions from '2.2.6. Responses' in the Fetch spec 2022-07-16 21:05:00 +01:00
Linus Groh
7116a7d2bf LibWeb: Add definitions from '2.2.5 Requests' in the Fetch spec 2022-07-15 14:15:30 +02:00
Linus Groh
4f02bac39c LibWeb: Add a couple of missing includes to Fetch's Headers.h 2022-07-15 14:15:30 +02:00
Linus Groh
f507f68d4a LibWeb: Add definitions from '2.2.4. Bodies' in the Fetch spec
...at least the ones that don't require an implementation of the Streams
spec :^)
2022-07-14 00:42:26 +01:00
Linus Groh
1694279dd8 LibWeb: Add definitions from '2.2.3. Statuses' in the Fetch spec 2022-07-14 00:42:26 +01:00
Linus Groh
dd9bf10151 LibWeb: Add definitions from '2.2.2. Headers' in the Fetch spec 2022-07-14 00:42:26 +01:00
Linus Groh
9244f1697d LibWeb: Add definitions from '2.2.1. Methods' in the Fetch spec 2022-07-14 00:42:26 +01:00
Linus Groh
9d60010b44 LibWeb: Mark Fetch::collect_an_http_quoted_string() [[nodiscard]] 2022-07-14 00:42:26 +01:00
Linus Groh
f42f0cceaa LibWeb: Make Fetch::collect_an_http_quoted_string()'s 2nd param optional 2022-07-14 00:42:26 +01:00
Linus Groh
fad69fcacd LibWeb: Move Fetch::collect_an_http_quoted_string() into HTTP.{cpp,h}
The Fetch spec is too big to have a generic AbstractOperations.{cpp,h}
file, so let's keep AOs in their section-specific files.
2022-07-14 00:42:26 +01:00
Linus Groh
e3798886ed LibWeb: Add & use 'HTTP whitespace' from '2.2. HTTP' in the Fetch spec
We had two independent definitions of this already, both referring to
the Fetch spec.
2022-07-14 00:42:26 +01:00
Linus Groh
df3e25f1bb LibWeb: Add & use 'HTTP tab or space' from '2.2. HTTP' in the Fetch spec 2022-07-14 00:42:26 +01:00
Linus Groh
7c2c9b6859 LibWeb: Add definitions from '2.1. URL' in the Fetch spec 2022-07-14 00:42:26 +01:00
Luke Wilde
8cfeca5261 LibWeb: Implement spec-compliant MIME type struct and parser
This will be used by XHR to extract the Content-Type MIME type to
retrieve the charset.
2022-02-12 12:53:28 +01:00