Title: [289131] trunk/Source/WebCore
Revision
289131
Author
[email protected]
Date
2022-02-04 11:19:42 -0800 (Fri, 04 Feb 2022)

Log Message

Cache some expensive AXIsolatedObject properties lazily.
https://bugs.webkit.org/show_bug.cgi?id=236115
<rdar://problem/88467667>

Reviewed by Chris Fleizach.

Some properties can be very expensive to compute for every object, and
may not even be used by the clients. Furthermore
descriptionAttributeValue() and titleAttributeValue() call
textUnderElement() which may crash if it is called in the middle of a
layout. This is the actual cause of
https://bugs.webkit.org/show_bug.cgi?id=220446.
In this patch, we delay the computation and caching of these two
properties until they are first requested. This solves both the wasteful
computation if these properties are not used, and more importantly the
crash in the above mentioned bug.
This is a follow up change to:
https://bugs.webkit.org/show_bug.cgi?id=236053

* accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::getOrRetrieveStringPropertyValue):
New method to lazily retrieve and cache any String property.
(WebCore::AXIsolatedObject::innerHTML const): Uses getOrRetrieveStringPropertyValue.
(WebCore::AXIsolatedObject::outerHTML const): Dito.
* accessibility/isolatedtree/AXIsolatedObject.h:
* accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:
(WebCore::AXIsolatedObject::initializePlatformProperties):
No longer caches the above mentioned properties.
(WebCore::AXIsolatedObject::descriptionAttributeValue const): Uses getOrRetrieveStringPropertyValue.
(WebCore::AXIsolatedObject::titleAttributeValue const): Dito.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (289130 => 289131)


--- trunk/Source/WebCore/ChangeLog	2022-02-04 18:58:02 UTC (rev 289130)
+++ trunk/Source/WebCore/ChangeLog	2022-02-04 19:19:42 UTC (rev 289131)
@@ -1,3 +1,36 @@
+2022-02-04  Andres Gonzalez  <[email protected]>
+
+        Cache some expensive AXIsolatedObject properties lazily.
+        https://bugs.webkit.org/show_bug.cgi?id=236115
+        <rdar://problem/88467667>
+
+        Reviewed by Chris Fleizach.
+
+        Some properties can be very expensive to compute for every object, and
+        may not even be used by the clients. Furthermore
+        descriptionAttributeValue() and titleAttributeValue() call
+        textUnderElement() which may crash if it is called in the middle of a
+        layout. This is the actual cause of
+        https://bugs.webkit.org/show_bug.cgi?id=220446.
+        In this patch, we delay the computation and caching of these two
+        properties until they are first requested. This solves both the wasteful
+        computation if these properties are not used, and more importantly the
+        crash in the above mentioned bug.
+        This is a follow up change to:
+        https://bugs.webkit.org/show_bug.cgi?id=236053
+
+        * accessibility/isolatedtree/AXIsolatedObject.cpp:
+        (WebCore::AXIsolatedObject::getOrRetrieveStringPropertyValue):
+        New method to lazily retrieve and cache any String property.
+        (WebCore::AXIsolatedObject::innerHTML const): Uses getOrRetrieveStringPropertyValue.
+        (WebCore::AXIsolatedObject::outerHTML const): Dito.
+        * accessibility/isolatedtree/AXIsolatedObject.h:
+        * accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm:
+        (WebCore::AXIsolatedObject::initializePlatformProperties):
+        No longer caches the above mentioned properties.
+        (WebCore::AXIsolatedObject::descriptionAttributeValue const): Uses getOrRetrieveStringPropertyValue.
+        (WebCore::AXIsolatedObject::titleAttributeValue const): Dito.
+
 2022-02-04  Alexander Mikhaylenko  <[email protected]>
 
         [GTK] Crash when starting DND on touchscreen

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp (289130 => 289131)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2022-02-04 18:58:02 UTC (rev 289130)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2022-02-04 19:19:42 UTC (rev 289131)
@@ -975,6 +975,43 @@
     );
 }
 
+String AXIsolatedObject::getOrRetrieveStringPropertyValue(AXPropertyName propertyName)
+{
+    if (m_propertyMap.contains(propertyName))
+        return stringAttributeValue(propertyName);
+
+    Accessibility::performFunctionOnMainThread([&propertyName, this] () {
+        auto* axObject = associatedAXObject();
+        if (!axObject)
+            return;
+
+        String value;
+        switch (propertyName) {
+#if PLATFORM(COCOA)
+        case AXPropertyName::Description:
+            value = axObject->descriptionAttributeValue();
+            break;
+        case AXPropertyName::TitleAttributeValue:
+            value = axObject->titleAttributeValue();
+            break;
+#endif
+        case AXPropertyName::InnerHTML:
+            value = axObject->innerHTML();
+            break;
+        case AXPropertyName::OuterHTML:
+            value = axObject->outerHTML();
+            break;
+        default:
+            break;
+        }
+
+        // Cache value so that there is no need to access the main thread in subsequent calls.
+        setProperty(propertyName, value.isolatedCopy());
+    });
+
+    return stringAttributeValue(propertyName);
+}
+
 void AXIsolatedObject::fillChildrenVectorForProperty(AXPropertyName propertyName, AccessibilityChildrenVector& children) const
 {
     Vector<AXID> childIDs = vectorAttributeValue<AXID>(propertyName);
@@ -2436,34 +2473,12 @@
 
 String AXIsolatedObject::innerHTML() const
 {
-    if (m_propertyMap.contains(AXPropertyName::InnerHTML))
-        return stringAttributeValue(AXPropertyName::InnerHTML);
-
-    return Accessibility::retrieveValueFromMainThread<String>([this] () -> String {
-        auto* axObject = associatedAXObject();
-        String value = axObject ? axObject->innerHTML().isolatedCopy() : String();
-
-        // Cache value so that there is no need to access the main thread in subsequent calls.
-        const_cast<AXIsolatedObject*>(this)->setProperty(AXPropertyName::InnerHTML, value);
-
-        return value;
-    });
+    return const_cast<AXIsolatedObject*>(this)->getOrRetrieveStringPropertyValue(AXPropertyName::InnerHTML);
 }
 
 String AXIsolatedObject::outerHTML() const
 {
-    if (m_propertyMap.contains(AXPropertyName::OuterHTML))
-        return stringAttributeValue(AXPropertyName::OuterHTML);
-
-    return Accessibility::retrieveValueFromMainThread<String>([this] () -> String {
-        auto* axObject = associatedAXObject();
-        String value = axObject ? axObject->outerHTML().isolatedCopy() : String();
-
-        // Cache value so that there is no need to access the main thread in subsequent calls.
-        const_cast<AXIsolatedObject*>(this)->setProperty(AXPropertyName::OuterHTML, value);
-
-        return value;
-    });
+    return const_cast<AXIsolatedObject*>(this)->getOrRetrieveStringPropertyValue(AXPropertyName::OuterHTML);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h (289130 => 289131)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h	2022-02-04 18:58:02 UTC (rev 289130)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.h	2022-02-04 19:19:42 UTC (rev 289131)
@@ -98,6 +98,11 @@
     template<typename T> std::pair<T, T> pairAttributeValue(AXPropertyName) const;
     template<typename T> T propertyValue(AXPropertyName) const;
 
+    // The following method performs a lazy caching of the given property.
+    // If the property is already in m_propertyMap, returns the existing value.
+    // If not, retrieves the property from the main thread and cache it for later use.
+    String getOrRetrieveStringPropertyValue(AXPropertyName);
+
     void fillChildrenVectorForProperty(AXPropertyName, AccessibilityChildrenVector&) const;
     void setMathscripts(AXPropertyName, AXCoreObject&);
     void insertMathPairs(Vector<std::pair<AXID, AXID>>&, AccessibilityMathMultiscriptPairs&);
@@ -332,9 +337,9 @@
 #if PLATFORM(COCOA)
     bool fileUploadButtonReturnsValueInTitle() const override { return boolAttributeValue(AXPropertyName::FileUploadButtonReturnsValueInTitle); }
     String speechHintAttributeValue() const override { return stringAttributeValue(AXPropertyName::SpeechHint); }
-    String descriptionAttributeValue() const override { return stringAttributeValue(AXPropertyName::Description); }
+    String descriptionAttributeValue() const override;
     String helpTextAttributeValue() const override { return stringAttributeValue(AXPropertyName::HelpText); }
-    String titleAttributeValue() const override { return stringAttributeValue(AXPropertyName::TitleAttributeValue); }
+    String titleAttributeValue() const override;
 #endif
 #if PLATFORM(MAC)
     bool caretBrowsingEnabled() const override { return boolAttributeValue(AXPropertyName::CaretBrowsingEnabled); }

Modified: trunk/Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm (289130 => 289131)


--- trunk/Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm	2022-02-04 18:58:02 UTC (rev 289130)
+++ trunk/Source/WebCore/accessibility/isolatedtree/mac/AXIsolatedObjectMac.mm	2022-02-04 19:19:42 UTC (rev 289131)
@@ -34,11 +34,9 @@
 
 void AXIsolatedObject::initializePlatformProperties(const AXCoreObject& object, bool isRoot)
 {
-    setProperty(AXPropertyName::Description, object.descriptionAttributeValue().isolatedCopy());
     setProperty(AXPropertyName::HasApplePDFAnnotationAttribute, object.hasApplePDFAnnotationAttribute());
     setProperty(AXPropertyName::HelpText, object.helpTextAttributeValue().isolatedCopy());
     setProperty(AXPropertyName::SpeechHint, object.speechHintAttributeValue().isolatedCopy());
-    setProperty(AXPropertyName::TitleAttributeValue, object.titleAttributeValue().isolatedCopy());
     setProperty(AXPropertyName::CaretBrowsingEnabled, object.caretBrowsingEnabled());
 
     if (isRoot)
@@ -100,6 +98,16 @@
     });
 }
 
+String AXIsolatedObject::descriptionAttributeValue() const
+{
+    return const_cast<AXIsolatedObject*>(this)->getOrRetrieveStringPropertyValue(AXPropertyName::Description);
+}
+
+String AXIsolatedObject::titleAttributeValue() const
+{
+    return const_cast<AXIsolatedObject*>(this)->getOrRetrieveStringPropertyValue(AXPropertyName::TitleAttributeValue);
+}
+
 } // WebCore
 
 #endif // ENABLE(ACCESSIBILITY_ISOLATED_TREE) && PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to