[go: nahoru, domu]

[Read Anything] Pass AXTreeID to screen2x callback.

We should never pass a reference to a callback without any lifetime
tracking. Passing an AXTreeID removes this risk.

This also removes the call to distill by algorithm after a failed
screen2x attempt. We had discussed removing this before so this is an
opportune time.

Fixed: 1434669
Bug: 1266555
Change-Id: If03255c1ab0c4636e2b0580389850b1e5da21c53
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4494011
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Reviewed-by: Kristi Saney <kristislee@google.com>
Cr-Commit-Position: refs/heads/main@{#1138051}
diff --git a/chrome/renderer/accessibility/ax_tree_distiller.cc b/chrome/renderer/accessibility/ax_tree_distiller.cc
index 1c5035d..a61dda6 100644
--- a/chrome/renderer/accessibility/ax_tree_distiller.cc
+++ b/chrome/renderer/accessibility/ax_tree_distiller.cc
@@ -129,24 +129,19 @@
   DCHECK(main_content_extractor_.is_bound());
   main_content_extractor_->ExtractMainContent(
       snapshot, ukm_source_id,
-      base::BindOnce(
-          &AXTreeDistiller::ProcessScreen2xResult,
-          weak_ptr_factory_.GetWeakPtr(),
-          base::UnsafeDanglingUntriaged(raw_ref<const ui::AXTree>(tree))));
+      base::BindOnce(&AXTreeDistiller::ProcessScreen2xResult,
+                     weak_ptr_factory_.GetWeakPtr(), tree.GetAXTreeID()));
 }
 
 void AXTreeDistiller::ProcessScreen2xResult(
-    const ui::AXTree& tree,
+    const ui::AXTreeID& tree_id,
     const std::vector<ui::AXNodeID>& content_node_ids) {
   // If content nodes were identified, run callback.
   if (!content_node_ids.empty()) {
-    on_ax_tree_distilled_callback_.Run(tree.GetAXTreeID(), content_node_ids);
+    on_ax_tree_distilled_callback_.Run(tree_id, content_node_ids);
     return;
   }
 
-  // Otherwise, try the rules-based approach.
-  DistillViaAlgorithm(tree);
-
   // TODO(crbug.com/1266555): If still no content nodes were identified, and
   // there is a selection, try sending Screen2x a partial tree just containing
   // the selected nodes.