mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 00:29:15 +00:00
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.
This commit is contained in:
parent
1adcaf7181
commit
14a8ffa867
Notes:
github-actions[bot]
2025-03-04 20:35:05 +00:00
Author: https://github.com/trflynn89
Commit: 14a8ffa867
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3801
Reviewed-by: https://github.com/AtkinsSJ
5 changed files with 53 additions and 60 deletions
|
@ -27,9 +27,11 @@ private:
|
||||||
|
|
||||||
virtual void handle_result(JS::Value) override;
|
virtual void handle_result(JS::Value) override;
|
||||||
virtual void report_exception(JS::Error const&, bool) 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<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
|
virtual void send_messages(i32 start_index) override;
|
||||||
|
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel, PrinterArguments) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/MemoryStream.h>
|
#include <AK/MemoryStream.h>
|
||||||
#include <AK/String.h>
|
|
||||||
#include <LibJS/MarkupGenerator.h>
|
#include <LibJS/MarkupGenerator.h>
|
||||||
#include <LibJS/Print.h>
|
#include <LibJS/Print.h>
|
||||||
#include <LibJS/Runtime/Realm.h>
|
#include <LibJS/Runtime/Realm.h>
|
||||||
|
@ -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());
|
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)
|
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;
|
auto messages_to_send = m_message_log.size() - start_index;
|
||||||
if (messages_to_send < 1) {
|
if (messages_to_send < 1) {
|
||||||
// When the console is first created, it requests any messages that happened before
|
// When the console is first created, it requests any messages that happened before then, by requesting with
|
||||||
// then, by requesting with start_index=0. If we don't have any messages at all, that
|
// start_index=0. If we don't have any messages at all, that is still a valid request, and we can just ignore it.
|
||||||
// is still a valid request, and we can just ignore it.
|
|
||||||
if (start_index != 0)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/String.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
|
#include <AK/Vector.h>
|
||||||
#include <LibWeb/Forward.h>
|
#include <LibWeb/Forward.h>
|
||||||
#include <WebContent/Forward.h>
|
#include <WebContent/Forward.h>
|
||||||
#include <WebContent/WebContentConsoleClient.h>
|
#include <WebContent/WebContentConsoleClient.h>
|
||||||
|
@ -28,8 +30,14 @@ private:
|
||||||
|
|
||||||
virtual void handle_result(JS::Value) override;
|
virtual void handle_result(JS::Value) override;
|
||||||
virtual void report_exception(JS::Error const&, bool) 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<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
|
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
|
||||||
|
|
||||||
virtual void add_css_style_to_current_message(StringView style) override
|
virtual void add_css_style_to_current_message(StringView style) override
|
||||||
|
@ -38,6 +46,19 @@ private:
|
||||||
m_current_message_style.append(';');
|
m_current_message_style.append(';');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ConsoleOutput {
|
||||||
|
enum class Type {
|
||||||
|
HTML,
|
||||||
|
Clear,
|
||||||
|
BeginGroup,
|
||||||
|
BeginGroupCollapsed,
|
||||||
|
EndGroup,
|
||||||
|
};
|
||||||
|
Type type;
|
||||||
|
String data;
|
||||||
|
};
|
||||||
|
|
||||||
|
Vector<ConsoleOutput> m_message_log;
|
||||||
StringBuilder m_current_message_style;
|
StringBuilder m_current_message_style;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/Vector.h>
|
|
||||||
#include <LibJS/Console.h>
|
#include <LibJS/Console.h>
|
||||||
#include <LibJS/Forward.h>
|
#include <LibJS/Forward.h>
|
||||||
#include <LibJS/Runtime/Value.h>
|
#include <LibJS/Runtime/Value.h>
|
||||||
|
@ -34,30 +33,9 @@ protected:
|
||||||
|
|
||||||
virtual void visit_edges(JS::Cell::Visitor&) override;
|
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<JS::Realm> m_realm;
|
GC::Ref<JS::Realm> m_realm;
|
||||||
GC::Ref<PageClient> m_client;
|
GC::Ref<PageClient> m_client;
|
||||||
GC::Ref<ConsoleGlobalEnvironmentExtensions> m_console_global_environment_extensions;
|
GC::Ref<ConsoleGlobalEnvironmentExtensions> m_console_global_environment_extensions;
|
||||||
|
|
||||||
struct ConsoleOutput {
|
|
||||||
enum class Type {
|
|
||||||
HTML,
|
|
||||||
Clear,
|
|
||||||
BeginGroup,
|
|
||||||
BeginGroupCollapsed,
|
|
||||||
EndGroup,
|
|
||||||
};
|
|
||||||
Type type;
|
|
||||||
String data;
|
|
||||||
};
|
|
||||||
Vector<ConsoleOutput> m_message_log;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue