#include "config.h"
#include "UTIRegistry.h"
#if USE(CG)
#include "ImageSourceCG.h"
#include "MIMETypeRegistry.h"
#include <wtf/HashSet.h>
#include <wtf/NeverDestroyed.h>
#include <ImageIO/ImageIO.h>
#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
#include "ArchiveFactory.h"
#endif
namespace WebCore {
const HashSet<String>& defaultSupportedImageTypes()
{
static NeverDestroyed<HashSet<String>> defaultSupportedImageTypes = std::initializer_list<String> {
"com.compuserve.gif",
"com.microsoft.bmp",
"com.microsoft.cur",
"com.microsoft.ico",
"public.jpeg",
"public.jpeg-2000",
"public.mpo-image",
"public.png",
"public.tiff",
};
#ifndef NDEBUG
static std::once_flag onceFlag;
std::call_once(onceFlag, [] {
RetainPtr<CFArrayRef> systemImageTypes = adoptCF(CGImageSourceCopyTypeIdentifiers());
CFIndex count = CFArrayGetCount(systemImageTypes.get());
for (auto& imageType : defaultSupportedImageTypes.get()) {
RetainPtr<CFStringRef> string = imageType.createCFString();
ASSERT(CFArrayContainsValue(systemImageTypes.get(), CFRangeMake(0, count), string.get()));
}
});
#endif
return defaultSupportedImageTypes;
}
HashSet<String>& additionalSupportedImageTypes()
{
static NeverDestroyed<HashSet<String>> additionalSupportedImageTypes;
return additionalSupportedImageTypes;
}
void setAdditionalSupportedImageTypes(const Vector<String>& imageTypes)
{
MIMETypeRegistry::additionalSupportedImageMIMETypes().clear();
for (const auto& imageType : imageTypes) {
additionalSupportedImageTypes().add(imageType);
auto mimeType = MIMETypeForImageType(imageType);
if (!mimeType.isEmpty())
MIMETypeRegistry::additionalSupportedImageMIMETypes().add(mimeType);
}
}
bool isSupportedImageType(const String& imageType)
{
if (imageType.isEmpty())
return false;
return defaultSupportedImageTypes().contains(imageType) || additionalSupportedImageTypes().contains(imageType);
}
}
#endif