Changeset 225472 in webkit


Ignore:
Timestamp:
Dec 4, 2017 12:49:26 AM (6 years ago)
Author:
jer.noble@apple.com
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.
Location:
trunk
Files:
7 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r225467 r225472  
     12017-12-04  Jer Noble  <jer.noble@apple.com>
     2
     3        Include 'video/*' in image request Accept header if browser supports video media in image contexts.
     4        https://bugs.webkit.org/show_bug.cgi?id=179178
     5
     6        Reviewed by Alex Christensen.
     7
     8        * http/tests/images/image-supports-video-expected.txt: Added.
     9        * http/tests/images/image-supports-video.html: Added.
     10        * http/tests/misc/resources/image-checks-for-accept.php:
     11        * http/tests/resources/redirect-to-video-if-accepted.php: Added.
     12        * platform/ios/TestExpectations:
     13        * platform/mac/imported/w3c/web-platform-tests/html/semantics/the-img-element/update-the-source-set-expected.txt: Added.
     14
    1152017-12-03  Chris Dumez  <cdumez@apple.com>
    216
  • trunk/LayoutTests/http/tests/misc/resources/image-checks-for-accept.php

    r206206 r225472  
    11<?php
    2     if($_SERVER["HTTP_ACCEPT"] == "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5")
     2    if($_SERVER["HTTP_ACCEPT"] == "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"
     3        || $_SERVER["HTTP_ACCEPT"] == "image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5")
    34    {
    45        header("Content-Type: image/jpg");
  • trunk/LayoutTests/platform/ios/TestExpectations

    r225426 r225472  
    33033303# Skip WebGL while the ANGLE update has caused many failures
    33043304webgl [ Skip ]
     3305
     3306# Requries AVFoundation support <rdar://problem/34502208>
     3307http/tests/images/image-supports-video.html
  • trunk/Source/WebCore/ChangeLog

    r225470 r225472  
     12017-12-04  Jer Noble  <jer.noble@apple.com>
     2
     3        Include 'video/*' in image request Accept header if browser supports video media in image contexts.
     4        https://bugs.webkit.org/show_bug.cgi?id=179178
     5
     6        Reviewed by Alex Christensen.
     7
     8        Test: http/tests/images/image-supports-video.html
     9
     10        Ensure that 'video/*' is included in the Accept header by asking the ImageDecoder whether "Video"
     11        media is supported. The ImageDecoder will ask all it's constituent decoders, which aside from
     12        ImageDecoderAVFObjC will say only support the "Image" media type.
     13
     14        Drive-by fix: Make sure the MIMETypeRegistry includes all the types supported by AVFoundation when
     15        ImageDecoderAVFObjC is enabled. Also, now that Image reports it can support video mime types, check
     16        whether MediaDocument can support a given mime type before asking ImageDocument.
     17
     18        * html/HTMLImageElement.cpp:
     19        (WebCore::HTMLImageElement::bestFitSourceFromPictureElement):
     20        * loader/LinkLoader.cpp:
     21        (WebCore::LinkLoader::isSupportedType):
     22        * loader/cache/CachedResourceRequest.cpp:
     23        (WebCore::acceptHeaderValueFromType):
     24        * platform/MIMETypeRegistry.cpp:
     25        (WebCore::MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType):
     26        (WebCore::MIMETypeRegistry::isSupportedImageOrSVGMIMEType): Deleted.
     27        * platform/MIMETypeRegistry.h:
     28        * platform/graphics/ImageDecoder.cpp:
     29        (WebCore::ImageDecoder::supportsMediaType):
     30        * platform/graphics/ImageDecoder.h:
     31        * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h:
     32        (WebCore::ImageDecoderAVFObjC::supportsMediaType):
     33        * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm:
     34        (WebCore::ImageDecoderAVFObjC::supportsContentType):
     35        * platform/graphics/cg/ImageDecoderCG.h:
     36        * platform/graphics/win/ImageDecoderDirect2D.h:
     37        * platform/image-decoders/ScalableImageDecoder.h:
     38        (WebCore::ScalableImageDecoder::supportsMediaType):
     39        * html/parser/HTMLPreloadScanner.cpp:
     40        (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute):
     41
    1422017-12-03  Yusuke Suzuki  <utatane.tea@gmail.com>
    243
  • trunk/Source/WebCore/html/HTMLImageElement.cpp

    r224390 r225472  
    164164            type.truncate(type.find(';'));
    165165            type = stripLeadingAndTrailingHTMLSpaces(type);
    166             if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageOrSVGMIMEType(type))
     166            if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(type))
    167167                continue;
    168168        }
  • trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp

    r224928 r225472  
    224224                // when multiple type attributes present: first value wins, ignore subsequent (to match ImageElement parser and Blink behaviours)
    225225                m_typeAttribute = attributeValue;
    226                 m_typeMatched &= MIMETypeRegistry::isSupportedImageOrSVGMIMEType(m_typeAttribute);
     226                m_typeMatched &= MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(m_typeAttribute);
    227227            }
    228228            break;
  • trunk/Source/WebCore/loader/LinkLoader.cpp

    r222673 r225472  
    182182    switch (resourceType) {
    183183    case CachedResource::ImageResource:
    184         return MIMETypeRegistry::isSupportedImageOrSVGMIMEType(mimeType);
     184        return MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(mimeType);
    185185    case CachedResource::Script:
    186186        return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType);
  • trunk/Source/WebCore/loader/cache/CachedResourceRequest.cpp

    r225294 r225472  
    3434#include "FrameLoader.h"
    3535#include "HTTPHeaderValues.h"
     36#include "ImageDecoder.h"
    3637#include "MemoryCache.h"
    3738#include "SecurityPolicy.h"
     
    146147        return ASCIILiteral("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
    147148    case CachedResource::Type::ImageResource:
     149        if (ImageDecoder::supportsMediaType(ImageDecoder::MediaType::Video))
     150            return ASCIILiteral("image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5");
    148151        return ASCIILiteral("image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5");
    149152    case CachedResource::Type::CSSStyleSheet:
  • trunk/Source/WebCore/platform/MIMETypeRegistry.cpp

    r225241 r225472  
    5454#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
    5555#include "ArchiveFactory.h"
     56#endif
     57
     58#if HAVE(AVSAMPLEBUFFERGENERATOR)
     59#include "ContentType.h"
     60#include "ImageDecoderAVFObjC.h"
    5661#endif
    5762
     
    451456}
    452457
    453 bool MIMETypeRegistry::isSupportedImageOrSVGMIMEType(const String& mimeType)
    454 {
    455     return isSupportedImageMIMEType(mimeType) || equalLettersIgnoringASCIICase(mimeType, "image/svg+xml");
     458bool MIMETypeRegistry::isSupportedImageVideoOrSVGMIMEType(const String& mimeType)
     459{
     460    if (isSupportedImageMIMEType(mimeType) || equalLettersIgnoringASCIICase(mimeType, "image/svg+xml"))
     461        return true;
     462
     463#if HAVE(AVSAMPLEBUFFERGENERATOR)
     464    if (ImageDecoderAVFObjC::supportsContentType(ContentType(mimeType)))
     465        return true;
     466#endif
     467
     468    return false;
    456469}
    457470
  • trunk/Source/WebCore/platform/MIMETypeRegistry.h

    r225241 r225472  
    4848    WEBCORE_EXPORT static bool isSupportedImageMIMEType(const String& mimeType);
    4949
    50     // Check to see if a MIME type is suitable for being loaded as an image, including SVG.
    51     WEBCORE_EXPORT static bool isSupportedImageOrSVGMIMEType(const String& mimeType);
     50    // Check to see if a MIME type is suitable for being loaded as an image, including SVG and Video (where supported).
     51    WEBCORE_EXPORT static bool isSupportedImageVideoOrSVGMIMEType(const String& mimeType);
    5252
    5353    // Check to see if a MIME type is suitable for being loaded as an image
  • trunk/Source/WebCore/platform/graphics/ImageDecoder.cpp

    r222225 r225472  
    5959}
    6060
     61bool ImageDecoder::supportsMediaType(MediaType type)
     62{
     63    bool supports = false;
     64#if HAVE(AVSAMPLEBUFFERGENERATOR)
     65    if (ImageDecoderAVFObjC::supportsMediaType(type))
     66        supports = true;
     67#endif
     68
     69#if USE(CG)
     70    if (ImageDecoderCG::supportsMediaType(type))
     71        supports = true;
     72#elif USE(DIRECT2D)
     73    if (ImageDecoderDirect2D::supportsMediaType(type))
     74        supports = true;
     75#else
     76    if (ScalableImageDecoder::supportsMediaType(type))
     77        supports = true;
     78#endif
     79
     80    return supports;
    6181}
     82
     83}
  • trunk/Source/WebCore/platform/graphics/ImageDecoder.h

    r222225 r225472  
    4747    virtual ~ImageDecoder() = default;
    4848
     49    enum class MediaType {
     50        Image,
     51        Video,
     52    };
     53    static bool supportsMediaType(MediaType);
     54
    4955    virtual size_t bytesDecodedToDetermineProperties() const = 0;
    5056
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.h

    r223452 r225472  
    4949namespace WebCore {
    5050
     51class ContentType;
    5152class PixelBufferConformerCV;
    5253class WebCoreDecompressionSession;
     
    5657    static RefPtr<ImageDecoderAVFObjC> create(SharedBuffer&, const String& mimeType, AlphaOption, GammaAndColorProfileOption);
    5758    virtual ~ImageDecoderAVFObjC();
     59
     60    static bool supportsMediaType(MediaType);
     61    static bool supportsContentType(const ContentType&);
    5862
    5963    size_t bytesDecodedToDetermineProperties() const override { return 0; }
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm

    r224620 r225472  
    2929#if HAVE(AVSAMPLEBUFFERGENERATOR)
    3030
     31#import "AVFoundationMIMETypeCache.h"
    3132#import "AffineTransform.h"
     33#import "ContentType.h"
    3234#import "FloatQuad.h"
    3335#import "FloatRect.h"
     
    310312ImageDecoderAVFObjC::~ImageDecoderAVFObjC() = default;
    311313
     314bool ImageDecoderAVFObjC::supportsMediaType(MediaType type)
     315{
     316    if (type == MediaType::Video)
     317        return getAVURLAssetClass() && canLoad_VideoToolbox_VTCreateCGImageFromCVPixelBuffer();
     318    return false;
     319}
     320
     321bool ImageDecoderAVFObjC::supportsContentType(const ContentType& type)
     322{
     323    if (getAVURLAssetClass() && canLoad_VideoToolbox_VTCreateCGImageFromCVPixelBuffer())
     324        return AVFoundationMIMETypeCache::singleton().types().contains(type.containerType());
     325    return false;
     326}
     327
    312328bool ImageDecoderAVFObjC::canDecodeType(const String& mimeType)
    313329{
     330    if (!supportsMediaType(MediaType::Video))
     331        return nullptr;
     332
    314333    return [getAVURLAssetClass() isPlayableExtendedMIMEType:mimeType];
    315334}
  • trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h

    r222196 r225472  
    3939        return adoptRef(*new ImageDecoderCG(data, alphaOption, gammaAndColorProfileOption));
    4040    }
     41
     42    static bool supportsMediaType(MediaType type) { return type == MediaType::Image; }
    4143   
    4244    size_t bytesDecodedToDetermineProperties() const final;
  • trunk/Source/WebCore/platform/graphics/win/ImageDecoderDirect2D.h

    r222151 r225472  
    4848    }
    4949
     50    static bool supportsMediaType(MediaType type) { return type == MediaType::Image; }
     51
    5052    static size_t bytesDecodedToDetermineProperties();
    5153
  • trunk/Source/WebCore/platform/image-decoders/ScalableImageDecoder.h

    r225091 r225472  
    5757    }
    5858
     59    static bool supportsMediaType(MediaType type) { return type == MediaType::Image; }
     60
    5961    // Returns nullptr if we can't sniff a supported type from the provided data (possibly
    6062    // because there isn't enough data yet).
Note: See TracChangeset for help on using the changeset viewer.