Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "nsCOMPtr.h" |
michael@0 | 7 | #include "nsString.h" |
michael@0 | 8 | #include "nsXPIDLString.h" |
michael@0 | 9 | #include "nsIServiceManager.h" |
michael@0 | 10 | #include "nsICategoryManager.h" |
michael@0 | 11 | #include "nsXPCOM.h" |
michael@0 | 12 | #include "nsISupportsPrimitives.h" |
michael@0 | 13 | #include "nsAppStartupNotifier.h" |
michael@0 | 14 | #include "nsISimpleEnumerator.h" |
michael@0 | 15 | |
michael@0 | 16 | NS_IMPL_ISUPPORTS(nsAppStartupNotifier, nsIObserver) |
michael@0 | 17 | |
michael@0 | 18 | nsAppStartupNotifier::nsAppStartupNotifier() |
michael@0 | 19 | { |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | nsAppStartupNotifier::~nsAppStartupNotifier() |
michael@0 | 23 | { |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | NS_IMETHODIMP nsAppStartupNotifier::Observe(nsISupports *aSubject, const char *aTopic, const char16_t *someData) |
michael@0 | 27 | { |
michael@0 | 28 | NS_ENSURE_ARG(aTopic); |
michael@0 | 29 | nsresult rv; |
michael@0 | 30 | |
michael@0 | 31 | // now initialize all startup listeners |
michael@0 | 32 | nsCOMPtr<nsICategoryManager> categoryManager = |
michael@0 | 33 | do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); |
michael@0 | 34 | NS_ENSURE_SUCCESS(rv, rv); |
michael@0 | 35 | |
michael@0 | 36 | nsCOMPtr<nsISimpleEnumerator> enumerator; |
michael@0 | 37 | rv = categoryManager->EnumerateCategory(aTopic, |
michael@0 | 38 | getter_AddRefs(enumerator)); |
michael@0 | 39 | if (NS_FAILED(rv)) return rv; |
michael@0 | 40 | |
michael@0 | 41 | nsCOMPtr<nsISupports> entry; |
michael@0 | 42 | while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) { |
michael@0 | 43 | nsCOMPtr<nsISupportsCString> category = do_QueryInterface(entry, &rv); |
michael@0 | 44 | |
michael@0 | 45 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 46 | nsAutoCString categoryEntry; |
michael@0 | 47 | rv = category->GetData(categoryEntry); |
michael@0 | 48 | |
michael@0 | 49 | nsXPIDLCString contractId; |
michael@0 | 50 | categoryManager->GetCategoryEntry(aTopic, |
michael@0 | 51 | categoryEntry.get(), |
michael@0 | 52 | getter_Copies(contractId)); |
michael@0 | 53 | |
michael@0 | 54 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 55 | |
michael@0 | 56 | // If we see the word "service," in the beginning |
michael@0 | 57 | // of the contractId then we create it as a service |
michael@0 | 58 | // if not we do a createInstance |
michael@0 | 59 | |
michael@0 | 60 | nsCOMPtr<nsISupports> startupInstance; |
michael@0 | 61 | if (Substring(contractId, 0, 8).EqualsLiteral("service,")) |
michael@0 | 62 | startupInstance = do_GetService(contractId.get() + 8, &rv); |
michael@0 | 63 | else |
michael@0 | 64 | startupInstance = do_CreateInstance(contractId, &rv); |
michael@0 | 65 | |
michael@0 | 66 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 67 | // Try to QI to nsIObserver |
michael@0 | 68 | nsCOMPtr<nsIObserver> startupObserver = |
michael@0 | 69 | do_QueryInterface(startupInstance, &rv); |
michael@0 | 70 | if (NS_SUCCEEDED(rv)) { |
michael@0 | 71 | rv = startupObserver->Observe(nullptr, aTopic, nullptr); |
michael@0 | 72 | |
michael@0 | 73 | // mainly for debugging if you want to know if your observer worked. |
michael@0 | 74 | NS_ASSERTION(NS_SUCCEEDED(rv), "Startup Observer failed!\n"); |
michael@0 | 75 | } |
michael@0 | 76 | } |
michael@0 | 77 | else { |
michael@0 | 78 | #ifdef DEBUG |
michael@0 | 79 | nsAutoCString warnStr("Cannot create startup observer : "); |
michael@0 | 80 | warnStr += contractId.get(); |
michael@0 | 81 | NS_WARNING(warnStr.get()); |
michael@0 | 82 | #endif |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | return NS_OK; |
michael@0 | 90 | } |