sugar-toolkit-gtk3/browser/GeckoContentHandler.cpp

143 lines
3.3 KiB
C++
Raw Normal View History

#include <nsCExternalHandlerService.h>
#include <nsIFile.h>
2007-01-29 18:36:10 +01:00
#include <nsIFactory.h>
#include <nsILocalFile.h>
#include <nsStringAPI.h>
#include <nsComponentManagerUtils.h>
#include "GeckoContentHandler.h"
2007-01-29 18:36:10 +01:00
class GeckoContentHandler : public nsIHelperAppLauncherDialog
{
2007-01-29 20:41:15 +01:00
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
2007-01-29 18:36:10 +01:00
2007-01-29 20:41:15 +01:00
GeckoContentHandler();
virtual ~GeckoContentHandler();
2007-01-29 18:36:10 +01:00
};
GeckoContentHandler::GeckoContentHandler()
{
}
GeckoContentHandler::~GeckoContentHandler()
{
}
NS_IMPL_ISUPPORTS1(GeckoContentHandler, nsIHelperAppLauncherDialog)
NS_IMETHODIMP
GeckoContentHandler::Show (nsIHelperAppLauncher *aLauncher,
nsISupports *aContext,
PRUint32 aReason)
{
aLauncher->SaveToDisk(NULL, PR_FALSE);
return NS_OK;
}
#include <glib.h>
NS_IMETHODIMP
GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
nsISupports *aWindowContext,
const PRUnichar *aDefaultFile,
const PRUnichar *aSuggestedFileExtension,
nsILocalFile **_retval)
{
char *filename = NULL;
nsCString defaultFile;
NS_UTF16ToCString(nsString(aDefaultFile), NS_CSTRING_ENCODING_UTF8, defaultFile);
2007-03-15 11:11:44 +01:00
nsCOMPtr <nsILocalFile> destFile(do_CreateInstance("@mozilla.org/file/local;1"));
NS_ENSURE_TRUE(destFile, NS_ERROR_FAILURE);
const char * suggested = defaultFile.get();
if (strlen(suggested) > 0) {
filename = g_build_path("/", g_get_tmp_dir (), suggested, NULL);
} else {
filename = tempnam(NULL, NULL);
}
if (filename == NULL)
return NS_ERROR_OUT_OF_MEMORY;
destFile->InitWithNativePath(nsCString(filename));
g_free(filename);
NS_IF_ADDREF(*_retval = destFile);
return NS_OK;
}
2007-01-29 18:36:10 +01:00
//*****************************************************************************
// GeckoContentHandlerFactory
//*****************************************************************************
class GeckoContentHandlerFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
GeckoContentHandlerFactory();
virtual ~GeckoContentHandlerFactory();
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(GeckoContentHandlerFactory, nsIFactory)
GeckoContentHandlerFactory::GeckoContentHandlerFactory() {
}
GeckoContentHandlerFactory::~GeckoContentHandlerFactory() {
}
2007-01-29 20:41:15 +01:00
NS_IMETHODIMP
GeckoContentHandlerFactory::CreateInstance(nsISupports *aOuter,
const nsIID & aIID,
void **aResult)
2007-01-29 18:36:10 +01:00
{
2007-01-29 20:41:15 +01:00
NS_ENSURE_ARG_POINTER(aResult);
2007-01-29 18:36:10 +01:00
2007-01-29 20:41:15 +01:00
*aResult = NULL;
GeckoContentHandler *inst = new GeckoContentHandler;
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
2007-01-29 18:36:10 +01:00
2007-01-29 20:41:15 +01:00
nsresult rv = inst->QueryInterface(aIID, aResult);
if (rv != NS_OK) {
// We didn't get the right interface, so clean up
delete inst;
}
2007-01-29 18:36:10 +01:00
2007-01-29 20:41:15 +01:00
return rv;
2007-01-29 18:36:10 +01:00
}
2007-01-29 20:41:15 +01:00
NS_IMETHODIMP
GeckoContentHandlerFactory::LockFactory(PRBool lock)
2007-01-29 18:36:10 +01:00
{
2007-01-29 20:41:15 +01:00
return NS_OK;
2007-01-29 18:36:10 +01:00
}
//*****************************************************************************
2007-01-29 20:41:15 +01:00
nsresult
NS_NewGeckoContentHandlerFactory(nsIFactory** aFactory)
2007-01-29 18:36:10 +01:00
{
2007-01-29 20:41:15 +01:00
NS_ENSURE_ARG_POINTER(aFactory);
*aFactory = nsnull;
2007-01-29 18:36:10 +01:00
2007-01-29 20:41:15 +01:00
GeckoContentHandlerFactory *result = new GeckoContentHandlerFactory;
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
2007-01-29 18:36:10 +01:00
2007-01-29 20:41:15 +01:00
NS_ADDREF(result);
*aFactory = result;
2007-01-29 18:36:10 +01:00
2007-01-29 20:41:15 +01:00
return NS_OK;
2007-01-29 18:36:10 +01:00
}