summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAdam Hodgen <ant1441@gmail.com>2021-06-07 16:35:10 +0100
committerAndreas Kling <kling@serenityos.org>2021-06-29 23:06:48 +0200
commitcd6b9613c506096fa2737f37a2af7e85a8b01461 (patch)
treed2d5eeafedf77da2e328d9f1e8e7cd209ce6f8e2 /Userland
parent4affe052b8e6a955e3c5ca06ea58accf985ae51e (diff)
downloadserenity-cd6b9613c506096fa2737f37a2af7e85a8b01461.zip
LibWeb+WebContent: Add IPC flow for Inspect DOM Tree
Add `inspect_dom_tree` to WebContentServer and 'did_get_dom_tree' to WebContentClient. These two async methods form a request & response for requesting a JSON representation of the Content's DOM tree.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/OutOfProcessWebView.cpp11
-rw-r--r--Userland/Libraries/LibWeb/OutOfProcessWebView.h2
-rw-r--r--Userland/Libraries/LibWeb/WebContentClient.cpp5
-rw-r--r--Userland/Libraries/LibWeb/WebContentClient.h1
-rw-r--r--Userland/Libraries/LibWeb/WebViewHooks.h1
-rw-r--r--Userland/Services/WebContent/ClientConnection.cpp8
-rw-r--r--Userland/Services/WebContent/ClientConnection.h1
-rw-r--r--Userland/Services/WebContent/WebContentClient.ipc1
-rw-r--r--Userland/Services/WebContent/WebContentServer.ipc1
9 files changed, 31 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
index e84be38764..3c64233791 100644
--- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
+++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp
@@ -335,6 +335,12 @@ void OutOfProcessWebView::notify_server_did_get_source(const URL& url, const Str
on_get_source(url, source);
}
+void OutOfProcessWebView::notify_server_did_get_dom_tree(const String& dom_tree)
+{
+ if (on_get_dom_tree)
+ on_get_dom_tree(dom_tree);
+}
+
void OutOfProcessWebView::notify_server_did_js_console_output(const String& method, const String& line)
{
if (on_js_console_output)
@@ -391,6 +397,11 @@ void OutOfProcessWebView::get_source()
client().async_get_source();
}
+void OutOfProcessWebView::inspect_dom_tree()
+{
+ client().async_inspect_dom_tree();
+}
+
void OutOfProcessWebView::js_console_initialize()
{
client().async_js_console_initialize();
diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h
index c82508f58c..ff7cac6151 100644
--- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h
+++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h
@@ -31,6 +31,7 @@ public:
void debug_request(const String& request, const String& argument = {});
void get_source();
+ void inspect_dom_tree();
void js_console_initialize();
void js_console_input(const String& js_source);
@@ -57,6 +58,7 @@ public:
bool notify_server_did_request_confirm(Badge<WebContentClient>, const String& message);
String notify_server_did_request_prompt(Badge<WebContentClient>, const String& message, const String& default_);
void notify_server_did_get_source(const URL& url, const String& source);
+ void notify_server_did_get_dom_tree(const String& dom_tree);
void notify_server_did_js_console_output(const String& method, const String& line);
void notify_server_did_change_favicon(const Gfx::Bitmap& favicon);
String notify_server_did_request_cookie(Badge<WebContentClient>, const URL& url, Cookie::Source source);
diff --git a/Userland/Libraries/LibWeb/WebContentClient.cpp b/Userland/Libraries/LibWeb/WebContentClient.cpp
index 34904b9f75..86d9acd0ea 100644
--- a/Userland/Libraries/LibWeb/WebContentClient.cpp
+++ b/Userland/Libraries/LibWeb/WebContentClient.cpp
@@ -136,6 +136,11 @@ void WebContentClient::did_get_source(URL const& url, String const& source)
m_view.notify_server_did_get_source(url, source);
}
+void WebContentClient::did_get_dom_tree(const String& dom_tree)
+{
+ m_view.notify_server_did_get_dom_tree(dom_tree);
+}
+
void WebContentClient::did_js_console_output(String const& method, String const& line)
{
m_view.notify_server_did_js_console_output(method, line);
diff --git a/Userland/Libraries/LibWeb/WebContentClient.h b/Userland/Libraries/LibWeb/WebContentClient.h
index 15664fb819..60e89d1127 100644
--- a/Userland/Libraries/LibWeb/WebContentClient.h
+++ b/Userland/Libraries/LibWeb/WebContentClient.h
@@ -49,6 +49,7 @@ private:
virtual void did_request_link_context_menu(Gfx::IntPoint const&, URL const&, String const&, unsigned) override;
virtual void did_request_image_context_menu(Gfx::IntPoint const&, URL const&, String const&, unsigned, Gfx::ShareableBitmap const&) override;
virtual void did_get_source(URL const&, String const&) override;
+ virtual void did_get_dom_tree(String const&) override;
virtual void did_js_console_output(String const&, String const&) override;
virtual void did_change_favicon(Gfx::ShareableBitmap const&) override;
virtual void did_request_alert(String const&) override;
diff --git a/Userland/Libraries/LibWeb/WebViewHooks.h b/Userland/Libraries/LibWeb/WebViewHooks.h
index 635cb3b3c5..e33ef529f0 100644
--- a/Userland/Libraries/LibWeb/WebViewHooks.h
+++ b/Userland/Libraries/LibWeb/WebViewHooks.h
@@ -27,6 +27,7 @@ public:
Function<void(const URL&)> on_url_drop;
Function<void(DOM::Document*)> on_set_document;
Function<void(const URL&, const String&)> on_get_source;
+ Function<void(const String&)> on_get_dom_tree;
Function<void(const String& method, const String& line)> on_js_console_output;
Function<String(const URL& url, Cookie::Source source)> on_get_cookie;
Function<void(const URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source)> on_set_cookie;
diff --git a/Userland/Services/WebContent/ClientConnection.cpp b/Userland/Services/WebContent/ClientConnection.cpp
index 5cf714a0b3..b2ed2a32eb 100644
--- a/Userland/Services/WebContent/ClientConnection.cpp
+++ b/Userland/Services/WebContent/ClientConnection.cpp
@@ -6,6 +6,7 @@
#include <AK/Badge.h>
#include <AK/Debug.h>
+#include <AK/JsonObject.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/FontDatabase.h>
#include <LibGfx/SystemTheme.h>
@@ -216,6 +217,13 @@ void ClientConnection::get_source()
}
}
+void ClientConnection::inspect_dom_tree()
+{
+ if (auto* doc = page().top_level_browsing_context().document()) {
+ async_did_get_dom_tree(doc->dump_dom_tree_as_json());
+ }
+}
+
void ClientConnection::js_console_initialize()
{
if (auto* document = page().top_level_browsing_context().document()) {
diff --git a/Userland/Services/WebContent/ClientConnection.h b/Userland/Services/WebContent/ClientConnection.h
index cd8f3577d9..6ceb158597 100644
--- a/Userland/Services/WebContent/ClientConnection.h
+++ b/Userland/Services/WebContent/ClientConnection.h
@@ -48,6 +48,7 @@ private:
virtual void remove_backing_store(i32) override;
virtual void debug_request(String const&, String const&) override;
virtual void get_source() override;
+ virtual void inspect_dom_tree() override;
virtual void js_console_initialize() override;
virtual void js_console_input(String const&) override;
diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc
index f9a40b30ef..16d8f111ee 100644
--- a/Userland/Services/WebContent/WebContentClient.ipc
+++ b/Userland/Services/WebContent/WebContentClient.ipc
@@ -23,6 +23,7 @@ endpoint WebContentClient
did_request_confirm(String message) => (bool result)
did_request_prompt(String message, String default_) => (String response)
did_get_source(URL url, String source) =|
+ did_get_dom_tree(String dom_tree) =|
did_js_console_output(String method, String line) =|
did_change_favicon(Gfx::ShareableBitmap favicon) =|
did_request_cookie(URL url, u8 source) => (String cookie)
diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc
index 40b97157fd..fc92a6ffaa 100644
--- a/Userland/Services/WebContent/WebContentServer.ipc
+++ b/Userland/Services/WebContent/WebContentServer.ipc
@@ -22,6 +22,7 @@ endpoint WebContentServer
debug_request(String request, String argument) =|
get_source() =|
+ inspect_dom_tree() =|
js_console_initialize() =|
js_console_input(String js_source) =|
}