[GTK] Remove subresource leaks from WebKit1 and WebKit2
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Feb 2013 17:50:37 +0000 (17:50 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Feb 2013 17:50:37 +0000 (17:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108960

Patch by George McCollister <george.mccollister@gmail.com> on 2013-02-21
Reviewed by Martin Robinson.

* WebCoreSupport/FrameLoaderClientGtk.cpp:
(WebKit::FrameLoaderClient::dispatchDidFinishLoading): Remove resource
if it isn't the main resource to prevent leak.
(WebKit::FrameLoaderClient::dispatchDidFailLoading): Ditto
* webkit/webkitwebview.cpp:
(cleanupTemporarilyCachedSubresources): Added to cleanup subresources.
(webkit_web_view_get_subresources): Use getSubresources from the
documentLoader to provide subresources since resources will be removed
from webview after loading.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@143619 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/gtk/ChangeLog
Source/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp
Source/WebKit/gtk/webkit/webkitwebview.cpp

index 93aff651e3ed13b11dd1c79334c6319043d6616d..f7ea4e205899d95ecc98ba6c5d2a34ad888aeb9a 100644 (file)
@@ -1,3 +1,20 @@
+2013-02-21  George McCollister  <george.mccollister@gmail.com>
+
+        [GTK] Remove subresource leaks from WebKit1 and WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=108960
+
+        Reviewed by Martin Robinson.
+
+        * WebCoreSupport/FrameLoaderClientGtk.cpp:
+        (WebKit::FrameLoaderClient::dispatchDidFinishLoading): Remove resource
+        if it isn't the main resource to prevent leak.
+        (WebKit::FrameLoaderClient::dispatchDidFailLoading): Ditto
+        * webkit/webkitwebview.cpp:
+        (cleanupTemporarilyCachedSubresources): Added to cleanup subresources.
+        (webkit_web_view_get_subresources): Use getSubresources from the
+        documentLoader to provide subresources since resources will be removed
+        from webview after loading.
+
 2013-02-21  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix make distcheck.
index 24652954287789a26fd8a6df61557ba2820b3eef..6b40e29ba1a8231ad10f499cf268e1baab6fedb5 100644 (file)
@@ -1020,6 +1020,9 @@ void FrameLoaderClient::dispatchDidFinishLoading(WebCore::DocumentLoader* loader
     g_signal_emit_by_name(webResource, "load-finished");
     g_signal_emit_by_name(m_frame, "resource-load-finished", webResource);
     g_signal_emit_by_name(webView, "resource-load-finished", m_frame, webResource);
+
+    if (!g_str_equal(identifierString.get(), webView->priv->mainResourceIdentifier.data()))
+        webkit_web_view_remove_resource(webView, identifierString.get());
 }
 
 void FrameLoaderClient::dispatchDidFailLoading(WebCore::DocumentLoader* loader, unsigned long identifier, const ResourceError& error)
@@ -1042,6 +1045,9 @@ void FrameLoaderClient::dispatchDidFailLoading(WebCore::DocumentLoader* loader,
     g_signal_emit_by_name(webResource, "load-failed", webError.get());
     g_signal_emit_by_name(m_frame, "resource-load-failed", webResource, webError.get());
     g_signal_emit_by_name(webView, "resource-load-failed", m_frame, webResource, webError.get());
+
+    if (!g_str_equal(identifierString.get(), webView->priv->mainResourceIdentifier.data()))
+        webkit_web_view_remove_resource(webView, identifierString.get());
 }
 
 bool FrameLoaderClient::dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length)
index 4d16716b8d9f49aefb003e470b170b3ad99325f6..3c02ff9c784c535b31b3cd8f80dc3a36fc72d005 100644 (file)
@@ -32,6 +32,7 @@
 #include "webkitwebview.h"
 
 #include "AXObjectCache.h"
+#include "ArchiveResource.h"
 #include "BackForwardListImpl.h"
 #include "CairoUtilities.h"
 #include "Chrome.h"
 #include "webkitwebinspectorprivate.h"
 #include "webkitwebpolicydecision.h"
 #include "webkitwebresource.h"
+#include "webkitwebresourceprivate.h"
 #include "webkitwebsettingsprivate.h"
 #include "webkitwebplugindatabaseprivate.h"
 #include "webkitwebwindowfeatures.h"
@@ -5106,11 +5108,32 @@ void webkit_web_view_clear_resources(WebKitWebView* webView)
         g_hash_table_remove_all(priv->subResources.get());
 }
 
+static gboolean cleanupTemporarilyCachedSubresources(gpointer data)
+{
+    GList* subResources = static_cast<GList*>(data);
+    g_list_foreach(subResources, reinterpret_cast<GFunc>(g_object_unref), NULL);
+    g_list_free(subResources);
+    return FALSE;
+}
+
 GList* webkit_web_view_get_subresources(WebKitWebView* webView)
 {
-    WebKitWebViewPrivate* priv = webView->priv;
-    GList* subResources = g_hash_table_get_values(priv->subResources.get());
-    return g_list_remove(subResources, priv->mainResource.get());
+    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), NULL);
+    GList* subResources = 0;
+    Vector<PassRefPtr<ArchiveResource> > coreSubResources;
+
+    core(webView)->mainFrame()->loader()->documentLoader()->getSubresources(coreSubResources);
+
+    for (unsigned i = 0; i < coreSubResources.size(); i++) {
+        WebKitWebResource* webResource = WEBKIT_WEB_RESOURCE(g_object_new(WEBKIT_TYPE_WEB_RESOURCE, NULL));
+        webkit_web_resource_init_with_core_resource(webResource, coreSubResources[i]);
+        subResources = g_list_append(subResources, webResource);
+    }
+
+    if (subResources)
+        g_timeout_add(1, cleanupTemporarilyCachedSubresources, g_list_copy(subResources));
+
+    return subResources;
 }
 
 /* From EventHandler.cpp */