OutOfProcessWebView.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #pragma once
  27. #include <AK/URL.h>
  28. #include <LibGUI/ScrollableWidget.h>
  29. #include <LibGUI/Widget.h>
  30. #include <LibWeb/WebViewHooks.h>
  31. namespace Web {
  32. class WebContentClient;
  33. class OutOfProcessWebView final
  34. : public GUI::ScrollableWidget
  35. , public Web::WebViewHooks {
  36. C_OBJECT(OutOfProcessWebView);
  37. public:
  38. virtual ~OutOfProcessWebView() override;
  39. URL url() const { return m_url; }
  40. void load(const URL&);
  41. void load_html(const StringView&, const URL&);
  42. void load_empty_document();
  43. void debug_request(const String& request, const String& argument = {});
  44. void get_source();
  45. void js_console_initialize();
  46. void js_console_input(const String& js_source);
  47. void notify_server_did_layout(Badge<WebContentClient>, const Gfx::IntSize& content_size);
  48. void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id);
  49. void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, const Gfx::IntRect&);
  50. void notify_server_did_change_selection(Badge<WebContentClient>);
  51. void notify_server_did_request_cursor_change(Badge<WebContentClient>, Gfx::StandardCursor cursor);
  52. void notify_server_did_change_title(Badge<WebContentClient>, const String&);
  53. void notify_server_did_request_scroll(Badge<WebContentClient>, int);
  54. void notify_server_did_request_scroll_into_view(Badge<WebContentClient>, const Gfx::IntRect&);
  55. void notify_server_did_enter_tooltip_area(Badge<WebContentClient>, const Gfx::IntPoint&, const String&);
  56. void notify_server_did_leave_tooltip_area(Badge<WebContentClient>);
  57. void notify_server_did_hover_link(Badge<WebContentClient>, const URL&);
  58. void notify_server_did_unhover_link(Badge<WebContentClient>);
  59. void notify_server_did_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers);
  60. void notify_server_did_middle_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers);
  61. void notify_server_did_start_loading(Badge<WebContentClient>, const URL&);
  62. void notify_server_did_finish_loading(Badge<WebContentClient>, const URL&);
  63. void notify_server_did_request_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&);
  64. void notify_server_did_request_link_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers);
  65. void notify_server_did_request_image_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers, const Gfx::ShareableBitmap&);
  66. void notify_server_did_request_alert(Badge<WebContentClient>, const String& message);
  67. bool notify_server_did_request_confirm(Badge<WebContentClient>, const String& message);
  68. String notify_server_did_request_prompt(Badge<WebContentClient>, const String& message, const String& default_);
  69. void notify_server_did_get_source(const URL& url, const String& source);
  70. void notify_server_did_js_console_output(const String& method, const String& line);
  71. void notify_server_did_change_favicon(const Gfx::Bitmap& favicon);
  72. String notify_server_did_request_cookie(Badge<WebContentClient>, const URL& url);
  73. void notify_server_did_set_cookie(Badge<WebContentClient>, const URL& url, const String& cookie);
  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 theme_change_event(GUI::ThemeChangeEvent&) override;
  85. virtual void screen_rect_change_event(GUI::ScreenRectChangeEvent&) override;
  86. // ^ScrollableWidget
  87. virtual void did_scroll() override;
  88. void request_repaint();
  89. void handle_resize();
  90. void create_client();
  91. WebContentClient& client();
  92. void handle_web_content_process_crash();
  93. URL m_url;
  94. struct ClientState {
  95. RefPtr<WebContentClient> client;
  96. RefPtr<Gfx::Bitmap> front_bitmap;
  97. RefPtr<Gfx::Bitmap> back_bitmap;
  98. i32 front_bitmap_id { -1 };
  99. i32 back_bitmap_id { -1 };
  100. i32 next_bitmap_id { 0 };
  101. bool has_usable_bitmap { false };
  102. } m_client_state;
  103. RefPtr<Gfx::Bitmap> m_backup_bitmap;
  104. };
  105. }