Commit graph

32441 commits

Author SHA1 Message Date
Nico Weber
21c54839e6 LibGfx/JBIG2: Add two dbgln_if()s 2024-03-16 09:21:42 -04:00
Nico Weber
b8f80501ec LibGfx/JBIG2: Pass Context to get_next_bit() instead of to initialize()
The context can vary for every bit we read.

This does not affect the one use in the test which reuses the same
context for all bits, but it is necessary for future changes.
2024-03-16 09:21:42 -04:00
Aliaksandr Kalenik
e0713376a0 LibWeb: Capture weak this ptr in HTMLTextAreaElement input callback
Fixes GC-leak caused by cycle dependency between input callback and
HTMLTextAreaElement that owns it.
2024-03-16 09:12:02 -04:00
Timothy Flynn
9eb38ce79c LibWeb: Update the <textarea> shadow DOM after reseting its form owner
This generally happens after a form is submitted. We need to update the
text node in the shadow DOM to actually display the reset value.
2024-03-16 13:11:57 +01:00
Timothy Flynn
c0d594568d LibWeb: Partially implement <textarea>'s selectionStart and selectionEnd
This implementation pretends we never have a selection. GitHub relies on
these values to know where to insert text corresponding to file uploads.
2024-03-16 13:11:57 +01:00
Timothy Flynn
abc1be5b9e LibWeb: Update the <textarea> shadow DOM when the value attribute is set
Otherwise, setting the value attribute after the element is added to the
DOM is not visibile. The logic here was stolen from the <input> element.
2024-03-16 13:11:57 +01:00
Timothy Flynn
2b6c00e8b9 LibWeb: Use the <textarea>'s API value, not its raw value, where needed
The API value of a <textarea> element is its raw value with normalized
newlines. This should be used in a couple of places where we currently
use the raw value.
2024-03-16 13:11:57 +01:00
Timothy Flynn
1c0541d706 LibWeb: Implement an AO to normalize newlines in a string 2024-03-16 13:11:57 +01:00
Timothy Flynn
324feb04e7 LibWeb: Fix spec link on <textarea>'s value setter 2024-03-16 13:11:57 +01:00
Aliaksandr Kalenik
a9b8840a82 LibWeb: Add fast path for animated style properties update
Patch up existing style properties instead of using the regular style
invalidation path, which requires rule matching for each element in the
invalidated subtree.

- !important properties: this change introduces a flag used to skip the
  update of animated properties overridden by !important.
- inherited animated properties: for now, these are invalidated by
  traversing animated element's subtree to propagate the update.
- StyleProperties has a separate array for animated properties that
  allows the removal animated properties after animation has ended,
  without requiring full style invalidation.
2024-03-16 09:49:40 +01:00
Aliaksandr Kalenik
dd07c7f729 LibWeb: Delete AnimationEffect::create() function
It should not be possible to create AnimationEffect because it is
an abstract interface according to the spec.
2024-03-16 09:49:40 +01:00
Timothy Flynn
764286676f Browser: Implement <input type=file> file type filtering 2024-03-16 08:42:33 +01:00
Timothy Flynn
feac88f3cb LibGUI: Add FileTypeFilter factories for common audio and video types 2024-03-16 08:42:33 +01:00
Timothy Flynn
1f44c9468a LibCore: Replace MIME type description lookup with a more generic method
Rather than adding a bunch of `get_*_from_mime_type` functions, add just
one to get the Core::MimeType instance. We will need multiple fields at
once in Browser.
2024-03-16 08:42:33 +01:00
Timothy Flynn
6760d236e4 Ladybird+LibWeb+WebContent: Parse the <input type=file> accept attribute
This parses the accept attribute value for file input types and passes
it along to the browser chromes.
2024-03-16 08:42:33 +01:00
Ali Mohammad Pur
0994aa91dc LibCrypto: Remove unused Crypto::PK::EMSA_PSS class
This is not used, and its implementation is not actually correct
regardless.
2024-03-16 01:17:02 -06:00
Ali Mohammad Pur
15836cc865 LibCrypto: Parse and store all RSA private key components 2024-03-16 01:17:02 -06:00
Ali Mohammad Pur
dc1180d6b2 LibCrypto: Use UnsignedBigInteger::is_odd() instead of manually checking
The previous implementation ignored "empty" bigints that represented
zero, leading to random crashes.
2024-03-16 01:17:02 -06:00
Ali Mohammad Pur
d451f84f31 LibCrypto: Add a minimal DER encoder
Progress towards #23562.
2024-03-16 01:17:02 -06:00
Sam Atkins
f00afa4a71 HexEditor: Avoid painting white rectangle on a white background
Most of the time, the background color for the hex and text areas will
be the widget's normal background color, so skip painting it in those
cases.
2024-03-15 08:37:21 +00:00
Sam Atkins
d4c051ece2 HexEditor: Add gaps between byte groups 2024-03-15 08:37:21 +00:00
Sam Atkins
4a2a40a3c8 HexEditor: Break bytes-per-row into numbers of groups of bytes 2024-03-15 08:37:21 +00:00
Ollrogge
c87e1084b6 LibELF: Prevent negative index when determining dynamic symbol count 2024-03-14 18:19:04 -06:00
Liav A.
a90e876667 Userland/mount: Fix srcobfuscate => srchidden when printing mounts
Fixes 0734de9f9a.
By mistake, I forgot to change this instance to "srchidden", so let's
fix this.
2024-03-14 18:18:39 -06:00
Nico Weber
df9dd8ec69 LibGfx/JBIG2: Add arithmetic coding decoder
I think the context normally changes for every bit. But this here
is enough to correctly decode the test bitstream in Annex H.2 in
the spec, which seems like a good checkpoint.

The internals of the decoder use spec naming, to make the code
look virtually identical to what's in the spec. (Even so, I managed
to put in several typos that took a while to track down.)
2024-03-14 18:18:15 -06:00
Andrew Kaster
1521a60a67 LibWeb: Support SubtleCrypto.exportKey for RSA-OAEP in JsonWebKey format 2024-03-14 17:57:37 -06:00
Andrew Kaster
2599142214 LibWeb: Export UnsignedBigInts into Uint8Arrays without losing bytes
The behavior of Crypto::UnsignedBigInt::export_data unexpectedly
does not actually remove leading zero bytes when the corresponding
parameter is passed. The caller must manually adjust for the location
of the zero bytes.
2024-03-14 17:57:37 -06:00
Andrew Kaster
0a3d27c41d LibWeb: Make SubtleCrypto AlgorithmParams classes virtual
This allows us to properly destroy the child classes through a pointer
to the base class, avoiding ASAN/UBSAN errors.
2024-03-14 17:57:37 -06:00
Lucas CHOLLET
06665cba9c LibGfx/TIFF: Reject images with an incoherent number of BitsPerSample
Fixes oss-fuzz issue 66588:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66588
2024-03-14 11:12:31 -04:00
Nico Weber
98729c97f4 LibGfx/JBIG2: Simplify and restrict adaptive template pixel reading
EXTTEMPLATE=1 was added later and doesn't seem to be used much in
practice -- it doesn't appear in no simple generic regions in any PDF
I tested so far at least. Since the spec contradicts itself on what
to do with these as far as I can tell, error out on them for now and
then add support once we find actual files using this, so that we can
check our implementation actually works.

Deduplicate the data reading for the different cases, and
zero-initialize all adaptive template pixels to zero to make that
possible.

Other than prohibiting EXTTEMPLATE=1, no behavior change.
2024-03-14 10:57:57 -04:00
Nico Weber
596b06333f LibGfx/JBIG2: Add a dbgln_if(JBIG2_DEBUG) for non-MMR generic regions 2024-03-14 10:57:57 -04:00
Andreas Kling
0c76c7ee36 LibWeb: Make Element::is_document_element() slightly nicer
By following the spec more closely, we can actually make this function
a bit more efficient (by comparing the parent against the document
instead of looking for the first element child of the document).
2024-03-14 12:42:08 +01:00
Andreas Kling
bbf67faa95 LibWeb: Add CSS rule buckets for pseudo elements, and for :root
If a selector must match a pseudo element, or must match the root
element, we now cache that information in the MatchingRule struct.
We also introduce separate buckets for these rules, so we can avoid
running them altogether if the current element can't possibly match.

This cuts the number of selectors evaluated by 32% when loading our
GitHub repo page https://github.com/SerenityOS/serenity
2024-03-14 12:42:08 +01:00
Andreas Kling
c6e37d0c44 LibWeb: Give Vector<MatchingRule> some inline capacity in StyleComputer
We frequently end up matching hundreds or even thousands of rules. By
giving this vector some inline capacity, we avoid a lot of the
repetitive churn from dynamically growing it all the way from 0
capacity.
2024-03-14 12:42:08 +01:00
Timothy Flynn
bc23c5b9fe LibWeb: Append the bytes of File objects in submitted form data
This is required to upload files to GitHub. Unfortunately, this is not
currently testable with our test infrastructure. This path is only hit
from HTTP/S uploads, whereas all of our tests are limited to file://.
2024-03-14 10:10:33 +01:00
Timothy Flynn
c0d18e976e LibWeb: Use string literals as format strings during form serialization
Passing a StringView bypasses compile-time format string validation.
2024-03-14 10:10:33 +01:00
Timothy Flynn
bb38cc1010 LibWeb: Do not blindly create File objects when adding FormData entries
We were unconditionally creating new File objects for all Blob-type
values passed to `FormData.append`. We should only do so if the value is
not already a File object (or if the `filename` attribute is present).

We must also carry MIME type information forward from the underlying
Blob object.
2024-03-14 10:10:33 +01:00
Timothy Flynn
f55471333b LibWeb: Set the MIME type when creating an <input> element's File list
We were passing the MIME type to the underlying Blob, but the factory
for creating a File only checks an explicit options structure.
2024-03-14 10:10:33 +01:00
Timothy Flynn
0cc8698a62 LibWeb: Reverse check for whether a FilesList index is supported
This fixes for..of iteration of a FilesList object.
2024-03-14 10:10:33 +01:00
Timothy Flynn
c2ef506b4a LibWeb: Add an empty DataTransfer IDL implementation
This does not implement any of the IDL methods, but GitHub requires the
interface exists to upload files via an <input type="file"> element.
Their JS handles uploads via this element and via drag-and-drop in one
function, and check if the uploaded file is `instanceof DataTransfer` to
decide how to handle it.
2024-03-14 10:10:33 +01:00
Timothy Flynn
7681772b9f LibWeb: Log failed Fetch responses when WEB_FETCH_DEBUG is enabled
We do the same for successful responses. Very useful for debugging
issues on live websites.
2024-03-14 10:10:33 +01:00
Cubic Love
15d6b3017a Snake: Set Snake as default skin
Set 'Snake' as the default skin for its aesthetic appeal and color
harmony with the game's icon.
2024-03-13 22:05:31 -06:00
Nico Weber
7740aeca29 LibGfx/JBIG2: Fix size bound in scan_for_immediate_generic_region_size()
The memmem() call passes `data.size() - 19 - sizeof(u32)` for big_len,
(18 prefix bytes skipped, the flag byte, and the trailing u32), so the
buffer needs to be at least that large.

Should fix https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=67332
2024-03-13 22:01:06 -06:00
Liav A
0734de9f9a Kernel+Userland: Add mount MS_SRCHIDDEN option
Either we mount from a loop device or other source, the user might want
to obfuscate the given source for security reasons, so this option will
ensure this will happen.
If passed during a mount, the source will be hidden when reading from
the /sys/kernel/df node.
2024-03-13 15:33:47 -06:00
Liav A
0739b5df11 Utilities/mount: Automatically mount regular files with loop devices
Check if the source fd is not a block device file using the fstat
syscall and if that's the case, try to mount the file using a temporary
loop device.
2024-03-13 15:33:47 -06:00
Liav A
d14a0a454a SystemServer: Mount DevLoopFS on /dev/loop
Let's use the new DevLoopFS filesystem on /dev/loop to see the loop
devices immediately as they're created or deleted.
2024-03-13 15:33:47 -06:00
Andrew Kaster
a9d240c647 LibWeb: Implement SubtleCrypto.generateKey for RSA-OAEP
This patch implements and tests window.crypto.sublte.generateKey with
an RSA-OAEP algorithm. In order for the types to be happy, the
KeyAlgorithms objects are moved to their own .h/.cpp pair, and the new
KeyAlgorithms for RSA are added there.
2024-03-13 15:31:00 -06:00
Andrew Kaster
008c89edde LibCrypto: Add observers for the *byte* length of UnsignedBigInteger
When calling the export_data method, it's a bit of a hassle to remember
that the caller's buffer needs to be the length() * Word.
2024-03-13 15:31:00 -06:00
Andrew Kaster
139ff3552c LibCrypto: Allow callers to pass exponent to RSA::generate_key_pair 2024-03-13 15:31:00 -06:00
Andrew Kaster
0b4858e589 LibWeb: Implement SubtleCrypto.generateKey skeleton
We don't have any algorithms defined that actually support generateKey,
but now all the scaffolding is there.
2024-03-13 15:31:00 -06:00
Andrew Kaster
810be6af07 LibWeb: Add CryptoKeyPair object for use in upcoming SubtleCrypto APIs 2024-03-13 15:31:00 -06:00
Andrew Kaster
0a6f195a71 LibWeb: Implement usages property for CryptoKey
And set it from the only place we currently create a CryptoKey, in
importKey.
2024-03-13 15:31:00 -06:00
Andrew Kaster
2d59d6c98c LibWeb: Refactor SubtleCrypto to allow adding more algorithms easier
This patch throws away some of the spec suggestions for how to implement
the normalize_algorithm AO and uses a new pattern that we can actually
extend in our C++.

Also update CryptoKey to store the key data.
2024-03-13 15:31:00 -06:00
Timothy Flynn
644e764620 RequestServer: Use Core::System::pipe2 for creating the request FDs
This causes a behavior change in which the read FD is now non-blocking.
This is intentional, as this change avoids a deadlock between RS and
WebContent, where WC could block while reading from the request FD,
while RS is blocked sending a message to WC.
2024-03-13 12:52:07 -04:00
Timothy Flynn
a973fe13cb LibCore: Use Core::System::pipe2 for creating the event loops waking FDs 2024-03-13 12:52:07 -04:00
Timothy Flynn
40beebca71 LibCore: Apply the flags provided to System::pipe2 on all systems
We currently drop the flags on the floor for systems that do not have a
pipe2 syscall. Instead, use fcntl to set the flags.
2024-03-13 12:52:07 -04:00
Timothy Flynn
dd271adcf5 RequestServer: Do not defer establishing a TCP/TLS connection
The underlying issue here isn't quite understood yet, but for some
reason, when we defer this connection, we ultimately end up blocking
indefinitely on macOS when a subsequent StartRequest message tries to
send its request FD over IPC. We should continue investigating that
issue, but for now, this lets us use RequestServer more reliably on
macOS.
2024-03-13 12:52:07 -04:00
Andreas Kling
72e6581585 LibWeb: Store copy of MutationObserver set in a MarkedVector
While iterating over MutationObservers in the microtask callback, we
need to keep them in a MarkedVector to ensure they don't get GC'd.
2024-03-13 09:41:55 +01:00
Tim Ledbetter
fc1f037cd1 LibWeb: Implement the window.opener attribute
This returns a reference to the window that opened the current window.
2024-03-13 08:06:00 +00:00
MacDue
4c15c87d0c LibGfx/TinyVG: Fix decoding green channel of graphics RGB565 colors
The division was missed here, so this would produce overly bright greens
(or overflow).
2024-03-12 21:53:23 +00:00
MacDue
633f0067c1 LibGfx: Remove suspicious const& in TinyVGLoader
`decode_color_table()` returns a vector by value (not reference), so
assigning it to a const reference (while legal), seems odd.
2024-03-12 21:53:23 +00:00
Aliaksandr Kalenik
bf11f4f73f LibWeb: Visit m_when_defined_promise_map in CustomElementRegistry 2024-03-12 18:18:10 +01:00
Aliaksandr Kalenik
90112468ac LibWeb: Visit custom element definitions in CustomElementRegistry 2024-03-12 18:18:10 +01:00
Aliaksandr Kalenik
bf8bbea209 LibWeb: Visit constructor callback in CustomElementDefinition 2024-03-12 18:18:10 +01:00
Aliaksandr Kalenik
3b4230e0b0 LibWeb: Visit custom element's lifecycle callbacks
...instead of using JS::Handle which causes leaks when object holding
the callback can be reached by visiting the callback's dependencies.
2024-03-12 18:18:10 +01:00
Ali Mohammad Pur
5a40ce442b LibWasm: Remove uses of AK::Result
Closes #23500.
2024-03-12 17:10:47 +01:00
Ali Mohammad Pur
8003bde03d AK+LibRegex+LibWasm: Remove the non-const COWVector::operator[]
This was copying the vector behind our backs, let's remove it and make
the copying explicit by putting it behind COWVector::mutable_at().
This is a further 64% performance improvement on Wasm validation.
2024-03-12 17:10:47 +01:00
Ali Mohammad Pur
cced555879 LibWasm: Avoid pointless vector copies in Validator::Context
These vector copies accounted for more than 50% of the current runtime
of the validator on a large wasm file, this commit makes them
copy-on-write to avoid the copies where possible, gaining nearly a 50%
speedup.
2024-03-12 17:10:47 +01:00
Ali Mohammad Pur
cefe177a56 AK+LibRegex: Move COWVector to AK
This is about to gain a new user, so move it to AK.
2024-03-12 17:10:47 +01:00
Andreas Kling
bbb96d65b1 LibWeb: Don't crash on live range offset update during node insertion
When inserting a node into a parent, any live DOM ranges that reference
the parent may need to be updated. The spec does this by increasing or
decreasing the start/end offsets of each live range *before* actually
performing the insertion.

This caused us to crash with a verification failure, since it was
possible to set the range offset to an invalid value (that would go on
to immediately become valid after the insertion was finished).

This patch fixes the issue by adding special badged helpers on Range for
Node to reach into it and increase/decrease the offsets during node
insertion. This skips the offset validity check and actually makes our
code read slightly more like the spec.

Found by Domato :^)
2024-03-12 16:30:39 +01:00
Andreas Kling
43d2c920e0 LibWeb: Ignore MessagePort.start() on already-closed port
This matches other browsers, and fixes an assertion found by Domato.
2024-03-12 16:30:39 +01:00
Andreas Kling
c11f710628 LibWeb: Fix bogus insertion logic in HTMLTableSectionElement.insertRow()
Found by Domato :^)
2024-03-12 16:30:39 +01:00
Tim Ledbetter
7625d8a155 LibWeb: Implement AbortSignal.any()
This method takes a list of AbortSignals and returns an AbortSignal
that is aborted when any of the input signals is aborted.
2024-03-12 09:31:41 +01:00
Tim Ledbetter
9eaae99da7 LibIDL: Ignore leading underscores in IDL identifier names
According to the WebIDL specification, any leading underscores in
identifier names are ignored. A leading underscore is used when an
identifier would otherwise be a reserved word.
2024-03-12 09:31:41 +01:00
Tim Ledbetter
130f28cf50 LibWeb: Mark abort event as trusted before dispatching it
This matches the behavior of Firefox and Chrome.
2024-03-12 09:31:41 +01:00
Cubic Love
3bec616893 Base+ImageViewer: Add new icons for ImageViewer
Add ImageViewer application icons (16 and 32px) and matching image
filetype icons.
2024-03-12 08:08:19 +00:00
MacDue
163b6bb401 LibWeb: Special case SVG masks during layout
Rather than try to lay out masks normally, this updates the TreeBuilder
to create layout nodes for masks as a child of their user (i.e. the
masked element). This allows each use of a mask to be laid out
differently, which makes supporting `maskContentUnits=objectBoundingBox`
fairly easy.

The `SVGFormattingContext` is then updated to lay out masks last (as
their sizing may depend on their parent), and treats them like
viewports.

This is pretty ad-hoc, but the SVG specification does not give any
guidance on how to actually implement this.
2024-03-12 08:51:50 +01:00
MacDue
15e3b0ebde LibWeb: Use SVGGraphicsBox for <symbol> and <use> elements
This allows various SVG properties (like masking) to be applied to these
elements.
2024-03-12 08:51:50 +01:00
MacDue
05f42efc06 LibWeb: Support preserveAspectRatio=none for SVGs
This is very easy now all transforms are computed during layout.
2024-03-12 08:51:50 +01:00
mobounya
190a8f948e LibWeb: Don't crash when visiting about:srcdoc
When navigating to about:srcdoc we try to populate the session history
by calling populate_session_history_entry_document, if the resource is
an about:srcdoc this method will rely on the document_resource in the
SessionHistoryEntry to have a String in order for it call the right
method to create navigation params.

However when navigating to about:srcdoc directly, document_resource
will have an Empty, this leads populate_session_history_entry_document
to call the wrong method to create navigation params.

This fixes the issue by populating document_resource with an empty
string if it has an Empty and we're dealing with an about:srcdoc.

Issue: #23216
2024-03-12 00:11:57 -06:00
Andreas Kling
9aefc5c927 LibWeb: Return a dummy value from various SVG getters
Instead of crashing with a TODO() on half of the test cases generated by
Domato, let's just return a zeroed-out SVGAnimatedLength or
SVGAnimatedNumber from getters that return them.

We'll eventually have to implement these correctly, but crashing is not
productive since it blocks us from finding other issues.
2024-03-11 18:29:10 +01:00
Andreas Kling
35f359c51c LibWeb: Fix infinite loop in ChildNode's before() and after()
The loop that was supposed to check the chain of previous or next
siblings had a logic mistake where it would never traverse the chain,
so we would get stuck looking at the immediate sibling forever.
2024-03-11 18:29:10 +01:00
Andreas Kling
ad843b6e4a LibWeb: Don't crash when accessing property in detached Window object
After removing an iframe from the DOM, its contentWindow will be
detached from its browsing context, per spec.

Because the contentWindow is still accessible, we cannot assume that
Window objects always have an associated browsing context.

This needs to be fixed in the spec, but let's add a sensible null check
in the meantime.
2024-03-11 18:29:10 +01:00
Andreas Kling
2e0297d703 LibWeb: Handle reference cycles in SVG gradient linking
Since SVG gradients can reference each other, we have to keep track of
visited gradients when traversing the link chain, or we will recurse
infinitely when there's a reference cycle.
2024-03-11 18:29:10 +01:00
Andreas Kling
1b8d8c7bbc LibWeb: Make a Layout::BlockContainer for MathML boxes
Instead of creating a generic Layout::Box, make a BlockContainer. This
allows them to be laid out by BFC, which is better than nothing(?),
even if it's not going to be correct at all.
2024-03-11 18:29:10 +01:00
Andreas Kling
3591a82e8d LibWeb: Look at paintable directly in Element::scroll* APIs
We don't need to go via the layout tree as the element has a link
directly to its paintable where the relevant metrics are stored.
2024-03-11 18:29:10 +01:00
Andreas Kling
b98a2be96b LibWeb: Ignore window-forwarded document.body.onfoo in detached DOM
Normally, assigning to e.g document.body.onload will forward to
window.onload. However, in a detached DOM tree, there is no associated
window, so we have nowhere to forward to, making this a no-op.

The bulk of this change is making Document::window() return a nullable
pointer, as documents created by DOMParser or DOMImplementation do not
have an associated window object, and so must be able to return null
from here.
2024-03-11 18:29:10 +01:00
Andreas Kling
7139d5945f LibWeb: Use NonnullGCPtr in EventTarget's event handler map
Null entries are not valid, so let's not allow them.
2024-03-11 18:29:10 +01:00
Andreas Kling
99ca2ccf08 LibWeb: Make DOMImplementation.createHTMLDocument() create HTMLDocument
Prior to this change, this API would actually create an XML Document(!)
2024-03-11 18:29:10 +01:00
Andreas Kling
b9bacb3ff4 LibWeb: Don't assume HTMLTableCellElement always has table ancestor
That's not actually a DOM invariant, just something the HTML parser
refuses to build. You can still construct table-less th and td elements
using the DOM API.
2024-03-11 18:29:10 +01:00
Nico Weber
bc42144642 LibGfx/JBIG2: Start implementing the generic region decoding procedure
If the "MMR" bit is set, the generic region decoding procedure just
uses ITU-T T.6 (2D CCITT), which we already have an implementation of.
In practice, this is used almost never in .jbig2 files and in none of
the PDFs I have.

The two files that do use MMR are:

1.) JBIG2_ConformanceData-A20180829/F01_200_TT9.jb2
2) 042_3.jb2 from the ghostpdl tests

The first uses an immediate _lossless_ generic region, which we don't
implement yet (but I think it should just forward to the normal
immediate generic region code? Not in this commit, though). The second
uses a regular immediate generic region, and we can decode it now:

    Build/lagom/bin/image -o out.png \
        path/to/ghostpdl/tests/jbig2/042_3.jb2
2024-03-11 16:48:57 +01:00
Nico Weber
e0af3ae8d9 LibGfx/JBIG2: Implement decode_end_of_file() 2024-03-11 16:48:57 +01:00
Nico Weber
323cacc593 LibGfx/JBIG2: Implement decode_end_of_page() 2024-03-11 16:48:57 +01:00
Aliaksandr Kalenik
ecce570cb7 LibWeb: Stop animation driver timer after document becomes inactive 2024-03-11 16:44:05 +01:00
Aliaksandr Kalenik
fd63ffb8c3 LibWeb: Use Core::Timer instead for animation driver timer
Platform::Timer uses JS::SafeFunction that prevents document from ever
being deallocated because of strong reference.
2024-03-11 16:44:05 +01:00
Aliaksandr Kalenik
2129c5d8b0 LibWeb: Unregister AnimationTimeline from document in finalize()
...instead of destructor because by the time it is executed, document
could already be destroyed.
2024-03-11 16:44:05 +01:00
Aliaksandr Kalenik
bcdf4a375d LibWeb: Use resolve_grid_position for abspos boxes layout in GFC
Removes duplicated code that resolves position based on computed
values.

No behaviour change intended.
2024-03-11 15:20:58 +01:00
Bastiaan van der Plaat
bd86beb7e4 Maps: Add FavoritesModel and remove hacky misusage of JSONArrayModel 2024-03-11 10:40:23 +00:00
Bastiaan van der Plaat
29026ce965 Maps: Move TileProviders.json to user independent folder 2024-03-11 10:40:23 +00:00
implicitfield
5da9f52b1f LibWeb: Use the parent container's y offset when finding static position
Fixes #18819.
2024-03-10 18:10:01 +01:00
Lucas CHOLLET
2b8594dc85 LibGfx: Replace FLATTEN with ALWAYS_INLINE for draw_glyph() overload
While IMO, the change makes sense on its own as flattening this function
will just duplicate the code from `draw_glyph()` with no benefits, this
is not what motivated this patch.

When compiling with debug information and ASAN, GCC 13.2 would issue
this warning:

Userland/Libraries/LibGfx/Painter.cpp: In member function ‘void Gfx::Pai
nter::draw_glyph(Gfx::FloatPoint, u32, Gfx::Color)’:
Userland/Libraries/LibGfx/Painter.cpp:1354:14: note: variable tracking s
ize limit exceeded with ‘-fvar-tracking-assignments’, retrying without
 1354 | FLATTEN void Painter::draw_glyph(FloatPoint point, u32 code_poin
t, Color color)
      |              ^~~~~~~

From what I've read online, this is caused by some limit on the number
of symbols in the compiler's internal data structures. People at Google
have fixed this warning by splitting functions:
https://codereview.chromium.org/1164893003

While getting us rid of the warning, it also drastically improves
compilation time. Going from 1min27 to 59s on my machine.
2024-03-10 10:18:36 -04:00
Matthew Olsson
e91f4dcd79 LibWeb: Use Performance for animation time instead of MonotonicTime
Performance handles the document origin time correctly, and prevents
these times from being unusually large. Also initialize the
DocumentTimeline time in the constructor, since these can be created
from JS.
2024-03-10 15:13:47 +01:00
Nico Weber
bdbc21c52d LibGfx/JBIG2: Implement conversion to Gfx::Bitmap and ByteBuffer
With this, `image` can convert any jbig2 file, as long as it's
black (or white), and LibPDF can draw jbig2 files (again, as long
as they only contain a single color stored in just a
PageInformation segment).
2024-03-10 10:10:55 -04:00
Nico Weber
be9a6caa0a LibPDF: In Filter::decode_jbig2(), invert bits
See included comment.
2024-03-10 10:10:55 -04:00
Nico Weber
54982857bd LibGfx/JBIG2: Implement decode_page_information()
Also make scan_for_page_size() not early return, so that it has the
same behavior as the main decoding look. (Multiple page information
segments for a single page are likely invalid and don't happen in
practice, so this is mostly an academic change.)

Add a BitBuffer class to store the bit image data, and introduce a
Page struct for storing data associated with a page. We currently
only handle a single page, but a) this makes it easier to decode
multiple pages in the future if we want b) it makes the code easier
to understand.
2024-03-10 10:10:55 -04:00
Nico Weber
4b01f2f158 LibGfx/JBIG2: Implement decode_extension()
Only logs the data to dbgln().

All jb2 files in ghostpdl/tests start with this segment.
2024-03-10 10:10:55 -04:00
Nico Weber
9cd0c5658e LibGfx/JBIG2: Reject files with delayed height information for now
7.4.8.2 Page bitmap height:
"In some cases, this value may not be known at the time that the page
information segment is written. In this case, this field must contain
0xFFFFFFFF, and the actual page height may be communicated later, once
it is known."
2024-03-10 10:10:55 -04:00
Nico Weber
f592a2ac72 LibPDF/JBIG2: Print a warning on files with more than one page 2024-03-10 10:10:55 -04:00
Nico Weber
2caf603836 LibGfx/JBIG2: Add scaffolding for interpreting segment data 2024-03-10 10:10:55 -04:00
Nico Weber
af20ebe4a0 LibGfx/JBIG2: Scan for page size of page "1"
Sounds like the spec guarantees that that's the number of the first
page.

(In practice, all but one of all jbig2 files I've found contain just
page 1. PDFs almost always contain just page 1, and very rarely a
page 0 for globally shared parameters.)
2024-03-10 10:10:55 -04:00
Timothy Flynn
842caf5e8c LibWeb: Do not shrink the CPU painter's corner clipping vector
If the provided ID is smaller than the corner clipping vector, we would
shrink the vector to match. This causes a crash when we have nested
PaintContext instances (as these IDs are allocated by PaintContext),
each of which perform radius painting.

This is seen on https://www.strava.com/login when it loads a reCAPTCHA.
The outer div has a border radius, which contains the reCAPTCHA in an
iframe. That iframe contains an SVG which also has a border radius.
2024-03-10 00:39:49 +01:00
Aliaksandr Kalenik
33294aea86 LibWeb: Apply shadow root style sheets in StyleComputer
Now, if an element belongs to a shadow tree, we use only the style
sheets from the corresponding shadow root during style computation,
instead of using all available style sheets as was the case
previously.

The only exception is the user agent style sheets, which are still
taken into account for all elements.

Tests/LibWeb/Layout/input/input-element-with-display-inline.html
is affected because style of document no longer affects shadow tree
of input element, like it is supposed to be.

Co-authored-by: Simon Wanner <simon+git@skyrising.xyz>
2024-03-09 16:13:32 +01:00
Aliaksandr Kalenik
91ec1d6f95 LibWeb: Maintain list of allocated shadow roots in Document
Doing that will allow us to get a list of style sheets for each shadow
root from StyleComputer without having to traverse the entire tree in
upcoming changes.
2024-03-09 16:13:32 +01:00
Aliaksandr Kalenik
c6e69d501f LibWeb: Add style sheets to the shadow root if applicable
If a style element belongs to a shadow tree, its CSSStyleSheet is now
added to the corresponding ShadowRoot instead of the document.

Co-authored-by: Simon Wanner <simon+git@skyrising.xyz>
2024-03-09 16:13:32 +01:00
Aliaksandr Kalenik
8ce8697a66 LibWeb: Add styleSheets and adoptedStyleSheets attributes in ShadowRoot
Co-authored-by: Simon Wanner <simon+git@skyrising.xyz>
2024-03-09 16:13:32 +01:00
Aliaksandr Kalenik
f19c92d78e LibWeb: Add ObservableArray::for_each() 2024-03-09 16:13:32 +01:00
implicitfield
54d8e58a68 LibWeb: Account for margin and padding of justified abspos flex items 2024-03-09 16:02:17 +01:00
implicitfield
3888a91c5b LibWeb: Account for margin and padding of aligned abspos flex items
This patch also makes FlexFormattingContext::calculate_static_position
use computed values for margins and borders, since this function may be
called before the box's state has been finalized.
2024-03-09 16:02:17 +01:00
implicitfield
e3b1d4a141 LibWeb: Compute content width before static position for abspos elements
In some scenarios, correctly computing the static position may depend on
the content width having been calculated beforehand.
2024-03-09 16:02:17 +01:00
implicitfield
18fe86adc3 LibWeb: Add support for the inline-size CSS property 2024-03-09 16:02:17 +01:00
Nico Weber
dd593d16c4 Fuzzers: Add JBIG2 fuzzer 2024-03-09 16:01:22 +01:00
Nico Weber
8f4930f2df LibGfx/JBIG2: Scan for the first PageInformation segment and decode it
This allows `file` to correctly print the dimensions of a .jbig2 file,
and it allows us to write a test that covers much of all the code
written so far.
2024-03-09 16:01:22 +01:00
Nico Weber
1eaaa8c3e9 LibPDF+LibGfx: Support JBIG2s with /JBIG2Globals set
Several ramifications:

* /JBIG2Globals is an indirect reference, which means we now need
  a Document for unfiltering. (Technically, other decode parameters
  can also be indirect objects and we should use the Document to
  resolve() those too, but in practice it only seems to be needed
  for /JBIG2Globals.)

* Since /JBIG2Globals are so rare, we just parse once for each
  image that use them, and decode_embedded() now receives a
  Vector<ReadonlyBytes> with all sections of sequences of
  segments.

* Internally, decode_segment_headers() is now called several times
  for embedded JBIG2s with multiple such sections (e.g. PDFs with
  /JBIG2Globals).

* That means `data` is now no longer part of JBIG2LoadingContext
  and things get slightly reshuffled due to this.

This completes the LibPDF part of JBIG2 support. Once LibGfx
implements actual decoding of JBIG2s, things should start to
Just Work in PDFs.
2024-03-09 16:01:22 +01:00
Nico Weber
09ca66cb8b LibGfx/JBIG2: Scan for end of immediate generic regions of unknown size
Found e.g. in 0000033.pdf (both pages).
2024-03-09 16:01:22 +01:00
Nico Weber
379ef45688 LibGfx/JBIG2: Store location of segment data bodies
They're in different places for Sequential/Embedded (right after
the header) and RandomAccess (which has all headers first, followed
by all data bits next).

We don't do anything with the data yet, but now everything's in
place to actually process segment data.
2024-03-09 16:01:22 +01:00
Nico Weber
953f6c5d9b LibPDF+LibGfx: Pass jbig2-filtered data to JBIG2ImageDecoderPlugin
Except for /JBIG2Globals, which we bail out on for now. In my 1000
files, 13 use JBIG2, and of those, 2 use JBIG2Globals (0000372.pdf e.g.
page 11 and 0000857.pdf e.g. page 1), and only one (the latter) of the
two uses the same JBIG2Globals stream for more than a single image.

JBIG2ImageDecoderPlugin cannot decode the data yet, so no behavior
change, but with `#define JBIG2_DEBUG 1` at the top of that file,
it now prints segment header info for PDFs containing JBIG2 data :^)
2024-03-09 16:01:22 +01:00
Nico Weber
b1fdc33a22 LibGfx/JBIG2: Decode all segment headers
With `#define JBIG2_DEBUG 1` at the top of the file:

    % Build/lagom/bin/image --no-output \
       .../JBIG2_ConformanceData-A20180829/F01_200_TT10.jb2
    JBIG2LoadingContext: Organization: 0 (Sequential)
    JBIG2LoadingContext: Number of pages: 1
    Segment number: 0
    Segment type: 48
    Referred to segment count: 0
    Segment page association: 1
    Segment data length: 19
    Segment number: 1
    Segment type: 39
    Referred to segment count: 0
    Segment page association: 1
    Segment data length: 12666
    Segment number: 2
    Segment type: 49
    Referred to segment count: 0
    Segment page association: 1
    Segment data length: 0
    Runtime error: JBIG2ImageDecoderPlugin: Draw the rest of the owl
2024-03-09 16:01:22 +01:00
Nico Weber
177664cfae LibGfx/JBIG2: Add an initial decode_segment_header()
With `#define JBIG2_DEBUG 1` at the top of the file:

    % Build/lagom/bin/image --no-output \
        .../JBIG2_ConformanceData-A20180829/F01_200_TT10.jb2
    JBIG2LoadingContext: Organization: 0 (Sequential)
    JBIG2LoadingContext: Number of pages: 1
    Segment number: 0
    Segment type: 48
    Referred to segment count: 0
    Segment page association: 1
    Segment data length: 19
    Runtime error: JBIG2ImageDecoderPlugin: Draw the rest of the owl
2024-03-09 16:01:22 +01:00
Nico Weber
5cefcad2fe LibGfx/JBIG2: Decode the file header
Running `image` with `#define JBIG2_DEBUG 1` now prints number of pages.
2024-03-09 16:01:22 +01:00
Nico Weber
58838db445 LibGfx: Add the start of a JBIG2 loader
JBIG2 is infamous for two things:

1. It's used in xerox scanners were it falsifies scanned numbers:

https://www.dkriesel.com/en/blog/2013/0802_xerox-workcentres_are_switching_written_numbers_when_scanning

2. It was allegedly used in an iOS zero day, in a very cool way:

https://googleprojectzero.blogspot.com/2021/12/a-deep-dive-into-nso-zero-click.html

Needless to say, we need support for it in Serenity. (...because it's
used in PDF files.)

This adds all the scaffolding, but no actual implementation yet.

It's enough for `file` to print the mime type of .jb2 files, but `image`
can't do anything with the files yet.
2024-03-09 16:01:22 +01:00
Matthew Olsson
d76c2d45c4 LibWeb: Remove scopes for execution contexts in Animation finish steps 2024-03-09 15:34:27 +01:00
Matthew Olsson
fc6a6d29ec LibWeb: Ensure m_is_finished is false after cancelling Animation 2024-03-09 15:34:27 +01:00
Matthew Olsson
e11b9658ed LibWeb: Disassociate animations from Animatables when setting effects 2024-03-09 15:34:27 +01:00
Matthew Olsson
90290eb985 LibWeb: Store Animations in Animatable instead of AnimationEffects
This is closer to what the spec instructs us to do, and matches how
associations are maintained in the timelines. Also note that the removed
destructor logic is not necessary since we visit the associated
animations anyways.
2024-03-09 15:34:27 +01:00
Matthew Olsson
f386c01ae1 LibWeb: Use the correct start time when pausing/playing animations 2024-03-09 15:34:27 +01:00
Matthew Olsson
24ec5838ba LibWeb: Visit Animatable::m_associated_effects 2024-03-09 15:34:27 +01:00
Timothy Flynn
2a021a35fc LibGUI: Consider carriage returns when counting lines in a label
We create labels in the Browser from text on web documents, which may
use carriage returns. LibGfx will split lines on CR already, but LibGUI
would not consider CRs when computing the height of the containing
widget. The result was text that would not fit in the label's box.
2024-03-08 14:43:33 -05:00
Timothy Flynn
07a27b2ec0 AK: Replace the boolean parameter of StringView::lines with a named enum 2024-03-08 14:43:33 -05:00
Timothy Flynn
d9349f1510 LibGfx: Treat "\r\n" as a single line break during text layout
We currently insert two line breaks for this sequence. This Windows-
style of line breaking can be seen in documents on the web.
2024-03-08 14:43:33 -05:00
Sam Atkins
4bdb7dba8c LibWeb: Add and use a helper to reject a promise with an exception 2024-03-08 14:14:57 -05:00
Nico Weber
24951a039e LibPDF: Clip stroke for B / B* operators
Fixes pages 17-19 on
https://www.iro.umontreal.ca/~feeley/papers/ChevalierBoisvertFeeleyECOOP15.pdf

Calling the fill handler after painting the stroke as previously doesn't
work, since we need to set up the clip before both stroke and fill, and
unset it after both. The duplication is a bit unfortunate, but also
minor.
2024-03-08 10:45:28 -05:00
Aliaksandr Kalenik
7c322ec710 LibWeb: Implement adoptedStyleSheets attribute for Document
https://drafts.csswg.org/cssom/#dom-documentorshadowroot-adoptedstylesheets

The attribute implementation for ShadowRoot is currently missing
because we do not yet distinguish between the style sheets of
ShadowRoot and Document, and we need to address the issue first.
2024-03-08 16:31:21 +01:00
Aliaksandr Kalenik
fceba6a257 LibWeb/WebIDL: Introduce ObservableArray
ObservableArray inherits from JS::Array and overrides `internal_set`
and `internal_delete` to run an interceptor callback when an indexed
item is added or deleted.
2024-03-08 16:31:21 +01:00
Nico Weber
75a8d37c99 LibGfx: Make mime-based image loaders not throw away their error either
Small follow-up to #23489.
2024-03-08 08:38:31 +01:00
Nico Weber
8ec6dad449 LibGfx/TGA: Move a variable closer to its use
No behavior change.
2024-03-08 08:38:31 +01:00
Nico Weber
6607757b08 LibGfx: Make validate_before_create() create a regular bool
This is for validating that a decoder with a weak or nonexistent
sniff() method thinks it can decode an image. This should not be
treated as an error.

No behavior change.
2024-03-08 08:38:31 +01:00
Bastiaan van der Plaat
69e4f924b7 LibWeb: Add element adjust_computed_style and move set_property() to it 2024-03-08 08:38:18 +01:00
Timothy Flynn
928287b782 LibCrypto: Store ASN1 certificate timestamps as UnixDateTime
We are currently using Core::DateTime, which is meant to represent local
time. However, we are doing no conversion between the parsed time in UTC
and local time, so we end up comparing time stamps from different time
zones.

Instead, store the parsed times as UnixDateTime, which is UTC. Then we
can always compare the parsed times against the current UTC time.

This also lets us store parsed milliseconds.
2024-03-08 00:41:23 +01:00
Sam Atkins
da118f2adf HackStudio: Enable permissive mode for Config access
Displaying a GML preview in HackStudio seems to be broken at the moment,
but this change will be needed once it does work again, so might as well
make it now, while I'm aware of the issue.
2024-03-07 17:49:01 -05:00
Sam Atkins
e8a803ca5d GMLPlayground: Enable permissive mode for Config access
Instead of having to list any Config domains that may be used by a
Widget, let accessing those domains be a no-op.
2024-03-07 17:49:01 -05:00
Sam Atkins
5bcb3e2f16 LibConfig+ConfigServer: Add permissive mode
When in permissive mode, the ConfigServer will not treat reads and
writes to non-pledged domains as errors, but instead turns them into
no-ops: Reads will act as if the key was not found, and writes will do
nothing. Permissive mode must be enabled before pledging any domains.

This is needed to make GUI Widgets nicer to work with in GML Playground:
a few Widgets include reads and writes to LibConfig in order to load
system settings (eg, GUI::Calendar) or to save and restore state
(eg, GUI::DynamicWidgetContainer). Without this change, editing a
layout that includes one of these Widgets will cause GML Playground to
crash when they try to access config domains that are not pledged.

The solution used previously is to make Playground pledge more domains,
but not only does this mean Playground has to know about these cases,
but also that working on a layout file can alter the user's settings in
other arbitrary apps, which is not something we want.

By simply ignoring these config accesses, we avoid those downsides, and
Widgets will simply use the fallback values they already have to provide
to Config::read_foo_value().
2024-03-07 17:49:01 -05:00
Lucas CHOLLET
0e20d51b0e LibGfx: Prevent overflow when creating CMYKBitmaps
Fixes oss-fuzz issue 66629.
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66629
2024-03-07 11:32:57 -05:00
Lucas CHOLLET
40cf205c81 LibGfx/TIFF: Reject images with a null value in tile's dimensions
Fixes oss-fuzz issue 66844.
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66844&sort=-opened&q=proj%3Aserenity%20TIFF&can=1
2024-03-07 11:31:38 -05:00
Nico Weber
3a39939995 LibPDF: Make truetype fonts marked as symbol fonts actually work
Turns out the spec didn't mean that the whole range is populated,
but that one of these ranges is populated. So take the argmax.

As fallout, explicitly mark the Liberation fonts as nonsymbolic
when we use them for the 14 standard fonts. Else, we'd regress
"PostScrõpt", since the Liberation fonts would otherwise go down
the "is symbolic or doesn't have explicit encoding" codepath,
since the standard fonts usually don't have an explicit encoding.

As a fallout from _that_, since the 14 standard fonts now go down
the regular truetype rendering path, and since we don't implement
lookup by postscript name yet, glyphs not present in Liberation
now cause text to stop rendering with a diag, instead of rendering
a "glyph not found" symbol. That isn't super common, only an
additional 4 files appear for the "'post' table not yet implemented"
diag. Since we'll implement that soon, this seems fine until then.
2024-03-07 11:29:47 -05:00
Nico Weber
2e2cae26c6 LibGfx+Fallout: Make ImageDecoder return ErrorOr
...from try_create_for_raw_bytes().

If a plugin returns `true` from sniff but then fails when calling
its `create()` method, we now no longer swallow that error.

Allows `image` (and other places in the system) to print a more
actionable error if early image headers are invalid.

(We now no longer try to find another plugin that can also handle
the image.)

Fixes a regression from #20063 / #19893 -- before then, we didn't
do fallible work this early.
2024-03-07 11:20:06 -05:00
Lucas CHOLLET
be5e7a360f LibGfx/CCITT: Add support for images with an unknown number of lines 2024-03-07 11:07:20 -05:00
Lucas CHOLLET
cefb2d65d8 LibGfx/CCITT: Always accept the end of line as the next changing element 2024-03-07 11:07:20 -05:00
Lucas CHOLLET
780e230af5 LibGfx/CCITT: Don't use change's color to set current_color
No behavior change, `to_encode` always receive a `Change` with a
different color.
2024-03-07 11:07:20 -05:00
Bastiaan van der Plaat
110e74b9c1 LibWeb: Move textarea cols rows attr size from css to create_layout_node 2024-03-07 10:38:17 +00:00
Bastiaan van der Plaat
7e76358a99 LibWeb: Move input size attr width from css to create_layout_node 2024-03-07 10:38:17 +00:00
Aliaksandr Kalenik
749dcac196 LibWeb: Add record_grid_placement() helper in GFC
When placement position is found we always want to do following:
- Mark the occupied cells in the occupation grid
- Add the item to the list of placed items

Therefore, having helper that does both is useful
2024-03-07 08:26:37 +01:00
Aliaksandr Kalenik
2a3891781c LibWeb: Delete is_auto_positioned_row{column} in GFC
Use is_auto_positioned_track() instead.
2024-03-07 08:26:37 +01:00
Aliaksandr Kalenik
1fbd9674b4 LibWeb: Use resolve_grid_position if row and column are definite in GFC
With this change we use the same code to resolve (start, end, span)
based on computed values in all cases:
- When only column is definite
- When only row is definite
- When both are definite
2024-03-07 08:26:37 +01:00
Aliaksandr Kalenik
8695a82c56 LibWeb: Extract common path in definite row/column placement in GFC
Moves the code that identifies (start, end, span) for a grid item into
a separate function. By doing so, we can eliminate the duplicated code
between the placement of grid items with definite columns and those
with definite rows.

This change omits some of the comments that reference the spec, as they
were largely irrelevant and unhelpful for making changes or diagnosing
issues.
2024-03-07 08:26:37 +01:00
implicitfield
0243278587 LibWeb: Account for absolutely positioned table wrappers
Table wrappers don't quite behave the same as most elements, in that
their computed height and width are not meant to be used for layout.
Instead, we now calculate suitable widths and heights based on the
contents of the table wrapper when performing absolute layout.

Fixes the layout of
http://wpt.live/css/css-position/position-absolute-center-007.html
2024-03-07 08:09:04 +01:00
Timothy Flynn
ed13793110 LibWeb: Update the stored textarea value upon change
And fire the "input" event upon change. This is needed to submit a
comment on GitHub; otherwise, GitHub thinks the textarea value is empty.
2024-03-07 00:38:33 +01:00
Timothy Flynn
50d3f85f75 LibWeb: Stub out a few HTMLTextArea validity IDL methods
These are invoked by GitHub when submitting a comment. Stub them out for
now, as this is enough to let GitHub proceed with (attempting) to submit
the comment.
2024-03-07 00:38:33 +01:00
Bastiaan van der Plaat
76f767c867 LibWeb: Apply transform origin in Element::get_client_rects() 2024-03-07 00:28:29 +01:00
Timothy Flynn
5a20353bc4 LibWebView: Ensure we resolve cookie promises upon early returns
Note no test here, because this early return involves HTTP-only cookies,
which we don't have the infrastructure to test (we would need to support
custom HTTP headers in tests).
2024-03-06 14:38:49 -05:00
Timothy Flynn
18b71a363a WebContent: Update mouse event data when coalescing consecutive events
When we coalesce mouse wheel events, we need to be sure to include the
previous event's wheel deltas. This was errantly excluded in commit
baf359354b.
2024-03-06 11:20:44 -05:00
Ali Mohammad Pur
6dfb2f9dc8 Everywhere: Merge the WebSocket service into RequestServer
This keeps the APIs separate as they are wildly different, a future
improvement could be to somehow unify the APIs (if possible).

Closes #23080.
2024-03-06 10:07:27 +01:00
Andrew Kaster
4dd2ec68fc RequestServer: Transfer ownership of Protocols to all_protocols map
It's no change in application behavior to have these objects owned by
the function-scope static map in Protocol.cpp, while allowing us to
remove some ugly FIXMEs from time immemorial.
2024-03-06 08:15:03 +00:00
Andreas Kling
5b69413c4b Revert "LibJS/Bytecode: Bring back the bytecode optimization pipeline"
This reverts commit 5b29974bfa.
2024-03-06 08:39:29 +01:00
Andreas Kling
b37d84be58 Revert "LibJS/Bytecode: Don't replace the entry block in MergeBlocks"
This reverts commit acd29e064c.
2024-03-06 08:39:29 +01:00
Andreas Kling
cf81bf48c6 Revert "LibJS/Bytecode: Add peephole optimization pass and fuse compare+jump"
This reverts commit 4438ec481c.

Fixes #23480.
2024-03-06 08:39:29 +01:00
Andreas Kling
c4a0afbe28 Revert "LibJS/Bytecode: Fuse [Not, JumpIf] instructions into JumpIfNot"
This reverts commit 795149e585.
2024-03-06 08:39:29 +01:00
Andreas Kling
ea0b7192fa Revert "LibJS/Bytecode: Don't fuse unrelated compare and jump in peephole pass"
This reverts commit c1dbde72e9.
2024-03-06 08:39:29 +01:00
Timothy Flynn
baf359354b LibWebView+WebContent: Use Web::InputEvent for WebContent input IPC
Now that all input events are handled by LibWebView, replace the IPCs
which send the fields of Web::KeyEvent / Web::MouseEvent individually
with one IPC per event type (key or mouse).

We can also replace the ad-hoc queued input structure with a smaller
struct that simply holds the tranferred Web::KeyEvent / Web::MouseEvent.

In the future, we can also adapt Web::EventHandler to use these structs.
2024-03-06 07:46:18 +01:00
Timothy Flynn
ea682207d0 LibWeb+LibWebView: Migrate Browser's input event handling to LibWebView
The Serenity chrome is the only chrome thus far that sends all input key
and mouse events to WebContent, including shortcut activations. This is
necessary for all chromes - we must give web pages a chance to intercept
input events before handling them ourselves.

To make this easier for other chromes, this patch moves Serenity's input
event handling to LibWebView. To do so, we add the Web::InputEvent type,
which models the event data we need within LibWeb. Chromes will then be
responsible for converting between this type and their native events.

This class lives in LibWeb (rather than LibWebView) because the plan is
to use it wholesale throughout the Page's event handler and across IPC.
Right now, we still send the individual fields of the event over IPC,
but it will be an easy refactor to send the event itself. We just can't
do this until all chromes have been ported to this event queueing.

Also note that we now only handle key input events back in the chrome.
WebContent handles all mouse events that it possibly can. If it was not
able to handle a mouse event, there's nothing for the chrome to do (i.e.
there is no clicking, scrolling, etc. the chrome is able to do if the
WebContent couldn't).
2024-03-06 07:46:18 +01:00
Timothy Flynn
f2204e2b3a LibGUI: Define bitwise operations for GUI::MouseButton
This type is designed to be use as a flag. Define bitwise operations for
convenience.

(clang-format-17 caught an east-const conversion here as well).
2024-03-06 07:46:18 +01:00
Matthew Olsson
8f3b97e095 LibWeb: Don't render elements with invalid interpolated transform values 2024-03-06 07:45:56 +01:00
Matthew Olsson
e6aef49ef3 LibWeb: Consider fill state before calling Animation::play()
Animation::play_state() does not consider the fill state, and thus will
not return "Playing" for a fill-forward animation in the after phase.
It is still valid for paused, as pausing is not affected by the fill
mode.
2024-03-06 07:45:56 +01:00
Matthew Olsson
5dfe99e247 LibWeb: Do not assert the type of transformation style values
In this case, the StyleValue may be "unresolved", however let's just
avoid the assert altogether and treat all non-transform values as
"none".
2024-03-06 07:45:56 +01:00
Matthew Olsson
1ca31e0dc1 LibWeb: Remove unnecessary ErrorOr<> from StyleComputer
All of this error propogation came from a single call to
HashMap::try_ensure_capacity! As part of the ongoing effort to ignore
small allocation failures, lets just assert this works. This has the
nice side-effect of propogating out to a few other classes.
2024-03-06 07:45:56 +01:00
Matthew Olsson
8bb635bd33 LibWeb: Prevent transform interpolations from failing
Style computation should never fail. Instead, we just ignore the
transformation that led to the invalid matrix.
2024-03-06 07:45:56 +01:00
Aliaksandr Kalenik
4d8bc16812 LibWeb: Respect "auto flow" property in grid layout
Before this change, we only considering `grid-auto-flow` to determine
whether a row or column should be added when there was not enough space
in the implicit grid to fit the next unplaced item.

Now, we also choose the direction in which the "auto placement cursor"
is moved, based on the auto flow property.
2024-03-06 07:23:27 +01:00
Andrew Kaster
f67bc591a0 LibWeb: Implement and use the fetch a module worker script graph AO
This involves plumbing the perform the fetch hook argument throughout
all of the module fetch implementation AOs, where it was left as a FIXME
before.

With this change we can load module scripts in DedicatedWorkers.
2024-03-06 07:19:10 +01:00
Andrew Kaster
b5acc5f2df LibWeb: Serialize and pass to the WebWorker the current ESO
This allows the initial fetch() in the run a worker AO to use the proper
values from the outside settings.
2024-03-06 07:19:10 +01:00
Andrew Kaster
4d22358e05 LibWeb: Add facilities to serialize EnvironmentSettingsObjects
This will be used to transfer information about the parent context to
DedicatedWorkers and future out-of-process Worker/Worklet
implementations for fetching purposes. In order to properly check
same-origin and other policies, we need to know more about the outside
settings than we were previously passing to the WebWorker process.
2024-03-06 07:19:10 +01:00
Andrew Kaster
c79bac70f4 LibWeb: Consistently use the EmptyString state of ReferrerPolicy
We previously used an empty optional to denote that a ReferrerPolicy is
in the default empty string state. However, later additions added an
explicit EmptyString state. This patch moves all users to the explicit
state, and stops using `Optional<ReferrerPolicy>` everywhere except for
when an option not being passed from JavaScript has meaning.
2024-03-06 07:19:10 +01:00
Andrew Kaster
637f2f2ed6 LibProtocol: Keep reading until an error occurs for buffered reads
When buffering is enabled for the entire protocol request, it's possible
that the entirety of the file data might be available on the first read
of the pipe passed from RequestServer. If the file is then closed on the
RequestServer end, the client would never realize that the file is EOF
and call the user-provided on_finish callback.

By reading until there's an error, we expect to get an EAGAIN or similar
non-blocking pipe error message if there is still more data.
2024-03-06 07:19:10 +01:00
Andrew Kaster
7e6918e14a LibIPC: Add support for encoding and decoding Array<T, N>
Also add a note to the Concepts header that the reason we have all the
strange concepts in place for container types is to work around the
language limitation that we cannot partially specialize function
templates.
2024-03-06 07:19:10 +01:00
Andrew Kaster
e09bfc1a8c LibCore: Recognize .mjs as a common extension for application/javascript 2024-03-06 07:19:10 +01:00
Nico Weber
ab143e9b0e LibGfx/BMP: Clear alpha in palette entries
The semantics of BGRx8888 aren't super clear and it means different
things for different parts of the codebase. In particular, the PNG
writer still writes the x channel to the alpha channel of its output.

In BMPs, the 4th palette byte is usually 0, which means after #21412 we
started writing all .bmp files with <= 8bpp as completely transparent
to PNGs.

This works around that.

(See also #19464 for previous similar workarounds.)

The added `bitmap.bmp` is a 1bpp file I drew in Photoshop and saved
using its "Save as..." saving path.
2024-03-05 21:27:41 +00:00
Aliaksandr Kalenik
16f33aafda LibWeb: Always check paintable boxes children during hit-testing
Children of a paintable box are not guaranteed to be contained within
its border box. Therefore, during hit-testing, we must always check
them.

Fixes https://github.com/SerenityOS/serenity/issues/23219
2024-03-05 15:43:17 +01:00
Andreas Kling
c1dbde72e9 LibJS/Bytecode: Don't fuse unrelated compare and jump in peephole pass
Fixes an issue where https://x.com/awesomekling crashed on load. :^)
2024-03-05 13:39:25 +01:00
Andreas Kling
0f8c6dc9ad LibJS/Bytecode: Always evaluate LHS first in assignment expressions
This fixes an issue where expressions like `a[i] = a[++i]` could
evaluate `++i` before `a[i]`.
2024-03-05 10:19:38 +01:00
Andreas Kling
17c1f742a9 LibJS/Bytecode: Increase coverage of left/shift expression fast paths
As long as the inputs are Int32, we can convert them to UInt32 in a
spec-compliant way with a simple static_cast<u32>.

This allows calculations like `-3 >>> 2` to take the fast path as well,
which is extremely valuable for stuff like crypto code.

While we're doing this, also remove the fast paths from the generic
shift functions in Value.cpp, since we only end up there if we *didn't*
take the same fast path in the interpreter.
2024-03-04 20:54:51 +01:00
Andreas Kling
a5e1e66abc LibJS/Bytecode: Add fast path for LeftShift with Int32 operands 2024-03-04 20:54:51 +01:00
Andreas Kling
8e04791480 LibJS/Bytecode: Combine has_index() and get() in GetByVal and PutByVal
Since get() returns an empty Optional if the index is not present, we
can combine these two into a single get() operation and save the cost of
a virtual call.
2024-03-04 20:54:51 +01:00
Andreas Kling
55e9df4954 LibJS/Bytecode: Add fast paths for equality checks with same-tag values 2024-03-04 20:54:51 +01:00
Andreas Kling
795149e585 LibJS/Bytecode: Fuse [Not, JumpIf] instructions into JumpIfNot 2024-03-04 20:54:51 +01:00
Andreas Kling
4438ec481c LibJS/Bytecode: Add peephole optimization pass and fuse compare+jump
This patch adds a new "Peephole" pass for performing small, local
optimizations to bytecode.

We also introduce the first such optimization, fusing a sequence of
some comparison instruction FooCompare followed by a JumpIf into a
new set of JumpFooCompare instructions.

This gives a ~50% speed-up on the following microbenchmark:

    for (let i = 0; i < 10_000_000; ++i) {
    }

But more traditional benchmarks see a pretty sizable speed-up as well,
for example 15% on Kraken/ai-astar.js and 16% on Kraken/audio-dft.js :^)
2024-03-04 20:54:51 +01:00
Andreas Kling
acd29e064c LibJS/Bytecode: Don't replace the entry block in MergeBlocks
The entry block must stay in place, although it's okay to merge stuff
into it.

This fixes 4 test262 tests and brings us to parity with optimization
disabled. :^)
2024-03-04 20:54:51 +01:00
Andreas Kling
5b29974bfa LibJS/Bytecode: Bring back the bytecode optimization pipeline
...minus the EliminateLoads pass, since it was not compatible with the
new bytecode format.
2024-03-04 20:54:51 +01:00
Hugh Davenport
d8f756ce1d Escalator: Allow failed password attempts to be retried
There is a limit of 3 attempts before quitting, but the user can try
again after that.

The error messages now display to help the user understand the issue.
2024-03-04 13:25:22 -05:00
MacDue
74b655d035 LibWeb: Update SVG <circle> element to use geometry properties
With this the `<circle>` element now correctly parses percentage sizes,
and resolves them relative to the viewport.

The rest of the geometry elements are still left TODO.
2024-03-04 10:50:32 +01:00
MacDue
344eb98b3c LibWeb: Add helper to convert CSS LengthPercentage to SVGLength 2024-03-04 10:50:32 +01:00
MacDue
4f78ddd6a2 LibWeb: Setup computed values for SVG geometry properties 2024-03-04 10:50:32 +01:00
MacDue
b9afea40e6 LibWeb: Update SVG get_path() API to take a viewport size
This will allow resolving paths that use sizes that are relative to the
viewport. This necessarily removes the on element caching, which has
been redundant for a while as computed paths are stored on the
paintable.
2024-03-04 10:50:32 +01:00
MacDue
1fbf1073ab LibWeb: Define the rest of the SVG geometry properties
This defines all the (remaining) geometry properties from
https://svgwg.org/svg2-draft/geometry.html#Sizing.
2024-03-04 10:50:32 +01:00
Timothy Flynn
552f63a283 LibWebView: Protect the Inspector against rapid inspection requests
This was seen in Browser when hotkey activations were processed twice.
If we open the Inspector with a hotkey (F12) and quickly activate that
hotkey again, we could try sending a JS command (inspector.loadDOMTree)
before the inspector.js file was actually loaded in the WebContent.

The window for this bug is larger on Serenity, where loading WebContent
is a bit slower than on Linux. So even with the Browser bug fixed, it is
pretty easy to hit this window still.
2024-03-04 10:49:43 +01:00
Timothy Flynn
d392375a08 Revert "Browser: Allow system shortcuts to function"
This reverts commit 2e8ff1855c.

We had some awkward timing around the merging of this commit and commit
b073fdd570. With both commits in tree, we
are now processing hotkey activations twice. For example, ctrl+t will
open 2 tabs.
2024-03-04 10:49:43 +01:00
Kyle Lanmon
a099d0e140 PDFViewer: Hide the rendering diagnostics window by default
You can enable it in the Debug menu and we will remember your choice.
2024-03-04 10:43:41 +01:00
Filiph Siitam Sandström
d6ab5c9b7d LibCore: Fix AK_OS_ANDROID build
b9dc2d7 accidentally broke Android builds, this fixes that regression.
2024-03-04 07:55:39 +00:00
Sönke Holz
c20bc22bae DynamicLoader: Disable stack protector in some files for RISC-V 2024-03-04 01:44:11 +01:00
Andreas Kling
60a555e364 LibJS/Bytecode: Make NewPrimitiveArray a variable-length instruction
Instead of having a FixedArray with a separate heap allocation, we can
just bake the primitive values into the instruction itself.
2024-03-03 22:27:44 +01:00
Andreas Kling
5813df21c8 LibJS/Bytecode: Make primitive bigints be constants
Instead of emitting a NewBigInt instruction to construct a primitive
bigint from a parsed literal, we now instantiate the BigInt on the heap
during codegen.
2024-03-03 22:27:44 +01:00
Andreas Kling
46d209c55b LibJS/Bytecode: Make primitive strings be constants
Instead of emitting a NewString instruction to construct a primitive
string from a parsed literal, we now instantiate the PrimitiveString on
the heap during codegen.
2024-03-03 22:27:44 +01:00
Filiph Siitam Sandström
fd694e8672 AK+Lagom: Make it possible to build for iOS
This commit makes it possible to build AK and most of Lagom for iOS,
based on the work for the Ladybird build demoed on discord:
https://discord.com/channels/830522505605283862/830525031720943627/1211987732646068314
2024-03-03 13:13:42 -07:00
Matthew Olsson
ae321b2cdf LibWeb: Add interpolation for shadow values 2024-03-03 19:50:25 +01:00
Matthew Olsson
3c21dd4d2b LibWeb: Move color interpolation into a helper function
This will be needed for other interpolations
2024-03-03 19:50:25 +01:00
Matthew Olsson
8502b7ee9f LibWeb: Properly serialize shadow colors 2024-03-03 19:50:25 +01:00
Matthew Olsson
da18957063 LibWeb: Limit color alpha values to 4 decimal places when serializing
The spec explicitly mentions that these values need to round-trip, and
4 decimal places is enough for 8-bit values
2024-03-03 19:50:25 +01:00
Matthew Olsson
0487485fb1 LibWeb: Limit length values to 5 decimal places when serializing 2024-03-03 19:50:25 +01:00
Matthew Olsson
7dcf060927 LibWeb: Limit ratio parts to 5 decimal places when printing
Printing 15 or so decimal places for each value is a bit excessive
2024-03-03 19:50:25 +01:00
Matthew Olsson
4d9f2bf5f1 LibWeb: Add interpolation for ratio values 2024-03-03 19:50:25 +01:00
Matthew Olsson
f02cd4d0b0 LibWeb: Add a spec comment for color interpolation 2024-03-03 19:50:25 +01:00
Matthew Olsson
29b70485fc LibGfx: Add formatters for Gfx::Color's different representations
This makes debugging these values a bit easier
2024-03-03 19:50:25 +01:00
Matthew Olsson
1f88ca2a03 LibWeb: Remove transform interpolation optimization
The property values here will always be StyleValueLists and not
TransformationStyleValues. The handling of interpolation in this case
gets quite a bit more complex, so let's just remove the dead code for
now and attempt this optimization again in the future if it's needed.
2024-03-03 19:50:25 +01:00
Aliaksandr Kalenik
ee1d8a534d LibWeb: Remove wrappers for gradient painting command recording
These were adding unnecessary indirection, whereas recording painter
could be called directly.
2024-03-03 18:19:20 +01:00
Nico Weber
c6b484a728 LibPDF: Make image creation in Renderer::load_image() fallible 2024-03-03 11:18:37 -05:00
Nico Weber
9bff8abcc7 LibPDF: Add support for array image masks
An array image mask contains a min/max range for each channel,
and if each channel of a given pixel is in that channel's range,
that pixel is masked out (i.e. transparent). (It's similar to
having a single color or palette index be transparent, but it
supports a range of transparent colors if desired.)

What makes this a bit awkward is that the range is relative to the
origin bits per pixel and the inputs to the image's color space.

So an indexed (palettized) image with 4bpp has a 2-element mask
array where both entries are between 0 and 15.

We currently apply masks after converting images to a Gfx::Bitmap,
that is after converting to 8bpp sRGB. And we do this by mapping
everything to 8bpp very early on in load_image().

This leaves us with a bunch of options that are all a bit awkward:

1. Make load_image() store the up- (or for 16bpp inputs, down-)
   sampled-to-8bpp pixel data. And also return if we expanded the
   pixel range while resampling (for color values) or not (for
   palettized images). Then, when applying the image filter,
   resample the array bounds in exactly the same way. This requires
   passing around more stuff.

2. Like 1, but pass in the mask array to load_image() and apply
   the mask right there and then. This means we'd apply mask arrays
   at a different time than other masks.

3. Make the function that computes the mask from the mask array
   work from the original, unprocessed image data. This is the most
   local change, but probably also requires the largest amount of
   code (in return, the color mask for 16bpp images is precise, in
   addition that it separates concerns the most nicely).

This goes with 3 for now.
2024-03-03 11:18:37 -05:00
Hugh Davenport
0d6573be14 Escalator: Set focus to password input automatically 2024-03-03 11:00:05 -05:00
Bastiaan van der Plaat
a2f101c10b LibWeb: Add input and textarea minlength and maxlength support 2024-03-03 10:02:30 -05:00
Bastiaan van der Plaat
9b645d20b9 LibWeb: Refactor input range sanitization code use min and max getters 2024-03-03 10:02:30 -05:00
Zac Brannelly
9165faca5e LibWeb: Support CSS property background-clip: text
From https://drafts.csswg.org/css-backgrounds-4/#background-clip
"The background is painted within (clipped to) the intersection of the
border box and the geometry of the text in the element and its in-flow
and floated descendants"

This change implements it in the following way:
1. Traverse the descendants of the element, collecting the Gfx::Path of
   glyphs into a vector.
2. The vector of collected paths is saved in the background painting
   command.
3. The painting commands executor uses the list of glyphs to paint a
   mask for background clipping.

Co-authored-by: Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
2024-03-03 15:33:12 +01:00
Zac Brannelly
4a3680cafc LibWeb/CSS: Add "text" into list of possible "background-box" values 2024-03-03 15:33:12 +01:00
Andreas Kling
0c18450c4f LibJS/Bytecode: Fix bad serialization of Postfix{Increment,Decrement}
We were serializing the dst operand twice in both instructions.
2024-03-03 09:08:20 +01:00
Shannon Booth
4bce61e508 patch+LibDiff: Add support for applying patches with preprocessor macro 2024-03-03 08:56:00 +01:00
Shannon Booth
ee643b6417 LibDiff: Prevent negative underflow calculating suffix and prefix fuzz
In the situation where the amount of content preceeding the hunk was
greater than the max context of the hunk there would be an unsigned
underflow, as the logic was assuming signed arithmitic.

This underflow would result in the patch not applying, as patch would
assume the massive calculated fuzz would result in the patch matching
against any file.
2024-03-03 08:56:00 +01:00
Shannon Booth
abf35f5bd6 LibCore: Support Optional<StringView> as an argument to ArgsParser
While StringView does have a null state, we have been moving away from
this in our other String classes. To represent a StringView not being
given at all on the commandline, use an Optional.
2024-03-03 08:56:00 +01:00
Shannon Booth
3e61d20b40 LibDiff: Handle parsing patches containing timestamps separated by \t
This is still a very naive implementation and there are plenty of other
cases that we should handle (like a quoted path) - but just looking for
a tab handles the common case.
2024-03-03 08:56:00 +01:00
circl
3e3a200eee LibWeb: Do not issue change event for every update of color input
Per spec, the change event shall only be issued once the change is
finally committed by the user, IE by closing the color picker window.
2024-03-03 08:42:41 +01:00
Johannes Røsvik
d89e617a42 LibWeb: Make SubtleCrypto use the correct algorithm name for SHA-1
The spec defines "SHA-1" as a recognized algorithm name, not "SHA1".

This makes SHA-1 hash values show up on string.248.no.
2024-03-03 08:41:32 +01:00
Aliaksandr Kalenik
d5e74b1bdc LibWeb: Use a precalculated list of positioned descendants for painting
This allows us to avoid the need for costly traversals to gather
boxes that have been saved during the construction of the stacking
context tree.

No behavior change intended.
2024-03-03 08:40:46 +01:00
Kenneth Myhra
cd0302426f LibWeb: Move serialization of serializable object's interface name
To be consistent with the deserialization steps, move serialization of
the serializable object's interface name out of the serialization steps.
2024-03-02 17:04:09 -07:00
Kenneth Myhra
4751ab9f0b LibWeb: Add convenience methods {,de}serialize_{u,i}64()
To avoid differing logic for serializing and deserializing similar
types, move the logic into separate helpers.

Also, adds security checks like VERIFY to avoid reading past the end of
the serialized data. If we try to read past the end of the serialized
data, either our program logic is wrong or our serialized data has
somehow been corrupted. Therefore, at least currently, it is better to
crash by VERIFYing.
2024-03-02 17:04:09 -07:00
Kenneth Myhra
79978063b9 LibWeb: Extract deserialization logic for {,object} primitives
To avoid differing logic for deserializing similar types, move the logic
into separate helpers.

Also, adds security checks like VERIFY to avoid reading past the end of
the serialized data. If we try to read past the end of the serialized
data, either our program logic is wrong or our serialized data has
somehow been corrupted. Therefore, at least currently, it is better to
crash by VERIFYing.
2024-03-02 17:04:09 -07:00
Kenneth Myhra
c384f22d67 LibWeb: Extract serialization logic for primitives and object primitives
To avoid differing logic for serializing similar types, move the logic
into separate helpers.
2024-03-02 17:04:09 -07:00