WebContentConsoleClient.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. * Copyright (c) 2021, Brandon Scott <xeon.productions@gmail.com>
  3. * Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
  4. * Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include "ClientConnection.h"
  10. #include <LibJS/Console.h>
  11. #include <LibJS/Forward.h>
  12. #include <LibWeb/Forward.h>
  13. #include <WebContent/Forward.h>
  14. namespace WebContent {
  15. class WebContentConsoleClient final : public JS::ConsoleClient {
  16. public:
  17. WebContentConsoleClient(JS::Console&, WeakPtr<JS::Interpreter>, ClientConnection&);
  18. void handle_input(String const& js_source);
  19. void send_messages(i32 start_index);
  20. private:
  21. virtual JS::Value clear() override;
  22. virtual JS::Value trace() override;
  23. virtual JS::Value assert_() override;
  24. virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, Vector<JS::Value>&) override;
  25. ClientConnection& m_client;
  26. WeakPtr<JS::Interpreter> m_interpreter;
  27. JS::Handle<ConsoleGlobalObject> m_console_global_object;
  28. void clear_output();
  29. void print_html(String const& line);
  30. struct ConsoleOutput {
  31. enum class Type {
  32. HTML,
  33. Clear
  34. };
  35. Type type;
  36. String html;
  37. };
  38. Vector<ConsoleOutput> m_message_log;
  39. };
  40. }