Bug #43556 --> merging nsIMIMEService and making it use OS specific

This commit is contained in:
mscott%netscape.com 2000-09-15 06:06:58 +00:00
Родитель 84a46d679c
Коммит 4744cb1ded
2 изменённых файлов: 72 добавлений и 14 удалений

Просмотреть файл

@ -105,25 +105,34 @@ NS_IMETHODIMP nsOSHelperAppService::DoContent(const char *aMimeContentType, nsIU
}
*aStreamListener = nsnull;
// use InternetConfig to fill in MIMEInfo
// first, try to see if we can find the content based on just the specified content type...
nsCOMPtr<nsIMIMEInfo> mimeInfo;
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService)
rv = GetFromMIMEType(aMimeContentType, getter_AddRefs(mimeInfo));
if (NS_FAILED(rv) || !mimeInfo)
{
if (url)
rv = icService->FillInMIMEInfo(aMimeContentType, url, getter_AddRefs(mimeInfo));
else
rv = icService->FillInMIMEInfo(aMimeContentType, nsnull, getter_AddRefs(mimeInfo));
if (NS_SUCCEEDED(rv) && mimeInfo)
// if the content based search failed, then try looking up based on the file extension....
if (url)
{
// this code is incomplete and just here to get things started..
nsXPIDLCString fileExtension;
mimeInfo->FirstExtension(getter_Copies(fileExtension));
nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext);
handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener);
rv = NS_OK;
nsXPIDLCString extension;
url->GetFileExtension(getter_Copies(extension));
const char * ext = (const char *) extension;
if (ext && *ext)
rv = GetFromExtension(ext, getter_AddRefs(mimeInfo));
}
}
if (NS_SUCCEEDED(rv) && mimeInfo)
{
// create an app handler to handle the content...
nsXPIDLCString fileExtension;
mimeInfo->FirstExtension(getter_Copies(fileExtension));
nsExternalAppHandler * handler = CreateNewExternalHandler(mimeInfo, fileExtension, aWindowContext);
handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener);
rv = NS_OK;
}
return rv;
}
@ -177,3 +186,48 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
return rv;
}
///////////////////////////
// nsIMIMEService overrides --> used to leverage internet config information for mime types.
///////////////////////////
NS_IMETHODIMP nsOSHelperAppService::GetFromExtension(const char * aFileExt, nsIMIMEInfo ** aMIMEInfo)
{
// first, ask our base class. We may already have this information cached....
nsresult rv = nsExternalHelperAppService::GetFromExtension(aFileExt, aMIMEInfo);
if (NS_SUCCEEDED(rv) && *aMIMEInfo) return rv;
// oops, we didn't find an entry....ask the internet config service to look it up for us...
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService)
{
rv = icService->GetMIMEInfoFromExtension(aFileExt, aMIMEInfo);
// if we got an entry, don't waste time hitting IC for this information next time, store it in our
// hash table....
if (NS_SUCCEEDED(rv) && *aMIMEInfo)
AddMimeInfoToCache(*aMIMEInfo);
}
if (!*aMIMEInfo) rv = NS_ERROR_FAILURE;
return rv;
}
NS_IMETHODIMP nsOSHelperAppService::GetFromMIMEType(const char * aMIMEType, nsIMIMEInfo ** aMIMEInfo)
{
// first, ask our base class. We may already have this information cached....
nsresult rv = nsExternalHelperAppService::GetFromMIMEType(aMIMEType, aMIMEInfo);
if (NS_SUCCEEDED(rv) && *aMIMEInfo) return rv;
// oops, we didn't find an entry....ask the internet config service to look it up for us...
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService)
{
rv = icService->FillInMIMEInfo(aMIMEType, nsnull, aMIMEInfo);
// if we got an entry, don't waste time hitting IC for this information next time, store it in our
// hash table....
if (NS_SUCCEEDED(rv) && *aMIMEInfo)
AddMimeInfoToCache(*aMIMEInfo);
}
if (!*aMIMEInfo) rv = NS_ERROR_FAILURE;
return rv;
}

Просмотреть файл

@ -45,6 +45,10 @@ public:
// override nsIExternalProtocolService methods
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
NS_IMETHOD LoadUrl(nsIURI * aURL);
// nsIMIMEService over-rides --> used to hook the mime service into internet config....
NS_IMETHOD GetFromExtension(const char * aFileExt, nsIMIMEInfo ** aMIMEInfo);
NS_IMETHOD GetFromMIMEType(const char * aMIMEType, nsIMIMEInfo ** aMIMEInfo);
// GetFileTokenForPath must be implemented by each platform.
// platformAppPath --> a platform specific path to an application that we got out of the