Commit Graph

179 Commits

Author SHA1 Message Date
Kenneth Myhra
29112f7365 LibWeb: Integrate Streams in XHR::send() 2024-05-20 16:57:52 -04:00
Shannon Booth
f7ba07cc8b LibWeb: Handle non-object JSON in XMLHttpRequest response
This fixes a crash seen on https://web.basemark.com/run/
2024-05-04 14:11:10 +02:00
Andreas Kling
527ad9ac01 LibWeb: Implement XMLHttpRequest.responseURL
This was used on https://twinings.co.uk/ so let's support it :^)
2024-05-01 12:52:03 +02:00
Timothy Flynn
b3032befe0 LibWeb: Remove OOM propagation from Fetch::Infrastructure::Methods 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
Timothy Flynn
3dee703227 LibWeb: Avoid UAF parsing an XML document's charset
The value returned by get_final_encoding() was a temporarily allocated
string which we were holding a view into.
2024-04-04 11:23:21 +02: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
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
Andrew Kaster
9ab312e001 LibWeb: Hide XHR send debug messages behind SPAM_DEBUG 2023-12-08 20:04:13 -05:00
Shannon Booth
96af80acd1 LibWeb: Port Intrinsics from DeprecatedString 2023-11-28 17:15:27 -05:00
Shannon Booth
6c42de3e8b LibWeb: Port XMLSerializer from DeprecatedString to String 2023-11-20 15:00:19 +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
Idan Horowitz
278e8afb42 LibWeb: Consider content-type charset when determining XML encoding 2023-11-17 16:02:36 +01:00
Ali Mohammad Pur
aeee98b3a1 AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
2023-10-13 18:33:21 +03:30
Andreas Kling
0762388709 LibWeb: Make XHR.response an actual XMLDocument for XML documents
Before this change, we were producing a generic DOM::Document, which
was not distinguishable from an XMLDocument by IDL interface type.
2023-10-07 10:19:18 +02:00
Andreas Kling
2b343c9508 LibWeb: Don't crash in XHR.response{,XML} for empty XML document
There were some unhandled paths due to the liberally typed XHR response
object. This patch flushes out those issues by using a tighter type set
in the Variant. (NonnullGCPtr<Object> instead of Value)
2023-10-07 10:19:18 +02:00
Aliaksandr Kalenik
09c1eccb50 LibWeb: Fix crash in XMLHttpRequest::response_xml() if response empty
If response object is empty we should return nullptr.

Fixes crash on https://store.steampowered.com/
2023-10-04 20:09:21 +02:00
Shannon Booth
e74031a396 LibWeb: Port Document interface from DeprecatedString to String 2023-09-16 11:17:19 +02:00
Bastiaan van der Plaat
222cc29c5c LibWeb: Add XMLHttpRequest Document response type 2023-09-14 22:58:42 +02:00
Shannon Booth
41928c2902 LibWeb: Port DOMException interface from DeprecatedString to String 2023-09-06 11:44:45 -04:00
Aliaksandr Kalenik
bdd3a16b16 LibWeb: Make Fetch::Infrastructure::Body be GC allocated
Making the body GC-allocated allows us to avoid using `JS::Handle`
for `m_stream` in its members.
2023-08-19 15:12:00 +02:00
Shannon Booth
55a01e72ca AK: Port URL username/password from DeprecatedString to String
And for cases that just need to check whether the password/username is
empty, add a raw_{password,username} helper to avoid any allocation.
2023-08-13 15:03:53 -06:00
Andreas Kling
72c9f56c66 LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449.

While going through these, I also changed the function signature in many
places where returning ThrowCompletionOr<T> is no longer necessary.
2023-08-13 15:38:42 +02:00
Andreas Kling
18c54d8d40 LibJS: Make Cell::initialize() return void
Stop worrying about tiny OOMs.

Work towards #20405
2023-08-08 07:39:11 +02:00
Lucas CHOLLET
3f35ffb648 Userland: Prefer _string over _short_string
As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
2023-08-08 07:37:21 +02:00
Andreas Kling
34344120f2 AK: Make "foo"_string infallible
Stop worrying about tiny OOMs.

Work towards #20405.
2023-08-07 16:03:27 +02:00
Shannon Booth
8751be09f9 AK: Serialize URL hosts with 'concept-host-serializer'
In order to follow spec text to achieve this, we need to change the
underlying representation of a host in AK::URL to deserialized format.
Before this, we were parsing the host and then immediately serializing
it again.

Making that change resulted in a whole bunch of fallout.

After this change, callers can access the serialized data through
this concept-host-serializer. The functional end result of this
change is that IPv6 hosts are now correctly serialized to be
surrounded with '[' and ']'.
2023-07-31 05:18:51 +02:00
Kenneth Myhra
bf048da8cb LibWeb: Port fire_progress_event() + request_error_steps() to new String
This ports XHR's fire_progress_event() and request_error_steps() to new
FlyString.

Signature of fire_progress_event() parameter event_name  was changed
from 'String const&' to 'FlyString const&'.
2023-04-09 17:27:27 +02:00
Kenneth Myhra
2091a11488 LibWeb: Port EventTarget to new {Fly}String 2023-04-09 17:27:27 +02:00
Kenneth Myhra
ad5cbdc51b LibWeb: Port {Mouse,UI,Wheel,}Event to new String
This ports MouseEvent, UIEvent, WheelEvent, and Event to new String.
They all had a dependency to T::create() in
WebDriverConnection::fire_an_event() and therefore had to be ported in
the same commit.
2023-04-07 22:41:01 +02:00
Kenneth Myhra
4d87072201 LibWeb: Port {HTML,UIEvents,XHR}::EventNames to new String 2023-04-06 23:49:08 +02:00
Luke Wilde
ddec4cd7f2 LibWeb: Create the correct error objects in XHR::handle_errors
Aborts and network errors were accidentally creating TimeoutError
exceptions instead of AbortError and NetworkError respectively.
2023-03-23 20:01:38 +01:00
Luke Wilde
d036862f2b LibWeb: Refactor XHR (almost) exactly to the spec
This makes XHR now rely on Fetch, which allows it to correct send
Origin and Referer headers, CORS-preflight and filtering and many other
goodies.

The main thing that's missing is Streams, which means we can't properly
produce progress events or switch to the Loading ready state.

This also doesn't implement the Document responseType just yet.
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
Kenneth Myhra
ab6bd946d8 LibWeb: Port ProgressEvent to new String 2023-03-05 18:25:59 +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
65ab6d3b6f LibWeb/XHR: Fix blob type in XMLHttpRequest::response()
The type attribute of a blob is supposed to be a complete mime type of
the form "type/subtype", not just the determined mime type's type.
2023-03-03 11:02:21 +00:00
Kenneth Myhra
9a5a8d617d LibWeb: Port IDL implementations Blob and File to new String 2023-02-26 00:27:22 +01:00
Sam Atkins
2db168acc1 LibTextCodec+Everywhere: Port Decoders to new Strings 2023-02-19 17:15:47 +01:00
Sam Atkins
f2a9426885 LibTextCodec+Everywhere: Return Optional<Decoder&> from decoder_for() 2023-02-19 17:15:47 +01:00
Kenneth Myhra
84c7af4dcb LibWeb: Make factory method of XHR::ProgressEvent fallible 2023-02-18 00:52:47 +01:00
Kenneth Myhra
c120c46acc LibWeb: Make factory methods of DOM::Event fallible
Because of interdependencies between DOM::Event and UIEvents::MouseEvent
to template function fire_an_event() in WebDriverConnection.cpp, the
commit: 'LibWeb: Make factory methods of UIEvents::MouseEvent fallible'
have been squashed into this commit.
2023-02-18 00:52:47 +01:00
Kenneth Myhra
f28b8431bf LibWeb: Make factory method of XHR::XMLHttpRequest fallible 2023-02-18 00:52:47 +01:00
Kenneth Myhra
15917146d3 LibWeb: Make factory method of FileAPI::Blob fallible 2023-02-18 00:52:47 +01:00
Timothy Flynn
49e8dcf0b2 LibJS+LibWeb: Convert empty PrimitiveString instances to String 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
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