Commit graph

15 commits

Author SHA1 Message Date
Timothy Flynn
daca9f5995 LibDevTools+LibWebView+WebContent: Selectively fetch DOM node properties
When we inspect a DOM node, we currently serialize many properties for
that node, including its layout, computed style, used fonts, etc. Now
that we aren't piggy-backing on the Inspector interface, we can instead
only serialize the specific information required by DevTools.
2025-03-20 09:01:26 +01:00
Timothy Flynn
19529590b9 LibDevTools+WebContent: Simplify sending box-model properties a bit
Now that we aren't piggy-backing on the Inspector interface, we can make
our box-model serialization provide exactly the values that DevTools
requires.
2025-03-20 09:01:26 +01:00
Timothy Flynn
2ee3985fd1 LibDevTools+LibWebView: Implement getting the used fonts for a DOM node
This also includes a request to get all fonts for a page, which we stub
out for now as we don't have the IPC to retrieve all fonts.
2025-03-13 16:56:28 -04:00
Timothy Flynn
f9e83af475 LibDevTools: Re-implement how we handle ordered responses
We must reply to requests received from the client in the order they are
received. The wrench in this requirement is handling requests that must
be performed asynchronously, such as fetching the serialized DOM tree
from the WebContent process.

We currently handle this with a "block token". Async request handlers
hold a token that blocks any subsequent responses from being sent. When
that token is removed (i.e. the async request now has a response to be
sent), the async response is then sent followed by the blocked responses
in-order.

This strategy had a limitation that we could not handle an actor trying
to take 2 block tokens, meaning only one async request could be handled
at a time. This has been fine so far, but an upcoming feature (style
sheet sources) will break this limitation. The client will request N
sources at a time, which would try to take N block tokens.

The new strategy is to assign all requests an ID, and store a list of
request IDs that are awaiting a response. When the server wants to send
a reply, we match the ID of the replied-to message to this list of IDs.
If it is not the first in this list, then we are blocked waiting for an
earlier reply, and just store the response. When the earlier request(s)
receive their response, we can then send out all blocked replies (up to
the next request that has not yet received a response).
2025-03-13 16:56:28 -04:00
Timothy Flynn
24a5e4e7d5 LibDevTools: Move message data into a structure
This is to prepare for an upcoming change where we will need to track
replies to messages by ID. We will be able to add parameters to this
structure without having to edit every single actor subclass header
file.
2025-03-13 16:56:28 -04:00
Timothy Flynn
49adec1396 LibDevTools: Add a helper to handle asynchronous request replies
This removes some boilerplate around executing async requests, such as
calling dbgln_if on any errors, handling weak pointers to `this`, and
dealing with block tokens.
2025-03-12 12:48:05 -04:00
Timothy Flynn
e1ed8722e0 LibDevTools: Add a helper to acquire required message parameters
This is just to help make the message handlers a bit briefer. I had
considered adding a TRY-like macro to auto-return when the lookup fails,
but since statement expressions cannot return references, that would
result in a copy of all e.g. object and array lookups.
2025-03-12 12:48:05 -04:00
Timothy Flynn
4ce10f3bf4 LibDevTools: Automatically set the "from" field for server responses
The "from" field is required in every response. It is the name of the
actor sending the message. This patch fills in the "from" field in the
Actor base class so that subclasses don't have to.
2025-03-12 12:48:05 -04:00
Timothy Flynn
a7b577126a LibDevTools: Send an unknown actor error for failed DOM node lookups
DevTools will ask us to find nodes by their actor names. If the actor is
missing, we should inform DevTools of the error instead of just dropping
the request.

The diff here is a bit noisy, just due to a leftward shift of code that
used to be in an if-statement.
2025-03-12 12:48:05 -04:00
Timothy Flynn
ddea67034f LibDevTools: Associate node actors with a DOM node identifier
This is a prepatory commit to be able to handle DOM mutations. Once a
node actor is created, the DOM node it is created for must continue to
be associated with the same actor even after DOM mutations. This change
stores an identifier on the node actor, and only creates new actors when
an actor for a node does not exist.
2025-03-08 01:25:55 +01:00
Timothy Flynn
ee88edc750 LibDevTools: Add a helper to extract a DOM node JSON object more easily
The pattern of:

    auto tab = get_tab();
    auto walker = get_walker();

    if (tab && walker) {
        if (auto node = walker->dom_node(node_id)) {
            delegate().do_something(tab->description(), node);
        }
    }

Is getting a bit unergonomic and is often repeated. This patch just adds
a helper to WalkerActor to do most of this work, so now we have:

    if (auto node = WalkerActor::dom_node_for(get_walker(), node_id)) {
        delegate().do_something(node->tab->description(), node);
    }
2025-03-08 01:25:55 +01:00
Timothy Flynn
0d1ce48071 LibDevTools+LibWebView: Avoid dependence on LibWebView from LibDevTools
Some checks failed
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Has been cancelled
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Has been cancelled
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Has been cancelled
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Has been cancelled
Package the js repl as a binary artifact / build-and-package (macos-14, macOS, macOS-universal2) (push) Has been cancelled
Package the js repl as a binary artifact / build-and-package (ubuntu-24.04, Linux, Linux-x86_64) (push) Has been cancelled
Run test262 and test-wasm / run_and_update_results (push) Has been cancelled
Lint Code / lint (push) Has been cancelled
Label PRs with merge conflicts / auto-labeler (push) Has been cancelled
Push notes / build (push) Has been cancelled
LibDevTools was implicitly including generated IPC endpoints from
LibWebView. This is not a dependency declared in the CMakeLists.txt. So
updates to the IPC file might not have caused the endpoint header to be
regenerated by the time LibDevTools is compiled, resulting in a build
error.

This patch removes that implicit dependency entirely.
2025-02-26 19:48:24 -05:00
Timothy Flynn
afb0a0a394 LibDevTools: Support inspecting DOM node box models and computed styles 2025-02-24 12:05:29 -05:00
Timothy Flynn
4791ec35bf LibDevTools+LibWebView: Port DevTools to String 2025-02-20 19:27:51 -05:00
Timothy Flynn
5ed91dc915 LibDevTools: Implement enough of the protocol to inspect tabs
There is a lot needed all at once to actually inspect a tab's DOM tree.
It begins with requesting a "watcher" from a TabActor. It seems there
can be many types of watchers, but here we implement the "frame" watcher
only. The watcher creates an "inspector", which in turn creates a
"walker", which is the actor ultimately responsible for serializing and
inspecting the DOM tree.

In between all that, the DevTools client will send a handful of other
informational requests. If we do not reply to these, the client will not
move forward with the walker. For example, the CSSPropertiesActor will
be asked for a list of all known CSS properties.
2025-02-19 08:45:51 -05:00