WebContentConsoleClient.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. JS_CELL(WebContentConsoleClient, JS::ConsoleClient);
  19. JS_DECLARE_ALLOCATOR(WebContentConsoleClient);
  20. public:
  21. virtual ~WebContentConsoleClient() override;
  22. void handle_input(ByteString const& js_source);
  23. void send_messages(i32 start_index);
  24. void report_exception(JS::Error const&, bool) override;
  25. private:
  26. WebContentConsoleClient(JS::Console&, JS::Realm&, PageClient&);
  27. virtual void visit_edges(JS::Cell::Visitor&) override;
  28. virtual void clear() override;
  29. virtual JS::ThrowCompletionOr<JS::Value> printer(JS::Console::LogLevel log_level, PrinterArguments) override;
  30. virtual void add_css_style_to_current_message(StringView style) override
  31. {
  32. m_current_message_style.append(style);
  33. m_current_message_style.append(';');
  34. }
  35. JS::NonnullGCPtr<PageClient> m_client;
  36. JS::GCPtr<ConsoleGlobalEnvironmentExtensions> m_console_global_environment_extensions;
  37. void clear_output();
  38. void print_html(ByteString const& line);
  39. void begin_group(ByteString const& label, bool start_expanded);
  40. virtual void end_group() override;
  41. struct ConsoleOutput {
  42. enum class Type {
  43. HTML,
  44. Clear,
  45. BeginGroup,
  46. BeginGroupCollapsed,
  47. EndGroup,
  48. };
  49. Type type;
  50. ByteString data;
  51. };
  52. Vector<ConsoleOutput> m_message_log;
  53. StringBuilder m_current_message_style;
  54. };
  55. }