Bug #43583 --> updates for helper app launching to work with the dialog.

This commit is contained in:
mscott%netscape.com 2000-07-07 01:48:57 +00:00
Родитель 677c8d5d17
Коммит ec140450ed
2 изменённых файлов: 23 добавлений и 128 удалений

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

@ -28,96 +28,6 @@
#include "nsILocalFile.h"
#include <stdlib.h> // for system()
// this is a platform specific class that abstracts an application.
// we treat this object as a cookie when we pass it to an external app handler..
// the handler will present this cookie back to the helper app service along with a
// an argument (the temp file).
class nsExternalApplication : public nsISupports
{
public:
NS_DECL_ISUPPORTS
nsExternalApplication();
virtual ~nsExternalApplication();
// the app registry name is the key we got from the registry for the
// application. We should be able to just call ::ShellExecute on this name
// in order to launch the application.
void SetAppRegistryName(const char * aAppRegistryName);
void SetLocalFile(nsIFile * aApplicationToUse);
// used to launch the application passing in the location of the temp file
// to be associated with this app.
nsresult LaunchApplication(nsIFile * aTempFile);
protected:
nsCString mAppRegistryName;
nsCOMPtr<nsIFile> mApplicationToUse;
};
NS_IMPL_THREADSAFE_ADDREF(nsExternalApplication)
NS_IMPL_THREADSAFE_RELEASE(nsExternalApplication)
NS_INTERFACE_MAP_BEGIN(nsExternalApplication)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsISupports)
NS_INTERFACE_MAP_END_THREADSAFE
nsExternalApplication::nsExternalApplication()
{
NS_INIT_ISUPPORTS();
}
nsExternalApplication::~nsExternalApplication()
{}
void nsExternalApplication::SetAppRegistryName(const char * aAppRegistryName)
{
mAppRegistryName = aAppRegistryName;
}
void nsExternalApplication::SetLocalFile(nsIFile * aApplicationToUse)
{
mApplicationToUse = aApplicationToUse;
}
nsresult nsExternalApplication::LaunchApplication(nsIFile * aTempFile)
{
nsresult rv = NS_OK;
nsXPIDLCString path;
aTempFile->GetPath(getter_Copies(path));
// if we were given an application to use then use it....otherwise
if (mApplicationToUse)
{
const char * strPath = (const char *) path;
mApplicationToUse->Spawn(&strPath, 1);
}
else if (!mAppRegistryName.IsEmpty() && aTempFile)
{
nsCAutoString command;
// build the command to run
command = (const char *)mAppRegistryName;
command += " ";
command += (const char *)path;
#ifdef DEBUG_seth
printf("spawn this: %s\n",(const char *)command);
#endif
int err = system((const char *)command);
if (err == 0) {
rv = NS_OK;
}
else {
rv = NS_ERROR_FAILURE;
}
}
return rv;
}
nsOSHelperAppService::nsOSHelperAppService() : nsExternalHelperAppService()
{
@ -160,15 +70,30 @@ NS_IMETHODIMP nsOSHelperAppService::DoContent(const char *aMimeContentType, nsIU
return NS_OK;
}
NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIFile * aTempFile, nsISupports * aAppCookie)
NS_IMETHODIMP nsOSHelperAppService::LaunchAppWithTempFile(nsIMIMEInfo * aMIMEInfo, nsIFile * aTempFile)
{
if (aAppCookie)
{
nsExternalApplication * application = NS_STATIC_CAST(nsExternalApplication *, aAppCookie);
return application->LaunchApplication(aTempFile);
nsresult rv = NS_OK;
if (aMIMEInfo)
{
nsCOMPtr<nsIFile> application;
nsXPIDLCString path;
aTempFile->GetPath(getter_Copies(path));
aMIMEInfo->GetPreferredApplicationHandler(getter_AddRefs(application));
if (application)
{
// if we were given an application to use then use it....otherwise
// make the registry call to launch the app
const char * strPath = (const char *) path;
application->Spawn(&strPath, 1);
}
else
{
// if we had hooks into the OS we can use them here to launch the app
}
}
else
return NS_ERROR_FAILURE;
return rv;
}
NS_IMETHODIMP nsOSHelperAppService::ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists)
@ -200,26 +125,3 @@ nsresult nsOSHelperAppService::GetFileTokenForPath(const PRUnichar * platformApp
return rv;
}
nsresult nsOSHelperAppService::CreateStreamListenerWithApp(nsIFile * aApplicationToUse, const char * aFileExtension, nsIStreamListener ** aStreamListener)
{
nsresult rv = NS_OK;
// create an application that represents this app name...
nsExternalApplication * application = nsnull;
NS_NEWXPCOM(application, nsExternalApplication);
NS_IF_ADDREF(application);
if (application)
{
application->SetLocalFile(aApplicationToUse);
nsCOMPtr<nsISupports> appSupports = do_QueryInterface(application);
// this code is incomplete and just here to get things started..
nsExternalAppHandler * handler = CreateNewExternalHandler(appSupports, aFileExtension);
handler->QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aStreamListener);
}
NS_IF_RELEASE(application);
return rv;
}

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

@ -40,7 +40,7 @@ public:
// override nsIExternalHelperAppService methods....
NS_IMETHOD CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool *_retval);
NS_IMETHOD DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, PRBool *aAbortProcess, nsIStreamListener **_retval);
NS_IMETHOD LaunchAppWithTempFile(nsIFile * aTempFile, nsISupports * aAppCookie);
NS_IMETHOD LaunchAppWithTempFile(nsIMIMEInfo *aMIMEInfo, nsIFile * aTempFile);
// override nsIExternalProtocolService methods
NS_IMETHOD ExternalProtocolHandlerExists(const char * aProtocolScheme, PRBool * aHandlerExists);
@ -52,13 +52,6 @@ public:
// aFile --> an nsIFile representation of that platform application path.
virtual nsresult GetFileTokenForPath(const PRUnichar * platformAppPath, nsIFile ** aFile);
// CreateStreamListenerWithApp --> must be implemented by each platform.
// aApplicationToUse --> the application the user wishes to launch with the incoming data
// aFileExtensionForData --> the extension we are going to use for the temp file in the external app handler
// aStreamListener --> the stream listener (really a external app handler) we're going to use for retrieving the data
virtual nsresult CreateStreamListenerWithApp(nsIFile * aApplicationToUse, const char * aFileExtensionForData, nsIStreamListener ** aStreamListener);
protected:
};