b=506470, Mac alerts service should not initialize Growl on app startup; r=sdwilsh

This commit is contained in:
Vladimir Vukicevic 2009-08-20 12:55:21 -07:00
parent 58486359e8
commit a57b68f667
2 changed files with 20 additions and 68 deletions

View File

@ -149,13 +149,26 @@ nsAlertsService::Init()
if ([GrowlApplicationBridge isGrowlInstalled] == NO)
return NS_ERROR_SERVICE_NOT_AVAILABLE;
NS_ASSERTION([GrowlApplicationBridge growlDelegate] == nil,
"We already registered with Growl!");
nsresult rv;
nsCOMPtr<nsIObserverService> os =
do_GetService("@mozilla.org/observer-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = os->AddObserver(this, "final-ui-startup", PR_FALSE);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsNotificationsList> notifications = new nsNotificationsList();
if (notifications)
(void)os->NotifyObservers(notifications, "before-growl-registration", nsnull);
mDelegate = new GrowlDelegateWrapper();
if (notifications)
notifications->informController(mDelegate->delegate);
// registers with Growl
[GrowlApplicationBridge setGrowlDelegate: mDelegate->delegate];
(void)os->AddObserver(this, DOM_WINDOW_DESTROYED_TOPIC, PR_FALSE);
(void)os->AddObserver(this, "profile-before-change", PR_FALSE);
@ -227,32 +240,15 @@ nsAlertsService::Observe(nsISupports* aSubject, const char* aTopic,
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT;
if (strcmp(aTopic, "final-ui-startup") == 0) {
NS_ASSERTION([GrowlApplicationBridge growlDelegate] == nil,
"We already registered with Growl!");
if (!mDelegate)
return NS_OK;
nsRefPtr<nsNotificationsList> notifications = new nsNotificationsList();
if (notifications) {
nsCOMPtr<nsIObserverService> os =
do_GetService("@mozilla.org/observer-service;1");
(void)os->NotifyObservers(notifications, "before-growl-registration", nsnull);
}
mDelegate = new GrowlDelegateWrapper();
if (notifications)
notifications->informController(mDelegate->delegate);
// registers with Growl
[GrowlApplicationBridge setGrowlDelegate: mDelegate->delegate];
}
else if (strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) == 0 && mDelegate) {
if (strcmp(aTopic, DOM_WINDOW_DESTROYED_TOPIC) == 0) {
nsCOMPtr<nsIDOMWindow> window(do_QueryInterface(aSubject));
if (window)
[mDelegate->delegate forgetObserversForWindow:window];
}
else if (strcmp(aTopic, "profile-before-change") == 0 && mDelegate) {
else if (strcmp(aTopic, "profile-before-change") == 0) {
[mDelegate->delegate forgetObservers];
}

View File

@ -45,56 +45,12 @@
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAlertsService, Init)
static
NS_METHOD
nsAlertsServiceRegister(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const char* componentType,
const nsModuleComponentInfo* info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
char* prev = nsnull;
rv = catman->AddCategoryEntry("app-startup", "nsAlertsService",
"service," NS_ALERTSERVICE_CONTRACTID, PR_TRUE,
PR_TRUE, &prev);
if (prev)
nsMemory::Free(prev);
return rv;
}
static
NS_METHOD
nsAlertsServiceUnregister(nsIComponentManager* aCompMgr,
nsIFile* aPath,
const char* registryLocation,
const nsModuleComponentInfo* info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager> catman =
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = catman->DeleteCategoryEntry("app-startup", "nsAlertsService", PR_TRUE);
return rv;
}
static const nsModuleComponentInfo components[] =
{
{ "Alerts Service",
NS_ALERTSSERVICE_CID,
NS_ALERTSERVICE_CONTRACTID,
nsAlertsServiceConstructor,
nsAlertsServiceRegister,
nsAlertsServiceUnregister },
nsAlertsServiceConstructor },
};
NS_IMPL_NSGETMODULE(nsAlertsServiceModule, components)