Commit Graph

32252 Commits

Author SHA1 Message Date
Andreas Kling
a378303629 LibWeb: Use unchecked_append in StyleComputer::collect_matching_rules()
We already grow the "rules to run" vector before appending to it, so we
can actually use unchecked_append() here and avoid the "needs to grow"
checks every time we append to it.

This takes appending from 3% to <1% when loading our GitHub repo.
2024-03-16 14:27:59 +01:00
Andreas Kling
b15316eba8 LibWeb: Avoid FlyString->String->FlyString roundtrips in CSS variables 2024-03-16 14:27:59 +01:00
Andreas Kling
7da3b0dd7b LibWeb: Avoid a FlyString->String->FlyString round-trip in StyleComputer 2024-03-16 14:27:59 +01:00
Andreas Kling
c0e0cb86e1 LibWeb: Make CSS::string_from_property_id() return FlyString const&
This avoids costly conversions from StringView to FlyString in CSS
parsing and variable expansion.
2024-03-16 14:27:59 +01:00
Andreas Kling
1cea4e6407 LibWeb: Use cached UsedValues pointer in IFC and its helper classes
This avoids expensive LayoutState lookups when we already have the
pointer sitting around anyway.
2024-03-16 14:27:59 +01:00
Andreas Kling
43ef3dc0ab LibWeb: Cache attribute names in lowercase to speed up selector matching
When matching a CSS attribute selector against an HTML element, the
attribute name is case-insensitive. Before this change, that meant we
had to call equals_ignoring_ascii_case() on all the attribute names.

We now cache the attribute name lowercased on each Attr node, which
allows us to do FlyString-to-FlyString comparison (simple pointer
comparison).

This brings attribute selector matching from 6% to <1% when loading our
GitHub repo at https://github.com/SerenityOS/serenity
2024-03-16 14:27:59 +01:00
Aliaksandr Kalenik
a3b4c2a30f LibJS+LibWeb: Change JobCallback to be GC-allocated
Fixes leak caused by mutual dependency when JS::Handle<JobCallback> is
owned by GC-allocated PromiseReaction.
2024-03-16 14:27:06 +01:00
Nico Weber
f391c7822d LibGfx/JBIG2: Call decode_immediate_generic_region for lossless regions
It seems to do the right thing already, and nothing in the spec says
not to do this as far as I can tell.

With this, we can finally decode
Tests/LibGfx/test-inputs/jbig2/bitmap.jbig2 and add a test for
decoding simple arithmetic-coded images.
2024-03-16 09:21:42 -04:00
Nico Weber
6788a82ec5 LibGfx/JBIG2: Implement generic_region_decoding_procedure() happy path
This errors out on many special cases. None of those seem to be hit
in practice (with the exception of TPGDON, which is used in a handful
PDFs. I have an implementation of that locally, but I'll put that
in a separate PR. The code for it is straightforward, but adding a
test for it is a bit involved.)

With this, we can decode about half of the JBIG2 images in my PDF
test dataset.
2024-03-16 09:21:42 -04:00
Nico Weber
b0c73d1652 LibGfx/JBIG2: Reject unimplemented combination operators
In practice, everything uses white backgrounds and operators `or`
or `xor` to turn them black, at least for the simple images we're
about to be able to decode.

To make sure we don't forget implementing this for real once needed,
reject other ops, and also reject black backgrounds (because 1 | 0
is 1, not 0 like our overwrite implementation will produce).

This means we have to remove a test, but since this scenario doesn't
seem to happen in practice, that seems ok.
2024-03-16 09:21:42 -04:00
Nico Weber
5dc9ead1c5 LibGfx/JBIG2: Expand a comment 2024-03-16 09:21:42 -04:00
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