diff options
author | Sam Atkins <atkinssj@serenityos.org> | 2021-09-04 11:14:25 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-06 18:20:26 +0200 |
commit | c619a57cf8f0d38c5acd71d6ae221b57b015a249 (patch) | |
tree | a8e2cc97241beccef0b33db03fe6a4a07f29efa2 /Userland | |
parent | 5220d6d2e50ce9ab7e5238a080438dea5d3d6656 (diff) | |
download | serenity-c619a57cf8f0d38c5acd71d6ae221b57b015a249.zip |
LibWeb+WebContent: Add new console-message IPC calls
This patch introduces three new IPC calls for WebContent:
- `Client::did_output_js_console_message(index)`:
Notifies the client that a new console message was logged.
- `Server::js_console_request_messages(start_index)`:
Ask the server for console messages starting at the given index.
- `Client::did_get_js_console_messages(start_index, types, messages)`:
Send the client the messages they requested.
This mechanism will replace the current
`Client::did_js_console_output()` call in the next few commits. This
will allow us to display messages in the console that happened before
the console was opened.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/OutOfProcessWebView.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/OutOfProcessWebView.h | 3 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebContentClient.cpp | 10 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebContentClient.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/WebViewHooks.h | 2 | ||||
-rw-r--r-- | Userland/Services/WebContent/ClientConnection.cpp | 17 | ||||
-rw-r--r-- | Userland/Services/WebContent/ClientConnection.h | 5 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebContentClient.ipc | 4 | ||||
-rw-r--r-- | Userland/Services/WebContent/WebContentServer.ipc | 1 |
9 files changed, 61 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp index 5e642df6e9..19ca8c47f9 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.cpp @@ -353,6 +353,18 @@ void OutOfProcessWebView::notify_server_did_js_console_output(const String& meth on_js_console_output(method, line); } +void OutOfProcessWebView::notify_server_did_output_js_console_message(i32 message_index) +{ + if (on_js_console_new_message) + on_js_console_new_message(message_index); +} + +void OutOfProcessWebView::notify_server_did_get_js_console_messages(i32 start_index, const Vector<String>& message_types, const Vector<String>& messages) +{ + if (on_get_js_console_messages) + on_get_js_console_messages(start_index, message_types, messages); +} + void OutOfProcessWebView::notify_server_did_change_favicon(const Gfx::Bitmap& favicon) { if (on_favicon_change) @@ -439,6 +451,11 @@ void OutOfProcessWebView::js_console_input(const String& js_source) client().async_js_console_input(js_source); } +void OutOfProcessWebView::js_console_request_messages(i32 start_index) +{ + client().async_js_console_request_messages(start_index); +} + void OutOfProcessWebView::run_javascript(StringView js_source) { client().async_run_javascript(js_source); diff --git a/Userland/Libraries/LibWeb/OutOfProcessWebView.h b/Userland/Libraries/LibWeb/OutOfProcessWebView.h index f3a997bf79..d63db9dc27 100644 --- a/Userland/Libraries/LibWeb/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWeb/OutOfProcessWebView.h @@ -43,6 +43,7 @@ public: void js_console_initialize(); void js_console_input(const String& js_source); + void js_console_request_messages(i32 start_index); void run_javascript(StringView); @@ -75,6 +76,8 @@ public: void notify_server_did_get_dom_tree(const String& dom_tree); void notify_server_did_get_dom_node_properties(i32 node_id, String const& specified_style, String const& computed_style); void notify_server_did_js_console_output(const String& method, const String& line); + void notify_server_did_output_js_console_message(i32 message_index); + void notify_server_did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages); void notify_server_did_change_favicon(const Gfx::Bitmap& favicon); String notify_server_did_request_cookie(Badge<WebContentClient>, const URL& url, Cookie::Source source); void notify_server_did_set_cookie(Badge<WebContentClient>, const URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source); diff --git a/Userland/Libraries/LibWeb/WebContentClient.cpp b/Userland/Libraries/LibWeb/WebContentClient.cpp index 90a43e9dbe..25e3e28204 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.cpp +++ b/Userland/Libraries/LibWeb/WebContentClient.cpp @@ -151,6 +151,16 @@ void WebContentClient::did_js_console_output(String const& method, String const& m_view.notify_server_did_js_console_output(method, line); } +void WebContentClient::did_output_js_console_message(i32 message_index) +{ + m_view.notify_server_did_output_js_console_message(message_index); +} + +void WebContentClient::did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages) +{ + m_view.notify_server_did_get_js_console_messages(start_index, message_types, messages); +} + void WebContentClient::did_request_alert(String const& message) { m_view.notify_server_did_request_alert({}, message); diff --git a/Userland/Libraries/LibWeb/WebContentClient.h b/Userland/Libraries/LibWeb/WebContentClient.h index 309f3f43d5..65ee0c4298 100644 --- a/Userland/Libraries/LibWeb/WebContentClient.h +++ b/Userland/Libraries/LibWeb/WebContentClient.h @@ -52,6 +52,8 @@ private: virtual void did_get_dom_tree(String const&) override; virtual void did_get_dom_node_properties(i32 node_id, String const& specified_style, String const& computed_style) override; virtual void did_js_console_output(String const&, String const&) override; + virtual void did_output_js_console_message(i32 message_index) override; + virtual void did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages) override; virtual void did_change_favicon(Gfx::ShareableBitmap const&) override; virtual void did_request_alert(String const&) override; virtual Messages::WebContentClient::DidRequestConfirmResponse did_request_confirm(String const&) override; diff --git a/Userland/Libraries/LibWeb/WebViewHooks.h b/Userland/Libraries/LibWeb/WebViewHooks.h index 24cc012b1f..3bdb5386a5 100644 --- a/Userland/Libraries/LibWeb/WebViewHooks.h +++ b/Userland/Libraries/LibWeb/WebViewHooks.h @@ -30,6 +30,8 @@ public: Function<void(const String&)> on_get_dom_tree; Function<void(i32 node_id, String const& specified_style, String const& computed_style)> on_get_dom_node_properties; Function<void(const String& method, const String& line)> on_js_console_output; + Function<void(i32 message_id)> on_js_console_new_message; + Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_get_js_console_messages; 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 031ae6307b..7d9064ad04 100644 --- a/Userland/Services/WebContent/ClientConnection.cpp +++ b/Userland/Services/WebContent/ClientConnection.cpp @@ -283,6 +283,18 @@ void ClientConnection::js_console_initialize() } } +void ClientConnection::initialize_js_console(Badge<PageHost>) +{ + auto* document = page().top_level_browsing_context().document(); + auto interpreter = document->interpreter().make_weak_ptr(); + if (m_interpreter.ptr() == interpreter.ptr()) + return; + + m_interpreter = interpreter; + m_console_client = make<WebContentConsoleClient>(interpreter->global_object().console(), interpreter, *this); + interpreter->global_object().console().set_client(*m_console_client.ptr()); +} + void ClientConnection::js_console_input(const String& js_source) { if (m_console_client) @@ -306,6 +318,11 @@ void ClientConnection::run_javascript(String const& js_source) } } +void ClientConnection::js_console_request_messages(i32) +{ + TODO(); +} + Messages::WebContentServer::GetSelectedTextResponse ClientConnection::get_selected_text() { return page().focused_context().selected_text(); diff --git a/Userland/Services/WebContent/ClientConnection.h b/Userland/Services/WebContent/ClientConnection.h index f4b6494048..77232f1ba4 100644 --- a/Userland/Services/WebContent/ClientConnection.h +++ b/Userland/Services/WebContent/ClientConnection.h @@ -29,6 +29,8 @@ public: virtual void die() override; + void initialize_js_console(Badge<PageHost>); + private: Web::Page& page(); const Web::Page& page() const; @@ -52,9 +54,12 @@ 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 void js_console_initialize() override; virtual void js_console_input(String const&) override; virtual void run_javascript(String const&) override; + virtual void js_console_request_messages(i32) override; + virtual Messages::WebContentServer::GetSelectedTextResponse get_selected_text() override; virtual void select_all() override; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index d5ea58a09d..ca1edbdb36 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -33,4 +33,8 @@ endpoint WebContentClient did_change_favicon(Gfx::ShareableBitmap favicon) =| did_request_cookie(URL url, u8 source) => (String cookie) did_set_cookie(URL url, Web::Cookie::ParsedCookie cookie, u8 source) =| + + did_output_js_console_message(i32 message_index) =| + did_get_js_console_messages(i32 start_index, Vector<String> message_types, Vector<String> messages) =| + } diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index fd84e456c0..23da9c81c1 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -31,6 +31,7 @@ endpoint WebContentServer get_hovered_node_id() => (i32 node_id) js_console_initialize() =| js_console_input(String js_source) =| + js_console_request_messages(i32 start_index) =| run_javascript(String js_source) =| |