OutOfProcessWebView.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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_hover_link(Badge<WebContentClient>, const URL&);
  56. void notify_server_did_unhover_link(Badge<WebContentClient>);
  57. void notify_server_did_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers);
  58. void notify_server_did_middle_click_link(Badge<WebContentClient>, const URL&, const String& target, unsigned modifiers);
  59. void notify_server_did_start_loading(Badge<WebContentClient>, const URL&);
  60. void notify_server_did_finish_loading(Badge<WebContentClient>, const URL&);
  61. void notify_server_did_request_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&);
  62. void notify_server_did_request_link_context_menu(Badge<WebContentClient>, const Gfx::IntPoint&, const URL&, const String& target, unsigned modifiers);
  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 URL& url, const String& source);
  67. void notify_server_did_js_console_output(const String& method, const String& line);
  68. private:
  69. OutOfProcessWebView();
  70. // ^Widget
  71. virtual void paint_event(GUI::PaintEvent&) override;
  72. virtual void resize_event(GUI::ResizeEvent&) override;
  73. virtual void mousedown_event(GUI::MouseEvent&) override;
  74. virtual void mouseup_event(GUI::MouseEvent&) override;
  75. virtual void mousemove_event(GUI::MouseEvent&) override;
  76. virtual void mousewheel_event(GUI::MouseEvent&) override;
  77. virtual void keydown_event(GUI::KeyEvent&) override;
  78. virtual void theme_change_event(GUI::ThemeChangeEvent&) override;
  79. // ^ScrollableWidget
  80. virtual void did_scroll() override;
  81. void request_repaint();
  82. void handle_resize();
  83. void create_client();
  84. WebContentClient& client();
  85. void handle_web_content_process_crash();
  86. URL m_url;
  87. struct ClientState {
  88. RefPtr<WebContentClient> client;
  89. RefPtr<Gfx::Bitmap> front_bitmap;
  90. RefPtr<Gfx::Bitmap> back_bitmap;
  91. i32 front_bitmap_id { -1 };
  92. i32 back_bitmap_id { -1 };
  93. i32 next_bitmap_id { 0 };
  94. bool has_usable_bitmap { false };
  95. } m_client_state;
  96. RefPtr<Gfx::Bitmap> m_backup_bitmap;
  97. };
  98. }