bug 49758, r=alecf, sr=sfraser, implement nsOSHelperAppService::ExternalProtocolHandlerExists() and implement nsOSHelperAppService::LoadURL() for mac

This commit is contained in:
pchen%netscape.com 2001-04-16 20:16:41 +00:00
parent f1b7600dc5
commit bb513f39f4

View File

@ -28,9 +28,18 @@
#include "nsILocalFile.h"
#include "nsILocalFileMac.h"
#include "nsMimeTypes.h"
#include "nsIStringBundle.h"
#include "nsIPromptService.h"
#include "nsMemory.h"
#include "nsIInternetConfigService.h"
// chrome URL's
#define HELPERAPPLAUNCHER_BUNDLE_URL "chrome://global/locale/helperAppLauncher.properties"
#define BRAND_BUNDLE_URL "chrome://global/locale/brand.properties"
#define NS_PROMPTSERVICE_CID "@mozilla.org/embedcomp/prompt-service;1"
nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
{
}
@ -61,14 +70,72 @@ NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInf
NS_IMETHODIMP nsOSHelperAppService::ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
{
// look up the protocol scheme in the windows registry....if we find a match then we have a handler for it...
// look up the protocol scheme in Internet Config....if we find a match then we have a handler for it...
*aHandlerExists = PR_FALSE;
return NS_OK;
// ask the internet config service to look it up for us...
nsresult rv = NS_ERROR_FAILURE;
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService)
{
rv = icService->HasProtocolHandler(aProtocolScheme, aHandlerExists);
if (rv == NS_ERROR_NOT_AVAILABLE)
{
// current app is registered to handle the protocol, put up an alert
nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if (stringBundleService)
{
nsILocale* locale = nsnull;
nsCOMPtr<nsIStringBundle> appLauncherBundle;
rv = stringBundleService->CreateBundle(HELPERAPPLAUNCHER_BUNDLE_URL, locale, getter_AddRefs(appLauncherBundle));
if (rv == NS_OK)
{
nsCOMPtr<nsIStringBundle> brandBundle;
rv = stringBundleService->CreateBundle(BRAND_BUNDLE_URL, locale, getter_AddRefs(brandBundle));
if (rv == NS_OK)
{
nsXPIDLString brandName;
rv = brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(brandName));
if (rv == NS_OK)
{
nsXPIDLString errorStr;
NS_ConvertASCIItoUCS2 proto(aProtocolScheme);
const PRUnichar *formatStrings[] = { brandName.get(), proto.get() };
rv = appLauncherBundle->FormatStringFromName(NS_LITERAL_STRING("protocolNotHandled").get(),
formatStrings,
2,
getter_Copies(errorStr));
if (rv == NS_OK)
{
nsCOMPtr<nsIPromptService> prompt (do_GetService(NS_PROMPTSERVICE_CID));
if (prompt)
prompt->Alert(nsnull, NS_LITERAL_STRING("Alert").get(), errorStr.get());
}
}
}
}
}
}
}
return rv;
}
NS_IMETHODIMP nsOSHelperAppService::LoadUrl(nsIURI * aURL)
{
return NS_ERROR_FAILURE;
char *url = nsnull;
nsresult rv = NS_ERROR_FAILURE;
if (aURL)
{
aURL->GetSpec(&url);
if (url)
{
nsCOMPtr<nsIInternetConfigService> icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID));
if (icService)
rv = icService->LaunchURL(url);
nsMemory::Free(url);
}
}
return rv;
}
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile)