Commit Graph

2838 Commits

Author SHA1 Message Date
Tim Ledbetter
0ea547dc2d LibWeb: Use correct integer parsing rules in HTMLLIElement::value()
(cherry picked from commit a61883ae88eb3fd4b35cc51db77a4c9405480fb5)
2024-11-26 22:37:15 -05:00
Tim Ledbetter
107ea0c79a LibWeb: Use [URL] extended attribute for HTMLVideoElement.poster
(cherry picked from commit 67d05b0104dab928fc5334fe63e46cd62d1e4e22)
2024-11-26 22:37:15 -05:00
Glenn Skrzypczak
4fce2cffb2 LibWeb/HTML: Implement cite attribute according to spec
Implements the cite attribute of `q`, `blockqoute`, `ins` and `del`
elements according to spec by returning a valid URL.

(cherry picked from commit 74645facae366d62ee4c44bd4a96d02df345a5d4)
2024-11-26 22:37:15 -05:00
Sam Atkins
6026e4b2e7 LibWeb: Fill-in some fixmes around sandboxing flag sets
...Including a couple of steps in
obtain_a_browsing_context_to_use_for_a_navigation_response() which
didn't have FIXMEs.

No apparent changes on WPT.

(cherry picked from commit 310cdc35f05946be15cb16ccc2f32e4f1e43efe3)
2024-11-26 22:37:15 -05:00
Sam Atkins
25f9dfdd20 LibWeb/HTML: Consume user activation when choosing a Navigable
Corresponds to https://github.com/whatwg/html/pull/10547

(cherry picked from commit 2c7e73072685d241585795c8f82bb9f1b1840c98)
2024-11-26 22:37:15 -05:00
Timothy Flynn
d0e18b896b LibWeb: Support ctrl/cmd-clicking a link to open it in a new tab
The spec does not define activation behavior of ctrl/cmd clicks, so we
have to go a bit ad-hoc here. When an anchor element is clicked with the
cmd (on macOS) or ctrl (on other platforms) modifier pressed, we will
skip activation of that element and pass the event on to the chrome. We
still dispatch the event to allow scripts to cancel the event.

(cherry picked from commit 40b2d24d5585a94f09f521bb0ceb055dcae7b6e9)
2024-11-26 16:03:32 -05:00
Timothy Flynn
4208ce6eae LibWeb: Port text segmentation to the Segmenter API
(cherry picked from commit 12f177e9e94ca71c619ec1171078e8635debde09;
amended to remove mention of ICU in commit message, and to resolve
a minor conflict in CharacterData.h due to serenity cherry-picking
LadybirdBrowser/ladybird#901 before this change)
2024-11-26 13:50:49 -05:00
Sam Atkins
dad75576d3 LibWeb: Match spec changes to "apply the history step"
Corresponds to https://github.com/whatwg/html/pull/10704

(cherry picked from commit c5c5d97544cd49425d057028964e7c7af4cae3cf)
2024-11-25 12:19:48 -05:00
Sam Atkins
a7934a9445 LibWeb/HTML: Update spec comments for "URL and history update steps"
Corresponds to:
https://github.com/whatwg/html/pull/10587

(cherry picked from commit 0a578ee3452217701c61ba8ac8e66b0d71e714a0)
2024-11-25 12:19:48 -05:00
Tim Ledbetter
7e288e80fe LibWeb: Allow FormData entry list to be mutated within a FormDataEvent
Previously, the list was copied when constructing the FormData object,
then the original list was passed to the event, meaning any changes to
the list that happened within the event would not be reflected outside
of it.

(cherry picked from commit ea0e434d1d6b464ab0a56c4b7150950be78ae7d3)
2024-11-25 12:19:33 -05:00
Tim Ledbetter
6bf08818be LibWeb: Don't crash when parsing large floating point number values
Previously, attempting to parse a floating point number with an integer
part larger than `(2 ^ 31) - 1` would cause the browser to crash. We now
avoid this by converting the integer part of the number to a `double`
rather than an `i32`.

(cherry picked from commit 21a32e4b6dc594c2fe8dd3ee11c829c250a103ad)
2024-11-25 12:19:33 -05:00
Khaled Lakehal
438b568256 LibWeb: Implement HTML spec-compliant rules for floating-point parsing
Attempt to implement HTML specs for parsing floating-point number
https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-floating-point-number-values

(cherry picked from commit 14e1e55319b7c128d88f1b1f2752ffc9e34858f5;
amended to remove `std::` qualifiers))
2024-11-25 09:21:14 -05:00
Alan Kemp
ae8d143338 LibWeb: Pageshow event dispatched by the user agent should be trusted
The spec says that "isTrusted is a convenience that indicates whether
an event is dispatched by the user agent (as opposed to using
dispatchEvent())"

But when dispatching a pageshow event the flag was incorrectly set
to false.

This fixes https://wpt.fyi/results/html/syntax/parsing/the-end.html

(cherry picked from commit d2fbbabd893d84a6b8b68a8bc8034e4d6dc4da4a)
2024-11-25 09:21:14 -05:00
samu698
20a830ab66 LibWeb: Fixed IDL for HTMLInputElement
Use Enumerated for the form{Enctype, Method} attributes

(cherry picked from commit d08d3053999619aa90469c07ee758cd036298a2b)
2024-11-25 09:21:14 -05:00
samu698
da90fb81a6 LibWeb: Fixed IDL for HTMLButtonElement
Use Enumerated for the form{Enctype, Method} attributes

(cherry picked from commit ab04f6d422a0a328f2ded1e3d5bbcf614c95f07a)
2024-11-25 09:21:14 -05:00
samu698
31cc24feed LibWeb: Use correct IDL for HTTPFormElement's method attribute
Removed the custom getter and updated the idl so that the attribute
is Reflected and Enumerated.

(cherry picked from commit 68924827551fc3169c1b9b59c0d7e8bc999a390c)
2024-11-25 09:21:14 -05:00
Taylor Mapes
06d58ae78c LibWeb: Implement CanvasRenderingContext2D.createImageData(ImageData)
Fixes at least one WPT test.
https://wpt.live/html/canvas/element/pixel-manipulation/2d.imageData.create1.basic.html

(cherry picked from commit 0522e514a92e6534311a33890780b877b6353979)
2024-11-25 08:50:54 -05:00
Taylor Mapes
f505dd7371 LibWeb: Correct spec link for CanvasImageData
(cherry picked from commit 6ffe83c9da0b450579ca83e9bdec40a01b15b228)
2024-11-25 08:50:54 -05:00
Cory Virok
e5339b7e0b LibWeb: Implemented the CanvasRenderingContext2D::createImageData() spec
The only real change here is to use the absolute magnitude of the
width/height when creating the ImageData.

This fixes the crash on this WPT test:
https://wpt.fyi/results/html/canvas/element/pixel-manipulation/2d.imageData.create2.double.html?label=master&product=ladybird

(cherry picked from commit 560c3824b95b3130f05dbceeebff23fbfc7f69ad)
2024-11-25 08:50:54 -05:00
Fernando Kiotheka
a269e28cfa LibWeb: Implement activation behavior on input[type=reset]
This fixes WPT html/semantics/forms/resetting-a-form/reset-form.html.
I added a test based on the WPT test, but simpler.

(cherry picked from commit caf74e7ed69c6f64fc2f770d03fe61bc60cdc08b)
2024-11-25 08:50:54 -05:00
Shannon Booth
d1c0fa3245 LibWeb: Do not spin the event loop on processing iframe attributes
Partially reverting a3149c1ce9

Spinning the event loop was causing a crash on:

https://wpt.live/url/percent-encoding.window.html

As it was turning what is meant to be a synchronous operation into an
asynchronous one.

The sequence demonstrated by the reproducing test is as follows:
  * A src attribute is changed for the iframe
  * process_the_iframe_attributes entered with valid content navigable
  * Event loop is spun, allowing the queued iframe removal to execute
  * process_the_iframe_attributes continues with null content navigable
  * 💥

(cherry picked from commit 30377e6e3500049c5442fac9d242d3b795861116)
2024-11-25 08:50:54 -05:00
Andreas Kling
48d994839c LibWeb: Don't swallow args when forwarding cross-origin WindowProxy call
Fixes at least one WPT test that was previously timing out:
- html/semantics/document-metadata/the-base-element/base_target_does_not_affect_iframe_src_navigation.html

(cherry picked from commit 0b403d30d765ab8e5db3b7443ebeca7f85c3acf2)
2024-11-25 08:50:54 -05:00
Timothy Flynn
09dfa66fe3 LibWeb: Mark a BC's navigable as destroyed if it does not exist
(cherry picked from commit 84df1bf585de217ccf3399e31708af96c95bb9fe)
2024-11-24 21:30:22 -05:00
Timothy Flynn
47497fa4fe LibWeb: Break the Window open steps into two methods for internal use
Some callers (namely WebDriver) will need access to the navigable opened
by these steps. But if the noopener parameter is set, the returned proxy
will always be null.

This splits some of the Window open steps into an internal method that
returns the chosen navigable.

(cherry picked from commit 981aaba96cd6ee752d9cf76595731612898fe05c)
2024-11-24 17:29:26 -05:00
Tim Ledbetter
f6ef0a2c5d LibWeb: Rename Window::open_impl() to Window::window_open_steps()
This is the same name used in the specification.

(cherry picked from commit f3c6326f27e4427b549f7d88c99580cb356b5c3c)
2024-11-24 17:29:26 -05:00
Cory Virok
d8d86d7847 LibWeb: Wrap negative dims for getImageData()
Given negative width or height values for CanvasRenderingContext2D
getImageData(), translate the source rect.

I wasn't able to find this in the spec, but WPT tests for it and MDN
defines this behavior.

Fixes this WPT test:
https://wpt.live/html/canvas/element/pixel-manipulation/2d.imageData.get.source.negative.html

Described in MDN here:
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/getImageData#sw

getImageData() spec:
https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getimagedata

(cherry picked from commit 01301c374b295578740a3a9ebf19468a870c763e)
2024-11-24 10:27:54 -05:00
Cory Virok
3bf4d524fd LibWeb: Use abs() dimensions for canvas getImageData()
Similar to https://github.com/LadybirdBrowser/ladybird/pull/1774

Fixes the crash in the WPT test:
https://wpt.fyi/results/html/canvas/element/pixel-manipulation/2d.imageData.get.double.html?label=master&product=ladybird

(cherry picked from commit d71887e48cb8438784735fe9b2a546990318ab4b)
2024-11-24 10:27:54 -05:00
Andreas Kling
303ec1c8a3 LibWeb: Don't let input element placeholders influence line-height
Before this change, we transferred the input element's line-height to
both the editable text *and* the placeholder. This caused some strange
doubling of the effective line-height when the editable text was empty,
pushing down the placeholder.

(cherry picked from commit 13ba491924c4fc3831d5a8986673d832a721f545;
amended some slighly different horizontal sizes in the expectations
file. Maybe due to serenity not using harfbuzz for shaping, or due
to not have another earlier change yet. If it's the latter, this will
fix itself when that's brought in.)
2024-11-23 23:48:34 -05:00
Andreas Kling
9b4db4a0e0 LibWeb: Make DOMException take error message as a String
There was no need to use FlyString for error messages, and it just
caused a bunch of churn since these strings typically only existed
during the lifetime of the error.

(cherry picked from commit 175f3febb8037a440d4ead7347d3266ee3d345e1;
minorly amended to fix conflict in WebSocket.cpp due to serenity
not having the adapter class removal in LadybirdBrowser/ladybird#1671)
2024-11-22 11:13:42 -05:00
Shannon Booth
8c3cb23384 LibWeb+LibURL: Consolidate Origin parsing and serialization into LibURL
Because of the previous awkward factoring of Origin we had two
implementations of Origin serializing and creation. Move the
implementation of DOMURL::url_origin into URL::origin, and
instead use the implemenation of URL::Origin::serialize for
serialization (replacing URL::serialize_origin).

This happens to fix 8 URL subtests as the two implemenations had
diverged, and URL::serialize_origin was previously missing the spec
changes of: whatwg/url@eee49fd and whatwg/url@fff33c3

(cherry picked from commit 501f92b54eee7bcf7b60621aa4238fcbdc610d99;
amended to add leading whitespace to expectation due to serenity not
yet having LadybirdBrowser/ladybird#1603)
2024-11-21 22:16:27 -05:00
Shannon Booth
485150860a LibURL: Define Origin methods depending on URL::Parser out of line
This is also in an effort towards resolving a future circular dependency
between Origin.h and URL.h

(cherry picked from commit 43973f2d0a32aedf4405f246b5f2806f61016384;
amended to fix tiny include conflict in Document.cpp)
2024-11-21 22:16:27 -05:00
Shannon Booth
2855880f8a LibWeb+LibURL: Move HTML::Origin to URL::Origin
While Origin is defined in the HTML spec - this leaves us with quite an
awkward relationship as the URL spec makes use of AO's from what is
defined in the HTML spec.

To simplify this factoring, relocate Origin into LibURL.

(cherry picked from commit dc401f49ea7e861064484e79594e35c3d93000ae;
amended to fix minor conflicts due to serenity not (yet?) having a
LibUnicode/Segmenter.h include in Document.cpp, and due to
BrowsingContext already having LadybirdBrowser/ladybird#2358 in
serenity)
2024-11-21 22:16:27 -05:00
Shannon Booth
65f4aae1d8 LibURL+Everywhere: Only percent decode URL paths when actually needed
Web specs do not return through javascript percent decoded URL path
components - but we were doing this in a number of places due to the
default behaviour of URL::serialize_path.

Since percent encoded URL paths may not contain valid UTF-8 - this was
resulting in us crashing in these places.

For example - on an HTMLAnchorElement when retrieving the pathname for
the URL of:

http://ladybird.org/foo%C2%91%91

To fix this make the URL class only return the percent encoded
serialized path, matching the URL spec. When the decoded path is
required instead explicitly call URL::percent_decode.

This fixes a crash running WPT URL tests for the anchor element on:

https://wpt.live/url/a-element.html
(cherry picked from commit cc557323326ba55514ef2a8a6e0efd7f09330f06;
amended heavily to call `URL::percent_decode()` on all results of
`url.serialize_path()` in the rest of serenity -- except in
LibGemini, where it looked incorrect, and in LibHTTP, where
LadybirdBrowser/ladybird#983 will add it.)
2024-11-21 17:47:14 -05:00
Timothy Flynn
68e58b56c4 LibWeb: Visit the MessagePort's associated Worker target
Without this, a worker can be GC'd in a very simple script such as:

    const worker = new Worker("script.js");
    worker.onmessage = () => {};

Where script.js attempts to post a message back to the parent window.

When the Worker is GC'd, the IPC connection from the WebContent process
to the WebWorker process is closed. When this occurs, the WebWorker will
exit() from LibIPC, and any message from the worker to its parent does
not have a chance to run.

(cherry picked from commit eeee6ba3f54bc920e7cd493820faab943b59e0bd)
2024-11-21 09:41:42 -05:00
Timothy Flynn
94af8840a4 LibWeb: Disentangle associated MessagePorts when a document is destroyed
(cherry picked from commit ba1b26cdc2f5012e8c9ac705854f621a83eeda4c)
2024-11-21 09:41:42 -05:00
Timothy Flynn
4e0ac5e125 LibWeb: Reset MessagePort's worker event target when it is disentangled
(cherry picked from commit d44dd756b382c5f8966ad98b78020e01a6f31b2a)
2024-11-21 09:41:42 -05:00
Timothy Flynn
cc4c7917d5 LibWeb: Move StructuredSerializeOptions to its own header
This largely reduces the number of files needed to be compiled when we
change the MessagePort header.

(cherry picked from commit 32a22c49e3e999e681e2d1de1ebabd092a7f9b47)
2024-11-21 09:41:42 -05:00
Julius Elshoff
15e1590def LibWeb: Rename 'cross-origin opener policy' to 'opener policy'
(cherry picked from commit de31ea5852e3fc0aca1e86e06c6bc019f27824de)
2024-11-21 07:32:56 -05:00
Andreas Kling
a65b5cb135 LibWeb: Mark image elements for layout before firing their load event
This removes a long-standing source of flakiness seen for example in
WPT's /referrer-policy/ tests.

(cherry picked from commit 063cd68bf472061ec35cf9b8970aa6e614632c9b)
2024-11-20 22:51:34 -05:00
Andreas Kling
e1ba881587 AK+LibWeb: Add {Fly,}String::to_ascii_{upper,lower}_case()
These don't have to worry about the input not being valid UTF-8 and
so can be infallible (and can even return self if no changes needed.)

We use this instead of Infra::to_ascii_{upper,lower}_case in LibWeb.

(cherry picked from commit 073bcfd3866852a4c4bcca2bd131bd65ae53541f)
2024-11-18 20:22:45 -05:00
Psychpsyo
459f13ee74 LibWeb: Prevent checkboxes from firing change events when losing focus
This is because toggling the checkbox is committing the value.

(cherry picked from commit 3856dd946b94b61be2ddac80c8cf60278fcc56ab;
amended to add spaces to expected output due to serenity not yet
having LadybirdBrowser/ladybird#1603, and to add a trailing newline
to the test input file)
2024-11-18 13:21:10 -05:00
Totto16
8987d773a1 LibWeb: Make HTMLVideoElement part of CanvasImageSource union
(cherry picked from commit abe1172d7097ddae2aff2ddd839b96ed90ba7a13)
2024-11-17 18:57:16 -05:00
Andreas Kling
abf9980ea1 LibWeb: Make SVGImageElement part of CanvasImageSource union
This is very janky at the moment but it also more correct. :^)

(cherry picked from commit cd0e4a49b8a758aca847ceaf57eec0a62cd7b687;
amended to add a missing include of LibGfx/ImmutableBitmap.h to
SVGImageElement.h that ladybird seems to get transitively somehow)
2024-11-17 16:48:43 -05:00
Andreas Kling
0b5719685d LibWeb+LibGfx: Serialize HTML canvas fill/strokeStyle colors correctly
Before this change we were serializing them in a bogus 8-digit hex color
format that isn't actually recognized by HTML.

This code will need more work when we start supporting color spaces
other than sRGB.

(cherry picked from commit 4590c081c2eb257232463ed660498a02f9bbe7b8;
amended expected output because serenity does not yet have
LadybirdBrowser/ladybird#1603)
2024-11-17 16:48:43 -05:00
Tim Ledbetter
790eadf2fc LibWeb: Don't discard PostedMessage tasks when closing a worker
The spec expects `postMessage()` to act as if it is invoked
immediately. Since `postMessage()` isn't actually invoked immediately,
keep tasks with source `PostedMessage` in the task queue, so that these
tasks are processed. Fixes a hang when `WorkerGlobalScope.close()` is
called immediately after `postMessage()`.

(cherry picked from commit fd8d350b4756817598ee49a11b9efc3b953dbb00)
2024-11-17 15:18:38 -05:00
Luke Wilde
a7b4b170ed LibWeb: Make MessageEvents from {Window,MessagePort}.postMessage trusted
The MessagePort one in particular is required by Cloudflare Turnstile,
as the method it takes to run JS in a worker is to `eval` the contents
of `MessageEvent.data`. However, it will only do this if
`MessageEvent.isTrusted` is true, `MessageEvent.origin` is the empty
string and `MessageEvent.source` is `null`.

The Window version is a quick fix whilst in the vicinity, as its
MessageEvent should also be trusted.

(cherry picked from commit 079c28d5e68ad983340c02f3d043acfdf2846d18)
2024-11-17 15:18:20 -05:00
Shannon Booth
0eab74d09e LibWeb: Change URL parsing sequence for window open steps
This adapts to the latest HTML spec which fixed the issue we had
reported of:

https://github.com/whatwg/html/commit/316b83
(cherry picked from commit ab309dcc586f15cb7d11d79e7eb916652edf5b60)
2024-11-17 14:44:11 -05:00
Jamie Mansfield
775db34d5e LibWeb/HTML: Update "can have its URL rewritten" for spec changes
This updates the spec comments and removes a FIXME. Functionally,
this doesn't change anything as a fix was already in place.

See:
 - https://github.com/whatwg/html/commit/89a387c
 - https://github.com/whatwg/html/issues/10551
(cherry picked from commit aac342bf7445a2ef9407c45ac66615ac3d0e97ce)
2024-11-17 14:44:11 -05:00
Shannon Booth
25e71eb01a LibWeb: Expose MessagePort.postMessage(message, transfer)
The overload resolution is no longer an issue, and we already had this
implemented :^)

(cherry picked from commit 2c5cfbb968113a5630a8cd580bb100852aadeb95)
2024-11-17 13:47:42 -05:00
Shannon Booth
424d5c7574 LibWeb: Use FIXME extended attribute for ServiceWorker.postMessage
The old FIXME is no longer relevant :^)

(cherry picked from commit 897ba19e0fa783c548281e8fee5d44ce9b5f6dca)
2024-11-17 13:47:42 -05:00