2011-05-28 Gavin Peters <gavinp@chromium.org>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 May 2011 18:18:49 +0000 (18:18 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 May 2011 18:18:49 +0000 (18:18 +0000)
        Reviewed by Adam Barth.

        prevent HTMLLinkElement from watching multiple CachedResources
        https://bugs.webkit.org/show_bug.cgi?id=61686

        If we modify an existing link element, stop listening to the previous
        cached resource, to prevent double notifications (which crash).

        * fast/dom/HTMLLinkElement/prefetch-too-many-clients-expected.txt: Added.
        * fast/dom/HTMLLinkElement/prefetch-too-many-clients.html: Added.
        * platform/gtk/Skipped:
        * platform/mac/Skipped:
        * platform/qt/Skipped:
        * platform/win/Skipped:
2011-05-28  Gavin Peters  <gavinp@chromium.org>

        Reviewed by Adam Barth.

        prevent HTMLLinkElement from watching multiple CachedResources
        https://bugs.webkit.org/show_bug.cgi?id=61686

        If we modify an existing link element, stop listening to the previous
        cached resource, to prevent double notifications (which crash).

        Test: fast/dom/HTMLLinkElement/prefetch-too-many-clients.html

        * html/HTMLLinkElement.cpp:
        (WebCore::HTMLLinkElement::process):

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

LayoutTests/ChangeLog
LayoutTests/fast/dom/HTMLLinkElement/prefetch-too-many-clients-expected.txt [new file with mode: 0644]
LayoutTests/fast/dom/HTMLLinkElement/prefetch-too-many-clients.html [new file with mode: 0644]
LayoutTests/platform/gtk/Skipped
LayoutTests/platform/mac/Skipped
LayoutTests/platform/qt/Skipped
LayoutTests/platform/win/Skipped
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLLinkElement.cpp

index 151972e..da8d05b 100644 (file)
@@ -1,3 +1,20 @@
+2011-05-28  Gavin Peters  <gavinp@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        prevent HTMLLinkElement from watching multiple CachedResources
+        https://bugs.webkit.org/show_bug.cgi?id=61686
+
+        If we modify an existing link element, stop listening to the previous
+        cached resource, to prevent double notifications (which crash).
+
+        * fast/dom/HTMLLinkElement/prefetch-too-many-clients-expected.txt: Added.
+        * fast/dom/HTMLLinkElement/prefetch-too-many-clients.html: Added.
+        * platform/gtk/Skipped:
+        * platform/mac/Skipped:
+        * platform/qt/Skipped:
+        * platform/win/Skipped:
+
 2011-05-28  Tonis Tiigi  <tonistiigi@gmail.com>
 
         Reviewed by Pavel Feldman.
diff --git a/LayoutTests/fast/dom/HTMLLinkElement/prefetch-too-many-clients-expected.txt b/LayoutTests/fast/dom/HTMLLinkElement/prefetch-too-many-clients-expected.txt
new file mode 100644 (file)
index 0000000..47cdd03
--- /dev/null
@@ -0,0 +1,2 @@
+PASS we didn't crash.
+This test makes sure that a single prefetch element is not a client of multiple cachedresources at the same time; by repeatedly changing an existing link element, we will induce a double-notify bug if that element is not releasing its cachedresource on update.
diff --git a/LayoutTests/fast/dom/HTMLLinkElement/prefetch-too-many-clients.html b/LayoutTests/fast/dom/HTMLLinkElement/prefetch-too-many-clients.html
new file mode 100644 (file)
index 0000000..b15832c
--- /dev/null
@@ -0,0 +1,38 @@
+<html>
+<body onload="many_link_updates(50);setTimeout('done();',0)">
+<div id="console"></div>
+<script src="../../js/resources/js-test-pre.js"></script>
+<script>
+
+function addLink(url, rel) {
+    var link = document.getElementById(rel) ||
+               document.createElement('link');
+    link.id = rel;
+    link.rel = rel;
+    link.href = url;
+    document.body.appendChild(link);
+}
+
+function many_link_updates(iter) {
+    for(var i=0;i<iter;++i) {
+        addLink("many_link_updates_" + i + ".html", "prefetch");
+    }
+}
+
+function done() {
+    testPassed("we didn't crash.");
+    if (window.layoutTestController) {
+        layoutTestController.notifyDone();
+    }
+}
+
+if (window.layoutTestController) {
+    layoutTestController.waitUntilDone(); 
+    layoutTestController.dumpAsText();
+}
+</script>
+<p>This test makes sure that a single prefetch element is not a client of multiple cachedresources at the same time; by 
+repeatedly changing an existing link element, we will induce a double-notify bug if that element is not releasing its
+cachedresource on update.</p>
+</body>
+</html>
index 49c44cb..3415804 100644 (file)
@@ -942,9 +942,10 @@ fast/forms/slider-zoomed.html
 # Link prefetch is disabled by default
 fast/dom/HTMLLinkElement/link-and-subresource-test.html
 fast/dom/HTMLLinkElement/prefetch.html
+fast/dom/HTMLLinkElement/prefetch-beforeload.html
 fast/dom/HTMLLinkElement/prefetch-onerror.html
 fast/dom/HTMLLinkElement/prefetch-onload.html
-fast/dom/HTMLLinkElement/prefetch-beforeload.html
+fast/dom/HTMLLinkElement/prefetch-too-many-clients.html
 fast/dom/HTMLLinkElement/prerender.html
 fast/dom/HTMLLinkElement/subresource.html
 
index c306325..0e7dfc8 100644 (file)
@@ -182,6 +182,7 @@ fast/dom/HTMLLinkElement/prefetch.html
 fast/dom/HTMLLinkElement/prefetch-beforeload.html
 fast/dom/HTMLLinkElement/prefetch-onerror.html
 fast/dom/HTMLLinkElement/prefetch-onload.html
+fast/dom/HTMLLinkElement/prefetch-too-many-clients.html
 fast/dom/HTMLLinkElement/prerender.html
 fast/dom/HTMLLinkElement/subresource.html
 http/tests/misc/link-rel-prefetch-and-subresource.html
index 9ba9943..31fe4b8 100644 (file)
@@ -1948,6 +1948,7 @@ fast/dom/HTMLLinkElement/prefetch.html
 fast/dom/HTMLLinkElement/prefetch-beforeload.html
 fast/dom/HTMLLinkElement/prefetch-onerror.html
 fast/dom/HTMLLinkElement/prefetch-onload.html
+fast/dom/HTMLLinkElement/prefetch-too-many-clients.html
 fast/dom/HTMLLinkElement/prerender.html
 fast/dom/HTMLLinkElement/subresource.html
 http/tests/misc/link-rel-prefetch-and-subresource.html
index e7b283c..38b2749 100644 (file)
@@ -1007,6 +1007,7 @@ fast/dom/HTMLLinkElement/prefetch.html
 fast/dom/HTMLLinkElement/prefetch-beforeload.html
 fast/dom/HTMLLinkElement/prefetch-onerror.html
 fast/dom/HTMLLinkElement/prefetch-onload.html
+fast/dom/HTMLLinkElement/prefetch-too-many-clients.html
 http/tests/misc/link-rel-prefetch-and-subresource.html
 fast/dom/HTMLLinkElement/prerender.html
 fast/dom/HTMLLinkElement/subresource.html
index 179dc70..06d08e2 100644 (file)
@@ -1,3 +1,18 @@
+2011-05-28  Gavin Peters  <gavinp@chromium.org>
+
+        Reviewed by Adam Barth.
+
+        prevent HTMLLinkElement from watching multiple CachedResources
+        https://bugs.webkit.org/show_bug.cgi?id=61686
+
+        If we modify an existing link element, stop listening to the previous
+        cached resource, to prevent double notifications (which crash).
+
+        Test: fast/dom/HTMLLinkElement/prefetch-too-many-clients.html
+
+        * html/HTMLLinkElement.cpp:
+        (WebCore::HTMLLinkElement::process):
+
 2011-05-28  Tonis Tiigi  <tonistiigi@gmail.com>
 
         Reviewed by Pavel Feldman.
index e607997..4d5671c 100644 (file)
@@ -266,6 +266,11 @@ void HTMLLinkElement::process()
             type = CachedResource::LinkPrerender;
 
         ResourceRequest linkRequest(document()->completeURL(m_url));
+        
+        if (m_cachedLinkResource) {
+            m_cachedLinkResource->removeClient(this);
+            m_cachedLinkResource = 0;
+        }
         m_cachedLinkResource = document()->cachedResourceLoader()->requestLinkResource(type, linkRequest, priority);
         if (m_cachedLinkResource)
             m_cachedLinkResource->addClient(this);