ConsoleClient.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/DeprecatedString.h>
  8. #include <AK/Function.h>
  9. #include <AK/Span.h>
  10. #include <AK/String.h>
  11. #include <AK/StringView.h>
  12. #include <AK/Vector.h>
  13. #include <LibWebView/Forward.h>
  14. namespace WebView {
  15. class ConsoleClient {
  16. public:
  17. explicit ConsoleClient(ViewImplementation& content_web_view, ViewImplementation& console_web_view);
  18. ~ConsoleClient();
  19. void execute(String);
  20. Optional<String> previous_history_item();
  21. Optional<String> next_history_item();
  22. void clear();
  23. void reset();
  24. private:
  25. void handle_console_message(i32 message_index);
  26. void handle_console_messages(i32 start_index, ReadonlySpan<DeprecatedString> message_types, ReadonlySpan<DeprecatedString> messages);
  27. void print_source(StringView);
  28. void print_html(StringView);
  29. void request_console_messages();
  30. void begin_group(StringView label, bool start_expanded);
  31. void end_group();
  32. ViewImplementation& m_content_web_view;
  33. ViewImplementation& m_console_web_view;
  34. i32 m_highest_notified_message_index { -1 };
  35. i32 m_highest_received_message_index { -1 };
  36. bool m_waiting_for_messages { false };
  37. struct Group {
  38. int id { 0 };
  39. DeprecatedString label;
  40. };
  41. Vector<Group> m_group_stack;
  42. int m_next_group_id { 1 };
  43. Vector<String> m_history;
  44. size_t m_history_index { 0 };
  45. };
  46. }