From 14a8ffa867a6cf21cfc59924dd345d22e924172b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 3 Mar 2025 16:12:49 -0500 Subject: [PATCH] WebContent: Move console handling from WebContentCC to InspectorCC The idea originally was that the WebContentConsoleClient would perform some amount of console handling that both InspectorConsoleClient and DevToolsConsoleClient needed. But in implementing the DevTools console, it's become clear that these implementations will not overlap at all. So this patch moves the existing Inspector functionality away from WebContentConsoleClient. --- Services/WebContent/DevToolsConsoleClient.h | 6 ++-- .../WebContent/InspectorConsoleClient.cpp | 33 +++++++++++++++---- Services/WebContent/InspectorConsoleClient.h | 23 ++++++++++++- .../WebContent/WebContentConsoleClient.cpp | 29 ---------------- Services/WebContent/WebContentConsoleClient.h | 22 ------------- 5 files changed, 53 insertions(+), 60 deletions(-) diff --git a/Services/WebContent/DevToolsConsoleClient.h b/Services/WebContent/DevToolsConsoleClient.h index 0f86c6320fd..59e87bd574e 100644 --- a/Services/WebContent/DevToolsConsoleClient.h +++ b/Services/WebContent/DevToolsConsoleClient.h @@ -27,9 +27,11 @@ private: virtual void handle_result(JS::Value) override; virtual void report_exception(JS::Error const&, bool) override; - virtual void send_messages(i32 start_index) override; + virtual void end_group() override { } + virtual void clear() override { } - virtual JS::ThrowCompletionOr printer(JS::Console::LogLevel log_level, PrinterArguments) override; + virtual void send_messages(i32 start_index) override; + virtual JS::ThrowCompletionOr printer(JS::Console::LogLevel, PrinterArguments) override; }; } diff --git a/Services/WebContent/InspectorConsoleClient.cpp b/Services/WebContent/InspectorConsoleClient.cpp index 7c7d7d0eb61..6ac4878c33e 100644 --- a/Services/WebContent/InspectorConsoleClient.cpp +++ b/Services/WebContent/InspectorConsoleClient.cpp @@ -8,7 +8,6 @@ */ #include -#include #include #include #include @@ -47,16 +46,38 @@ void InspectorConsoleClient::report_exception(JS::Error const& exception, bool i print_html(JS::MarkupGenerator::html_from_error(exception, in_promise).release_value_but_fixme_should_propagate_errors()); } +void InspectorConsoleClient::begin_group(String const& label, bool start_expanded) +{ + m_message_log.append({ .type = start_expanded ? ConsoleOutput::Type::BeginGroup : ConsoleOutput::Type::BeginGroupCollapsed, .data = label }); + m_client->did_output_js_console_message(m_message_log.size() - 1); +} + +void InspectorConsoleClient::end_group() +{ + m_message_log.append({ .type = ConsoleOutput::Type::EndGroup, .data = String {} }); + m_client->did_output_js_console_message(m_message_log.size() - 1); +} + +void InspectorConsoleClient::clear() +{ + m_message_log.append({ .type = ConsoleOutput::Type::Clear, .data = String {} }); + m_client->did_output_js_console_message(m_message_log.size() - 1); +} + +void InspectorConsoleClient::print_html(String const& line) +{ + m_message_log.append({ .type = ConsoleOutput::Type::HTML, .data = line }); + m_client->did_output_js_console_message(m_message_log.size() - 1); +} + void InspectorConsoleClient::send_messages(i32 start_index) { - // FIXME: Cap the number of messages we send at once? auto messages_to_send = m_message_log.size() - start_index; if (messages_to_send < 1) { - // When the console is first created, it requests any messages that happened before - // then, by requesting with start_index=0. If we don't have any messages at all, that - // is still a valid request, and we can just ignore it. + // When the console is first created, it requests any messages that happened before then, by requesting with + // start_index=0. If we don't have any messages at all, that is still a valid request, and we can just ignore it. if (start_index != 0) - m_client->console_peer_did_misbehave("Requested non-existent console message index."); + m_client->console_peer_did_misbehave("Requested non-existent console message index"); return; } diff --git a/Services/WebContent/InspectorConsoleClient.h b/Services/WebContent/InspectorConsoleClient.h index c5985fae060..b81b747de38 100644 --- a/Services/WebContent/InspectorConsoleClient.h +++ b/Services/WebContent/InspectorConsoleClient.h @@ -8,7 +8,9 @@ #pragma once +#include #include +#include #include #include #include @@ -28,8 +30,14 @@ private: virtual void handle_result(JS::Value) override; virtual void report_exception(JS::Error const&, bool) override; - virtual void send_messages(i32 start_index) override; + void begin_group(String const& label, bool start_expanded); + virtual void end_group() override; + virtual void clear() override; + + void print_html(String const& line); + + virtual void send_messages(i32 start_index) override; virtual JS::ThrowCompletionOr printer(JS::Console::LogLevel log_level, PrinterArguments) override; virtual void add_css_style_to_current_message(StringView style) override @@ -38,6 +46,19 @@ private: m_current_message_style.append(';'); } + struct ConsoleOutput { + enum class Type { + HTML, + Clear, + BeginGroup, + BeginGroupCollapsed, + EndGroup, + }; + Type type; + String data; + }; + + Vector m_message_log; StringBuilder m_current_message_style; }; diff --git a/Services/WebContent/WebContentConsoleClient.cpp b/Services/WebContent/WebContentConsoleClient.cpp index 6cc652aefc5..046d33b9fa4 100644 --- a/Services/WebContent/WebContentConsoleClient.cpp +++ b/Services/WebContent/WebContentConsoleClient.cpp @@ -54,33 +54,4 @@ void WebContentConsoleClient::handle_input(StringView js_source) } } -void WebContentConsoleClient::print_html(String const& line) -{ - m_message_log.append({ .type = ConsoleOutput::Type::HTML, .data = line }); - m_client->did_output_js_console_message(m_message_log.size() - 1); -} - -void WebContentConsoleClient::clear() -{ - clear_output(); -} - -void WebContentConsoleClient::clear_output() -{ - m_message_log.append({ .type = ConsoleOutput::Type::Clear, .data = String {} }); - m_client->did_output_js_console_message(m_message_log.size() - 1); -} - -void WebContentConsoleClient::begin_group(String const& label, bool start_expanded) -{ - m_message_log.append({ .type = start_expanded ? ConsoleOutput::Type::BeginGroup : ConsoleOutput::Type::BeginGroupCollapsed, .data = label }); - m_client->did_output_js_console_message(m_message_log.size() - 1); -} - -void WebContentConsoleClient::end_group() -{ - m_message_log.append({ .type = ConsoleOutput::Type::EndGroup, .data = String {} }); - m_client->did_output_js_console_message(m_message_log.size() - 1); -} - } diff --git a/Services/WebContent/WebContentConsoleClient.h b/Services/WebContent/WebContentConsoleClient.h index c302f8c43ba..9c1bce75f61 100644 --- a/Services/WebContent/WebContentConsoleClient.h +++ b/Services/WebContent/WebContentConsoleClient.h @@ -8,7 +8,6 @@ #pragma once -#include #include #include #include @@ -34,30 +33,9 @@ protected: virtual void visit_edges(JS::Cell::Visitor&) override; - void print_html(String const& line); - - virtual void clear() override; - void clear_output(); - - void begin_group(String const& label, bool start_expanded); - virtual void end_group() override; - GC::Ref m_realm; GC::Ref m_client; GC::Ref m_console_global_environment_extensions; - - struct ConsoleOutput { - enum class Type { - HTML, - Clear, - BeginGroup, - BeginGroupCollapsed, - EndGroup, - }; - Type type; - String data; - }; - Vector m_message_log; }; }