NS_IMETHODIMP nsGIOService::GetMimeTypeFromExtension(const nsACString& aExtension, nsACString& aMimeType) { nsCAutoString fileExtToUse("file."); fileExtToUse.Append(aExtension); gboolean result_uncertain; char *content_type = g_content_type_guess(fileExtToUse.get(), NULL, 0, &result_uncertain); if (!content_type) return NS_ERROR_FAILURE; char *mime_type = g_content_type_get_mime_type(content_type); if (!mime_type) { g_free(content_type); return NS_ERROR_FAILURE; } aMimeType.Assign(mime_type); g_free(mime_type); g_free(content_type); return NS_OK; }
NS_IMETHODIMP nsGnomeVFSService::GetMimeTypeFromExtension(const nsACString &aExtension, nsACString& aMimeType) { nsCAutoString fileExtToUse(NS_LITERAL_CSTRING(".") + aExtension); const char *mimeType = gnome_vfs_mime_type_from_name(fileExtToUse.get()); aMimeType.Assign(mimeType); // |mimeType| points to internal gnome-vfs data, so don't free it. return NS_OK; }