WebContentConsoleClient.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2021, Brandon Scott <xeon.productions@gmail.com>
  3. * Copyright (c) 2020, Hunter Salyer <thefalsehonesty@gmail.com>
  4. * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/Vector.h>
  10. #include <AK/Weakable.h>
  11. #include <LibJS/Console.h>
  12. #include <LibJS/Forward.h>
  13. #include <LibWeb/Forward.h>
  14. #include <WebContent/ConsoleGlobalEnvironmentExtensions.h>
  15. #include <WebContent/Forward.h>
  16. namespace WebContent {
  17. class WebContentConsoleClient final : public JS::ConsoleClient
  18. , public Weakable<WebContentConsoleClient> {
  19. public:
  20. WebContentConsoleClient(JS::Console&, JS::Realm&, PageClient&);
  21. void handle_input(ByteString const& js_source);
  22. void send_messages(i32 start_index);
  23. void report_exception(JS::Error const&, bool) override;
  24. private:
  25. virtual void clear() override;
  26. virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
  27. virtual void add_css_style_to_current_message(StringView style) override
  28. {
  29. m_current_message_style.append(style);
  30. m_current_message_style.append(';');
  31. }
  32. PageClient& m_client;
  33. JS::Handle<ConsoleGlobalEnvironmentExtensions> m_console_global_environment_extensions;
  34. void clear_output();
  35. void print_html(ByteString const& line);
  36. void begin_group(ByteString const& label, bool start_expanded);
  37. virtual void end_group() override;
  38. struct ConsoleOutput {
  39. enum class Type {
  40. HTML,
  41. Clear,
  42. BeginGroup,
  43. BeginGroupCollapsed,
  44. EndGroup,
  45. };
  46. Type type;
  47. ByteString data;
  48. };
  49. Vector<ConsoleOutput> m_message_log;
  50. StringBuilder m_current_message_style;
  51. };
  52. }