2000-06-17 01:35:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Mozilla browser.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications, Inc. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Scott MacGregor <mscott@netscape.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsExternalHelperAppService.h"
|
|
|
|
#include "nsIURI.h"
|
2000-06-17 04:06:26 +04:00
|
|
|
#include "nsIURL.h"
|
2000-06-17 01:35:13 +04:00
|
|
|
#include "nsIFile.h"
|
2000-06-17 04:06:26 +04:00
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2000-06-17 01:35:13 +04:00
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsExternalHelperAppService)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsExternalHelperAppService)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsExternalHelperAppService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIExternalHelperAppService)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIExternalHelperAppService)
|
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
|
|
|
nsExternalHelperAppService::nsExternalHelperAppService()
|
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsExternalHelperAppService::~nsExternalHelperAppService()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* boolean canHandleContent (in string aMimeContentType); */
|
2000-06-17 04:06:26 +04:00
|
|
|
NS_IMETHODIMP nsExternalHelperAppService::CanHandleContent(const char *aMimeContentType, nsIURI * aURI, PRBool *_retval)
|
2000-06-17 01:35:13 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* nsIStreamListener doContent (in string aMimeContentType, in nsIURI aURI, in nsISupports aWindowContext, out boolean aAbortProcess); */
|
|
|
|
NS_IMETHODIMP nsExternalHelperAppService::DoContent(const char *aMimeContentType, nsIURI *aURI, nsISupports *aWindowContext, PRBool *aAbortProcess, nsIStreamListener **_retval)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2000-06-17 04:06:26 +04:00
|
|
|
nsExternalAppHandler * nsExternalHelperAppService::CreateNewExternalHandler()
|
|
|
|
{
|
|
|
|
nsExternalAppHandler* handler = nsnull;
|
|
|
|
NS_NEWXPCOM(handler, nsExternalAppHandler);
|
|
|
|
// add any XP intialization code for an external handler that we may need here...
|
|
|
|
// right now we don't have any but i bet we will before we are done.
|
|
|
|
return handler;
|
|
|
|
}
|
|
|
|
|
2000-06-17 01:35:13 +04:00
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// begin external app handler implementation
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsExternalAppHandler)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsExternalAppHandler)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsExternalAppHandler)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStreamListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamObserver)
|
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
|
|
|
nsExternalAppHandler::nsExternalAppHandler()
|
|
|
|
{
|
|
|
|
NS_INIT_ISUPPORTS();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsExternalAppHandler::~nsExternalAppHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIChannel * aChannel, nsISupports * aCtxt)
|
|
|
|
{
|
2000-06-17 04:06:26 +04:00
|
|
|
NS_ENSURE_ARG(aChannel);
|
|
|
|
|
2000-06-17 01:35:13 +04:00
|
|
|
// create a temp file for the data...and open it for writing.
|
2000-06-17 04:06:26 +04:00
|
|
|
NS_GetSpecialDirectory("system.OS_TemporaryDirectory", getter_AddRefs(mTempFile));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
aChannel->GetURI(getter_AddRefs(uri));
|
|
|
|
nsCOMPtr<nsIURL> url = do_QueryInterface(uri);
|
|
|
|
|
|
|
|
if (url)
|
|
|
|
{
|
|
|
|
// try to extract the file name from the url and use that as a first pass as the
|
|
|
|
// leaf name of our temp file...
|
|
|
|
nsXPIDLCString leafName;
|
|
|
|
url->GetFileName(getter_Copies(leafName));
|
|
|
|
if (leafName)
|
|
|
|
{
|
|
|
|
mTempFile->Append(leafName); // WARNING --> neeed a make Unique routine on nsIFile!!
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mTempFile->Append("test.tmp"); // WARNING THIS IS TEMPORARY CODE!!!
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mTempFile->Append("test.tmp"); // WARNING THIS IS TEMPORARY CODE!!!
|
|
|
|
|
2000-06-17 06:34:44 +04:00
|
|
|
nsCOMPtr<nsIFileChannel> mFileChannel = do_CreateInstance(NS_LOCALFILECHANNEL_PROGID);
|
|
|
|
if (mFileChannel)
|
|
|
|
{
|
|
|
|
mFileChannel->Init(mTempFile, nsIFileChannel::NS_WRONLY || nsIFileChannel::NS_TRUNCATE, 0);
|
|
|
|
nsCOMPtr<nsIOutputStream> outStream;
|
|
|
|
mFileChannel->OpenOutputStream(getter_AddRefs(outStream));
|
|
|
|
mbufferOutStream = do_QueryInterface(outStream);
|
|
|
|
}
|
|
|
|
|
2000-06-17 01:35:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExternalAppHandler::OnDataAvailable(nsIChannel * aChannel, nsISupports * aCtxt,
|
|
|
|
nsIInputStream * inStr, PRUint32 sourceOffset, PRUint32 count)
|
|
|
|
{
|
|
|
|
// read the data out of the stream and write it to the temp file.
|
2000-06-17 06:34:44 +04:00
|
|
|
PRUint32 numBytesRead = 0;
|
|
|
|
if (mbufferOutStream)
|
|
|
|
mbufferOutStream->WriteFrom(inStr, count, &numBytesRead);
|
2000-06-17 01:35:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsExternalAppHandler::OnStopRequest(nsIChannel * aChannel, nsISupports *aCtxt,
|
|
|
|
nsresult aStatus, const PRUnichar * errorMsg)
|
|
|
|
{
|
|
|
|
// go ahead and execute the application passing in our temp file as an argument
|
2000-06-17 04:06:26 +04:00
|
|
|
// this may involve us calling back into the OS external app service to make the call
|
|
|
|
// for actually launching the helper app. It'd be great if nsIFile::spawn could be made to work
|
|
|
|
// on the mac...right now the mac implementation ignores all arguments passed in.
|
2000-06-17 06:34:44 +04:00
|
|
|
|
|
|
|
// close the stream...
|
|
|
|
if (mbufferOutStream)
|
|
|
|
mbufferOutStream->Close();
|
|
|
|
|
2000-06-17 01:35:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-17 06:34:44 +04:00
|
|
|
nsresult nsExternalAppHandler::Init(nsIFile * aExternalApplication)
|
|
|
|
{
|
|
|
|
mExternalApplication = aExternalApplication;
|
|
|
|
return NS_OK;
|
|
|
|
}
|