summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-01-31 09:06:25 +0100
committerAndreas Kling <kling@serenityos.org>2021-01-31 09:07:46 +0100
commitdf2a4adcd2e34a7998c181f088aa121fa5bbc4ff (patch)
tree63d64335db4581fc1a526663d9034d858faf7805 /Userland/Services
parent1dad47c0f9fde14f9cdd421cc257a520fa658cb0 (diff)
downloadserenity-df2a4adcd2e34a7998c181f088aa121fa5bbc4ff.zip
Browser+LibWeb+WebContent: Make the "Debug" menu work in multi-process
This patch adds an IPC call for debugging requests. It's stringly typed and very simple, and allows us to easily implement all the features in the Browser's Debug menu.
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/WebContent/ClientConnection.cpp43
-rw-r--r--Userland/Services/WebContent/ClientConnection.h1
-rw-r--r--Userland/Services/WebContent/PageHost.cpp1
-rw-r--r--Userland/Services/WebContent/PageHost.h3
-rw-r--r--Userland/Services/WebContent/WebContentServer.ipc2
5 files changed, 50 insertions, 0 deletions
diff --git a/Userland/Services/WebContent/ClientConnection.cpp b/Userland/Services/WebContent/ClientConnection.cpp
index 01af0de4ec..b41e35cb9b 100644
--- a/Userland/Services/WebContent/ClientConnection.cpp
+++ b/Userland/Services/WebContent/ClientConnection.cpp
@@ -28,11 +28,21 @@
#include <AK/Debug.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/SystemTheme.h>
+#include <LibJS/Heap/Heap.h>
+#include <LibJS/Runtime/VM.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/Dump.h>
+#include <LibWeb/Layout/InitialContainingBlockBox.h>
+#include <LibWeb/Page/Frame.h>
#include <WebContent/ClientConnection.h>
#include <WebContent/PageHost.h>
#include <WebContent/WebContentClientEndpoint.h>
#include <pthread.h>
+namespace Web::DOM {
+extern JS::VM& main_thread_vm();
+}
+
namespace WebContent {
static HashMap<int, RefPtr<ClientConnection>> s_connections;
@@ -165,4 +175,37 @@ void ClientConnection::handle(const Messages::WebContentServer::KeyDown& message
page().handle_keydown((KeyCode)message.key(), message.modifiers(), message.code_point());
}
+void ClientConnection::handle(const Messages::WebContentServer::DebugRequest& message)
+{
+ if (message.request() == "dump-dom-tree") {
+ if (auto* doc = page().main_frame().document())
+ Web::dump_tree(*doc);
+ }
+
+ if (message.request() == "dump-layout-tree") {
+ if (auto* doc = page().main_frame().document()) {
+ if (auto* icb = doc->layout_node())
+ Web::dump_tree(*icb);
+ }
+ }
+
+ if (message.request() == "dump-style-sheets") {
+ if (auto* doc = page().main_frame().document()) {
+ for (auto& sheet : doc->style_sheets().sheets()) {
+ Web::dump_sheet(sheet);
+ }
+ }
+ }
+
+ if (message.request() == "collect-garbage") {
+ ::Web::DOM::main_thread_vm().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true);
+ }
+
+ if (message.request() == "set-line-box-borders") {
+ bool state = message.argument() == "on";
+ m_page_host->set_should_show_line_box_borders(state);
+ page().main_frame().set_needs_display(page().main_frame().viewport_rect());
+ }
+}
+
}
diff --git a/Userland/Services/WebContent/ClientConnection.h b/Userland/Services/WebContent/ClientConnection.h
index 34a13713f3..39faf16165 100644
--- a/Userland/Services/WebContent/ClientConnection.h
+++ b/Userland/Services/WebContent/ClientConnection.h
@@ -62,6 +62,7 @@ private:
virtual void handle(const Messages::WebContentServer::KeyDown&) override;
virtual void handle(const Messages::WebContentServer::AddBackingStore&) override;
virtual void handle(const Messages::WebContentServer::RemoveBackingStore&) override;
+ virtual void handle(const Messages::WebContentServer::DebugRequest&) override;
void flush_pending_paint_requests();
diff --git a/Userland/Services/WebContent/PageHost.cpp b/Userland/Services/WebContent/PageHost.cpp
index f4a47e1259..d37ff61054 100644
--- a/Userland/Services/WebContent/PageHost.cpp
+++ b/Userland/Services/WebContent/PageHost.cpp
@@ -93,6 +93,7 @@ void PageHost::paint(const Gfx::IntRect& content_rect, Gfx::Bitmap& target)
painter.translate(-content_rect.x(), -content_rect.y());
Web::PaintContext context(painter, palette(), Gfx::IntPoint());
+ context.set_should_show_line_box_borders(m_should_show_line_box_borders);
context.set_viewport_rect(content_rect);
layout_root->paint_all_phases(context);
}
diff --git a/Userland/Services/WebContent/PageHost.h b/Userland/Services/WebContent/PageHost.h
index 6983421840..580685cfdb 100644
--- a/Userland/Services/WebContent/PageHost.h
+++ b/Userland/Services/WebContent/PageHost.h
@@ -48,6 +48,8 @@ public:
void set_palette_impl(const Gfx::PaletteImpl&);
void set_viewport_rect(const Gfx::IntRect&);
+ void set_should_show_line_box_borders(bool b) { m_should_show_line_box_borders = b; }
+
private:
// ^PageClient
virtual bool is_multi_process() const override { return true; }
@@ -75,6 +77,7 @@ private:
ClientConnection& m_client;
NonnullOwnPtr<Web::Page> m_page;
RefPtr<Gfx::PaletteImpl> m_palette_impl;
+ bool m_should_show_line_box_borders { false };
};
}
diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc
index e025e0b0cd..81620f7ecf 100644
--- a/Userland/Services/WebContent/WebContentServer.ipc
+++ b/Userland/Services/WebContent/WebContentServer.ipc
@@ -18,4 +18,6 @@ endpoint WebContentServer = 89
MouseUp(Gfx::IntPoint position, unsigned button, unsigned buttons, unsigned modifiers) =|
KeyDown(i32 key, unsigned modifiers, u32 code_point) =|
+
+ DebugRequest(String request, String argument) =|
}