[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

xan at webkit.org xan at webkit.org
Wed Dec 22 16:17:20 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 7af4f3c7e98732323893d2ebaee9cf49289d2a68
Author: xan at webkit.org <xan at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sun Nov 21 06:11:57 2010 +0000

    WebCore:
    
    2010-11-20  Xan Lopez  <xlopez at igalia.com>
    
            Reviewed by Martin Robinson.
    
            [GTK] Memory managament for DOM GObject wrappers
            https://bugs.webkit.org/show_bug.cgi?id=40302
    
            Initial attempt to have a kind of poor man's garbage collection
            for GObject DOM objects. We tie the object's lifecycle to their
            parent Frame and/or its document; that is, all objects will be
            collected when their parent frame is destroyed or when that frame
            transitions to a new document. Manual management (calling
            g_object_unref on them) is also allowed, and is required for
            objects that are not in the DOM tree (eg NodeLists).
    
            * GNUmakefile.am:
            * bindings/gobject/DOMObjectCache.cpp: Added.
            * bindings/gobject/DOMObjectCache.h: Copied from WebCore/bindings/gobject/WebKitDOMBinding.h.
            * bindings/gobject/WebKitDOMBinding.cpp: Remove the old cache code.
            * bindings/gobject/WebKitDOMBinding.h: ditto.
            * bindings/scripts/CodeGeneratorGObject.pm: include the new DOMObjectCache header.
    
    WebKit/gtk:
    
    2010-11-20  Xan Lopez  <xlopez at igalia.com>
    
            Reviewed by Martin Robinson.
    
            [GTK] Memory managament for DOM GObject wrappers
            https://bugs.webkit.org/show_bug.cgi?id=40302
    
            Initial attempt to have a kind of poor man's garbage collection
            for GObject DOM objects. We tie the object's lifecycle to their
            parent Frame and/or its document; that is, all objects will be
            collected when their parent frame is destroyed or when that frame
            transitions to a new document. Manual management (calling
            g_object_unref on them) is also allowed, and is required for
            objects that are not in the DOM tree (eg NodeLists).
    
            * GNUmakefile.am: add testutils file to testdomdocument.c
            * WebCoreSupport/FrameLoaderClientGtk.cpp:
            (WebKit::FrameLoaderClient::setMainFrameDocumentReady): collect
            DOM objects on document transition.
            * tests/testdomdocument.c:
            (dom_document_fixture_teardown): only destroy the view if it's not
            already destroyed, since the new test detroys it on its own.
            (test_dom_document_get_elements_by_tag_name): manually unref node list.
            (test_dom_document_get_elements_by_class_name): ditto.
            (test_dom_document_get_links): ditto.
            (test_dom_document_garbage_collection): test all possible
            scenarios for DOM object "garbage collection".
            (main): add new test.
            * tests/testdomnode.c:
            (test_dom_node_hierarchy_navigation): manually unref node list.
            (test_dom_node_insertion): ditto.
            * webkit/webkithittestresult.cpp:
            (webkit_hit_test_result_dispose): unref the inner node on dispose
            now that the memory management model is clarified.
            (webkit_hit_test_result_class_init): hook dispose.
            * webkit/webkitwebframe.cpp:
            (webkit_web_frame_core_frame_gone): clear DOM objects attached to this frame.
            (webkit_web_frame_finalize): ditto.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72492 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 142a2f2..f7ae57f 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,25 @@
+2010-11-20  Xan Lopez  <xlopez at igalia.com>
+
+        Reviewed by Martin Robinson.
+
+        [GTK] Memory managament for DOM GObject wrappers
+        https://bugs.webkit.org/show_bug.cgi?id=40302
+
+        Initial attempt to have a kind of poor man's garbage collection
+        for GObject DOM objects. We tie the object's lifecycle to their
+        parent Frame and/or its document; that is, all objects will be
+        collected when their parent frame is destroyed or when that frame
+        transitions to a new document. Manual management (calling
+        g_object_unref on them) is also allowed, and is required for
+        objects that are not in the DOM tree (eg NodeLists).
+
+        * GNUmakefile.am:
+        * bindings/gobject/DOMObjectCache.cpp: Added.
+        * bindings/gobject/DOMObjectCache.h: Copied from WebCore/bindings/gobject/WebKitDOMBinding.h.
+        * bindings/gobject/WebKitDOMBinding.cpp: Remove the old cache code.
+        * bindings/gobject/WebKitDOMBinding.h: ditto.
+        * bindings/scripts/CodeGeneratorGObject.pm: include the new DOMObjectCache header.
+
 2010-11-20  Helder Correia  <helder at sencha.com>
 
         Reviewed by Andreas Kling.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index e8eb386..e5fe2a7 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -639,6 +639,8 @@ webcore_sources += \
 	WebCore/bindings/generic/RuntimeEnabledFeatures.h \
 	WebCore/bindings/gobject/ConvertToUTF8String.cpp \
 	WebCore/bindings/gobject/ConvertToUTF8String.h \
+	WebCore/bindings/gobject/DOMObjectCache.cpp \
+	WebCore/bindings/gobject/DOMObjectCache.h \
 	WebCore/bindings/gobject/GObjectEventListener.cpp \
 	WebCore/bindings/gobject/GObjectEventListener.h \
 	WebCore/bindings/gobject/WebKitDOMBinding.cpp \
diff --git a/WebCore/bindings/gobject/DOMObjectCache.cpp b/WebCore/bindings/gobject/DOMObjectCache.cpp
new file mode 100644
index 0000000..7bf1679
--- /dev/null
+++ b/WebCore/bindings/gobject/DOMObjectCache.cpp
@@ -0,0 +1,153 @@
+/*
+ *  Copyright (C) 2010 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "DOMObjectCache.h"
+
+#include "Document.h"
+#include "Node.h"
+#include <wtf/HashMap.h>
+
+namespace WebKit {
+
+typedef struct {
+    GObject* object;
+    WebCore::Frame* frame;
+    guint timesReturned;
+} DOMObjectCacheData;
+
+typedef HashMap<void*, DOMObjectCacheData*> DOMObjectMap;
+
+static DOMObjectMap& domObjects()
+{
+    static DOMObjectMap staticDOMObjects;
+    return staticDOMObjects;
+}
+
+static WebCore::Frame* getFrameFromHandle(void* objectHandle)
+{
+    WebCore::Node* node = static_cast<WebCore::Node*>(objectHandle);
+    if (!node->inDocument())
+        return 0;
+    WebCore::Document* document = node->document();
+    if (!document)
+        return 0;
+    return document->frame();
+}
+
+void DOMObjectCache::forget(void* objectHandle)
+{
+    DOMObjectCacheData* cacheData = domObjects().get(objectHandle);
+    ASSERT(cacheData);
+    g_slice_free(DOMObjectCacheData, cacheData);
+    domObjects().take(objectHandle);
+}
+
+static void weakRefNotify(gpointer data, GObject* zombie)
+{
+    gboolean* objectDead = static_cast<gboolean*>(data);
+    *objectDead = TRUE;
+}
+
+void DOMObjectCache::clearByFrame(WebCore::Frame* frame)
+{
+    Vector<DOMObjectCacheData*> toUnref;
+
+    // Unreffing the objects removes them from the cache in their
+    // finalize method, so just save them to do that while we are not
+    // iterating the cache itself.
+    DOMObjectMap::iterator end = domObjects().end();
+    for (DOMObjectMap::iterator iter = domObjects().begin(); iter != end; ++iter) {
+        DOMObjectCacheData* data = iter->second;
+        ASSERT(data);
+        if ((!frame || data->frame == frame) && data->timesReturned)
+            toUnref.append(data);
+    }
+
+    Vector<DOMObjectCacheData*>::iterator last = toUnref.end();
+    for (Vector<DOMObjectCacheData*>::iterator it = toUnref.begin(); it != last; ++it) {
+        DOMObjectCacheData* data = *it;
+        // We can't really know what the user has done with the DOM
+        // objects, so in case any of the external references to them
+        // were unreffed (but not all, otherwise the object would be
+        // dead and out of the cache) we'll add a weak ref before we
+        // start to get rid of the cache's own references; if the
+        // object dies in the middle of the process, we'll just stop.
+        gboolean objectDead = FALSE;
+        g_object_weak_ref(data->object, weakRefNotify, &objectDead);
+        // We need to check objectDead first, otherwise the cache data
+        // might be garbage already.
+        while (!objectDead && data->timesReturned > 0) {
+            // If this is the last unref we are going to do,
+            // disconnect the weak ref. We cannot do it afterwards
+            // because the object might be dead at that point.
+            if (data->timesReturned == 1)
+                g_object_weak_unref(data->object, weakRefNotify, &objectDead);
+            data->timesReturned--;
+            g_object_unref(data->object);
+        }
+    }
+}
+
+DOMObjectCache::~DOMObjectCache()
+{
+    clearByFrame();
+}
+
+void* DOMObjectCache::get(void* objectHandle)
+{
+    DOMObjectCacheData* data = domObjects().get(objectHandle);
+    if (!data)
+        return 0;
+
+    // We want to add one ref each time a wrapper is returned, so that
+    // the user can manually unref them if he chooses to.
+    ASSERT(data->object);
+    data->timesReturned++;
+    return g_object_ref(data->object);
+}
+
+void* DOMObjectCache::put(void* objectHandle, void* wrapper)
+{
+    if (domObjects().get(objectHandle))
+        return wrapper;
+
+    DOMObjectCacheData* data = g_slice_new(DOMObjectCacheData);
+    data->object = static_cast<GObject*>(wrapper);
+    data->frame = 0;
+    data->timesReturned = 1;
+
+    domObjects().set(objectHandle, data);
+    return wrapper;
+}
+
+void* DOMObjectCache::put(WebCore::Node* objectHandle, void* wrapper)
+{
+    // call the ::put version that takes void* to do the basic cache
+    // insertion work
+    put(static_cast<void*>(objectHandle), wrapper);
+
+    DOMObjectCacheData* data = domObjects().get(objectHandle);
+    ASSERT(data);
+
+    data->frame = getFrameFromHandle(objectHandle);
+
+    return wrapper;
+}
+
+}
diff --git a/WebCore/bindings/gobject/DOMObjectCache.h b/WebCore/bindings/gobject/DOMObjectCache.h
new file mode 100644
index 0000000..568e8b6
--- /dev/null
+++ b/WebCore/bindings/gobject/DOMObjectCache.h
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (C) 2010 Igalia S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef DOMObjectCache_h
+#define DOMObjectCache_h
+
+namespace WebCore {
+class Node;
+class Frame;
+};
+
+namespace WebKit {
+class DOMObjectCache {
+public:
+    static void* get(void* objectHandle);
+    static void* put(void* objectHandle, void* wrapper);
+    static void* put(WebCore::Node* objectHandle, void* wrapper);
+    static void clearByFrame(WebCore::Frame* frame = 0);
+    static void forget(void* objectHandle);
+    ~DOMObjectCache();
+};
+} // namespace WebKit
+
+#endif
diff --git a/WebCore/bindings/gobject/GObjectEventListener.cpp b/WebCore/bindings/gobject/GObjectEventListener.cpp
index 3e0aa2a..27432b9 100644
--- a/WebCore/bindings/gobject/GObjectEventListener.cpp
+++ b/WebCore/bindings/gobject/GObjectEventListener.cpp
@@ -71,6 +71,7 @@ void GObjectEventListener::handleEvent(ScriptExecutionContext*, Event* event)
     gboolean handled = FALSE;
     WebKitDOMEvent* gobjectEvent = WEBKIT_DOM_EVENT(WebKit::kit(event));
     g_signal_emit_by_name(m_object, m_signalName.data(), gobjectEvent, &handled);
+    g_object_unref(gobjectEvent);
 }
 
 bool GObjectEventListener::operator==(const EventListener& listener)
diff --git a/WebCore/bindings/gobject/WebKitDOMBinding.cpp b/WebCore/bindings/gobject/WebKitDOMBinding.cpp
index 3c066e3..a8a8956 100644
--- a/WebCore/bindings/gobject/WebKitDOMBinding.cpp
+++ b/WebCore/bindings/gobject/WebKitDOMBinding.cpp
@@ -24,6 +24,7 @@
 #include "config.h"
 #include "WebKitDOMBinding.h"
 
+#include "DOMObjectCache.h"
 #include "Element.h"
 #include "Event.h"
 #include "EventException.h"
@@ -44,32 +45,6 @@ namespace WebKit {
 using namespace WebCore;
 using namespace WebCore::HTMLNames;
 
-// DOMObjectCache
-
-typedef HashMap<void*, gpointer> DOMObjectMap;
-
-static DOMObjectMap& domObjects()
-{
-    static DOMObjectMap staticDOMObjects;
-    return staticDOMObjects;
-}
-
-gpointer DOMObjectCache::get(void* objectHandle)
-{
-    return domObjects().get(objectHandle);
-}
-
-gpointer DOMObjectCache::put(void* objectHandle, gpointer wrapper)
-{
-    domObjects().set(objectHandle, wrapper);
-    return wrapper;
-}
-
-void DOMObjectCache::forget(void* objectHandle)
-{
-    domObjects().take(objectHandle);
-}
-
 // kit methods
 
 static gpointer createWrapper(Node* node)
diff --git a/WebCore/bindings/gobject/WebKitDOMBinding.h b/WebCore/bindings/gobject/WebKitDOMBinding.h
index 2248f78..47594a6 100644
--- a/WebCore/bindings/gobject/WebKitDOMBinding.h
+++ b/WebCore/bindings/gobject/WebKitDOMBinding.h
@@ -38,13 +38,6 @@ gpointer kit(WebCore::Node* node);
 gpointer kit(WebCore::Element* element);
 gpointer kit(WebCore::Event* event);
 gpointer kit(WebCore::EventTarget* target);
-
-class DOMObjectCache {
-public:
-    static gpointer get(void* objectHandle);
-    static gpointer put(void* objectHandle, gpointer wrapper);
-    static void forget(void* objectHandle);
-};
 } // namespace WebKit
 
 #endif // WebKitDOMBinding_h
diff --git a/WebCore/bindings/scripts/CodeGeneratorGObject.pm b/WebCore/bindings/scripts/CodeGeneratorGObject.pm
index 6c450ad..ca2bd9c 100644
--- a/WebCore/bindings/scripts/CodeGeneratorGObject.pm
+++ b/WebCore/bindings/scripts/CodeGeneratorGObject.pm
@@ -1322,6 +1322,7 @@ sub Generate {
 
     $implIncludes{"webkitmarshal.h"} = 1;
     $implIncludes{"webkitprivate.h"} = 1;
+    $implIncludes{"DOMObjectCache.h"} = 1;
     $implIncludes{"WebKitDOMBinding.h"} = 1;
     $implIncludes{"gobject/ConvertToUTF8String.h"} = 1;
     $implIncludes{"webkit/$className.h"} = 1;
diff --git a/WebKit/gtk/ChangeLog b/WebKit/gtk/ChangeLog
index bc00b85..245c253 100644
--- a/WebKit/gtk/ChangeLog
+++ b/WebKit/gtk/ChangeLog
@@ -1,3 +1,42 @@
+2010-11-20  Xan Lopez  <xlopez at igalia.com>
+
+        Reviewed by Martin Robinson.
+
+        [GTK] Memory managament for DOM GObject wrappers
+        https://bugs.webkit.org/show_bug.cgi?id=40302
+
+        Initial attempt to have a kind of poor man's garbage collection
+        for GObject DOM objects. We tie the object's lifecycle to their
+        parent Frame and/or its document; that is, all objects will be
+        collected when their parent frame is destroyed or when that frame
+        transitions to a new document. Manual management (calling
+        g_object_unref on them) is also allowed, and is required for
+        objects that are not in the DOM tree (eg NodeLists).
+
+        * GNUmakefile.am: add testutils file to testdomdocument.c
+        * WebCoreSupport/FrameLoaderClientGtk.cpp:
+        (WebKit::FrameLoaderClient::setMainFrameDocumentReady): collect
+        DOM objects on document transition.
+        * tests/testdomdocument.c:
+        (dom_document_fixture_teardown): only destroy the view if it's not
+        already destroyed, since the new test detroys it on its own.
+        (test_dom_document_get_elements_by_tag_name): manually unref node list.
+        (test_dom_document_get_elements_by_class_name): ditto.
+        (test_dom_document_get_links): ditto.
+        (test_dom_document_garbage_collection): test all possible
+        scenarios for DOM object "garbage collection".
+        (main): add new test.
+        * tests/testdomnode.c:
+        (test_dom_node_hierarchy_navigation): manually unref node list.
+        (test_dom_node_insertion): ditto.
+        * webkit/webkithittestresult.cpp:
+        (webkit_hit_test_result_dispose): unref the inner node on dispose
+        now that the memory management model is clarified.
+        (webkit_hit_test_result_class_init): hook dispose.
+        * webkit/webkitwebframe.cpp:
+        (webkit_web_frame_core_frame_gone): clear DOM objects attached to this frame.
+        (webkit_web_frame_finalize): ditto.
+
 2010-11-18  Xan Lopez  <xlopez at igalia.com>
 
         Reviewed by Martin Robinson.
diff --git a/WebKit/gtk/GNUmakefile.am b/WebKit/gtk/GNUmakefile.am
index a3be816..325270e 100644
--- a/WebKit/gtk/GNUmakefile.am
+++ b/WebKit/gtk/GNUmakefile.am
@@ -391,7 +391,7 @@ TEST_PROGS += \
 	Programs/unittests/testcopyandpaste
 
 # Add additional tests here
-Programs_unittests_testdomdocument_SOURCES = WebKit/gtk/tests/testdomdocument.c
+Programs_unittests_testdomdocument_SOURCES = WebKit/gtk/tests/testdomdocument.c WebKit/gtk/tests/test_utils.c
 Programs_unittests_testdomdocument_CFLAGS = $(webkit_tests_cflags)
 Programs_unittests_testdomdocument_LDADD = $(webkit_tests_ldadd)
 Programs_unittests_testdomdocument_LDFLAGS = $(webkit_tests_ldflags)
diff --git a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
index b23bd70..fdef9dc 100644
--- a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
+++ b/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
@@ -28,6 +28,7 @@
 #include "ArchiveResource.h"
 #include "CachedFrame.h"
 #include "Color.h"
+#include "DOMObjectCache.h"
 #include "DocumentLoader.h"
 #include "DocumentLoaderGtk.h"
 #include "FormState.h"
@@ -696,9 +697,10 @@ void FrameLoaderClient::registerForIconNotification(bool shouldRegister)
     notImplemented();
 }
 
-void FrameLoaderClient::setMainFrameDocumentReady(bool)
+void FrameLoaderClient::setMainFrameDocumentReady(bool ready)
 {
-    // this is only interesting once we provide an external API for the DOM
+    if (!ready)
+        DOMObjectCache::clearByFrame(core(m_frame));
 }
 
 bool FrameLoaderClient::hasWebView() const
diff --git a/WebKit/gtk/tests/testdomdocument.c b/WebKit/gtk/tests/testdomdocument.c
index ec2f579..b251b96 100644
--- a/WebKit/gtk/tests/testdomdocument.c
+++ b/WebKit/gtk/tests/testdomdocument.c
@@ -30,7 +30,8 @@
 #define HTML_DOCUMENT_ELEMENTS "<html><body><ul><li>1</li><li>2</li><li>3</li></ul></body></html>"
 #define HTML_DOCUMENT_ELEMENTS_CLASS "<html><body><div class=\"test\"></div><div class=\"strange\"></div><div class=\"test\"></div></body></html>"
 #define HTML_DOCUMENT_ELEMENTS_ID "<html><body><div id=\"testok\"></div><div id=\"testbad\">first</div><div id=\"testbad\">second</div></body></html>"
-#define HTML_DOCUMENT_LINKS "<html><body><a href=\"about:blank\">blank</a><a href=\"http://www.google.com\">google</a><a href=\"http://www.webkit.org\">webkit</a></body></html>"
+#define HTML_DOCUMENT_LINKS "<html><head><title>Title</title></head><body><a href=\"about:blank\">blank</a><a href=\"http://www.google.com\">google</a><a href=\"http://www.webkit.org\">webkit</a></body></html>"
+#define HTML_DOCUMENT_IFRAME "<html><head><title>IFrame</title></head><body><iframe id='iframe'></iframe><div id='test'></div></body></html>"
 
 typedef struct {
     GtkWidget* webView;
@@ -60,7 +61,8 @@ static void dom_document_fixture_setup(DomDocumentFixture* fixture, gconstpointe
 
 static void dom_document_fixture_teardown(DomDocumentFixture* fixture, gconstpointer data)
 {
-    g_object_unref(fixture->webView);
+    if (fixture->webView)
+        g_object_unref(fixture->webView);
     g_main_loop_unref(fixture->loop);
 }
 
@@ -107,6 +109,8 @@ static void test_dom_document_get_elements_by_tag_name(DomDocumentFixture* fixtu
         g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, n);
         g_free(n);
     }
+
+    g_object_unref(list);
 }
 
 static void test_dom_document_get_elements_by_class_name(DomDocumentFixture* fixture, gconstpointer data)
@@ -130,6 +134,8 @@ static void test_dom_document_get_elements_by_class_name(DomDocumentFixture* fix
         g_assert(element);
         g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "DIV");
     }
+
+    g_object_unref(list);
 }
 
 static void test_dom_document_get_element_by_id(DomDocumentFixture* fixture, gconstpointer data)
@@ -178,6 +184,138 @@ static void test_dom_document_get_links(DomDocumentFixture* fixture, gconstpoint
         WebKitDOMHTMLAnchorElement *anchor = (WebKitDOMHTMLAnchorElement*)element;
         g_assert_cmpstr(webkit_dom_html_anchor_element_get_href(anchor), ==, uris[i]);
     }
+    g_object_unref(collection);
+}
+
+static void weak_notify(gpointer data, GObject* zombie)
+{
+    guint* count = (guint*)data;
+    (*count)++;
+}
+
+static void test_dom_document_garbage_collection(DomDocumentFixture* fixture, gconstpointer data)
+{
+    guint count = 0;
+    g_assert(fixture);
+    WebKitWebView* view = (WebKitWebView*)fixture->webView;
+    g_assert(view);
+    WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
+    g_assert(document);
+    g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count);
+    WebKitDOMHTMLHeadElement* head = webkit_dom_document_get_head(document);
+    g_assert(head);
+    g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count);
+    WebKitDOMHTMLElement* body = webkit_dom_document_get_body(document);
+    g_assert(body);
+    g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count);
+    WebKitDOMHTMLCollection *collection = webkit_dom_document_get_links(document);
+    g_assert(collection);
+    g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count);
+
+    webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_LINKS, NULL, NULL, NULL);
+
+    while (g_main_context_pending(NULL))
+        g_main_context_iteration(NULL, FALSE);
+
+    g_assert_cmpuint(count, ==, 3);
+
+    g_object_unref(collection);
+    g_assert_cmpuint(count, ==, 4);
+
+    count = 0;
+
+    document = webkit_web_view_get_dom_document(view);
+    g_assert(document);
+    g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count);
+    head = webkit_dom_document_get_head(document);
+    g_assert(head);
+    g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count);
+    body = webkit_dom_document_get_body(document);
+    g_assert(body);
+    g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count);
+    collection = webkit_dom_document_get_links(document);
+    g_assert(collection);
+    g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count);
+    /* Ask twice for the same object */
+    WebKitDOMHTMLCollection* collection2 = webkit_dom_document_get_links(document);
+    g_assert(collection2);
+    g_object_weak_ref(G_OBJECT(collection2), (GWeakNotify)weak_notify, &count);
+
+    g_object_unref(document);
+    g_object_unref(head);
+    g_object_unref(body);
+    g_object_unref(collection);
+    g_object_unref(collection2);
+
+    g_assert_cmpuint(count, ==, 5);
+
+    webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_IFRAME, NULL, NULL, NULL);
+
+    while (g_main_context_pending(NULL))
+        g_main_context_iteration(NULL, FALSE);
+
+    count = 0;
+
+    document = webkit_web_view_get_dom_document(view);
+    WebKitDOMElement* div = webkit_dom_document_get_element_by_id(document, "test");
+    g_assert(div);
+    g_object_weak_ref(G_OBJECT(div), (GWeakNotify)weak_notify, &count);
+    WebKitDOMElement* iframe = webkit_dom_document_get_element_by_id(document, "iframe");
+    g_assert(iframe);
+
+    /* FIXME: IFrame APIs have the 'i' in the wrong place */
+    webkit_dom_element_set_attribute(iframe, "src", "data:<html><head></head></html>", NULL);
+
+    while (g_main_context_pending(NULL))
+        g_main_context_iteration(NULL, FALSE);
+
+    WebKitDOMDocument* iframeDocument = webkit_dom_htmli_frame_element_get_content_document(WEBKIT_DOM_HTMLI_FRAME_ELEMENT(iframe));
+    g_assert(iframeDocument);
+    head = webkit_dom_document_get_head(iframeDocument);
+    g_assert(head);
+    g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count);
+
+    webkit_dom_element_set_attribute(iframe, "src", "about:blank", NULL);
+
+    while (g_main_context_pending(NULL))
+        g_main_context_iteration(NULL, FALSE);
+
+    g_assert_cmpuint(count, ==, 1);
+
+    webkit_web_view_load_string(WEBKIT_WEB_VIEW(view), HTML_DOCUMENT_LINKS, NULL, NULL, NULL);
+
+    while (g_main_context_pending(NULL))
+        g_main_context_iteration(NULL, FALSE);
+
+    g_assert_cmpuint(count, ==, 2);
+
+    count = 0;
+
+    document = webkit_web_view_get_dom_document(view);
+    g_assert(document);
+    g_object_weak_ref(G_OBJECT(document), (GWeakNotify)weak_notify, &count);
+    /* Ask twice for the Document */
+    WebKitDOMDocument* document2 = webkit_web_view_get_dom_document(view);
+    g_assert(document2);
+    g_object_weak_ref(G_OBJECT(document2), (GWeakNotify)weak_notify, &count);
+    head = webkit_dom_document_get_head(document);
+    g_assert(head);
+    g_object_weak_ref(G_OBJECT(head), (GWeakNotify)weak_notify, &count);
+    body = webkit_dom_document_get_body(document);
+    g_assert(body);
+    g_object_weak_ref(G_OBJECT(body), (GWeakNotify)weak_notify, &count);
+    collection = webkit_dom_document_get_links(document);
+    g_assert(collection);
+    g_object_weak_ref(G_OBJECT(collection), (GWeakNotify)weak_notify, &count);
+
+    gtk_widget_destroy(fixture->webView);
+    fixture->webView = NULL;
+
+    g_assert_cmpuint(count, ==, 4);
+
+    g_object_unref(collection);
+
+    g_assert_cmpuint(count, ==, 5);
 }
 
 int main(int argc, char** argv)
@@ -187,6 +325,8 @@ int main(int argc, char** argv)
 
     gtk_test_init(&argc, &argv, NULL);
 
+    testutils_relative_chdir("WebKit/gtk/tests/resources/iframedocument.html", argv[0]);
+
     g_test_bug_base("https://bugs.webkit.org/");
 
     g_test_add("/webkit/domdocument/test_title",
@@ -219,6 +359,12 @@ int main(int argc, char** argv)
                test_dom_document_get_links,
                dom_document_fixture_teardown);
 
+    g_test_add("/webkit/domdocument/test_garbage_collection",
+               DomDocumentFixture, HTML_DOCUMENT_LINKS,
+               dom_document_fixture_setup,
+               test_dom_document_garbage_collection,
+               dom_document_fixture_teardown);
+
     return g_test_run();
 }
 
diff --git a/WebKit/gtk/tests/testdomnode.c b/WebKit/gtk/tests/testdomnode.c
index c6056d6..7d62720 100644
--- a/WebKit/gtk/tests/testdomnode.c
+++ b/WebKit/gtk/tests/testdomnode.c
@@ -84,6 +84,7 @@ static void test_dom_node_hierarchy_navigation(DomNodeFixture* fixture, gconstpo
     ptr = webkit_dom_node_list_item(list, 0);
     g_assert(ptr);
     g_assert(WEBKIT_DOM_IS_HTML_TITLE_ELEMENT(ptr));
+    g_object_unref(list);
 
     /* Body, Head sibling */
     ptr = webkit_dom_node_get_next_sibling(WEBKIT_DOM_NODE(head));
@@ -118,6 +119,7 @@ static void test_dom_node_hierarchy_navigation(DomNodeFixture* fixture, gconstpo
         /* Nothing */;
 
     g_assert_cmpint(i, ==, 3);
+    g_object_unref(list);
 }
 
 static void test_dom_node_insertion(DomNodeFixture* fixture, gconstpointer data)
@@ -148,6 +150,7 @@ static void test_dom_node_insertion(DomNodeFixture* fixture, gconstpointer data)
     node = webkit_dom_node_list_item(list, 0);
     g_assert(node);
     g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(p), node));
+    g_object_unref(list);
 
     /* Replace the P tag with a DIV tag */
     div = webkit_dom_document_create_element(document, "DIV", NULL);
@@ -158,11 +161,13 @@ static void test_dom_node_insertion(DomNodeFixture* fixture, gconstpointer data)
     node = webkit_dom_node_list_item(list, 0);
     g_assert(node);
     g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(div), node));
+    g_object_unref(list);
 
     /* Now remove the tag */
     webkit_dom_node_remove_child(WEBKIT_DOM_NODE(body), node, NULL);
     list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
     g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 0);
+    g_object_unref(list);
 
     /* TODO: insert_before, which does not seem to be working correctly */
 }
diff --git a/WebKit/gtk/webkit/webkithittestresult.cpp b/WebKit/gtk/webkit/webkithittestresult.cpp
index 862d94a..931289e 100644
--- a/WebKit/gtk/webkit/webkithittestresult.cpp
+++ b/WebKit/gtk/webkit/webkithittestresult.cpp
@@ -71,6 +71,13 @@ static void webkit_hit_test_result_finalize(GObject* object)
     G_OBJECT_CLASS(webkit_hit_test_result_parent_class)->finalize(object);
 }
 
+static void webkit_hit_test_result_dispose(GObject* object)
+{
+    g_object_unref(WEBKIT_HIT_TEST_RESULT(object)->priv->innerNode);
+
+    G_OBJECT_CLASS(webkit_hit_test_result_parent_class)->dispose(object);
+}
+
 static void webkit_hit_test_result_get_property(GObject* object, guint propertyID, GValue* value, GParamSpec* pspec)
 {
     WebKitHitTestResult* web_hit_test_result = WEBKIT_HIT_TEST_RESULT(object);
@@ -131,6 +138,7 @@ static void webkit_hit_test_result_class_init(WebKitHitTestResultClass* webHitTe
     GObjectClass* objectClass = G_OBJECT_CLASS(webHitTestResultClass);
 
     objectClass->finalize = webkit_hit_test_result_finalize;
+    objectClass->dispose = webkit_hit_test_result_dispose;
     objectClass->get_property = webkit_hit_test_result_get_property;
     objectClass->set_property = webkit_hit_test_result_set_property;
 
diff --git a/WebKit/gtk/webkit/webkitwebframe.cpp b/WebKit/gtk/webkit/webkitwebframe.cpp
index 63a2413..fcb5197 100644
--- a/WebKit/gtk/webkit/webkitwebframe.cpp
+++ b/WebKit/gtk/webkit/webkitwebframe.cpp
@@ -35,6 +35,7 @@
 #include "AccessibilityObjectWrapperAtk.h"
 #include "AnimationController.h"
 #include "AXObjectCache.h"
+#include "DOMObjectCache.h"
 #include "DocumentLoader.h"
 #include "DocumentLoaderGtk.h"
 #include "FrameLoader.h"
@@ -146,7 +147,10 @@ static void webkit_web_frame_get_property(GObject* object, guint prop_id, GValue
 void webkit_web_frame_core_frame_gone(WebKitWebFrame* frame)
 {
     ASSERT(WEBKIT_IS_WEB_FRAME(frame));
-    frame->priv->coreFrame = 0;
+    WebKitWebFramePrivate* priv = frame->priv;
+    if (priv->coreFrame)
+        DOMObjectCache::clearByFrame(priv->coreFrame);
+    priv->coreFrame = 0;
 }
 
 static WebKitWebDataSource* webkit_web_frame_get_data_source_from_core_loader(WebCore::DocumentLoader* loader)
@@ -160,6 +164,7 @@ static void webkit_web_frame_finalize(GObject* object)
     WebKitWebFramePrivate* priv = frame->priv;
 
     if (priv->coreFrame) {
+        DOMObjectCache::clearByFrame(priv->coreFrame);
         priv->coreFrame->loader()->cancelAndClear();
         priv->coreFrame = 0;
     }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list