ConnectionFromClient.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
  4. * Copyright (c) 2022, Tim Flynn <trflynn89@serenityos.org>
  5. *
  6. * SPDX-License-Identifier: BSD-2-Clause
  7. */
  8. #pragma once
  9. #include <AK/HashMap.h>
  10. #include <LibIPC/ConnectionFromClient.h>
  11. #include <LibJS/Forward.h>
  12. #include <LibJS/Heap/Handle.h>
  13. #include <LibWeb/CSS/PreferredColorScheme.h>
  14. #include <LibWeb/Forward.h>
  15. #include <LibWeb/Loader/FileRequest.h>
  16. #include <LibWeb/Platform/Timer.h>
  17. #include <WebContent/Forward.h>
  18. #include <WebContent/WebContentClientEndpoint.h>
  19. #include <WebContent/WebContentConsoleClient.h>
  20. #include <WebContent/WebContentServerEndpoint.h>
  21. namespace WebContent {
  22. class ConnectionFromClient final
  23. : public IPC::ConnectionFromClient<WebContentClientEndpoint, WebContentServerEndpoint> {
  24. C_OBJECT(ConnectionFromClient);
  25. public:
  26. ~ConnectionFromClient() override = default;
  27. virtual void die() override;
  28. void initialize_js_console(Badge<PageHost>);
  29. void request_file(NonnullRefPtr<Web::FileRequest>&);
  30. Optional<int> fd() { return socket().fd(); }
  31. PageHost& page_host() { return *m_page_host; }
  32. PageHost const& page_host() const { return *m_page_host; }
  33. private:
  34. explicit ConnectionFromClient(NonnullOwnPtr<Core::Stream::LocalSocket>);
  35. Web::Page& page();
  36. Web::Page const& page() const;
  37. virtual void connect_to_webdriver(DeprecatedString const& webdriver_ipc_path) override;
  38. virtual void update_system_theme(Core::AnonymousBuffer const&) override;
  39. virtual void update_system_fonts(DeprecatedString const&, DeprecatedString const&, DeprecatedString const&) override;
  40. virtual void update_screen_rects(Vector<Gfx::IntRect> const&, u32) override;
  41. virtual void load_url(URL const&) override;
  42. virtual void load_html(DeprecatedString const&, URL const&) override;
  43. virtual void paint(Gfx::IntRect const&, i32) override;
  44. virtual void set_viewport_rect(Gfx::IntRect const&) override;
  45. virtual void mouse_down(Gfx::IntPoint, unsigned, unsigned, unsigned) override;
  46. virtual void mouse_move(Gfx::IntPoint, unsigned, unsigned, unsigned) override;
  47. virtual void mouse_up(Gfx::IntPoint, unsigned, unsigned, unsigned) override;
  48. virtual void mouse_wheel(Gfx::IntPoint, unsigned, unsigned, unsigned, i32, i32) override;
  49. virtual void doubleclick(Gfx::IntPoint, unsigned, unsigned, unsigned) override;
  50. virtual void key_down(i32, unsigned, u32) override;
  51. virtual void key_up(i32, unsigned, u32) override;
  52. virtual void add_backing_store(i32, Gfx::ShareableBitmap const&) override;
  53. virtual void remove_backing_store(i32) override;
  54. virtual void debug_request(DeprecatedString const&, DeprecatedString const&) override;
  55. virtual void get_source() override;
  56. virtual void inspect_dom_tree() override;
  57. virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> const& pseudo_element) override;
  58. virtual void inspect_accessibility_tree() override;
  59. virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override;
  60. virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override;
  61. virtual void set_content_filters(Vector<DeprecatedString> const&) override;
  62. virtual void set_proxy_mappings(Vector<DeprecatedString> const&, HashMap<DeprecatedString, size_t> const&) override;
  63. virtual void set_preferred_color_scheme(Web::CSS::PreferredColorScheme const&) override;
  64. virtual void set_has_focus(bool) override;
  65. virtual void set_is_scripting_enabled(bool) override;
  66. virtual void set_window_position(Gfx::IntPoint) override;
  67. virtual void set_window_size(Gfx::IntSize) override;
  68. virtual void handle_file_return(i32 error, Optional<IPC::File> const& file, i32 request_id) override;
  69. virtual void set_system_visibility_state(bool visible) override;
  70. virtual void js_console_input(DeprecatedString const&) override;
  71. virtual void run_javascript(DeprecatedString const&) override;
  72. virtual void js_console_request_messages(i32) override;
  73. virtual void alert_closed() override;
  74. virtual void confirm_closed(bool accepted) override;
  75. virtual void prompt_closed(DeprecatedString const& response) override;
  76. virtual Messages::WebContentServer::TakeDocumentScreenshotResponse take_document_screenshot() override;
  77. virtual Messages::WebContentServer::GetLocalStorageEntriesResponse get_local_storage_entries() override;
  78. virtual Messages::WebContentServer::GetSessionStorageEntriesResponse get_session_storage_entries() override;
  79. virtual Messages::WebContentServer::GetSelectedTextResponse get_selected_text() override;
  80. virtual void select_all() override;
  81. void flush_pending_paint_requests();
  82. void report_finished_handling_input_event(bool event_was_handled);
  83. NonnullOwnPtr<PageHost> m_page_host;
  84. struct PaintRequest {
  85. Gfx::IntRect content_rect;
  86. NonnullRefPtr<Gfx::Bitmap> bitmap;
  87. i32 bitmap_id { -1 };
  88. };
  89. Vector<PaintRequest> m_pending_paint_requests;
  90. RefPtr<Web::Platform::Timer> m_paint_flush_timer;
  91. HashMap<i32, NonnullRefPtr<Gfx::Bitmap>> m_backing_stores;
  92. WeakPtr<JS::Realm> m_realm;
  93. OwnPtr<WebContentConsoleClient> m_console_client;
  94. JS::Handle<JS::GlobalObject> m_console_global_object;
  95. HashMap<int, NonnullRefPtr<Web::FileRequest>> m_requested_files {};
  96. int last_id { 0 };
  97. };
  98. }