MIMETypeRegistryChromium.cpp [plain text]
#include "config.h"
#include "MIMETypeRegistry.h"
#include "MediaPlayer.h"
#include "PluginDataChromium.h"
#include <public/Platform.h>
#include <public/WebMimeRegistry.h>
#include <wtf/text/CString.h>
namespace WebCore {
String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
{
return WebKit::Platform::current()->mimeRegistry()->mimeTypeForExtension(ext);
}
#if ENABLE(FILE_SYSTEM)
String MIMETypeRegistry::getWellKnownMIMETypeForExtension(const String &ext)
{
return WebKit::Platform::current()->mimeRegistry()->wellKnownMimeTypeForExtension(ext);
}
#endif
String MIMETypeRegistry::getPreferredExtensionForMIMEType(const String& type)
{
String mimeType = type.substring(0, static_cast<unsigned>(type.find(';')));
String ext = WebKit::Platform::current()->mimeRegistry()->preferredExtensionForMIMEType(type);
if (!ext.isEmpty() && ext[0] == '.')
ext = ext.substring(1);
return ext;
}
String MIMETypeRegistry::getMIMETypeForPath(const String& path)
{
int pos = path.reverseFind('.');
if (pos < 0)
return "application/octet-stream";
String extension = path.substring(pos + 1);
String mimeType = getMIMETypeForExtension(extension);
if (mimeType.isEmpty()) {
mimeType = getPluginMimeTypeFromExtension(extension);
}
if (mimeType.isEmpty())
return "application/octet-stream";
return mimeType;
}
bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
{
return WebKit::Platform::current()->mimeRegistry()->supportsImageMIMEType(mimeType)
!= WebKit::WebMimeRegistry::IsNotSupported;
}
bool MIMETypeRegistry::isSupportedImageResourceMIMEType(const String& mimeType)
{
return isSupportedImageMIMEType(mimeType);
}
bool MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(const String& mimeType)
{
if (mimeType == "image/jpeg" || mimeType == "image/png")
return true;
#if USE(WEBP) && USE(SKIA)
if (mimeType == "image/webp")
return true;
#endif
return false;
}
bool MIMETypeRegistry::isSupportedJavaScriptMIMEType(const String& mimeType)
{
return WebKit::Platform::current()->mimeRegistry()->supportsJavaScriptMIMEType(mimeType)
!= WebKit::WebMimeRegistry::IsNotSupported;
}
bool MIMETypeRegistry::isSupportedNonImageMIMEType(const String& mimeType)
{
return WebKit::Platform::current()->mimeRegistry()->supportsNonImageMIMEType(mimeType)
!= WebKit::WebMimeRegistry::IsNotSupported;
}
bool MIMETypeRegistry::isSupportedMediaMIMEType(const String& mimeType)
{
HashSet<String> supportedMediaMIMETypes;
#if ENABLE(VIDEO)
MediaPlayer::getSupportedTypes(supportedMediaMIMETypes);
#endif
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);
}
String MIMETypeRegistry::getMediaMIMETypeForExtension(const String&)
{
return String();
}
bool MIMETypeRegistry::isApplicationPluginMIMEType(const String&)
{
return false;
}
static HashSet<String>& dummyHashSet()
{
ASSERT_NOT_REACHED();
DEFINE_STATIC_LOCAL(HashSet<String>, dummy, ());
return dummy;
}
HashSet<String>& MIMETypeRegistry::getSupportedImageMIMETypes() { return dummyHashSet(); }
HashSet<String>& MIMETypeRegistry::getSupportedImageResourceMIMETypes() { return dummyHashSet(); }
HashSet<String>& MIMETypeRegistry::getSupportedImageMIMETypesForEncoding() { return dummyHashSet(); }
HashSet<String>& MIMETypeRegistry::getSupportedNonImageMIMETypes() { return dummyHashSet(); }
HashSet<String>& MIMETypeRegistry::getSupportedMediaMIMETypes() { return dummyHashSet(); }
}