Title: [258776] trunk/Source/WebCore
Revision
258776
Author
[email protected]
Date
2020-03-20 11:50:00 -0700 (Fri, 20 Mar 2020)

Log Message

Fix for retrieving focus in isolated tree mode.
https://bugs.webkit.org/show_bug.cgi?id=209336

Reviewed by Chris Fleizach.

Focused object requests can come on the secondary thread before the
isolated tree has been generated. Thus, AXObjectCache::isolatedTreeFocusedObject
needs to generate the isolated tree if it doesn't exist, similar to
isolatedTreeRootObject.

* accessibility/AXObjectCache.cpp:
(WebCore::AXObjectCache::isolatedTreeFocusedObject):
(WebCore::AXObjectCache::focusedUIElementForPage):
(WebCore::AXObjectCache::getOrCreateIsolatedTree const):
(WebCore::AXObjectCache::isolatedTreeRootObject):
* accessibility/AXObjectCache.h:
* accessibility/isolatedtree/AXIsolatedObject.cpp:
(WebCore::AXIsolatedObject::focusedUIElement const):
* accessibility/isolatedtree/AXIsolatedTree.h:
m_pendingFocusedNodeID wasn't being initialized, which was causing
random crashes when accessing the HashMap of isolated objects for a
spurious AXID.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (258775 => 258776)


--- trunk/Source/WebCore/ChangeLog	2020-03-20 18:40:36 UTC (rev 258775)
+++ trunk/Source/WebCore/ChangeLog	2020-03-20 18:50:00 UTC (rev 258776)
@@ -1,3 +1,28 @@
+2020-03-20  Andres Gonzalez  <[email protected]>
+
+        Fix for retrieving focus in isolated tree mode.
+        https://bugs.webkit.org/show_bug.cgi?id=209336
+
+        Reviewed by Chris Fleizach.
+
+        Focused object requests can come on the secondary thread before the
+        isolated tree has been generated. Thus, AXObjectCache::isolatedTreeFocusedObject
+        needs to generate the isolated tree if it doesn't exist, similar to
+        isolatedTreeRootObject.
+
+        * accessibility/AXObjectCache.cpp:
+        (WebCore::AXObjectCache::isolatedTreeFocusedObject):
+        (WebCore::AXObjectCache::focusedUIElementForPage):
+        (WebCore::AXObjectCache::getOrCreateIsolatedTree const):
+        (WebCore::AXObjectCache::isolatedTreeRootObject):
+        * accessibility/AXObjectCache.h:
+        * accessibility/isolatedtree/AXIsolatedObject.cpp:
+        (WebCore::AXIsolatedObject::focusedUIElement const):
+        * accessibility/isolatedtree/AXIsolatedTree.h:
+        m_pendingFocusedNodeID wasn't being initialized, which was causing
+        random crashes when accessing the HashMap of isolated objects for a
+        spurious AXID.
+
 2020-03-20  Tim Horton  <[email protected]>
 
         Upstream a variety of Cocoa-platform HAVE and ENABLE macros

Modified: trunk/Source/WebCore/accessibility/AXObjectCache.cpp (258775 => 258776)


--- trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2020-03-20 18:40:36 UTC (rev 258775)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.cpp	2020-03-20 18:50:00 UTC (rev 258776)
@@ -382,19 +382,9 @@
 }
 
 #if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-AXCoreObject* AXObjectCache::isolatedTreeFocusedObject(Document& document)
+AXCoreObject* AXObjectCache::isolatedTreeFocusedObject()
 {
-    auto pageID = document.pageID();
-    if (!pageID)
-        return nullptr;
-
-    auto tree = AXIsolatedTree::treeForPageID(*pageID);
-    if (!tree) {
-        tree = generateIsolatedTree(*pageID, document);
-        initializeSecondaryAXThread();
-    }
-
-    if (tree)
+    if (auto tree = getOrCreateIsolatedTree())
         return tree->focusedUIElement().get();
 
     // Should not get here, couldn't create the IsolatedTree.
@@ -421,6 +411,11 @@
     if (!gAccessibilityEnabled)
         return nullptr;
 
+#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
+    if (isIsolatedTreeEnabled())
+        return isolatedTreeFocusedObject();
+#endif
+
     // get the focused node in the page
     Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
     if (!focusedDocument)
@@ -428,11 +423,6 @@
 
     focusedDocument->updateStyleIfNeeded();
 
-#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
-    if (isIsolatedTreeEnabled())
-        return isolatedTreeFocusedObject(*focusedDocument);
-#endif
-
     return focusedObject(*focusedDocument);
 }
 
@@ -753,7 +743,7 @@
         _AXUIElementUseSecondaryAXThread(true);
 }
 
-AXCoreObject* AXObjectCache::isolatedTreeRootObject()
+RefPtr<AXIsolatedTree> AXObjectCache::getOrCreateIsolatedTree() const
 {
     if (!m_pageID)
         return nullptr;
@@ -766,7 +756,12 @@
         AXObjectCache::initializeSecondaryAXThread();
     }
 
-    if (tree)
+    return tree;
+}
+
+AXCoreObject* AXObjectCache::isolatedTreeRootObject()
+{
+    if (auto tree = getOrCreateIsolatedTree())
         return tree->rootNode().get();
 
     // Should not get here, couldn't create the IsolatedTree.

Modified: trunk/Source/WebCore/accessibility/AXObjectCache.h (258775 => 258776)


--- trunk/Source/WebCore/accessibility/AXObjectCache.h	2020-03-20 18:40:36 UTC (rev 258775)
+++ trunk/Source/WebCore/accessibility/AXObjectCache.h	2020-03-20 18:50:00 UTC (rev 258776)
@@ -143,7 +143,7 @@
     explicit AXObjectCache(Document&);
     ~AXObjectCache();
 
-    WEBCORE_EXPORT static AXCoreObject* focusedUIElementForPage(const Page*);
+    WEBCORE_EXPORT AXCoreObject* focusedUIElementForPage(const Page*);
 
     // Returns the root object for the entire document.
     WEBCORE_EXPORT AXCoreObject* rootObject();
@@ -356,8 +356,9 @@
 private:
     static bool clientSupportsIsolatedTree();
     AXCoreObject* isolatedTreeRootObject();
-    static AXCoreObject* isolatedTreeFocusedObject(Document&);
+    AXCoreObject* isolatedTreeFocusedObject();
     void setIsolatedTreeFocusedObject(Node*);
+    RefPtr<AXIsolatedTree> getOrCreateIsolatedTree() const;
     static Ref<AXIsolatedTree> generateIsolatedTree(PageIdentifier, Document&);
     void updateIsolatedTree(AXCoreObject*, AXNotification);
     static void initializeSecondaryAXThread();

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp (258775 => 258776)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2020-03-20 18:40:36 UTC (rev 258775)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedObject.cpp	2020-03-20 18:50:00 UTC (rev 258776)
@@ -584,9 +584,7 @@
 
 AXCoreObject* AXIsolatedObject::focusedUIElement() const
 {
-    if (auto focusedElement = tree()->focusedUIElement())
-        return focusedElement.get();
-    return nullptr;
+    return tree()->focusedUIElement().get();
 }
     
 AXCoreObject* AXIsolatedObject::parentObjectUnignored() const

Modified: trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h (258775 => 258776)


--- trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h	2020-03-20 18:40:36 UTC (rev 258775)
+++ trunk/Source/WebCore/accessibility/isolatedtree/AXIsolatedTree.h	2020-03-20 18:50:00 UTC (rev 258776)
@@ -102,7 +102,7 @@
     // Written to by main thread under lock, accessed and applied by AX thread.
     Vector<NodeChange> m_pendingAppends;
     Vector<AXID> m_pendingRemovals;
-    AXID m_pendingFocusedNodeID;
+    AXID m_pendingFocusedNodeID { InvalidAXID };
     Lock m_changeLogLock;
 
     AXIsolatedTreeID m_treeID;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to