diff --git a/mozilla/embedding/base/nsEmbedAPI.cpp b/mozilla/embedding/base/nsEmbedAPI.cpp index 3beb3ce1b13..b32b200f852 100644 --- a/mozilla/embedding/base/nsEmbedAPI.cpp +++ b/mozilla/embedding/base/nsEmbedAPI.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file @@ -55,7 +55,7 @@ public: NS_TermEmbedding(); } // XXX Global destructors and NS_ShutdownXPCOM don't seem to mix -// NS_ShutdownXPCOM(sServiceManager); +// NS_ShutdownXPCOM(sServiceManager); } } }; @@ -71,12 +71,12 @@ static NS_DEFINE_IID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); nsresult NS_InitEmbedding(const char *aPath) { - // Create an object to represent the path - nsILocalFile *localFile = nsnull; - if (aPath && strlen(aPath) > 0) - { - NS_NewLocalFile(aPath, &localFile); - } + // Create an object to represent the path + nsILocalFile *localFile = nsnull; + if (aPath && strlen(aPath) > 0) + { + NS_NewLocalFile(aPath, &localFile); + } nsresult rv = NS_InitEmbedding(localFile); NS_IF_RELEASE(localFile); @@ -88,89 +88,85 @@ nsresult NS_InitEmbedding(const char *aPath) nsresult NS_InitEmbedding(nsILocalFile *aPath) { // Reentrant calls to this method do nothing except increment a counter - if (++sInitCounter > 1) - { + sInitCounter++; + if (sInitCounter > 1) return NS_OK; - } - // Initialise XPCOM + // Initialise XPCOM #ifdef HACK_AROUND_NONREENTRANT_INITXPCOM - // Can't call NS_InitXPCom more than once or things go boom! - if (!sXPCOMInitializedFlag) + // Can't call NS_InitXPCom more than once or things go boom! + if (!sXPCOMInitializedFlag) #endif - { - // Initialise XPCOM - if (aPath) - { - NS_InitXPCOM(&sServiceManager, aPath); - } - else - { - NS_InitXPCOM(&sServiceManager, nsnull); - } + { + // Initialise XPCOM + if (aPath) + NS_InitXPCOM(&sServiceManager, aPath); + else + NS_InitXPCOM(&sServiceManager, nsnull); #ifdef HACK_AROUND_NONREENTRANT_INITXPCOM - sXPCOMInitializedFlag = PR_TRUE; + sXPCOMInitializedFlag = PR_TRUE; sXPCOMCleanupHack.mCleanOnExit = PR_TRUE; #endif - } + } nsresult rv; - // Register components - if (!sRegistryInitializedFlag) - { + // Register components + if (!sRegistryInitializedFlag) + { // XXX hack method - NS_SetupRegistry(); - - rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, NULL /* default */); - if (NS_OK != rv) + NS_SetupRegistry(); + + rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup, + NULL /* default */); + if (NS_FAILED(rv)) { - NS_ASSERTION(PR_FALSE, "Could not AutoRegister"); - return rv; - } + NS_ASSERTION(PR_FALSE, "Could not AutoRegister"); + return rv; + } - sRegistryInitializedFlag = PR_TRUE; - } + sRegistryInitializedFlag = PR_TRUE; + } - // Create the Event Queue for the UI thread... - // - // If an event queue already exists for the thread, then - // CreateThreadEventQueue(...) will fail... + // Create the Event Queue for the UI thread... + // + // If an event queue already exists for the thread, then + // CreateThreadEventQueue(...) will fail... + NS_WITH_SERVICE(nsIEventQueueService, eventQService, + kEventQueueServiceCID, &rv); + if (NS_FAILED(rv)) + return rv; - nsIEventQueueService* eventQService = NULL; - rv = nsServiceManager::GetService(kEventQueueServiceCID, - NS_GET_IID(nsIEventQueueService), - (nsISupports **)&eventQService); - if (NS_SUCCEEDED(rv)) - { - rv = eventQService->CreateThreadEventQueue(); - nsServiceManager::ReleaseService(kEventQueueServiceCID, eventQService); - } + eventQService->CreateThreadEventQueue(); #ifdef HACK_AROUND_THREADING_ISSUES // XXX force certain objects to be created on the main thread - nsresult res; - NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &res); - if (NS_SUCCEEDED (res) && (nsnull != sBundleService)) + NS_WITH_SERVICE(nsIStringBundleService, sBundleService, + kStringBundleServiceCID, &rv); + if (NS_SUCCEEDED(rv)) { nsCOMPtr stringBundle; char* propertyURL = "chrome://necko/locale/necko.properties"; nsILocale *locale = nsnull; - res = sBundleService->CreateBundle(propertyURL, locale, getter_AddRefs(stringBundle)); + rv = sBundleService->CreateBundle(propertyURL, locale, + getter_AddRefs(stringBundle)); } #endif - // Init the chrome registry. - - nsCOMPtr chromeReg = do_GetService("component://netscape/chrome/chrome-registry"); + nsCOMPtr chromeReg = + do_GetService("component://netscape/chrome/chrome-registry"); NS_ASSERTION(chromeReg, "chrome check couldn't get the chrome registry"); if (!chromeReg) return NS_ERROR_FAILURE; - return chromeReg->CheckForNewChrome(); + // Ignore the return value here. If chrome is already initialized + // this call will return an error even though nothing is wrong. + chromeReg->CheckForNewChrome(); + + return NS_OK; } @@ -185,23 +181,19 @@ nsresult NS_TermEmbedding() } sInitCounter = 0; - // Destroy the event queue - nsIEventQueueService* eventQService = NULL; - nsresult rv = nsServiceManager::GetService(kEventQueueServiceCID, - NS_GET_IID(nsIEventQueueService), - (nsISupports **)&eventQService); - if (NS_SUCCEEDED(rv)) - { - rv = eventQService->DestroyThreadEventQueue(); - nsServiceManager::ReleaseService(kEventQueueServiceCID, eventQService); - } + nsresult rv; + // Destroy the event queue + NS_WITH_SERVICE(nsIEventQueueService, eventQService, + kEventQueueServiceCID, &rv); + if (NS_SUCCEEDED(rv)) + rv = eventQService->DestroyThreadEventQueue(); - NS_RELEASE(sServiceManager); + NS_RELEASE(sServiceManager); - // Terminate XPCOM & cleanup + // Terminate XPCOM & cleanup #ifndef HACK_AROUND_NONREENTRANT_INITXPCOM - NS_ShutdownXPCOM(sServiceManager); + NS_ShutdownXPCOM(sServiceManager); #endif - return NS_OK; + return NS_OK; }