Fix to only broadcast to the autoreg observer if we are really registering.

git-svn-id: svn://10.0.0.236/trunk@70236 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
sfraser%netscape.com
2000-05-17 01:54:18 +00:00
parent c12dfc2263
commit 7ae6aff2d5

View File

@@ -572,22 +572,7 @@ mozJSComponentLoader::AutoRegisterComponent(PRInt32 when,
fprintf(stderr, "mJCL: registering JS component %s\n",
(const char *)leafName);
#endif
// Notify observers, if any, of autoregistration work
NS_WITH_SERVICE (nsIObserverService, observerService, NS_OBSERVERSERVICE_PROGID, &rv);
if (NS_SUCCEEDED(rv))
{
nsIServiceManager *mgr; // NO COMPtr as we dont release the service manager
rv = nsServiceManager::GetGlobalServiceManager(&mgr);
if (NS_SUCCEEDED(rv))
{
nsAutoString topic; // This is quite ineficient, but is how it is
// done in every other example.
topic.AssignWithConversion(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID);
(void) observerService->Notify(mgr, topic.GetUnicode(), sJSComponentReg);
}
}
rv = AttemptRegistration(component, PR_FALSE);
#ifdef DEBUG_shaver
if (NS_SUCCEEDED(rv))
@@ -629,20 +614,6 @@ mozJSComponentLoader::AutoUnregisterComponent(PRInt32 when,
if (len < jsExtensionLen || // too short
PL_strcasecmp(leafName + len - jsExtensionLen, jsExtension))
return NS_OK;
// Notify observers, if any, of autoregistration work
NS_WITH_SERVICE (nsIObserverService, observerService, NS_OBSERVERSERVICE_PROGID, &rv);
if (NS_SUCCEEDED(rv))
{
nsIServiceManager *mgr; // NO COMPtr as we dont release the service manager
rv = nsServiceManager::GetGlobalServiceManager(&mgr);
if (NS_SUCCEEDED(rv))
{
nsAutoString topic; // This is quite ineficient, but is how it is
// done in every other example.
topic.AssignWithConversion(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID);
(void) observerService->Notify(mgr, topic.GetUnicode(), sJSComponentUnreg);
}
}
rv = UnregisterComponent(component);
#ifdef DEBUG_dp
@@ -676,6 +647,36 @@ mozJSComponentLoader::AttemptRegistration(nsIFile *component,
if (!module)
goto out;
{
// Notify observers, if any, of autoregistration work
NS_WITH_SERVICE (nsIObserverService, observerService, NS_OBSERVERSERVICE_PROGID, &rv);
if (NS_SUCCEEDED(rv))
{
nsIServiceManager *mgr; // NO COMPtr as we dont release the service manager
rv = nsServiceManager::GetGlobalServiceManager(&mgr);
if (NS_SUCCEEDED(rv))
{
// this string can't come from a string bundle, because we don't have string
// bundles yet.
NS_ConvertASCIItoUCS2 statusMsg("Registering JS component ");
NS_ConvertASCIItoUCS2 fileName("(no name)");
// get the file name
if (component)
{
nsXPIDLCString leafName;
component->GetLeafName(getter_Copies(leafName));
fileName.AssignWithConversion(leafName);
}
statusMsg.Append(fileName);
(void) observerService->Notify(mgr,
NS_ConvertASCIItoUCS2(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID).GetUnicode(),
statusMsg.GetUnicode());
}
}
}
rv = module->RegisterSelf(mCompMgr, component, registryLocation,
jsComponentTypeName);
if (rv == NS_ERROR_FACTORY_REGISTER_AGAIN) {
@@ -710,6 +711,22 @@ mozJSComponentLoader::UnregisterComponent(nsIFile *component)
if (!module)
return NS_ERROR_FAILURE;
{
// Notify observers, if any, of autoregistration work
NS_WITH_SERVICE (nsIObserverService, observerService, NS_OBSERVERSERVICE_PROGID, &rv);
if (NS_SUCCEEDED(rv))
{
nsIServiceManager *mgr; // NO COMPtr as we dont release the service manager
rv = nsServiceManager::GetGlobalServiceManager(&mgr);
if (NS_SUCCEEDED(rv))
{
(void) observerService->Notify(mgr,
NS_ConvertASCIItoUCS2(NS_XPCOM_AUTOREGISTRATION_OBSERVER_ID).GetUnicode(),
NS_ConvertASCIItoUCS2("Unregistering JS component").GetUnicode());
}
}
}
rv = module->UnregisterSelf(mCompMgr, component, registryLocation);
if (NS_SUCCEEDED(rv))