Modified: trunk/Source/WebCore/platform/MIMETypeRegistry.cpp (135506 => 135507)
--- trunk/Source/WebCore/platform/MIMETypeRegistry.cpp 2012-11-22 13:16:48 UTC (rev 135506)
+++ trunk/Source/WebCore/platform/MIMETypeRegistry.cpp 2012-11-22 13:23:28 UTC (rev 135507)
@@ -491,6 +491,7 @@
return findMimeType(commonMediaTypes, sizeof(commonMediaTypes) / sizeof(commonMediaTypes[0]), extension);
}
+#if !PLATFORM(QT)
String MIMETypeRegistry::getMIMETypeForPath(const String& path)
{
size_t pos = path.reverseFind('.');
@@ -500,8 +501,9 @@
if (result.length())
return result;
}
- return "application/octet-stream";
+ return defaultMIMEType();
}
+#endif
bool MIMETypeRegistry::isSupportedImageMIMEType(const String& mimeType)
{
@@ -638,6 +640,13 @@
return defaultMIMEType;
}
+#if !PLATFORM(QT) && !PLATFORM(BLACKBERRY)
+String MIMETypeRegistry::getNormalizedMIMEType(const String& mimeType)
+{
+ return mimeType;
+}
+#endif
+
#if PLATFORM(BLACKBERRY)
typedef HashMap<String, String> MIMETypeAssociationMap;
@@ -696,18 +705,16 @@
return *mimeTypeMap;
}
-#endif
String MIMETypeRegistry::getNormalizedMIMEType(const String& mimeType)
{
-#if PLATFORM(BLACKBERRY)
MIMETypeAssociationMap::const_iterator it = mimeTypeAssociationMap().find(mimeType);
if (it != mimeTypeAssociationMap().end())
return it->value;
-#endif
+
return mimeType;
}
+#endif
-
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp (135506 => 135507)
--- trunk/Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp 2012-11-22 13:16:48 UTC (rev 135506)
+++ trunk/Source/WebCore/platform/qt/MIMETypeRegistryQt.cpp 2012-11-22 13:23:28 UTC (rev 135507)
@@ -29,76 +29,41 @@
#include "config.h"
#include "MIMETypeRegistry.h"
+#include <QMimeDatabase>
#include <wtf/Assertions.h>
#include <wtf/MainThread.h>
namespace WebCore {
-struct ExtensionMap {
- const char* extension;
- const char* mimeType;
-};
+String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
+{
+ // QMimeDatabase lacks the ability to query by extension alone, so we create a fake filename to lookup.
+ const QString filename = QStringLiteral("filename.") + QString(ext.lower());
-static const ExtensionMap extensionMap[] = {
- { "bmp", "image/bmp" },
- { "css", "text/css" },
- { "gif", "image/gif" },
- { "html", "text/html" },
- { "htm", "text/html" },
- { "ico", "image/x-icon" },
- { "jpeg", "image/jpeg" },
- { "jpg", "image/jpeg" },
- { "js", "application/x-_javascript_" },
- { "mng", "video/x-mng" },
- { "mp4", "video/mp4" },
- { "m4v", "video/mp4" },
- { "m4a", "audio/x-m4a" },
- { "mht", "multipart/related" },
- { "mhtml", "multipart/related" },
- { "mp3", "audio/mp3" },
- { "ogv", "video/ogg" },
- { "oga", "audio/ogg" },
- { "ogm", "audio/ogg" },
- { "ogg", "audio/ogg" },
- { "webm", "video/webm" },
- { "webm", "audio/webm" },
- { "wav", "audio/wav" },
- { "mov", "video/quicktime" },
- { "pbm", "image/x-portable-bitmap" },
- { "pgm", "image/x-portable-graymap" },
- { "pdf", "application/pdf" },
- { "png", "image/png" },
- { "ppm", "image/x-portable-pixmap" },
- { "rss", "application/rss+xml" },
- { "svg", "image/svg+xml" },
- { "text", "text/plain" },
- { "tif", "image/tiff" },
- { "tiff", "image/tiff" },
- { "txt", "text/plain" },
- { "xbm", "image/x-xbitmap" },
- { "xml", "text/xml" },
- { "xpm", "image/x-xpm" },
- { "xsl", "text/xsl" },
- { "xhtml", "application/xhtml+xml" },
- { "wml", "text/vnd.wap.wml" },
- { "wmlc", "application/vnd.wap.wmlc" },
- { 0, 0 }
-};
+ QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename, QMimeDatabase::MatchExtension);
+ if (mimeType.isValid() && !mimeType.isDefault())
+ return mimeType.name();
-String MIMETypeRegistry::getMIMETypeForExtension(const String &ext)
+ return String();
+}
+
+String MIMETypeRegistry::getMIMETypeForPath(const String& path)
{
- ASSERT(isMainThread());
+ QMimeType type = QMimeDatabase().mimeTypeForFile(path, QMimeDatabase::MatchExtension);
+ if (type.isValid())
+ return type.name();
- String s = ext.lower();
+ return defaultMIMEType();
+}
- const ExtensionMap *e = extensionMap;
- while (e->extension) {
- if (s == e->extension)
- return e->mimeType;
- ++e;
- }
+String MIMETypeRegistry::getNormalizedMIMEType(const String& mimeTypeName)
+{
+ // This looks up the mime type object by preferred name or alias, and returns the preferred name.
+ QMimeType mimeType = QMimeDatabase().mimeTypeForName(mimeTypeName);
+ if (mimeType.isValid() && !mimeType.isDefault())
+ return mimeType.name();
- return String();
+ return mimeTypeName;
}
bool MIMETypeRegistry::isApplicationPluginMIMEType(const String& mimeType)