Commit Graph

9067 Commits

Author SHA1 Message Date
Aliaksandr Kalenik
939a8e9393 LibWeb: Reload navigable only if delta=0 in History::go() 2024-04-11 09:40:45 +02:00
Aliaksandr Kalenik
d86ad2fcfa LibWeb: Process all task source while waiting for document population
"apply the history step" initiated by reloading or back/forward
navigation might require doing fetching while populating a document,
so it is not possible to restrict spin_until() to process only
NavigationAndTraversal task source.

"apply the history step" initiated by synchronous navigation keeps
processing only NavigationAndTraversal task source because it will
never have to populate a document. Another reason to keep synchronous
navigation blocking other task sources is that we crash if active SHE
changes in the middle of "apply the history step" initiated by sync
navigation. The new test is added to makes sure we don't regress that.
2024-04-11 09:40:45 +02:00
Aliaksandr Kalenik
600ecdd5f7 LibWeb: Separate spin_until() into multiple steps in apply history step
Now "apply history step" waits for all document population tasks to
complete before doing subsequent steps.
2024-04-11 09:40:45 +02:00
Andrew Kaster
29b12cb449 LibWeb: Add a workaround for excessive memory usage in Page::load_html 2024-04-10 17:17:58 -06:00
Aliaksandr Kalenik
8fa636d8d5 LibWeb: Make SessionHistoryTraversalQueue GC-allocated
- Add missing visit of a navigable in SHTQ entry
- Use HeapFunction instead of SafeFunction for entry callback
2024-04-10 17:18:03 +02:00
Aliaksandr Kalenik
664611bae4 LibWeb: Forbid interleaving execution of HTML tasks with same source
From HTML spec https://html.spec.whatwg.org/#definitions-3
"... Note that in this setup, the processing model still enforces that
the user agent would never process events from any one task source out
of order."

I can't come up with an example that is fixed by this change. However,
debugging a bug caused by violating this assumption from the spec is
likely to be very painful.
2024-04-10 07:36:42 +02:00
Aliaksandr Kalenik
ba633882bf LibWeb: Change load_html_document to run parsing from deferred_invoke()
...callback, otherwise Networking task source will be blocked until the
end of HTML parsing.

This is a preparation before forbidding to interleave HTML tasks with
the same source.
2024-04-10 07:36:42 +02:00
Andreas Kling
870a954e11 LibWeb: Implement Element.outerHTML
This piggybacks on the same fragment serialization code that innerHTML
uses, but instead of constructing an imaginary parent element like the
spec asks us to, we just add a separate serialization mode that includes
the context element in the serialized markup.

This makes the image carousel on https://utah.edu/ show up :^)
2024-04-09 18:17:14 -04:00
Andreas Kling
0412e17bac LibWeb: Factor out attribute serialization into a separate function 2024-04-09 18:17:14 -04:00
Andreas Kling
2317a8a4eb LibWeb: Incorrectly skip visiting MessagePort::m_worker_event_target
This is a stopgap hack to prevent CI from hanging until we figure out
what's going on.

Bug: https://github.com/SerenityOS/serenity/issues/23899
2024-04-09 09:28:44 +02:00
Bastiaan van der Plaat
8342525434 LibWeb: Use HTMLOptionElement in select item getter
fix item
2024-04-09 09:23:57 +02:00
Bastiaan van der Plaat
6f84f69677 LibWeb: Add select selected options collection getter 2024-04-09 09:23:57 +02:00
Bastiaan van der Plaat
7372c01786 LibWeb: Add select and options collection remove method 2024-04-09 09:23:57 +02:00
Bastiaan van der Plaat
5decf4b33c LibWeb: Add HTMLOptionsCollection selected index property 2024-04-09 09:23:57 +02:00
Bastiaan van der Plaat
5c277144d8 LibWeb: Add select and option collection set length 2024-04-09 09:23:57 +02:00
Bastiaan van der Plaat
4e5ce7b63e LibWeb: Add select element size property 2024-04-09 09:23:57 +02:00
Matthew Olsson
abb4b6d117 LibJSGCVerifier: Detect missing JS_CELL() calls 2024-04-09 09:13:06 +02:00
Matthew Olsson
31341b280a LibWeb: Add calls to JS_{DECLARE,DEFINE}_ALLOCATOR() 2024-04-09 09:13:06 +02:00
Matthew Olsson
d47f656a3a LibJS+LibWeb: Mark a few variables as IGNORE_USE_IN_ESCAPING_LAMBDA
This is a bit noisy, but it'll be better once we upgrade to C++23.
2024-04-09 09:10:44 +02:00
Matthew Olsson
ff00d21d58 Everywhere: Mark a bunch of function parameters as NOESCAPE
This fixes the relevant warnings when running LibJSGCVerifier. Note that
the analysis is only performed over LibJS-adjacent code, but could be
performed over the entire codebase. That will have to wait for a future
commit.
2024-04-09 09:10:44 +02:00
Matthew Olsson
31c5cdcbd5 LibWeb+Assistant: Do not ref-capture stack vars in deferred lambdas 2024-04-09 09:10:44 +02:00
Bastiaan van der Plaat
1475c1810f LibWeb: Add support for select options disabled state 2024-04-08 17:24:48 -04:00
Bastiaan van der Plaat
4408581ee0 LibWeb: Refactor SelectItem to allow selecting options without value
Currently the `<select>` dropdown IPC uses the option value attr to
find which option is selected. This won't work when options don't
have values or when multiple options have the same value. Also the
`SelectItem` contained so weird recursive structures that are
impossible to create with HTML. So I refactored `SelectItem` as a
variant, and gave the options a unique id. The id is send back to
`HTMLSelectElement` so it can find out exactly which option element
is selected.
2024-04-08 17:24:48 -04:00
Aliaksandr Kalenik
94d72c174a LibWeb: Allow executing scripts for iframes with src=about:blank
Fixes https://github.com/SerenityOS/serenity/issues/23836
2024-04-08 21:27:34 +02:00
Lucas CHOLLET
94128fe027 LibWeb: Make CanvasImageSource also be an ImageBitmap 2024-04-08 14:25:36 +02:00
Lucas CHOLLET
af3a73c0a4 LibWeb: Provide an IDL definition for CanvasImageSource 2024-04-08 14:25:36 +02:00
Lucas CHOLLET
7d5b9122ec LibWeb: Define CanvasImageSource only once
The Variant is already defined in CanvasDrawImage.h.
2024-04-08 14:25:36 +02:00
Lucas CHOLLET
676fc5e8c6 LibWeb: Implement HTML::ImageBitmap
And the two methods of `WindowOrWorkerGlobalScope` that are used as
constructors for it.
2024-04-08 14:25:36 +02:00
Shannon Booth
db0519ddc1 LibWeb: Fire a pointer event on synthetic clicks 2024-04-08 14:25:08 +02:00
Shannon Booth
b873e5bc1d LibWeb: Implement the PointerEvent interface
As defined in: https://w3c.github.io/pointerevents

With the exception of the getCoalescedEvents and getPredictedEvents
APIs.

There are still many other parts of that spec (such as the event
handlers) left to implement, but this does get us at least some of the
way.
2024-04-08 14:25:08 +02:00
MacDue
d7b77d7695 LibWeb: Split SVGFormattingContext up into functions
Doing multiple `for_each_in_subtree()` passes was kind of a hack. We
can resolve everything in a single pass with a little more control over
the layout process. This also fixes a few minor issues like the sizing
of nested `<g>` elements.

More work is needed here though as this is still fairly ad-hoc.

Note: This does regress `css-namespace-tag-name-selector.html`,
previously SVG text within `<a>` elements would appear. However, this
was only because `for_each_in_subtree()` would blindly look through the
InlineNodes from the unimplemented `SVGAElement`s.
2024-04-08 14:24:35 +02:00
Aliaksandr Kalenik
a3149c1ce9 LibWeb: Wait for initial navigation to complete before modifying iframe
If initial src of an iframe is "about:blank", it does synchronous
navigation that is not supposed to be interleaved by other navigation
or usage of Document.open().

Fixes crashing in navigation on https://twinings.co.uk/
2024-04-08 09:07:18 +02:00
Andreas Kling
c0ea8825b5 LibWeb: Always log debug message about failure to parse CSS fonts
It's always good to know when and why a CSS font fails to parse,
so that we can file issues about missing functionality.
2024-04-07 19:15:23 +02:00
Shannon Booth
70e2f51674 LibWeb: Prefer GCPtr<T> over Optional<NonnullGCPtr<T>> 2024-04-07 18:01:05 +02:00
Shannon Booth
80658743d3 LibWeb: Generate Optional<NonnullGCPtr<T>> as GCPtr<T>
This is the general pattern which has been adopted in LibWeb, so let's
generate our IDL like this too.
2024-04-07 18:01:05 +02:00
Kenneth Myhra
d593436b6d LibWeb: Implement ReadableStream.pipeThrough() 2024-04-07 14:26:34 +01:00
Matthew Olsson
aac873fcec LibWeb: Fix a few "missing visit_edges" warnings from the GC verifier 2024-04-07 07:03:13 +02:00
Matthew Olsson
3c3ead5ff4 LibWeb: Don't store WindowOrWorkerGlobalScopeMixin in Performance
It wasn't used anyways, instead preferring to do dynamic_casts in every
method. Let's keep doing that, but move it into a helper function.
2024-04-07 07:03:13 +02:00
Matthew Olsson
7001e0a428 LibWeb: Fix a LibJSGCVerifier warning in DOM::Text 2024-04-07 07:03:13 +02:00
Matthew Olsson
8450041b52 LibWeb: Fix some GCVerifier warnings 2024-04-07 07:03:13 +02:00
Matthew Olsson
4701c4bb01 LibWeb: Add a missing visit in HTMLFormElement 2024-04-07 07:03:13 +02:00
Kenneth Myhra
d3b2cd8ab6 LibWeb: Implement ReadableStream.pipeTo() 2024-04-07 07:01:52 +02:00
Kenneth Myhra
559d983fa1 LibWeb: Implement AO readable_stream_pipe_to()
This is currently a naive implementation of readable_stream_pipe_to()
which will need some further iterations before it is par with the spec.
2024-04-07 07:01:52 +02:00
Kenneth Myhra
12cfa08a09 LibWeb: Use Vector<ByteBuffer> to store chunks in ReadLoopReadRequest
This stores the incoming chunks into a Vector of ByteBuffer in order to
be able to retrieve them in the same order as they came in.
2024-04-07 07:01:52 +02:00
Aliaksandr Kalenik
2c86633c51 LibWeb: Fix out of order spec step numbers in "create child navigable"
No behaviour change.
2024-04-06 21:57:55 +02:00
Shannon Booth
18520561e7 LibWeb: Fix crash for calculated transition duration/delays
As the parser was trying to directly unwrap an unresolved duration.
Currently we are outputting the wrong results for the serialized
duration, but this is still a step forwards.

Fixes a crash seen on: https://evaparish.com/blog/how-i-edit
2024-04-06 19:35:27 +01:00
Shannon Booth
f186e7e537 LibWeb: Fill out implementation for navigator.hardwareConcurrency
Instead of always reporting 1 :^)
2024-04-06 07:20:22 +02:00
Idan Horowitz
42853fb980 LibWeb: Add missing visit_edges implementation to MathMLElement 2024-04-06 06:59:36 +02:00
Idan Horowitz
c61f341320 LibWeb: Add missing visit_edges implementation to AnimationEffect 2024-04-06 06:59:36 +02:00
Idan Horowitz
46ad9d51df LibWeb: Replace MarkedVector with Vector in AudioTrackList
There's no need to make the m_audio_tracks entries heap roots, we can
visit them instead.
2024-04-06 06:59:36 +02:00
Idan Horowitz
270e0d4b58 LibWeb: Replace MarkedVector with Vector in VideoTrackList
There's no need to make the m_video_tracks entries heap roots, we can
visit them instead.
2024-04-06 06:59:36 +02:00
Shannon Booth
c3217754f1 LibWeb: Remove a bunch of calls to to_byte_string
A bunch of this is leftover from pre porting over to new AK::String.
For example, for functions which previously took a ByteString const&
now accepting a StringView.
2024-04-05 20:01:37 -04:00
Shannon Booth
0090b916dd LibJS: Make ParserError::to_string infallible 2024-04-05 20:01:37 -04:00
stelar7
7c7f01b82f LibWeb: Add RSAOAEP.exportKey for the pkcs8 format 2024-04-05 21:53:12 +02:00
stelar7
f9dd028119 LibWeb: Add RSAOAEP.exportKey for the spki format 2024-04-05 21:53:12 +02:00
Aliaksandr Kalenik
4ca715d2ef LibWeb: Skip SHTQ processing if ongoing task form queue is not finished
Fixes a bug when session history traversal queue task could be
interrupted by another SHTQ task execution. For example:
1. SHTQ timer callback starts executing a task from the queue.
2. spin_until() is invoked during task execution.
3. SHTQ timer callback starts executing a task from the queue.
2024-04-05 21:28:41 +02:00
Aliaksandr Kalenik
00531573a4 LibWeb: Remove SessionHistoryTraversalQueue::process()
...because existance of this method conflicts with the purpose of
having a queue as it allows to start executing next task in the middle
of ongoing task.

For example:

1. SHTQ timer starts executing a task.
2. Task does SHTQ::process().

Another example:

1. SHTQ::process() start executing a task.
2. task does SHTQ::process().
2024-04-05 21:28:41 +02:00
Aliaksandr Kalenik
11011cf250 LibWeb: Don't rely on SHTQ::process() in process_the_iframe_attributes
`HTMLIFrameElement::inserted()` does following:
1. Init a new navigable. This step appends a task on session history
   traversal queue (SHTQ) that creates a new nested history.
2. Process iframe's attributes

Processing of iframe's attributes might result in synchronous
navigation that fails to get active SHE if SHTQ task that creates
new nested history is not yet completed.

Before this change, a workaround involved forcing the processing of
SHTQ, which was terrible hack because it could occur in the middle of
another SHTQ task.

This change removes the need for "force SHTQ processing" by ensuring
that the processing of iframe's attributes is always executed after
the iframe's navigable nested history has been created.
2024-04-05 21:28:41 +02:00
Aliaksandr Kalenik
8cc2ee34db LibWeb: Check if entryToReplace is contained in session history entries
This small hack will allow us to get rid of "force processing of
session history traversal queue" which is significantly more cumbersome
hack.
2024-04-05 21:28:41 +02:00
Aliaksandr Kalenik
adcc3905e5 LibWeb: Pass SynchronousNavigation flag into "apply the history step"
Workaround spec bug by explicitly carrying information whether
navigation is sync (History api, fragment change) or not.

See for more details https://github.com/whatwg/html/issues/10232
2024-04-05 21:28:41 +02:00
Andreas Kling
93ba99f14a LibWeb/WebAssembly: Add missing visit of WebAssembly::Memory::m_buffer 2024-04-05 16:22:54 +02:00
Shannon Booth
aab5d4e6f9 LibCore: Prevent SIGPIPE on Sockets by default
While this is the default for an underlying socket, it doesn't seem good
to have this as the default for our socket wrapper.

This fixes a crash in ladybird when connecting to the python HTTP server
with HTTPS.
2024-04-05 16:02:46 +02:00
Aliaksandr Kalenik
db31fa730a LibWeb: Increase completed jobs number even if navigable is destroyed
...otherwise spin_until() will stuck waiting.
2024-04-05 08:15:07 +02:00
Aliaksandr Kalenik
aefed21927 LibWeb: Add missing set_delaying_load_events(false) in navigate()
If navigation early returns before reaching "finalize a cross document
navigation" then we have to make sure delaying load events is disabled.

See spec issue https://github.com/whatwg/html/issues/10252
2024-04-05 08:15:07 +02:00
Andreas Kling
b2a099e647 LibWeb: Don't leak entire realm after parsing CSS @supports rule
Before this change, every CSS @supports rule would keep the containing
JS realm alive via a JS::Handle. This led to a GC reference cycle and
the whole realm leaked.

Since we only need the realm at construction time, we can take it as a
parameter instead, and stop storing it.
2024-04-05 08:14:19 +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
Shannon Booth
973cc67e81 LibWeb: Implement <a> element activation behavior for ismap <img>s
This allows you to click on a <img> that has an ismap attribute, and
will result in the navigation URL having the coordinates appended as a
query to the URL.
2024-04-04 17:17:57 -04:00
Shannon Booth
8af7b64acc LibWeb: Fix typo passing through url_string in 'follow the hyperlink'
It's a little bit confusing and awkward that we have `url` _and_
`url_string` here, but let's just fix the typo so that we correctly pass
through the URL with the given suffix (if any).

Currently, nothing is actually passing through this suffix - so it
doesn't fix anything yet, but it becomes relevant in the next commit.
2024-04-04 17:17:57 -04:00
Timothy Flynn
5d5b69578f LibWeb: Handle <input> element type changing to the image button state
The spec has special steps specific to the image button state to load
the element's image URL.
2024-04-04 21:06:45 +02:00
Timothy Flynn
0e774fe780 LibWeb: Recreate the <input> shadow tree when the type attribute changes
This is often used on login forms, for example, to toggle the visibility
of a password. The site will change the <input> element's type to "text"
to allow the password to show.
2024-04-04 21:06:45 +02:00
Timothy Flynn
06a3ca734e LibWeb: Handle changes to an input element's "multiple" attribute
Update the shadow tree so that the attribute is reflected on the page.
2024-04-04 21:06:45 +02:00
Timothy Flynn
6af7f7e0f5 LibWeb: Update placeholder visibility when the placeholder value changes
Otherwise, setting a placeholder on an element that previously did not
have a placeholder would have no visible effect.
2024-04-04 21:06:45 +02:00
stelar7
9f3c3925e0 LibWeb: Implement skeleton of SubtleCrypto.deriveKey 2024-04-04 21:00:40 +02:00
stelar7
abf55fe33d LibWeb: Implement PBKDF2 getKeyLength for SubtleCrypto 2024-04-04 21:00:40 +02:00
stelar7
19bb62d60e LibWeb: Implement PBKDF2 deriveBits for SubtleCrypto 2024-04-04 21:00:40 +02:00
stelar7
daf2c4ce46 LibWeb: Implement skeleton of SubtleCrypto.deriveBits 2024-04-04 21:00:40 +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
Timothy Flynn
48fb343230 LibWeb: Change HTMLParser's factory to accept the encoding as StringView
No need to force an allocation. This makes a future patch a bit simpler,
where we will have the encoding as a String. With this patch, we won't
have to convert it to a ByteString.
2024-04-04 11:23:21 +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
Andrew Kaster
bf722d49b0 LibWeb: Remove WebContent include from SVGDecodedImageData
This is a layering violation, and is not used. Caught by the gn build.
2024-04-04 07:47:16 +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
d91d6ee205 LibWeb: Stop leaking entire realms via Blob URLs
This patch implements the File API spec's supplemental steps for
document's "unloading document cleanup steps" so that we now remove blob
URLs associated with the document's relevant settings object when the
document is being unloaded.

Fixes two realm leaks when running our test suite.
2024-04-03 22:20:50 +02:00
Aliaksandr Kalenik
696cf7b9fb LibWeb: Fix "destroy the child navigable" to call Document::destroy()
f66d33423b was not sufficient to ensure
document destruction when a child navigable is destroyed. This is
because a navigable was remove from the set of all navigables too early
which led to `Navigable::navigable_with_active_document()` being unable
to find a navigable that is still in the process of destruction.

This change solves that by making all steps of a navigable destruction
to happen in afterAllDestruction callback.

Unfortunately, writing a test to verify document destruction is
challenging because no events are emitted to indicate that it has
happened.
2024-04-03 21:17:57 +02:00
stelar7
35676491ec LibWeb: Implement ED25519 verify for SubtleCrypto 2024-04-03 13:10:01 -06:00
stelar7
9ad10566b2 LibWeb: Implement ED25519 sign for SubtleCrypto 2024-04-03 13:10:01 -06:00
stelar7
ec015034bd LibWeb: Implement ED25519 generateKey for SubtleCrypto 2024-04-03 13:10:01 -06:00
stelar7
069295d132 LibWeb: Improve NotSupported error message for normalize_an_algorithm 2024-04-03 13:10:01 -06:00
stelar7
ae230c9150 LibWeb: Implement most of ECDSA verify for SubtleCrypto 2024-04-03 13:10:01 -06:00
stelar7
6906b7c1e6 LibWeb: Implement skeleton of SubtleCrypto.verify 2024-04-03 13:10:01 -06:00
stelar7
bc2a5e24bc LibWeb: Implement skeleton of ECDSA sign for SubtleCrypto 2024-04-03 13:10:01 -06:00
stelar7
41449814db LibWeb: Implement generateKey for ECDSA 2024-04-03 13:10:01 -06:00
stelar7
cfae6523be LibWeb: Implement skeleton of SubtleCrypto.sign 2024-04-03 13:10:01 -06:00
Andreas Kling
fb263e232a LibWeb: Fix typo: covert_number_to_string => convert_number_to_string 2024-04-03 18:17:24 +02:00
Andreas Kling
ffac32d20e LibWeb: Use JS::HeapFunction for WebIDL promise reaction steps
Switching away from SafeFunction immediately backfired here, as we're
dealing with two layers of captures, not one.

Let's do the correct fix, which is to use HeapFunction. This makes the
API and its behavior explicit, and keeps captures alive as long as the
HeapFunction is alive.

Fixes #23819.
2024-04-03 18:14:33 +02:00
Andreas Kling
f1eb837c3d LibWeb: Remove unnecessary JS::Handle in AbortSignal::timeout()
This fixes yet another GC reference cycle.
2024-04-03 18:14:33 +02:00
Andreas Kling
32d065011b LibWeb: Use Core::Timer in AnimationFrameCallbackDriver
There was no need to use a Platform::Timer here since we're not making
use of the automatic SafeFunction behavior anyway.
2024-04-03 18:14:33 +02:00
Andreas Kling
518cedc8f3 LibWeb: Don't store root as JS::Handle in IntersectionObserver
Instead, use a JS::GCPtr and visit it, to prevent GC reference cycles.
2024-04-03 18:14:33 +02:00
Andreas Kling
52fa415779 LibWeb: Use JS::SafeFunction for ResourceLoader callbacks
This is one of the cases where SafeFunction actually makes sense.
Since every resource load will always either succeed, fail, or time out,
it's okay to use a SafeFunction since we know it will eventually get
destroyed.

Until it does, this allows it to keep any captures alive.
2024-04-03 18:14:33 +02: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
Andrew Kaster
12fce55caf LibWeb: Don't load favicons twice for non-SVG documents
This seems to be a rebase mishap in bdb8af94ee.
2024-04-03 09:56:53 -06:00
mobounya
bdb8af94ee LibWeb: Don't load fallback icon for SVG documents
Skip loading a fallback favicon if Document represents a decoded SVG.

Issue: #23405
2024-04-03 09:45:31 -06:00
Andreas Kling
c10f9856a4 LibWeb: Don't use JS::SafeFunction for WebIDL promise reaction steps
SafeFunction was causing massive GC reference cycles here and leaking
entire realms as a result.

Since we end up storing these reaction steps in a JS::NativeFunction
(which uses JS::HeapFunction internally) there should be no need to
protect the captures with SafeFunction.

This dramatically shrinks our memory footprint while running tests.
2024-04-03 12:41:59 +02:00
Shannon Booth
ccebc7a905 LibWeb: Add stubs for the Screen Orientation API
As defined in: https://w3c.github.io/screen-orientation
2024-04-03 10:09:58 +01:00
Aliaksandr Kalenik
7fb09bf95b LibWeb: Skip not runnable in spin_processing_tasks_with_source_until()
Fixes https://github.com/SerenityOS/serenity/issues/23801
2024-04-03 10:25:38 +02:00
Aliaksandr Kalenik
f66d33423b LibWeb: Fix spec bug in "destroy child navigable"
See for more details:
https://github.com/whatwg/html/issues/10242

Before this change it only worked because of another bug in
`EventLoop::spin_processing_tasks_with_source_until()`
where we execute tasks regardless of whether they are runnable or not.
2024-04-03 10:25:38 +02:00
Luke Wilde
facece1a2a LibWeb: Implement PerformanceObserver.supportedEntryTypes 2024-04-03 07:55:51 +02:00
Andreas Kling
e66a4668f9 LibWeb: Use plain Vector for HTMLMediaElement::m_pending_play_promises
These are now covered by visit_edges() instead of being strong GC roots.
2024-04-02 15:56:05 +02:00
Andreas Kling
08e62f883d LibWeb: Add missing visits in ResizeObserverEntry
Both m_device_pixel_content_box_size and m_content_rect were missing.
2024-04-02 15:56:05 +02:00
Andreas Kling
c409a7cdfd LibWeb: Add missing visit of ResizeObservation::m_realm 2024-04-02 15:56:05 +02:00
Shannon Booth
ce341c0230 LibWeb: Add support for document.lastModified 2024-04-02 07:51:02 +02:00
Shannon Booth
d200704b6d LibWeb: Add Last-Modified header to file and resource requests 2024-04-02 07:51:02 +02:00
Tim Ledbetter
3876875bd8 LibWeb: Stub out missing cross origin properties on the window object
Previously, trying to access the `close`, `closed` or `blur` properties
on a cross origin window would cause a crash.
2024-04-02 07:46:16 +02:00
Tim Ledbetter
558fef237c LibWeb: Use the global object to access the performance object
Previously, we were accessing the performance through the current
window object. Thus caused a crash when `animate()` was called on an
element within a document with no associated window object. The global
object is now used to access the performance object in places where
a window object is not guaranteed to exist.
2024-04-02 07:46:16 +02:00
Tim Ledbetter
eebdc7bc88 LibWeb: Allow the Performance object to be used by workers 2024-04-02 07:46:16 +02:00
Shannon Booth
adf061a29c LibWeb: Avoid copying cached elements in HTMLCollection
Once we have built up a cache, we can use that internally for operations
on the collection, instead of copying over the list of elements every
time.

On a synthentic benchmark of a page with ~500 link elements, this
results in a 45% percent speedup on my machine.

```html
<body>
    <ul>
        <li><a href="#">Link 1</a></li>
        ...
        <li><a href="#">Link N</a></li>
    </ul>

    <script>
        window.onload = function() {
            const startTime = performance.now();
            for (let i = 0; i < 1_000_000; ++i) {
                const numLinks = document.links.length;
            }
            const endTime = performance.now();
            const timeTaken = endTime - startTime;
            console.log(timeTaken);
        };
    </script>
</body>
</html>
```
2024-04-02 07:33:40 +02:00
Shannon Booth
094ab8b4d2 LibWeb: Remove some uneeded const_casts from HTMLCollection
Correcting a variable name while we're at it.
2024-04-02 07:33:40 +02:00
Shannon Booth
b1be8bd826 LibWeb: Implement is_supported_property_index in terms of length() 2024-04-02 07:33:40 +02:00
Shannon Booth
b9b264e97a LibWeb: Remove redundant is_empty check from is_supported_property_index
An empty list of elements will not return true for any unsigned number,
so we can simply remove this check.
2024-04-02 07:33:40 +02:00
Shannon Booth
cdd0038c9e LibWeb: Factor out a method to update the cached elements
This is useful for any function which is needing to read the from the
cache, instead of onl using `collect_matching_elements`.
2024-04-02 07:33:40 +02:00
Timothy Flynn
b6501adef8 LibWeb: Use the proper in-flight request to check if a stream is closing 2024-04-01 21:11:01 +02:00
MacDue
59cd086199 LibWeb: Stub (and implement) SVGSVGElement methods and attributes
This implements trivial functions and stubs out the rest.

Implemented:

```
[SameObject] readonly attribute SVGAnimatedLength x;
[SameObject] readonly attribute SVGAnimatedLength y;
[SameObject] readonly attribute SVGAnimatedLength width;
[SameObject] readonly attribute SVGAnimatedLength height;

undefined deselectAll();

SVGLength createSVGLength();
DOMPoint createSVGPoint();
DOMMatrix createSVGMatrix();
DOMRect createSVGRect();
SVGTransform createSVGTransform();

Element getElementById(DOMString elementId);

unsigned long suspendRedraw(unsigned long maxWaitMilliseconds);
undefined unsuspendRedraw(unsigned long suspendHandleID);
undefined unsuspendRedrawAll();
undefined forceRedraw();
```

Stubbed:

```
attribute float currentScale;
[SameObject] readonly attribute DOMPointReadOnly currentTranslate;

NodeList getIntersectionList(
  DOMRectReadOnly rect, SVGElement? referenceElement);
NodeList getEnclosureList(
  DOMRectReadOnly rect, SVGElement? referenceElement);
boolean checkIntersection(SVGElement element, DOMRectReadOnly rect);
boolean checkEnclosure(SVGElement element, DOMRectReadOnly rect);
```
2024-04-01 21:10:35 +02:00
MacDue
5739ea9ba1 LibWeb: Stub SVGGraphicsElement methods/attributes
This stubs the `SVGGraphicsElement.getBBox()` method and the
`.transform` attribute.
2024-04-01 21:10:35 +02:00
MacDue
329262d54f LibWeb: Stub SVGTextContentElement.getStartPositionOfChar() 2024-04-01 21:10:35 +02:00
MacDue
bafb6bd059 LibWeb: Move SVGLength unit constants to header
No behaviour change.
2024-04-01 21:10:35 +02:00
MacDue
d2918b8204 LibWeb: Add (and use) CSS property to SVGAnimatedLength helper
No behaviour change.
2024-04-01 21:10:35 +02:00
MacDue
6d72f40d8d LibWeb: Stub out SVGAnimatedTransformList 2024-04-01 21:10:35 +02:00
MacDue
3bab4fbae9 LibWeb: Stub out SVGTransformList 2024-04-01 21:10:35 +02:00
MacDue
a6a40a5bc6 LibWeb: Stub out SVGTransform 2024-04-01 21:10:35 +02:00
Shannon Booth
249ee0a30e LbiWeb: Return an HTMLAllCollection from document.all 2024-04-01 14:41:00 +02:00
Shannon Booth
1f59e21829 LibWeb: Implement HTMLAllCollection
This collection has some pretty strange behaviour, particularly with the
IsHTMLDDA slot which is defined in the javascript spec specifically for
this object.

This commit implements pretty much all of this interface, besides from
the custom [[Call]].

There is also no caching over this collection. Since it is a live
collection over the entire document, the performance is never going to
be great, and I am not convinced any speedup for this legacy interface
is worth a massive cache.
2024-04-01 14:41:00 +02:00
Shannon Booth
897f55ca8a LibWeb: Use NonnullGCPtr for HTMLCollection::collect_matching_elements
The pointers here can never be null, so lets engrain that into the type
for clarity.
2024-04-01 14:41:00 +02:00
Shannon Booth
8fa0730b84 LibWeb: Remove resolved FIXME about caching in HTMLCollection 2024-04-01 14:41:00 +02:00
Aliaksandr Kalenik
9098fa23a2 LibWeb: Catch up with the spec on document destroy, abort and unload
These changes do not solve hanging `location.reload()` and
`location.go()` but only align implementation with the latest edits in
the specification.

`WindowProxy-Get-after-detaching-from-browsing-context` test output is
affected because `iframe.remove();` no longer synchronously does
destruction of a document, but queues a task on event loop.

Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2024-04-01 13:23:58 +02:00
MacDue
06ed56f4f6 LibWeb: Paint SVGDecodedImageData via Navigable::paint()
Going via the `ViewportPaintable` missed some steps (in particular
computing clip rects), which meant nested SVGs within SVGs-as-images
were completely clipped.
2024-03-30 21:35:22 +01:00
Kenneth Myhra
4b66f5662b LibWeb: Correct spec steps for serializable objects
This aligns us with the current spec steps for serializable objects in
StructuredSerializeInternal.
2024-03-30 21:26:37 +01:00
Shannon Booth
d725076c7f LibWeb: Fix a silly mistake for bitLength 64 in conversion to int
Which was resulting in 32 bit numbers getting the max array like
index instead of 64 bit numbers!
2024-03-30 21:21:23 +01:00
Kenneth Myhra
40d62a4365 LibWeb: Add missing spec link for ImageData constructor 2024-03-30 19:29:14 +01:00
Kenneth Myhra
c17171b86c LibWeb: Add ImageData constructor with data 2024-03-30 19:29:14 +01:00
Timothy Flynn
f61f55d397 LibWeb+LibWebView+WebContent: Support muting an entire page
This adds an IPC for chromes to mute a tab. When muted, we trigger an
internal volume change notification and indicate that the user agent has
overriden the media volume.
2024-03-30 19:28:20 +01:00
Timothy Flynn
7c31343df0 LibWeb: Store the ID of all media elements on a page
This will be used to inform the media elements when the user has muted
the page.
2024-03-30 19:28:20 +01:00
Matthew Olsson
b2907f62a6 LibWeb: Reject invalid easing functions in AnimationEffect.updateTiming 2024-03-30 19:26:58 +01:00
Andreas Kling
f90489acd6 Revert "LibWeb: Fix endless spinning in apply_the_history_step()"
This reverts commit 609a72f7c7.
2024-03-30 08:28:16 +01:00
Andreas Kling
872fa58ef8 Revert "LibWeb: Fix hanging location.reload() when SHE is populated by fetching"
This reverts commit 966b042db6.
2024-03-30 08:28:05 +01:00
Andreas Kling
14f2012c8b LibWeb: Fix a bunch of bad stack captures in AudioContext
It's not safe to capture a local NonnullGCPtr by reference in a closure
that will execute at some arbitrary time in the future when the local is
out of scope.
2024-03-30 08:25:59 +01:00
Andreas Kling
6103884c18 LibWeb: Add some extra browsing context null checks
I saw a suspicious null dereference in
check_if_access_between_two_browsing_contexts_should_be_reported(),
but I have no idea how to reproduce it.

Still, it seems harmless to paper over it with a FIXME debug log.
2024-03-30 08:15:49 +01:00
Aliaksandr Kalenik
966b042db6 LibWeb: Fix hanging location.reload() when SHE is populated by fetching
Adds a hack to address spec bug https://github.com/whatwg/html/issues/9869
2024-03-30 07:35:55 +01:00
Aliaksandr Kalenik
609a72f7c7 LibWeb: Fix endless spinning in apply_the_history_step()
While waiting for a task that populates a session history entry, we
can't limit the processing of the event loop to the
`NavigationAndTraversal` task source. This is because fetching uses the
`Networking` task source, which also needs to be processed.

Since making a fetch request might take some time, we want to process
everything on the event loop while waiting, to avoid blocking user
interactions.

It is still possible to use `spin_processing_tasks_with_source_until()`
on subsequent steps of `apply_the_history_step()`.

Also modifies test that was flaky.
2024-03-30 07:35:55 +01:00
Aliaksandr Kalenik
baf589deef LibWeb: Add missing navigable destroyed check 2024-03-30 07:35:55 +01:00
Timothy Flynn
2393ee6548 LibWeb: Don't attempt to notify chromes about audio playing until ready
The current location of the IPC invocation is often too soon. We reach
it before the audio file has completely finished downloading / loading,
thus there isn't an AudioTrack object yet.

Instead, wait until we are actually playing the audio to invoke the IPC.

This is particularly frequent on bandcamp.
2024-03-30 07:35:30 +01:00
Matthew Olsson
87155c7b1d LibWeb: Fix infinite loop in CSS::Parser::parse_transition_value() 2024-03-30 07:34:25 +01:00
Andreas Kling
906c69c6d1 LibWeb: Don't fall apart on transition: none in CSS
Fixes a crash when loading https://soundcloud.com/
2024-03-30 07:34:02 +01:00
MacDue
8cec7ea221 LibWeb: Paint/apply uses of SVG <clipPath>s
This works just like masks, with a few more (spec imposed) limitations.
All the style properties on the contents of a <clipPath> are ignored,
and instead we just paint the "raw geometry" (as all black), then apply
that as an alpha mask to the target element.

If the element has both a `mask` and `clip-path` set, we compute the
masking area as the intersection of the mask rect and clip rect, then
apply the clip mask to the `mask` (producing a combined mask).

Fixes #19648
Fixes #23006
2024-03-29 21:59:56 +01:00
MacDue
c1b5fe61d1 LibWeb: Lay out SVG <clipPath> uses
This uses the same trick as done for masks in #23554. Each use of an
SVG `<clipPath>` becomes it's own layout subtree rooted at it's user.
This allows each use have it's own layout (which allows supporting
features such as `clipPathUnits`).
2024-03-29 21:59:56 +01:00
MacDue
0a061a6a63 LibWeb: Allow references via xlink:href for SVG <use> elements 2024-03-29 21:59:56 +01:00
MacDue
03f957dc79 LibWeb: Add the clip-path property and resolve it for SVG elements 2024-03-29 21:59:56 +01:00
Matthew Olsson
3160733c1a LibWeb: Expand transition longhand values 2024-03-29 21:58:12 +01:00
Matthew Olsson
1e6ad075f3 LibWeb: Add transition properties to Properties.json 2024-03-29 21:58:12 +01:00
Matthew Olsson
5dce559ed8 LibWeb: Parse transition style values 2024-03-29 21:58:12 +01:00
Matthew Olsson
911088278d LibWeb: Add the CSSTransition IDL object 2024-03-29 21:58:12 +01:00
Matthew Olsson
e4f1cb6f8c LibWeb: Track the transition generation
This is used for transition's class-specific composite ordering
2024-03-29 21:58:12 +01:00
Andreas Kling
dd3e002ecf LibWeb: Make empty images (no bitmap, no alt text) take no layout space
This matches the behavior of other browsers.
2024-03-29 08:52:55 -04:00
Timothy Flynn
43e55668eb LibWeb: Implement Document's supported property names closer to the spec
Our implementation was errantly matching HTML tags other than the list
specified by the spec. For example, a <meta name=title> tag would be a
match for document.title.

For example, bandcamp will dynamically update its title when audio is
played as follows:

    document.title = "▶︎ " + document.title;

And bandcamp also has a <meta name=title> tag. The result was that the
title would become "▶︎ [object HTMLMetaElement]".
2024-03-29 08:52:01 -04:00
Timothy Flynn
8b1ad5c496 LibWeb+LibWebView+WebContent: Add a new IPC for modifying history state
Let's not re-invoke the "page did start loading" IPC when the history
state is pushed/replaced. It's a bit misleading (the change does not
actually load the new URL), but also the chromes may do more work than
we want when we change the URL.

Instead, add a new IPC for the history object to invoke.
2024-03-29 08:52:01 -04:00
Timothy Flynn
1767f405dc LibWeb+LibWebView+WebContent: Convert URL declarations to east-const 2024-03-29 08:52:01 -04:00
Matthew Olsson
291871e0cc LibWeb: Associate InternalAnimationTimeline with a DOM::Document 2024-03-29 06:59:37 +01:00
Matthew Olsson
c33f6b2ff6 LibWeb: Ensure requestAnimationFrame callbacks run in the proper order
From https://html.spec.whatwg.org/#list-of-animation-frame-callbacks:

    Each target object has a map of animation frame callbacks, which is
    an ordered map that must be initially empty, and an animation frame
    callback identifier, which is a number that must initially be zero.
2024-03-29 06:59:37 +01:00
Matthew Olsson
ffc648196a LibWeb: Dispatch animation events before requestAnimationFrame callbacks
Most of the time there won't be any animation frame callbacks, and we
can keep our behavior of dispatching events in the animation timer.
2024-03-29 06:59:37 +01:00
Matthew Olsson
4dc8492155 LibWeb: Move animation event dispatch into update_animations_and_...()
This will be important for the next commit
2024-03-29 06:59:37 +01:00
Aliaksandr Kalenik
ca363f0024 LibWeb: Add basic "top layer" support
Implements the "top layer" concept from "CSS Positioned Layout Module
Level 4" specification.

- The tree builder is modified to ensure that layout nodes created by
  top layer elements are children of the viewport.
- Implements missing steps in `showModal()` to add an element top top
  layer.
- Implements missing steps in `close()` to remove an element from top
  layer.

Further steps could be:
- Add support for `::backdrop` pseudo-element.
- Implement the "inert" concept from HTML spec to block hit-testing
  when element from top layer is displayed.
2024-03-29 06:57:07 +01:00
Matthew Olsson
560b07dda3 LibWeb: Use the timeline time when saving animation play/pause time 2024-03-28 21:08:32 +01:00
Matthew Olsson
a1f4d1875e LibWeb: Add an InternalAnimationTimeline object
This will allow fine grained control over animation times, which will
allow us to write timing tests that can reliably pass on the much slower
CI machines.
2024-03-28 21:08:32 +01:00
Timothy Flynn
40c0dd81d2 LibWeb+LibWebView+WebContent: Inform chromes when audio is played/paused
Most browsers have some indicator when audio is playing in a tab, which
makes it easier to find that tab and mute unwanted audio. This adds an
IPC to allow the Ladybird chromes to do something similar.
2024-03-28 21:08:23 +01:00
Timothy Flynn
5424135d81 LibWeb: Remove unnecessary trailing semi-colons from Page.h
These should be caught by clang-format (via the RemoveSemicolon option),
but it does not seem to get these.
2024-03-28 21:08:23 +01:00
Aliaksandr Kalenik
220088480b LibWeb: Bring "apply the history step" up to date with the spec
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2024-03-28 15:34:52 +01:00
Aliaksandr Kalenik
18cfbb5cb4 LibWeb: Bring initialize_navigable() up to date with the spec 2024-03-28 15:34:52 +01:00
Aliaksandr Kalenik
ffd3639b17 LibWeb: Pass navigation params by const-ref to load_document() 2024-03-28 15:34:52 +01:00
Aliaksandr Kalenik
39f74d3437 LibWeb: Bring HistoryHandlingBehavior up to date with the specification
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2024-03-28 15:34:52 +01:00
Aliaksandr Kalenik
ce325a9912 LibWeb: Add SessionHistoryEntry::document()
No behaviour change intended.
2024-03-27 18:07:07 +01:00
Aliaksandr Kalenik
b590d1b48b LibWeb: Transform SessionHistoryEntry from a struct to a class
No behaviour change intended.
2024-03-27 18:07:07 +01:00
Andreas Kling
d37c0a2cab LibWeb: Don't make flex layout responsible for flex container cross size
Although the flex algorithm as specified does say to determine the cross
size of the flex container, this is not how our layout engine works.

The parent formatting context is responsible for sizing its children,
and since that's already happening, we can simply remove the cross
sizing step from FFC.
2024-03-27 16:43:04 +01:00
Andreas Kling
ead341738e LibWeb: Don't use stretch-fit width for inline boxes with aspect ratio 2024-03-27 16:43:04 +01:00
Andreas Kling
1cfd8b3ac0 LibWeb: Retain size definiteness when transferred through aspect ratio
If a box has definite width and a preferred aspect ratio, we can
determine its height without performing layout. Hence, its height should
also be considered definite. And the other way around for width from
height as well.
2024-03-27 16:43:04 +01:00
Andreas Kling
ca53eefe11 LibWeb: Compute height early when possible for floating boxes
This is preparation for the next commit, which will make flex layout
relinquish control of the flex container cross size to the parent
formatting context.
2024-03-27 16:43:04 +01:00
Andreas Kling
aa59419529 LibWeb: Remove unnecessary check that BFC isn't clearing a flex item
A block-level box in BFC will never be a flex item. It may be a flex
container, but not an item. Hence this check was unnecessary.
2024-03-27 16:43:04 +01:00
Andreas Kling
a0ed8bdb57 LibWeb: Remove outdated comment about definite calc() sizes
We already do determine whether calc() sizes are definite, so this
comment was not necessary.
2024-03-27 16:43:04 +01:00
Matthew Olsson
e4dba9d932 LibWeb: Cache the last CSS play-state value on KeyframeEffect
This way we can just leave it alone if the property hasn't changed.
Notably, if the play-state property has been set to 'paused', and then
the user gets the animation with JS and calls .play() on it, it should
start playing despite the play-state property value.
2024-03-27 09:40:05 -06: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
8e6e938167 LibWeb: Remove AbortSignal::follow()
This no longer has any callers.
`AbortSignal::create_dependent_abort_signal()` should be used instead.
2024-03-26 11:42:40 +01: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
Andreas Kling
3d78f86a2f LibWeb: Don't ask RequestServer to prefetch DNS for file: and data: URLs 2024-03-26 11:39:45 +01:00
Andreas Kling
41cc8e75f2 LibJS: Make PromiseJob store callback as a HeapFunction
This is a speculative fix for a flake seen on CI where a JobCallback
captured by a PromiseJob callback was GC'd prematurely.
2024-03-26 05:47:24 +01:00
Matthew Olsson
cf54ba01ac LibWeb: Be more strict about invoking .play() on element animations
We don't want to always invoke the .play() method if an animation is
relevant and had a play state of running, as the play state is
essentially just "paused" or "not paused". We replace that relevancy
check with the inverse of the pause check so we don't constantly call
.play() on animations that are finished.

Also duplicates and moves the temporary context into both blocks, since
most of the time neither condition will be true.
2024-03-26 05:47:09 +01:00
Matthew Olsson
e2dfef90fb LibWeb: Remove useless animation relevancy check
This is already done in Animatable::get_animations()
2024-03-26 05:47:09 +01:00
Andrew Kaster
cddbdf5ae9 LibWeb: Implement skeleton of RSA-OAEP decrypt for SubtleCrypto
The actual Crypto algorithm part isn't implemented yet, so we just copy
the ciphertext and claim that's the plaintext :^)
2024-03-25 17:01:23 -06:00
Andrew Kaster
29b68a1b10 LibWeb: Implement skeleton of RSA-OAEP encrypt for SubtleCrypto
The actual Crypto algorithm part isn't implemented yet, so we just copy
the plaintext and claim that's the ciphertext :^)
2024-03-25 17:01:23 -06:00
Andrew Kaster
d71bd185c6 LibWeb: Implement skeleton of SubtleCrypto.decrypt 2024-03-25 17:01:23 -06:00
Andrew Kaster
df3d0538a9 LibWeb: Implement skeleton of SubtleCrypto.encrypt
No algorithms implement this yet, but this is the high level entry
point.
2024-03-25 17:01:23 -06:00
Andrew Kaster
ae4d90c88a LibWeb: Error out SubtleCrypto.digest with a OOM on Buffer copy error
Instead of returning a custom OperationError, let's just return a LibJS
defined OOM error instead.
2024-03-25 17:01:23 -06:00
Andrew Kaster
497f3ca0fd LibWeb: Store PBKDF2Params' salt field as a ByteBuffer directly
Rather than trying to store a Handle to a WebIDL::BufferSource, let's
look ahead to what the spec wants us to do with this field and get a
copy of the bytes held by the buffer source right away.
2024-03-25 17:01:23 -06:00