Fixed components initialization
authorromashin
Sat, 19 Apr 2008 18:37:10 +0300
changeset 16798 a7daf5a96c25bd6cb3267f1ee518695b8d5851dd
parent 16797 26414f2c3299545d246c414a0b4fe399532807cd
child 16799 f8ed893486d261d45d900bdfe599ed9a7070d167
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
milestone2.0a1pre
Fixed components initialization
embedding/browser/qt/src/qgeckoglobals.cpp
--- a/embedding/browser/qt/src/qgeckoglobals.cpp
+++ b/embedding/browser/qt/src/qgeckoglobals.cpp
@@ -152,16 +152,19 @@ static const nsModuleComponentInfo defau
     "@mozilla.org/embedcomp/prompt-service;1",
     QtPromptServiceConstructor
   }
 };
 #else
 static const nsModuleComponentInfo defaultAppComps[] = {};
 #endif
 
+const nsModuleComponentInfo *QGeckoGlobals::sAppComps = defaultAppComps;
+int   QGeckoGlobals::sNumAppComps = sizeof(defaultAppComps) / sizeof(nsModuleComponentInfo);
+
 void
 QGeckoGlobals::pushStartup()
 {
     // increment the number of widgets
     sWidgetCount++;
 
     // if this is the first widget, fire up xpcom
     if (sWidgetCount == 1) {
@@ -249,19 +252,21 @@ QGeckoGlobals::setCompPath(const char *a
         free(sCompPath);
     if (aPath)
         sCompPath = strdup(aPath);
     else
         sCompPath = nsnull;
 }
 
 void
-QGeckoGlobals::setAppComponents(const nsModuleComponentInfo *,
-                             int)
+QGeckoGlobals::setAppComponents(const nsModuleComponentInfo *aComps,
+                                int aNumComponents)
 {
+  sAppComps = aComps;
+  sNumAppComps = aNumComponents;
 }
 
 void
 QGeckoGlobals::setProfilePath(const char *aDir, const char *aName)
 {
     if (sProfileDir) {
         if (sWidgetCount) {
             NS_ERROR("Cannot change profile directory during run.");
@@ -312,36 +317,46 @@ QGeckoGlobals::setDirectoryServiceProvid
         NS_ADDREF(sAppFileLocProvider);
     }
 }
 
 /* static */
 int
 QGeckoGlobals::registerAppComponents()
 {
-  nsCOMPtr<nsIComponentRegistrar> cr;
-  nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
-  NS_ENSURE_SUCCESS(rv, rv);
+    nsCOMPtr<nsIComponentRegistrar> cr;
+    nsresult rv = NS_GetComponentRegistrar(getter_AddRefs(cr));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    nsCOMPtr<nsIComponentManager> cm;
+    rv = NS_GetComponentManager (getter_AddRefs (cm));
+    NS_ENSURE_SUCCESS (rv, rv);
 
-  int numAppComps = sizeof(defaultAppComps) / sizeof(nsModuleComponentInfo);
-  for (int i = 0; i < numAppComps; ++i) {
-    nsCOMPtr<nsIGenericFactory> componentFactory;
-    rv = NS_NewGenericFactory(getter_AddRefs(componentFactory),
-                              &(defaultAppComps[i]));
-    if (NS_FAILED(rv)) {
-      NS_WARNING("Unable to create factory for component");
-      continue;  // don't abort registering other components
+    for (int i = 0; i < sNumAppComps; ++i) {
+        nsCOMPtr<nsIGenericFactory> 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");
+        }
     }
 
-    rv = cr->RegisterFactory(defaultAppComps[i].mCID, defaultAppComps[i].mDescription,
-                             defaultAppComps[i].mContractID, componentFactory);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to register factory for component");
-  }
-
-  return rv;
+    return rv;
 }
 
 void QGeckoGlobals::initializeGlobalObjects()
 {
     if (!sWindowList) {
         sWindowList = new nsVoidArray();
     }
 }