| Index: Source/WebCore/platform/MIMETypeRegistry.cpp
|
| ===================================================================
|
| --- Source/WebCore/platform/MIMETypeRegistry.cpp (revision 90866)
|
| +++ Source/WebCore/platform/MIMETypeRegistry.cpp (working copy)
|
| @@ -49,6 +49,139 @@
|
|
|
| namespace WebCore {
|
|
|
| +namespace {
|
| +struct TypeExtensionPair {
|
| + const char* type;
|
| + const char* extension;
|
| +};
|
| +}
|
| +
|
| +// A table of common media MIME types and file extenstions used when a platform's
|
| +// specific MIME type lookup doesn't have a match for a media file extension.
|
| +static const TypeExtensionPair commonMediaTypes[] = {
|
| +
|
| + // Ogg
|
| + { "application/ogg", "ogx" },
|
| + { "audio/ogg", "ogg" },
|
| + { "audio/ogg", "oga" },
|
| + { "video/ogg", "ogv" },
|
| +
|
| + // Annodex
|
| + { "application/annodex", "anx" },
|
| + { "audio/annodex", "axa" },
|
| + { "video/annodex", "axv" },
|
| + { "audio/speex", "spx" },
|
| +
|
| + // WebM
|
| + { "video/webm", "webm" },
|
| + { "audio/webm", "webm" },
|
| +
|
| + // MPEG
|
| + { "audio/mpeg", "m1a" },
|
| + { "audio/mpeg", "m2a" },
|
| + { "audio/mpeg", "m1s" },
|
| + { "audio/mpeg", "mpa" },
|
| + { "video/mpeg", "mpg" },
|
| + { "video/mpeg", "m15" },
|
| + { "video/mpeg", "m1s" },
|
| + { "video/mpeg", "m1v" },
|
| + { "video/mpeg", "m75" },
|
| + { "video/mpeg", "mpa" },
|
| + { "video/mpeg", "mpeg" },
|
| + { "video/mpeg", "mpm" },
|
| + { "video/mpeg", "mpv" },
|
| +
|
| + // MPEG playlist
|
| + { "application/vnd.apple.mpegurl", "m3u8" },
|
| + { "application/mpegurl", "m3u8" },
|
| + { "application/x-mpegurl", "m3u8" },
|
| + { "audio/mpegurl", "m3url" },
|
| + { "audio/x-mpegurl", "m3url" },
|
| + { "audio/mpegurl", "m3u" },
|
| + { "audio/x-mpegurl", "m3u" },
|
| +
|
| + // MPEG-4
|
| + { "video/x-m4v", "m4v" },
|
| + { "audio/x-m4a", "m4a" },
|
| + { "audio/x-m4b", "m4b" },
|
| + { "audio/x-m4p", "m4p" },
|
| + { "audio/mp4", "m4a" },
|
| +
|
| + // MP3
|
| + { "audio/mp3", "mp3" },
|
| + { "audio/x-mp3", "mp3" },
|
| + { "audio/x-mpeg", "mp3" },
|
| +
|
| + // MPEG-2
|
| + { "video/x-mpeg2", "mp2" },
|
| + { "video/mpeg2", "vob" },
|
| + { "video/mpeg2", "mod" },
|
| + { "video/m2ts", "m2ts" },
|
| + { "video/x-m2ts", "m2t" },
|
| + { "video/x-m2ts", "ts" },
|
| +
|
| + // 3GP/3GP2
|
| + { "audio/3gpp", "3gpp" },
|
| + { "audio/3gpp2", "3g2" },
|
| + { "application/x-mpeg", "amc" },
|
| +
|
| + // AAC
|
| + { "audio/aac", "aac" },
|
| + { "audio/aac", "adts" },
|
| + { "audio/x-aac", "m4r" },
|
| +
|
| + // CoreAudio File
|
| + { "audio/x-caf", "caf" },
|
| + { "audio/x-gsm", "gsm" },
|
| +
|
| + // ADPCM
|
| + { "audio/x-wav", "wav" }
|
| +};
|
| +
|
| +#if ENABLE(FILE_SYSTEM)
|
| +static const char textPlain[] = "text/plain";
|
| +static const char textHtml[] = "text/html";
|
| +static const char imageJpeg[] = "image/jpeg";
|
| +static const char octetStream[] = "application/octet-stream";
|
| +
|
| +// A table of well known MIME types used when we don't want to leak to the
|
| +// caller information about types known to underlying platform.
|
| +static const TypeExtensionPair wellKnownMimeTypes[] = {
|
| + { textPlain, "txt" },
|
| + { textPlain, "text" },
|
| + { textHtml, "html" },
|
| + { textHtml, "htm" },
|
| + { "text/css", "css" },
|
| + { "text/xml", "xml" },
|
| + { "text/xsl", "xsl" },
|
| + { "image/gif", "gif" },
|
| + { "image/png", "png" },
|
| + { imageJpeg, "jpeg" },
|
| + { imageJpeg, "jpg" },
|
| + { imageJpeg, "jfif" },
|
| + { imageJpeg, "pjpeg" },
|
| + { "image/webp", "webp" },
|
| + { "image/bmp", "bmp" },
|
| + { "application/xhtml+xml", "xhtml" },
|
| + { "application/x-javascript", "js" },
|
| + { "application/json", "json" },
|
| + { octetStream, "exe" },
|
| + { octetStream, "com" },
|
| + { octetStream, "bin" },
|
| + { "application/zip", "zip" },
|
| + { "application/gzip", "gz" },
|
| + { "application/pdf", "pdf" },
|
| + { "application/postscript", "ps" },
|
| + { "image/x-icon", "ico" },
|
| + { "image/tiff", "tiff" },
|
| + { "image/x-xbitmap", "xbm" },
|
| + { "image/svg+xml", "svg" },
|
| + { "application/rss+xml", "rss" },
|
| + { "application/rdf+xml", "rdf" },
|
| + { "application/x-shockwave-flash", "swf" },
|
| +};
|
| +#endif
|
| +
|
| static HashSet<String>* supportedImageResourceMIMETypes;
|
| static HashSet<String>* supportedImageMIMETypes;
|
| static HashSet<String>* supportedImageMIMETypesForEncoding;
|
| @@ -232,126 +365,32 @@
|
|
|
| static MediaMIMETypeMap& mediaMIMETypeMap()
|
| {
|
| - struct TypeExtensionPair {
|
| - const char* type;
|
| - const char* extension;
|
| - };
|
| -
|
| - // A table of common media MIME types and file extenstions used when a platform's
|
| - // specific MIME type lookup doesn't have a match for a media file extension.
|
| - static const TypeExtensionPair pairs[] = {
|
| -
|
| - // Ogg
|
| - { "application/ogg", "ogx" },
|
| - { "audio/ogg", "ogg" },
|
| - { "audio/ogg", "oga" },
|
| - { "video/ogg", "ogv" },
|
| -
|
| - // Annodex
|
| - { "application/annodex", "anx" },
|
| - { "audio/annodex", "axa" },
|
| - { "video/annodex", "axv" },
|
| - { "audio/speex", "spx" },
|
| -
|
| - // WebM
|
| - { "video/webm", "webm" },
|
| - { "audio/webm", "webm" },
|
| -
|
| - // MPEG
|
| - { "audio/mpeg", "m1a" },
|
| - { "audio/mpeg", "m2a" },
|
| - { "audio/mpeg", "m1s" },
|
| - { "audio/mpeg", "mpa" },
|
| - { "video/mpeg", "mpg" },
|
| - { "video/mpeg", "m15" },
|
| - { "video/mpeg", "m1s" },
|
| - { "video/mpeg", "m1v" },
|
| - { "video/mpeg", "m75" },
|
| - { "video/mpeg", "mpa" },
|
| - { "video/mpeg", "mpeg" },
|
| - { "video/mpeg", "mpm" },
|
| - { "video/mpeg", "mpv" },
|
| -
|
| - // MPEG playlist
|
| - { "application/vnd.apple.mpegurl", "m3u8" },
|
| - { "application/mpegurl", "m3u8" },
|
| - { "application/x-mpegurl", "m3u8" },
|
| - { "audio/mpegurl", "m3url" },
|
| - { "audio/x-mpegurl", "m3url" },
|
| - { "audio/mpegurl", "m3u" },
|
| - { "audio/x-mpegurl", "m3u" },
|
| -
|
| - // MPEG-4
|
| - { "video/x-m4v", "m4v" },
|
| - { "audio/x-m4a", "m4a" },
|
| - { "audio/x-m4b", "m4b" },
|
| - { "audio/x-m4p", "m4p" },
|
| - { "audio/mp4", "m4a" },
|
| -
|
| - // MP3
|
| - { "audio/mp3", "mp3" },
|
| - { "audio/x-mp3", "mp3" },
|
| - { "audio/x-mpeg", "mp3" },
|
| -
|
| - // MPEG-2
|
| - { "video/x-mpeg2", "mp2" },
|
| - { "video/mpeg2", "vob" },
|
| - { "video/mpeg2", "mod" },
|
| - { "video/m2ts", "m2ts" },
|
| - { "video/x-m2ts", "m2t" },
|
| - { "video/x-m2ts", "ts" },
|
| -
|
| - // 3GP/3GP2
|
| - { "audio/3gpp", "3gpp" },
|
| - { "audio/3gpp2", "3g2" },
|
| - { "application/x-mpeg", "amc" },
|
| -
|
| - // AAC
|
| - { "audio/aac", "aac" },
|
| - { "audio/aac", "adts" },
|
| - { "audio/x-aac", "m4r" },
|
| -
|
| - // CoreAudio File
|
| - { "audio/x-caf", "caf" },
|
| - { "audio/x-gsm", "gsm" },
|
| -
|
| - // ADPCM
|
| - { "audio/x-wav", "wav" }
|
| - };
|
| -
|
| DEFINE_STATIC_LOCAL(MediaMIMETypeMap, mediaMIMETypeForExtensionMap, ());
|
|
|
| if (!mediaMIMETypeForExtensionMap.isEmpty())
|
| return mediaMIMETypeForExtensionMap;
|
|
|
| - const unsigned numPairs = sizeof(pairs) / sizeof(pairs[0]);
|
| + const unsigned numPairs = sizeof(commonMediaTypes) / sizeof(commonMediaTypes[0]);
|
| for (unsigned ndx = 0; ndx < numPairs; ++ndx) {
|
|
|
| - if (mediaMIMETypeForExtensionMap.contains(pairs[ndx].extension))
|
| - mediaMIMETypeForExtensionMap.get(pairs[ndx].extension)->append(pairs[ndx].type);
|
| + if (mediaMIMETypeForExtensionMap.contains(commonMediaTypes[ndx].extension))
|
| + mediaMIMETypeForExtensionMap.get(commonMediaTypes[ndx].extension)->append(commonMediaTypes[ndx].type);
|
| else {
|
| Vector<String>* synonyms = new Vector<String>;
|
|
|
| // If there is a system specific type for this extension, add it as the first type so
|
| // getMediaMIMETypeForExtension will always return it.
|
| - String systemType = MIMETypeRegistry::getMIMETypeForExtension(pairs[ndx].extension);
|
| - if (!systemType.isEmpty() && pairs[ndx].type != systemType)
|
| + String systemType = MIMETypeRegistry::getMIMETypeForExtension(commonMediaTypes[ndx].extension);
|
| + if (!systemType.isEmpty() && commonMediaTypes[ndx].type != systemType)
|
| synonyms->append(systemType);
|
| - synonyms->append(pairs[ndx].type);
|
| - mediaMIMETypeForExtensionMap.add(pairs[ndx].extension, synonyms);
|
| + synonyms->append(commonMediaTypes[ndx].type);
|
| + mediaMIMETypeForExtensionMap.add(commonMediaTypes[ndx].extension, synonyms);
|
| }
|
| }
|
|
|
| return mediaMIMETypeForExtensionMap;
|
| }
|
|
|
| -#if ENABLE(FILE_SYSTEM) && ENABLE(WORKERS)
|
| -String MIMETypeRegistry::getMIMETypeForExtension(const String& extension)
|
| -{
|
| - return getMIMETypeForExtensionThreadSafe(extension);
|
| -}
|
| -#endif
|
| -
|
| String MIMETypeRegistry::getMediaMIMETypeForExtension(const String& ext)
|
| {
|
| // Look in the system-specific registry first.
|
| @@ -430,6 +469,28 @@
|
| initializeUnsupportedTextMIMETypes();
|
| }
|
|
|
| +#if ENABLE(FILE_SYSTEM)
|
| +static String findMimeType(const TypeExtensionPair* pairs, unsigned numPairs, const String& extension)
|
| +{
|
| + if (!extension.isEmpty()) {
|
| + for (unsigned i = 0; i < numPairs; ++i, ++pairs) {
|
| + if (equalIgnoringCase(extension, pairs->extension))
|
| + return String(pairs->type);
|
| + }
|
| + }
|
| + return String();
|
| +}
|
| +
|
| +String MIMETypeRegistry::getWellKnownMIMETypeForExtension(const String& extension)
|
| +{
|
| + // This method must be thread safe and should not consult the OS/registry.
|
| + String found = findMimeType(wellKnownMimeTypes, sizeof(wellKnownMimeTypes) / sizeof(wellKnownMimeTypes[0]), extension);
|
| + if (!found.isEmpty())
|
| + return found;
|
| + return findMimeType(commonMediaTypes, sizeof(commonMediaTypes) / sizeof(commonMediaTypes[0]), extension);
|
| +}
|
| +#endif
|
| +
|
| String MIMETypeRegistry::getMIMETypeForPath(const String& path)
|
| {
|
| size_t pos = path.reverseFind('.');
|
|
|