From 367b1634fd4a0c3764d1f618b8045a5d15096a07 Mon Sep 17 00:00:00 2001 From: Jonah Date: Wed, 7 Dec 2022 19:30:37 -0600 Subject: [PATCH] LibWebView+WebContent: Expose the Accessibility Tree to Other Processes This patch also stubs out notify_server_did_get_accessiblity_tree in ladybird since ViewImplementation now has it. However, this feature is still immature, so just stubbing out in ladybird for now. Once we have more robust support in Serenity (namely ARIA properties/state and accessible names and descriptions) we can port this functionality over. --- Ladybird/WebContentView.cpp | 5 +++++ Ladybird/WebContentView.h | 1 + Userland/Libraries/LibWebView/OutOfProcessWebView.cpp | 11 +++++++++++ Userland/Libraries/LibWebView/OutOfProcessWebView.h | 3 +++ Userland/Libraries/LibWebView/ViewImplementation.h | 1 + Userland/Libraries/LibWebView/WebContentClient.cpp | 5 +++++ Userland/Libraries/LibWebView/WebContentClient.h | 1 + Userland/Services/WebContent/ConnectionFromClient.cpp | 7 +++++++ Userland/Services/WebContent/ConnectionFromClient.h | 1 + Userland/Services/WebContent/WebContentClient.ipc | 1 + Userland/Services/WebContent/WebContentServer.ipc | 1 + 11 files changed, 37 insertions(+) diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp index 5dd9e2c7afd..2e00479bc00 100644 --- a/Ladybird/WebContentView.cpp +++ b/Ladybird/WebContentView.cpp @@ -1093,3 +1093,8 @@ void WebContentView::notify_server_did_finish_handling_input_event(bool event_wa // we don't need to do anything here. But we'll need to once we start asking web content first. (void)event_was_accepted; } + +void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString const&) +{ + dbgln("TODO: support accessibility tree in Ladybird"); +} diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h index 83abdfb4d7b..a4f1cc5c126 100644 --- a/Ladybird/WebContentView.h +++ b/Ladybird/WebContentView.h @@ -144,6 +144,7 @@ public: virtual void notify_server_did_get_source(const AK::URL& url, DeprecatedString const& source) override; virtual void notify_server_did_get_dom_tree(DeprecatedString const& dom_tree) override; virtual void notify_server_did_get_dom_node_properties(i32 node_id, DeprecatedString const& specified_style, DeprecatedString const& computed_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing) override; + virtual void notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_tree) override; virtual void notify_server_did_output_js_console_message(i32 message_index) override; virtual void notify_server_did_get_js_console_messages(i32 start_index, Vector const& message_types, Vector const& messages) override; virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) override; diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp index 3fce45a13db..cf3958df0af 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp @@ -830,4 +830,15 @@ void OutOfProcessWebView::notify_server_did_finish_handling_input_event(bool eve process_next_input_event(); } +void OutOfProcessWebView::inspect_accessibility_tree() +{ + client().async_inspect_accessibility_tree(); +} + +void OutOfProcessWebView::notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_tree) +{ + if (on_get_accessibility_tree) + on_get_accessibility_tree(accessibility_tree); +} + } diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h index 9fb0808ddc2..f7f761e29de 100644 --- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h +++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h @@ -50,6 +50,7 @@ public: DeprecatedString node_box_sizing_json; }; Optional inspect_dom_node(i32 node_id, Optional); + void inspect_accessibility_tree(); void clear_inspected_dom_node(); i32 get_hovered_node_id(); @@ -97,6 +98,7 @@ public: Function on_get_source; Function on_get_dom_tree; Function on_get_dom_node_properties; + Function on_get_accessibility_tree; Function on_js_console_new_message; Function const& message_types, Vector const& messages)> on_get_js_console_messages; Function(AK::URL const& url)> on_get_all_cookies; @@ -170,6 +172,7 @@ private: virtual void notify_server_did_get_source(const AK::URL& url, DeprecatedString const& source) override; virtual void notify_server_did_get_dom_tree(DeprecatedString const& dom_tree) override; virtual void notify_server_did_get_dom_node_properties(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing) override; + virtual void notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_tree) override; virtual void notify_server_did_output_js_console_message(i32 message_index) override; virtual void notify_server_did_get_js_console_messages(i32 start_index, Vector const& message_types, Vector const& messages) override; virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) override; diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h index b7187e21901..7689b933802 100644 --- a/Userland/Libraries/LibWebView/ViewImplementation.h +++ b/Userland/Libraries/LibWebView/ViewImplementation.h @@ -50,6 +50,7 @@ public: virtual void notify_server_did_get_source(const AK::URL& url, DeprecatedString const& source) = 0; virtual void notify_server_did_get_dom_tree(DeprecatedString const& dom_tree) = 0; virtual void notify_server_did_get_dom_node_properties(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing) = 0; + virtual void notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_tree) = 0; virtual void notify_server_did_output_js_console_message(i32 message_index) = 0; virtual void notify_server_did_get_js_console_messages(i32 start_index, Vector const& message_types, Vector const& messages) = 0; virtual void notify_server_did_change_favicon(Gfx::Bitmap const& favicon) = 0; diff --git a/Userland/Libraries/LibWebView/WebContentClient.cpp b/Userland/Libraries/LibWebView/WebContentClient.cpp index 6aa29a743ef..7f9b891d7ff 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.cpp +++ b/Userland/Libraries/LibWebView/WebContentClient.cpp @@ -285,4 +285,9 @@ void WebContentClient::did_finish_handling_input_event(bool event_was_accepted) m_view.notify_server_did_finish_handling_input_event(event_was_accepted); } +void WebContentClient::did_get_accessibility_tree(DeprecatedString const& accessibility_tree) +{ + m_view.notify_server_did_get_accessibility_tree(accessibility_tree); +} + } diff --git a/Userland/Libraries/LibWebView/WebContentClient.h b/Userland/Libraries/LibWebView/WebContentClient.h index 08bf3f59001..c5e1e95d521 100644 --- a/Userland/Libraries/LibWebView/WebContentClient.h +++ b/Userland/Libraries/LibWebView/WebContentClient.h @@ -54,6 +54,7 @@ private: virtual void did_get_source(AK::URL const&, DeprecatedString const&) override; virtual void did_get_dom_tree(DeprecatedString const&) override; virtual void did_get_dom_node_properties(i32 node_id, DeprecatedString const& computed_style, DeprecatedString const& resolved_style, DeprecatedString const& custom_properties, DeprecatedString const& node_box_sizing) override; + virtual void did_get_accessibility_tree(DeprecatedString const&) override; virtual void did_output_js_console_message(i32 message_index) override; virtual void did_get_js_console_messages(i32 start_index, Vector const& message_types, Vector const& messages) override; virtual void did_change_favicon(Gfx::ShareableBitmap const&) override; diff --git a/Userland/Services/WebContent/ConnectionFromClient.cpp b/Userland/Services/WebContent/ConnectionFromClient.cpp index e4f9da7229c..ddd2b605530 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.cpp +++ b/Userland/Services/WebContent/ConnectionFromClient.cpp @@ -595,4 +595,11 @@ void ConnectionFromClient::prompt_closed(DeprecatedString const& response) m_page_host->prompt_closed(response); } +void ConnectionFromClient::inspect_accessibility_tree() +{ + if (auto* doc = page().top_level_browsing_context().active_document()) { + async_did_get_accessibility_tree(doc->dump_accessibility_tree_as_json()); + } +} + } diff --git a/Userland/Services/WebContent/ConnectionFromClient.h b/Userland/Services/WebContent/ConnectionFromClient.h index fa354309bd4..45d1963b0e0 100644 --- a/Userland/Services/WebContent/ConnectionFromClient.h +++ b/Userland/Services/WebContent/ConnectionFromClient.h @@ -68,6 +68,7 @@ private: virtual void get_source() override; virtual void inspect_dom_tree() override; virtual Messages::WebContentServer::InspectDomNodeResponse inspect_dom_node(i32 node_id, Optional const& pseudo_element) override; + virtual void inspect_accessibility_tree() override; virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override; virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override; virtual void set_content_filters(Vector const&) override; diff --git a/Userland/Services/WebContent/WebContentClient.ipc b/Userland/Services/WebContent/WebContentClient.ipc index 6d579639046..98811b36457 100644 --- a/Userland/Services/WebContent/WebContentClient.ipc +++ b/Userland/Services/WebContent/WebContentClient.ipc @@ -38,6 +38,7 @@ endpoint WebContentClient did_get_source(URL url, DeprecatedString source) =| did_get_dom_tree(DeprecatedString dom_tree) =| did_get_dom_node_properties(i32 node_id, DeprecatedString computed_style, DeprecatedString resolved_style, DeprecatedString custom_properties, DeprecatedString node_box_sizing_json) =| + did_get_accessibility_tree(DeprecatedString accessibility_tree) =| did_change_favicon(Gfx::ShareableBitmap favicon) =| did_request_all_cookies(URL url) => (Vector cookies) did_request_named_cookie(URL url, DeprecatedString name) => (Optional cookie) diff --git a/Userland/Services/WebContent/WebContentServer.ipc b/Userland/Services/WebContent/WebContentServer.ipc index 55f5a43a1c0..5362651a3c4 100644 --- a/Userland/Services/WebContent/WebContentServer.ipc +++ b/Userland/Services/WebContent/WebContentServer.ipc @@ -37,6 +37,7 @@ endpoint WebContentServer get_source() =| inspect_dom_tree() =| inspect_dom_node(i32 node_id, Optional pseudo_element) => (bool has_style, DeprecatedString computed_style, DeprecatedString resolved_style, DeprecatedString custom_properties, DeprecatedString node_box_sizing) + inspect_accessibility_tree() =| get_hovered_node_id() => (i32 node_id) js_console_input(DeprecatedString js_source) =| js_console_request_messages(i32 start_index) =|