Title: [134178] trunk/Source/WebCore
Revision
134178
Author
[email protected]
Date
2012-11-11 16:29:47 -0800 (Sun, 11 Nov 2012)

Log Message

axObjectCache code is more complicated than necessary
https://bugs.webkit.org/show_bug.cgi?id=101820

Reviewed by Darin Adler.

This code should use OwnPtr rather than manually calling new/delete.
Also, instead of using a "double check" pattern, we can just access the
private fields on the top document directly.

* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::clearAXObjectCache):
(WebCore::Document::axObjectCacheExists):
(WebCore):
(WebCore::Document::axObjectCache):
* dom/Document.h:
(Document):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (134177 => 134178)


--- trunk/Source/WebCore/ChangeLog	2012-11-12 00:12:03 UTC (rev 134177)
+++ trunk/Source/WebCore/ChangeLog	2012-11-12 00:29:47 UTC (rev 134178)
@@ -1,3 +1,23 @@
+2012-11-11  Adam Barth  <[email protected]>
+
+        axObjectCache code is more complicated than necessary
+        https://bugs.webkit.org/show_bug.cgi?id=101820
+
+        Reviewed by Darin Adler.
+
+        This code should use OwnPtr rather than manually calling new/delete.
+        Also, instead of using a "double check" pattern, we can just access the
+        private fields on the top document directly.
+
+        * dom/Document.cpp:
+        (WebCore::Document::Document):
+        (WebCore::Document::clearAXObjectCache):
+        (WebCore::Document::axObjectCacheExists):
+        (WebCore):
+        (WebCore::Document::axObjectCache):
+        * dom/Document.h:
+        (Document):
+
 2012-11-10  Simon Fraser  <[email protected]>
 
         Save one call to containerForRepaint() when updating layer positions

Modified: trunk/Source/WebCore/dom/Document.cpp (134177 => 134178)


--- trunk/Source/WebCore/dom/Document.cpp	2012-11-12 00:12:03 UTC (rev 134177)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-11-12 00:29:47 UTC (rev 134178)
@@ -526,8 +526,6 @@
     if ((frame && frame->ownerElement()) || !url.isEmpty())
         setURL(url);
 
-    m_axObjectCache = 0;
-
     m_markers = adoptPtr(new DocumentMarkerController);
 
     if (m_frame)
@@ -2201,69 +2199,27 @@
 
 void Document::clearAXObjectCache()
 {
-    // clear cache in top document
-    if (m_axObjectCache) {
-        // Clear the cache member variable before calling delete because attempts
-        // are made to access it during destruction.
-        AXObjectCache* axObjectCache = m_axObjectCache;
-        m_axObjectCache = 0;
-        delete axObjectCache;
-        return;
-    }
-    
-    // ask the top-level document to clear its cache
-    Document* doc = topDocument();
-    if (doc != this)
-        doc->clearAXObjectCache();
+    // Clear the cache member variable before calling delete because attempts
+    // are made to access it during destruction.
+    topDocument()->m_axObjectCache.release();
 }
 
 bool Document::axObjectCacheExists() const
 {
-    if (m_axObjectCache)
-        return true;
-    
-    Document* doc = topDocument();
-    if (doc != this)
-        return doc->axObjectCacheExists();
-    
-    return false;
+    return topDocument()->m_axObjectCache;
 }
-    
+
 AXObjectCache* Document::axObjectCache() const
 {
     // The only document that actually has a AXObjectCache is the top-level
     // document.  This is because we need to be able to get from any WebCoreAXObject
     // to any other WebCoreAXObject on the same page.  Using a single cache allows
     // lookups across nested webareas (i.e. multiple documents).
-    
-    if (m_axObjectCache) {
-        // return already known top-level cache
-        if (!ownerElement())
-            return m_axObjectCache;
-        
-        // In some pages with frames, the cache is created before the sub-webarea is
-        // inserted into the tree.  Here, we catch that case and just toss the old
-        // cache and start over.
-        // NOTE: This recovery may no longer be needed. I have been unable to trigger
-        // it again. See rdar://5794454
-        // FIXME: Can this be fixed when inserting the subframe instead of now?
-        // FIXME: If this function was called to get the cache in order to remove
-        // an AXObject, we are now deleting the cache as a whole and returning a
-        // new empty cache that does not contain the AXObject! That should actually
-        // be OK. I am concerned about other cases like this where accessing the
-        // cache blows away the AXObject being operated on.
-        delete m_axObjectCache;
-        m_axObjectCache = 0;
-    }
-
-    // ask the top-level document for its cache
-    Document* doc = topDocument();
-    if (doc != this)
-        return doc->axObjectCache();
-    
-    // this is the top-level document, so install a new cache
-    m_axObjectCache = new AXObjectCache(this);
-    return m_axObjectCache;
+    Document* document = topDocument();
+    ASSERT(document == this || !m_axObjectCache);
+    if (!document->m_axObjectCache)
+        document->m_axObjectCache = adoptPtr(new AXObjectCache(this));
+    return document->m_axObjectCache.get();
 }
 
 void Document::setVisuallyOrdered()

Modified: trunk/Source/WebCore/dom/Document.h (134177 => 134178)


--- trunk/Source/WebCore/dom/Document.h	2012-11-12 00:12:03 UTC (rev 134177)
+++ trunk/Source/WebCore/dom/Document.h	2012-11-12 00:29:47 UTC (rev 134178)
@@ -1362,7 +1362,7 @@
 
     OwnPtr<RenderArena> m_renderArena;
 
-    mutable AXObjectCache* m_axObjectCache;
+    OwnPtr<AXObjectCache> m_axObjectCache;
     OwnPtr<DocumentMarkerController> m_markers;
     
     Timer<Document> m_updateFocusAppearanceTimer;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to