Skip to content

Commit

Permalink
Cherry-pick 261131@main (151a757). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=253046

    Image types enabled by additionalSupportedImageTypes do not show up in the Accept: header
    https://bugs.webkit.org/show_bug.cgi?id=253046
    rdar://106006530

    Reviewed by Said Abou-Hallawa.

    We can simply augment the Accept: header with the mime types of these image formats.

    * LayoutTests/http/tests/misc/heic-accept-header-expected.txt: Added.
    * LayoutTests/http/tests/misc/heic-accept-header.html: Added.
    * LayoutTests/http/tests/misc/resources/image-heic-accept.py: Added.
    * Source/WebCore/loader/cache/CachedResourceRequest.cpp:
    (WebCore::acceptHeaderValueForAdditionalSupportedImageMIMETypes):
    (WebCore::acceptHeaderValueForImageResource):

    Canonical link: https://commits.webkit.org/261131@main
  • Loading branch information
litherum authored and aperezdc committed Apr 1, 2023
1 parent 564e5b8 commit 1cb47f5
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions LayoutTests/TestExpectations
Expand Up @@ -6276,3 +6276,6 @@ webkit.org/b/252183 imported/w3c/web-platform-tests/css/css-box/margin-trim/bloc
imported/w3c/web-platform-tests/css/css-text/text-spacing/tentative/parsing/text-spacing-computed.html [ Skip ]
imported/w3c/web-platform-tests/css/css-text/text-spacing/tentative/parsing/text-spacing-invalid.html [ Skip ]
imported/w3c/web-platform-tests/css/css-text/text-spacing/tentative/parsing/text-spacing-valid.html [ Skip ]

# Most ports don't have a HEIC decoder.
http/tests/misc/heic-accept-header.html [ Pass Failure ]
3 changes: 3 additions & 0 deletions LayoutTests/http/tests/misc/heic-accept-header-expected.txt
@@ -0,0 +1,3 @@
Tests that HEIC is sent in the accept header if it's enabled.

PASS
29 changes: 29 additions & 0 deletions LayoutTests/http/tests/misc/heic-accept-header.html
@@ -0,0 +1,29 @@
<!DOCTYPE html><!-- webkit-test-runner [ additionalSupportedImageTypes=public.heic;public.heics ] -->
<html>
<head>
<script>
if (window.testRunner) {
testRunner.dumpAsText()
testRunner.waitUntilDone();
}

function test() {
var image = document.getElementById("testImage");
var result = document.getElementById("result");

if (image.width == 400 && image.height == 400)
result.innerHTML = "PASS";
else
result.innerHTML = "FAIL";

if (window.testRunner)
testRunner.notifyDone();
}
</script>
</head>
<body>
Tests that HEIC is sent in the accept header if it's enabled.<br>
<img id="testImage" src="resources/image-heic-accept.py" onload="test()" onerror="test()"/>
<div id="result"/>
</body>
</html>
Binary file not shown.
27 changes: 27 additions & 0 deletions LayoutTests/http/tests/misc/resources/image-heic-accept.py
@@ -0,0 +1,27 @@
#!/usr/bin/env python3

import os
import sys

http_accept = os.environ.get('HTTP_ACCEPT', '')

if 'image/heic' in http_accept:
sys.stdout.write(
'Content-Type: image/heic\r\n'
'Cache-Control: no-store\r\n'
'Connection: close\r\n\r\n'
)

sys.stdout.flush()
with open(os.path.join(os.path.dirname(__file__), 'green-400x400.heic'), 'rb') as fn:
sys.stdout.buffer.write(fn.read())
else:
sys.stdout.write(
'Content-Type: image/jpg\r\n'
'Cache-Control: no-store\r\n'
'Connection: close\r\n\r\n'
)

sys.stdout.flush()
with open(os.path.join(os.path.dirname(__file__), 'compass.jpg'), 'rb') as fn:
sys.stdout.buffer.write(fn.read())
2 changes: 2 additions & 0 deletions LayoutTests/platform/ios/TestExpectations
Expand Up @@ -4228,3 +4228,5 @@ webkit.org/b/252317 imported/w3c/web-platform-tests/css/css-counter-styles/devan
webkit.org/b/252504 http/tests/site-isolation/basic-iframe.html [ Pass ImageOnlyFailure ]

http/wpt/service-workers/basic-fetch-with-contentfilter.https.html [ Pass ]

http/tests/misc/heic-accept-header.html [ Pass ]
2 changes: 2 additions & 0 deletions LayoutTests/platform/mac/TestExpectations
Expand Up @@ -2801,3 +2801,5 @@ webkit.org/b/251710 webaudio/AudioBuffer/huge-buffer.html [ Pass Timeout ]
[ Ventura+ ] fast/images/image-overlay-mutiple-frames.html [ Pass ImageOnlyFailure ]

http/wpt/service-workers/basic-fetch-with-contentfilter.https.html [ Pass ]

http/tests/misc/heic-accept-header.html [ Pass ]
11 changes: 11 additions & 0 deletions Source/WebCore/loader/cache/CachedResourceRequest.cpp
Expand Up @@ -35,10 +35,12 @@
#include "FrameLoader.h"
#include "HTTPHeaderValues.h"
#include "ImageDecoder.h"
#include "MIMETypeRegistry.h"
#include "MemoryCache.h"
#include "SecurityPolicy.h"
#include "ServiceWorkerRegistrationData.h"
#include <wtf/NeverDestroyed.h>
#include <wtf/text/StringBuilder.h>

namespace WebCore {

Expand Down Expand Up @@ -141,6 +143,14 @@ static constexpr ASCIILiteral acceptHeaderValueForAVIFImageResource()
#endif
}

static String acceptHeaderValueForAdditionalSupportedImageMIMETypes()
{
StringBuilder sb;
for (const auto& additionalSupportedImageMIMEType : MIMETypeRegistry::additionalSupportedImageMIMETypes())
sb.append(makeString(additionalSupportedImageMIMEType, ','));
return sb.toString();
}

static constexpr ASCIILiteral acceptHeaderValueForVideoImageResource(bool supportsVideoImage)
{
if (supportsVideoImage)
Expand All @@ -152,6 +162,7 @@ static String acceptHeaderValueForImageResource()
{
return String(acceptHeaderValueForWebPImageResource())
+ acceptHeaderValueForAVIFImageResource()
+ acceptHeaderValueForAdditionalSupportedImageMIMETypes()
+ acceptHeaderValueForVideoImageResource(ImageDecoder::supportsMediaType(ImageDecoder::MediaType::Video))
+ "image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5"_s;
}
Expand Down

0 comments on commit 1cb47f5

Please sign in to comment.