Updated doc downloading to gecko 1.9

This commit is contained in:
Tomeu Vizoso 2007-01-29 18:36:10 +01:00
parent fbdc1579f4
commit 54b7420ef0
5 changed files with 184 additions and 74 deletions

View File

@ -1,8 +1,22 @@
#include <nsCExternalHandlerService.h>
#include <nsIFile.h>
#include <nsIFactory.h>
#include "GeckoContentHandler.h"
class GeckoContentHandler : public nsIHelperAppLauncherDialog
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
GeckoContentHandler();
virtual ~GeckoContentHandler();
private:
};
GeckoContentHandler::GeckoContentHandler()
{
@ -38,3 +52,65 @@ GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
return NS_OK;
}
//*****************************************************************************
// GeckoContentHandlerFactory
//*****************************************************************************
class GeckoContentHandlerFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
GeckoContentHandlerFactory();
virtual ~GeckoContentHandlerFactory();
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(GeckoContentHandlerFactory, nsIFactory)
GeckoContentHandlerFactory::GeckoContentHandlerFactory() {
}
GeckoContentHandlerFactory::~GeckoContentHandlerFactory() {
}
NS_IMETHODIMP GeckoContentHandlerFactory::CreateInstance(nsISupports *aOuter, const nsIID & aIID, void **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = NULL;
GeckoContentHandler *inst = new GeckoContentHandler;
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = inst->QueryInterface(aIID, aResult);
if (rv != NS_OK) {
// We didn't get the right interface, so clean up
delete inst;
}
return rv;
}
NS_IMETHODIMP GeckoContentHandlerFactory::LockFactory(PRBool lock)
{
return NS_OK;
}
//*****************************************************************************
nsresult NS_NewGeckoContentHandlerFactory(nsIFactory** aFactory)
{
NS_ENSURE_ARG_POINTER(aFactory);
*aFactory = nsnull;
GeckoContentHandlerFactory *result = new GeckoContentHandlerFactory;
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aFactory = result;
return NS_OK;
}

View File

@ -12,17 +12,8 @@
{0x96, 0x7b, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \
}
class GeckoContentHandler : public nsIHelperAppLauncherDialog
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
class nsIFactory;
GeckoContentHandler();
virtual ~GeckoContentHandler();
private:
};
extern "C" NS_EXPORT nsresult NS_NewGeckoContentHandlerFactory(nsIFactory** aFactory);
#endif /* __GECKO_CONTENT_HANDLER_H */

View File

@ -1,7 +1,27 @@
#include <nsIFactory.h>
#include "sugar-download-manager.h"
#include "GeckoDownload.h"
class GeckoDownload : public nsITransfer
{
public:
GeckoDownload();
virtual ~GeckoDownload();
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIWEBPROGRESSLISTENER2
NS_DECL_NSITRANSFER
protected:
nsIURI *mSource;
nsCString mTargetFileName;
nsIMIMEInfo *mMIMEInfo;
nsILocalFile *mTempFile;
};
GeckoDownload::GeckoDownload ()
{
}
@ -127,3 +147,65 @@ GeckoDownload::OnSecurityChange (nsIWebProgress *aWebProgress,
{
return NS_OK;
}
//*****************************************************************************
// GeckoDownloadFactory
//*****************************************************************************
class GeckoDownloadFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
GeckoDownloadFactory();
virtual ~GeckoDownloadFactory();
};
//*****************************************************************************
NS_IMPL_ISUPPORTS1(GeckoDownloadFactory, nsIFactory)
GeckoDownloadFactory::GeckoDownloadFactory() {
}
GeckoDownloadFactory::~GeckoDownloadFactory() {
}
NS_IMETHODIMP GeckoDownloadFactory::CreateInstance(nsISupports *aOuter, const nsIID & aIID, void **aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = NULL;
GeckoDownload *inst = new GeckoDownload;
if (!inst)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = inst->QueryInterface(aIID, aResult);
if (rv != NS_OK) {
// We didn't get the right interface, so clean up
delete inst;
}
return rv;
}
NS_IMETHODIMP GeckoDownloadFactory::LockFactory(PRBool lock)
{
return NS_OK;
}
//*****************************************************************************
nsresult NS_NewGeckoDownloadFactory(nsIFactory** aFactory)
{
NS_ENSURE_ARG_POINTER(aFactory);
*aFactory = nsnull;
GeckoDownloadFactory *result = new GeckoDownloadFactory;
if (!result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*aFactory = result;
return NS_OK;
}

View File

@ -18,22 +18,8 @@
{0x96, 0x7e, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \
}
class GeckoDownload : public nsITransfer
{
public:
GeckoDownload();
virtual ~GeckoDownload();
class nsIFactory;
NS_DECL_ISUPPORTS
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIWEBPROGRESSLISTENER2
NS_DECL_NSITRANSFER
protected:
nsIURI *mSource;
nsCString mTargetFileName;
nsIMIMEInfo *mMIMEInfo;
nsILocalFile *mTempFile;
};
extern "C" NS_EXPORT nsresult NS_NewGeckoDownloadFactory(nsIFactory** aFactory);
#endif // __GECKO_DOWNLOAD_H__

View File

@ -35,7 +35,6 @@
#include <nsIGenericFactory.h>
#include <nsIHelperAppLauncherDialog.h>
#include <nsIComponentRegistrar.h>
#include <nsIComponentManager.h>
enum {
PROP_0,
@ -47,28 +46,21 @@ enum {
PROP_LOADING
};
#ifndef HAVE_GECKO_1_9
NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoContentHandler)
NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoDownload)
static const nsModuleComponentInfo sSugarComponents[] = {
{
"Gecko Content Handler",
GECKOCONTENTHANDLER_CID,
NS_IHELPERAPPLAUNCHERDLG_CONTRACTID,
GeckoContentHandlerConstructor
NULL
},
{
"Gecko Download",
GECKODOWNLOAD_CID,
NS_TRANSFER_CONTRACTID,
GeckoDownloadConstructor
NULL
}
};
#endif
static void
setup_plugin_path ()
{
@ -120,48 +112,31 @@ sugar_browser_startup(const char *profile_path, const char *profile_name)
g_warning ("failed to read user preferences, error: %x", rv);
}
#ifndef HAVE_GECKO_1_9
/* Register our components */
nsCOMPtr<nsIComponentRegistrar> componentRegistrar;
NS_GetComponentRegistrar(getter_AddRefs(componentRegistrar));
NS_ENSURE_TRUE (componentRegistrar, FALSE);
nsCOMPtr<nsIComponentManager> componentManager;
NS_GetComponentManager (getter_AddRefs (componentManager));
NS_ENSURE_TRUE (componentManager, FALSE);
for (guint i = 0; i < G_N_ELEMENTS(sSugarComponents); i++) {
nsCOMPtr<nsIGenericFactory> componentFactory;
rv = NS_NewGenericFactory(getter_AddRefs(componentFactory),
&(sSugarComponents[i]));
if (NS_FAILED(rv) || !componentFactory) {
g_warning ("Failed to make a factory for %s\n", sSugarComponents[i].mDescription);
return FALSE;
}
rv = componentRegistrar->RegisterFactory(sSugarComponents[i].mCID,
sSugarComponents[i].mDescription,
sSugarComponents[i].mContractID,
componentFactory);
nsCOMPtr<nsIFactory> contentHandlerFactory;
rv = NS_NewGeckoContentHandlerFactory(getter_AddRefs(contentHandlerFactory));
rv = componentRegistrar->RegisterFactory(sSugarComponents[0].mCID,
sSugarComponents[0].mDescription,
sSugarComponents[0].mContractID,
contentHandlerFactory);
if (NS_FAILED(rv)) {
g_warning ("Failed to register factory for %s\n", sSugarComponents[i].mDescription);
g_warning ("Failed to register factory for %s\n", sSugarComponents[0].mDescription);
return FALSE;
}
if (sSugarComponents[i].mRegisterSelfProc) {
rv = sSugarComponents[i].mRegisterSelfProc(componentManager, nsnull,
nsnull, nsnull,
&sSugarComponents[i]);
nsCOMPtr<nsIFactory> downloadFactory;
rv = NS_NewGeckoDownloadFactory(getter_AddRefs(downloadFactory));
rv = componentRegistrar->RegisterFactory(sSugarComponents[1].mCID,
sSugarComponents[1].mDescription,
sSugarComponents[1].mContractID,
downloadFactory);
if (NS_FAILED(rv)) {
g_warning ("Failed to register-self for %s\n", sSugarComponents[i].mDescription);
g_warning ("Failed to register factory for %s\n", sSugarComponents[1].mDescription);
return FALSE;
}
}
}
#endif
return TRUE;
}