Commit Graph

396 Commits

Author SHA1 Message Date
Timothy Flynn
1322fed4c8 LibWeb+WebContent: Do not include DOM HTML in text test expectations
For example, in the following abbreviated test HTML:

    <span>some text</span>
    <script>println("whf")</script>

We would have to craft the expectation file to include the "some text"
segment, usually with some leading whitespace. This is a bit annoying,
and makes it difficult to manually craft expectation files.

So instead of comparing the expectation against the entire DOM inner
text, we now send the inner text of just the <pre> element containing
the test output when we invoke `internals.signalTextTestIsDone`.

(cherry picked from commit bf668696de9a68bbcd6adfeaac809a475da015dc;
amended a bit but not as much as one might think -- see PR for details)
2024-11-24 22:42:15 -05:00
Timothy Flynn
6cbfce87bd LibWeb+LibWebView: Set the default path for invalid cookie Path values
We were missing this spec step when parsing the Path attribute.

(cherry picked from commit e74d2b17620b1d68d66d51a13831ee1657154a1c)
2024-11-24 21:30:22 -05:00
Aliaksandr Kalenik
360fa4a0bf Everywhere: Hand pid of new process to client in launch_server_process()
Allows WebContentClient to get pid of WebContent process right after
creation, so there is no window between forking and
notify_process_information() IPC response, when client doesn't know the
pid.

(cherry picked from commit c46bea479c1cbf9bb9a30cbecaaa10c85a4ba321)
2024-11-24 20:50:01 -05:00
Timothy Flynn
bd845f87a1 LibWeb+LibWebView: Implement the latest cookie draft RFC
We currently implement the official cookie RFC, which was last updated
in 2011. Unfortunately, web reality conflicts with the RFC. For example,
all of the major browsers allow nameless cookies, which the RFC forbids.

There has since been draft versions of the RFC published to address such
issues. This patch implements the latest draft.

Major differences include:
* Allowing nameless or valueless (but not both) cookies
* Formal cookie length limits
* Formal same-site rules (not fully implemented here)
* More rules around cookie domains

(cherry picked from commit fce003a8f581a49d1c6e6472e33b8250052530db)
2024-11-24 17:29:26 -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
52099ff54d LibWebView: Generate hyperlinks for attributes that represent links
On the view-source page, generate anchor tags for any 'href' or 'src'
attribute value we come across. This handles both when the attribute
contains an absolute URL and a URL relative to the page.

This requires sending the document's base URL over IPC to resolve
relative URLs.

(cherry picked from commit 1aab7b51ea9c27a6ffff8df0c8bcbec87680865c;
amended to update `on_received_source` signature in Browser too)
2024-11-17 11:03:57 -05:00
Sam Atkins
c7613b186b LibWebView+UI: Highlight CSS in the style sheet inspector
(cherry picked from commit f0dd0c51073823ad2e30041896030a2831419786)
2024-11-16 14:05:12 -05:00
Sam Atkins
c74ee65745 LibWebView: Move line-number styling into HTML_HIGHLIGHTER_STYLE
(cherry picked from commit af23f3890b1a8ecb767b956a16b2146534253139)
2024-11-16 14:05:12 -05:00
Sam Atkins
5aaec92e6c LibWebView: Preserve whitespace in view-source
(cherry picked from commit e03da0e60037e41cf1a36af6bb9eaf017d71eadd)
2024-11-16 14:05:12 -05:00
Sam Atkins
29d71d8574 LibWebView: Highlight CSS and JS in view-source
The colors and categories here could probably be better, but it works.
:^)

(cherry picked from commit bd6fdbf312bedaae4bb5d95167e4262ec37fc4eb)
2024-11-16 14:05:12 -05:00
Sam Atkins
40b5c35c8a LibWebView: Use custom properties for syntax-highlighting colors
(cherry picked from commit 66c39f3da4938be13460e7d248da95cb2d1a411d)
2024-11-16 14:05:12 -05:00
Sam Atkins
13a3e93e08 LibWebView: Use LibSyntax to highlight document source
This has no visible effect, but internally it's also highlighting any
CSS and JS embedded in the page, which will be made use of later. We'll
also be able to use this code for highlighting CSS or JS files directly
in the future.

It's not a perfect fit - the syntax highlighters give specific styles to
their spans, which we then ignore and just use their data integer to
figure out which CSS class to give to the span. It feels cleaner to me
to produce HTML styled that way, instead of every token having
`style="color: ...; font-weight: ...; text-decoration: ...;"` set on
it.

Most of this new `to_html_string()` code is adapted from Serenity's
`TextEditor::paint_event()`, so it should be pretty solid.

(cherry picked from commit 1db243c0060c2ae74194f3c5996093b8507ba095;
amended to fix tiny conflict in CMakeLists.txt)
2024-11-16 14:05:12 -05:00
Sam Atkins
d094c2984b Inspector: Add a basic style sheet inspector
Choosing options from the `<select>` will load and display that style
sheet's source text, with some checks to make sure that the text that
just loaded is the one we currently want.

The UI is a little goofy when scrolling, as it uses `position: sticky`
which we don't implement yet. But that's just more motivation to
implement it! :^)

(cherry picked from commit da171c3230caaee53213d0dd04007c9b4343e3e2)
2024-11-15 23:10:03 -05:00
Sam Atkins
5d86305596 Meta: Make embed_as_string_view.py produce Strings instead
This is only used for CSS style sheets. One case wants it as a String,
and the others don't care, but will in future also want to have the
source as a String.

(cherry picked from commit 8cbc2116162764479edeec78e4b2b7c41447b643;
amended to fix conflicts in two cmake files, due to serenity
still having more code_generators, and still buildling
OutOfProcessWebView.cpp. Also kept embed_as_string_view because
it's used by stringify_gml. Did this by giving embed_as_string.py
a --type= argument that defaults to string but can also be set
to string-view.)
2024-11-15 23:10:03 -05:00
Asutosh Variar
50cc1b5d63 Everywhere: Convert from_string_view -> from_string_literal where static
(cherry picked from commit 229b64a4b723a391c21f247d72d78cd575ace6ff;
minorly amended to fix conflict in image.cpp due to serenity in the
meantime adding webp writing support, and due to changes in Android and
Vulkan-related files that serenity doesn't have)
2024-11-15 08:56:39 -05:00
Sebastian-Webster
029cbbf61d LibWebView: Add Startpage search engine
(cherry picked from commit eec2602424d25cf4c83c6a87fa9e348ec6ed115a)
2024-11-14 17:46:06 -05:00
Douwe Zumker
cde2d51d27 LibWebView: Add GoogleScholar search engine to selection menu
(cherry picked from commit d6d94ba8cb07e1cd511d4ff1d7b34f01e4db06fd)
2024-11-13 10:17:34 -05:00
mrdcbrush
588d79e36e LibWebView: Add Kagi search engine to menu
LibWebView: Add Kagi search engine to selection menu
(cherry picked from commit b757ee0bc8863b7785fe6f5f15ae6d4d3c82896f)
2024-11-12 22:26:21 -05:00
Sebastian-Webster
584e555f33 LibWebView: Add Ecosia search engine
(cherry picked from commit b0e3b289299728583847590209f9ed4b9083bbe3)
2024-11-12 22:26:21 -05:00
Timothy Flynn
ae6599c07a LibWebView+WebContent+headless-browser: Make the page info IPCs async
The IPCs to request a page's text, layout tree, etc. are currently all
synchronous. This can result in a deadlock when WebContent also makes
a synchronous IPC call, as both ends will be waiting on each other.

This replaces the page info IPCs with a single, asynchronous IPC. This
new IPC is promise-based, much like our screenshot IPC.

(cherry picked from commit 3332230cef8091f94f5c30e1f1984c1038cd4a1d)
2024-11-12 10:45:53 -05:00
Nico Weber
163cd81156 LibWebView: Remove unused dump_layout_tree()
This was added in 9d03ea6f74 for LibWeb/DumpLayoutTree/main.cpp.
That utility was moved to LibViewView in #14018 and then deleted
in #18879 after #17836 moved that functionality to headless-browser.

No behavior change.
2024-11-12 10:45:53 -05:00
Timothy Flynn
9f9c9c8bcb LibWeb+LibWebView+WebContent: Return a named enum from UI event handlers
UI event handlers currently return a boolean where false means the event
was cancelled by a script on the page, or otherwise dropped. It has been
a point of confusion for some time now, as it's not particularly clear
what should be returned in some special cases, or how the UI process
should handle the response.

This adds an enumeration with a few states that indicate exactly how the
WebContent process handled the event. This should remove all ambiguity,
and let us properly handle these states going forward.

There should be no behavior change with this patch. It's meant to only
introduce the enum, not change any of our decisions based on the result.

(cherry picked from commit 541968b30dc50208f473566498100769711f10c8;
amended to fix tiny conflict in ConnectionFromClient.h due to serenity
not having #1182 yet)
2024-11-12 06:45:27 -05:00
Andreas Kling
e715c973cc LibWebView: Update User-Agent spoofing strings with new versions
Also use an OrderedHashMap so they show up in the same order in UI.

(cherry picked from commit a2a9a11466aba1ab357922e8bd0338222e3f4179)
2024-11-10 20:06:23 -05:00
ronak69
ec2ee2720a LibWebView: Do floating-point-error-free zoom calculation using rounding
The current min/max zoom levels are supposed to be: 30% and 500%.
Before, due to floating point error accumulation in incremental addition
of zoom-step into zoom-level, one extra zoom step would get allowed,
enabling user to zoom 20%-to-510%.

Now, using rounding, the intermediate zoom-level values should be as
close to the theoretical value as FP32 can represent. E.g. zoom-level of
70% (theoretical multiplier 0.7) is 0.69... .

(cherry picked from commit 96335f31d5a8c6180a4cc0254585bc01ba6742fa)
2024-11-10 10:46:01 -05:00
Timothy Flynn
2222b9f958 LibWebView: Properly handle new lines inside styled view-source elements
When we want to inject a CSS counter for a line, we need to be sure to
handle if we had previously opened a styled span for the current source
substring. For example, if we see a new line in the middle of a comment,
we will have previously opened the following tag:

    <span class="comment">

So when injecting a new line and the <span class="line"> element (for
CSS counters), we need to close the previous span and insert a newly
opened tag to continue using the style.

(cherry picked from commit f1395a2c3859fce1daddb385582433c072ebf052)
2024-11-09 07:29:52 -05:00
Timothy Flynn
335b527f19 LibWeb+LibWebView: Add a button to the Inspector to export its contents
When working on the Inspector's HTML, it's often kind of tricky to debug
when an element is styled / positioned incorrectly. We don't have a way
to inspect the Inspector itself.

This adds a button to the Inspector to export its HTML/CSS/JS contents
to the downloads directory. This allows for more easily testing changes,
especially by opening the exported HTML in another browser's dev tools.

We will ultimately likely remove this button (or make it hidden) by the
time we are production-ready. But it's quite useful for now.

(cherry picked from commit 3ec5c1941f25041c6bf073f2940f6035e084a4e2)
2024-11-08 07:44:45 -05:00
Tobias Christiansen
61848ff6c2 Inspector: Add "Fonts" tab
This adds another tab to the bottom tabs providing information
regarding the fonts computed for the currently selected DOM node.

(cherry picked from commit c3e69f2fc6ced035f59f3c78f54556a372d2fd14)
2024-11-08 07:44:45 -05:00
Tobias Christiansen
ce0b0c43ed LibWebView + WebContent: Add fonts to be transferable to inspector
This patch adds all the needed plumbing to transfer information
regarding fonts of the selected DOM node to the inspector.

(cherry picked from commit 5621f34062f744086b9dc378212af35efe597c74)
2024-11-08 07:44:45 -05:00
Timothy Flynn
67166d4642 LibWebView: Insert line numbers before each line in about:srcdoc
The behavior chosen here (fixed-width counters, alignment, etc.) matches
Firefox.

(cherry picked from commit c1b0e180ba64d2ea7e815e2c2e93087ae9a26500)
2024-11-07 22:15:54 -05:00
simonkrauter
3a44f30734 LibWebView: Remove early exit in InspectorClient::inspect()
This early exit prevents to show the current DOM in the inspector, when
the inspector was already opened.

Fixes #990

(cherry picked from commit dd5550dde39f177d44cd776ebca033ea99ce5749)
2024-11-07 21:52:13 -05:00
circl
e744abc3ce LibWeb+UI: Add tooltip overriding and use it for <video> tags
This call is used to inform the chrome that it should display a tooltip
now and avoid any hovering timers. This is used by <video> tags to
display the volume percentage when it is changed.

(cherry picked from commit ceb9c3b79746e5499dce781e1fc81a9107c86f84;
amended to add a FIXME: to OutOfProcessWebView for these new hooks)
2024-11-07 20:52:11 -05:00
circl
206642afb1 LibWeb+UI/Qt: Display 'title' tooltips only when the mouse stops moving
Now instead of sending the position in which the user entered the
tooltip area, send just the text, and let the chrome figure out how to
display it.

In the case of Qt, wait for 600 milliseconds of no mouse movement, then
display it under the mouse cursor.

(cherry picked from commit 0f7623dd8322f0fd5ef6ee0e27e1295e11f276e6;
amended to update OutOfProcessWebView.cpp for on_enter_tooltip_area
API change)
2024-11-07 20:52:11 -05:00
Jamie Mansfield
a49db64dac LibWeb: Make preferred languages configurable
This also changes fetch to use the preferred languages for the
Accept-Language header.

(cherry picked from commit 2ca8fd1832462c05fdec16a1de73494820597140)
2024-11-05 11:41:15 -05:00
Timothy Flynn
6f90b46295 LibWebView: Escape HTML entities in attribute names
Otherwise, we can embed invalid HTML in the Inspector web view.

(cherry picked from commit 93f2af38b1603b2f963a14333513bbfae4728d01)
2024-11-04 13:17:19 -05:00
Timothy Flynn
631f03c955 LibWeb+LibWebView+WebContent: Add IPC to send drag-and-drop events
This adds the IPC and related hooks to allow the UI to send drag-and-
drop events from the UI process to the WebContent process.

(cherry picked from commit 948b6de3b122b50d67d967ed780133e847d629df;
amended to fix in ConnectionFromClient.h due to us still having
`add_backing_store` due to not having LadybirdBrowser/ladybird#233)
2024-11-01 19:58:08 -04:00
Jamie Mansfield
f1052ca896 LibWeb: Support sending DNT header with requests
(cherry picked from commit fb2032697986f0048bf84ba03f60b5d851333c06)
2024-11-01 12:00:07 -04:00
Samuel Eisenhandler
5067a040ba LibWebView: Append remaining source after consuming all tokens
Since "Character" tokens do not have an "end position", viewing source
drops the source contents following the final non-"Character" token.

By handling the EOF token and breaking out of the loop, we avoid this
issue.

(cherry picked from commit 7de669dc07956c402e0ddec76e3f214f622cf2c4)
2024-11-01 06:25:07 -04:00
Andreas Kling
85e721a3da LibWebView: Remove ProcessManager debug spam
(cherry picked from commit a0874dc870ea5746c33165c56532480670d55492)
2024-10-19 20:56:10 -04:00
Luke Warlow
f747be119d LibWeb: Add motion preference
This adds a motion preference to the browser UI similar to the existing
ones for color scheme and contrast.
Both AppKit UI and Qt UI has this new preference.
The auto value is currently the same as NoPreference, follow-ups can
address wiring that up to the actual preference for the OS.

(cherry picked from commit 099b77d60f6c30b4d533872fda29ea6d660ed358)
2024-09-28 07:57:00 -04:00
Tim Ledbetter
a4ec2a3703 LibWeb+WebContent: Provide feedback on find in page requests
This change allows the results of a find in page query to be reported
back to the user interface. Currently, the number of results found and
the current match index are reported.

(cherry picked from commit d33c4c751f3b69d9371e20234478b845f6cc0da4)
2024-09-28 00:16:05 -04:00
Luke Warlow
2dce7000c8 LibWeb: Add Contrast preference
(cherry picked from commit ee6468456580fa0380daeb0b9ab0bdf2832f9dcf)
2024-09-27 23:31:40 -04:00
kleines Filmröllchen
a3077203fe AK: Don't implicitly convert Optional<T&> to Optional<T>
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.
2024-09-14 13:30:27 +02:00
Timothy Flynn
c4f8b961b0 LibWebView: Make open file limit modifications non-fatal
If setrlimit fails, let's just report the error rather than failing to
start the browser at all.

(cherry picked from commit cf25a06d6715c8ef699973db7634016f8659c9d7)
2024-08-13 15:43:40 -04:00
Timothy Flynn
4ee1e3d5a1 LibWebView+UI: Raise the chrome process open file limit
The default limit (at least on Linux) causes us to run out of file
descriptors at around 15 tabs. Increase this limit to 8k. This is a
rather arbitrary number, but matches the limit set by Chrome.

(cherry picked from commit d58a8b514647a1137d76a1d601f0c325a51f29b3;
amended to also update Userland/Applications/Browser/main.cpp)
2024-07-29 01:01:11 -04:00
Diego Frias
4c0fcb7ae3 LibWebView: Trim whitespace when sanitizing file paths
Previously, the presence of surrounding whitespace would give file paths
the `https` schema instead of the `file` schema, making navigation
unsuccessful.

(cherry picked from commit ff7ca5c48c316e07b1bf631b2d7ed14c358dfa42)
2024-07-14 19:34:49 -04:00
Aliaksandr Kalenik
0d9a9490f0 LibWeb: Remove did_request_scroll_to IPC call
No longer used after moving scrollbar painting into WebContent.

(cherry picked from commit 94eacf6da736f957a5fc22faa552341165aaf1ca)
2024-07-07 11:32:25 +02:00
Aliaksandr Kalenik
5728f22dd8 LibWeb: Remove did_request_scroll IPC call
No longer used after moving scrollbar painting into WebContent.

(cherry picked from commit cc3d95a356ea3769d325c2f7bb73947cb4ba7baa)
2024-07-07 11:32:25 +02:00
Aliaksandr Kalenik
40a570e237 LibWeb+WebContent: Move scrollbar painting into WebContent
The main intention of this change is to have a consistent look and
behavior across all scrollbars, including elements with
`overflow: scroll` and `overflow: auto`, iframes, and a page.

Before:
- Page's scrollbar is painted by Browser (Qt/AppKit) using the
  corresponding UI framework style,
- Both WebContent and Browser know the scroll position offset.
- WebContent uses did_request_scroll_to() IPC call to send updates.
- Browser uses set_viewport_rect() to send updates.

After:
- Page's scrollbar is painted on WebContent side using the same style as
  currently used for elements with `overflow: scroll` and
  `overflow: auto`. A nice side effects: scrollbars are now painted for
  iframes, and page's scrollbar respects scrollbar-width CSS property.
- Only WebContent knows scroll position offset.
- did_request_scroll_to() is no longer used.
- set_viewport_rect() is changed to set_viewport_size().

(cherry picked from commit 5285e22f2aa09152365179865f135e7bc5d254a5)

Co-authored-by: Jamie Mansfield <jmansfield@cadixdev.org>
Co-authored-by: Nico Weber <thakis@chromium.org>
2024-07-07 11:32:25 +02:00
Luke Warlow
d29cef8d5f LibWebView: Allow data URLs in sanitize_url
Allow navigation to data URLs from browser UI.

(cherry picked from commit 6014727c20ad108e8345e89cba8e9eace3c157b3)
2024-06-27 17:14:22 +02:00
Tim Ledbetter
7561a48ec6 LibWebView: Don't query public suffix list when sanitizing URLs
Previously, part of the procedure we used to sanitize URLs entered via
the command line would check the host against the public suffix
database. This led to some valid, but not publicly accessible URLs
being treated as invalid.

(cherry picked from commit e9f34c7bd1e72da9a57a721d4ad501e8208cc986)
2024-06-27 14:00:51 +02:00