Title: [181631] trunk
Revision
181631
Author
[email protected]
Date
2015-03-17 04:10:13 -0700 (Tue, 17 Mar 2015)

Log Message

[GTK] WebKitDOM objects leaking
https://bugs.webkit.org/show_bug.cgi?id=118788

Reviewed by Darin Adler and Sergio Villar Senin.

Source/WebCore:

Use a DOMwindowObserver class, derived from DOMWindowProperty to
be notified when the window object is detached from the frame to
clear the DOM objects associated to that frame in that case too.

* bindings/gobject/DOMObjectCache.cpp:

Tools:

Update DOMObjectCache unit test to check that DOM objects are also
released when new contents are loaded in the web view, and the old
document is detached from the frame.

* TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp:
(testWebKitDOMObjectCache):
* TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp:
(runTest):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (181630 => 181631)


--- trunk/Source/WebCore/ChangeLog	2015-03-17 10:04:34 UTC (rev 181630)
+++ trunk/Source/WebCore/ChangeLog	2015-03-17 11:10:13 UTC (rev 181631)
@@ -1,3 +1,16 @@
+2015-03-17  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] WebKitDOM objects leaking
+        https://bugs.webkit.org/show_bug.cgi?id=118788
+
+        Reviewed by Darin Adler and Sergio Villar Senin.
+
+        Use a DOMwindowObserver class, derived from DOMWindowProperty to
+        be notified when the window object is detached from the frame to
+        clear the DOM objects associated to that frame in that case too.
+
+        * bindings/gobject/DOMObjectCache.cpp:
+
 2015-03-17  Zan Dobersek  <[email protected]>
 
         [CMake] Use a forwarding header for ANGLE's ShaderLang.h to avoid picking up ANGLE's EGL headers

Modified: trunk/Source/WebCore/bindings/gobject/DOMObjectCache.cpp (181630 => 181631)


--- trunk/Source/WebCore/bindings/gobject/DOMObjectCache.cpp	2015-03-17 10:04:34 UTC (rev 181630)
+++ trunk/Source/WebCore/bindings/gobject/DOMObjectCache.cpp	2015-03-17 11:10:13 UTC (rev 181631)
@@ -19,7 +19,9 @@
 #include "config.h"
 #include "DOMObjectCache.h"
 
+#include "DOMWindowProperty.h"
 #include "Document.h"
+#include "Frame.h"
 #include "FrameDestructionObserver.h"
 #include "Node.h"
 #include <glib-object.h>
@@ -94,11 +96,38 @@
     {
         ASSERT(!m_objects.contains(&data));
 
+        if (!m_domWindowObserver && m_frame->document()->domWindow())
+            m_domWindowObserver = std::make_unique<DOMWindowObserver>(*m_frame, *this);
+
         m_objects.append(&data);
         g_object_weak_ref(data.object, DOMObjectCacheFrameObserver::objectFinalizedCallback, this);
     }
 
 private:
+    class DOMWindowObserver final: public WebCore::DOMWindowProperty {
+        WTF_MAKE_FAST_ALLOCATED;
+    public:
+        DOMWindowObserver(WebCore::Frame& frame, DOMObjectCacheFrameObserver& frameObserver)
+            : DOMWindowProperty(&frame)
+            , m_frameObserver(frameObserver)
+        {
+        }
+
+        virtual ~DOMWindowObserver()
+        {
+        }
+
+    private:
+        virtual void willDetachGlobalObjectFromFrame() override
+        {
+            // Clear the DOMWindowProperty first, and then notify the Frame observer.
+            DOMWindowProperty::willDetachGlobalObjectFromFrame();
+            m_frameObserver.willDetachGlobalObjectFromFrame();
+        }
+
+        DOMObjectCacheFrameObserver& m_frameObserver;
+    };
+
     static void objectFinalizedCallback(gpointer userData, GObject* finalizedObject)
     {
         DOMObjectCacheFrameObserver* observer = static_cast<DOMObjectCacheFrameObserver*>(userData);
@@ -132,7 +161,14 @@
         domObjectCacheFrameObservers().remove(frame);
     }
 
+    void willDetachGlobalObjectFromFrame()
+    {
+        clear();
+        m_domWindowObserver = nullptr;
+    }
+
     Vector<DOMObjectCacheData*, 8> m_objects;
+    std::unique_ptr<DOMWindowObserver> m_domWindowObserver;
 };
 
 typedef HashMap<void*, std::unique_ptr<DOMObjectCacheData>> DOMObjectMap;

Modified: trunk/Tools/ChangeLog (181630 => 181631)


--- trunk/Tools/ChangeLog	2015-03-17 10:04:34 UTC (rev 181630)
+++ trunk/Tools/ChangeLog	2015-03-17 11:10:13 UTC (rev 181631)
@@ -1,3 +1,19 @@
+2015-03-17  Carlos Garcia Campos  <[email protected]>
+
+        [GTK] WebKitDOM objects leaking
+        https://bugs.webkit.org/show_bug.cgi?id=118788
+
+        Reviewed by Darin Adler and Sergio Villar Senin.
+
+        Update DOMObjectCache unit test to check that DOM objects are also
+        released when new contents are loaded in the web view, and the old
+        document is detached from the frame.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp:
+        (testWebKitDOMObjectCache):
+        * TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp:
+        (runTest):
+
 2015-03-17  Youenn Fablet  <[email protected]>
 
         W3C test importer default import folder should be LayoutTests/imported/w3c

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp (181630 => 181631)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp	2015-03-17 10:04:34 UTC (rev 181630)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp	2015-03-17 11:10:13 UTC (rev 181631)
@@ -62,10 +62,15 @@
 static void testWebKitDOMObjectCache(WebViewTest* test, gconstpointer)
 {
     static const char* testHTML = "<html><body><div id='container'><p>DOM Cache test</p><a id='link href=''>link</a></div></body></html>";
-    test->loadHtml(testHTML, nullptr);
-    test->waitUntilLoadFinished();
 
-    g_assert(test->runWebProcessTest("WebKitDOMNode", "dom-cache"));
+    // Run the test 3 times to make sure the DOM objects are correctly released when the
+    // document is detached from the frame for every new document created.
+    for (unsigned i = 0; i < 3; ++i) {
+        test->loadHtml(testHTML, nullptr);
+        test->waitUntilLoadFinished();
+
+        g_assert(test->runWebProcessTest("WebKitDOMNode", "dom-cache"));
+    }
 }
 
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp (181630 => 181631)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp	2015-03-17 10:04:34 UTC (rev 181630)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp	2015-03-17 11:10:13 UTC (rev 181631)
@@ -64,7 +64,14 @@
 
     WebKitWebPage* webPage = WEBKIT_WEB_PAGE(JSObjectGetPrivate(thisObject));
     g_assert(WEBKIT_IS_WEB_PAGE(webPage));
-    WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
+    // Test /WebKitDOMNode/dom-cache is an exception, because it's called 3 times, so
+    // the WebPage is destroyed after the third time.
+    if (g_str_equal(testPath.get(), "WebKitDOMNode/dom-cache")) {
+        static unsigned domCacheTestRunCount = 0;
+        if (++domCacheTestRunCount == 3)
+            WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
+    } else
+        WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
 
     std::unique_ptr<WebProcessTest> test = WebProcessTest::create(String::fromUTF8(testPath.get()));
     return JSValueMakeBoolean(context, test->runTest(g_strrstr(testPath.get(), "/") + 1, webPage));
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to