OutOfProcessWebView.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/WebViewHooks.h>
  11. namespace Web {
  12. class WebContentClient;
  13. class OutOfProcessWebView final
  14. : public GUI::AbstractScrollableWidget
  15. , public Web::WebViewHooks {
  16. C_OBJECT(OutOfProcessWebView);
  17. public:
  18. virtual ~OutOfProcessWebView() override;
  19. URL url() const { return m_url; }
  20. void load(const URL&);
  21. void load_html(const StringView&, const URL&);
  22. void load_empty_document();
  23. void debug_request(const String& request, const String& argument = {});
  24. void get_source();
  25. void inspect_dom_tree();
  26. void js_console_initialize();
  27. void js_console_input(const String& js_source);
  28. String selected_text();
  29. void select_all();
  30. void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
  31. void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
  32. void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&);
  33. void notify_server_did_change_selection(Badge<WebContentClient>);
  34. void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor);
  35. void notify_server_did_change_title(Badge<WebContentClient>, const String&);
  36. void notify_server_did_request_scroll(Badge<WebContentClient>, int);
  37. void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, const Gfx::IntRect&);
  38. void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, const Gfx::IntPoint&, const String&);
  39. void notify_server_did_leave_tooltip_area(Badge<WebContentClient>);
  40. void notify_server_did_hover_link(Badge<WebContentClient>, const URL&);
  41. void notify_server_did_unhover_link(Badge<WebContentClient>);
  42. void notify_server_did_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers);
  43. void notify_server_did_middle_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers);
  44. void notify_server_did_start_loading(Badge<WebContentClient>, const URL&);
  45. void notify_server_did_finish_loading(Badge<WebContentClient>, const URL&);
  46. void notify_server_did_request_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&);
  47. void notify_server_did_request_link_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers);
  48. void notify_server_did_request_image_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::ShareableBitmap&);
  49. void notify_server_did_request_alert(Badge<WebContentClient>, const String& message);
  50. bool notify_server_did_request_confirm(Badge<WebContentClient>, const String& message);
  51. String notify_server_did_request_prompt(Badge<WebContentClient>, const String& message, const String& default_);
  52. void notify_server_did_get_source(const URL& url, const String& source);
  53. void notify_server_did_get_dom_tree(const String& dom_tree);
  54. void notify_server_did_js_console_output(const String& method, const String& line);
  55. void notify_server_did_change_favicon(const Gfx::Bitmap& favicon);
  56. String notify_server_did_request_cookie(Badge<WebContentClient>, const URL& url, Cookie::Source source);
  57. void notify_server_did_set_cookie(Badge<WebContentClient>, const URL& url, const Cookie::ParsedCookie& cookie, Cookie::Source source);
  58. private:
  59. OutOfProcessWebView();
  60. // ^Widget
  61. virtual void paint_event(GUI::PaintEvent&) override;
  62. virtual void resize_event(GUI::ResizeEvent&) override;
  63. virtual void mousedown_event(GUI::MouseEvent&) override;
  64. virtual void mouseup_event(GUI::MouseEvent&) override;
  65. virtual void mousemove_event(GUI::MouseEvent&) override;
  66. virtual void mousewheel_event(GUI::MouseEvent&) override;
  67. virtual void keydown_event(GUI::KeyEvent&) override;
  68. virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
  69. virtual void screen_rects_change_event(GUI::ScreenRectsChangeEvent&) override;
  70. // ^AbstractScrollableWidget
  71. virtual void did_scroll() override;
  72. void request_repaint();
  73. void handle_resize();
  74. void create_client();
  75. WebContentClient& client();
  76. void handle_web_content_process_crash();
  77. URL m_url;
  78. struct ClientState {
  79. RefPtr<WebContentClient> client;
  80. RefPtr<Gfx::Bitmap> front_bitmap;
  81. RefPtr<Gfx::Bitmap> back_bitmap;
  82. i32 front_bitmap_id { -1 };
  83. i32 back_bitmap_id { -1 };
  84. i32 next_bitmap_id { 0 };
  85. bool has_usable_bitmap { false };
  86. } m_client_state;
  87. RefPtr<Gfx::Bitmap> m_backup_bitmap;
  88. };
  89. }