OutOfProcessWebView.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/URL.h>
  8. #include <LibGUI/AbstractScrollableWidget.h>
  9. #include <LibGUI/Widget.h>
  10. #include <LibWeb/CSS/Selector.h>
  11. #include <LibWeb/Page/Page.h>
  12. namespace WebView {
  13. class WebContentClient;
  14. class OutOfProcessWebView final : public GUI::AbstractScrollableWidget {
  15. C_OBJECT(OutOfProcessWebView);
  16. public:
  17. virtual ~OutOfProcessWebView() override;
  18. AK::URL url() const { return m_url; }
  19. void load(const AK::URL&);
  20. void load_html(StringView, const AK::URL&);
  21. void load_empty_document();
  22. void debug_request(String const& request, String const& argument = {});
  23. void get_source();
  24. void inspect_dom_tree();
  25. struct DOMNodeProperties {
  26. String specified_values_json;
  27. String computed_values_json;
  28. String custom_properties_json;
  29. String node_box_sizing_json;
  30. };
  31. Optional<DOMNodeProperties> inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement>);
  32. void clear_inspected_dom_node();
  33. i32 get_hovered_node_id();
  34. void js_console_input(String const& js_source);
  35. void js_console_request_messages(i32 start_index);
  36. void run_javascript(StringView);
  37. String selected_text();
  38. void select_all();
  39. String dump_layout_tree();
  40. OrderedHashMap<String, String> get_local_storage_entries();
  41. OrderedHashMap<String, String> get_session_storage_entries();
  42. void set_content_filters(Vector<String>);
  43. void set_proxy_mappings(Vector<String> proxies, HashMap<String, size_t> mappings);
  44. void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
  45. Function<void(Gfx::IntPoint const& screen_position)> on_context_menu_request;
  46. Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_click;
  47. Function<void(const AK::URL&, Gfx::IntPoint const& screen_position)> on_link_context_menu_request;
  48. Function<void(const AK::URL&, Gfx::IntPoint const& screen_position, Gfx::ShareableBitmap const&)> on_image_context_menu_request;
  49. Function<void(const AK::URL&, String const& target, unsigned modifiers)> on_link_middle_click;
  50. Function<void(const AK::URL&)> on_link_hover;
  51. Function<void(String const&)> on_title_change;
  52. Function<void(const AK::URL&)> on_load_start;
  53. Function<void(const AK::URL&)> on_load_finish;
  54. Function<void(Gfx::Bitmap const&)> on_favicon_change;
  55. Function<void(const AK::URL&)> on_url_drop;
  56. Function<void(Web::DOM::Document*)> on_set_document;
  57. Function<void(const AK::URL&, String const&)> on_get_source;
  58. Function<void(String const&)> on_get_dom_tree;
  59. Function<void(i32 node_id, String const& specified_style, String const& computed_style, String const& custom_properties, String const& node_box_sizing)> on_get_dom_node_properties;
  60. Function<void(i32 message_id)> on_js_console_new_message;
  61. Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_get_js_console_messages;
  62. Function<String(const AK::URL& url, Web::Cookie::Source source)> on_get_cookie;
  63. Function<void(const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)> on_set_cookie;
  64. Function<void(i32 count_waiting)> on_resource_status_change;
  65. void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize const& content_size);
  66. void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
  67. void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&);
  68. void notify_server_did_change_selection(Badge<WebContentClient>);
  69. void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor);
  70. void notify_server_did_change_title(Badge<WebContentClient>, String const&);
  71. void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32);
  72. void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint const&);
  73. void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&);
  74. void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint const&, String const&);
  75. void notify_server_did_leave_tooltip_area(Badge<WebContentClient>);
  76. void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&);
  77. void notify_server_did_unhover_link(Badge<WebContentClient>);
  78. void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers);
  79. void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, String const& target, unsigned modifiers);
  80. void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&);
  81. void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&);
  82. void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&);
  83. void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers);
  84. void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint const&, const AK::URL&, String const& target, unsigned modifiers, Gfx::ShareableBitmap const&);
  85. void notify_server_did_request_alert(Badge<WebContentClient>, String const& message);
  86. bool notify_server_did_request_confirm(Badge<WebContentClient>, String const& message);
  87. String notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_);
  88. void notify_server_did_get_source(const AK::URL& url, String const& source);
  89. void notify_server_did_get_dom_tree(String const& dom_tree);
  90. void notify_server_did_get_dom_node_properties(i32 node_id, String const& specified_style, String const& computed_style, String const& custom_properties, String const& node_box_sizing);
  91. void notify_server_did_output_js_console_message(i32 message_index);
  92. void notify_server_did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages);
  93. void notify_server_did_change_favicon(Gfx::Bitmap const& favicon);
  94. String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source);
  95. void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source);
  96. void notify_server_did_update_resource_count(i32 count_waiting);
  97. void notify_server_did_request_file(Badge<WebContentClient>, String const& path, i32);
  98. private:
  99. OutOfProcessWebView();
  100. // ^Widget
  101. virtual void paint_event(GUI::PaintEvent&) override;
  102. virtual void resize_event(GUI::ResizeEvent&) override;
  103. virtual void mousedown_event(GUI::MouseEvent&) override;
  104. virtual void mouseup_event(GUI::MouseEvent&) override;
  105. virtual void mousemove_event(GUI::MouseEvent&) override;
  106. virtual void mousewheel_event(GUI::MouseEvent&) override;
  107. virtual void doubleclick_event(GUI::MouseEvent&) override;
  108. virtual void keydown_event(GUI::KeyEvent&) override;
  109. virtual void keyup_event(GUI::KeyEvent&) override;
  110. virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
  111. virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;
  112. virtual void focusin_event(GUI::FocusEvent&) override;
  113. virtual void focusout_event(GUI::FocusEvent&) override;
  114. virtual void show_event(GUI::ShowEvent&) override;
  115. virtual void hide_event(GUI::HideEvent&) override;
  116. // ^AbstractScrollableWidget
  117. virtual void did_scroll() override;
  118. void request_repaint();
  119. void handle_resize();
  120. void create_client();
  121. WebContentClient& client();
  122. void handle_web_content_process_crash();
  123. AK::URL m_url;
  124. struct SharedBitmap {
  125. i32 id { -1 };
  126. i32 pending_paints { 0 };
  127. RefPtr<Gfx::Bitmap> bitmap;
  128. };
  129. struct ClientState {
  130. RefPtr<WebContentClient> client;
  131. SharedBitmap front_bitmap;
  132. SharedBitmap back_bitmap;
  133. i32 next_bitmap_id { 0 };
  134. bool has_usable_bitmap { false };
  135. bool got_repaint_requests_while_painting { false };
  136. } m_client_state;
  137. RefPtr<Gfx::Bitmap> m_backup_bitmap;
  138. };
  139. }