From 15e3a4f7914984422af0086cadc5bcea5a14f34a Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 25 Oct 2006 10:18:43 +0200 Subject: [PATCH] Register a nsIHelperAppLauncherDialog to handle docs out of gtkmozembed (pdfs, ...) --- activities/web/webactivity.py | 3 +- lib/python/_sugar.defs | 2 +- lib/src/Makefile.am | 4 ++- lib/src/sugar-browser.cpp | 60 +++++++++++++++++++++++++++++-- lib/src/sugar-browser.h | 2 +- lib/src/sugar-content-handler.cpp | 36 +++++++++++++++++++ lib/src/sugar-content-handler.h | 28 +++++++++++++++ 7 files changed, 128 insertions(+), 7 deletions(-) create mode 100644 lib/src/sugar-content-handler.cpp create mode 100644 lib/src/sugar-content-handler.h diff --git a/activities/web/webactivity.py b/activities/web/webactivity.py index d96f412e..372fad40 100644 --- a/activities/web/webactivity.py +++ b/activities/web/webactivity.py @@ -98,7 +98,8 @@ def start(): gtkmozembed.set_profile_path(env.get_profile_path(), 'gecko') gtkmozembed.push_startup() - _sugar.startup_browser() + if not _sugar.startup_browser(): + raise "Error when initializising the web activity." style.load_stylesheet(web.stylesheet) diff --git a/lib/python/_sugar.defs b/lib/python/_sugar.defs index 1548d6ff..a720fee5 100644 --- a/lib/python/_sugar.defs +++ b/lib/python/_sugar.defs @@ -56,7 +56,7 @@ (define-function startup_browser (c-name "sugar_browser_startup") - (return-type "none") + (return-type "gboolean") ) (define-method grab_focus diff --git a/lib/src/Makefile.am b/lib/src/Makefile.am index 9dc7455e..688170a9 100644 --- a/lib/src/Makefile.am +++ b/lib/src/Makefile.am @@ -20,7 +20,9 @@ libsugarprivate_la_SOURCES = \ sugar-push-scroller.c \ sugar-push-scroller.h \ sugar-tray-manager.c \ - sugar-tray-manager.h + sugar-tray-manager.h \ + sugar-content-handler.h \ + sugar-content-handler.cpp BUILT_SOURCES = \ sugar-marshal.c \ diff --git a/lib/src/sugar-browser.cpp b/lib/src/sugar-browser.cpp index 1d9efc7c..3ba7fdcf 100644 --- a/lib/src/sugar-browser.cpp +++ b/lib/src/sugar-browser.cpp @@ -18,6 +18,7 @@ */ #include "sugar-browser.h" +#include "sugar-content-handler.h" #include #include @@ -26,6 +27,12 @@ #include #include #include +#include +#include +#include +#include + +NS_GENERIC_FACTORY_CONSTRUCTOR(GSugarContentHandler) enum { PROP_0, @@ -37,17 +44,27 @@ enum { PROP_LOADING }; -void +static const nsModuleComponentInfo sSugarComponents[] = { + { + "Sugar Content Handler", + G_SUGARCONTENTHANDLER_CID, + NS_IHELPERAPPLAUNCHERDLG_CONTRACTID, + GSugarContentHandlerConstructor + } +}; + +gboolean sugar_browser_startup(void) { nsCOMPtr prefService; + nsresult rv; prefService = do_GetService(NS_PREFSERVICE_CONTRACTID); - NS_ENSURE_TRUE(prefService, ); + NS_ENSURE_TRUE(prefService, FALSE); nsCOMPtr pref; prefService->GetBranch("", getter_AddRefs(pref)); - NS_ENSURE_TRUE(pref, ); + NS_ENSURE_TRUE(pref, FALSE); /* Block onload popups */ pref->SetBoolPref("dom.disable_open_during_load", TRUE); @@ -60,6 +77,43 @@ sugar_browser_startup(void) pref->SetCharPref("ui.buttonface", "#D3D3DD"); pref->SetCharPref("ui.-moz-field", "#FFFFFF"); pref->SetCharPref("ui.-moz-fieldtext", "#000000"); + + nsCOMPtr componentRegistrar; + NS_GetComponentRegistrar(getter_AddRefs(componentRegistrar)); + NS_ENSURE_TRUE (componentRegistrar, FALSE); + + nsCOMPtr componentManager; + NS_GetComponentManager (getter_AddRefs (componentManager)); + NS_ENSURE_TRUE (componentManager, FALSE); + + nsCOMPtr componentFactory; + rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), + &(sSugarComponents[0])); + if (NS_FAILED(rv) || !componentFactory) { + g_warning ("Failed to make a factory for %s\n", sSugarComponents[0].mDescription); + return FALSE; + } + + rv = componentRegistrar->RegisterFactory(sSugarComponents[0].mCID, + sSugarComponents[0].mDescription, + sSugarComponents[0].mContractID, + componentFactory); + if (NS_FAILED(rv)) { + g_warning ("Failed to register factory for %s\n", sSugarComponents[0].mDescription); + return FALSE; + } + + if (sSugarComponents[0].mRegisterSelfProc) { + rv = sSugarComponents[0].mRegisterSelfProc(componentManager, nsnull, + nsnull, nsnull, + &sSugarComponents[0]); + if (NS_FAILED(rv)) { + g_warning ("Failed to register-self for %s\n", sSugarComponents[0].mDescription); + return FALSE; + } + } + + return TRUE; } G_DEFINE_TYPE(SugarBrowser, sugar_browser, GTK_TYPE_MOZ_EMBED) diff --git a/lib/src/sugar-browser.h b/lib/src/sugar-browser.h index a60889f0..cec5f9f1 100644 --- a/lib/src/sugar-browser.h +++ b/lib/src/sugar-browser.h @@ -54,7 +54,7 @@ struct _SugarBrowserClass { }; GType sugar_browser_get_type (void); -void sugar_browser_startup (void); +gboolean sugar_browser_startup (void); SugarBrowser *sugar_browser_create_window (SugarBrowser *browser); void sugar_browser_scroll_pixels (SugarBrowser *browser, int dx, diff --git a/lib/src/sugar-content-handler.cpp b/lib/src/sugar-content-handler.cpp new file mode 100644 index 00000000..56fe587f --- /dev/null +++ b/lib/src/sugar-content-handler.cpp @@ -0,0 +1,36 @@ +#include + +#include "sugar-content-handler.h" + +GSugarContentHandler::GSugarContentHandler() +{ + +} + +GSugarContentHandler::~GSugarContentHandler() +{ + +} + +NS_IMPL_ISUPPORTS1(GSugarContentHandler, nsIHelperAppLauncherDialog) + +NS_IMETHODIMP +GSugarContentHandler::Show (nsIHelperAppLauncher *aLauncher, + nsISupports *aContext, + PRUint32 aReason) +{ + + return NS_OK; +} + +NS_IMETHODIMP GSugarContentHandler::PromptForSaveToFile( + nsIHelperAppLauncher *aLauncher, + nsISupports *aWindowContext, + const PRUnichar *aDefaultFile, + const PRUnichar *aSuggestedFileExtension, + nsILocalFile **_retval) +{ + + return NS_OK; +} + diff --git a/lib/src/sugar-content-handler.h b/lib/src/sugar-content-handler.h new file mode 100644 index 00000000..da5ae408 --- /dev/null +++ b/lib/src/sugar-content-handler.h @@ -0,0 +1,28 @@ +#ifndef __SUGAR_CONTENT_HANDLER_H__ +#define __SUGAR_CONTENT_HANDLER_H__ + +#include +#include + +#define G_SUGARCONTENTHANDLER_CID \ +{ /* 2321843e-6377-11db-967b-00e08161165f */ \ + 0x2321843e, \ + 0x6377, \ + 0x11db, \ + {0x96, 0x7b, 0x0, 0xe0, 0x81, 0x61, 0x16, 0x5f} \ +} + +class GSugarContentHandler : public nsIHelperAppLauncherDialog +{ + public: + NS_DECL_ISUPPORTS + NS_DECL_NSIHELPERAPPLAUNCHERDIALOG + + GSugarContentHandler(); + virtual ~GSugarContentHandler(); + + private: + +}; + +#endif /* __SUGAR_CONTENT_HANDLER_H */