AXObjectCache::rootObject should generate the isolated tree.
authorandresg_22@apple.com <andresg_22@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Nov 2019 19:00:20 +0000 (19:00 +0000)
committerandresg_22@apple.com <andresg_22@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 13 Nov 2019 19:00:20 +0000 (19:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204131

Reviewed by Chris Fleizach.

Source/WebCore:

No new tests, no change in functionality.

AXObjectCache::rootObject now returns an AccessibilityObject or an
IsolatedObject. This makes it possible for client code to use the
isolated tree seamlessly, as long as the client call happens on a
secondary thread. This allows WKTR AccessibilityController to use the
isolated tree in LayoutTests.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::clientSupportsIsolatedTree):
(WebCore::AXObjectCache::rootObject):
(WebCore::AXObjectCache::createIsolatedTreeHierarchy):
(WebCore::AXObjectCache::generateIsolatedTree):
(WebCore::AXObjectCache::rootWebArea):
(WebCore::AXObjectCache::createIsolatedAccessibilityTreeHierarchy): Renamed.
(WebCore::AXObjectCache::generateIsolatedAccessibilityTree): renamed.
* accessibility/AXObjectCache.h:

Source/WebKit:

* WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.h:
* WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.mm:
(-[WKAccessibilityWebPageObjectBase accessibilityRootObjectWrapper]):
(-[WKAccessibilityWebPageObjectBase clientSupportsIsolatedTree]): Became a member of AXObjectCache.
(-[WKAccessibilityWebPageObjectBase isolatedTreeRootObject]): Deleted.
* WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm:
(-[WKAccessibilityWebPageObject accessibilityHitTest:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252417 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/accessibility/AXObjectCache.cpp
Source/WebCore/accessibility/AXObjectCache.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/WebPage/atk/WebKitWebPageAccessibilityObject.cpp
Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.h
Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.mm
Source/WebKit/WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm
Source/WebKitLegacy/win/AccessibleDocument.cpp

index 518ebb6..1897a23 100644 (file)
@@ -1,3 +1,28 @@
+2019-11-13  Andres Gonzalez  <andresg_22@apple.com>
+
+        AXObjectCache::rootObject should generate the isolated tree.
+        https://bugs.webkit.org/show_bug.cgi?id=204131
+
+        Reviewed by Chris Fleizach.
+
+        No new tests, no change in functionality.
+
+        AXObjectCache::rootObject now returns an AccessibilityObject or an
+        IsolatedObject. This makes it possible for client code to use the
+        isolated tree seamlessly, as long as the client call happens on a
+        secondary thread. This allows WKTR AccessibilityController to use the
+        isolated tree in LayoutTests.
+        
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::clientSupportsIsolatedTree):
+        (WebCore::AXObjectCache::rootObject):
+        (WebCore::AXObjectCache::createIsolatedTreeHierarchy):
+        (WebCore::AXObjectCache::generateIsolatedTree):
+        (WebCore::AXObjectCache::rootWebArea):
+        (WebCore::AXObjectCache::createIsolatedAccessibilityTreeHierarchy): Renamed.
+        (WebCore::AXObjectCache::generateIsolatedAccessibilityTree): renamed.
+        * accessibility/AXObjectCache.h:
+
 2019-11-13  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][Invalidation] Introduce InvalidationState and Context
index 4fec457..367eab8 100644 (file)
 #include "TextBoundaries.h"
 #include "TextControlInnerElements.h"
 #include "TextIterator.h"
+
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE) && PLATFORM(MAC)
+#include <pal/spi/mac/HIServicesSPI.h>
+#endif
+
 #include <wtf/DataLog.h>
 #include <wtf/SetForScope.h>
 
@@ -123,7 +128,7 @@ const AXID InvalidAXID = 0;
 static const Seconds accessibilityPasswordValueChangeNotificationInterval { 25_ms };
 static const Seconds accessibilityLiveRegionChangedNotificationInterval { 20_ms };
 static const Seconds accessibilityFocusModalNodeNotificationInterval { 50_ms };
-    
+
 static bool rendererNeedsDeferredUpdate(const RenderObject& renderer)
 {
     ASSERT(!renderer.beingDestroyed());
@@ -648,15 +653,58 @@ AccessibilityObject* AXObjectCache::getOrCreate(RenderObject* renderer)
     
     return newObj.get();
 }
-    
-AccessibilityObject* AXObjectCache::rootObject()
+
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+bool AXObjectCache::clientSupportsIsolatedTree()
+{
+    AXClientType type = _AXGetClientForCurrentRequestUntrusted();
+    // FIXME: Remove unknown client before enabling ACCESSIBILITY_ISOLATED_TREE.
+    return type == kAXClientTypeVoiceOver
+        || type == kAXClientTypeUnknown
+        || type == kAXClientTypeNoActiveRequestFound; // For LayoutTests.
+}
+#endif
+
+AXCoreObject* AXObjectCache::rootObject()
 {
     if (!gAccessibilityEnabled)
         return nullptr;
 
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+    if (clientSupportsIsolatedTree())
+        return isolatedTreeRootObject();
+#endif
+
     return getOrCreate(m_document.view());
 }
 
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+AXCoreObject* AXObjectCache::isolatedTreeRootObject()
+{
+    auto pageID = m_document.pageID();
+    if (!pageID)
+        return nullptr;
+
+    auto tree = AXIsolatedTree::treeForPageID(*pageID);
+    if (!tree && isMainThread()) {
+        tree = generateIsolatedTree(*pageID);
+        // Now that we have created our tree, initialize the secondary thread,
+        // so future requests come in on the other thread.
+        _AXUIElementUseSecondaryAXThread(true);
+        return tree->rootNode().get();
+    }
+
+    if (tree && !isMainThread()) {
+        tree->applyPendingChanges();
+        return tree->rootNode().get();
+    }
+
+    // Should not get here, couldn't create or update the IsolatedTree.
+    ASSERT(false);
+    return nullptr;
+}
+#endif
+
 AccessibilityObject* AXObjectCache::rootObjectForFrame(Frame* frame)
 {
     if (!gAccessibilityEnabled)
@@ -2943,7 +2991,7 @@ void AXObjectCache::performDeferredCacheUpdate()
 }
     
 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-Ref<AXIsolatedObject> AXObjectCache::createIsolatedAccessibilityTreeHierarchy(AXCoreObject& object, AXID parentID, AXIsolatedTree& tree, Vector<Ref<AXIsolatedObject>>& nodeChanges)
+Ref<AXIsolatedObject> AXObjectCache::createIsolatedTreeHierarchy(AXCoreObject& object, AXID parentID, AXIsolatedTree& tree, Vector<Ref<AXIsolatedObject>>& nodeChanges)
 {
     auto isolatedTreeNode = AXIsolatedObject::create(object);
     nodeChanges.append(isolatedTreeNode.copyRef());
@@ -2953,24 +3001,25 @@ Ref<AXIsolatedObject> AXObjectCache::createIsolatedAccessibilityTreeHierarchy(AX
     attachWrapper(&isolatedTreeNode.get());
 
     for (const auto& child : object.children()) {
-        auto staticChild = createIsolatedAccessibilityTreeHierarchy(*child, isolatedTreeNode->objectID(), tree, nodeChanges);
+        auto staticChild = createIsolatedTreeHierarchy(*child, isolatedTreeNode->objectID(), tree, nodeChanges);
         isolatedTreeNode->appendChild(staticChild->objectID());
     }
 
     return isolatedTreeNode;
 }
     
-Ref<AXIsolatedTree> AXObjectCache::generateIsolatedAccessibilityTree()
+Ref<AXIsolatedTree> AXObjectCache::generateIsolatedTree(PageIdentifier pageID)
 {
     RELEASE_ASSERT(isMainThread());
 
-    auto tree = AXIsolatedTree::treeForPageID(*m_document.pageID());
+    auto tree = AXIsolatedTree::treeForPageID(pageID);
     if (!tree)
-        tree = AXIsolatedTree::createTreeForPageID(*m_document.pageID());
+        tree = AXIsolatedTree::createTreeForPageID(pageID);
     
     Vector<Ref<AXIsolatedObject>> nodeChanges;
-    auto root = createIsolatedAccessibilityTreeHierarchy(*rootObject(), InvalidAXID, *tree, nodeChanges);
-    tree->setRoot(root);
+    AccessibilityObject* axRoot = getOrCreate(m_document.view());
+    auto isolatedRoot = createIsolatedTreeHierarchy(*axRoot, InvalidAXID, *tree, nodeChanges);
+    tree->setRoot(isolatedRoot);
     tree->appendNodeChanges(nodeChanges);
 
     return makeRef(*tree);
@@ -3064,7 +3113,7 @@ bool isNodeAriaVisible(Node* node)
 
 AccessibilityObject* AXObjectCache::rootWebArea()
 {
-    AccessibilityObject* rootObject = this->rootObject();
+    AXCoreObject* rootObject = this->rootObject();
     if (!rootObject || !rootObject->isAccessibilityScrollView())
         return nullptr;
     return downcast<AccessibilityScrollView>(*rootObject).webAreaObject();
index fd4344f..df45185 100644 (file)
@@ -151,7 +151,7 @@ public:
     WEBCORE_EXPORT static AXCoreObject* focusedUIElementForPage(const Page*);
 
     // Returns the root object for the entire document.
-    WEBCORE_EXPORT AccessibilityObject* rootObject();
+    WEBCORE_EXPORT AXCoreObject* rootObject();
     // Returns the root object for a specific frame.
     WEBCORE_EXPORT AccessibilityObject* rootObjectForFrame(Frame*);
     
@@ -192,11 +192,14 @@ public:
     void recomputeIsIgnored(RenderObject* renderer);
 
 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-    WEBCORE_EXPORT Ref<AXIsolatedTree> generateIsolatedAccessibilityTree();
-
-    Ref<AXIsolatedObject> createIsolatedAccessibilityTreeHierarchy(AXCoreObject&, AXID, AXIsolatedTree&, Vector<Ref<AXIsolatedObject>>&);
+    WEBCORE_EXPORT static bool clientSupportsIsolatedTree();
+private:
+    AXCoreObject* isolatedTreeRootObject();
+    Ref<AXIsolatedTree> generateIsolatedTree(PageIdentifier);
+    Ref<AXIsolatedObject> createIsolatedTreeHierarchy(AXCoreObject&, AXID, AXIsolatedTree&, Vector<Ref<AXIsolatedObject>>&);
 #endif
-    
+
+public:
 #if ENABLE(ACCESSIBILITY)
     WEBCORE_EXPORT static void enableAccessibility();
     WEBCORE_EXPORT static void disableAccessibility();
index 428134e..053e341 100644 (file)
@@ -1,3 +1,18 @@
+2019-11-13  Andres Gonzalez  <andresg_22@apple.com>
+
+        AXObjectCache::rootObject should generate the isolated tree.
+        https://bugs.webkit.org/show_bug.cgi?id=204131
+
+        Reviewed by Chris Fleizach.
+
+        * WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.h:
+        * WebProcess/WebPage/mac/WKAccessibilityWebPageObjectBase.mm:
+        (-[WKAccessibilityWebPageObjectBase accessibilityRootObjectWrapper]):
+        (-[WKAccessibilityWebPageObjectBase clientSupportsIsolatedTree]): Became a member of AXObjectCache.
+        (-[WKAccessibilityWebPageObjectBase isolatedTreeRootObject]): Deleted.
+        * WebProcess/WebPage/mac/WKAccessibilityWebPageObjectMac.mm:
+        (-[WKAccessibilityWebPageObject accessibilityHitTest:]):
+
 2019-11-13  Youenn Fablet  <youenn@apple.com>
 
         [ iOS ]: Layout Test http/tests/IndexedDB/storage-limit-1.https.html is a Flaky Failure
index 07bc35b..091fb8f 100644 (file)
@@ -53,7 +53,7 @@ static void coreRootObjectWrapperDetachedCallback(AtkObject* wrapper, const char
     g_signal_emit_by_name(atkObject, "children-changed::remove", 0, wrapper);
 }
 
-static AccessibilityObjectWrapper* rootWebAreaWrapper(AccessibilityObject& rootObject)
+static AccessibilityObjectWrapper* rootWebAreaWrapper(AXCoreObject& rootObject)
 {
     if (!rootObject.isAccessibilityScrollView())
         return nullptr;
@@ -85,7 +85,7 @@ static AtkObject* accessibilityRootObjectWrapper(AtkObject* atkObject)
     if (!cache)
         return nullptr;
 
-    AccessibilityObject* coreRootObject = cache->rootObject();
+    AXCoreObject* coreRootObject = cache->rootObject();
     if (!coreRootObject)
         return nullptr;
 
index 6b7ec5b..aecd4a5 100644 (file)
@@ -46,10 +46,6 @@ class WebPage;
 - (id)accessibilityRootObjectWrapper;
 - (id)accessibilityFocusedUIElement;
 
-#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-- (BOOL)clientSupportsIsolatedTree;
-#endif
-
 @end
 
 #endif // WKAccessibilityWebPageObjectBase_h
index 53fcb84..d8682a9 100644 (file)
@@ -26,7 +26,6 @@
 #import "config.h"
 #import "WKAccessibilityWebPageObjectBase.h"
 
-#import "ApplicationServicesSPI.h"
 #import "WebFrame.h"
 #import "WebPage.h"
 #import "WKArray.h"
@@ -35,7 +34,6 @@
 #import "WKSharedAPICast.h"
 #import "WKString.h"
 #import "WKStringCF.h"
-#import <WebCore/AXIsolatedTree.h>
 #import <WebCore/AXObjectCache.h>
 #import <WebCore/Document.h>
 #import <WebCore/Frame.h>
     return retrieveBlock();
 }
 
-#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-- (BOOL)clientSupportsIsolatedTree
-{
-    AXClientType type = _AXGetClientForCurrentRequestUntrusted();
-    // FIXME: Remove unknown client before enabling ACCESSIBILITY_ISOLATED_TREE.
-    return type == kAXClientTypeVoiceOver || type == kAXClientTypeUnknown;
-}
-
-- (id)isolatedTreeRootObject
-{
-    if (isMainThread()) {
-        if (auto cache = [self axObjectCache]) {
-            auto tree = cache->generateIsolatedAccessibilityTree();
-
-            // Now that we have created our tree, initialize the secondary thread,
-            // so future requests come in on the other thread.
-            _AXUIElementUseSecondaryAXThread(true);
-            if (auto rootNode = tree->rootNode())
-                return rootNode->wrapper();
-        }
-    } else {
-        auto tree = WebCore::AXIsolatedTree::treeForPageID(m_pageID);
-        tree->applyPendingChanges();
-        if (auto rootNode = tree->rootNode())
-            return rootNode->wrapper();
-    }
-
-    return nil;
-}
-#endif
-
 - (id)accessibilityRootObjectWrapper
 {
     if (!WebCore::AXObjectCache::accessibilityEnabled())
     if (m_hasMainFramePlugin)
         return self.accessibilityPluginObject;
 
-#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-    // If VoiceOver is on, ensure subsequent requests are now handled on the secondary AX thread.
-    bool clientSupportsIsolatedTree = [self clientSupportsIsolatedTree];
-    if (clientSupportsIsolatedTree)
-        return [self isolatedTreeRootObject];
-#endif
-
     if (auto cache = [self axObjectCache]) {
-        if (WebCore::AccessibilityObject* root = cache->rootObject())
+        if (WebCore::AXCoreObject* root = cache->rootObject())
             return root->wrapper();
     }
 
index 3477d48..8d121bc 100644 (file)
@@ -28,6 +28,7 @@
 
 #if PLATFORM(MAC)
 
+#import "ApplicationServicesSPI.h"
 #import "PluginView.h"
 #import "WebFrame.h"
 #import "WebPage.h"
@@ -253,7 +254,7 @@ ALLOW_DEPRECATED_DECLARATIONS_BEGIN
 
         // Isolated tree frames have the offset encoded into them so we don't need to undo here.
 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-        bool queryingIsolatedTree = [self clientSupportsIsolatedTree] && _AXUIElementRequestServicedBySecondaryAXThread();
+        bool queryingIsolatedTree = WebCore::AXObjectCache::clientSupportsIsolatedTree() && _AXUIElementRequestServicedBySecondaryAXThread();
         applyContentOffset = !queryingIsolatedTree;
 #endif
         if (auto pluginView = WebKit::WebPage::pluginViewForFrame(m_page->mainFrame()))
index cd9ca27..8a5609d 100644 (file)
@@ -34,7 +34,7 @@ using namespace WebCore;
 
 // AccessibleDocument
 AccessibleDocument::AccessibleDocument(Document* doc, HWND window)
-    : AccessibleBase(doc->axObjectCache()->rootObject(), window)
+    : AccessibleBase(static_cast<AccessibilityObject*>(doc->axObjectCache()->rootObject()), window)
 {
 }