Skip to content

Commit

Permalink
AX: Avoid unnecessary main-thread trip to get selectedTextRange() for…
Browse files Browse the repository at this point in the history
… secure fields

https://bugs.webkit.org/show_bug.cgi?id=256407
rdar://problem/108977135

Reviewed by Chris Fleizach.

Secure fields always return an empty selected text range. Since we cache
AXPropertyName::IsSecureField, we can use this information to avoid a
main-thread hit.

* Source/WebCore/accessibility/AccessibilityObjectInterface.h:
(WebCore::AXCoreObject::shouldReturnEmptySelectedText const):
* Source/WebCore/accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::selectedTextRange const):
* Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::selectedTextRange const):

Canonical link: https://commits.webkit.org/263762@main
  • Loading branch information
twilco committed May 6, 2023
1 parent 85db9e0 commit 23f4fb0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Expand Up @@ -1195,6 +1195,7 @@ class AXCoreObject : public ThreadSafeRefCounted<AXCoreObject> {
virtual Path elementPath() const = 0;
virtual bool supportsPath() const = 0;

bool shouldReturnEmptySelectedText() const { return isSecureField(); }
virtual PlainTextRange selectedTextRange() const = 0;
virtual int insertionPointLineNumber() const = 0;

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Expand Up @@ -1389,8 +1389,8 @@ PlainTextRange AccessibilityRenderObject::selectedTextRange() const
{
ASSERT(isTextControl());

if (isSecureField())
return PlainTextRange();
if (shouldReturnEmptySelectedText())
return { };

// Use the text control native range if it's a native object.
if (isNativeTextControl()) {
Expand Down
Expand Up @@ -1168,6 +1168,9 @@ bool AXIsolatedObject::isNativeTextControl() const

PlainTextRange AXIsolatedObject::selectedTextRange() const
{
if (shouldReturnEmptySelectedText())
return { };

return Accessibility::retrieveValueFromMainThread<PlainTextRange>([this] () -> PlainTextRange {
if (auto* object = associatedAXObject())
return object->selectedTextRange();
Expand Down

0 comments on commit 23f4fb0

Please sign in to comment.