Commit Graph

1286 Commits

Author SHA1 Message Date
Andreas Kling
3c7b0192fa LibWeb: Load external images with image/svg+xml as SVG-as-image 2023-05-21 07:44:29 +02:00
Andreas Kling
41ab0837fa LibWeb: Render SVG-as-image into an isolated top-level browsing context
In order to separate the SVG content from the rest of the engine, it
gets its very own Page, PageClient, top-level browsing context, etc.

Unfortunately, we do have to get the palette and CSS/device pixel ratios
from the host Page for now, maybe that's something we could refactor in
the future.

Note that this doesn't work visually yet, since we don't calculate the
intrinsic sizes & ratio for SVG images. That comes next. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
e63f68661f LibWeb: Have ImageProvider bitmap getter take optional size argument
This allows the painting subsystem to request a bitmap with the exact
size needed for painting, instead of being limited to "just give me a
bitmap" (which was perfectly enough for raster images, but not for
vector graphics).
2023-05-21 07:44:29 +02:00
Andreas Kling
8d3240d633 LibWeb: Make ImageBox ask ImageProvider for intrinsic size and ratio
This paves the way for ImageProvider to have something vector-based
underneath. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
4ee1e5b224 LibWeb: Make DecodedImageData an abstract class
The existing implementation moves down into a new subclass called
AnimatedBitmapDecodedImageData.

The purpose of this change is to create an extension point where we can
plug in an SVG renderer. :^)
2023-05-21 07:44:29 +02:00
Andreas Kling
f823b297b4 LibWeb: Push the realm execution context while linking modules
If linking fails, we throw a JS exception, and if there's no execution
context on the VM stack at that time, we assert in VM::current_realm().

This is a hack to prevent crashing on failed module loads. Long term we
need to rewrite module loading since it has been refactored to share
code differently between HTML and ECMA262.
2023-05-19 06:20:14 +02:00
Andreas Kling
819fb39a87 LibWeb: Implement the "error to rethrow" mechanism in HTML::Script
This allows JS module loads to fail and throw without crashing the
WebContent process due to a TODO() assertion.
2023-05-19 06:20:14 +02:00
Andreas Kling
f063eb3218 LibWeb: Add missing call to Base in VideoTrack::visit_edges()
This fixes a GC crash that happened after a while on the Steam store.
2023-05-17 13:09:02 -07:00
Andreas Kling
5bb6e2c80c LibWeb: Null-check layout node before dereferencing in HTMLVideoElement
DOM elements don't always have a corresponding layout node. This fixes a
crash soon after loading the Steam store.
2023-05-17 13:09:02 -07:00
Luke Wilde
00493687f2 LibWeb: Implement location.assign 2023-05-16 11:25:44 +02:00
Sam Atkins
9c2d496dbe LibWeb: Make processBodyError take an optional exception
Changed here:
018ac19838
2023-05-15 16:28:16 +02:00
Andreas Kling
20e2c9a7dd LibWeb: Cache state of the contenteditable attribute on HTMLElement
Instead of recomputing the state whenever someone asks for it, we now
cache it when the attribute is added/changed/removed.

Before this change, HTMLElement::is_editable() was 6.5% of CPU time
when furiously resizing Hacker News. After, it's less than 0.5%. :^)
2023-05-15 14:08:20 +02:00
Andreas Kling
719f1db6c9 LibWeb: Protect against dereferencing a null pending image request
The spec seems to neglect the potential nullity of an image's pending
request in various cases.

Let's protect against crashing and mark these cases with a FIXME about
figuring out whether they are really spec bugs or not.
2023-05-14 10:25:25 +02:00
Luke Wilde
036e1e1bcf LibWeb: Implement performance.{measure,clearMeasures} 2023-05-13 16:31:10 +02:00
Timothy Flynn
05019746d2 LibWeb: Partially implement HTMLSourceElement's insertion/removal steps
This implements the substeps which concern HTMLMediaElement parents.
2023-05-13 15:51:44 +02:00
Timothy Flynn
c161a0fc49 LibWeb: Implement the HTMLMediaElement child <source> selection steps
Rather than setting the src attribute on the HTMLMediaElement, websites
may append a list of HTMLSourceElement nodes to the media element. There
is a series of "try the next source" steps to attempt to fetch/load each
source until we find one that works.
2023-05-13 15:51:44 +02:00
Andreas Kling
9d78619b59 LibWeb: Let HTMLImageElement delay the document load event again 2023-05-13 09:08:42 +02:00
Andreas Kling
c648e24cff LibWeb: Don't force HTMLImageElement to have a legacy ImageLoader
We achieve this by adding a new Layout::ImageProvider class and having
both HTMLImageElement and HTMLObjectElement inherit from it.

The HTML spec is vague on how object image loading should work, which
is why this first pass is focusing on image elements.
2023-05-13 09:08:42 +02:00
Andreas Kling
3cf73ca0b3 LibWeb: Implement enough of "update the image data" to load images
This first pass is enough to get us:
- Image loading via fetch
- Source selection via srcset and sizes attributes
2023-05-13 09:08:42 +02:00
Andreas Kling
6fe4fcb74b LibWeb: Add a class to represent the "source set" concept from HTML
Also comes with a little extra CSS parser helper for parsing "sizes"
attributes in images.
2023-05-13 09:08:42 +02:00
Andreas Kling
9281bf7a01 LibWeb: Add class to represent "list of available images" from HTML spec 2023-05-13 09:08:42 +02:00
Andreas Kling
596eabe9e6 LibWeb: Start fleshing out HTML "image requests" and "image data"
This patch adds HTML::ImageRequest and HTML::DecodedImageData.

The latter had to use a different name than "ImageData", as there is
already an IDL-exposed ImageData class in HTML.
2023-05-13 09:08:42 +02:00
Timothy Flynn
a84e64ed22 LibWeb: Implement fetching classic scripts using Fetch infrastructure 2023-05-12 05:47:36 +02:00
Timothy Flynn
12976b74ca LibWeb: Implement the fetch a classic script AO
Note that this unfortunately requires the same workaround as <link>
elements to handle CORS cross-origin responses.
2023-05-12 05:47:36 +02:00
Timothy Flynn
567b8da1e0 LibWeb: Change the script fetch completion callback to accept any script
The completion callback currently only accepts a JavaScriptModuleScript.
The same callback will need to be used for ClassicScript scripts as well
so allow the callback to accept any Script type. The single existing
outside caller already stores the result as a Script.
2023-05-12 05:47:36 +02:00
Timothy Flynn
9701128145 LibWeb: Implement the CORS settings attribute credentials mode AO 2023-05-12 05:47:36 +02:00
Andreas Kling
6ae208dbf6 LibWeb: Broadcast the viewport rect to clients immediately after layout
This lets elements figure out if they're visible within the viewport or
not, so they take appropriate action.

Fixes the issues with animations not starting until the viewport was
resized or scrolled.
2023-05-09 09:48:49 +02:00
Timothy Flynn
872e18f660 LibWeb: Convert Navigable::navigate's csp_navigation_type to an enum
Some versions of clang will have an issue using a consteval function to
set the optional parameter's default value. For example, see:
https://stackoverflow.com/questions/68789984/immediate-function-as-default-function-argument-initializer-in-clang

This doesn't need to be a String anyways, so let's make it an enum.
2023-05-08 20:54:31 -06:00
Aliaksandr Kalenik
5896f4c400 LibWeb: Implement "populate session history entry" step in navigate()
Implements
https://html.spec.whatwg.org/multipage/browsing-the-web.html#finalize-a-cross-document-navigation
2023-05-08 17:53:59 +02:00
Aliaksandr Kalenik
0444df1a7c LibWeb: Implement "clear the forward session history" for traversable
https://html.spec.whatwg.org/multipage/browsing-the-web.html#clear-the-forward-session-history
2023-05-08 17:53:59 +02:00
Andreas Kling
064b7a6216 LibWeb: Make HTMLObjectElement invalidate the document layout
This is an oversized hammer for sure, but we have to make sure the
layout tree gets rebuilt in case the object representation changes.
Since "throw out the entire layout tree" is the finest tool we have
right now, it'll have to do.

This fixes an issue where the eyes on Acid2 would sometimes not show up
until the next layout invalidation occurred.
2023-05-08 10:26:09 +02:00
Andreas Kling
70db40c9b0 LibWeb: Don't include Layout/Node.h from DOM/Element.h
This required moving the CSS::StyleProperty destruct out of line.
2023-05-08 09:29:44 +02:00
Andreas Kling
e43027091d LibWeb: Don't include HTML/Window.h from DOM/Element.h
This required moving HTML::ScrollOptions to its own header file.
2023-05-08 09:29:44 +02:00
Andreas Kling
4637d020c3 LibWeb: Add fast_is<T>() helper for HTMLScriptElement
This makes loading Google Groups quite a bit faster, as 20% of runtime
while loading was spent asking if DOM nodes are HTMLScriptElement.
2023-05-07 10:47:30 +02:00
Ben Wiederhake
36ff6187f6 Everywhere: Change spelling of 'behaviour' to 'behavior'
"The official project language is American English […]."
5d2e915623/CONTRIBUTING.md (L30)

Here's a short statistic of the occurrences of the word "behavio(u)r":

$ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n
      2 BEHAVIOR
     24 Behaviour
     32 behaviour
    407 Behavior
    992 behavior

Therefore, it is clear that "behaviour" (56 occurrences) should be
regarded a typo, and "behavior" (1401 occurrences) should be preferred.

Note that The occurrences in LibJS are intentionally NOT changed,
because there are taken verbatim from the specification. Hence:

$ git grep -IPioh 'behaviou?r' | sort | uniq -c | sort -n
      2 BEHAVIOR
     10 behaviour
     24 Behaviour
    407 Behavior
   1014 behavior
2023-05-07 01:05:09 +02:00
Sam Atkins
f4d8a24fe4 LibWeb: Propagate errors from parse_css_value and property_initial_value 2023-05-06 08:07:28 +02:00
Sam Atkins
d16600a48b LibWeb: Propagate errors from StyleValue construction
Turns out we create a lot of these, mostly from places that don't return
ErrorOr. The yak stack grows.
2023-05-06 08:07:28 +02:00
Andreas Kling
66c41e7c45 LibWeb: Use JS::SafeFunction for module fetching callbacks
This fixes another GC crash seen on https://shopify.com/

Found it by collecting garbage after every 500th heap allocation.
2023-05-04 18:30:57 +02:00
Timothy Flynn
ac8b892a25 LibWeb: Pause HTMLMediaElement when its document becomes inactive
For example, when navigating to another page, this ensures any media
resource will not continue playing.
2023-05-04 16:48:10 +02:00
Timothy Flynn
88b8969443 LibWeb: Implement steps for removing an HTMLMediaElement from a document 2023-05-04 16:48:10 +02:00
Andreas Kling
3811be2f7c LibWeb: Make module maps GC-allocated
This allows them to mark JS modules, and fixes a crash seen on
https://shopify.com/
2023-05-04 11:56:55 +02:00
Aliaksandr Kalenik
e1c1aaa956 LibWeb: Implement "create navigation params from a srcdoc resource"
Implements:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-from-a-srcdoc-resource

This is supporting function for populating document in session history
entry.

This function populates navigation params response with HTML text
passed in document resource.
2023-05-03 09:39:49 +02:00
Aliaksandr Kalenik
c235ee380f LibWeb: Implement "create navigation params by fetching"
Implements:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching

This is supporting function for population of document in a session
history entry.

This function populates response in navigation params by fetching url
in navigation params and handling redirects if required.
2023-05-03 09:39:49 +02:00
Aliaksandr Kalenik
de2c016556 LibWeb: Implement "attempt to populate the history entry's document"
Implements:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#attempt-to-populate-the-history-entry's-document

This is going to be a replacement for `FrameLoader::load()` after
switching to navigables.

Brief description of `populate_session_history_entry_document`:
- If navigation params have url with fetch scheme then DOM document
  will be populated by fetching url and parsing response. This
  is going to be a replacement for `FrameLoader::load(AK::URL&)`.
- If url in navigation params is abort:srcdoc then DOM document
  will be populated by parsing HTML text passed in document resource.
  This is going to be a replacement for `FrameLoader::load_html()`
2023-05-03 09:39:49 +02:00
Aliaksandr Kalenik
60a26077a7 LibWeb: Reuse ReferrerType from Fetch in HTML::DocumentState 2023-05-03 09:39:49 +02:00
Aliaksandr Kalenik
a27a30898c LibWeb: Add fetch_controller property in HTML::NavigationParams 2023-05-03 09:39:49 +02:00
Aliaksandr Kalenik
38a2d5ead3 LibWeb: Add navigable property in NavigationParams 2023-05-03 09:39:49 +02:00
Aliaksandr Kalenik
0c919718ae LibWeb: Change id to be optional in HTML::NavigationParams 2023-05-03 09:39:49 +02:00
Aliaksandr Kalenik
71b7a929db LibWeb: Fix typo in HTML::DocumentState
ever_navigable_target_name -> navigable_target_name
2023-05-03 09:39:49 +02:00
Aliaksandr Kalenik
f738a166f2 LibWeb: Add resource property in DocumentState 2023-05-03 09:39:49 +02:00