static void initializeSupportedImageMIMETypes() { #if PLATFORM(CG) RetainPtr<CFArrayRef> supportedTypes(AdoptCF, CGImageSourceCopyTypeIdentifiers()); CFIndex count = CFArrayGetCount(supportedTypes.get()); for (CFIndex i = 0; i < count; i++) { RetainPtr<CFStringRef> supportedType(AdoptCF, reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i))); String mimeType = getMIMETypeForUTI(supportedType.get()); if (!mimeType.isEmpty()) { supportedImageMIMETypes->add(mimeType); supportedImageResourceMIMETypes->add(mimeType); } } // On Tiger and Leopard, com.microsoft.bmp doesn't have a MIME type in the registry. supportedImageMIMETypes->add("image/bmp"); supportedImageResourceMIMETypes->add("image/bmp"); // Favicons don't have a MIME type in the registry either. supportedImageMIMETypes->add("image/x-icon"); supportedImageResourceMIMETypes->add("image/x-icon"); // We only get one MIME type per UTI, hence our need to add these manually supportedImageMIMETypes->add("image/pjpeg"); supportedImageResourceMIMETypes->add("image/pjpeg"); // We don't want to try to treat all binary data as an image supportedImageMIMETypes->remove("application/octet-stream"); supportedImageResourceMIMETypes->remove("application/octet-stream"); // Don't treat pdf/postscript as images directly supportedImageMIMETypes->remove("application/pdf"); supportedImageMIMETypes->remove("application/postscript"); #elif PLATFORM(QT) QList<QByteArray> formats = QImageReader::supportedImageFormats(); for (size_t i = 0; i < formats.size(); ++i) { #if ENABLE(SVG) /* * Qt has support for SVG, but we want to use KSVG2 */ if (formats.at(i).toLower().startsWith("svg")) continue; #endif String mimeType = MIMETypeRegistry::getMIMETypeForExtension(formats.at(i).constData()); supportedImageMIMETypes->add(mimeType); supportedImageResourceMIMETypes->add(mimeType); } #else // assume that all implementations at least support the following standard // image types: static const char* types[] = { "image/jpeg", "image/png", "image/gif", "image/bmp", "image/x-icon", // ico "image/x-xbitmap" // xbm }; for (size_t i = 0; i < sizeof(types) / sizeof(types[0]); ++i) { supportedImageMIMETypes->add(types[i]); supportedImageResourceMIMETypes->add(types[i]); } #endif }
static void initializeSupportedImageMIMETypes() { #if USE(CG) RetainPtr<CFArrayRef> supportedTypes = adoptCF(CGImageSourceCopyTypeIdentifiers()); CFIndex count = CFArrayGetCount(supportedTypes.get()); for (CFIndex i = 0; i < count; i++) { CFStringRef supportedType = reinterpret_cast<CFStringRef>(CFArrayGetValueAtIndex(supportedTypes.get(), i)); String mimeType = MIMETypeForImageSourceType(supportedType); if (!mimeType.isEmpty()) { supportedImageMIMETypes->add(mimeType); supportedImageResourceMIMETypes->add(mimeType); } } // On Tiger and Leopard, com.microsoft.bmp doesn't have a MIME type in the registry. supportedImageMIMETypes->add("image/bmp"); supportedImageResourceMIMETypes->add("image/bmp"); // Favicons don't have a MIME type in the registry either. supportedImageMIMETypes->add("image/vnd.microsoft.icon"); supportedImageMIMETypes->add("image/x-icon"); supportedImageResourceMIMETypes->add("image/vnd.microsoft.icon"); supportedImageResourceMIMETypes->add("image/x-icon"); // We only get one MIME type per UTI, hence our need to add these manually supportedImageMIMETypes->add("image/pjpeg"); supportedImageResourceMIMETypes->add("image/pjpeg"); // We don't want to try to treat all binary data as an image supportedImageMIMETypes->remove("application/octet-stream"); supportedImageResourceMIMETypes->remove("application/octet-stream"); // Don't treat pdf/postscript as images directly supportedImageMIMETypes->remove("application/pdf"); supportedImageMIMETypes->remove("application/postscript"); #if PLATFORM(IOS) // Add malformed image mimetype for compatibility with Mail and to handle malformed mimetypes from the net // These were removed for <rdar://problem/6564538> Re-enable UTI code in WebCore now that MobileCoreServices exists // But Mail relies on at least image/tif reported as being supported (should be image/tiff). // This can be removed when Mail addresses: // <rdar://problem/7879510> Mail should use standard image mimetypes // and we fix sniffing so that it corrects items such as image/jpg -> image/jpeg. static const char* malformedMIMETypes[] = { // JPEG (image/jpeg) "image/jpg", "image/jp_", "image/jpe_", "application/jpg", "application/x-jpg", "image/pipeg", "image/vnd.switfview-jpeg", "image/x-xbitmap", // GIF (image/gif) "image/gi_", // PNG (image/png) "application/png", "application/x-png", // TIFF (image/tiff) "image/x-tif", "image/tif", "image/x-tiff", "application/tif", "application/x-tif", "application/tiff", "application/x-tiff", // BMP (image/bmp, image/x-bitmap) "image/x-bmp", "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 (auto& type : malformedMIMETypes) { supportedImageMIMETypes->add(type); supportedImageResourceMIMETypes->add(type); } #endif #else // assume that all implementations at least support the following standard // image types: static const char* types[] = { "image/jpeg", "image/png", "image/gif", "image/bmp", "image/vnd.microsoft.icon", // ico "image/x-icon", // ico "image/x-xbitmap" // xbm }; for (auto& type : types) { supportedImageMIMETypes->add(type); supportedImageResourceMIMETypes->add(type); } #if USE(WEBP) supportedImageMIMETypes->add("image/webp"); supportedImageResourceMIMETypes->add("image/webp"); #endif #endif // USE(CG) }