Handle no data cases for ScreenAI OCR results.
When OCR module cannot process an image or cannot extract data from the
image, an AXTreeIDUnknown is sent back to the caller.
This patch updates PdfAccessibilityTree to handle this result and avoid
updating based on it.
AX-Relnotes: n/a
Bug: 1278249
Change-Id: Ic98535af36773509e510808321c404bfdab80579
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4165833
Reviewed-by: David Tseng <dtseng@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1093753}
diff --git a/components/pdf/renderer/pdf_accessibility_tree.cc b/components/pdf/renderer/pdf_accessibility_tree.cc
index ed8032f..7385fb2f 100644
--- a/components/pdf/renderer/pdf_accessibility_tree.cc
+++ b/components/pdf/renderer/pdf_accessibility_tree.cc
@@ -1778,7 +1778,13 @@
// more convenient and less complex if an `ui::AXTree` was never constructed
// and if the `ui::AXTreeSource` was able to use the collection of `nodes_`
// directly.
+ if (child_tree_id == ui::AXTreeIDUnknown()) {
+ VLOG(1) << "Empty OCR data received.";
+ return;
+ }
+
VLOG(1) << "OCR data received: " << child_tree_id.ToString();
+
DCHECK_NE(image_node_id, ui::kInvalidAXNodeID);
DCHECK_NE(parent_node_id, ui::kInvalidAXNodeID);
DCHECK(!image_bounds.IsEmpty());
diff --git a/components/services/screen_ai/screen_ai_service_impl.cc b/components/services/screen_ai/screen_ai_service_impl.cc
index 8150bb8..7ae00e8 100644
--- a/components/services/screen_ai/screen_ai_service_impl.cc
+++ b/components/services/screen_ai/screen_ai_service_impl.cc
@@ -371,9 +371,9 @@
result = CallLibraryLayoutExtractionFunction(image, annotation_proto,
annotation_proto_length);
}
- if (!result) {
+ if (!result || !annotation_proto_length) {
DCHECK_EQ(annotation->tree_data.tree_id, ui::AXTreeIDUnknown());
- VLOG(1) << "Screen AI library could not process snapshot.";
+ VLOG(1) << "Screen AI library could not process snapshot or no OCR data.";
return;
}