Commit Graph

902 Commits

Author SHA1 Message Date
Andreas Kling
1e92081546 LibWeb: Avoid some heap churn during text splitting
Use Vector capacity while splitting text into chunks (to avoid many
small heap allocations.)
2020-11-22 13:48:43 +01:00
Andreas Kling
10b534849d LibWeb: Remove ancient HTML_DEBUG debug logging 2020-11-19 23:10:21 +01:00
Andreas Kling
adabcf24ec Everywhere: Add missing <AK/ByteBuffer.h> includes
All of these files were getting ByteBuffer.h from someone else and then
using it. Let's include it explicitly.
2020-11-15 13:11:21 +01:00
Luke
ed2689c00a LibWeb: Use standardized encoding names, add encoding attribute to document 2020-11-14 10:14:03 +01:00
Luke
1993ccb456 LibWeb: Add default values of URL and content type in document
As per this line in the specification:
Unless stated otherwise, a document’s encoding is the utf-8 encoding,
content type is "application/xml", URL is "about:blank", origin is an
opaque origin, type is "xml", and its mode is "no-quirks".

https://dom.spec.whatwg.org/#document
2020-11-13 09:51:07 +01:00
Luke
dcb21b0c3a LibWeb: Add initial implementation of document.implementation 2020-11-13 09:51:07 +01:00
Luke
3ec54448f5 LibWeb: Add contentType attribute to Document 2020-11-13 09:51:07 +01:00
Andreas Kling
81add73955 LibWeb: Make Frame point weakly to Page
This patch makes Page weakable and allows page-less frames to exist.

Page is single-owner, and Frame is multiple-owner, so it's not sound
for Frame to assume its containing Page will stick around for its own
entire lifetime.

Fixes #3976.
2020-11-12 18:29:55 +01:00
Luke
3f73b0f896 LibWeb: Add almost all obsolete but required IDL attributes
As according to https://html.spec.whatwg.org/multipage/obsolete.html
Section 16.3 "Requirements for implementations"

Not all of these attributes are included due to requiring a bit more
functionality.
2020-11-12 10:38:26 +01:00
Luke
62a74bf282 LibWeb: Advertise to servers that we support gzip encoding
We've had gzip support for a while now, but it never really got
used because we never advertised it.
2020-11-11 12:15:18 +01:00
Luke
397049aae8 LibWeb: Move innerText from DOM::Element to HTML::HTMLElement 2020-11-11 12:15:05 +01:00
Luke
bb22b04d44 LibWeb+LibJS: Add [LegacyNullToEmptyString] attribute
If specified, to_string() returns an empty string instead of "null" for
null values.
2020-11-11 12:15:05 +01:00
Tom
75f61fe3d9 AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safe
This makes most operations thread safe, especially so that they
can safely be used in the Kernel. This includes obtaining a strong
reference from a weak reference, which now requires an explicit
call to WeakPtr::strong_ref(). Another major change is that
Weakable::make_weak_ref() may require the explicit target type.
Previously we used reinterpret_cast in WeakPtr, assuming that it
can be properly converted. But WeakPtr does not necessarily have
the knowledge to be able to do this. Instead, we now ask the class
itself to deliver a WeakPtr to the type that we want.

Also, WeakLink is no longer specific to a target type. The reason
for this is that we want to be able to safely convert e.g. WeakPtr<T>
to WeakPtr<U>, and before this we just reinterpret_cast the internal
WeakLink<T> to WeakLink<U>, which is a bold assumption that it would
actually produce the correct code. Instead, WeakLink now operates
on just a raw pointer and we only make those constructors/operators
available if we can verify that it can be safely cast.

In order to guarantee thread safety, we now use the least significant
bit in the pointer for locking purposes. This also means that only
properly aligned pointers can be used.
2020-11-10 19:11:52 +01:00
Luke
e2e6b03a45 LibWeb: Add support for reflected boolean values
Also throw in some missing reflected DOMString values
2020-11-09 09:51:22 +01:00
Linus Groh
b97a900595 LibWeb: Don't attempt to create new bitmap for zero-size OOPWV
It's not possible to construct a Gfx::Bitmap with empty size. Let the
client know the new viewport rect and return before even attempting to
create new front and back bitmaps.

Also consider that we might have to paint the widget but not have a
front/back bitmap available (e.g. when only part of a scrollbar is
visible, and the inner rect is empty).
2020-11-08 17:21:11 +01:00
Andreas Kling
2d96a07b26 LibWeb: Don't assume backing store allocation succeeds on OOPWV resize
Backing store allocation can fail if the requested size is too small,
or too large. We should not crash when this happens.

Fixes #3986.
2020-11-08 16:16:03 +01:00
Andreas Kling
a49802558d LibWeb: Use the system theme's button text color for <input> buttons 2020-11-08 01:36:45 +01:00
Brendan Coles
02d6252949 LibWeb: Restrict HTML form submissions to permitted URL protocols
Form submissions to file:// URLs are now permitted only if the
submitting document is also a file:// URL and the form method is "get".

Form submissions to URLs with a http(s):// URL protocol are permitted.

Form submissions for all other URL protocols are rejected.
2020-11-07 17:57:22 +01:00
Brendan Coles
a950d3dd5f LibWeb: Reject iframing file:// URLs if document is not a file:// URL 2020-11-07 10:53:09 +01:00
Brendan Coles
a0130b55d4 LibWeb: Load favicon.ico only for http/https URLs 2020-11-07 10:05:35 +01:00
AnotherTest
060ddd2a7a AK: Really disallow making OwnPtrs from refcounted types
This looks at three things:
- if the type has a typedef `AllowOwnPtr', respect that
- if not, disallow construction if both of `ref()' and `unref()' are
  present.
Note that in the second case, if a type only defines `ref()' or only
defines `unref()', an OwnPtr can be created, as a RefPtr of that type
would be ill-formed.

Also marks a `Performance' to explicitly allow OwnPtrs.
2020-11-03 19:14:34 +01:00
Brendan Coles
3482b9b937 LibWeb: Enforce Same-Origin Policy (SOP) for XMLHttpRequest requests
`DOM::XMLHttpRequest` now checks if the requested URL has the same
`Origin` as the requesting `Document`. If the requested URL is in
violation of SOP the request is rejected and an "error" `DOM::Event`
is dispatched.
2020-11-01 10:23:08 +01:00
Linus Groh
e5ec4d35ea LibWeb: Don't use 'font-weight: lighter' for Csilla in Default.css
Base/res/fonts/CsillaThin7x10.font was renamed to
Base/res/fonts/CsillaRegular10.font in 5abc03d, breaking the default
styles of <code> and <pre>.
The font lookup should still find a font variant when a non-existent
weight is specified, but that's another issue for another day.
2020-10-31 20:52:54 +01:00
Andreas Kling
aef56159a8 LibGUI: Add Widget focus policies
Every widget now has a GUI::FocusPolicy that determines how it can
receive focus:

- NoFocus: The widget is not focusable (default)
- TabFocus: The widget can be focused using the tab key.
- ClickFocus: The widget can be focused by clicking on it.
- StrongFocus: Both of the above.

For widgets that have a focus proxy, getting/setting the focus policy
will affect the proxy instead.
2020-10-30 17:03:28 +01:00
Andreas Kling
5abc03db0d Fonts: Rename font files consistently
Font files are now all named like this:

    <Family><Weight><Size>.font

This will make it much easier/sane to perform font lookup.
2020-10-25 10:12:03 +01:00
asynts
88bca152c9 AK: Eradicate the uses of out(). 2020-10-24 12:56:25 +02:00
Andreas Kling
bf1ed34236 LibWeb: Don't send OOPWV repaint requests for views without backing
This fixes an assertion in TextEditor when changing the system theme,
since that would trigger a repaint request for the HTML preview widget
which may not have backing unless it's actually been used to perform
HTML (or Markdown) preview yet.
2020-10-24 12:30:21 +02:00
Andreas Kling
46c15276e9 LibWeb: Fix Document construction mishap in <template> element
Ref-counted objects must not be stack allocated. Make DOM::Document's
constructor private to avoid this issue. (I wish we could mark classes
as heap-only..)
2020-10-23 08:33:16 +02:00
Andreas Kling
f79e28bd65 LibWeb: Break reference cycles so DOM::Document actually gets deleted
When a document reaches ref_count==0, we will now remove all of the
descendant nodes from the document, and also break all the explicit
links (such as the currently hovered element.)

Basically, DOM nodes will keep the document alive even after the
document reaches ref_count==0. This allows JS wrappers to stay alive
and keep the document alive as well. This matches the behavior of
at least some other browsers.

This patch also adds a bunch of sanity checking assertions around
DOM teardown, to help catch mistakes in the future.

Fixes #3771.
2020-10-22 23:41:32 +02:00
Andreas Kling
018b458962 LibWeb: Make sure nodes are adopted when moving between documents
Otherwise, the "referencing node count" accounting won't be accurate,
and anything that accesses the document will be confused.
2020-10-22 23:37:17 +02:00
Andreas Kling
c67b45aa1f LibWeb: Forget frame selection when changing documents
The old selection is obviously not relevant in the new document.
2020-10-22 23:23:57 +02:00
Andreas Kling
8de743a878 LibWeb: Remove unused TreeNode::donate_all_children_to() 2020-10-22 23:14:23 +02:00
Andreas Kling
385d744989 LibWeb: Use smart pointers between DOM and Layout tree
DOM::Node now points to its LayoutNode with a WeakPtr.
LayoutNode points to its DOM::Node and DOM::Document with RefPtrs.

Layout trees come and go in response to various events, so the DOM tree
already has to deal with that. The DOM should always live at least as
long as the layout tree, so this patch enforces that assumption by
making layout nodes keep their corresponding DOM objects alive.

This may not be optimal, but it removes a lot of ambiguous raw pointer
action which is not worth accomodating.
2020-10-22 20:26:32 +02:00
Andreas Kling
5fdc8c14a6 LibWeb: Make Nodes actually ref/unref their Document
Oops, it seems like I implemented all of the "nodes keep the document
alive" mechanism except the part where the functions are actually
called. :^)

Fixes #3811.
2020-10-22 18:48:01 +02:00
Luke
4e8cb4558b LibWeb: Add initial implementation of foreign content parsing
Plus sneak in a FIXME for the list of active formatting elements
and a test for Element.namespaceURI
2020-10-22 15:24:42 +02:00
Luke
e8a9e8aed5 LibWeb: Add namespace to Element 2020-10-22 15:24:42 +02:00
Luke
efaf03e986 LibWeb: Use modern namespaces and fix clang-format comments in tag names 2020-10-22 15:24:42 +02:00
Tom
6413acd78c AK: Make Utf8View and Utf32View more consistent
This enables use of these classes in templated code.
2020-10-22 15:23:45 +02:00
Andreas Kling
5043c4a3e5 LibCore+WebServer+LibWeb: Make MIME type guesser take a StringView
This reverts my previous commit in WebServer and fixes the whole issue
in a much better way. Instead of having the MIME type guesser take a
URL (which we don't actually have in the WebServer at that point),
just take a path as a StringView.

Also, make use of the case-insensitive StringView::ends_with() :^)
2020-10-21 21:16:20 +02:00
Andreas Kling
0af2795662 LibWeb: Tear down layout trees properly
Instead of just ripping out the root of the layout tree from its RefPtr
in Document, actually go through the DOM and gather up all the layout
nodes. Then destroy them all in one swoop.

Also, make sure to do this when detaching Document from Frame,
to enforce the invariant that layout only occurs in framed documents.
2020-10-20 18:08:37 +02:00
Andreas Kling
24162127ba LibWeb: Dispatch "load" on document and window
These happen right after "DOMContentLoaded" for now, which is incorrect
since they should really wait until subresources have loaded.
However, this makes a bunch of things work already so let's do it.
2020-10-18 13:45:28 +02:00
Andreas Kling
b71c1851b7 LibWeb: Dispatch "load" event on script elements 2020-10-18 13:44:20 +02:00
Andreas Kling
b92bc9c6e5 LibWeb: Make DOM::Window into an EventTarget
This will allow us to dispatch window events.
2020-10-18 13:43:44 +02:00
Linus Groh
ac98a48177 LibWeb: Fix EventDispatcher::dispatch()
We were never wrapping and using the actual DOM::Event but instead
wrapped the *target* twice and passed it to the event listener callback,
as this value and as argument.

This unbreaks "fun demo" and "canvas path quadratic curve test" - and
event dispatching in general, of course :^)

Fixes #3721.
2020-10-15 20:40:35 +02:00
Andreas Kling
f68ed6d25b LibWeb: Make DOM Nodes keep their Document alive
In addition to being reference-counted, all nodes that are part of a
document must also keep the document alive.

This is achieved by adding a second ref-count to the Document object
and incrementing/decrementing it whenever a node is created/destroyed
in that document.

This brings us much closer to a proper DOM lifetime model, although
the JS bindings still need more work.
2020-10-11 21:52:59 +02:00
Andreas Kling
99acbbe86b LibWeb: Remove unused Document::fixup()
This was some naive fixup mechanism we used before implementing a spec
compliant HTML parser.
2020-10-11 21:24:14 +02:00
Matthew Olsson
455ce0b9c3 LibWeb: Create LayoutNodes for each SVG element
This brings the SVG API closer to the rest of LibWeb
2020-10-10 23:28:41 +02:00
Matthew Olsson
f2055bb509 LibWeb: Add a basic SVGContext object, add to PaintContext
This will be used to transmit any svg-relevant data between svg nodes.
This is prep for moving a lot of the SVG logic into Layout nodes.
2020-10-10 23:28:41 +02:00
Matthew Olsson
0b3b6310ec LibWeb: Add {before,after}_children_paint() methods
This allows layout nodes to do some setup before their children paint,
and cleanup after their children paint. This will be used for SVG
components, where their attributes (like stroke width, fill color, etc)
need to be correctly propogated to layout nodes down the line.
2020-10-10 23:28:41 +02:00
Luke
4155de2572 LibWeb: Cache the default font if we fail to find the specified font
This is a hack to stop chewing CPU on sites that use a font we don't
have and have a lot of text or changes text often.

Examples are the Serenity 2nd birthday page and the JS specification.
2020-10-10 23:25:19 +02:00