<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[182396] releases/WebKitGTK/webkit-2.6</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/182396">182396</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2015-04-06 05:03:55 -0700 (Mon, 06 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/181631">r181631</a> - [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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#releasesWebKitGTKwebkit26SourceWebCoreChangeLog">releases/WebKitGTK/webkit-2.6/Source/WebCore/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit26SourceWebCorebindingsgobjectDOMObjectCachecpp">releases/WebKitGTK/webkit-2.6/Source/WebCore/bindings/gobject/DOMObjectCache.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit26ToolsChangeLog">releases/WebKitGTK/webkit-2.6/Tools/ChangeLog</a></li>
<li><a href="#releasesWebKitGTKwebkit26ToolsTestWebKitAPITestsWebKit2GtkTestDOMNodecpp">releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp</a></li>
<li><a href="#releasesWebKitGTKwebkit26ToolsTestWebKitAPITestsWebKit2GtkWebProcessTestcpp">releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="releasesWebKitGTKwebkit26SourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.6/Source/WebCore/ChangeLog (182395 => 182396)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.6/Source/WebCore/ChangeLog        2015-04-06 12:00:47 UTC (rev 182395)
+++ releases/WebKitGTK/webkit-2.6/Source/WebCore/ChangeLog        2015-04-06 12:03:55 UTC (rev 182396)
</span><span class="lines">@@ -1,3 +1,16 @@
</span><ins>+2015-03-17  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [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:
+
</ins><span class="cx"> 2015-02-17  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] GObject DOM bindings object are cached forever
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit26SourceWebCorebindingsgobjectDOMObjectCachecpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.6/Source/WebCore/bindings/gobject/DOMObjectCache.cpp (182395 => 182396)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.6/Source/WebCore/bindings/gobject/DOMObjectCache.cpp        2015-04-06 12:00:47 UTC (rev 182395)
+++ releases/WebKitGTK/webkit-2.6/Source/WebCore/bindings/gobject/DOMObjectCache.cpp        2015-04-06 12:03:55 UTC (rev 182396)
</span><span class="lines">@@ -19,7 +19,9 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;DOMObjectCache.h&quot;
</span><span class="cx"> 
</span><ins>+#include &quot;DOMWindowProperty.h&quot;
</ins><span class="cx"> #include &quot;Document.h&quot;
</span><ins>+#include &quot;Frame.h&quot;
</ins><span class="cx"> #include &quot;FrameDestructionObserver.h&quot;
</span><span class="cx"> #include &quot;Node.h&quot;
</span><span class="cx"> #include &lt;glib-object.h&gt;
</span><span class="lines">@@ -98,11 +100,38 @@
</span><span class="cx">     {
</span><span class="cx">         ASSERT(!m_objects.contains(&amp;data));
</span><span class="cx"> 
</span><ins>+        if (!m_domWindowObserver &amp;&amp; m_frame-&gt;document()-&gt;domWindow())
+            m_domWindowObserver = std::make_unique&lt;DOMWindowObserver&gt;(*m_frame, *this);
+
</ins><span class="cx">         m_objects.append(&amp;data);
</span><span class="cx">         g_object_weak_ref(data.object, DOMObjectCacheFrameObserver::objectFinalizedCallback, this);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx"> private:
</span><ins>+    class DOMWindowObserver final: public WebCore::DOMWindowProperty {
+        WTF_MAKE_FAST_ALLOCATED;
+    public:
+        DOMWindowObserver(WebCore::Frame&amp; frame, DOMObjectCacheFrameObserver&amp; frameObserver)
+            : DOMWindowProperty(&amp;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&amp; m_frameObserver;
+    };
+
</ins><span class="cx">     static void objectFinalizedCallback(gpointer userData, GObject* finalizedObject)
</span><span class="cx">     {
</span><span class="cx">         DOMObjectCacheFrameObserver* observer = static_cast&lt;DOMObjectCacheFrameObserver*&gt;(userData);
</span><span class="lines">@@ -139,7 +168,14 @@
</span><span class="cx">         domObjectCacheFrameObservers().remove(frame);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    void willDetachGlobalObjectFromFrame()
+    {
+        clear();
+        m_domWindowObserver = nullptr;
+    }
+
</ins><span class="cx">     Vector&lt;DOMObjectCacheData*, 8&gt; m_objects;
</span><ins>+    std::unique_ptr&lt;DOMWindowObserver&gt; m_domWindowObserver;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> typedef HashMap&lt;void*, std::unique_ptr&lt;DOMObjectCacheData&gt;&gt; DOMObjectMap;
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit26ToolsChangeLog"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.6/Tools/ChangeLog (182395 => 182396)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.6/Tools/ChangeLog        2015-04-06 12:00:47 UTC (rev 182395)
+++ releases/WebKitGTK/webkit-2.6/Tools/ChangeLog        2015-04-06 12:03:55 UTC (rev 182396)
</span><span class="lines">@@ -1,3 +1,19 @@
</span><ins>+2015-03-17  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
+
+        [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):
+
</ins><span class="cx"> 2015-02-17  Carlos Garcia Campos  &lt;cgarcia@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Unreviewed. Fix /webkit2/WebKitDOMNode/dom-cache after r180214.
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit26ToolsTestWebKitAPITestsWebKit2GtkTestDOMNodecpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp (182395 => 182396)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp        2015-04-06 12:00:47 UTC (rev 182395)
+++ releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMNode.cpp        2015-04-06 12:03:55 UTC (rev 182396)
</span><span class="lines">@@ -62,10 +62,15 @@
</span><span class="cx"> static void testWebKitDOMObjectCache(WebViewTest* test, gconstpointer)
</span><span class="cx"> {
</span><span class="cx">     static const char* testHTML = &quot;&lt;html&gt;&lt;body&gt;&lt;div id='container'&gt;&lt;p&gt;DOM Cache test&lt;/p&gt;&lt;a id='link href='#'&gt;link&lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;&quot;;
</span><del>-    test-&gt;loadHtml(testHTML, nullptr);
-    test-&gt;waitUntilLoadFinished();
</del><span class="cx"> 
</span><del>-    g_assert(test-&gt;runWebProcessTest(&quot;WebKitDOMNode&quot;, &quot;dom-cache&quot;));
</del><ins>+    // 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 &lt; 3; ++i) {
+        test-&gt;loadHtml(testHTML, nullptr);
+        test-&gt;waitUntilLoadFinished();
+
+        g_assert(test-&gt;runWebProcessTest(&quot;WebKitDOMNode&quot;, &quot;dom-cache&quot;));
+    }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="releasesWebKitGTKwebkit26ToolsTestWebKitAPITestsWebKit2GtkWebProcessTestcpp"></a>
<div class="modfile"><h4>Modified: releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp (182395 => 182396)</h4>
<pre class="diff"><span>
<span class="info">--- releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp        2015-04-06 12:00:47 UTC (rev 182395)
+++ releases/WebKitGTK/webkit-2.6/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebProcessTest.cpp        2015-04-06 12:03:55 UTC (rev 182396)
</span><span class="lines">@@ -64,7 +64,14 @@
</span><span class="cx"> 
</span><span class="cx">     WebKitWebPage* webPage = WEBKIT_WEB_PAGE(JSObjectGetPrivate(thisObject));
</span><span class="cx">     g_assert(WEBKIT_IS_WEB_PAGE(webPage));
</span><del>-    WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
</del><ins>+    // 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(), &quot;WebKitDOMNode/dom-cache&quot;)) {
+        static unsigned domCacheTestRunCount = 0;
+        if (++domCacheTestRunCount == 3)
+            WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
+    } else
+        WebProcessTest::assertObjectIsDeletedWhenTestFinishes(G_OBJECT(webPage));
</ins><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;WebProcessTest&gt; test = WebProcessTest::create(String::fromUTF8(testPath.get()));
</span><span class="cx">     return JSValueMakeBoolean(context, test-&gt;runTest(g_strrstr(testPath.get(), &quot;/&quot;) + 1, webPage));
</span></span></pre>
</div>
</div>

</body>
</html>