[GTK] GObject DOM bindings object are cached forever
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 09:57:42 +0000 (09:57 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 17 Feb 2015 09:57:42 +0000 (09:57 +0000)
commit040aeaede0fc8e6a936fa1f0e7b6a8694bc80ead
tree6eef13dda9a7b98474173223e602bde328d45789
parent8102392147be3b27663e836de2699a5452c03662
[GTK] GObject DOM bindings object are cached forever
https://bugs.webkit.org/show_bug.cgi?id=141558

Reviewed by Sergio Villar Senin.

Source/WebCore:

Rework the DOMObjectCache to avoid having to manually clear the
objects when the frame is destroyed, using a FrameDestructionObserver
instead. When a new object associated to a Frame is added to the
cache, a FrameDestructionObserver is created for the frame if
needed, and the DOM object is tracked by the observer too. When
the frame is detached from the page all its objects are cleared,
and if the aren't additional references, the object is finalized
and removed from the cache normally.
This patch also simplifies and modernizes the code to make it
easier to read an maintain.

* bindings/gobject/DOMObjectCache.cpp:
(WebKit::DOMObjectCacheData::DOMObjectCacheData): Add constructor
to initialize its members and simplify the callers.
(WebKit::DOMObjectCacheData::clearObject): Remove the references
added by the cache, ensuring the GObject is not finalized until
the method returns.
(WebKit::DOMObjectCacheData::refObject): Adds a reference owned by
the cache.
(WebKit::domObjectCacheFrameObservers): Map a frame to a FrameDestructionObserver.
(WebKit::getOrCreateDOMObjectCacheFrameObserver): Create a new
FrameDestructionObserver for the given Frame or return the
existing one.
(WebKit::domObjects): Map wrapped object to wrapper object.
(WebKit::DOMObjectCache::forget): Remove the wrapped object from
the cache.
(WebKit::DOMObjectCache::get): Return the wrapped object if it is
in the cache, increasing the cache references.
(WebKit::DOMObjectCache::put): Add the wrapper object to the cache
for the given wrapped object. If it's a Node and has a frame add
the node to the FrameDestructionObserver corresponding to the frame.
(WebKit::getFrameFromHandle): Deleted.
(WebKit::weakRefNotify): Deleted.
(WebKit::DOMObjectCache::clearByFrame): Deleted.
(WebKit::DOMObjectCache::~DOMObjectCache): Deleted.
* bindings/gobject/DOMObjectCache.h:

Tools:

Add checks for all DOM objects to ensure they are not leaked. Also
add a dedicated test for the DOM Object Cache.

* TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeFilterTest.cpp:
(WebKitDOMNodeFilterTest::testTreeWalker):
(WebKitDOMNodeFilterTest::testNodeIterator):
* TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp:
(WebKitDOMNodeTest::testHierarchyNavigation):
(WebKitDOMNodeTest::testInsertion):
(WebKitDOMNodeTest::testTagNames):
(WebKitDOMNodeTest::testDOMCache):
(registerTests):
* TestWebKitAPI/Tests/WebKit2Gtk/DOMXPathNSResolverTest.cpp:
(WebKitDOMXPathNSResolverTest::evaluateFooChildTextAndCheckResult):
(WebKitDOMXPathNSResolverTest::testXPathNSResolverNative):
(WebKitDOMXPathNSResolverTest::testXPathNSResolverCustom):
* TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp:
(testWebKitDOMObjectCache):
(beforeAll):
* TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
(documentLoadedCallback):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180214 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Source/WebCore/ChangeLog
Source/WebCore/bindings/gobject/DOMObjectCache.cpp
Source/WebCore/bindings/gobject/DOMObjectCache.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeFilterTest.cpp
Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMNodeTest.cpp
Tools/TestWebKitAPI/Tests/WebKit2Gtk/DOMXPathNSResolverTest.cpp
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp
Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp