From 347c0558b17be6935fe35991c8fa807a92020ec1 Mon Sep 17 00:00:00 2001 From: Aaron Leventhal Date: Sun, 11 Jun 2023 14:56:23 +0000 Subject: [PATCH] [A11y] Speculative fix for placeholder elements trying to add children The crash reports are all logging placeholder elements as trying to add children but having a return value of false for CanHaveChildren(). A possible explanation is that CanHaveChildren() returned true earlier because the placeholder element.ShadowPseudoId() value was not set for the initial call. This hopefully fixes the issue by using a more robust API to check for the placeholder element. Even if it does not fix the crash, it seems cleaner and less brittle. (cherry picked from commit 926950c3d726a343a40cb916ad615db90012e66b) Bug: 1407397 Change-Id: I59a10338525076e756e5a60cd475bdb26e75af9c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4590613 Reviewed-by: Chris Harrelson Commit-Queue: Chris Harrelson Reviewed-by: Mason Freed Auto-Submit: Aaron Leventhal Cr-Original-Commit-Position: refs/heads/main@{#1154087} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4604457 Commit-Queue: Rubber Stamper Bot-Commit: Rubber Stamper Cr-Commit-Position: refs/branch-heads/5790@{#600} Cr-Branched-From: 1d71a337b1f6e707a13ae074dca1e2c34905eb9f-refs/heads/main@{#1148114} --- .../blink/renderer/modules/accessibility/ax_object.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/third_party/blink/renderer/modules/accessibility/ax_object.cc b/third_party/blink/renderer/modules/accessibility/ax_object.cc index d5d6120c6a328..873391bfc3b4b 100644 --- a/third_party/blink/renderer/modules/accessibility/ax_object.cc +++ b/third_party/blink/renderer/modules/accessibility/ax_object.cc @@ -1004,9 +1004,13 @@ bool AXObject::CanHaveChildren(Element& element) { // so there's no need to add its text children. Placeholder text is a separate // node that gets removed when it disappears, so this will only be present if // the placeholder is visible. - if (element.ShadowPseudoId() == - shadow_element_names::kPseudoInputPlaceholder) { - return false; + if (Element* host = element.OwnerShadowHost()) { + if (auto* ancestor_input = DynamicTo(host)) { + if (ancestor_input->PlaceholderElement() == &element) { + // |element| is a placeholder. + return false; + } + } } if (IsA(element)) {