InspectorClient.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Function.h>
  7. #include <AK/HashMap.h>
  8. #include <AK/JsonValue.h>
  9. #include <AK/StringView.h>
  10. #include <AK/Vector.h>
  11. #include <LibGfx/Point.h>
  12. #include <LibWebView/Attribute.h>
  13. #include <LibWebView/ViewImplementation.h>
  14. #pragma once
  15. namespace WebView {
  16. class InspectorClient {
  17. public:
  18. InspectorClient(ViewImplementation& content_web_view, ViewImplementation& inspector_web_view);
  19. ~InspectorClient();
  20. void inspect();
  21. void reset();
  22. void select_hovered_node();
  23. void select_default_node();
  24. void clear_selection();
  25. void context_menu_edit_dom_node();
  26. void context_menu_copy_dom_node();
  27. void context_menu_screenshot_dom_node();
  28. void context_menu_create_child_element();
  29. void context_menu_create_child_text_node();
  30. void context_menu_clone_dom_node();
  31. void context_menu_remove_dom_node();
  32. void context_menu_add_dom_node_attribute();
  33. void context_menu_remove_dom_node_attribute();
  34. void context_menu_copy_dom_node_attribute_value();
  35. void context_menu_delete_cookie();
  36. void context_menu_delete_all_cookies();
  37. Function<void(Gfx::IntPoint)> on_requested_dom_node_text_context_menu;
  38. Function<void(Gfx::IntPoint, String const&)> on_requested_dom_node_tag_context_menu;
  39. Function<void(Gfx::IntPoint, String const&, Attribute const&)> on_requested_dom_node_attribute_context_menu;
  40. Function<void(Gfx::IntPoint, Web::Cookie::Cookie const&)> on_requested_cookie_context_menu;
  41. private:
  42. void load_inspector();
  43. String generate_dom_tree(JsonObject const&);
  44. String generate_accessibility_tree(JsonObject const&);
  45. void select_node(i32 node_id);
  46. void load_cookies();
  47. void request_console_messages();
  48. void handle_console_message(i32 message_index);
  49. void handle_console_messages(i32 start_index, ReadonlySpan<ByteString> message_types, ReadonlySpan<ByteString> messages);
  50. void append_console_source(StringView);
  51. void append_console_message(StringView);
  52. void append_console_warning(StringView);
  53. void append_console_output(StringView);
  54. void clear_console_output();
  55. void begin_console_group(StringView label, bool start_expanded);
  56. void end_console_group();
  57. ViewImplementation& m_content_web_view;
  58. ViewImplementation& m_inspector_web_view;
  59. Optional<i32> m_body_node_id;
  60. Optional<i32> m_pending_selection;
  61. bool m_inspector_loaded { false };
  62. bool m_dom_tree_loaded { false };
  63. struct ContextMenuData {
  64. i32 dom_node_id { 0 };
  65. Optional<String> tag;
  66. Optional<Attribute> attribute;
  67. };
  68. Optional<ContextMenuData> m_context_menu_data;
  69. HashMap<int, Vector<Attribute>> m_dom_node_attributes;
  70. Vector<Web::Cookie::Cookie> m_cookies;
  71. Optional<size_t> m_cookie_context_menu_index;
  72. i32 m_highest_notified_message_index { -1 };
  73. i32 m_highest_received_message_index { -1 };
  74. bool m_waiting_for_messages { false };
  75. };
  76. }