Title: [199881] trunk
Revision
199881
Author
an...@apple.com
Date
2016-04-22 10:37:09 -0700 (Fri, 22 Apr 2016)

Log Message

REGRESSION (r194898): Multi download of external SVG defs file by <use> xlinks:href (caching)
https://bugs.webkit.org/show_bug.cgi?id=156368
<rdar://problem/25611746>

Reviewed by Simon Fraser.

Source/WebCore:

We would load svg resources with fragment identifier again because the encoding never matched.

Test: http/tests/svg/svg-use-external.html

* loader/TextResourceDecoder.cpp:
(WebCore::TextResourceDecoder::setEncoding):
(WebCore::TextResourceDecoder::hasEqualEncodingForCharset):

    Encoding can depend on mime type. Add a comparison function that takes this into account.

(WebCore::findXMLEncoding):
* loader/TextResourceDecoder.h:
(WebCore::TextResourceDecoder::encoding):
* loader/cache/CachedCSSStyleSheet.h:
* loader/cache/CachedResource.h:
(WebCore::CachedResource::textResourceDecoder):

    Add a way to get the TextResourceDecoder from a cached resource.

* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::determineRevalidationPolicy):

    Use the new comparison function.

* loader/cache/CachedSVGDocument.h:
* loader/cache/CachedScript.h:
* loader/cache/CachedXSLStyleSheet.h:

LayoutTests:

* http/tests/svg/resources/symbol-defs.svg: Added.
* http/tests/svg/svg-use-external-expected.txt: Added.
* http/tests/svg/svg-use-external.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (199880 => 199881)


--- trunk/LayoutTests/ChangeLog	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/LayoutTests/ChangeLog	2016-04-22 17:37:09 UTC (rev 199881)
@@ -1,3 +1,15 @@
+2016-04-22  Antti Koivisto  <an...@apple.com>
+
+        REGRESSION (r194898): Multi download of external SVG defs file by <use> xlinks:href (caching)
+        https://bugs.webkit.org/show_bug.cgi?id=156368
+        <rdar://problem/25611746>
+
+        Reviewed by Simon Fraser.
+
+        * http/tests/svg/resources/symbol-defs.svg: Added.
+        * http/tests/svg/svg-use-external-expected.txt: Added.
+        * http/tests/svg/svg-use-external.html: Added.
+
 2016-04-22  Chris Dumez  <cdu...@apple.com>
 
         Drop [UsePointersEvenForNonNullableObjectArguments] from MutationObserver

Added: trunk/LayoutTests/http/tests/svg/resources/symbol-defs.svg (0 => 199881)


--- trunk/LayoutTests/http/tests/svg/resources/symbol-defs.svg	                        (rev 0)
+++ trunk/LayoutTests/http/tests/svg/resources/symbol-defs.svg	2016-04-22 17:37:09 UTC (rev 199881)
@@ -0,0 +1,28 @@
+<svg style="position: absolute; width: 0; height: 0;" width="0" height="0" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <defs>
+        <symbol id="icon-rocket" viewBox="0 0 16 16">
+            <title>rocket</title>
+            <path class="path1" d="M11 1l-5 5h-3l-3 4c0 0 3.178-0.885 5.032-0.47l-5.032 6.47 6.592-5.127c0.919 2.104-0.592 5.127-0.592 5.127l4-3v-3l5-5 1-5-5 1z"></path>
+        </symbol>
+        <symbol id="icon-fire" viewBox="0 0 16 16">
+            <title>fire</title>
+            <path class="path1" d="M5.016 16c-1.066-2.219-0.498-3.49 0.321-4.688 0.897-1.312 1.129-2.61 1.129-2.61s0.706 0.917 0.423 2.352c1.246-1.387 1.482-3.598 1.293-4.445 2.817 1.969 4.021 6.232 2.399 9.392 8.631-4.883 2.147-12.19 1.018-13.013 0.376 0.823 0.448 2.216-0.313 2.893-1.287-4.879-4.468-5.879-4.468-5.879 0.376 2.516-1.364 5.268-3.042 7.324-0.059-1.003-0.122-1.696-0.649-2.656-0.118 1.823-1.511 3.309-1.889 5.135-0.511 2.473 0.383 4.284 3.777 6.197z"></path>
+        </symbol>
+        <symbol id="icon-lab" viewBox="0 0 16 16">
+            <title>lab</title>
+            <path class="path1" d="M14.942 12.57l-4.942-8.235v-3.335h0.5c0.275 0 0.5-0.225 0.5-0.5s-0.225-0.5-0.5-0.5h-5c-0.275 0-0.5 0.225-0.5 0.5s0.225 0.5 0.5 0.5h0.5v3.335l-4.942 8.235c-1.132 1.886-0.258 3.43 1.942 3.43h10c2.2 0 3.074-1.543 1.942-3.43zM3.766 10l3.234-5.39v-3.61h2v3.61l3.234 5.39h-8.468z"></path>
+        </symbol>
+        <symbol id="icon-magnet" viewBox="0 0 16 16">
+            <title>magnet</title>
+            <path class="path1" d="M14 0h-4l1 9c0 1.657-1.343 3-3 3s-3-1.343-3-3l1-9h-4l-1 9c0 3.866 3.134 7 7 7s7-3.134 7-7l-1-9zM12.154 13.154c-1.11 1.11-2.585 1.721-4.154 1.721s-3.045-0.611-4.154-1.721c-1.096-1.096-1.705-2.548-1.72-4.095l0.564-5.075h1.736l-0.55 4.953v0.062c0 1.102 0.429 2.138 1.208 2.917s1.815 1.208 2.917 1.208 2.138-0.429 2.917-1.208c0.779-0.779 1.208-1.815 1.208-2.917v-0.062l-0.007-0.062-0.543-4.891h1.736l0.564 5.075c-0.015 1.547-0.625 2.999-1.72 4.095z"></path>
+        </symbol>
+        <symbol id="icon-shield" viewBox="0 0 16 16">
+            <title>shield</title>
+            <path class="path1" d="M15 0l-7 2-7-2c0 0-0.070 0.808 0 2l7 2.189 7-2.189c0.070-1.192 0-2 0-2zM1.128 3.049c0.375 3.917 1.773 10.504 6.872 12.951 5.099-2.448 6.497-9.034 6.872-12.951l-6.872 2.584-6.872-2.584z"></path>
+        </symbol>
+        <symbol id="icon-power" viewBox="0 0 16 16">
+            <title>power</title>
+            <path class="path1" d="M6 0l-6 8h6l-4 8 14-10h-8l6-6z"></path>
+        </symbol>
+    </defs>
+</svg>
Property changes on: trunk/LayoutTests/http/tests/svg/resources/symbol-defs.svg
___________________________________________________________________

Added: svn:executable

Added: trunk/LayoutTests/http/tests/svg/svg-use-external-expected.txt (0 => 199881)


--- trunk/LayoutTests/http/tests/svg/svg-use-external-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/svg/svg-use-external-expected.txt	2016-04-22 17:37:09 UTC (rev 199881)
@@ -0,0 +1,5 @@
+http://127.0.0.1:8000/svg/resources/symbol-defs.svg#icon-rocket - willSendRequest <NSURLRequest URL http://127.0.0.1:8000/svg/resources/symbol-defs.svg#icon-rocket, main document URL http://127.0.0.1:8000/svg/svg-use-external.html, http method GET> redirectResponse (null)
+http://127.0.0.1:8000/svg/svg-use-external.html - didFinishLoading
+http://127.0.0.1:8000/svg/resources/symbol-defs.svg#icon-rocket - didReceiveResponse <NSURLResponse http://127.0.0.1:8000/svg/resources/symbol-defs.svg#icon-rocket, http status code 200>
+http://127.0.0.1:8000/svg/resources/symbol-defs.svg#icon-rocket - didFinishLoading
+   

Added: trunk/LayoutTests/http/tests/svg/svg-use-external.html (0 => 199881)


--- trunk/LayoutTests/http/tests/svg/svg-use-external.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/svg/svg-use-external.html	2016-04-22 17:37:09 UTC (rev 199881)
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+
+    <title>Verify that the SVG use resource only loads once</title>
+    <script>
+    if (window.testRunner) {
+        testRunner.dumpAsText();
+        testRunner.dumpResourceLoadCallbacks();
+        testRunner.waitUntilDone();
+        _onload_ = function() {
+            testRunner.notifyDone();
+        }
+    }
+    </script>
+</head>
+<body>
+    <svg>
+        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=""
+    </svg>
+
+    <svg>
+        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=""
+    </svg>
+
+    <svg>
+        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=""
+    </svg>
+
+    <svg>
+        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=""
+    </svg>
+
+    <svg>
+        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=""
+    </svg>
+
+    <svg>
+        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=""
+    </svg>
+</body>
+</html>
Property changes on: trunk/LayoutTests/http/tests/svg/svg-use-external.html
___________________________________________________________________

Added: svn:executable

Modified: trunk/Source/WebCore/ChangeLog (199880 => 199881)


--- trunk/Source/WebCore/ChangeLog	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/ChangeLog	2016-04-22 17:37:09 UTC (rev 199881)
@@ -1,3 +1,39 @@
+2016-04-22  Antti Koivisto  <an...@apple.com>
+
+        REGRESSION (r194898): Multi download of external SVG defs file by <use> xlinks:href (caching)
+        https://bugs.webkit.org/show_bug.cgi?id=156368
+        <rdar://problem/25611746>
+
+        Reviewed by Simon Fraser.
+
+        We would load svg resources with fragment identifier again because the encoding never matched.
+
+        Test: http/tests/svg/svg-use-external.html
+
+        * loader/TextResourceDecoder.cpp:
+        (WebCore::TextResourceDecoder::setEncoding):
+        (WebCore::TextResourceDecoder::hasEqualEncodingForCharset):
+
+            Encoding can depend on mime type. Add a comparison function that takes this into account.
+
+        (WebCore::findXMLEncoding):
+        * loader/TextResourceDecoder.h:
+        (WebCore::TextResourceDecoder::encoding):
+        * loader/cache/CachedCSSStyleSheet.h:
+        * loader/cache/CachedResource.h:
+        (WebCore::CachedResource::textResourceDecoder):
+
+            Add a way to get the TextResourceDecoder from a cached resource.
+
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::determineRevalidationPolicy):
+
+            Use the new comparison function.
+
+        * loader/cache/CachedSVGDocument.h:
+        * loader/cache/CachedScript.h:
+        * loader/cache/CachedXSLStyleSheet.h:
+
 2016-04-22  Youenn Fablet  <youenn.fab...@crf.canon.fr>
 
         Drop [UsePointersEvenForNonNullableObjectArguments] from InspectorFrontendHost

Modified: trunk/Source/WebCore/loader/TextResourceDecoder.cpp (199880 => 199881)


--- trunk/Source/WebCore/loader/TextResourceDecoder.cpp	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/loader/TextResourceDecoder.cpp	2016-04-22 17:37:09 UTC (rev 199881)
@@ -359,6 +359,11 @@
     m_source = source;
 }
 
+bool TextResourceDecoder::hasEqualEncodingForCharset(const String& charset) const
+{
+    return defaultEncoding(m_contentType, charset) == m_encoding;
+}
+
 // Returns the position of the encoding string.
 static int findXMLEncoding(const char* str, int len, int& encodingLength)
 {

Modified: trunk/Source/WebCore/loader/TextResourceDecoder.h (199880 => 199881)


--- trunk/Source/WebCore/loader/TextResourceDecoder.h	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/loader/TextResourceDecoder.h	2016-04-22 17:37:09 UTC (rev 199881)
@@ -52,6 +52,8 @@
     void setEncoding(const TextEncoding&, EncodingSource);
     const TextEncoding& encoding() const { return m_encoding; }
 
+    bool hasEqualEncodingForCharset(const String&) const;
+
     WEBCORE_EXPORT String decode(const char* data, size_t length);
     WEBCORE_EXPORT String flush();
 

Modified: trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.h (199880 => 199881)


--- trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.h	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/loader/cache/CachedCSSStyleSheet.h	2016-04-22 17:37:09 UTC (rev 199881)
@@ -55,6 +55,7 @@
 
         void setEncoding(const String&) override;
         String encoding() const override;
+        const TextResourceDecoder* textResourceDecoder() const override { return m_decoder.get(); }
         void finishLoading(SharedBuffer*) override;
         void destroyDecodedData() override;
 

Modified: trunk/Source/WebCore/loader/cache/CachedResource.h (199880 => 199881)


--- trunk/Source/WebCore/loader/cache/CachedResource.h	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/loader/cache/CachedResource.h	2016-04-22 17:37:09 UTC (rev 199881)
@@ -50,6 +50,7 @@
 class SecurityOrigin;
 class SharedBuffer;
 class SubresourceLoader;
+class TextResourceDecoder;
 
 // A resource that is held in the cache. Classes who want to use this object should derive
 // from CachedResourceClient, to get the function calls in case the requested data has arrived.
@@ -100,6 +101,7 @@
 
     virtual void setEncoding(const String&) { }
     virtual String encoding() const { return String(); }
+    virtual const TextResourceDecoder* textResourceDecoder() const { return nullptr; }
     virtual void addDataBuffer(SharedBuffer&);
     virtual void addData(const char* data, unsigned length);
     virtual void finishLoading(SharedBuffer*);

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (199880 => 199881)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2016-04-22 17:37:09 UTC (rev 199881)
@@ -758,7 +758,8 @@
         return Reload;
     }
 
-    if (existingResource->encoding() != TextEncoding(cachedResourceRequest.charset()))
+    auto* textDecoder = existingResource->textResourceDecoder();
+    if (textDecoder && !textDecoder->hasEqualEncodingForCharset(cachedResourceRequest.charset()))
         return Reload;
 
     // FIXME: We should use the same cache policy for all resource types. The raw resource policy is overly strict

Modified: trunk/Source/WebCore/loader/cache/CachedSVGDocument.h (199880 => 199881)


--- trunk/Source/WebCore/loader/cache/CachedSVGDocument.h	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/loader/cache/CachedSVGDocument.h	2016-04-22 17:37:09 UTC (rev 199881)
@@ -41,6 +41,7 @@
     bool mayTryReplaceEncodedData() const override { return true; }
     void setEncoding(const String&) override;
     String encoding() const override;
+    const TextResourceDecoder* textResourceDecoder() const override { return m_decoder.get(); }
     void finishLoading(SharedBuffer*) override;
 
     RefPtr<SVGDocument> m_document;

Modified: trunk/Source/WebCore/loader/cache/CachedScript.h (199880 => 199881)


--- trunk/Source/WebCore/loader/cache/CachedScript.h	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/loader/cache/CachedScript.h	2016-04-22 17:37:09 UTC (rev 199881)
@@ -53,6 +53,7 @@
 
     void setEncoding(const String&) override;
     String encoding() const override;
+    const TextResourceDecoder* textResourceDecoder() const override { return m_decoder.get(); }
     void finishLoading(SharedBuffer*) override;
 
     void destroyDecodedData() override;

Modified: trunk/Source/WebCore/loader/cache/CachedXSLStyleSheet.h (199880 => 199881)


--- trunk/Source/WebCore/loader/cache/CachedXSLStyleSheet.h	2016-04-22 17:18:40 UTC (rev 199880)
+++ trunk/Source/WebCore/loader/cache/CachedXSLStyleSheet.h	2016-04-22 17:37:09 UTC (rev 199881)
@@ -47,6 +47,7 @@
     void didAddClient(CachedResourceClient*) override;
     void setEncoding(const String&) override;
     String encoding() const override;
+    const TextResourceDecoder* textResourceDecoder() const override { return m_decoder.get(); }
     void finishLoading(SharedBuffer*) override;
 
     String m_sheet;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to