Title: [225472] trunk
Revision
225472
Author
jer.no...@apple.com
Date
2017-12-04 00:49:26 -0800 (Mon, 04 Dec 2017)

Log Message

Include 'video/*' in image request Accept header if browser supports video media in image contexts.
https://bugs.webkit.org/show_bug.cgi?id=179178

Reviewed by Alex Christensen.

Source/WebCore:

Test: http/tests/images/image-supports-video.html

Ensure that 'video/*' is included in the Accept header by asking the ImageDecoder whether "Video"
media is supported. The ImageDecoder will ask all it's constituent decoders, which aside from
ImageDecoderAVFObjC will say only support the "Image" media type.

Drive-by fix: Make sure the MIMETypeRegistry includes all the types supported by AVFoundation when
ImageDecoderAVFObjC is enabled. Also, now that Image reports it can support video mime types, check
whether MediaDocument can support a given mime type before asking ImageDocument.

* html/HTMLImageElement.cpp:
(WebCore::HTMLImageElement::bestFitSourceFromPictureElement):
* loader/LinkLoader.cpp:
(WebCore::LinkLoader::isSupportedType):
* loader/cache/CachedResourceRequest.cpp:
(WebCore::acceptHeaderValueFromType):
* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType):
(WebCore::MIMETypeRegistry::isSupportedImageOrSVGMIMEType): Deleted.
* platform/MIMETypeRegistry.h:
* platform/graphics/ImageDecoder.cpp:
(WebCore::ImageDecoder::supportsMediaType):
* platform/graphics/ImageDecoder.h:
* platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h:
(WebCore::ImageDecoderAVFObjC::supportsMediaType):
* platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm:
(WebCore::ImageDecoderAVFObjC::supportsContentType):
* platform/graphics/cg/ImageDecoderCG.h:
* platform/graphics/win/ImageDecoderDirect2D.h:
* platform/image-decoders/ScalableImageDecoder.h:
(WebCore::ScalableImageDecoder::supportsMediaType):
* html/parser/HTMLPreloadScanner.cpp:
(WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):

LayoutTests:

* http/tests/images/image-supports-video-expected.txt: Added.
* http/tests/images/image-supports-video.html: Added.
* http/tests/misc/resources/image-checks-for-accept.php:
* http/tests/resources/redirect-to-video-if-accepted.php: Added.
* platform/ios/TestExpectations:
* platform/mac/imported/w3c/web-platform-tests/html/semantics/the-img-element/update-the-source-set-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225471 => 225472)


--- trunk/LayoutTests/ChangeLog	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/LayoutTests/ChangeLog	2017-12-04 08:49:26 UTC (rev 225472)
@@ -1,3 +1,17 @@
+2017-12-04  Jer Noble  <jer.no...@apple.com>
+
+        Include 'video/*' in image request Accept header if browser supports video media in image contexts.
+        https://bugs.webkit.org/show_bug.cgi?id=179178
+
+        Reviewed by Alex Christensen.
+
+        * http/tests/images/image-supports-video-expected.txt: Added.
+        * http/tests/images/image-supports-video.html: Added.
+        * http/tests/misc/resources/image-checks-for-accept.php:
+        * http/tests/resources/redirect-to-video-if-accepted.php: Added.
+        * platform/ios/TestExpectations:
+        * platform/mac/imported/w3c/web-platform-tests/html/semantics/the-img-element/update-the-source-set-expected.txt: Added.
+
 2017-12-03  Chris Dumez  <cdu...@apple.com>
 
         Re-sync Service Workers web-platform-tests from upstream

Added: trunk/LayoutTests/http/tests/images/image-supports-video-expected.txt (0 => 225472)


--- trunk/LayoutTests/http/tests/images/image-supports-video-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/images/image-supports-video-expected.txt	2017-12-04 08:49:26 UTC (rev 225472)
@@ -0,0 +1,2 @@
+  
+PASS: video source selected.

Added: trunk/LayoutTests/http/tests/images/image-supports-video.html (0 => 225472)


--- trunk/LayoutTests/http/tests/images/image-supports-video.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/images/image-supports-video.html	2017-12-04 08:49:26 UTC (rev 225472)
@@ -0,0 +1,36 @@
+<picture>
+    <source srcset="/resources/redirect-to-video-if-accepted.php?video=test.mp4" type="video/mp4">
+    <source srcset="/resources/redirect-to-video-if-accepted.php?video=test.ogv" type="video/ogv">
+    <img src=""
+</picture>
+<br>
+<script>
+if (window.testRunner) {
+    testRunner.dumpAsText(true);
+    testRunner.waitUntilDone();
+}
+
+function endTest() {
+    if (window.testRunner)
+        testRunner.notifyDone();
+}
+
+function logResult(text) {
+    document.body.appendChild(document.createTextNode(text));
+}
+
+var img = document.querySelector('img');
+img.addEventListener('load', event => {
+    if (img.currentSrc.endsWith('square100.png'))
+        logResult('FAIL: <img> fallback selected.');
+    else
+        logResult('PASS: video source selected.');
+
+    endTest();
+});
+
+img.addEventListener('error', event => {
+    logResult('FAIL: <img> threw error.');
+    endTest();
+});
+</script>

Modified: trunk/LayoutTests/http/tests/misc/resources/image-checks-for-accept.php (225471 => 225472)


--- trunk/LayoutTests/http/tests/misc/resources/image-checks-for-accept.php	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/LayoutTests/http/tests/misc/resources/image-checks-for-accept.php	2017-12-04 08:49:26 UTC (rev 225472)
@@ -1,5 +1,6 @@
 <?php
-    if($_SERVER["HTTP_ACCEPT"] == "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5")
+    if($_SERVER["HTTP_ACCEPT"] == "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"
+        || $_SERVER["HTTP_ACCEPT"] == "image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5")
     {
         header("Content-Type: image/jpg");
         header("Cache-Control: no-store");

Added: trunk/LayoutTests/http/tests/resources/redirect-to-video-if-accepted.php (0 => 225472)


--- trunk/LayoutTests/http/tests/resources/redirect-to-video-if-accepted.php	                        (rev 0)
+++ trunk/LayoutTests/http/tests/resources/redirect-to-video-if-accepted.php	2017-12-04 08:49:26 UTC (rev 225472)
@@ -0,0 +1,9 @@
+<?php
+if (strpos($_SERVER['HTTP_ACCEPT'], 'video/*') !== false) {
+    header('HTTP/1.1 301 Moved Permanently');
+    header('Location: ' . $_GET['video']);
+    return;
+}
+
+header('HTTP/1.1 400 Bad Request');
+?>

Modified: trunk/LayoutTests/platform/ios/TestExpectations (225471 => 225472)


--- trunk/LayoutTests/platform/ios/TestExpectations	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2017-12-04 08:49:26 UTC (rev 225472)
@@ -3302,3 +3302,6 @@
 
 # Skip WebGL while the ANGLE update has caused many failures
 webgl [ Skip ]
+
+# Requries AVFoundation support <rdar://problem/34502208>
+http/tests/images/image-supports-video.html

Added: trunk/LayoutTests/platform/mac/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/update-the-source-set-expected.txt (0 => 225472)


--- trunk/LayoutTests/platform/mac/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/update-the-source-set-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-img-element/update-the-source-set-expected.txt	2017-12-04 08:49:26 UTC (rev 225472)
@@ -0,0 +1,180 @@
+
+PASS <img data-expect=""> 
+FAIL <img src="" data-expect=""> assert_equals: expected "" but got "http://localhost:8800/html/semantics/embedded-content/the-img-element/update-the-source-set.html"
+PASS <img src="" data-expect="data:,a"> 
+PASS <img srcset="" src="" data-expect="data:,a"> 
+PASS <img srcset="data:,b" src="" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b" data-expect="data:,b"><!-- srcset after src --> 
+PASS <img src="" srcset="data:,b 1x" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b 1.0x" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b 1e0x" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b 10000w" sizes="1px" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b 10000w, data:,c 10000x" sizes="1px" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b 10000x, data:,c 10000w" sizes="1px" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b 1w" sizes="10000px" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b 1w, data:,c 0.0001x" sizes="10000px" data-expect="data:,b"> 
+PASS <img src="" srcset="data:,b 0.0001x, data:,c 1w" sizes="10000px" data-expect="data:,b"> 
+PASS <img srcset="data:,a" data-expect="data:,a"> 
+PASS <picture>foo<img src="" data-expect="data:,a"></picture> 
+PASS <picture><!--foo--><img src="" data-expect="data:,a"></picture> 
+PASS <picture><br><img src="" data-expect="data:,a"></picture> 
+PASS <picture><p></p><img src="" data-expect="data:,a"></picture> 
+PASS <picture><video><source srcset="data:,b"></video><img src="" data-expect="data:,a"></picture> 
+PASS <picture><span><source srcset="data:,b"></span><img src="" data-expect="data:,a"></picture> 
+PASS <picture><svg><source srcset="data:,b"></source></svg><img src="" data-expect="data:,a"></picture> 
+PASS <picture><svg></svg><source srcset="data:,b"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><svg><font></font><source srcset="data:,b"></source></svg><img src="" data-expect="data:,a"></picture> 
+PASS <picture><svg><!--<font face> tag breaks out of svg--></svg><font face=""></font><source srcset="data:,b"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><img src="" src="" data-expect="data:,b"></picture> 
+PASS <picture><source><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source src="" src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset=""><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset=", ,"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b 1x 1x"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" media=""><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" media="all"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" media="all and (min-width:0)"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" media="all and !"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" media="all and (!)"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" media="not all"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" media="not all and (min-width:0)"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" media="not all and (max-width:0)"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" media="not all and !"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" media="not all and (!)"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" media="all, !"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" media=","><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" media=", all"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type=""><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type=" "><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/gif"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type=" image/gif"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/gif "><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/gif;"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/gif;encodings"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/gif;encodings="><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/gif;encodings=foobar"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/png"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/jpeg"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/svg+xml"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="image/x-icon"><img src="" data-expect="data:,b"></picture> 
+PASS <picture><source srcset="data:,b" type="text/xml"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="text/html"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="text/plain"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="text/css"><img src="" data-expect="data:,a"></picture> 
+FAIL <picture><source srcset="data:,b" type="video/mp4"><img src="" data-expect="data:,a"></picture> assert_equals: expected "data:,a" but got "data:,b"
+PASS <picture><source srcset="data:,b" type="video/ogg"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="video/webm"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="unknown/unknown"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="application/octet-stream"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="application/x-shockwave-flash"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="image\gif"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="gif"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type=".gif"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="*"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="*/*"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="image/*"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type=","><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="image/gif, image/png"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="image/gif image/png"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><source srcset="data:,b" type="image/foobarbaz"><img src="" data-expect="data:,a"></picture> 
+PASS <picture><img src="" data-expect="data:,a">foo</picture> 
+PASS <picture><img src="" data-expect="data:,a"><br></picture> 
+PASS <picture><img src="" data-expect="data:,a"><!--foo--></picture> 
+PASS <picture><img src="" data-expect="data:,a"><img src="" 
+PASS <picture><img data-expect=""><img src="" 
+PASS <picture><img src="" data-expect="data:,a"><source srcset="data:,b"></picture> 
+PASS <picture><img data-expect=""><source srcset="data:,b"></picture> 
+PASS <picture><span><source srcset="data:,b"><img data-expect=""></span></picture> 
+PASS <picture><span><source srcset="data:,b"><img src="" data-expect="data:,a"></span></picture> 
+PASS <picture><source srcset="data:,b"><span><img src="" data-expect="data:,a"></span></picture> 
+PASS <picture><source srcset="data:,b"><img data-expect="data:,b"></picture> 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+foo
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+foo
+
+
+
+
+
+
+
+
+
+

Modified: trunk/Source/WebCore/ChangeLog (225471 => 225472)


--- trunk/Source/WebCore/ChangeLog	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/ChangeLog	2017-12-04 08:49:26 UTC (rev 225472)
@@ -1,3 +1,44 @@
+2017-12-04  Jer Noble  <jer.no...@apple.com>
+
+        Include 'video/*' in image request Accept header if browser supports video media in image contexts.
+        https://bugs.webkit.org/show_bug.cgi?id=179178
+
+        Reviewed by Alex Christensen.
+
+        Test: http/tests/images/image-supports-video.html
+
+        Ensure that 'video/*' is included in the Accept header by asking the ImageDecoder whether "Video"
+        media is supported. The ImageDecoder will ask all it's constituent decoders, which aside from
+        ImageDecoderAVFObjC will say only support the "Image" media type.
+
+        Drive-by fix: Make sure the MIMETypeRegistry includes all the types supported by AVFoundation when
+        ImageDecoderAVFObjC is enabled. Also, now that Image reports it can support video mime types, check
+        whether MediaDocument can support a given mime type before asking ImageDocument.
+
+        * html/HTMLImageElement.cpp:
+        (WebCore::HTMLImageElement::bestFitSourceFromPictureElement):
+        * loader/LinkLoader.cpp:
+        (WebCore::LinkLoader::isSupportedType):
+        * loader/cache/CachedResourceRequest.cpp:
+        (WebCore::acceptHeaderValueFromType):
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType):
+        (WebCore::MIMETypeRegistry::isSupportedImageOrSVGMIMEType): Deleted.
+        * platform/MIMETypeRegistry.h:
+        * platform/graphics/ImageDecoder.cpp:
+        (WebCore::ImageDecoder::supportsMediaType):
+        * platform/graphics/ImageDecoder.h:
+        * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h:
+        (WebCore::ImageDecoderAVFObjC::supportsMediaType):
+        * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm:
+        (WebCore::ImageDecoderAVFObjC::supportsContentType):
+        * platform/graphics/cg/ImageDecoderCG.h:
+        * platform/graphics/win/ImageDecoderDirect2D.h:
+        * platform/image-decoders/ScalableImageDecoder.h:
+        (WebCore::ScalableImageDecoder::supportsMediaType):
+        * html/parser/HTMLPreloadScanner.cpp:
+        (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
+
 2017-12-03  Yusuke Suzuki  <utatane....@gmail.com>
 
         WTF shouldn't have both Thread and ThreadIdentifier

Modified: trunk/Source/WebCore/html/HTMLImageElement.cpp (225471 => 225472)


--- trunk/Source/WebCore/html/HTMLImageElement.cpp	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/html/HTMLImageElement.cpp	2017-12-04 08:49:26 UTC (rev 225472)
@@ -163,7 +163,7 @@
             String type = typeAttribute.string();
             type.truncate(type.find(';'));
             type = stripLeadingAndTrailingHTMLSpaces(type);
-            if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageOrSVGMIMEType(type))
+            if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(type))
                 continue;
         }
 

Modified: trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp (225471 => 225472)


--- trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp	2017-12-04 08:49:26 UTC (rev 225472)
@@ -223,7 +223,7 @@
             if (match(attributeName, typeAttr) && m_typeAttribute.isNull()) {
                 // when multiple type attributes present: first value wins, ignore subsequent (to match ImageElement parser and Blink behaviours)
                 m_typeAttribute = attributeValue;
-                m_typeMatched &= MIMETypeRegistry::isSupportedImageOrSVGMIMEType(m_typeAttribute);
+                m_typeMatched &= MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(m_typeAttribute);
             }
             break;
         case TagId::Script:

Modified: trunk/Source/WebCore/loader/LinkLoader.cpp (225471 => 225472)


--- trunk/Source/WebCore/loader/LinkLoader.cpp	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/loader/LinkLoader.cpp	2017-12-04 08:49:26 UTC (rev 225472)
@@ -181,7 +181,7 @@
         return true;
     switch (resourceType) {
     case CachedResource::ImageResource:
-        return MIMETypeRegistry::isSupportedImageOrSVGMIMEType(mimeType);
+        return MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(mimeType);
     case CachedResource::Script:
         return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType);
     case CachedResource::CSSStyleSheet:

Modified: trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp (225471 => 225472)


--- trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp	2017-12-04 08:49:26 UTC (rev 225472)
@@ -33,6 +33,7 @@
 #include "Element.h"
 #include "FrameLoader.h"
 #include "HTTPHeaderValues.h"
+#include "ImageDecoder.h"
 #include "MemoryCache.h"
 #include "SecurityPolicy.h"
 #include <wtf/NeverDestroyed.h>
@@ -145,6 +146,8 @@
     case CachedResource::Type::MainResource:
         return ASCIILiteral("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
     case CachedResource::Type::ImageResource:
+        if (ImageDecoder::supportsMediaType(ImageDecoder::MediaType::Video))
+            return ASCIILiteral("image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5");
         return ASCIILiteral("image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5");
     case CachedResource::Type::CSSStyleSheet:
         return ASCIILiteral("text/css,*/*;q=0.1");

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (225471 => 225472)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp	2017-12-04 08:49:26 UTC (rev 225472)
@@ -55,6 +55,11 @@
 #include "ArchiveFactory.h"
 #endif
 
+#if HAVE(AVSAMPLEBUFFERGENERATOR)
+#include "ContentType.h"
+#include "ImageDecoderAVFObjC.h"
+#endif
+
 namespace WebCore {
 
 static HashSet<String, ASCIICaseInsensitiveHash>* supportedImageResourceMIMETypes;
@@ -450,9 +455,17 @@
     return supportedImageMIMETypes->contains(getNormalizedMIMEType(mimeType));
 }
 
-bool MIMETypeRegistry::isSupportedImageOrSVGMIMEType(const String& mimeType)
+bool MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(const String& mimeType)
 {
-    return isSupportedImageMIMEType(mimeType) || equalLettersIgnoringASCIICase(mimeType, "image/svg+xml");
+    if (isSupportedImageMIMEType(mimeType) || equalLettersIgnoringASCIICase(mimeType, "image/svg+xml"))
+        return true;
+
+#if HAVE(AVSAMPLEBUFFERGENERATOR)
+    if (ImageDecoderAVFObjC::supportsContentType(ContentType(mimeType)))
+        return true;
+#endif
+
+    return false;
 }
 
 bool MIMETypeRegistry::isSupportedImageResourceMIMEType(const String& mimeType)

Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.h (225471 => 225472)


--- trunk/Source/WebCore/platform/MIMETypeRegistry.h	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.h	2017-12-04 08:49:26 UTC (rev 225472)
@@ -47,8 +47,8 @@
     // image (e.g., <img> tags).
     WEBCORE_EXPORT static bool isSupportedImageMIMEType(const String& mimeType);
 
-    // Check to see if a MIME type is suitable for being loaded as an image, including SVG.
-    WEBCORE_EXPORT static bool isSupportedImageOrSVGMIMEType(const String& mimeType);
+    // Check to see if a MIME type is suitable for being loaded as an image, including SVG and Video (where supported).
+    WEBCORE_EXPORT static bool isSupportedImageVideoOrSVGMIMEType(const String& mimeType);
 
     // Check to see if a MIME type is suitable for being loaded as an image
     // document in a frame.

Modified: trunk/Source/WebCore/platform/graphics/ImageDecoder.cpp (225471 => 225472)


--- trunk/Source/WebCore/platform/graphics/ImageDecoder.cpp	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/graphics/ImageDecoder.cpp	2017-12-04 08:49:26 UTC (rev 225472)
@@ -58,4 +58,26 @@
 #endif
 }
 
+bool ImageDecoder::supportsMediaType(MediaType type)
+{
+    bool supports = false;
+#if HAVE(AVSAMPLEBUFFERGENERATOR)
+    if (ImageDecoderAVFObjC::supportsMediaType(type))
+        supports = true;
+#endif
+
+#if USE(CG)
+    if (ImageDecoderCG::supportsMediaType(type))
+        supports = true;
+#elif USE(DIRECT2D)
+    if (ImageDecoderDirect2D::supportsMediaType(type))
+        supports = true;
+#else
+    if (ScalableImageDecoder::supportsMediaType(type))
+        supports = true;
+#endif
+
+    return supports;
 }
+
+}

Modified: trunk/Source/WebCore/platform/graphics/ImageDecoder.h (225471 => 225472)


--- trunk/Source/WebCore/platform/graphics/ImageDecoder.h	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/graphics/ImageDecoder.h	2017-12-04 08:49:26 UTC (rev 225472)
@@ -46,6 +46,12 @@
     static RefPtr<ImageDecoder> create(SharedBuffer&, const String& mimeType, AlphaOption, GammaAndColorProfileOption);
     virtual ~ImageDecoder() = default;
 
+    enum class MediaType {
+        Image,
+        Video,
+    };
+    static bool supportsMediaType(MediaType);
+
     virtual size_t bytesDecodedToDetermineProperties() const = 0;
 
     virtual EncodedDataStatus encodedDataStatus() const = 0;

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h (225471 => 225472)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h	2017-12-04 08:49:26 UTC (rev 225472)
@@ -48,6 +48,7 @@
 
 namespace WebCore {
 
+class ContentType;
 class PixelBufferConformerCV;
 class WebCoreDecompressionSession;
 
@@ -56,6 +57,9 @@
     static RefPtr<ImageDecoderAVFObjC> create(SharedBuffer&, const String& mimeType, AlphaOption, GammaAndColorProfileOption);
     virtual ~ImageDecoderAVFObjC();
 
+    static bool supportsMediaType(MediaType);
+    static bool supportsContentType(const ContentType&);
+
     size_t bytesDecodedToDetermineProperties() const override { return 0; }
     static bool canDecodeType(const String& mimeType);
 

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm (225471 => 225472)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm	2017-12-04 08:49:26 UTC (rev 225472)
@@ -28,7 +28,9 @@
 
 #if HAVE(AVSAMPLEBUFFERGENERATOR)
 
+#import "AVFoundationMIMETypeCache.h"
 #import "AffineTransform.h"
+#import "ContentType.h"
 #import "FloatQuad.h"
 #import "FloatRect.h"
 #import "FloatSize.h"
@@ -309,8 +311,25 @@
 
 ImageDecoderAVFObjC::~ImageDecoderAVFObjC() = default;
 
+bool ImageDecoderAVFObjC::supportsMediaType(MediaType type)
+{
+    if (type == MediaType::Video)
+        return getAVURLAssetClass() && canLoad_VideoToolbox_VTCreateCGImageFromCVPixelBuffer();
+    return false;
+}
+
+bool ImageDecoderAVFObjC::supportsContentType(const ContentType& type)
+{
+    if (getAVURLAssetClass() && canLoad_VideoToolbox_VTCreateCGImageFromCVPixelBuffer())
+        return AVFoundationMIMETypeCache::singleton().types().contains(type.containerType());
+    return false;
+}
+
 bool ImageDecoderAVFObjC::canDecodeType(const String& mimeType)
 {
+    if (!supportsMediaType(MediaType::Video))
+        return nullptr;
+
     return [getAVURLAssetClass() isPlayableExtendedMIMEType:mimeType];
 }
 

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h (225471 => 225472)


--- trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h	2017-12-04 08:49:26 UTC (rev 225472)
@@ -38,6 +38,8 @@
     {
         return adoptRef(*new ImageDecoderCG(data, alphaOption, gammaAndColorProfileOption));
     }
+
+    static bool supportsMediaType(MediaType type) { return type == MediaType::Image; }
     
     size_t bytesDecodedToDetermineProperties() const final;
 

Modified: trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.h (225471 => 225472)


--- trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.h	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.h	2017-12-04 08:49:26 UTC (rev 225472)
@@ -47,6 +47,8 @@
         return adoptRef(*new ImageDecoderDirect2D());
     }
 
+    static bool supportsMediaType(MediaType type) { return type == MediaType::Image; }
+
     static size_t bytesDecodedToDetermineProperties();
 
     String filenameExtension() const final;

Modified: trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h (225471 => 225472)


--- trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h	2017-12-04 06:26:13 UTC (rev 225471)
+++ trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h	2017-12-04 08:49:26 UTC (rev 225472)
@@ -56,6 +56,8 @@
     {
     }
 
+    static bool supportsMediaType(MediaType type) { return type == MediaType::Image; }
+
     // Returns nullptr if we can't sniff a supported type from the provided data (possibly
     // because there isn't enough data yet).
     static RefPtr<ScalableImageDecoder> create(SharedBuffer& data, AlphaOption, GammaAndColorProfileOption);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to