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.
This commit is contained in:
Andreas Kling 2021-01-31 09:06:25 +01:00
parent 1dad47c0f9
commit df2a4adcd2
Notes: sideshowbarker 2024-07-18 22:42:53 +09:00
9 changed files with 64 additions and 6 deletions

View file

@ -362,7 +362,7 @@ Tab::Tab(Type type)
if (m_type == Type::InProcessWebView) {
Web::dump_tree(*m_page_view->document());
} else {
TODO();
m_web_content_view->debug_request("dump-dom-tree");
}
},
this));
@ -371,7 +371,7 @@ Tab::Tab(Type type)
if (m_type == Type::InProcessWebView) {
Web::dump_tree(*m_page_view->document()->layout_node());
} else {
TODO();
m_web_content_view->debug_request("dump-layout-tree");
}
},
this));
@ -382,7 +382,7 @@ Tab::Tab(Type type)
Web::dump_sheet(sheet);
}
} else {
TODO();
m_web_content_view->debug_request("dump-style-sheets");
}
},
this));
@ -396,7 +396,7 @@ Tab::Tab(Type type)
m_page_view->set_should_show_line_box_borders(action.is_checked());
m_page_view->update();
} else {
TODO();
m_web_content_view->debug_request("set-line-box-borders", action.is_checked() ? "on" : "off");
}
},
this);
@ -410,7 +410,7 @@ Tab::Tab(Type type)
document->interpreter().heap().collect_garbage(JS::Heap::CollectionType::CollectGarbage, true);
}
} else {
TODO();
m_web_content_view->debug_request("collect-garbage");
}
}));

View file

@ -534,7 +534,8 @@ Color Document::visited_link_color() const
return page()->palette().visited_link();
}
static JS::VM& main_thread_vm()
JS::VM& main_thread_vm();
JS::VM& main_thread_vm()
{
static RefPtr<JS::VM> vm;
if (!vm) {

View file

@ -299,4 +299,9 @@ WebContentClient& OutOfProcessWebView::client()
return *m_client_state.client;
}
void OutOfProcessWebView::debug_request(const String& request, const String& argument)
{
client().post_message(Messages::WebContentServer::DebugRequest(request, argument));
}
}

View file

@ -49,6 +49,8 @@ public:
void load_html(const StringView&, const URL&);
void load_empty_document();
void debug_request(const String& request, const String& argument = {});
void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&);

View file

@ -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());
}
}
}

View file

@ -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();

View file

@ -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);
}

View file

@ -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 };
};
}

View file

@ -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) =|
}