From 9d03ea6f74d3e479e3426479933cd7b9ba9270b8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 8 Sep 2021 00:55:35 +0200 Subject: [PATCH] LibWeb+WebContent: Port DumpLayoutTree to OutOfProcessWebView This required adding a simple OOPWV::dump_layout_tree() API that synchronously requests a dump of the layout tree from the WebContent process. --- .../Libraries/LibWeb/DumpLayoutTree/main.cpp | 21 ++++--------------- .../Libraries/LibWeb/OutOfProcessWebView.cpp | 5 +++++ .../Libraries/LibWeb/OutOfProcessWebView.h | 2 ++ .../Services/WebContent/ClientConnection.cpp | 13 ++++++++++++ .../Services/WebContent/ClientConnection.h | 3 ++- .../Services/WebContent/WebContentServer.ipc | 2 ++ 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Userland/Libraries/LibWeb/DumpLayoutTree/main.cpp b/Userland/Libraries/LibWeb/DumpLayoutTree/main.cpp index dc12f9085a..040d7f2e66 100644 --- a/Userland/Libraries/LibWeb/DumpLayoutTree/main.cpp +++ b/Userland/Libraries/LibWeb/DumpLayoutTree/main.cpp @@ -7,9 +7,7 @@ #include #include #include -#include -#include -#include +#include #include int main(int argc, char** argv) @@ -19,22 +17,11 @@ int main(int argc, char** argv) window->set_title("DumpLayoutTree"); window->resize(800, 600); window->show(); - auto& web_view = window->set_main_widget(); + auto& web_view = window->set_main_widget(); web_view.load(URL::create_with_file_protocol(argv[1])); web_view.on_load_finish = [&](auto&) { - auto* document = web_view.document(); - if (!document) { - warnln("No document."); - _exit(1); - } - auto* layout_root = document->layout_node(); - if (!layout_root) { - warnln("No layout tree."); - _exit(1); - } - StringBuilder builder; - Web::dump_tree(builder, *layout_root); - write(STDOUT_FILENO, builder.string_view().characters_without_null_termination(), builder.length()); + auto dump = web_view.dump_layout_tree(); + write(STDOUT_FILENO, dump.characters(), dump.length() + 1); _exit(0); }; return app->exec(); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index ae74ff24dd..af91644326 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -460,4 +460,9 @@ void OutOfProcessWebView::select_all() client().async_select_all(); } +String OutOfProcessWebView::dump_layout_tree() +{ + return client().dump_layout_tree(); +} + } diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h index a5df3b771b..7c7c1bdf6f 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h @@ -49,6 +49,8 @@ public: String selected_text(); void select_all(); + String dump_layout_tree(); + void notify_server_did_layout(Badge, const Gfx::IntSize& content_size); void notify_server_did_paint(Badge, i32 bitmap_id); void notify_server_did_invalidate_content_rect(Badge, const Gfx::IntRect&); diff --git a/Userland/Services/WebContent/ClientConnection.cpp b/Userland/Services/WebContent/ClientConnection.cpp index 30654f9977..ee519bb227 100644 --- a/Userland/Services/WebContent/ClientConnection.cpp +++ b/Userland/Services/WebContent/ClientConnection.cpp @@ -321,4 +321,17 @@ void ClientConnection::select_all() page().client().page_did_change_selection(); } +Messages::WebContentServer::DumpLayoutTreeResponse ClientConnection::dump_layout_tree() +{ + auto* document = page().top_level_browsing_context().document(); + if (!document) + return String { "(no DOM tree)" }; + auto* layout_root = document->layout_node(); + if (!layout_root) + return String { "(no layout tree)" }; + StringBuilder builder; + Web::dump_tree(builder, *layout_root); + return builder.to_string(); +} + } diff --git a/Userland/Services/WebContent/ClientConnection.h b/Userland/Services/WebContent/ClientConnection.h index 506f04414d..7a0f116c88 100644 --- a/Userland/Services/WebContent/ClientConnection.h +++ b/Userland/Services/WebContent/ClientConnection.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -54,6 +54,7 @@ private: virtual void inspect_dom_tree() override; virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32) override; virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override; + virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override; virtual void js_console_input(String const&) override; virtual void run_javascript(String const&) override; diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index b7006efeba..a8307c784f 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -34,6 +34,8 @@ endpoint WebContentServer run_javascript(String js_source) =| + dump_layout_tree() => (String dump) + get_selected_text() => (String selection) select_all() =| }