[AXTreeFixing] Add AXTreeFixing service for ScreenAI and create in Router
This CL adds a new internal service router for the AXTree fixing
feature. This router connects directly to the ScreenAI service and will
be used as a single pipe from the BrowserContextKeyedService tree fixing
Router to the ScreenAI service. This is made internal to the tree_fixing
target, and only the AXTreeFixingServicesRouter can depend on it. In the
future there will be many such internal routers. The top-level Router
provides a public API for any client to perform an AXTree fixing
operation, such as IdentifyMainNode, which is added in this CL.
AX-Relnotes: N/A
Bug: 395134535, 401034541, 399384018
Change-Id: Ic8aa07f2884b6ab3bc61a13e1466bdf6ee0765c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6325211
Reviewed-by: Nektarios Paisios <[email protected]>
Reviewed-by: Mustafa Emre Acer <[email protected]>
Commit-Queue: Mark Schillaci <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1429730}
diff --git a/services/screen_ai/screen_ai_service_impl.cc b/services/screen_ai/screen_ai_service_impl.cc
index 3d83053..5441438 100644
--- a/services/screen_ai/screen_ai_service_impl.cc
+++ b/services/screen_ai/screen_ai_service_impl.cc
@@ -455,6 +455,20 @@
}
}
+void ScreenAIService::IdentifyMainNode(const ui::AXTreeUpdate& snapshot,
+ IdentifyMainNodeCallback callback) {
+ ui::AXTree tree;
+ std::optional<std::vector<int32_t>> content_node_ids;
+ bool success = ExtractMainContentInternal(snapshot, tree, content_node_ids);
+
+ if (success) {
+ ui::AXNodeID main_node_id = ComputeMainNode(&tree, *content_node_ids);
+ std::move(callback).Run(tree.GetAXTreeID(), main_node_id);
+ } else {
+ std::move(callback).Run(ui::AXTreeIDUnknown(), ui::kInvalidAXNodeID);
+ }
+}
+
bool ScreenAIService::ExtractMainContentInternal(
const ui::AXTreeUpdate& snapshot,
ui::AXTree& tree,