Skip to content

Commit

Permalink
[visionOS] Refine MIME Type detection for Image Fullscreen
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=271321
<rdar://125023525>

Reviewed by Mike Wyrzykowski.

Fall back to generating a MIME Type based on the file extension if the
server-sent MIME Type is not a supported image type.
Bail out of the Quick Look path is this doesn't work either.

* Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.cpp:
(WebKit::WebFullScreenManager::enterFullScreenForElement):

Canonical link: https://commits.webkit.org/276436@main
  • Loading branch information
etiennesegonzac committed Mar 21, 2024
1 parent 1d87ffb commit 45c98e3
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions Source/WebKit/WebProcess/FullScreen/WebFullScreenManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <WebCore/JSDOMPromiseDeferred.h>
#include <WebCore/LocalFrame.h>
#include <WebCore/LocalFrameView.h>
#include <WebCore/MIMETypeRegistry.h>
#include <WebCore/Quirks.h>
#include <WebCore/RenderImage.h>
#include <WebCore/RenderLayerBacking.h>
Expand Down Expand Up @@ -243,20 +244,23 @@ void WebFullScreenManager::enterFullScreenForElement(WebCore::Element* element,
return sharedMemoryBuffer->createHandle(SharedMemory::Protection::ReadOnly);
};

auto getImageMIMEType = [&]() -> String {
if (auto* cachedImage = renderImage->cachedImage()) {
if (auto* image = cachedImage->image())
return image->mimeType();
}
return emptyString();
};
auto mimeType = emptyString();
if (auto* cachedImage = renderImage->cachedImage()) {
if (auto* image = cachedImage->image())
mimeType = image->mimeType();

mediaDetails = {
FullScreenMediaDetails::Type::Image,
{ },
getImageMIMEType(),
getImageResourceHandle()
};
if (!MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
mimeType = MIMETypeRegistry::mimeTypeForPath(cachedImage->url().string());
}

if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType)) {
mediaDetails = {
FullScreenMediaDetails::Type::Image,
{ },
mimeType,
getImageResourceHandle()
};
}
}
#endif

Expand Down

0 comments on commit 45c98e3

Please sign in to comment.