2021-02-28 03:44:49 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Brandon Scott <xeon.productions@gmail.com>
|
|
|
|
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
|
2022-11-19 16:12:19 +00:00
|
|
|
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
2021-02-28 03:44:49 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-28 03:44:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-02-03 01:00:48 +00:00
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <AK/Weakable.h>
|
2021-02-28 03:44:49 +00:00
|
|
|
#include <LibJS/Console.h>
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
#include <LibWeb/Forward.h>
|
2024-02-03 01:00:48 +00:00
|
|
|
#include <WebContent/ConsoleGlobalEnvironmentExtensions.h>
|
2021-02-28 03:44:49 +00:00
|
|
|
#include <WebContent/Forward.h>
|
|
|
|
|
|
|
|
namespace WebContent {
|
|
|
|
|
2024-05-02 08:24:23 +00:00
|
|
|
class WebContentConsoleClient final : public JS::ConsoleClient {
|
2024-11-14 15:01:23 +00:00
|
|
|
GC_CELL(WebContentConsoleClient, JS::ConsoleClient);
|
|
|
|
GC_DECLARE_ALLOCATOR(WebContentConsoleClient);
|
2024-04-20 19:19:51 +00:00
|
|
|
|
2021-02-28 03:44:49 +00:00
|
|
|
public:
|
2024-04-20 19:19:51 +00:00
|
|
|
virtual ~WebContentConsoleClient() override;
|
2021-02-28 03:44:49 +00:00
|
|
|
|
2023-12-16 14:19:34 +00:00
|
|
|
void handle_input(ByteString const& js_source);
|
2021-09-04 10:45:36 +00:00
|
|
|
void send_messages(i32 start_index);
|
2022-10-08 15:38:32 +00:00
|
|
|
void report_exception(JS::Error const&, bool) override;
|
2021-02-28 03:44:49 +00:00
|
|
|
|
|
|
|
private:
|
2024-04-20 19:19:51 +00:00
|
|
|
WebContentConsoleClient(JS::Console&, JS::Realm&, PageClient&);
|
|
|
|
|
|
|
|
virtual void visit_edges(JS::Cell::Visitor&) override;
|
2021-12-08 19:24:17 +00:00
|
|
|
virtual void clear() override;
|
2021-12-22 12:32:15 +00:00
|
|
|
virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
|
2021-02-28 03:44:49 +00:00
|
|
|
|
2022-09-20 17:23:04 +00:00
|
|
|
virtual void add_css_style_to_current_message(StringView style) override
|
|
|
|
{
|
|
|
|
m_current_message_style.append(style);
|
|
|
|
m_current_message_style.append(';');
|
|
|
|
}
|
|
|
|
|
2024-11-14 15:01:23 +00:00
|
|
|
GC::Ref<PageClient> m_client;
|
|
|
|
GC::Ptr<ConsoleGlobalEnvironmentExtensions> m_console_global_environment_extensions;
|
2021-09-03 09:16:36 +00:00
|
|
|
|
2021-02-28 03:44:49 +00:00
|
|
|
void clear_output();
|
2023-12-16 14:19:34 +00:00
|
|
|
void print_html(ByteString const& line);
|
|
|
|
void begin_group(ByteString const& label, bool start_expanded);
|
2021-12-22 12:32:15 +00:00
|
|
|
virtual void end_group() override;
|
2021-09-04 10:45:36 +00:00
|
|
|
|
|
|
|
struct ConsoleOutput {
|
|
|
|
enum class Type {
|
|
|
|
HTML,
|
2021-12-22 12:32:15 +00:00
|
|
|
Clear,
|
|
|
|
BeginGroup,
|
|
|
|
BeginGroupCollapsed,
|
|
|
|
EndGroup,
|
2021-09-04 10:45:36 +00:00
|
|
|
};
|
|
|
|
Type type;
|
2023-12-16 14:19:34 +00:00
|
|
|
ByteString data;
|
2021-09-04 10:45:36 +00:00
|
|
|
};
|
|
|
|
Vector<ConsoleOutput> m_message_log;
|
2022-09-20 17:23:04 +00:00
|
|
|
|
|
|
|
StringBuilder m_current_message_style;
|
2021-02-28 03:44:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|