From 0e097589ebfe2102182b060c258718ab97b5ba2b Mon Sep 17 00:00:00 2001 From: Benjamin Smedberg Date: Sat, 12 Jun 2010 20:50:29 -0400 Subject: [PATCH] Bug 568691 - Fix up gtkmozembed for static XPCOM registration --- embedding/browser/gtk/src/EmbedPrivate.cpp | 79 +++++-------------- embedding/browser/gtk/src/EmbedPrivate.h | 10 +-- embedding/browser/gtk/src/gtkmozembed2.cpp | 7 -- .../browser/gtk/src/gtkmozembed_glue.cpp | 3 +- .../browser/gtk/src/gtkmozembed_internal.h | 4 - 5 files changed, 23 insertions(+), 80 deletions(-) diff --git a/embedding/browser/gtk/src/EmbedPrivate.cpp b/embedding/browser/gtk/src/EmbedPrivate.cpp index 16a6d8d1406..57fd9b15e85 100644 --- a/embedding/browser/gtk/src/EmbedPrivate.cpp +++ b/embedding/browser/gtk/src/EmbedPrivate.cpp @@ -67,10 +67,6 @@ // For seting scrollbar visibilty #include "nsIDOMBarProp.h" -// app component registration -#include "nsIGenericFactory.h" -#include "nsIComponentRegistrar.h" - // all of our local includes #include "EmbedPrivate.h" #include "EmbedWindow.h" @@ -80,6 +76,8 @@ #include "EmbedWindowCreator.h" #include "GtkPromptService.h" +#include "mozilla/ModuleUtils.h" + #ifdef MOZ_ACCESSIBILITY_ATK #include "nsIAccessibilityService.h" #include "nsIAccessible.h" @@ -161,18 +159,23 @@ GTKEmbedDirectoryProvider::GetFiles(const char *aKey, {0x95611356, 0xf583, 0x46f5, {0x81, 0xff, 0x4b, 0x3e, 0x01, 0x62, 0xc6, 0x19}} NS_GENERIC_FACTORY_CONSTRUCTOR(GtkPromptService) +NS_DEFINE_NAMED_CID(NS_PROMPTSERVICE_CID); -static const nsModuleComponentInfo defaultAppComps[] = { - { - "Prompt Service", - NS_PROMPTSERVICE_CID, - "@mozilla.org/embedcomp/prompt-service;1", - GtkPromptServiceConstructor - } +static const mozilla::Module::CIDEntry kDefaultPromptCIDs[] = { + { &kNS_PROMPTSERVICE_CID, false, NULL, GtkPromptServiceConstructor }, + { NULL } }; -const nsModuleComponentInfo *EmbedPrivate::sAppComps = defaultAppComps; -int EmbedPrivate::sNumAppComps = sizeof(defaultAppComps) / sizeof(nsModuleComponentInfo); +static const mozilla::Module::ContractIDEntry kDefaultPromptContracts[] = { + { "@mozilla.org/embedcomp/prompt-service;1", &kNS_PROMPTSERVICE_CID }, + { NULL } +}; + +static const mozilla::Module kDefaultPromptModule = { + mozilla::Module::kVersion, + kDefaultPromptCIDs, + kDefaultPromptContracts +}; EmbedPrivate::EmbedPrivate(void) { @@ -531,17 +534,15 @@ EmbedPrivate::PushStartup(void) if (NS_FAILED(rv)) return; } - rv = XRE_InitEmbedding(greDir, binDir, - const_cast(&kDirectoryProvider), - nsnull, nsnull); + rv = XRE_InitEmbedding2(greDir, binDir, + const_cast(&kDirectoryProvider)); if (NS_FAILED(rv)) return; if (sProfileDir) XRE_NotifyProfile(); - rv = RegisterAppComponents(); - NS_ASSERTION(NS_SUCCEEDED(rv), "Warning: Failed to register app components.\n"); + RegisterAppComponents(); } } @@ -592,15 +593,6 @@ EmbedPrivate::SetCompPath(const char *aPath) sCompPath = nsnull; } -/* static */ -void -EmbedPrivate::SetAppComponents(const nsModuleComponentInfo* aComps, - int aNumComponents) -{ - sAppComps = aComps; - sNumAppComps = aNumComponents; -} - /* static */ void EmbedPrivate::SetProfilePath(const char *aDir, const char *aName) @@ -961,39 +953,10 @@ EmbedPrivate::GetAtkObjectForCurrentDocument() #endif /* MOZ_ACCESSIBILITY_ATK */ /* static */ -nsresult +void EmbedPrivate::RegisterAppComponents(void) { - nsCOMPtr cr; - nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr cm; - rv = NS_GetComponentManager (getter_AddRefs (cm)); - NS_ENSURE_SUCCESS (rv, rv); - - for (int i = 0; i < sNumAppComps; ++i) { - nsCOMPtr componentFactory; - rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), - &(sAppComps[i])); - if (NS_FAILED(rv)) { - NS_WARNING("Unable to create factory for component"); - continue; // don't abort registering other components - } - - rv = cr->RegisterFactory(sAppComps[i].mCID, sAppComps[i].mDescription, - sAppComps[i].mContractID, componentFactory); - NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to register factory for component"); - - // Call the registration hook of the component, if any - if (sAppComps[i].mRegisterSelfProc) { - rv = sAppComps[i].mRegisterSelfProc(cm, nsnull, nsnull, nsnull, - &(sAppComps[i])); - NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to self-register component"); - } - } - - return rv; + XRE_AddStaticComponent(&kDefaultPromptModule); } /* static */ diff --git a/embedding/browser/gtk/src/EmbedPrivate.h b/embedding/browser/gtk/src/EmbedPrivate.h index 1c272c3a9b0..01ae8814281 100644 --- a/embedding/browser/gtk/src/EmbedPrivate.h +++ b/embedding/browser/gtk/src/EmbedPrivate.h @@ -48,9 +48,6 @@ #include "nsIAppShell.h" #include "nsPIDOMEventTarget.h" #include "nsTArray.h" -// app component registration -#include "nsIGenericFactory.h" -#include "nsIComponentRegistrar.h" #include "gtkmozembedprivate.h" @@ -87,8 +84,6 @@ class EmbedPrivate { static void PopStartup (void); static void SetPath (const char *aPath); static void SetCompPath (const char *aPath); - static void SetAppComponents (const nsModuleComponentInfo* aComps, - int aNumComponents); static void SetProfilePath (const char *aDir, const char *aName); static void SetDirectoryServiceProvider (nsIDirectoryServiceProvider * appFileLocProvider); @@ -147,9 +142,6 @@ class EmbedPrivate { static char *sPath; // the path to components static char *sCompPath; - // the list of application-specific components to register - static const nsModuleComponentInfo *sAppComps; - static int sNumAppComps; // the appshell we have created static nsIAppShell *sAppShell; // the list of all open windows @@ -183,7 +175,7 @@ class EmbedPrivate { // this will get the PIDOMWindow for this widget nsresult GetPIDOMWindow (nsPIDOMWindow **aPIWin); - static nsresult RegisterAppComponents(); + static void RegisterAppComponents(); // offscreen window methods and the offscreen widget static void EnsureOffscreenWindow(void); diff --git a/embedding/browser/gtk/src/gtkmozembed2.cpp b/embedding/browser/gtk/src/gtkmozembed2.cpp index 4792ef6ab30..4138bfc34b4 100644 --- a/embedding/browser/gtk/src/gtkmozembed2.cpp +++ b/embedding/browser/gtk/src/gtkmozembed2.cpp @@ -661,13 +661,6 @@ gtk_moz_embed_set_comp_path(const char *aPath) EmbedPrivate::SetCompPath(aPath); } -void -gtk_moz_embed_set_app_components(const nsModuleComponentInfo* aComps, - int aNumComponents) -{ - EmbedPrivate::SetAppComponents(aComps, aNumComponents); -} - void gtk_moz_embed_set_profile_path(const char *aDir, const char *aName) { diff --git a/embedding/browser/gtk/src/gtkmozembed_glue.cpp b/embedding/browser/gtk/src/gtkmozembed_glue.cpp index 85b8c59779e..1cd53bd8fc5 100644 --- a/embedding/browser/gtk/src/gtkmozembed_glue.cpp +++ b/embedding/browser/gtk/src/gtkmozembed_glue.cpp @@ -80,8 +80,7 @@ GTKF(gtk_moz_embed_get_title_unichar) \ GTKF(gtk_moz_embed_get_js_status_unichar) \ GTKF(gtk_moz_embed_get_link_message_unichar) \ - GTKF(gtk_moz_embed_set_directory_service_provider) \ - GTKF(gtk_moz_embed_set_app_components) + GTKF(gtk_moz_embed_set_directory_service_provider) #define GTKF(fname) fname##Type fname; diff --git a/embedding/browser/gtk/src/gtkmozembed_internal.h b/embedding/browser/gtk/src/gtkmozembed_internal.h index d2fb2dd00e8..1ebbc6ebc2a 100644 --- a/embedding/browser/gtk/src/gtkmozembed_internal.h +++ b/embedding/browser/gtk/src/gtkmozembed_internal.h @@ -62,10 +62,6 @@ GTKMOZEMBED_API(PRUnichar*, GTKMOZEMBED_API(void, gtk_moz_embed_set_directory_service_provider, (nsIDirectoryServiceProvider *appFileLocProvider)) -GTKMOZEMBED_API(void, - gtk_moz_embed_set_app_components, (const nsModuleComponentInfo *aComps, - int aNumComps)) - #ifdef __cplusplus } #endif /* __cplusplus */