Title: [292142] trunk/Source/WebCore
Revision
292142
Author
[email protected]
Date
2022-03-30 23:02:36 -0700 (Wed, 30 Mar 2022)

Log Message

Split streaming of AX trees from the class AXLogger.
https://bugs.webkit.org/show_bug.cgi?id=238550
<rdar://problem/91041921>

Reviewed by Chris Fleizach.

AXLogger functionality is debug only. We need to stream the content of
the AX trees both in debug and release builds. This patch splits
streaming of the AX trees from the AXLogger class, which remains a debug
only utility.
In addition, added a mechanism to control what is streamed via the
AXStreamOptions enumeration.

* accessibility/AXLogger.cpp:
(WebCore::shouldLog):
(WebCore::operator<<):
(WebCore::streamIsolatedSubtreeOnMainThread):
Streams a snapshot of the hierarchy of AXIsolatedObjects on the main
thread, limiting the properties of the AXIsolatedObject that can be
accessed using AXStreamOptions.

(WebCore::streamAXCoreObject):
(WebCore::streamSubtree):
(WebCore::AXLogger::add): Replaced with streamSubtree.
* accessibility/AXLogger.h:
* accessibility/isolatedtree/AXIsolatedTree.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (292141 => 292142)


--- trunk/Source/WebCore/ChangeLog	2022-03-31 05:08:35 UTC (rev 292141)
+++ trunk/Source/WebCore/ChangeLog	2022-03-31 06:02:36 UTC (rev 292142)
@@ -1,3 +1,32 @@
+2022-03-30  Andres Gonzalez  <[email protected]>
+
+        Split streaming of AX trees from the class AXLogger.
+        https://bugs.webkit.org/show_bug.cgi?id=238550
+        <rdar://problem/91041921>
+
+        Reviewed by Chris Fleizach.
+
+        AXLogger functionality is debug only. We need to stream the content of
+        the AX trees both in debug and release builds. This patch splits
+        streaming of the AX trees from the AXLogger class, which remains a debug
+        only utility.
+        In addition, added a mechanism to control what is streamed via the
+        AXStreamOptions enumeration.
+
+        * accessibility/AXLogger.cpp:
+        (WebCore::shouldLog):
+        (WebCore::operator<<):
+        (WebCore::streamIsolatedSubtreeOnMainThread):
+        Streams a snapshot of the hierarchy of AXIsolatedObjects on the main
+        thread, limiting the properties of the AXIsolatedObject that can be
+        accessed using AXStreamOptions.
+
+        (WebCore::streamAXCoreObject):
+        (WebCore::streamSubtree):
+        (WebCore::AXLogger::add): Replaced with streamSubtree.
+        * accessibility/AXLogger.h:
+        * accessibility/isolatedtree/AXIsolatedTree.h:
+
 2022-03-30  Brent Fulgham  <[email protected]>
 
         [Cocoa] Ensure correct isAppInitiated state when creating URLRequests from URL 

Modified: trunk/Source/WebCore/accessibility/AXLogger.cpp (292141 => 292142)


--- trunk/Source/WebCore/accessibility/AXLogger.cpp	2022-03-31 05:08:35 UTC (rev 292141)
+++ trunk/Source/WebCore/accessibility/AXLogger.cpp	2022-03-31 06:02:36 UTC (rev 292142)
@@ -27,8 +27,6 @@
  */
 
 #include "config.h"
-
-#if !LOG_DISABLED
 #include "AXLogger.h"
 
 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
@@ -46,12 +44,14 @@
 static bool shouldLog()
 {
     // Modify the initializer list below to choose what thread you want to log messages from.
-    static OptionSet<AXLoggingOptions> loggingOptions { AXLoggingOptions::MainThread, AXLoggingOptions::OffMainThread };
+    static constexpr OptionSet<AXLoggingOptions> loggingOptions { AXLoggingOptions::MainThread, AXLoggingOptions::OffMainThread };
 
     return (isMainThread() && loggingOptions & AXLoggingOptions::MainThread)
         || (!isMainThread() && loggingOptions & AXLoggingOptions::OffMainThread);
 }
 
+#if !LOG_DISABLED
+
 AXLogger::AXLogger(const String& methodName)
     : m_methodName(methodName)
 {
@@ -116,23 +116,6 @@
     }
 }
 
-void AXLogger::add(TextStream& stream, const RefPtr<AXCoreObject>& object, bool recursive)
-{
-    if (shouldLog()) {
-        if (!object)
-            return;
-
-        stream.increaseIndent();
-        stream << *object;
-
-        if (recursive) {
-            for (auto& child : object->children(false))
-                add(stream, child, true);
-        }
-        stream.decreaseIndent();
-    }
-}
-
 void AXLogger::log(const std::pair<RefPtr<AXCoreObject>, AXObjectCache::AXNotification>& notification)
 {
     if (shouldLog()) {
@@ -180,6 +163,8 @@
     }
 }
 
+#endif // !LOG_DISABLED
+
 TextStream& operator<<(TextStream& stream, AccessibilityRole role)
 {
     stream << accessibilityRoleToString(role);
@@ -521,28 +506,8 @@
 
 TextStream& operator<<(TextStream& stream, const AXCoreObject& object)
 {
-    TextStream::GroupScope groupScope(stream);
-    stream << "objectID " << object.objectID();
-    auto role = object.roleValue();
-    stream.dumpProperty("roleValue", role);
-
-    auto* parent = object.parentObjectUnignored();
-    stream.dumpProperty("parentObject", parent ? parent->objectID() : AXID());
-
-    stream.dumpProperty("identifierAttribute", object.identifierAttribute());
-
-    auto* objectWithInterestingHTML = role == AccessibilityRole::Button ? // Add here other roles of interest.
-        &object : nullptr;
-    if (role == AccessibilityRole::StaticText && parent)
-        objectWithInterestingHTML = parent;
-    if (objectWithInterestingHTML)
-        stream.dumpProperty("outerHTML", objectWithInterestingHTML->outerHTML());
-
-    if (auto* axObject = dynamicDowncast<AccessibilityObject>(&object); axObject && axObject->hasDisplayContents())
-        stream.dumpProperty("hasDisplayContents", true);
-    stream.dumpProperty("address", &object);
-    stream.dumpProperty("wrapper", object.wrapper());
-
+    constexpr OptionSet<AXStreamOptions> options = { AXStreamOptions::ObjectID, AXStreamOptions::Role, AXStreamOptions::ParentID, AXStreamOptions::IdentifierAttribute, AXStreamOptions::OuterHTML, AXStreamOptions::DisplayContents, AXStreamOptions::Address };
+    streamAXCoreObject(stream, object, options);
     return stream;
 }
 
@@ -549,13 +514,38 @@
 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
 TextStream& operator<<(TextStream& stream, AXIsolatedTree& tree)
 {
+    ASSERT(!isMainThread());
     TextStream::GroupScope groupScope(stream);
     stream << "treeID " << tree.treeID();
     stream.dumpProperty("rootNodeID", tree.rootNode()->objectID());
     stream.dumpProperty("focusedNodeID", tree.m_focusedNodeID);
-    AXLogger::add(stream, tree.rootNode(), true);
+    constexpr OptionSet<AXStreamOptions> options = { AXStreamOptions::ObjectID, AXStreamOptions::Role, AXStreamOptions::ParentID, AXStreamOptions::IdentifierAttribute, AXStreamOptions::OuterHTML, AXStreamOptions::DisplayContents, AXStreamOptions::Address };
+    streamSubtree(stream, tree.rootNode(), options);
     return stream;
 }
+
+void streamIsolatedSubtreeOnMainThread(TextStream& stream, const AXIsolatedTree& tree, AXID objectID, const OptionSet<AXStreamOptions>& options)
+{
+    ASSERT(isMainThread());
+
+    if (!shouldLog())
+        return;
+
+    stream.increaseIndent();
+    TextStream::GroupScope groupScope(stream);
+
+    if (options & AXStreamOptions::ObjectID)
+        stream << "objectID " << objectID;
+
+    auto ids = tree.m_nodeMap.get(objectID);
+    if (options & AXStreamOptions::ParentID)
+        stream.dumpProperty("parentObject", ids.parentID);
+
+    for (auto& childID : ids.childrenIDs)
+        streamIsolatedSubtreeOnMainThread(stream, tree, childID, options);
+
+    stream.decreaseIndent();
+}
 #endif
 
 TextStream& operator<<(TextStream& stream, AXObjectCache& axObjectCache)
@@ -563,14 +553,69 @@
     TextStream::GroupScope groupScope(stream);
     stream << "AXObjectCache " << &axObjectCache;
 
-    if (auto* root = axObjectCache.get(axObjectCache.document().view()))
-        AXLogger::add(stream, root, true);
-    else
+    if (auto* root = axObjectCache.get(axObjectCache.document().view())) {
+        constexpr OptionSet<AXStreamOptions> options = { AXStreamOptions::ObjectID, AXStreamOptions::Role, AXStreamOptions::ParentID, AXStreamOptions::IdentifierAttribute, AXStreamOptions::OuterHTML, AXStreamOptions::DisplayContents, AXStreamOptions::Address };
+        streamSubtree(stream, root, options);
+    } else
         stream << "No root!";
 
     return stream;
 }
 
+void streamAXCoreObject(TextStream& stream, const AXCoreObject& object, const OptionSet<AXStreamOptions>& options)
+{
+    TextStream::GroupScope groupScope(stream);
+
+    if (options & AXStreamOptions::ObjectID)
+        stream << "objectID " << object.objectID();
+
+    if (options & AXStreamOptions::Role)
+        stream.dumpProperty("role", object.roleValue());
+
+    if (options & AXStreamOptions::ParentID) {
+        auto* parent = object.parentObjectUnignored();
+        stream.dumpProperty("parentObject", parent ? parent->objectID() : AXID());
+    }
+
+    if (options & AXStreamOptions::IdentifierAttribute)
+        stream.dumpProperty("identifierAttribute", object.identifierAttribute());
+
+    if (options & AXStreamOptions::OuterHTML) {
+        auto role = object.roleValue();
+        auto* objectWithInterestingHTML = role == AccessibilityRole::Button ? // Add here other roles of interest.
+            &object : nullptr;
+
+        auto* parent = object.parentObjectUnignored();
+        if (role == AccessibilityRole::StaticText && parent)
+            objectWithInterestingHTML = parent;
+
+        if (objectWithInterestingHTML)
+            stream.dumpProperty("outerHTML", objectWithInterestingHTML->outerHTML());
+    }
+
+    if (options & AXStreamOptions::DisplayContents) {
+        if (auto* axObject = dynamicDowncast<AccessibilityObject>(&object); axObject->hasDisplayContents())
+            stream.dumpProperty("hasDisplayContents", true);
+    }
+
+    if (options & AXStreamOptions::Address) {
+        stream.dumpProperty("address", &object);
+        stream.dumpProperty("wrapper", object.wrapper());
+    }
+}
+
+void streamSubtree(TextStream& stream, const RefPtr<AXCoreObject>& object, const OptionSet<AXStreamOptions>& options)
+{
+    if (!object || !shouldLog())
+        return;
+
+    stream.increaseIndent();
+
+    streamAXCoreObject(stream, *object, options);
+    for (auto& child : object->children(false))
+        streamSubtree(stream, child, options);
+
+    stream.decreaseIndent();
+}
+
 } // namespace WebCore
-
-#endif // !LOG_DISABLED

Modified: trunk/Source/WebCore/accessibility/AXLogger.h (292141 => 292142)


--- trunk/Source/WebCore/accessibility/AXLogger.h	2022-03-31 05:08:35 UTC (rev 292141)
+++ trunk/Source/WebCore/accessibility/AXLogger.h	2022-03-31 06:02:36 UTC (rev 292142)
@@ -25,8 +25,6 @@
 
 #pragma once
 
-#if !LOG_DISABLED
-
 #include "AXObjectCache.h"
 #include "AccessibilityObjectInterface.h"
 
@@ -37,6 +35,18 @@
     OffMainThread = 1 << 1, // Logs messages off the main thread.
 };
 
+enum class AXStreamOptions : uint8_t {
+    ObjectID = 1 << 0,
+    Role = 1 << 1,
+    ParentID = 1 << 2,
+    IdentifierAttribute = 1 << 3,
+    OuterHTML = 1 << 4,
+    DisplayContents = 1 << 5,
+    Address = 1 << 6,
+};
+
+#if !LOG_DISABLED
+
 class AXLogger {
 public:
     AXLogger() = default;
@@ -61,8 +71,6 @@
 #define AXTRACE(methodName) AXLogger axLogger(methodName)
 #define AXLOG(x) AXLogger::log(x)
 
-} // namespace WebCore
-
 #else
 
 #define AXTRACE(methodName) (void)0
@@ -69,3 +77,8 @@
 #define AXLOG(x) (void)0
 
 #endif // !LOG_DISABLED
+
+void streamAXCoreObject(TextStream&, const AXCoreObject&, const OptionSet<AXStreamOptions>&);
+void streamSubtree(TextStream&, const RefPtr<AXCoreObject>&, const OptionSet<AXStreamOptions>&);
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h (292141 => 292142)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h	2022-03-31 05:08:35 UTC (rev 292141)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h	2022-03-31 06:02:36 UTC (rev 292142)
@@ -44,6 +44,7 @@
 class AXIsolatedObject;
 class AXObjectCache;
 class Page;
+enum class AXStreamOptions : uint8_t;
 
 using AXIsolatedTreeID = unsigned;
 
@@ -323,6 +324,7 @@
 class AXIsolatedTree : public ThreadSafeRefCounted<AXIsolatedTree> {
     WTF_MAKE_NONCOPYABLE(AXIsolatedTree); WTF_MAKE_FAST_ALLOCATED;
     friend WTF::TextStream& operator<<(WTF::TextStream&, AXIsolatedTree&);
+    friend void streamIsolatedSubtreeOnMainThread(TextStream&, const AXIsolatedTree&, AXID, const OptionSet<AXStreamOptions>&);
 public:
     static Ref<AXIsolatedTree> create(AXObjectCache*);
     virtual ~AXIsolatedTree();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to