OutOfProcessWebView.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. * Copyright (c) 2020, 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/Page/Page.h>
  11. #include <LibWeb/WebViewHooks.h>
  12. namespace Web {
  13. class WebContentClient;
  14. class OutOfProcessWebView final
  15. : public GUI::AbstractScrollableWidget
  16. , public Web::WebViewHooks {
  17. C_OBJECT(OutOfProcessWebView);
  18. public:
  19. virtual ~OutOfProcessWebView() override;
  20. AK::URL url() const { return m_url; }
  21. void load(const AK::URL&);
  22. void load_html(StringView, const AK::URL&);
  23. void load_empty_document();
  24. void debug_request(const String& request, const String& argument = {});
  25. void get_source();
  26. void inspect_dom_tree();
  27. struct DOMNodeProperties {
  28. String specified_values_json;
  29. String computed_values_json;
  30. String custom_properties_json;
  31. };
  32. Optional<DOMNodeProperties> inspect_dom_node(i32 node_id);
  33. void clear_inspected_dom_node();
  34. i32 get_hovered_node_id();
  35. void js_console_input(const String& js_source);
  36. void js_console_request_messages(i32 start_index);
  37. void run_javascript(StringView);
  38. String selected_text();
  39. void select_all();
  40. String dump_layout_tree();
  41. void set_content_filters(Vector<String>);
  42. void set_preferred_color_scheme(Web::CSS::PreferredColorScheme);
  43. void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
  44. void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
  45. void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&);
  46. void notify_server_did_change_selection(Badge<WebContentClient>);
  47. void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor);
  48. void notify_server_did_change_title(Badge<WebContentClient>, const String&);
  49. void notify_server_did_request_scroll(Badge<WebContentClient>, i32, i32);
  50. void notify_server_did_request_scroll_to(Badge<WebContentClient>, Gfx::IntPoint const&);
  51. void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, const Gfx::IntRect&);
  52. void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, const Gfx::IntPoint&, const String&);
  53. void notify_server_did_leave_tooltip_area(Badge<WebContentClient>);
  54. void notify_server_did_hover_link(Badge<WebContentClient>, const AK::URL&);
  55. void notify_server_did_unhover_link(Badge<WebContentClient>);
  56. void notify_server_did_click_link(Badge<WebContentClient>, const AK::URL&, const String& target, unsigned modifiers);
  57. void notify_server_did_middle_click_link(Badge<WebContentClient>, const AK::URL&, const String& target, unsigned modifiers);
  58. void notify_server_did_start_loading(Badge<WebContentClient>, const AK::URL&);
  59. void notify_server_did_finish_loading(Badge<WebContentClient>, const AK::URL&);
  60. void notify_server_did_request_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&);
  61. void notify_server_did_request_link_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const AK::URL&, const String& target, unsigned modifiers);
  62. void notify_server_did_request_image_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const AK::URL&, const String& target, unsigned modifiers, const Gfx::ShareableBitmap&);
  63. void notify_server_did_request_alert(Badge<WebContentClient>, const String& message);
  64. bool notify_server_did_request_confirm(Badge<WebContentClient>, const String& message);
  65. String notify_server_did_request_prompt(Badge<WebContentClient>, const String& message, const String& default_);
  66. void notify_server_did_get_source(const AK::URL& url, const String& source);
  67. void notify_server_did_get_dom_tree(const String& dom_tree);
  68. void notify_server_did_get_dom_node_properties(i32 node_id, String const& specified_style, String const& computed_style, String const& custom_properties);
  69. void notify_server_did_output_js_console_message(i32 message_index);
  70. void notify_server_did_get_js_console_messages(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages);
  71. void notify_server_did_change_favicon(const Gfx::Bitmap& favicon);
  72. String notify_server_did_request_cookie(Badge<WebContentClient>, const AK::URL& url, Cookie::Source source);
  73. void notify_server_did_set_cookie(Badge<WebContentClient>, const AK::URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source);
  74. private:
  75. OutOfProcessWebView();
  76. // ^Widget
  77. virtual void paint_event(GUI::PaintEvent&) override;
  78. virtual void resize_event(GUI::ResizeEvent&) override;
  79. virtual void mousedown_event(GUI::MouseEvent&) override;
  80. virtual void mouseup_event(GUI::MouseEvent&) override;
  81. virtual void mousemove_event(GUI::MouseEvent&) override;
  82. virtual void mousewheel_event(GUI::MouseEvent&) override;
  83. virtual void keydown_event(GUI::KeyEvent&) override;
  84. virtual void keyup_event(GUI::KeyEvent&) override;
  85. virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
  86. virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;
  87. virtual void focusin_event(GUI::FocusEvent&) override;
  88. virtual void focusout_event(GUI::FocusEvent&) override;
  89. // ^AbstractScrollableWidget
  90. virtual void did_scroll() override;
  91. void request_repaint();
  92. void handle_resize();
  93. void create_client();
  94. WebContentClient& client();
  95. void handle_web_content_process_crash();
  96. AK::URL m_url;
  97. struct SharedBitmap {
  98. i32 id { -1 };
  99. i32 pending_paints { 0 };
  100. RefPtr<Gfx::Bitmap> bitmap;
  101. };
  102. struct ClientState {
  103. RefPtr<WebContentClient> client;
  104. SharedBitmap front_bitmap;
  105. SharedBitmap back_bitmap;
  106. i32 next_bitmap_id { 0 };
  107. bool has_usable_bitmap { false };
  108. bool got_repaint_requests_while_painting { false };
  109. } m_client_state;
  110. RefPtr<Gfx::Bitmap> m_backup_bitmap;
  111. };
  112. }