MIMETypeRegistry.h [plain text]
#pragma once
#include <wtf/HashSet.h>
#include <wtf/Vector.h>
#include <wtf/text/StringHash.h>
namespace WebCore {
struct TypeExtensionPair {
ASCIILiteral type;
ASCIILiteral extension;
};
WEBCORE_EXPORT const std::initializer_list<TypeExtensionPair>& commonMediaTypes();
struct MIMETypeRegistryThreadGlobalData {
WTF_MAKE_NONCOPYABLE(MIMETypeRegistryThreadGlobalData);
WTF_MAKE_FAST_ALLOCATED;
public:
MIMETypeRegistryThreadGlobalData(HashSet<String, ASCIICaseInsensitiveHash>&& supportedImageMIMETypesForEncoding)
: m_supportedImageMIMETypesForEncoding(supportedImageMIMETypesForEncoding)
{ }
const HashSet<String, ASCIICaseInsensitiveHash>& supportedImageMIMETypesForEncoding() const { return m_supportedImageMIMETypesForEncoding; }
private:
HashSet<String, ASCIICaseInsensitiveHash> m_supportedImageMIMETypesForEncoding;
};
class MIMETypeRegistry {
public:
WEBCORE_EXPORT static String mimeTypeForExtension(const String& extension);
WEBCORE_EXPORT static Vector<String> extensionsForMIMEType(const String& type);
WEBCORE_EXPORT static String preferredExtensionForMIMEType(const String& type);
WEBCORE_EXPORT static String mediaMIMETypeForExtension(const String& extension);
WEBCORE_EXPORT static String mimeTypeForPath(const String& path);
static std::unique_ptr<MIMETypeRegistryThreadGlobalData> createMIMETypeRegistryThreadGlobalData();
WEBCORE_EXPORT static bool isSupportedImageMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isSupportedImageVideoOrSVGMIMEType(const String& mimeType);
static bool isSupportedImageMIMETypeForEncoding(const String& mimeType);
WEBCORE_EXPORT static bool isSupportedJavaScriptMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isSupportedJSONMIMEType(const String& mimeType);
static bool isSupportedStyleSheetMIMEType(const String& mimeType);
static bool isSupportedFontMIMEType(const String& mimeType);
static bool isTextMediaPlaylistMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isSupportedNonImageMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isSupportedMediaMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isSupportedTextTrackMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isJavaAppletMIMEType(const String& mimeType);
static bool isApplicationPluginMIMEType(const String& mimeType);
static bool isPDFMIMEType(const String& mimeType);
static bool isPostScriptMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isPDFOrPostScriptMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isSystemPreviewMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool canShowMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isXMLMIMEType(const String& mimeType);
WEBCORE_EXPORT static bool isXMLEntityMIMEType(StringView mimeType);
WEBCORE_EXPORT static bool isTextMIMEType(const String& mimeType);
WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& supportedImageMIMETypes();
static HashSet<String, ASCIICaseInsensitiveHash>& additionalSupportedImageMIMETypes();
WEBCORE_EXPORT static HashSet<String, ASCIICaseInsensitiveHash>& supportedNonImageMIMETypes();
WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& supportedMediaMIMETypes();
WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& pdfMIMETypes();
WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& unsupportedTextMIMETypes();
WEBCORE_EXPORT static const HashSet<String, ASCIICaseInsensitiveHash>& systemPreviewMIMETypes();
static String normalizedMIMEType(const String&);
WEBCORE_EXPORT static String appendFileExtensionIfNecessary(const String& filename, const String& mimeType);
WEBCORE_EXPORT static String preferredImageMIMETypeForEncoding(const Vector<String>& mimeTypes, const Vector<String>& extensions);
WEBCORE_EXPORT static bool containsImageMIMETypeForEncoding(const Vector<String>& mimeTypes, const Vector<String>& extensions);
WEBCORE_EXPORT static Vector<String> allowedMIMETypes(const Vector<String>& mimeTypes, const Vector<String>& extensions);
WEBCORE_EXPORT static Vector<String> allowedFileExtensions(const Vector<String>& mimeTypes, const Vector<String>& extensions);
private:
static bool isUnsupportedTextMIMEType(const String& mimeType);
};
WEBCORE_EXPORT const String& defaultMIMEType();
}