Commit Graph

291 Commits

Author SHA1 Message Date
Timothy Flynn
552f63a283 LibWebView: Protect the Inspector against rapid inspection requests
This was seen in Browser when hotkey activations were processed twice.
If we open the Inspector with a hotkey (F12) and quickly activate that
hotkey again, we could try sending a JS command (inspector.loadDOMTree)
before the inspector.js file was actually loaded in the WebContent.

The window for this bug is larger on Serenity, where loading WebContent
is a bit slower than on Linux. So even with the Browser bug fixed, it is
pretty easy to hit this window still.
2024-03-04 10:49:43 +01:00
Andrew Kaster
0a55749a39 Ladybird+Userland: Use ByteString for candidate server paths
We've adopted a stance that paths should be ByteStrings rather than
UTF-8 strings, so apply that to the Ladybird helpers.
2024-02-26 13:16:27 -07:00
Andrew Kaster
9918dcd4d5 LibWebView: Extend GENERATED_SOURCES list instead of replacing 2024-02-26 13:16:27 -07:00
Timothy Flynn
f1d6693990 LibWebView: Reduce overhead of updating a cookie's last access time
Getting a document's cookie value currently involves:

1. Doing a large SELECT statement and filtering the results to match
   the document and some query parameters based on the cookie RFC.
2. For every cookie selected this way, doing an UPDATE to set its last
   access time.
3. For every UPDATE, do a DELETE to remove all expired cookies.

There's no need to perform cookie expiration for every UPDATE. Instead,
we can do the expiration once after all the UPDATEs are complete.

This reduces time spent waiting for cookies on https://twinings.co.uk
from ~1.9s to ~1.3s on my machine.
2024-02-26 19:59:09 +01:00
Timothy Flynn
108521a566 LibWeb+LibWebView+WebContent: Implement more <input type=file> behavior
We had previous implemented some plumbing for file input elements in
commit 636602a54e.

This implements the return path for chromes to inform WebContent of the
file(s) the user selected. This patch includes a dummy implementation
for headless-browser to enable testing.
2024-02-26 14:18:49 +01: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
Timothy Flynn
338f0382d3 LibWebView: Escape HTML within attribute values in the Inspector HTML
If an attribute value contains HTML, let's make sure we render it as
text, instead of injecting HTML in the middle of an Inspector field.
2024-02-20 17:04:36 +01:00
Timothy Flynn
fd558a012b LibWebView: Do not embed text as data in the Inspector HTML
We were previously embedding the original text to handle the special
case where the text is empty. We generate an extra span to hold the
string "#text" as a placeholder, so that we don't generate a 0px-wide,
unclickable (and therefore uneditable) node. Instead, we can just detect
when this is the case in the Inspector JS.

This further reduces the generated HTML for the Inspector on
https://github.com/SerenityOS/serenity from 1.9MB to 1.8MB (about 94KB,
or 4.7%).
2024-02-20 17:04:36 +01:00
Timothy Flynn
f07f5a2622 LibWeb+WebContent: Do not embed attributes as data in the Inspector HTML
Attribute values may contain HTML, and may contain invalid HTML at that.
If the latter occurs, let's not generate invalid Inspector HTML when we
embed the attribute values as data attributes. Instead, cache the values
in the InspectorClient, and embed just a lookup index into the HTML.

This also nicely reduces the size of the generated HTML. The Inspector
on https://github.com/SerenityOS/serenity reduces from 2.3MB to 1.9MB
(about 318KB, or 13.8%).
2024-02-20 17:04:36 +01:00
Andrew Kaster
36cd2fb7c5 Ladybird+WebContent: Update IPC calls to handle multiple traversables
The IPC layer between chromes and LibWeb now understands that multiple
top level traversables can live in each WebContent process.

This largely mechanical change adds a billion page_id/page_index
arguments to make sure that pages that end up opening new WebViews
through mechanisms like window.open() still work properly with those
extra windows.
2024-02-03 20:51:37 -05:00
Andrew Kaster
677bdc2a4f Ladybird: Add IPC call for creating a new child tab
This will be used for choosing a navigable that requires opening a new
tab or new window. Such as calls to window.open(), or specific WebDriver
calls.
2024-02-03 20:51:37 -05:00
Andrew Kaster
48ce8fb4e9 Ladybird: Add ability to create a tab without creating a new WebContent 2024-02-03 20:51:37 -05:00
Timothy Flynn
83d2f59e2a LibWebView: Port the CookieJar to String 2024-01-26 20:22:39 +01:00
Timothy Flynn
c4820838bf LibWeb+WebContent: Port the did_request_named_cookie IPC to String 2024-01-26 20:22:39 +01:00
Timothy Flynn
9b957ead13 LibWebView+WebContent: Do not manually serialize cookie sources over IPC
LibIPC can serialize enumeration automatically (this was not the case
when these IPCs were added).
2024-01-26 20:22:39 +01:00
Timothy Flynn
85b8971a80 Ladybird+LibWeb+WebContent: Port the did_request_cookie IPC to String 2024-01-26 20:22:39 +01:00
Timothy Flynn
8ea4e37c27 LibWebView: Convert trivial ByteString uses to StringView in CookieJar 2024-01-26 20:22:39 +01:00
Timothy Flynn
2fd034d1df LibWebView: Prevent quoting attribute values twice in the Inspector
As of commit ccd701809f, the formatter for
JsonValue now fully serializes the value. The serializer will surround
the string value with quotes. We want control over when we add quotes to
the generated Inspector HTML, so avoid formatting attributes as raw JSON
values.
2024-01-25 08:22:24 +01:00
Sam Atkins
56c5ffe398 LibFileSystem+Userland: Return ByteString from real_path() 2024-01-16 08:42:34 +00:00
Bastiaan van der Plaat
63c6eae918 LibWebView: Fix sanitizing about scheme URLs 2024-01-13 13:41:09 -05:00
Andrew Kaster
02edd240ae LibWeb+WebContent: Spawn Worker processes from the chrome
Instead of spawning these processes from the WebContent process, we now
create them in the Browser chrome.

Part 1/N of "all processes are owned by the chrome".
2024-01-12 15:53:11 -07:00
Timothy Flynn
5c5cbeb491 LibSQL+LibWebView: Do not manually serialize time stamps in CookieJar
LibSQL supports serializing time stamps as of commit
effcd080ca.

However, that commit serializes the timestamps as milliseconds, whereas
the CookieJar was serializing them as seconds. In retrospect, these
should have been updated in unison, along with the SQL heap version (as
this is a serialization change that affects the file format). So this
patch also updates the version, as this is not a backwards compatible
change.
2024-01-10 23:26:40 +01:00
Timothy Flynn
8b32f4ae7a LibWebView+WebContent: Let the WebView client broadcast when it painted
When the WebContent process has painted to its shared bitmaps, it sends
a synchronous IPC to the browser process to let the chrome paint. It is
synchronous to ensure the WC process doesn't paint onto the backing
bitmap again while it is being displayed.

However, this can cause a crash at exit if the browser process quits
while the WC process is waiting for a response to this IPC.

This patch makes the painting logic asynchronous by letting the browser
process broadcast when it has finished handling the paint IPC. The WC
process will not paint anything again until it receives that message. If
it had tried to repaint while waiting for that message, that paint will
be deferred until it arrives.
2024-01-08 00:51:59 +01:00
Bastiaan van der Plaat
0dd5aa40a8 LibWeb: Allow input color to give continuous updates 2024-01-06 10:02:15 -07:00
Kevin Meyer
f86ec46a6e Ladybird+LibWebView: Cleanup missing callbacks in InspectorClient
This was causing reproducible crashes, when closing the inspector
window of ladybird running on macos.
2024-01-01 16:04:29 -05:00
Timothy Flynn
d8fa226a8f Ladybird+LibWebView+WebContent: Make the screenshot IPCs async
These IPCs are different than other IPCs in that we can't just set up a
callback function to be invoked when WebContent sends us the screenshot
data. There are multiple places that would set that callback, and they
would step on each other's toes.

Instead, the screenshot APIs on ViewImplementation now return a Promise
which callers can interact with to receive the screenshot (or an error).
2024-01-01 10:11:45 +01:00
Timothy Flynn
93db790974 LibWebView+WebContent: Make the DOM node HTML retrieval IPC async 2024-01-01 10:11:45 +01:00
Timothy Flynn
3572a047d1 LibWebView+WebContent: Make the DOM node editing IPCs async
All DOM node mutation IPCs now invoke an async completion IPC after the
DOM is mutated. This allows consolidating where the Inspector updates
its view and the selected DOM node.

This also allows improving the response to removing a DOM node. We would
previously just select the <body> tag after removing a DOM node because
the Inspector client had no idea what node preceded the removed node.
Now the WebContent process can just indicate what that node is. So now
after removing a DOM node, we inspect either its previous sibling (if it
had one) or its parent.
2023-12-30 17:30:55 +01:00
Timothy Flynn
1eba170d03 LibWebView+WebContent: Make the hovered node retrieval IPC async 2023-12-30 17:30:55 +01:00
Timothy Flynn
760ba5932b LibWebView+WebContent: Make the DOM node inspection IPC async 2023-12-30 17:30:55 +01:00
Timothy Flynn
4c3bff264e LibWebView+WebContent: Rename DOM/a11y tree IPC response methods
Rename them from "did_get_*" to "did_inspect_*", to correspond to the
request methods "inspect_dom_tree" and "inspect_accessibility_tree". No
functional change, but this makes it a bit easier to stare at IPC files
side-by-side and know which response method corresponds to a request
method at a quick glance.
2023-12-30 17:30:55 +01:00
Aliaksandr Kalenik
8a4416837a LibWebView: Request repaint after replacing backing stores
Fixes a bug when the Qt client does not repaint after resizing
when the following sequence of IPC calls happens:

1. In the resize handler, the client sends set_viewport_rect to
   WebContent.
2. WebContent starts repainting in response to the changed viewport
   size.
3. In the resize handler, the client updates backing stores and sends
   new ids and shared bitmaps to WebContent using the add_backing_store
   call.
4. WebContent sends an acknowledgment to the client that painting
   finished using the old id.
5. The client discards the repaint because it expects a new backing
   store id.
2023-12-25 23:54:26 +01:00
Timothy Flynn
947136ca8d LibWebView: Load the Inspector CSS and JS resource files with LibWeb 2023-12-24 14:09:23 +01:00
Bastiaan van der Plaat
29ee576345 LibWeb: Fix select dropdown position when scrolled on a page 2023-12-23 10:12:36 +01:00
Aliaksandr Kalenik
02936f6944 LibWebView+WebContent: Drive repainting from WebContent process
With this change, chrome no longer has to ask the WebContent process
to paint the next frame into a specified bitmap. Instead, it allocates
bitmaps and sends them to WebContent, which then lets chrome know when
the painting is done.

This work is a preparation to move the execution of painting commands
into a separate thread. Now, it is much easier to start working on the
next frame while the current one is still rendering. This is because
WebContent does not have to inform chrome that the current frame is
ready before it can request the next frame.

Additionally, as a side bonus, we can now eliminate the
did_invalidate_content_rect and did_change_selection IPC calls. These
were used solely for the purpose of informing chrome that it needed to
request a repaint.
2023-12-22 17:47:34 +01:00
Aliaksandr Kalenik
d87f3a4101 LibWebView+Ladybird: Remove unused on_scroll_into_view callback
Leftover from 9624eca116
2023-12-21 19:25:18 +01:00
Aliaksandr Kalenik
9624eca116 LibWeb+LibWebView+WebContent: Remove unused request_scroll_into_view
`Element::scroll_into_view()` is supposed to be used instead.
2023-12-19 10:45:07 +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
Bastiaan van der Plaat
b73ae80d8b LibWeb: Refactor WebContentServer mouse input message to DevicePixel 2023-12-16 11:08:51 +01:00
Bastiaan van der Plaat
c069ab1ca0 LibWeb: Refactor int types in WebContentServer to DevicePixels 2023-12-15 17:01:16 +01:00
Bastiaan van der Plaat
cbb660c756 LibWeb: Make request_select_dropdown more similar to context menu api 2023-12-13 10:30:13 +01:00
Bastiaan van der Plaat
aee8b39c65 Ladybird/Qt: Open context menus at requested position 2023-12-13 10:30:13 +01:00
Aliaksandr Kalenik
57e5abae92 LibJS+LibWebView+WebContent+Ladybird: Output GC-graph into a file
Instead of displaying a massive JSON in stdout, it's more practical
to save the GC-graph to a file.
2023-12-12 15:35:35 +01:00
Shannon Booth
83758d4cdd LibWeb: Wrap PseudoElements stored in SimpleSelector in a class
No functional impact intended. This is just a more complicated way of
writing what we have now.

The goal of this commit is so that we are able to store the 'name' of a
pseudo element for use in serializing 'unknown -webkit-
pseudo-elements', see:

https://www.w3.org/TR/selectors-4/#compat

This is quite awkward, as in pretty much all cases just the selector
type enum is enough, but we will need to cache the name for serializing
these unknown selectors. I can't figure out any reason why we would need
this name anywhere else in the engine, so pretty much everywhere is
still just passing around this raw enum. But this change will allow us
to easily store the name inside of this new struct for when it is needed
for serialization, once those webkit unknown elements are supported by
our engine.
2023-12-11 16:54:59 +01:00
Timothy Flynn
451df70275 Ladybird+LibWebView: Ensure existing Inspector widgets inspect the page
If the Inspector widget already exists, be sure to inspect the page when
it is re-opened. However, this should be a no-op if the page was already
inspected (as any existing Inspector will be reset if a new page load
began).

Note this is not an issue in the AppKit chrome.
2023-12-10 16:45:08 +01:00
Timothy Flynn
41ffc69c9d LibWebView: Clear the Inspector DOM/accessibility trees upon reset
This prevents rendering stale trees while navigating to a new page. The
old non-WebView inspector widgets behaved this way.
2023-12-10 16:45:08 +01:00
Simon Wanner
0fe192dfd9 LibWebView: Use Unicode::parse_unicode_url for parsing URLs 2023-12-10 08:04:58 -05:00
Timothy Flynn
55ec1cbfb5 LibWebView: Allow editing empty DOM text nodes in the Inspector
When a DOM text node is empty, we currently render the node name (which
is "#text") in the Inspector. This is just to prevent displaying nothing
at all, which looks a bit off. However, the patch to allow editing text
fields neglected to allow editing these empty fields.

This patch attaches the original text data as a data attribute, much
like we do for DOM attributes. That is used as the editable text in the
inspector, and the empty text fields are now wrapped in an editable
span.
2023-12-10 09:44:34 +01:00
Timothy Flynn
6595e76fef Ladybird: Do not include comment start/end sequence in its editable text
Currently, when editing a comment, the `<!--` and `-->` start and end
sequences would be included in the generated <input> field. This would
result in including that text in the updated comment text. So, for
example, in a comment such as:

    <!-- foo -->

Changing "foo" to "bar" would result in the comment:

    <!--<!-- bar -->-->

And this would repeatedly nest for each edit.
2023-12-10 09:44:34 +01:00
Timothy Flynn
42c0ac9352 LibWebView: Log the result of taking screenshots to Inspector's console
It probably isn't obvious that screenshots are saved to the user's
Downloads folder, so add a console message to inform them.
2023-12-10 09:44:34 +01:00