MIMETypeRegistry.cpp [plain text]
#include "config.h"
#include "MIMETypeRegistry.h"
#include "MediaPlayer.h"
#include "StringHash.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#if PLATFORM(CG)
#endif
#if PLATFORM(MAC)
#include "WebCoreSystemInterface.h"
#endif
#if PLATFORM(QT)
#include <qimagereader.h>
#endif
namespace WebCore
{
static WTF::HashSet<String>* supportedImageResourceMIMETypes;
static WTF::HashSet<String>* supportedImageMIMETypes;
static WTF::HashSet<String>* supportedJavaScriptMIMETypes;
static WTF::HashSet<String>* supportedNonImageMIMETypes;
static WTF::HashSet<String>* supportedMediaMIMETypes;
static void initialiseSupportedImageMIMETypes()
{
static const char* types[] = {
"image/jpeg", "image/jpg", "image/jp_", "image/jpe_", "application/jpg", "application/x-jpg", "image/pjpeg", "image/pipeg", "image/vnd.switfview-jpeg", "image/x-xbitmap",
"image/gif", "image/x-xbitmap", "image/gi_",
"image/png", "application/png", "application/x-png",
"image/tif", "image/x-tif", "image/tiff", "image/x-tiff", "application/tif", "application/x-tif", "application/tiff", "application/x-tiff",
"image/bmp", "image/x-bmp", "image/x-bitmap", "image/x-win-bitmap", "image/x-windows-bmp", "image/ms-bmp", "image/x-ms-bmp", "application/bmp", "application/x-bmp", "application/x-win-bitmap",
};
for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); ++i) {
supportedImageMIMETypes->add(types[i]);
supportedImageResourceMIMETypes->add(types[i]);
}
}
static void initialiseSupportedJavaScriptMIMETypes()
{
static const char* types[] = {
"text/javascript",
"text/ecmascript",
"application/javascript",
"application/ecmascript",
"application/x-javascript",
"text/javascript1.1",
"text/javascript1.2",
"text/javascript1.3",
"text/jscript",
"text/livescript",
};
for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); ++i)
supportedJavaScriptMIMETypes->add(types[i]);
}
static void initialiseSupportedNonImageMimeTypes()
{
static const char* types[] = {
"text/html",
"text/xml",
"text/xsl",
"text/plain",
"text/",
"application/xml",
"application/xhtml+xml",
#if PLATFORM(MAC)
"application/x-webarchive",
#endif
"multipart/x-mixed-replace"
#if ENABLE(SVG)
, "image/svg+xml"
#endif
#if ENABLE(FTPDIR)
, "application/x-ftp-directory"
#endif
};
for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); ++i)
supportedNonImageMIMETypes->add(types[i]);
}
static void initialiseSupportedMediaMIMETypes()
{
supportedMediaMIMETypes = new WTF::HashSet<String>();
#if ENABLE(VIDEO)
MediaPlayer::getSupportedTypes(*supportedMediaMIMETypes);
#endif
}
static void initialiseMIMETypeRegistry()
{
supportedJavaScriptMIMETypes = new WTF::HashSet<String>();
initialiseSupportedJavaScriptMIMETypes();
supportedImageResourceMIMETypes = new WTF::HashSet<String>();
supportedImageMIMETypes = new WTF::HashSet<String>();
supportedNonImageMIMETypes = new WTF::HashSet<String>(*supportedJavaScriptMIMETypes);
initialiseSupportedNonImageMimeTypes();
initialiseSupportedImageMIMETypes();
}
String MIMETypeRegistry::getMIMETypeForPath(const String& path)
{
int pos = path.reverseFind('.');
if(pos >= 0) {
String extension = path.substring(pos + 1);
return getMIMETypeForExtension(extension);
}
return "application/octet-stream";
}
bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
{
if (!supportedImageMIMETypes)
initialiseMIMETypeRegistry();
return !mimeType.isEmpty() && supportedImageMIMETypes->contains(mimeType);
}
bool MIMETypeRegistry::isSupportedImageResourceMIMEType(const String& mimeType)
{
if (!supportedImageResourceMIMETypes)
initialiseMIMETypeRegistry();
return !mimeType.isEmpty() && supportedImageResourceMIMETypes->contains(mimeType);
}
bool MIMETypeRegistry::isSupportedJavaScriptMIMEType(const String& mimeType)
{
if (!supportedJavaScriptMIMETypes)
initialiseMIMETypeRegistry();
return !mimeType.isEmpty() && supportedJavaScriptMIMETypes->contains(mimeType);
}
bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType)
{
if (!supportedNonImageMIMETypes)
initialiseMIMETypeRegistry();
return !mimeType.isEmpty() && supportedNonImageMIMETypes->contains(mimeType);
}
bool MIMETypeRegistry::isSupportedMediaMIMEType(const String& mimeType)
{
if (!supportedMediaMIMETypes)
initialiseSupportedMediaMIMETypes();
return !mimeType.isEmpty() && supportedMediaMIMETypes->contains(mimeType);
}
bool MIMETypeRegistry::isJavaAppletMIMEType(const String& mimeType)
{
return mimeType.startsWith("application/x-java-applet", false)
|| mimeType.startsWith("application/x-java-bean", false)
|| mimeType.startsWith("application/x-java-vm", false);
}
HashSet<String> &MIMETypeRegistry::getSupportedImageMIMETypes()
{
if (!supportedImageMIMETypes)
initialiseMIMETypeRegistry();
return *supportedImageMIMETypes;
}
HashSet<String> &MIMETypeRegistry::getSupportedImageResourceMIMETypes()
{
if (!supportedImageResourceMIMETypes)
initialiseMIMETypeRegistry();
return *supportedImageResourceMIMETypes;
}
HashSet<String> &MIMETypeRegistry::getSupportedNonImageMIMETypes()
{
if (!supportedNonImageMIMETypes)
initialiseMIMETypeRegistry();
return *supportedNonImageMIMETypes;
}
HashSet<String> &MIMETypeRegistry::getSupportedMediaMIMETypes()
{
if (!supportedMediaMIMETypes)
initialiseSupportedMediaMIMETypes();
return *supportedMediaMIMETypes;
}
}