Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2007-01-29 17:36:10 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2007-01-29 17:36:10 (GMT)
commit54b7420ef0f77b73ec503a6319d86808f0c9d29c (patch)
tree37856f30105bffb7bdbaebc8011e6835248846f7 /lib
parentfbdc1579f487b094bfe2a4368db44cbbb2c086b2 (diff)
Updated doc downloading to gecko 1.9
Diffstat (limited to 'lib')
-rw-r--r--lib/src/GeckoContentHandler.cpp76
-rw-r--r--lib/src/GeckoContentHandler.h13
-rw-r--r--lib/src/GeckoDownload.cpp82
-rw-r--r--lib/src/GeckoDownload.h18
-rw-r--r--lib/src/sugar-browser.cpp67
5 files changed, 183 insertions, 73 deletions
diff --git a/lib/src/GeckoContentHandler.cpp b/lib/src/GeckoContentHandler.cpp
index 4d9de8e..3eb70fd 100644
--- a/lib/src/GeckoContentHandler.cpp
+++ b/lib/src/GeckoContentHandler.cpp
@@ -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;
+}
diff --git a/lib/src/GeckoContentHandler.h b/lib/src/GeckoContentHandler.h
index ef6f3e2..103166c 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 66eb7c8..c1b8aef 100644
--- a/lib/src/GeckoDownload.cpp
+++ b/lib/src/GeckoDownload.cpp
@@ -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;
+}
diff --git a/lib/src/GeckoDownload.h b/lib/src/GeckoDownload.h
index 24bff54..dd788f0 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 4bbbb62..5cc1ba9 100644
--- a/lib/src/sugar-browser.cpp
+++ b/lib/src/sugar-browser.cpp
@@ -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,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<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);
- if (NS_FAILED(rv)) {
- g_warning ("Failed to register factory for %s\n", sSugarComponents[i].mDescription);
- return FALSE;
- }
+ 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[0].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<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 factory for %s\n", sSugarComponents[1].mDescription);
+ return FALSE;
}
-#endif
-
return TRUE;
}