From 54b7420ef0f77b73ec503a6319d86808f0c9d29c Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Mon, 29 Jan 2007 18:36:10 +0100 Subject: [PATCH] Updated doc downloading to gecko 1.9 --- lib/src/GeckoContentHandler.cpp | 76 ++++++++++++++++++++++++++++++ lib/src/GeckoContentHandler.h | 13 +----- lib/src/GeckoDownload.cpp | 82 +++++++++++++++++++++++++++++++++ lib/src/GeckoDownload.h | 18 +------- lib/src/sugar-browser.cpp | 69 +++++++++------------------ 5 files changed, 184 insertions(+), 74 deletions(-) diff --git a/lib/src/GeckoContentHandler.cpp b/lib/src/GeckoContentHandler.cpp index 4d9de8e7..3eb70fdf 100644 --- a/lib/src/GeckoContentHandler.cpp +++ b/lib/src/GeckoContentHandler.cpp @@ -1,8 +1,22 @@ #include #include +#include #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; +} diff --git a/lib/src/GeckoContentHandler.h b/lib/src/GeckoContentHandler.h index ef6f3e2d..103166ce 100644 --- a/lib/src/GeckoContentHandler.h +++ b/lib/src/GeckoContentHandler.h @@ -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 */ diff --git a/lib/src/GeckoDownload.cpp b/lib/src/GeckoDownload.cpp index 66eb7c8f..c1b8aef0 100644 --- a/lib/src/GeckoDownload.cpp +++ b/lib/src/GeckoDownload.cpp @@ -1,7 +1,27 @@ +#include + #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; +} diff --git a/lib/src/GeckoDownload.h b/lib/src/GeckoDownload.h index 24bff544..dd788f0a 100644 --- a/lib/src/GeckoDownload.h +++ b/lib/src/GeckoDownload.h @@ -18,22 +18,8 @@ {0x96, 0x7e, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \ } -class GeckoDownload : public nsITransfer -{ -public: - GeckoDownload(); - virtual ~GeckoDownload(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWEBPROGRESSLISTENER - NS_DECL_NSIWEBPROGRESSLISTENER2 - NS_DECL_NSITRANSFER +class nsIFactory; -protected: - nsIURI *mSource; - nsCString mTargetFileName; - nsIMIMEInfo *mMIMEInfo; - nsILocalFile *mTempFile; -}; +extern "C" NS_EXPORT nsresult NS_NewGeckoDownloadFactory(nsIFactory** aFactory); #endif // __GECKO_DOWNLOAD_H__ diff --git a/lib/src/sugar-browser.cpp b/lib/src/sugar-browser.cpp index 4bbbb62f..5cc1ba9e 100644 --- a/lib/src/sugar-browser.cpp +++ b/lib/src/sugar-browser.cpp @@ -35,7 +35,6 @@ #include #include #include -#include 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,49 +112,32 @@ 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 componentRegistrar; NS_GetComponentRegistrar(getter_AddRefs(componentRegistrar)); NS_ENSURE_TRUE (componentRegistrar, FALSE); - nsCOMPtr componentManager; - NS_GetComponentManager (getter_AddRefs (componentManager)); - NS_ENSURE_TRUE (componentManager, FALSE); - - for (guint i = 0; i < G_N_ELEMENTS(sSugarComponents); i++) { - - nsCOMPtr 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); - if (NS_FAILED(rv)) { - g_warning ("Failed to register factory for %s\n", sSugarComponents[i].mDescription); - return FALSE; - } - - if (sSugarComponents[i].mRegisterSelfProc) { - rv = sSugarComponents[i].mRegisterSelfProc(componentManager, nsnull, - nsnull, nsnull, - &sSugarComponents[i]); - if (NS_FAILED(rv)) { - g_warning ("Failed to register-self for %s\n", sSugarComponents[i].mDescription); - return FALSE; - } - } + nsCOMPtr 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[0].mDescription); + return FALSE; + } + + nsCOMPtr 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 factory for %s\n", sSugarComponents[1].mDescription); + return FALSE; } -#endif - return TRUE; }