Title: [186180] trunk
Revision
186180
Author
an...@apple.com
Date
2015-07-01 10:22:27 -0700 (Wed, 01 Jul 2015)

Log Message

PNG mask images are loaded with Accept:image/svg+xml
https://bugs.webkit.org/show_bug.cgi?id=146509
Source/WebCore:

rdar://problem/21584740

Reviewed by Simon Fraser.

For some strange reason MaskImageOperation code loads all mask images, including non-SVG ones
using CachedSVGDocument. Resulting bad accept header may cause server to reject the request.

This is far from ideal but as a quick fix we can override the accept header for mask images to
allow any image type.

Test: http/tests/misc/mask-image-accept.html

* loader/cache/CachedResourceLoader.cpp:
(WebCore::CachedResourceLoader::requestResource):
* loader/cache/CachedResourceRequest.h:
(WebCore::CachedResourceRequest::acceptOverride):
(WebCore::CachedResourceRequest::setAcceptOverride):
* loader/cache/CachedSVGDocumentReference.cpp:
(WebCore::CachedSVGDocumentReference::load):
* loader/cache/CachedSVGDocumentReference.h:
(WebCore::CachedSVGDocumentReference::loadRequested):
(WebCore::CachedSVGDocumentReference::setAcceptsAnyImageType):
(WebCore::CachedSVGDocumentReference::document):
* platform/graphics/MaskImageOperation.cpp:
(WebCore::MaskImageOperation::ensureCachedSVGDocumentReference):

LayoutTests:


Reviewed by Simon Fraser.

* http/tests/misc/mask-image-accept-expected.html: Added.
* http/tests/misc/mask-image-accept.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (186179 => 186180)


--- trunk/LayoutTests/ChangeLog	2015-07-01 17:13:04 UTC (rev 186179)
+++ trunk/LayoutTests/ChangeLog	2015-07-01 17:22:27 UTC (rev 186180)
@@ -1,3 +1,13 @@
+2015-07-01  Antti Koivisto  <an...@apple.com>
+
+        PNG mask images are loaded with Accept:image/svg+xml
+        https://bugs.webkit.org/show_bug.cgi?id=146509
+
+        Reviewed by Simon Fraser.
+
+        * http/tests/misc/mask-image-accept-expected.html: Added.
+        * http/tests/misc/mask-image-accept.html: Added.
+
 2015-07-01  Jer Noble  <jer.no...@apple.com>
 
         [MSE] Failures on W3C media-source tests regarding MIME types

Added: trunk/LayoutTests/http/tests/misc/mask-image-accept-expected.html (0 => 186180)


--- trunk/LayoutTests/http/tests/misc/mask-image-accept-expected.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/misc/mask-image-accept-expected.html	2015-07-01 17:22:27 UTC (rev 186180)
@@ -0,0 +1,10 @@
+<html>
+<head>
+<style>
+#test { width:100px; height:100px; background-color: green;}
+</style>
+</head>
+<body>
+<div id="test"></div>
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/misc/mask-image-accept.html (0 => 186180)


--- trunk/LayoutTests/http/tests/misc/mask-image-accept.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/misc/mask-image-accept.html	2015-07-01 17:22:27 UTC (rev 186180)
@@ -0,0 +1,10 @@
+<html>
+<head>
+<style>
+#test { -webkit-mask-image: url(resources/image-checks-for-accept.php); width:100px; height:100px; background-color: green;}
+</style>
+</head>
+<body>
+<div id="test"></div>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (186179 => 186180)


--- trunk/Source/WebCore/ChangeLog	2015-07-01 17:13:04 UTC (rev 186179)
+++ trunk/Source/WebCore/ChangeLog	2015-07-01 17:22:27 UTC (rev 186180)
@@ -1,3 +1,33 @@
+2015-07-01  Antti Koivisto  <an...@apple.com>
+
+        PNG mask images are loaded with Accept:image/svg+xml
+        https://bugs.webkit.org/show_bug.cgi?id=146509
+        rdar://problem/21584740
+
+        Reviewed by Simon Fraser.
+
+        For some strange reason MaskImageOperation code loads all mask images, including non-SVG ones
+        using CachedSVGDocument. Resulting bad accept header may cause server to reject the request.
+
+        This is far from ideal but as a quick fix we can override the accept header for mask images to
+        allow any image type.
+
+        Test: http/tests/misc/mask-image-accept.html
+
+        * loader/cache/CachedResourceLoader.cpp:
+        (WebCore::CachedResourceLoader::requestResource):
+        * loader/cache/CachedResourceRequest.h:
+        (WebCore::CachedResourceRequest::acceptOverride):
+        (WebCore::CachedResourceRequest::setAcceptOverride):
+        * loader/cache/CachedSVGDocumentReference.cpp:
+        (WebCore::CachedSVGDocumentReference::load):
+        * loader/cache/CachedSVGDocumentReference.h:
+        (WebCore::CachedSVGDocumentReference::loadRequested):
+        (WebCore::CachedSVGDocumentReference::setAcceptsAnyImageType):
+        (WebCore::CachedSVGDocumentReference::document):
+        * platform/graphics/MaskImageOperation.cpp:
+        (WebCore::MaskImageOperation::ensureCachedSVGDocumentReference):
+
 2015-07-01  Jer Noble  <jer.no...@apple.com>
 
         [MSE] Failures on W3C media-source tests regarding MIME types

Modified: trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp (186179 => 186180)


--- trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2015-07-01 17:13:04 UTC (rev 186179)
+++ trunk/Source/WebCore/loader/cache/CachedResourceLoader.cpp	2015-07-01 17:22:27 UTC (rev 186180)
@@ -565,6 +565,9 @@
         resource->setLoadPriority(request.priority());
 
     if ((policy != Use || resource->stillNeedsLoad()) && CachedResourceRequest::NoDefer == request.defer()) {
+        if (request.acceptOverride())
+            resource->setAccept(request.acceptOverride().value());
+
         resource->load(*this, request.options());
 
         // We don't support immediate loads, but we do support immediate failure.

Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.h (186179 => 186180)


--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.h	2015-07-01 17:13:04 UTC (rev 186179)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.h	2015-07-01 17:22:27 UTC (rev 186180)
@@ -53,12 +53,14 @@
     const ResourceLoaderOptions& options() const { return m_options; }
     void setOptions(const ResourceLoaderOptions& options) { m_options = options; }
     const Optional<ResourceLoadPriority>& priority() const { return m_priority; }
+    const Optional<String>& acceptOverride() const { return m_acceptOverride; }
     bool forPreload() const { return m_forPreload; }
     void setForPreload(bool forPreload) { m_forPreload = forPreload; }
     DeferOption defer() const { return m_defer; }
     void setDefer(DeferOption defer) { m_defer = defer; }
     void setInitiator(PassRefPtr<Element>);
     void setInitiator(const AtomicString& name);
+    void setAcceptOverride(const String& accept) { m_acceptOverride = accept; }
     const AtomicString& initiatorName() const;
 
     void setInitiator(DocumentLoader&);
@@ -69,6 +71,7 @@
     String m_charset;
     ResourceLoaderOptions m_options;
     Optional<ResourceLoadPriority> m_priority;
+    Optional<String> m_acceptOverride;
     bool m_forPreload;
     DeferOption m_defer;
     RefPtr<Element> m_initiatorElement;

Modified: trunk/Source/WebCore/loader/cache/CachedSVGDocumentReference.cpp (186179 => 186180)


--- trunk/Source/WebCore/loader/cache/CachedSVGDocumentReference.cpp	2015-07-01 17:13:04 UTC (rev 186179)
+++ trunk/Source/WebCore/loader/cache/CachedSVGDocumentReference.cpp	2015-07-01 17:22:27 UTC (rev 186180)
@@ -60,6 +60,8 @@
 
     CachedResourceRequest request(ResourceRequest(loader.document()->completeURL(m_url)));
     request.setInitiator(cachedResourceRequestInitiators().css);
+    if (m_acceptsAnyImageType)
+        request.setAcceptOverride("image/*");
     m_document = loader.requestSVGDocument(request);
     if (m_document) {
         m_document->setCanReuse(m_canReuseResource);

Modified: trunk/Source/WebCore/loader/cache/CachedSVGDocumentReference.h (186179 => 186180)


--- trunk/Source/WebCore/loader/cache/CachedSVGDocumentReference.h	2015-07-01 17:13:04 UTC (rev 186179)
+++ trunk/Source/WebCore/loader/cache/CachedSVGDocumentReference.h	2015-07-01 17:22:27 UTC (rev 186180)
@@ -43,6 +43,7 @@
 
     void load(CachedResourceLoader&);
     bool loadRequested() const { return m_loadRequested; }
+    void setAcceptsAnyImageType() { m_acceptsAnyImageType = true; }
 
     CachedSVGDocument* document() { return m_document.get(); }
 
@@ -52,6 +53,7 @@
     bool m_loadRequested;
     CachedSVGDocumentClient* m_additionalDocumentClient;
     bool m_canReuseResource;
+    bool m_acceptsAnyImageType { false };
 };
 
 };

Modified: trunk/Source/WebCore/platform/graphics/MaskImageOperation.cpp (186179 => 186180)


--- trunk/Source/WebCore/platform/graphics/MaskImageOperation.cpp	2015-07-01 17:13:04 UTC (rev 186179)
+++ trunk/Source/WebCore/platform/graphics/MaskImageOperation.cpp	2015-07-01 17:22:27 UTC (rev 186180)
@@ -193,8 +193,12 @@
     if (image())
         return nullptr;
 
-    if (!m_cachedSVGDocumentReference.get())
+    if (!m_cachedSVGDocumentReference.get()) {
         m_cachedSVGDocumentReference = std::make_unique<CachedSVGDocumentReference>(m_url, this, false);
+        // FIXME: For some strange reason we load all mask resources using CachedSVGDocument.
+        //        This requires overriding SVG mime type in Accept header or server may reject the request.
+        m_cachedSVGDocumentReference->setAcceptsAnyImageType();
+    }
     return m_cachedSVGDocumentReference.get();
 }
 
@@ -219,9 +223,10 @@
             }
         }
     }
-    
+
     // If no valid mask was found, this is not a valid SVG document or it specified an invalid fragment identifier.
     // Fallback to the normal way of loading the document in an Image object.
+    // FIXME: This is silly.
     if (!validMaskFound) {
         // Get the resource loader, acquire the resource buffer and load it into an image.
         ASSERT(cachedSVGDocument->loader());
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to