/* static */ already_AddRefed<nsMIMEInfoBase> nsGNOMERegistry::GetFromExtension(const nsACString& aFileExt) { nsCAutoString mimeType; nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); if (giovfs) { // Get the MIME type from the extension, then call GetFromType to // fill in the MIMEInfo. if (NS_FAILED(giovfs->GetMimeTypeFromExtension(aFileExt, mimeType)) || mimeType.EqualsLiteral("application/octet-stream")) { return nullptr; } } else { /* Fallback to GnomeVFS */ nsCOMPtr<nsIGnomeVFSService> gnomevfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID); if (!gnomevfs) return nullptr; if (NS_FAILED(gnomevfs->GetMimeTypeFromExtension(aFileExt, mimeType)) || mimeType.EqualsLiteral("application/octet-stream")) return nullptr; } return GetFromType(mimeType); }
already_AddRefed<nsIMIMEInfo> nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aType, const nsACString& aFileExt, PRBool* aFound) { // printf("nsOSHelperAppService::GetMIMEInfoFromOS (%s, %s)\n", nsPromiseFlatCString(aType).get(), nsPromiseFlatCString(aFileExt).get()); *aFound = PR_TRUE; nsMIMEInfoBase* retval = GetFromType(PromiseFlatCString(aType)).get(); PRBool hasDefault = PR_FALSE; if (retval) retval->GetHasDefaultHandler(&hasDefault); if (!retval || !hasDefault) { nsRefPtr<nsMIMEInfoBase> miByExt = GetFromExtension(PromiseFlatCString(aFileExt)); // If we had no extension match, but a type match, use that if (!miByExt && retval) return retval; // If we had an extension match but no type match, set the mimetype and use // it if (!retval && miByExt) { if (!aType.IsEmpty()) miByExt->SetMIMEType(aType); miByExt.swap(retval); return retval; } // If we got nothing, make a new mimeinfo if (!retval) { *aFound = PR_FALSE; retval = new nsMIMEInfoAmigaOS(aType); if (retval) { NS_ADDREF(retval); if (!aFileExt.IsEmpty()) retval->AppendExtension(aFileExt); } return retval; } // Copy the attributes of retval (mimeinfo from type) onto miByExt, to // return it // but reset to just collected mDefaultAppDescription (from ext) nsAutoString byExtDefault; miByExt->GetDefaultDescription(byExtDefault); retval->SetDefaultDescription(byExtDefault); retval->CopyBasicDataTo(miByExt); miByExt.swap(retval); } return retval; }
/* static */ already_AddRefed<nsMIMEInfoBase> nsGNOMERegistry::GetFromExtension(const nsACString& aFileExt) { NS_ASSERTION(aFileExt[0] != '.', "aFileExt shouldn't start with a dot"); nsCOMPtr<nsIGnomeVFSService> vfs = do_GetService(NS_GNOMEVFSSERVICE_CONTRACTID); if (!vfs) return nsnull; // Get the MIME type from the extension, then call GetFromType to // fill in the MIMEInfo. nsCAutoString mimeType; if (NS_FAILED(vfs->GetMimeTypeFromExtension(aFileExt, mimeType)) || mimeType.EqualsLiteral("application/octet-stream")) return nsnull; return GetFromType(mimeType); }
/* static */ already_AddRefed<nsMIMEInfoBase> nsGNOMERegistry::GetFromExtension(const nsACString& aFileExt) { nsAutoCString mimeType; nsCOMPtr<nsIGIOService> giovfs = do_GetService(NS_GIOSERVICE_CONTRACTID); if (!giovfs) { return nullptr; } // Get the MIME type from the extension, then call GetFromType to // fill in the MIMEInfo. if (NS_FAILED(giovfs->GetMimeTypeFromExtension(aFileExt, mimeType)) || mimeType.EqualsLiteral("application/octet-stream")) { return nullptr; } nsRefPtr<nsMIMEInfoBase> mi = GetFromType(mimeType); if (mi) { mi->AppendExtension(aFileExt); } return mi.forget(); }