OutOfProcessWebView.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Queue.h>
  9. #include <AK/URL.h>
  10. #include <LibGUI/AbstractScrollableWidget.h>
  11. #include <LibGUI/Widget.h>
  12. #include <LibWeb/CSS/Selector.h>
  13. #include <LibWeb/HTML/ActivateTab.h>
  14. #include <LibWeb/Page/Page.h>
  15. #include <LibWebView/ViewImplementation.h>
  16. namespace Messages::WebContentServer {
  17. class WebdriverExecuteScriptResponse;
  18. }
  19. namespace WebView {
  20. class WebContentClient;
  21. class OutOfProcessWebView final
  22. : public GUI::AbstractScrollableWidget
  23. , public ViewImplementation {
  24. C_OBJECT(OutOfProcessWebView);
  25. using Super = GUI::AbstractScrollableWidget;
  26. public:
  27. virtual ~OutOfProcessWebView() override;
  28. void js_console_input(DeprecatedString const& js_source);
  29. void js_console_request_messages(i32 start_index);
  30. DeprecatedString dump_layout_tree();
  31. OrderedHashMap<DeprecatedString, DeprecatedString> get_local_storage_entries();
  32. OrderedHashMap<DeprecatedString, DeprecatedString> get_session_storage_entries();
  33. void set_content_filters(Vector<String>);
  34. void set_autoplay_allowed_on_all_websites();
  35. void set_autoplay_allowlist(Vector<String>);
  36. void set_proxy_mappings(Vector<DeprecatedString> proxies, HashMap<DeprecatedString, size_t> mappings);
  37. void connect_to_webdriver(DeprecatedString const& webdriver_ipc_path);
  38. void set_window_position(Gfx::IntPoint);
  39. void set_window_size(Gfx::IntSize);
  40. void set_system_visibility_state(bool visible);
  41. Gfx::ShareableBitmap take_screenshot() const;
  42. Gfx::ShareableBitmap take_document_screenshot();
  43. // This is a hint that tells OOPWV that the content will scale to the viewport size.
  44. // In practice, this means that OOPWV may render scaled stale versions of the content while resizing.
  45. void set_content_scales_to_viewport(bool);
  46. Function<String(Web::HTML::ActivateTab)> on_new_tab;
  47. Function<void()> on_activate_tab;
  48. Function<void()> on_close;
  49. Function<void(Gfx::IntPoint screen_position)> on_context_menu_request;
  50. Function<void(const AK::URL&, DeprecatedString const& target, unsigned modifiers)> on_link_click;
  51. Function<void(const AK::URL&, Gfx::IntPoint screen_position)> on_link_context_menu_request;
  52. Function<void(const AK::URL&, Gfx::IntPoint screen_position, Gfx::ShareableBitmap const&)> on_image_context_menu_request;
  53. Function<void(const AK::URL&, DeprecatedString const& target, unsigned modifiers)> on_link_middle_click;
  54. Function<void(const AK::URL&)> on_link_hover;
  55. Function<void(DeprecatedString const&)> on_title_change;
  56. Function<void(const AK::URL&, bool)> on_load_start;
  57. Function<void(const AK::URL&)> on_load_finish;
  58. Function<void()> on_navigate_back;
  59. Function<void()> on_navigate_forward;
  60. Function<void()> on_refresh;
  61. Function<void(Gfx::Bitmap const&)> on_favicon_change;
  62. Function<void(const AK::URL&)> on_url_drop;
  63. Function<void(Web::DOM::Document*)> on_set_document;
  64. Function<void(const AK::URL&, DeprecatedString const&)> on_get_source;
  65. Function<void(DeprecatedString const&)> on_get_dom_tree;
  66. Function<void(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing)> on_get_dom_node_properties;
  67. Function<void(DeprecatedString const&)> on_get_accessibility_tree;
  68. Function<void(i32 message_id)> on_js_console_new_message;
  69. Function<void(i32 start_index, Vector<DeprecatedString> const& message_types, Vector<DeprecatedString> const& messages)> on_get_js_console_messages;
  70. Function<Vector<Web::Cookie::Cookie>(AK::URL const& url)> on_get_all_cookies;
  71. Function<Optional<Web::Cookie::Cookie>(AK::URL const& url, DeprecatedString const& name)> on_get_named_cookie;
  72. Function<DeprecatedString(const AK::URL& url, Web::Cookie::Source source)> on_get_cookie;
  73. Function<void(const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source)> on_set_cookie;
  74. Function<void(Web::Cookie::Cookie const& cookie)> on_update_cookie;
  75. Function<void(i32 count_waiting)> on_resource_status_change;
  76. Function<void()> on_restore_window;
  77. Function<Gfx::IntPoint(Gfx::IntPoint)> on_reposition_window;
  78. Function<Gfx::IntSize(Gfx::IntSize)> on_resize_window;
  79. Function<Gfx::IntRect()> on_maximize_window;
  80. Function<Gfx::IntRect()> on_minimize_window;
  81. Function<Gfx::IntRect()> on_fullscreen_window;
  82. Function<void()> on_back_button;
  83. Function<void()> on_forward_button;
  84. private:
  85. OutOfProcessWebView();
  86. // ^Widget
  87. virtual void paint_event(GUI::PaintEvent&) override;
  88. virtual void resize_event(GUI::ResizeEvent&) override;
  89. virtual void mousedown_event(GUI::MouseEvent&) override;
  90. virtual void mouseup_event(GUI::MouseEvent&) override;
  91. virtual void mousemove_event(GUI::MouseEvent&) override;
  92. virtual void mousewheel_event(GUI::MouseEvent&) override;
  93. virtual void doubleclick_event(GUI::MouseEvent&) override;
  94. virtual void keydown_event(GUI::KeyEvent&) override;
  95. virtual void keyup_event(GUI::KeyEvent&) override;
  96. virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
  97. virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;
  98. virtual void focusin_event(GUI::FocusEvent&) override;
  99. virtual void focusout_event(GUI::FocusEvent&) override;
  100. virtual void show_event(GUI::ShowEvent&) override;
  101. virtual void hide_event(GUI::HideEvent&) override;
  102. // ^AbstractScrollableWidget
  103. virtual void did_scroll() override;
  104. // ^WebView::ViewImplementation
  105. virtual void create_client(EnableCallgrindProfiling = EnableCallgrindProfiling::No) override;
  106. virtual void update_zoom() override;
  107. virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) override;
  108. virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id, Gfx::IntSize) override;
  109. virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) override;
  110. virtual void notify_server_did_change_selection(Badge<WebContentClient>) override;
  111. virtual void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor) override;
  112. virtual void notify_server_did_change_title(Badge<WebContentClient>, DeprecatedString const&) override;
  113. virtual void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32) override;
  114. virtual void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint) override;
  115. virtual void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, Gfx::IntRect const&) override;
  116. virtual void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, Gfx::IntPoint, DeprecatedString const&) override;
  117. virtual void notify_server_did_leave_tooltip_area(Badge<WebContentClient>) override;
  118. virtual void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&) override;
  119. virtual void notify_server_did_unhover_link(Badge<WebContentClient>) override;
  120. virtual void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, DeprecatedString const& target, unsigned modifiers) override;
  121. virtual void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, DeprecatedString const& target, unsigned modifiers) override;
  122. virtual void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&, bool) override;
  123. virtual void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&) override;
  124. virtual void notify_server_did_request_navigate_back(Badge<WebContentClient>) override;
  125. virtual void notify_server_did_request_navigate_forward(Badge<WebContentClient>) override;
  126. virtual void notify_server_did_request_refresh(Badge<WebContentClient>) override;
  127. virtual void notify_server_did_request_context_menu(Badge<WebContentClient>, Gfx::IntPoint) override;
  128. virtual void notify_server_did_request_link_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers) override;
  129. virtual void notify_server_did_request_image_context_menu(Badge<WebContentClient>, Gfx::IntPoint, const AK::URL&, DeprecatedString const& target, unsigned modifiers, Gfx::ShareableBitmap const&) override;
  130. virtual void notify_server_did_request_alert(Badge<WebContentClient>, String const& message) override;
  131. virtual void notify_server_did_request_confirm(Badge<WebContentClient>, String const& message) override;
  132. virtual void notify_server_did_request_prompt(Badge<WebContentClient>, String const& message, String const& default_) override;
  133. virtual void notify_server_did_request_set_prompt_text(Badge<WebContentClient>, String const& message) override;
  134. virtual void notify_server_did_request_accept_dialog(Badge<WebContentClient>) override;
  135. virtual void notify_server_did_request_dismiss_dialog(Badge<WebContentClient>) override;
  136. virtual void notify_server_did_get_source(const AK::URL& url, DeprecatedString const& source) override;
  137. virtual void notify_server_did_get_dom_tree(DeprecatedString const& dom_tree) override;
  138. virtual void notify_server_did_get_dom_node_properties(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing) override;
  139. virtual void notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_tree) override;
  140. virtual void notify_server_did_output_js_console_message(i32 message_index) override;
  141. virtual void notify_server_did_get_js_console_messages(i32 start_index, Vector<DeprecatedString> const& message_types, Vector<DeprecatedString> const& messages) override;
  142. virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) override;
  143. virtual Vector<Web::Cookie::Cookie> notify_server_did_request_all_cookies(Badge<WebContentClient>, AK::URL const& url) override;
  144. virtual Optional<Web::Cookie::Cookie> notify_server_did_request_named_cookie(Badge<WebContentClient>, AK::URL const& url, DeprecatedString const& name) override;
  145. virtual DeprecatedString notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::Source source) override;
  146. virtual void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, Web::Cookie::ParsedCookie const& cookie, Web::Cookie::Source source) override;
  147. virtual void notify_server_did_update_cookie(Badge<WebContentClient>, Web::Cookie::Cookie const& cookie) override;
  148. virtual String notify_server_did_request_new_tab(Badge<WebContentClient>, Web::HTML::ActivateTab activate_tab) override;
  149. virtual void notify_server_did_request_activate_tab(Badge<WebContentClient>) override;
  150. virtual void notify_server_did_close_browsing_context(Badge<WebContentClient>) override;
  151. virtual void notify_server_did_update_resource_count(i32 count_waiting) override;
  152. virtual void notify_server_did_request_restore_window() override;
  153. virtual Gfx::IntPoint notify_server_did_request_reposition_window(Gfx::IntPoint) override;
  154. virtual Gfx::IntSize notify_server_did_request_resize_window(Gfx::IntSize) override;
  155. virtual Gfx::IntRect notify_server_did_request_maximize_window() override;
  156. virtual Gfx::IntRect notify_server_did_request_minimize_window() override;
  157. virtual Gfx::IntRect notify_server_did_request_fullscreen_window() override;
  158. virtual void notify_server_did_request_file(Badge<WebContentClient>, DeprecatedString const& path, i32) override;
  159. virtual void notify_server_did_finish_handling_input_event(bool event_was_accepted) override;
  160. void request_repaint();
  161. void handle_resize();
  162. void handle_web_content_process_crash();
  163. using InputEvent = Variant<GUI::KeyEvent, GUI::MouseEvent>;
  164. void enqueue_input_event(InputEvent const&);
  165. void process_next_input_event();
  166. RefPtr<Gfx::Bitmap> m_backup_bitmap;
  167. RefPtr<GUI::Dialog> m_dialog;
  168. bool m_is_awaiting_response_for_input_event { false };
  169. Queue<InputEvent> m_pending_input_events;
  170. bool m_content_scales_to_viewport { false };
  171. };
  172. }