Commit Graph

9103 Commits

Author SHA1 Message Date
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
Andrew Kaster
a0623a47de LibWeb: Implement importKey for RSA-OAEP 2024-03-25 17:01:23 -06:00
Andrew Kaster
28dc076764 LibWeb: Use a forgiving base64url encoding for JWK export 2024-03-25 17:01:23 -06:00
Andrew Kaster
e422c93537 LibWeb: Make normalize_an_algorithm from SubtleCrypto public
We'll need to call this from other source files when implementing
specific algorithms.
2024-03-25 17:01:23 -06:00
Aliaksandr Kalenik
1036e104ef LibWeb: Remove cache for Paintable::is_visible()
...because it depends on computed values that could be changed without
rebuilding paintable tree.
2024-03-25 14:17:30 +01:00
Andreas Kling
9af966f87d LibWeb: Avoid unnecessary Vector copying when generating line boxes
Carry the same Vector<Gfx::DrawGlyphOrEmoji> all the way from the inline
level iterator to the final line box fragment.
2024-03-25 12:39:23 +01:00
Aliaksandr Kalenik
0652d159cf LibWeb: Add a test for mouse{over,out,enter,leave} events 2024-03-25 08:14:13 +01:00
Aliaksandr Kalenik
4ae2eaead1 LibWeb: Dispatch mouseout and mouseover events 2024-03-25 08:14:13 +01:00
Timothy Flynn
74377618b1 LibWeb: Process Base64 data URLs with the forgiving Base64 algorithm 2024-03-25 08:13:27 +01:00
Timothy Flynn
24ecf31ff5 LibURL+LibWeb: Move data URL processing to LibWeb's fetch infrastructure
This is a fetching AO and is only used by LibWeb in the context of fetch
tasks. Move it to LibWeb with other fetch methods.

The main reason for this is that it requires the use of other LibWeb AOs
such as the forgiving Base64 decoder and MIME sniffing. These AOs aren't
available within LibURL.
2024-03-25 08:13:27 +01:00
MacDue
c6899b79b6 LibWeb: Normalize the angle delta in CanvasPath::ellipse()
This fixes both the incorrect arc and ellipse from #22817.
2024-03-24 18:37:44 +01:00
Aliaksandr Kalenik
b31fb36ed3 LibWeb: Reschedule repaint for navigables with ongoing painting
Fixes delayed repainting in the following case:
1. Style or layout invalidation triggers html event loop processing.
2. Event loop processing does nothing because there is no rendering
   opportunity.
3. Style or layout change won't be reflected until something else
   triggers event loop processing
2024-03-24 16:30:31 +01:00
Andreas Kling
8d7a1e5654 LibWeb: Skip some redundant UTF-8 validation in CSS tokenizer
If we're just adding code points to a StringBuilder, there's no need to
revalidate the result.
2024-03-24 13:28:24 +01:00
Kenneth Myhra
51847bbebf LibWeb: Remove ImageData's create_with_size() and use create() instead
Removes ImageData::create_with_size() and redirects previous usage to
ImageData::create().
2024-03-24 11:09:09 +01:00
Kenneth Myhra
8a1e88677f LibWeb: Add FIXME comments to ImageData.idl
Add FIXME comments for ImageData's missing constructor and attribute
colorSpace.
2024-03-24 11:09:09 +01:00
Kenneth Myhra
30a02fef91 LibWeb: Add one of the two documented constructors to ImageData
Also adds the IDL types:
- dictionary ImageDataSettings
- enum PredefinedColorSpace.
2024-03-24 11:09:09 +01:00
Timothy Flynn
feddecde5b LibWeb: Emit the current token before EOF on invalid comments
The spec for each of these state:

    -> EOF:
    This is an eof-in-comment parse error. Emit the current comment
    token. Emit an end-of-file token.

We were neglecting to emit the current comment token before emitting an
EOF token. Note the existing EMIT_CURRENT_TOKEN macro was unused.
2024-03-23 20:58:31 +01:00
Aliaksandr Kalenik
26a516c85f LibWeb: Allow any FC type for replaced boxes in dimension_box_on_line()
If box is sized as replaced it still could be anything, not only SVG.

This fixes crashing on https://www.shopify.com/ that was caused by a
missing paintable for a box that has a layout node. This occurred
because the box was not laid out in dimension_box_on_line().
2024-03-23 20:57:05 +01:00
Tim Ledbetter
e1fbb08747 LibWeb: Avoid division by zero when calculating box aspect ratio 2024-03-23 20:56:26 +01:00
Tim Ledbetter
2227674b91 LibWeb: Don't crash when updating a select with detached option elements
`Node::shadow_including_root()` was missing a null check, which caused
a crash when manipulating a select element, whose option elements were
initially detached.
2024-03-23 20:56:26 +01:00
Tim Ledbetter
521a1be97f LibWeb: Don't crash when querying the CDataSection.assignedSlot property 2024-03-23 20:56:26 +01:00
Tim Ledbetter
3518f39b60 LibWeb: Don't crash when querying detached circle element properties 2024-03-23 20:56:26 +01:00
Timothy Flynn
7b3ddd5e15 LibWeb: Track fetching-related tasks in FetchController for cancellation
The HTMLMediaElement, for example, contains spec text which states any
ongoing fetch process must be "stopped". The spec does not indicate how
to do this, so our implementation is rather ad-hoc.

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

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

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

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

It is a little bit awkward maintaining a fetch task ID. Ideally, we
could use the underlying task ID throughout. But we do not have access
to the underlying task nor its ID when the task is running, at which
point we need some ID to remove from the pending task list.
2024-03-23 13:45:35 +01:00
Timothy Flynn
4806cf9527 LibWeb: Return the ID of queued global events
This will allow callers to track the event.
2024-03-23 13:45:35 +01:00
Aliaksandr Kalenik
f932d5d825 LibWeb: Look for labeled control in DOM tree instead of layout tree
...because "change" event should be dispatched on control even if it
has "display: none" style.

This change fixes selection in labels dropdown on GitHub's "new issue"
page.
2024-03-23 12:46:37 +01:00
Aliaksandr Kalenik
561e011e07 LibWeb+WebContent+Ladybird: Add ability to paste text from clipboard
Text can be pasted by pressing Ctrl/Cmd+V or by using button in the
context menu. For now only the Qt client is supported.
2024-03-22 15:47:33 -04:00
Aliaksandr Kalenik
d5c6e45dca LibWeb: Change Element::closest() to check if any of selector matches
...instead of checking if all selectors match an element.

Fixes bug reduced from GitHub's "new issue" page.
2024-03-22 18:43:46 +01:00
Andreas Kling
afe6abfc09 LibWeb: Use an ancestor filter to quickly reject many CSS selectors
Given a selector like `.foo .bar #baz`, we know that elements with
the class names `foo` and `bar` must be present in the ancestor chain of
the candidate element, or the selector cannot match.

By keeping track of the current ancestor chain during style computation,
and which strings are used in tag names and attribute names, we can do
a quick check before evaluating the selector itself, to see if all the
required ancestors are present.

The way this works:

1. CSS::Selector now has a cache of up to 8 strings that must be present
   in the ancestor chain of a matching element. Note that we actually
   store string *hashes*, not the strings themselves.

2. When Document performs a recursive style update, we now push and pop
   elements to the ancestor chain stack as they are entered and exited.

3. When entering/exiting an ancestor, StyleComputer collects all the
   relevant string hashes from that ancestor element and updates a
   counting bloom filter.

4. Before evaluating a selector, we first check if any of the hashes
   required by the selector are definitely missing from the ancestor
   filter. If so, it cannot be a match, and we reject it immediately.

5. Otherwise, we carry on and evaluate the selector as usual.

I originally tried doing this with a HashMap, but we ended up losing
a huge chunk of the time saved to HashMap instead. As it turns out,
a simple counting bloom filter is way better at handling this.
The cost is a flat 8KB per StyleComputer, and since it's a bloom filter,
false positives are a thing.

This is extremely efficient, and allows us to quickly reject the
majority of selectors on many huge websites.

Some example rejection rates:
- https://amazon.com: 77%
- https://github.com/SerenityOS/serenity: 61%
- https://nytimes.com: 57%
- https://store.steampowered.com: 55%
- https://en.wikipedia.org: 45%
- https://youtube.com: 32%
- https://shopify.com: 25%

This also yields a chunky 37% speedup on StyleBench. :^)
2024-03-22 18:27:32 +01:00
Aliaksandr Kalenik
e232a84f0e LibWeb: Do not include box's own scroll offset in get_client_rects()
Fixes https://github.com/SerenityOS/serenity/issues/23631
2024-03-22 12:13:59 +01:00
Tim Ledbetter
7b08fd9f72 LibWeb: Simplify String to CORSSettingAttribute value conversion
There's no need to check the "anonymous" case explicitly, as
`CORSSettingAttribute::Anonymous` is the default value.
2024-03-22 11:29:57 +01:00
Tim Ledbetter
aabf1a65b1 LibWeb: Align CORSSettingsAttribute values with the specification
This change makes our crossOrigin attribute getter behave the same way
as other browsers.
2024-03-22 11:29:57 +01:00
Andreas Kling
df2cd33ccd Revert "LibWeb: Never claim "rendering opportunity" for SVG-as-image documents"
This reverts commit 8aae50f4ee.
2024-03-22 10:23:28 +01:00
Andreas Kling
34954f49b6 LibWeb: Log a FIXME when encountering an unexpected block-level box
I've seen a crash when trying to verify_cast some block-level box to a
BlockContainer when it's actually something else.

This patch adds a debug log message so we can learn more about it next
time it happens somewhere.
2024-03-22 06:43:57 +01:00
Andreas Kling
8aae50f4ee LibWeb: Never claim "rendering opportunity" for SVG-as-image documents
Since we drive painting for SVG-as-image manually anyway, there's no
need for them to say they are "ready to paint", since that just causes
unnecessary extra processing in the HTML event loop.
2024-03-22 06:43:57 +01:00
Aliaksandr Kalenik
42d5883d57 LibWeb: Set animation update flag from Animation::invalidate_effect()
Fixes regressed animation tests.
2024-03-21 16:10:26 +01:00
Aliaksandr Kalenik
b7d28ee57d LibWeb: Change update_style() to update animated style only if needed
Instead of invalidating animated style properties whenever
`Document::update_style()` is called, now we only do that when
animations might have actually progressed. We still have to ensure
animated properties are up-to-date in `update_style()` to ensure that
JS methods can access updated style properties.
2024-03-21 11:29:02 +01:00
MacDue
6b799a739c LibWeb: Use ensure_subpath() in CanvasPath::arc_to()
No behaviour change.
2024-03-21 09:19:22 +01:00
MacDue
d73c21b6fe LibWeb: Implement missing CanvasPath::ellipse() steps 2024-03-21 09:19:22 +01:00
MacDue
cf1f00943a LibWeb: Implement missing CanvasPath::bezierCurveTo() steps 2024-03-21 09:19:22 +01:00
MacDue
877a0e06c4 LibWeb: Implement missing CanvasPath::quadraticCurveTo() steps 2024-03-21 09:19:22 +01:00
MacDue
d951ee399f LibWeb: Implement missing CanvasPath::lineTo() steps 2024-03-21 09:19:22 +01:00
MacDue
6128a28f17 LibWeb: Implement missing CanvasPath::moveTo() steps 2024-03-21 09:19:22 +01:00
Aliaksandr Kalenik
96d67ded3e LibWeb: Always run layout and style updates from event loop processing
Before this change, we ran style and layout updates from both event
loop processing and update timers. This could have caused missed resize
observer updates and unnecessary updating of style or layout more than
once before repaint.

Also, we can now be sure unnecessary style or layout updates won't
happen in `EventLoop::spin_processing_tasks_with_source_until()`.
2024-03-20 20:28:21 +01:00
Aliaksandr Kalenik
e09816c37c LibWeb: Run only tasks with navigation source in "apply history step"
In our implementation of the "apply the history step" algorithm, we
have to spin-wait for the completion of tasks queued on the event loop.
Before this change, we allowed tasks from any source to be executed
while we were waiting. It should not be possible because it allows to
interrupt history step application by anything, including another
history step application.

Fixes https://github.com/SerenityOS/serenity/issues/23598
2024-03-20 20:28:21 +01:00
Andrew Kaster
f26dd29b4d LibWeb: Print more information about thrown DOMExceptions in the console
This doesn't quite match the behavior of other engines, but by golly is
it helpful.
2024-03-20 15:18:44 -04:00
Timothy Flynn
6e2685f091 LibWeb: Remove FLATTEN attribute from SelectorEngine::fast_matches
This causes compilation time with GCC to increase far too much.
2024-03-20 10:33:16 -04:00
Matthew Olsson
0d70311c90 LibWeb: Resolve unresolved style values eagerly in KeyframeEffect
This isn't required as the StyleComputer will do this when animating,
but this allows the properties to be resolved once instead of on
every animation frame.

Note that we still pass AllowUnresolved::Yes because the properties will
not be resolved if there is no target.
2024-03-20 09:17:33 +01:00
Matthew Olsson
3dd9f2715f LibWeb: Resolve unresolved style values when animating properties 2024-03-20 09:17:33 +01:00
Matthew Olsson
b2fb9cc7d3 LibWeb: Allow ignoring unresolved style values when iterating properties
When iterating through a @keyframes rule, it isn't possible to resolve
unresolved style properties since there are no elements. This change
allows those properties to simply pass through this helper function.
2024-03-20 09:17:33 +01:00
Matthew Olsson
1f53727a3f LibWeb: Remove Badge from CSS::Parser::resolve_unresolved_style_value
KeyframeEffect needs to use this method to resolve unresolved properties
in the same way that StyleComputer does.
2024-03-20 09:17:33 +01:00
Matthew Olsson
ebfc6c33a6 LibWeb: Remove "resolved" from the name of Keyframe's property map
These will need to store unresolved styles as well, since they may be
built during parsing of a @keyframes rule. In that case there is no
target element or pseudo-element, and thus the value cannot be resolved.
2024-03-20 09:17:33 +01:00
Kenneth Myhra
c92f556aa5 LibWeb: Add {,de}serialization steps for FileList 2024-03-20 09:16:01 +01:00
Kenneth Myhra
5397340724 LibWeb: Add {,de}serialization steps for DOMQuad 2024-03-20 09:16:01 +01:00
Kenneth Myhra
d086d0cd92 LibWeb: Remove 'FIXME' on comment which is already implemented 2024-03-20 09:16:01 +01:00
Kenneth Myhra
52f056503d LibWeb: Add {,de}serialization steps for CryptoKey 2024-03-20 09:16:01 +01:00
Kenneth Myhra
ca54691ecf LibWeb: Add structured_deserialize_internal()
structured_deserialize_internal() is added to support sub
deserialization from serializable interfaces serialization steps which
needs the ability to pass onto the current position in the deserialized
data.
2024-03-20 09:16:01 +01:00
Kenneth Myhra
31f345fcb0 LibWeb: Add DeserializationMemory parameter to deserialization_steps()
We want to bring with us the value of DeserializationMemory to
Serializable::deserialization_steps() when doing sub serialization.
2024-03-20 09:16:01 +01:00
Kenneth Myhra
4669c1ba31 LibWeb: Add SerializationMemory parameter to serialization_steps()
We want to bring with us the value of SerializationMemory to
Serializable::serialization_steps() when doing sub serialization.
2024-03-20 09:16:01 +01:00
Tim Ledbetter
c8b219914e LibWeb: Use ErrorOr to propagate SVG attribute parsing errors
If an unexpected token is encountered when parsing an SVG attribute it
is now immediately propagated with ErrorOr. Previously, some situations
where an unexpected token was encountered could cause a crash.
2024-03-20 09:09:35 +01:00
Tim Ledbetter
a55394c383 LibWeb: Fix typo in SVG attribute parser method name 2024-03-20 09:09:35 +01:00
Tim Ledbetter
c1b1233575 LibWeb: Avoid duplicating SVG viewbox height calculation 2024-03-20 09:09:35 +01:00
Andreas Kling
f58ca99a66 LibWeb: Parse the ::backdrop pseudo element
We don't do anything with this yet, but let's at least not reject
selectors with ::backdrop in the parser.
2024-03-19 20:59:41 +01:00
Andreas Kling
6bb4a2bfaa LibWeb: Let HTMLCollection cache its element list
Use the new DOM tree version mechanism to allow HTMLCollection to
remember its internal list of elements instead of rebuilding it on
every access.

This avoids thousands of full DOM walks while loading our GitHub repo.

~15% speed-up on jQuery subtests in Speedometer 3.0 :^)
2024-03-19 20:59:36 +01:00
Andreas Kling
cf60f52a78 LibWeb: Add DOM tree version counter
This patch adds a u64 version counter to DOM::Document that increments
whenever the tree structure changes (via node insertion or removal),
or an element attribute is changed somehow.

This will be used as a crude invalidation mechanism for HTMLCollection
to cache its elements.
2024-03-19 20:59:36 +01:00
Aliaksandr Kalenik
cf7c933312 LibWeb: Add fast path to calculate invalidations for animated css props
- Compare only the animated properties
- Clone only the hash map containing animated properties, instead of
  the entire StyleProperties.

Reduces `KeyframeEffect::update_style_properties()` from 10% to 3% in
GitHub profiles.
2024-03-19 17:30:34 +01:00