Commit Graph

109 Commits

Author SHA1 Message Date
Timothy Flynn
7c31343df0 LibWeb: Store the ID of all media elements on a page
This will be used to inform the media elements when the user has muted
the page.
2024-03-30 19:28:20 +01:00
Timothy Flynn
2393ee6548 LibWeb: Don't attempt to notify chromes about audio playing until ready
The current location of the IPC invocation is often too soon. We reach
it before the audio file has completely finished downloading / loading,
thus there isn't an AudioTrack object yet.

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

This is particularly frequent on bandcamp.
2024-03-30 07:35:30 +01:00
Timothy Flynn
40c0dd81d2 LibWeb+LibWebView+WebContent: Inform chromes when audio is played/paused
Most browsers have some indicator when audio is playing in a tab, which
makes it easier to find that tab and mute unwanted audio. This adds an
IPC to allow the Ladybird chromes to do something similar.
2024-03-28 21:08:23 +01:00
Shannon Booth
e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00
Andreas Kling
c0d7f748ed LibWeb: Avoid FlyString lookups when setting IDL interface prototypes
This commit introduces a WEB_SET_PROTOTYPE_FOR_INTERFACE macro that
caches the interface name in a local static FlyString. This means that
we only pay for FlyString-from-literal lookup once per browser lifetime
instead of every time the interface is instantiated.
2024-03-16 16:35:54 +01: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
Shannon Booth
9ce8189f21 Everywhere: Use unqualified AK::URL
Now possible in LibWeb now that there is no longer a Web::URL.
2024-02-25 08:54:31 +01:00
Bastiaan van der Plaat
a681429dff LibWeb: Remove DOM element deprecated_get_attribute() 2024-01-19 13:12:54 -07:00
Aliaksandr Kalenik
7c2713c14f LibWeb: Move set_needs_display() from layout node to paintable
For this method, there is no need to go through the layout node when we
can directly reach the paintable.
2024-01-15 09:00:35 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Shannon Booth
96af80acd1 LibWeb: Port Intrinsics from DeprecatedString 2023-11-28 17:15:27 -05:00
Andreas Kling
bfd354492e LibWeb: Put most LibWeb GC objects in type-specific heap blocks
With this change, we now have ~1200 CellAllocators across both LibJS and
LibWeb in a normal WebContent instance.

This gives us a minimum heap size of 4.7 MiB in the scenario where we
only have one cell allocated per type. Of course, in practice there will
be many more of each type, so the effective overhead is quite a bit
smaller than that in practice.

I left a few types unconverted to this mechanism because I got tired of
doing this. :^)
2023-11-19 22:00:48 +01:00
Shannon Booth
eca9874e56 LibWeb: Port Element::attribute_changed from DeprecatedString to String
Which as you would expect has a bunch of fallout, but also results in a
whole lot of awkward conversions falling away.
2023-11-19 08:16:34 +00:00
Ali Mohammad Pur
aeee98b3a1 AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
2023-10-13 18:33:21 +03:30
Shannon Booth
e4f8c59210 LibWeb: Port AttributeNames to FlyString 2023-10-08 08:11:48 -04:00
Aliaksandr Kalenik
cad2d2c85b LibWeb: Use JS::HeapFunction for DocumentObserver callbacks
If GC-allocated object wants to own a function it should use
HeapFunction because using SafeFunction will almost always lead to a
leak.
2023-09-27 19:39:57 +02:00
Shannon Booth
41928c2902 LibWeb: Port DOMException interface from DeprecatedString to String 2023-09-06 11:44:45 -04:00
Shannon Booth
f4bc1602e2 LibWeb: Port HTMLMediaElement interface from DeprecatedString to String 2023-09-05 20:36:09 -04:00
Shannon Booth
0f6782fae6 LibWeb: Rename Element::attribute to Element::deprecated_attribute
This should allow us to add a Element::attribute which returns an
Optional<String>. Eventually all callers should be ported to switch from
the DeprecatedString version, but in the meantime, this should allow us
to port some more IDL interfaces away from DeprecatedString.
2023-09-05 20:36:09 -04:00
Andrew Kaster
d97b09693e LibWeb: Convert SandboxingFlagSet into a enum class
Instead of having a nested enum within a struct, use the macro
AK_ENUM_BITWISE_OPERATORS to add all the convienent has_flag free
functions and such for ease of use.
2023-08-29 09:39:57 +02:00
Aliaksandr Kalenik
bdd3a16b16 LibWeb: Make Fetch::Infrastructure::Body be GC allocated
Making the body GC-allocated allows us to avoid using `JS::Handle`
for `m_stream` in its members.
2023-08-19 15:12:00 +02:00
Andreas Kling
72c9f56c66 LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449.

While going through these, I also changed the function signature in many
places where returning ThrowCompletionOr<T> is no longer necessary.
2023-08-13 15:38:42 +02:00
Andreas Kling
18c54d8d40 LibJS: Make Cell::initialize() return void
Stop worrying about tiny OOMs.

Work towards #20405
2023-08-08 07:39:11 +02:00
Andreas Kling
25eee91811 AK: Make "foo"_fly_string infallible
Stop worrying about tiny OOMs.

Work towards #20405.
2023-08-07 16:03:27 +02:00
Andreas Kling
34344120f2 AK: Make "foo"_string infallible
Stop worrying about tiny OOMs.

Work towards #20405.
2023-08-07 16:03:27 +02:00
Sam Atkins
f6e4caf197 LibWeb: Implement the :buffering and :stalled pseudo-classes
Currently, HTMLMediaElement doesn't implement the stall timeout, so
`:stalled` always returns false.
2023-08-01 12:50:40 -04:00
Sam Atkins
c8a51f232d LibWeb: Implement the :muted pseudo-class 2023-08-01 12:50:40 -04:00
Sam Atkins
7b4ae43b91 LibWeb: Implement the :seeking pseudo-class
This matches while a media element is seeking.
2023-08-01 12:50:40 -04:00
Sam Atkins
4df5e24926 LibWeb: Implement the :playing and :paused pseudo-classes
These match media elements (`<video>` and `<audio>`) which are playing
or paused, respectively.
2023-08-01 12:50:40 -04:00
Timothy Flynn
f57310999d LibWeb: Update workarounds for the empty execution context stack
Use the new helper class to perform this workaround.
2023-07-06 15:18:50 -04:00
Timothy Flynn
720d8889ad LibWeb: Allow changing media volume with keyboard controls
This allows increasing and decreasing the media volume by 10% with the
up and down arrow keys, respectively. This also allows toggling the mute
state with the M key.
2023-07-03 19:07:26 +02:00
Timothy Flynn
6a5229c2cb LibWeb: Allow seeking media elements with keyboard controls
This allows seeking backwards and forwards by 5 seconds with the left
and right arrow keys, respectively. This also allows seeking to the
beginning and end of the media track with the home and end keys.
2023-07-03 19:07:26 +02:00
Timothy Flynn
a4070b1452 LibWeb: Allow toggling playback of media elements with keyboard controls
This allows pausing/playing media elements with the space bar.
2023-07-03 19:07:26 +02:00
Timothy Flynn
3793b7c6bd LibWeb: Move helper to toggle a media element's playback to the element
This will be needed elsewhere.
2023-07-03 19:07:26 +02:00
Timothy Flynn
435ced70b8 LibWeb: Update the media element's display in a couple situations
Mostly seen on macOS, but when we toggle playing a media element, we
need to update its layout node's display to ensure the change is
reflected on the playback button. Further, when setting the element's
display time, we need to update the display to ensure the change is
refelected on the media timeline.
2023-07-03 19:07:26 +02:00
Andreas Kling
21260ea2ef LibWeb: Merge did_remove_attribute() into attribute_changed()
Instead of having two virtuals for attribute change notifications,
there is now only one. When the attribute is removed, the value is null.
2023-07-03 19:04:45 +02:00
Andreas Kling
5a74486b59 LibWeb: Rename DOM::Element::parse_attribute() => attribute_changed()
This is a first step towards merging attribute change and removal
notifications into a single function.
2023-07-03 19:04:45 +02:00
Zaggy1024
c760713650 LibWeb: Prioritize video duration when loading video element media
Previously, an audio loader could succeed for an HTMLVideoElement that
contains a video file, which caused the duration to be set to the bogus
duration of the audio loader instead of the correct duration from the
video container. Instead of setting the duration based on audio always,
set it to the video duration if we are creating a video element.
2023-06-24 06:20:06 +02:00
Timothy Flynn
1c991e5582 LibWeb: Add missing invocation to forget a media element's tracks
On bandcamp, this missing invocation would cause a playlist to loop one
single track indefinitely.
2023-06-22 14:58:43 +02:00
Timothy Flynn
9df2d6ee0f LibWeb: Implement scrubbing of the media element timeline and volume
This implements the ability to drag the timeline and volume buttons on
UA-rendered media controls. The two behave a bit differently:

Volume is updated as the user drags the volume button. This isn't a very
expensive operation, so updating in real-time and hearing the volume
change feels nice.

The current time, on the other hand, is not committed until the user
releases the mouse button. Performing a seek every time we get a mouse-
move event is pretty laggy, especially for video. However, we still want
to render updates on the timeline itself (so the position of the button
and the timestamp update as you drag). To do so, we internally pause the
media and override the timestamp provided to the layout node.

In the future, we may be able to seek video periodically to provide some
visual feedback. For example, we can seek after every N seconds of
scrubbing, or when the user pauses scrubbing for a while.
2023-06-22 06:58:07 +02:00
Luke Wilde
26f8a441f5 LibWeb: Add audio mime types to HTMLMediaElement.canPlayType
Now that we support audio, we can start correctly reporting we support
certain audio mime types!

Required by certain sites like Gartic Phone, which fails to load audio
because we didn't return a non-empty string for `audio/mpeg`:
```
"https://garticphone.com/sounds/turnundefined", Error: Load failed: 404
```

```js
(new Audio).canPlayType("audio/mpeg") && (this._extension = ".mp3"),
```
2023-06-17 06:26:56 -04:00
Timothy Flynn
a4cb3b5d4d LibWeb: Draw a speaker on media elements to toggle muting audio 2023-06-16 13:50:15 +02:00
Timothy Flynn
55b61724a0 LibWeb: Handle media elements being painted before their duration is set
It can take some time to download / decode a media resource. During this
time, its duration is set to NaN. The media control box would then have
some odd rendering glitches as it tried to treat NaN as an actual time.
Once we do have a duration, we also must ensure the media control box is
updated.
2023-06-16 13:50:15 +02:00
Timothy Flynn
b9e4dc2cb7 LibWeb: Implement the HTMLMediaElement volume and muted IDL attributes 2023-06-16 13:50:15 +02:00
Timothy Flynn
0c4b28faf3 LibWeb: Dispatch an addtrack event for newly created audio tracks 2023-06-14 17:54:40 +02:00
Timothy Flynn
6520a9a849 LibWeb: Support TrackEvent instances with an AudioTrack track type 2023-06-14 17:54:40 +02:00
Timothy Flynn
ac2238ee70 LibWeb: Begin implementing the HTMLAudioElement for audio playback
This uses LibAudio to attempt to decode resoures downloaded with <audio>
elements, and draws some basic media controls for the element.
2023-06-13 06:14:01 +02:00
Timothy Flynn
c89fd6dff0 LibWeb: Implement the AudioTrack and AudioTrackList interfaces
These are used to own and manage the playing of audio data.
2023-06-13 06:14:01 +02:00
Hendiadyoin1
eeb15fc10b LibWeb: Stop lying about string types 2023-06-13 01:49:02 +02:00
Timothy Flynn
8ff8309202 LibWeb: Update workarounds for fetching CORS cross-origin responses
Now that the processResponseConsumeBody algorithm receives the internal
response body of the fetched object, we do not need to go out of our way
to read its body from outside of fetch.

However, several elements do still need to manually inspect the internal
response for other data, such as response headers and status. Note that
HTMLScriptElement already does the new workaround as a proper spec step.
2023-05-29 17:12:46 +02:00