mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
229636 search for helper apps in mozilla directory before $PATH
r=bzbarsky sr=darin
This commit is contained in:
parent
854241d28c
commit
4ca8093ad9
@ -44,6 +44,8 @@
|
||||
#include "nsIDownload.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIRequest.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
|
||||
|
||||
// used to manage our in memory data source of helper applications
|
||||
#include "nsRDFCID.h"
|
||||
@ -917,10 +919,40 @@ nsresult nsExternalHelperAppService::GetMIMEInfoForExtensionFromDS(const char *
|
||||
return rv;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIMIMEInfo> nsExternalHelperAppService::GetMIMEInfoFromOS(const char * aContentType, const char * aFileExt, PRBool* aFound)
|
||||
|
||||
nsresult nsExternalHelperAppService::GetFileTokenForPath(const PRUnichar * aPlatformAppPath,
|
||||
nsIFile ** aFile)
|
||||
{
|
||||
NS_NOTREACHED("Should be implemented by per-platform derived classes");
|
||||
return nsnull;
|
||||
nsDependentString platformAppPath(aPlatformAppPath);
|
||||
// First, check if we have an absolute path
|
||||
nsILocalFile* localFile = nsnull;
|
||||
nsresult rv = NS_NewLocalFile(platformAppPath, PR_TRUE, &localFile);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aFile = localFile;
|
||||
PRBool exists;
|
||||
if (NS_FAILED((*aFile)->Exists(&exists)) || !exists) {
|
||||
NS_RELEASE(*aFile);
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// Second, check if file exists in mozilla program directory
|
||||
rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, aFile);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = (*aFile)->Append(platformAppPath);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PRBool exists = PR_FALSE;
|
||||
rv = (*aFile)->Exists(&exists);
|
||||
if (NS_SUCCEEDED(rv) && exists)
|
||||
return NS_OK;
|
||||
}
|
||||
NS_RELEASE(*aFile);
|
||||
}
|
||||
|
||||
|
||||
return NS_ERROR_FILE_NOT_FOUND;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -147,12 +147,15 @@ public:
|
||||
*/
|
||||
virtual already_AddRefed<nsIMIMEInfo> GetMIMEInfoFromOS(const char * aMIMEType,
|
||||
const char * aFileExt,
|
||||
PRBool * aFound);
|
||||
PRBool * aFound) = 0;
|
||||
|
||||
/**
|
||||
* Given a string identifying an application, create an nsIFile representing
|
||||
* it. This function should look in $PATH for the application.
|
||||
* GetFileTokenForPath must be implemented by each platform.
|
||||
* The base class implementation will first try to interpret platformAppPath
|
||||
* as an absolute path, and if that fails it will look for a file next to the
|
||||
* mozilla executable. Subclasses can override this method if they want a
|
||||
* different behaviour.
|
||||
* @param platformAppPath A platform specific path to an application that we
|
||||
* got out of the rdf data source. This can be a mac
|
||||
* file spec, a unix path or a windows path depending
|
||||
@ -161,7 +164,7 @@ public:
|
||||
* application path.
|
||||
*/
|
||||
virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath,
|
||||
nsIFile ** aFile) = 0;
|
||||
nsIFile ** aFile);
|
||||
|
||||
/**
|
||||
* Helper routine used to test whether a given mime type is in our
|
||||
|
@ -1337,83 +1337,6 @@ NS_IMETHODIMP nsOSHelperAppService::LoadUrl(nsIURI * aURL)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile)
|
||||
{
|
||||
#ifdef XP_OS2 /* Taking the old code - no idea if this was rewritten */
|
||||
nsCOMPtr<nsILocalFile> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (localFile)
|
||||
{
|
||||
if (localFile)
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
#else
|
||||
LOG(("-- nsOSHelperAppService::GetFileTokenForPath: '%s'\n",
|
||||
NS_LossyConvertUCS2toASCII(platformAppPath).get()));
|
||||
if (! *platformAppPath) { // empty filename--return error
|
||||
NS_WARNING("Empty filename passed in.");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
nsCOMPtr<nsILocalFile> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
nsresult rv;
|
||||
|
||||
if (!localFile) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// first check if this is a full path
|
||||
PRBool exists = PR_FALSE;
|
||||
if (*platformAppPath == '/') {
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
localFile->Exists(&exists);
|
||||
} else {
|
||||
|
||||
// ugly hack. Walk the PATH variable...
|
||||
char* unixpath = PR_GetEnv("PATH");
|
||||
nsCAutoString path(unixpath);
|
||||
nsACString::const_iterator start_iter, end_iter, colon_iter;
|
||||
|
||||
path.BeginReading(start_iter);
|
||||
colon_iter = start_iter;
|
||||
path.EndReading(end_iter);
|
||||
|
||||
while (start_iter != end_iter && !exists) {
|
||||
while (colon_iter != end_iter && *colon_iter != ':') {
|
||||
++colon_iter;
|
||||
}
|
||||
localFile->InitWithNativePath(Substring(start_iter, colon_iter));
|
||||
rv = localFile->AppendRelativePath(nsDependentString(platformAppPath));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
localFile->Exists(&exists);
|
||||
if (!exists) {
|
||||
if (colon_iter == end_iter) {
|
||||
break;
|
||||
}
|
||||
++colon_iter;
|
||||
start_iter = colon_iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
rv = NS_OK;
|
||||
} else {
|
||||
rv = NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
already_AddRefed<nsMIMEInfoOS2>
|
||||
nsOSHelperAppService::GetFromExtension(const char *aFileExt) {
|
||||
// if the extension is null, return immediately
|
||||
|
@ -50,12 +50,6 @@ public:
|
||||
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
|
||||
NS_IMETHOD LoadUrl(nsIURI * aURL);
|
||||
|
||||
// GetFileTokenForPath must be implemented by each platform.
|
||||
// platformAppPath --> a platform specific path to an application that we got out of the
|
||||
// rdf data source. This can be a mac file spec, a unix path or a windows path depending on the platform
|
||||
// aFile --> an nsIFile representation of that platform application path.
|
||||
virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile);
|
||||
|
||||
protected:
|
||||
already_AddRefed<nsMIMEInfoOS2> GetFromType(const char *aMimeType);
|
||||
already_AddRefed<nsMIMEInfoOS2> GetFromExtension(const char *aFileExt);
|
||||
|
@ -1287,42 +1287,39 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
|
||||
NS_WARNING("Empty filename passed in.");
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// first check if the base class implementation finds anything
|
||||
nsresult rv = nsExternalHelperAppService::GetFileTokenForPath(platformAppPath, aFile);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
nsresult rv;
|
||||
|
||||
if (!localFile) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// first check if this is a full path
|
||||
|
||||
PRBool exists = PR_FALSE;
|
||||
if (*platformAppPath == '/') {
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
localFile->Exists(&exists);
|
||||
} else {
|
||||
// ugly hack. Walk the PATH variable...
|
||||
char* unixpath = PR_GetEnv("PATH");
|
||||
nsCAutoString path(unixpath);
|
||||
|
||||
// ugly hack. Walk the PATH variable...
|
||||
char* unixpath = PR_GetEnv("PATH");
|
||||
nsCAutoString path(unixpath);
|
||||
nsACString::const_iterator start_iter, end_iter, colon_iter;
|
||||
const char* start_iter = path.BeginReading(start_iter);
|
||||
const char* colon_iter = start_iter;
|
||||
const char* end_iter = path.EndReading(end_iter);
|
||||
|
||||
path.BeginReading(start_iter);
|
||||
colon_iter = start_iter;
|
||||
path.EndReading(end_iter);
|
||||
|
||||
while (start_iter != end_iter && !exists) {
|
||||
while (colon_iter != end_iter && *colon_iter != ':') {
|
||||
++colon_iter;
|
||||
}
|
||||
localFile->InitWithNativePath(Substring(start_iter, colon_iter));
|
||||
rv = localFile->AppendRelativePath(nsDependentString(platformAppPath));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
localFile->Exists(&exists);
|
||||
if (!exists) {
|
||||
if (colon_iter == end_iter) {
|
||||
break;
|
||||
}
|
||||
++colon_iter;
|
||||
start_iter = colon_iter;
|
||||
while (start_iter != end_iter && !exists) {
|
||||
while (colon_iter != end_iter && *colon_iter != ':') {
|
||||
++colon_iter;
|
||||
}
|
||||
localFile->InitWithNativePath(Substring(start_iter, colon_iter));
|
||||
rv = localFile->AppendRelativePath(nsDependentString(platformAppPath));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
localFile->Exists(&exists);
|
||||
if (!exists) {
|
||||
if (colon_iter == end_iter) {
|
||||
break;
|
||||
}
|
||||
++colon_iter;
|
||||
start_iter = colon_iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -244,20 +244,6 @@ NS_IMETHODIMP nsOSHelperAppService::LoadUrl(nsIURI * aURL)
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> localFile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
|
||||
|
||||
if (!localFile)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
localFile->InitWithPath(nsDependentString(platformAppPath));
|
||||
*aFile = localFile;
|
||||
NS_IF_ADDREF(*aFile);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// GetMIMEInfoFromRegistry: This function obtains the values of some of the nsIMIMEInfo
|
||||
// attributes for the mimeType/extension associated with the input registry key. The default
|
||||
// entry for that key is the name of a registry key under HKEY_CLASSES_ROOT. The default
|
||||
|
Loading…
Reference in New Issue
Block a user