diff options
-rw-r--r-- | activities/web/webactivity.py | 3 | ||||
-rw-r--r-- | lib/python/_sugar.defs | 2 | ||||
-rw-r--r-- | lib/src/Makefile.am | 4 | ||||
-rw-r--r-- | lib/src/sugar-browser.cpp | 60 | ||||
-rw-r--r-- | lib/src/sugar-browser.h | 2 | ||||
-rw-r--r-- | lib/src/sugar-content-handler.cpp | 36 | ||||
-rw-r--r-- | lib/src/sugar-content-handler.h | 28 |
7 files changed, 128 insertions, 7 deletions
diff --git a/activities/web/webactivity.py b/activities/web/webactivity.py index d96f412..372fad4 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 1548d6f..a720fee 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 9dc7455..688170a 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 1d9efc7..3ba7fdc 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 <gtkmozembed_internal.h> #include <nsCOMPtr.h> @@ -26,6 +27,12 @@ #include <nsIWebBrowser.h> #include <nsIWebBrowserFocus.h> #include <nsIDOMWindow.h> +#include <nsIGenericFactory.h> +#include <nsIHelperAppLauncherDialog.h> +#include <nsIComponentRegistrar.h> +#include <nsIComponentManager.h> + +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<nsIPrefService> prefService; + nsresult rv; prefService = do_GetService(NS_PREFSERVICE_CONTRACTID); - NS_ENSURE_TRUE(prefService, ); + NS_ENSURE_TRUE(prefService, FALSE); nsCOMPtr<nsIPrefBranch> 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<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); + + nsCOMPtr<nsIGenericFactory> 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 a60889f..cec5f9f 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 0000000..56fe587 --- /dev/null +++ b/lib/src/sugar-content-handler.cpp @@ -0,0 +1,36 @@ +#include <stdio.h> + +#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 0000000..da5ae40 --- /dev/null +++ b/lib/src/sugar-content-handler.h @@ -0,0 +1,28 @@ +#ifndef __SUGAR_CONTENT_HANDLER_H__ +#define __SUGAR_CONTENT_HANDLER_H__ + +#include <nsCOMPtr.h> +#include <nsIHelperAppLauncherDialog.h> + +#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 */ |