2001-09-26 02:58:40 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-03-13 01:52:28 +03:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsICategoryManager.h"
|
2002-09-04 03:36:13 +04:00
|
|
|
#include "nsXPCOM.h"
|
2001-03-13 01:52:28 +03:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsAppStartupNotifier.h"
|
2013-09-23 21:29:27 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2010-05-20 03:22:19 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsAppStartupNotifier, nsIObserver)
|
2001-03-13 01:52:28 +03:00
|
|
|
|
|
|
|
nsAppStartupNotifier::nsAppStartupNotifier()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-22 15:56:19 +03:00
|
|
|
nsAppStartupNotifier::~nsAppStartupNotifier() = default;
|
2001-03-13 01:52:28 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
NS_IMETHODIMP nsAppStartupNotifier::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *someData)
|
2001-03-13 01:52:28 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aTopic);
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// now initialize all startup listeners
|
|
|
|
nsCOMPtr<nsICategoryManager> categoryManager =
|
|
|
|
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2018-07-24 03:41:06 +03:00
|
|
|
nsDependentCString topic(aTopic);
|
|
|
|
|
2001-03-13 01:52:28 +03:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
2018-07-24 03:41:06 +03:00
|
|
|
rv = categoryManager->EnumerateCategory(topic,
|
2001-03-13 01:52:28 +03:00
|
|
|
getter_AddRefs(enumerator));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> entry;
|
|
|
|
while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) {
|
2002-08-06 04:53:19 +04:00
|
|
|
nsCOMPtr<nsISupportsCString> category = do_QueryInterface(entry, &rv);
|
2001-03-13 01:52:28 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString categoryEntry;
|
2002-08-27 01:20:34 +04:00
|
|
|
rv = category->GetData(categoryEntry);
|
2001-03-13 01:52:28 +03:00
|
|
|
|
2017-08-21 13:01:27 +03:00
|
|
|
nsCString contractId;
|
2018-07-24 03:41:06 +03:00
|
|
|
categoryManager->GetCategoryEntry(topic, categoryEntry,
|
|
|
|
contractId);
|
2001-03-13 01:52:28 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
|
|
|
|
// If we see the word "service," in the beginning
|
|
|
|
// of the contractId then we create it as a service
|
|
|
|
// if not we do a createInstance
|
|
|
|
|
2007-05-17 00:06:01 +04:00
|
|
|
nsCOMPtr<nsISupports> startupInstance;
|
|
|
|
if (Substring(contractId, 0, 8).EqualsLiteral("service,"))
|
|
|
|
startupInstance = do_GetService(contractId.get() + 8, &rv);
|
2001-03-13 01:52:28 +03:00
|
|
|
else
|
2017-08-21 13:01:27 +03:00
|
|
|
startupInstance = do_CreateInstance(contractId.get(), &rv);
|
2001-03-13 01:52:28 +03:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-05-17 00:06:01 +04:00
|
|
|
// Try to QI to nsIObserver
|
|
|
|
nsCOMPtr<nsIObserver> startupObserver =
|
|
|
|
do_QueryInterface(startupInstance, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = startupObserver->Observe(nullptr, aTopic, nullptr);
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2007-05-17 00:06:01 +04:00
|
|
|
// mainly for debugging if you want to know if your observer worked.
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Startup Observer failed!\n");
|
|
|
|
}
|
2001-03-13 01:52:28 +03:00
|
|
|
}
|
2001-06-28 06:32:12 +04:00
|
|
|
else {
|
2012-06-25 23:59:42 +04:00
|
|
|
#ifdef DEBUG
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString warnStr("Cannot create startup observer : ");
|
2001-06-28 06:32:12 +04:00
|
|
|
warnStr += contractId.get();
|
|
|
|
NS_WARNING(warnStr.get());
|
|
|
|
#endif
|
|
|
|
}
|
2010-05-20 03:22:19 +04:00
|
|
|
|
2001-03-13 01:52:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|