2021-02-27 21:44:49 -06:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Brandon Scott <xeon.productions@gmail.com>
|
|
|
|
|
* Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
|
2021-09-04 11:45:36 +01:00
|
|
|
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
2021-02-27 21:44:49 -06:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-27 21:44:49 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2022-02-25 12:18:30 +02:00
|
|
|
#include "ConnectionFromClient.h"
|
2021-02-27 21:44:49 -06:00
|
|
|
#include <LibJS/Console.h>
|
|
|
|
|
#include <LibJS/Forward.h>
|
|
|
|
|
#include <LibWeb/Forward.h>
|
|
|
|
|
#include <WebContent/Forward.h>
|
|
|
|
|
|
|
|
|
|
namespace WebContent {
|
|
|
|
|
|
|
|
|
|
class WebContentConsoleClient final : public JS::ConsoleClient {
|
|
|
|
|
public:
|
2022-09-01 20:08:38 +02:00
|
|
|
WebContentConsoleClient(JS::Console&, JS::Realm&, ConnectionFromClient&);
|
2021-02-27 21:44:49 -06:00
|
|
|
|
2021-09-04 11:45:36 +01:00
|
|
|
void handle_input(String const& js_source);
|
|
|
|
|
void send_messages(i32 start_index);
|
2022-10-08 19:38:32 +04:00
|
|
|
void report_exception(JS::Error const&, bool) override;
|
2021-02-27 21:44:49 -06:00
|
|
|
|
|
|
|
|
private:
|
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-27 21:44:49 -06:00
|
|
|
|
2022-09-20 18:23:04 +01:00
|
|
|
virtual void add_css_style_to_current_message(StringView style) override
|
|
|
|
|
{
|
|
|
|
|
m_current_message_style.append(style);
|
|
|
|
|
m_current_message_style.append(';');
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-25 12:18:30 +02:00
|
|
|
ConnectionFromClient& m_client;
|
2022-09-01 20:08:38 +02:00
|
|
|
WeakPtr<JS::Realm> m_realm;
|
2022-04-05 17:47:52 +02:00
|
|
|
JS::Handle<ConsoleGlobalObject> m_console_global_object;
|
2021-09-03 10:16:36 +01:00
|
|
|
|
2021-02-27 21:44:49 -06:00
|
|
|
void clear_output();
|
2021-09-04 11:45:36 +01:00
|
|
|
void print_html(String const& line);
|
2021-12-22 12:32:15 +00:00
|
|
|
void begin_group(String const& label, bool start_expanded);
|
|
|
|
|
virtual void end_group() override;
|
2021-09-04 11:45:36 +01:00
|
|
|
|
|
|
|
|
struct ConsoleOutput {
|
|
|
|
|
enum class Type {
|
|
|
|
|
HTML,
|
2021-12-22 12:32:15 +00:00
|
|
|
Clear,
|
|
|
|
|
BeginGroup,
|
|
|
|
|
BeginGroupCollapsed,
|
|
|
|
|
EndGroup,
|
2021-09-04 11:45:36 +01:00
|
|
|
};
|
|
|
|
|
Type type;
|
2021-12-22 12:32:15 +00:00
|
|
|
String data;
|
2021-09-04 11:45:36 +01:00
|
|
|
};
|
|
|
|
|
Vector<ConsoleOutput> m_message_log;
|
2022-09-20 18:23:04 +01:00
|
|
|
|
|
|
|
|
StringBuilder m_current_message_style;
|
2021-02-27 21:44:49 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|