Changeset 270154 in webkit


Ignore:
Timestamp:
Nov 21, 2020 3:03:28 PM (3 years ago)
Author:
Andres Gonzalez
Message:

AccessibilityObject::FocusedUIElement should not call AXObjectCache::focusedUIElementForPage that can return an isolated object.
https://bugs.webkit.org/show_bug.cgi?id=219238

Reviewed by Chris Fleizach.

Since AXObjectCache::focusedUIElementForPage can return an isolated
object, AccessibilityObject::focusedUIElement should not use it to
determine the focused object. This causes that isolated objects may be
accessed on the main thread when they shouldn't, and even infinite
recursion if this happens when the isolated tree is being built.
This patch changes AccessibilityObject::focusedUIElement to call
AXObjectCache::focusedObjectForPage that always returns another AccessibilityObject.

  • accessibility/AXObjectCache.cpp:

(WebCore::AXObjectCache::focusedObjectForPage):
(WebCore::AXObjectCache::focusedUIElementForPage):
(WebCore::AXObjectCache::generateIsolatedTree):
(WebCore::AXObjectCache::focusedObject): Deleted.

  • accessibility/AXObjectCache.h:
  • accessibility/AccessibilityObject.cpp:

(WebCore::AccessibilityObject::focusedUIElement const):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r270153 r270154  
     12020-11-21  Andres Gonzalez  <andresg_22@apple.com>
     2
     3        AccessibilityObject::FocusedUIElement should not call AXObjectCache::focusedUIElementForPage that can return an isolated object.
     4        https://bugs.webkit.org/show_bug.cgi?id=219238
     5
     6        Reviewed by Chris Fleizach.
     7
     8        Since AXObjectCache::focusedUIElementForPage can return an isolated
     9        object, AccessibilityObject::focusedUIElement should not use it to
     10        determine the focused object. This causes that isolated objects may be
     11        accessed on the main thread when they shouldn't, and even infinite
     12        recursion if this happens when the isolated tree is being built.
     13        This patch changes AccessibilityObject::focusedUIElement to call
     14        AXObjectCache::focusedObjectForPage that always returns another AccessibilityObject.
     15
     16        * accessibility/AXObjectCache.cpp:
     17        (WebCore::AXObjectCache::focusedObjectForPage):
     18        (WebCore::AXObjectCache::focusedUIElementForPage):
     19        (WebCore::AXObjectCache::generateIsolatedTree):
     20        (WebCore::AXObjectCache::focusedObject): Deleted.
     21        * accessibility/AXObjectCache.h:
     22        * accessibility/AccessibilityObject.cpp:
     23        (WebCore::AccessibilityObject::focusedUIElement const):
     24
    1252020-11-21  Zalan Bujtas  <zalan@apple.com>
    226
  • trunk/Source/WebCore/accessibility/AXObjectCache.cpp

    r269568 r270154  
    370370}
    371371
    372 AXCoreObject* AXObjectCache::focusedObject(Document& document)
    373 {
    374     Element* focusedElement = document.focusedElement();
     372AXCoreObject* AXObjectCache::focusedObjectForPage(const Page* page)
     373{
     374    ASSERT(isMainThread());
     375
     376    if (!gAccessibilityEnabled)
     377        return nullptr;
     378
     379    // get the focused node in the page
     380    Document* document = page->focusController().focusedOrMainFrame().document();
     381    if (!document)
     382        return nullptr;
     383
     384    document->updateStyleIfNeeded();
     385
     386    Element* focusedElement = document->focusedElement();
    375387    if (is<HTMLAreaElement>(focusedElement))
    376388        return focusedImageMapUIElement(downcast<HTMLAreaElement>(focusedElement));
    377389
    378     auto* axObjectCache = document.axObjectCache();
     390    auto* axObjectCache = document->axObjectCache();
    379391    if (!axObjectCache)
    380392        return nullptr;
    381393
    382     AXCoreObject* focus = axObjectCache->getOrCreate(focusedElement ? focusedElement : static_cast<Node*>(&document));
     394    AXCoreObject* focus = axObjectCache->getOrCreate(focusedElement ? focusedElement : static_cast<Node*>(document));
    383395    if (!focus)
    384396        return nullptr;
     
    422434AXCoreObject* AXObjectCache::focusedUIElementForPage(const Page* page)
    423435{
    424     ASSERT(isMainThread());
    425     if (!gAccessibilityEnabled)
    426         return nullptr;
    427 
    428     // get the focused node in the page
    429     Document* focusedDocument = page->focusController().focusedOrMainFrame().document();
    430     if (!focusedDocument)
    431         return nullptr;
    432 
    433     // Call this before isolated or non-isolated cases so the document is up to do.
    434     focusedDocument->updateStyleIfNeeded();
    435    
    436436#if ENABLE(ACCESSIBILITY_ISOLATED_TREE)
    437437    if (isIsolatedTreeEnabled())
     
    439439#endif
    440440
    441     return focusedObject(*focusedDocument);
     441    return focusedObjectForPage(page);
    442442}
    443443
     
    31803180        tree->generateSubtree(*axRoot, nullptr, true);
    31813181
    3182     auto* axFocus = axObjectCache->focusedObject(document);
     3182    auto* axFocus = axObjectCache->focusedObjectForPage(document.page());
    31833183    if (axFocus)
    31843184        tree->setFocusedNodeID(axFocus->objectID());
  • trunk/Source/WebCore/accessibility/AXObjectCache.h

    r268454 r270154  
    146146
    147147    WEBCORE_EXPORT AXCoreObject* focusedUIElementForPage(const Page*);
     148    static AXCoreObject* focusedObjectForPage(const Page*);
    148149
    149150    // Returns the root object for the entire document.
     
    432433
    433434    static AccessibilityObject* focusedImageMapUIElement(HTMLAreaElement*);
    434     static AXCoreObject* focusedObject(Document&);
    435435
    436436    AXID getAXID(AccessibilityObject*);
  • trunk/Source/WebCore/accessibility/AccessibilityObject.cpp

    r269923 r270154  
    25452545    return document ? document->axObjectCache() : nullptr;
    25462546}
    2547    
     2547
    25482548AXCoreObject* AccessibilityObject::focusedUIElement() const
    25492549{
    25502550    auto* page = this->page();
    25512551    auto* axObjectCache = this->axObjectCache();
    2552     return page && axObjectCache ? axObjectCache->focusedUIElementForPage(page) : nullptr;
     2552    return page && axObjectCache ? axObjectCache->focusedObjectForPage(page) : nullptr;
    25532553}
    25542554   
Note: See TracChangeset for help on using the changeset viewer.