2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2006-05-10 17:30:15 +00:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 ci et: */
|
2012-05-21 11:12:37 +00: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/. */
|
1999-05-18 21:43:13 +00:00
|
|
|
|
2009-10-21 23:01:16 +00:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2013-07-20 03:14:34 +00:00
|
|
|
#include "mozilla/Atomics.h"
|
2013-05-07 18:48:59 +00:00
|
|
|
#include "mozilla/Poison.h"
|
2009-05-18 18:15:05 +00:00
|
|
|
#include "mozilla/XPCOM.h"
|
2009-08-28 23:16:19 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
2009-05-18 18:15:05 +00:00
|
|
|
|
2001-12-07 19:54:16 +00:00
|
|
|
#include "nsXPCOMPrivate.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsXPCOMCIDInternal.h"
|
2009-05-18 18:15:05 +00:00
|
|
|
|
2002-07-01 20:37:17 +00:00
|
|
|
#include "prlink.h"
|
2009-05-18 18:15:05 +00:00
|
|
|
|
2013-04-30 17:41:22 +00:00
|
|
|
#include "nsCycleCollector.h"
|
2001-03-03 01:24:36 +00:00
|
|
|
#include "nsObserverList.h"
|
2001-10-22 22:01:27 +00:00
|
|
|
#include "nsObserverService.h"
|
1999-05-18 21:43:13 +00:00
|
|
|
#include "nsProperties.h"
|
2000-01-05 09:29:25 +00:00
|
|
|
#include "nsPersistentProperties.h"
|
1999-12-04 20:31:38 +00:00
|
|
|
#include "nsScriptableInputStream.h"
|
2003-03-13 21:23:18 +00:00
|
|
|
#include "nsBinaryStream.h"
|
2004-03-02 01:11:06 +00:00
|
|
|
#include "nsStorageStream.h"
|
2005-07-18 23:39:56 +00:00
|
|
|
#include "nsPipe.h"
|
2011-06-08 18:08:31 +00:00
|
|
|
#include "nsScriptableBase64Encoder.h"
|
1999-05-18 21:43:13 +00:00
|
|
|
|
2000-06-03 09:46:12 +00:00
|
|
|
#include "nsMemoryImpl.h"
|
2003-07-07 22:11:36 +00:00
|
|
|
#include "nsDebugImpl.h"
|
2003-08-05 05:29:10 +00:00
|
|
|
#include "nsTraceRefcntImpl.h"
|
2000-07-22 05:48:04 +00:00
|
|
|
#include "nsErrorService.h"
|
2001-12-07 19:54:16 +00:00
|
|
|
|
1999-05-18 21:43:13 +00:00
|
|
|
#include "nsSupportsArray.h"
|
2002-10-07 19:03:41 +00:00
|
|
|
#include "nsArray.h"
|
2005-10-04 17:19:14 +00:00
|
|
|
#include "nsINIParserImpl.h"
|
1999-08-04 07:08:58 +00:00
|
|
|
#include "nsSupportsPrimitives.h"
|
2000-04-18 02:34:54 +00:00
|
|
|
#include "nsConsoleService.h"
|
1999-05-18 21:43:13 +00:00
|
|
|
|
|
|
|
#include "nsComponentManager.h"
|
2002-09-23 21:46:25 +00:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
1999-05-18 21:43:13 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadManager.h"
|
|
|
|
#include "nsThreadPool.h"
|
1999-05-18 21:43:13 +00:00
|
|
|
|
1999-10-05 00:07:39 +00:00
|
|
|
#include "xptinfo.h"
|
2000-02-15 06:45:30 +00:00
|
|
|
#include "nsIInterfaceInfoManager.h"
|
2005-11-08 18:17:49 +00:00
|
|
|
#include "xptiprivate.h"
|
2013-03-09 02:54:10 +00:00
|
|
|
#include "mozilla/XPTInterfaceInfoManager.h"
|
1999-05-28 01:14:59 +00:00
|
|
|
|
2001-12-16 06:13:17 +00:00
|
|
|
#include "nsTimerImpl.h"
|
|
|
|
#include "TimerThread.h"
|
|
|
|
|
1999-10-01 23:30:06 +00:00
|
|
|
#include "nsThread.h"
|
2001-01-22 21:52:01 +00:00
|
|
|
#include "nsProcess.h"
|
2004-01-23 10:23:12 +00:00
|
|
|
#include "nsEnvironment.h"
|
2005-07-23 14:05:25 +00:00
|
|
|
#include "nsVersionComparatorImpl.h"
|
1999-10-01 23:30:06 +00:00
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
#include "nsIFile.h"
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsLocalFile.h"
|
2014-02-10 22:57:01 +00:00
|
|
|
#if defined(XP_UNIX)
|
2002-06-10 18:50:11 +00:00
|
|
|
#include "nsNativeCharsetUtils.h"
|
2002-06-10 19:47:22 +00:00
|
|
|
#endif
|
2000-01-24 21:28:28 +00:00
|
|
|
#include "nsDirectoryService.h"
|
2000-08-11 20:31:57 +00:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2002-07-18 05:09:10 +00:00
|
|
|
#include "nsCategoryManager.h"
|
2000-02-06 02:02:24 +00:00
|
|
|
#include "nsICategoryManager.h"
|
2002-02-16 01:19:24 +00:00
|
|
|
#include "nsMultiplexInputStream.h"
|
1999-10-25 22:48:44 +00:00
|
|
|
|
2006-01-02 02:30:32 +00:00
|
|
|
#include "nsStringStream.h"
|
2010-06-10 18:11:11 +00:00
|
|
|
extern nsresult nsStringInputStreamConstructor(nsISupports *, REFNSIID, void **);
|
2006-01-02 02:30:32 +00:00
|
|
|
|
2000-03-31 09:50:00 +00:00
|
|
|
#include "nsAtomService.h"
|
2001-10-20 23:19:07 +00:00
|
|
|
#include "nsAtomTable.h"
|
2000-08-04 06:59:18 +00:00
|
|
|
#include "nsTraceRefcnt.h"
|
2000-03-31 09:50:00 +00:00
|
|
|
|
2004-11-24 23:21:14 +00:00
|
|
|
#include "nsHashPropertyBag.h"
|
|
|
|
|
2006-07-21 16:28:51 +00:00
|
|
|
#include "nsUnicharInputStream.h"
|
2001-10-31 23:35:07 +00:00
|
|
|
#include "nsVariant.h"
|
|
|
|
|
2005-11-21 21:01:45 +00:00
|
|
|
#include "nsUUIDGenerator.h"
|
|
|
|
|
2009-05-07 19:21:54 +00:00
|
|
|
#include "nsIOUtil.h"
|
|
|
|
|
2003-03-15 01:04:32 +00:00
|
|
|
#include "SpecialSystemDirectory.h"
|
2002-09-27 13:07:01 +00:00
|
|
|
|
2008-10-09 03:51:54 +00:00
|
|
|
#if defined(XP_WIN)
|
2005-05-16 21:23:09 +00:00
|
|
|
#include "nsWindowsRegKey.h"
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 12:57:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2006-02-18 21:09:59 +00:00
|
|
|
#include "nsMacUtilsImpl.h"
|
2006-02-17 16:19:53 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-06 06:32:03 +00:00
|
|
|
#include "nsSystemInfo.h"
|
2008-03-06 01:28:25 +00:00
|
|
|
#include "nsMemoryReporterManager.h"
|
2012-10-30 00:41:14 +00:00
|
|
|
#include "nsMemoryInfoDumper.h"
|
2013-07-26 15:37:02 +00:00
|
|
|
#include "nsSecurityConsoleMessage.h"
|
2012-10-25 15:36:24 +00:00
|
|
|
#include "nsMessageLoop.h"
|
2006-07-06 06:32:03 +00:00
|
|
|
|
2004-06-15 16:38:43 +00:00
|
|
|
#include <locale.h>
|
2010-04-02 18:38:25 +00:00
|
|
|
#include "mozilla/Services.h"
|
2010-08-10 22:08:06 +00:00
|
|
|
#include "mozilla/Omnijar.h"
|
2011-10-12 17:52:26 +00:00
|
|
|
#include "mozilla/HangMonitor.h"
|
2012-01-10 20:29:58 +00:00
|
|
|
#include "mozilla/Telemetry.h"
|
2013-11-22 19:17:29 +00:00
|
|
|
#include "mozilla/BackgroundHangMonitor.h"
|
2004-06-15 16:38:43 +00:00
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
#include "nsChromeRegistry.h"
|
|
|
|
#include "nsChromeProtocolHandler.h"
|
2013-11-05 12:45:20 +00:00
|
|
|
#include "mozilla/IOInterposer.h"
|
|
|
|
#include "mozilla/PoisonIOInterposer.h"
|
|
|
|
#include "mozilla/LateWriteChecks.h"
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
#include "mozilla/scache/StartupCache.h"
|
|
|
|
|
2009-07-29 21:11:42 +00:00
|
|
|
#include "base/at_exit.h"
|
|
|
|
#include "base/command_line.h"
|
|
|
|
#include "base/message_loop.h"
|
|
|
|
|
2010-02-03 22:17:09 +00:00
|
|
|
#include "mozilla/ipc/BrowserProcessSubThread.h"
|
2011-12-15 19:48:38 +00:00
|
|
|
#include "mozilla/AvailableMemoryTracker.h"
|
2012-01-26 20:54:03 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2013-12-05 03:32:50 +00:00
|
|
|
#include "mozilla/SystemMemoryReporter.h"
|
2009-08-28 19:46:21 +00:00
|
|
|
|
2013-03-28 17:38:05 +00:00
|
|
|
#ifdef MOZ_VISUAL_EVENT_TRACER
|
2012-06-12 17:06:21 +00:00
|
|
|
#include "mozilla/VisualEventTracer.h"
|
2013-03-28 17:38:05 +00:00
|
|
|
#endif
|
2012-06-12 17:06:21 +00:00
|
|
|
|
2013-03-18 14:25:50 +00:00
|
|
|
#include "GeckoProfiler.h"
|
2012-10-06 08:37:45 +00:00
|
|
|
|
2013-07-20 03:14:34 +00:00
|
|
|
#include "jsapi.h"
|
|
|
|
|
2013-03-09 02:54:10 +00:00
|
|
|
using namespace mozilla;
|
2009-07-29 21:11:42 +00:00
|
|
|
using base::AtExitManager;
|
2009-08-28 19:46:21 +00:00
|
|
|
using mozilla::ipc::BrowserProcessSubThread;
|
2013-03-28 17:38:05 +00:00
|
|
|
#ifdef MOZ_VISUAL_EVENT_TRACER
|
|
|
|
using mozilla::eventtracer::VisualEventTracer;
|
|
|
|
#endif
|
2009-07-29 21:11:42 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
static AtExitManager* sExitManager;
|
|
|
|
static MessageLoop* sMessageLoop;
|
|
|
|
static bool sCommandLineWasInitialized;
|
2009-08-28 19:46:21 +00:00
|
|
|
static BrowserProcessSubThread* sIOThread;
|
2014-01-14 16:33:31 +00:00
|
|
|
static BackgroundHangMonitor* sMainHangMonitor;
|
2009-07-29 21:11:42 +00:00
|
|
|
|
|
|
|
} /* anonymous namespace */
|
|
|
|
|
2002-06-14 21:33:05 +00:00
|
|
|
// Registry Factory creation function defined in nsRegistry.cpp
|
|
|
|
// We hook into this function locally to create and register the registry
|
|
|
|
// Since noone outside xpcom needs to know about this and nsRegistry.cpp
|
|
|
|
// does not have a local include file, we are putting this definition
|
|
|
|
// here rather than in nsIRegistry.h
|
2003-01-28 22:17:58 +00:00
|
|
|
extern nsresult NS_RegistryGetFactory(nsIFactory** aFactory);
|
2002-07-18 14:38:07 +00:00
|
|
|
extern nsresult NS_CategoryManagerGetFactory( nsIFactory** );
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2010-10-16 19:58:20 +00:00
|
|
|
#ifdef XP_WIN
|
2012-09-25 00:50:30 +00:00
|
|
|
extern nsresult CreateAnonTempFileRemover();
|
2010-10-16 19:58:20 +00:00
|
|
|
#endif
|
|
|
|
|
2003-09-08 00:31:50 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsProcess)
|
2001-01-22 21:52:01 +00:00
|
|
|
|
1999-08-04 07:08:58 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsIDImpl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsStringImpl)
|
2002-08-06 01:32:51 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCStringImpl)
|
1999-08-04 07:08:58 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRBoolImpl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint8Impl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint16Impl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint32Impl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRUint64Impl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRTimeImpl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsCharImpl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt16Impl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt32Impl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsPRInt64Impl)
|
1999-08-06 09:42:12 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsFloatImpl)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsDoubleImpl)
|
1999-08-20 03:14:46 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsVoidImpl)
|
2001-04-11 00:10:39 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSupportsInterfacePointerImpl)
|
1999-08-04 07:08:58 +00:00
|
|
|
|
2005-03-02 16:37:53 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsConsoleService, Init)
|
2003-09-08 00:31:50 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl)
|
2003-03-13 21:23:18 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryOutputStream)
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryInputStream)
|
2004-03-02 01:11:06 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsStorageStream)
|
2005-07-23 14:05:25 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsVersionComparatorImpl)
|
2011-06-08 18:08:31 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScriptableBase64Encoder)
|
2013-03-28 17:38:05 +00:00
|
|
|
#ifdef MOZ_VISUAL_EVENT_TRACER
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(VisualEventTracer)
|
|
|
|
#endif
|
2002-01-27 23:56:02 +00:00
|
|
|
|
2003-09-08 00:31:50 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsVariant)
|
2001-10-31 23:35:07 +00:00
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsHashPropertyBag)
|
2004-11-24 23:21:14 +00:00
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
NS_GENERIC_AGGREGATED_CONSTRUCTOR(nsProperties)
|
2005-09-28 13:13:27 +00:00
|
|
|
|
2006-05-14 22:41:47 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUUIDGenerator, Init)
|
2005-11-21 21:01:45 +00:00
|
|
|
|
2010-04-27 12:57:34 +00:00
|
|
|
#ifdef MOZ_WIDGET_COCOA
|
2006-02-18 21:09:59 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacUtilsImpl)
|
2006-02-17 16:19:53 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-06 06:32:03 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSystemInfo, Init)
|
|
|
|
|
2009-10-03 07:21:34 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMemoryReporterManager, Init)
|
2008-03-06 01:28:25 +00:00
|
|
|
|
2012-10-30 00:41:14 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMemoryInfoDumper)
|
|
|
|
|
2009-05-07 19:21:54 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsIOUtil)
|
|
|
|
|
2013-07-26 15:37:02 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsSecurityConsoleMessage)
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static nsresult
|
2006-05-10 17:30:15 +00:00
|
|
|
nsThreadManagerGetSingleton(nsISupports* outer,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void* *aInstancePtr)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aInstancePtr, "null outptr");
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(outer))
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
2006-05-10 17:30:15 +00:00
|
|
|
|
|
|
|
return nsThreadManager::get()->QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsThreadPool)
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static nsresult
|
2002-01-27 23:56:02 +00:00
|
|
|
nsXPTIInterfaceInfoManagerGetSingleton(nsISupports* outer,
|
|
|
|
const nsIID& aIID,
|
2001-11-26 22:31:39 +00:00
|
|
|
void* *aInstancePtr)
|
|
|
|
{
|
2005-11-08 18:17:49 +00:00
|
|
|
NS_ASSERTION(aInstancePtr, "null outptr");
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(outer))
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
2002-01-27 23:56:02 +00:00
|
|
|
|
2005-11-08 18:17:49 +00:00
|
|
|
nsCOMPtr<nsIInterfaceInfoManager> iim
|
2013-03-09 02:54:10 +00:00
|
|
|
(XPTInterfaceInfoManager::GetSingleton());
|
2005-11-08 18:17:49 +00:00
|
|
|
if (!iim)
|
2001-11-26 22:31:39 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return iim->QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
|
|
|
|
2013-10-10 20:41:00 +00:00
|
|
|
nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = nullptr;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool gXPCOMShuttingDown = false;
|
2013-07-07 20:23:43 +00:00
|
|
|
bool gXPCOMThreadsShutDown = false;
|
1999-05-18 21:43:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
|
|
|
static NS_DEFINE_CID(kINIParserFactoryCID, NS_INIPARSERFACTORY_CID);
|
|
|
|
static NS_DEFINE_CID(kSimpleUnicharStreamFactoryCID, NS_SIMPLE_UNICHAR_STREAM_FACTORY_CID);
|
2001-03-12 20:43:02 +00:00
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
NS_DEFINE_NAMED_CID(NS_CHROMEREGISTRY_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_CHROMEPROTOCOLHANDLER_CID);
|
|
|
|
|
2013-07-26 15:37:02 +00:00
|
|
|
NS_DEFINE_NAMED_CID(NS_SECURITY_CONSOLE_MESSAGE_CID);
|
|
|
|
|
2010-07-01 15:55:57 +00:00
|
|
|
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsChromeRegistry,
|
|
|
|
nsChromeRegistry::GetSingleton)
|
2010-06-11 20:13:26 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsChromeProtocolHandler)
|
|
|
|
|
2001-03-12 20:43:02 +00:00
|
|
|
#define NS_PERSISTENTPROPERTIES_CID NS_IPERSISTENTPROPERTIES_CID /* sigh */
|
2002-07-01 23:36:03 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static already_AddRefed<nsIFactory>
|
|
|
|
CreateINIParserFactory(const mozilla::Module& module,
|
|
|
|
const mozilla::Module::CIDEntry& entry)
|
|
|
|
{
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIFactory> f = new nsINIParserFactory();
|
|
|
|
return f.forget();
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2005-11-21 21:01:45 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static already_AddRefed<nsIFactory>
|
|
|
|
CreateUnicharStreamFactory(const mozilla::Module& module,
|
|
|
|
const mozilla::Module::CIDEntry& entry)
|
|
|
|
{
|
2013-04-22 11:15:59 +00:00
|
|
|
return already_AddRefed<nsIFactory>(
|
|
|
|
nsSimpleUnicharStreamFactory::GetInstance());
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2006-02-17 16:19:53 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#define COMPONENT(NAME, Ctor) static NS_DEFINE_CID(kNS_##NAME##_CID, NS_##NAME##_CID);
|
|
|
|
#include "XPCOMModule.inc"
|
|
|
|
#undef COMPONENT
|
2006-07-06 06:32:03 +00:00
|
|
|
|
2013-10-10 20:41:00 +00:00
|
|
|
#define COMPONENT(NAME, Ctor) { &kNS_##NAME##_CID, false, nullptr, Ctor },
|
2010-06-10 18:11:11 +00:00
|
|
|
const mozilla::Module::CIDEntry kXPCOMCIDEntries[] = {
|
2013-10-10 20:41:00 +00:00
|
|
|
{ &kComponentManagerCID, true, nullptr, nsComponentManagerImpl::Create },
|
2010-06-10 18:11:11 +00:00
|
|
|
{ &kINIParserFactoryCID, false, CreateINIParserFactory },
|
|
|
|
{ &kSimpleUnicharStreamFactoryCID, false, CreateUnicharStreamFactory },
|
|
|
|
#include "XPCOMModule.inc"
|
2013-10-10 20:41:00 +00:00
|
|
|
{ &kNS_CHROMEREGISTRY_CID, false, nullptr, nsChromeRegistryConstructor },
|
|
|
|
{ &kNS_CHROMEPROTOCOLHANDLER_CID, false, nullptr, nsChromeProtocolHandlerConstructor },
|
|
|
|
{ &kNS_SECURITY_CONSOLE_MESSAGE_CID, false, nullptr, nsSecurityConsoleMessageConstructor },
|
|
|
|
{ nullptr }
|
2001-03-12 20:43:02 +00:00
|
|
|
};
|
2010-06-10 18:11:11 +00:00
|
|
|
#undef COMPONENT
|
2001-03-12 20:43:02 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#define COMPONENT(NAME, Ctor) { NS_##NAME##_CONTRACTID, &kNS_##NAME##_CID },
|
|
|
|
const mozilla::Module::ContractIDEntry kXPCOMContracts[] = {
|
|
|
|
#include "XPCOMModule.inc"
|
2010-06-11 20:13:26 +00:00
|
|
|
{ NS_CHROMEREGISTRY_CONTRACTID, &kNS_CHROMEREGISTRY_CID },
|
|
|
|
{ NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "chrome", &kNS_CHROMEPROTOCOLHANDLER_CID },
|
2010-06-26 02:17:31 +00:00
|
|
|
{ NS_INIPARSERFACTORY_CONTRACTID, &kINIParserFactoryCID },
|
2013-07-26 15:37:02 +00:00
|
|
|
{ NS_SECURITY_CONSOLE_MESSAGE_CONTRACTID, &kNS_SECURITY_CONSOLE_MESSAGE_CID },
|
2013-10-10 20:41:00 +00:00
|
|
|
{ nullptr }
|
2010-06-10 18:11:11 +00:00
|
|
|
};
|
2001-03-12 20:43:02 +00:00
|
|
|
#undef COMPONENT
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
const mozilla::Module kXPCOMModule = { mozilla::Module::kVersion, kXPCOMCIDEntries, kXPCOMContracts };
|
2000-08-16 22:40:27 +00:00
|
|
|
|
2003-07-07 22:11:36 +00:00
|
|
|
// gDebug will be freed during shutdown.
|
2012-07-30 14:20:58 +00:00
|
|
|
static nsIDebug* gDebug = nullptr;
|
2005-11-08 18:17:49 +00:00
|
|
|
|
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
NS_GetDebug(nsIDebug** result)
|
2003-07-07 22:11:36 +00:00
|
|
|
{
|
2013-11-19 21:27:37 +00:00
|
|
|
return nsDebugImpl::Create(nullptr,
|
|
|
|
NS_GET_IID(nsIDebug),
|
2006-02-10 15:00:36 +00:00
|
|
|
(void**) result);
|
2003-07-07 22:11:36 +00:00
|
|
|
}
|
|
|
|
|
2005-11-08 18:17:49 +00:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
NS_GetTraceRefcnt(nsITraceRefcnt** result)
|
2003-08-05 05:29:10 +00:00
|
|
|
{
|
2013-11-19 21:27:37 +00:00
|
|
|
return nsTraceRefcntImpl::Create(nullptr,
|
|
|
|
NS_GET_IID(nsITraceRefcnt),
|
2006-02-10 15:00:36 +00:00
|
|
|
(void**) result);
|
2003-08-05 05:29:10 +00:00
|
|
|
}
|
2003-07-07 22:11:36 +00:00
|
|
|
|
2005-11-08 18:17:49 +00:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
NS_InitXPCOM(nsIServiceManager* *result,
|
2000-08-16 22:40:27 +00:00
|
|
|
nsIFile* binDirectory)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
return NS_InitXPCOM2(result, binDirectory, nullptr);
|
2000-08-16 22:40:27 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 06:09:10 +00:00
|
|
|
class ICUReporter MOZ_FINAL : public nsIMemoryReporter
|
2013-07-20 03:14:34 +00:00
|
|
|
{
|
2013-08-23 05:24:16 +00:00
|
|
|
public:
|
2013-12-08 06:09:10 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2013-08-23 05:24:16 +00:00
|
|
|
ICUReporter()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
// There must be only one instance of this class, due to |sAmount|
|
|
|
|
// being static.
|
|
|
|
static bool hasRun = false;
|
|
|
|
MOZ_ASSERT(!hasRun);
|
|
|
|
hasRun = true;
|
|
|
|
#endif
|
|
|
|
sAmount = 0;
|
|
|
|
}
|
2013-07-20 03:14:34 +00:00
|
|
|
|
2013-08-23 05:24:16 +00:00
|
|
|
static void* Alloc(const void*, size_t size)
|
|
|
|
{
|
|
|
|
void* p = malloc(size);
|
|
|
|
sAmount += MallocSizeOfOnAlloc(p);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* Realloc(const void*, void* p, size_t size)
|
|
|
|
{
|
|
|
|
sAmount -= MallocSizeOfOnFree(p);
|
|
|
|
void *pnew = realloc(p, size);
|
|
|
|
if (pnew) {
|
|
|
|
sAmount += MallocSizeOfOnAlloc(pnew);
|
|
|
|
} else {
|
|
|
|
// realloc failed; undo the decrement from above
|
|
|
|
sAmount += MallocSizeOfOnAlloc(p);
|
|
|
|
}
|
|
|
|
return pnew;
|
|
|
|
}
|
2013-07-20 03:14:34 +00:00
|
|
|
|
2013-08-23 05:24:16 +00:00
|
|
|
static void Free(const void*, void* p)
|
|
|
|
{
|
|
|
|
sAmount -= MallocSizeOfOnFree(p);
|
|
|
|
free(p);
|
|
|
|
}
|
2013-07-20 03:14:34 +00:00
|
|
|
|
2013-08-23 05:24:16 +00:00
|
|
|
private:
|
|
|
|
// |sAmount| can be (implicitly) accessed by multiple JSRuntimes, so it
|
|
|
|
// must be thread-safe.
|
|
|
|
static Atomic<size_t> sAmount;
|
2013-07-20 03:14:34 +00:00
|
|
|
|
2013-12-08 06:09:10 +00:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf)
|
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF_ON_ALLOC(MallocSizeOfOnAlloc)
|
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF_ON_FREE(MallocSizeOfOnFree)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CollectReports(nsIHandleReportCallback* aHandleReport, nsISupports* aData)
|
|
|
|
{
|
|
|
|
return MOZ_COLLECT_REPORT(
|
|
|
|
"explicit/icu", KIND_HEAP, UNITS_BYTES, sAmount,
|
|
|
|
"Memory used by ICU, a Unicode and globalization support library.");
|
|
|
|
}
|
2013-08-23 05:24:16 +00:00
|
|
|
};
|
2013-07-20 03:14:34 +00:00
|
|
|
|
2013-12-08 06:09:10 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(ICUReporter, nsIMemoryReporter)
|
|
|
|
|
2013-08-23 05:24:16 +00:00
|
|
|
/* static */ Atomic<size_t> ICUReporter::sAmount;
|
2013-07-20 03:14:34 +00:00
|
|
|
|
2005-11-08 18:17:49 +00:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
NS_InitXPCOM2(nsIServiceManager* *result,
|
2010-06-10 18:11:11 +00:00
|
|
|
nsIFile* binDirectory,
|
|
|
|
nsIDirectoryServiceProvider* appFileLocationProvider)
|
1999-05-18 21:43:13 +00:00
|
|
|
{
|
2013-05-07 18:48:59 +00:00
|
|
|
mozPoisonValueInit();
|
|
|
|
|
2013-05-28 12:03:38 +00:00
|
|
|
char aLocal;
|
|
|
|
profiler_init(&aLocal);
|
1999-05-18 21:43:13 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2002-06-11 19:26:04 +00:00
|
|
|
// We are not shutting down
|
2011-10-17 14:59:28 +00:00
|
|
|
gXPCOMShuttingDown = false;
|
2002-06-11 19:26:04 +00:00
|
|
|
|
2012-04-09 17:53:08 +00:00
|
|
|
// Initialize the available memory tracker before other threads have had a
|
|
|
|
// chance to start up, because the initialization is not thread-safe.
|
|
|
|
mozilla::AvailableMemoryTracker::Init();
|
|
|
|
|
2010-03-04 19:50:28 +00:00
|
|
|
NS_LogInit();
|
|
|
|
|
2009-07-29 21:11:42 +00:00
|
|
|
// Set up chromium libs
|
|
|
|
NS_ASSERTION(!sExitManager && !sMessageLoop, "Bad logic!");
|
|
|
|
|
|
|
|
if (!AtExitManager::AlreadyRegistered()) {
|
|
|
|
sExitManager = new AtExitManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MessageLoop::current()) {
|
2010-02-03 22:17:09 +00:00
|
|
|
sMessageLoop = new MessageLoopForUI(MessageLoop::TYPE_MOZILLA_UI);
|
2014-01-14 16:33:31 +00:00
|
|
|
sMessageLoop->set_thread_name("Gecko");
|
|
|
|
// Set experimental values for main thread hangs:
|
|
|
|
// 512ms for transient hangs and 8192ms for permanent hangs
|
|
|
|
sMessageLoop->set_hang_timeouts(512, 8192);
|
2009-07-29 21:11:42 +00:00
|
|
|
}
|
2009-08-28 19:46:21 +00:00
|
|
|
|
2009-08-28 23:16:19 +00:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default &&
|
|
|
|
!BrowserProcessSubThread::GetMessageLoop(BrowserProcessSubThread::IO)) {
|
2009-08-28 19:46:21 +00:00
|
|
|
scoped_ptr<BrowserProcessSubThread> ioThread(
|
|
|
|
new BrowserProcessSubThread(BrowserProcessSubThread::IO));
|
|
|
|
|
|
|
|
base::Thread::Options options;
|
|
|
|
options.message_loop_type = MessageLoop::TYPE_IO;
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(!ioThread->StartWithOptions(options)))
|
|
|
|
return NS_ERROR_FAILURE;
|
2009-08-28 19:46:21 +00:00
|
|
|
|
|
|
|
sIOThread = ioThread.release();
|
|
|
|
}
|
2009-07-29 21:11:42 +00:00
|
|
|
|
2000-03-05 21:26:01 +00:00
|
|
|
// Establish the main thread here.
|
2006-05-10 17:30:15 +00:00
|
|
|
rv = nsThreadManager::get()->Init();
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
1999-10-30 01:52:55 +00:00
|
|
|
|
2004-05-11 09:38:50 +00:00
|
|
|
// Set up the timer globals/timer thread
|
|
|
|
rv = nsTimerImpl::Startup();
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
2004-05-11 09:38:50 +00:00
|
|
|
|
2011-05-01 18:59:24 +00:00
|
|
|
#ifndef ANDROID
|
2004-06-15 16:38:43 +00:00
|
|
|
// If the locale hasn't already been setup by our embedder,
|
2013-11-19 21:27:37 +00:00
|
|
|
// get us out of the "C" locale and into the system
|
2013-10-10 20:41:00 +00:00
|
|
|
if (strcmp(setlocale(LC_ALL, nullptr), "C") == 0)
|
2004-06-15 16:38:43 +00:00
|
|
|
setlocale(LC_ALL, "");
|
2005-01-30 21:33:47 +00:00
|
|
|
#endif
|
2004-06-15 16:38:43 +00:00
|
|
|
|
2014-02-10 22:57:01 +00:00
|
|
|
#if defined(XP_UNIX)
|
2002-06-10 18:50:11 +00:00
|
|
|
NS_StartupNativeCharsetUtils();
|
2002-06-10 19:44:07 +00:00
|
|
|
#endif
|
2010-08-10 22:08:06 +00:00
|
|
|
|
2000-12-09 04:11:05 +00:00
|
|
|
NS_StartupLocalFile();
|
|
|
|
|
2001-02-19 03:09:57 +00:00
|
|
|
StartupSpecialSystemDirectory();
|
|
|
|
|
2012-08-21 12:02:37 +00:00
|
|
|
nsDirectoryService::RealInit();
|
2002-01-27 23:56:02 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool value;
|
2011-07-21 07:57:07 +00:00
|
|
|
|
2006-05-01 03:47:02 +00:00
|
|
|
if (binDirectory)
|
1999-05-18 21:43:13 +00:00
|
|
|
{
|
2006-05-01 03:47:02 +00:00
|
|
|
rv = binDirectory->IsDirectory(&value);
|
2002-09-27 13:07:01 +00:00
|
|
|
|
2006-05-01 03:47:02 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && value) {
|
|
|
|
nsDirectoryService::gService->Set(NS_XPCOM_INIT_CURRENT_PROCESS_DIR, binDirectory);
|
2001-01-18 22:51:57 +00:00
|
|
|
}
|
2006-05-01 03:47:02 +00:00
|
|
|
}
|
2011-07-21 07:57:07 +00:00
|
|
|
|
|
|
|
if (appFileLocationProvider) {
|
|
|
|
rv = nsDirectoryService::gService->RegisterProvider(appFileLocationProvider);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2006-05-01 03:47:02 +00:00
|
|
|
}
|
2002-01-27 23:56:02 +00:00
|
|
|
|
2011-07-21 07:57:07 +00:00
|
|
|
nsCOMPtr<nsIFile> xpcomLib;
|
|
|
|
|
|
|
|
nsDirectoryService::gService->Get(NS_GRE_DIR,
|
|
|
|
NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(xpcomLib));
|
|
|
|
|
2006-05-01 03:47:02 +00:00
|
|
|
if (xpcomLib) {
|
|
|
|
xpcomLib->AppendNative(nsDependentCString(XPCOM_DLL));
|
|
|
|
nsDirectoryService::gService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib);
|
|
|
|
}
|
2010-08-10 22:08:06 +00:00
|
|
|
|
2011-02-25 11:53:36 +00:00
|
|
|
if (!mozilla::Omnijar::IsInitialized()) {
|
|
|
|
mozilla::Omnijar::Init();
|
2010-08-10 22:08:06 +00:00
|
|
|
}
|
|
|
|
|
2009-09-04 07:23:06 +00:00
|
|
|
if ((sCommandLineWasInitialized = !CommandLine::IsInitialized())) {
|
|
|
|
#ifdef OS_WIN
|
2012-07-30 14:20:58 +00:00
|
|
|
CommandLine::Init(0, nullptr);
|
2009-09-04 07:23:06 +00:00
|
|
|
#else
|
|
|
|
nsCOMPtr<nsIFile> binaryFile;
|
2013-11-19 21:27:37 +00:00
|
|
|
nsDirectoryService::gService->Get(NS_XPCOM_CURRENT_PROCESS_DIR,
|
|
|
|
NS_GET_IID(nsIFile),
|
2009-09-04 07:23:06 +00:00
|
|
|
getter_AddRefs(binaryFile));
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(!binaryFile))
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-09-04 07:23:06 +00:00
|
|
|
rv = binaryFile->AppendNative(NS_LITERAL_CSTRING("nonexistent-executable"));
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
|
|
|
|
2009-09-04 07:23:06 +00:00
|
|
|
nsCString binaryPath;
|
|
|
|
rv = binaryFile->GetNativePath(binaryPath);
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv)))
|
|
|
|
return rv;
|
|
|
|
|
2009-09-04 07:23:06 +00:00
|
|
|
static char const *const argv = { strdup(binaryPath.get()) };
|
|
|
|
CommandLine::Init(1, &argv);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-10-10 20:41:00 +00:00
|
|
|
NS_ASSERTION(nsComponentManagerImpl::gComponentManager == nullptr, "CompMgr not null at init");
|
2006-05-01 03:47:02 +00:00
|
|
|
|
|
|
|
// Create the Component/Service Manager
|
2010-06-11 20:13:26 +00:00
|
|
|
nsComponentManagerImpl::gComponentManager = new nsComponentManagerImpl();
|
|
|
|
NS_ADDREF(nsComponentManagerImpl::gComponentManager);
|
2013-03-25 21:26:00 +00:00
|
|
|
|
|
|
|
// Global cycle collector initialization.
|
|
|
|
if (!nsCycleCollector_init()) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And start it up for this thread too.
|
2013-08-13 17:45:32 +00:00
|
|
|
nsCycleCollector_startup();
|
2010-06-22 16:59:57 +00:00
|
|
|
|
2013-07-20 03:14:34 +00:00
|
|
|
// Register ICU memory functions. This really shouldn't be necessary: the
|
|
|
|
// JS engine should do this on its own inside JS_Init, and memory-reporting
|
|
|
|
// code should call a JSAPI function to observe ICU memory usage. But we
|
|
|
|
// can't define the alloc/free functions in the JS engine, because it can't
|
|
|
|
// depend on the XPCOM-based memory reporting goop. So for now, we have
|
|
|
|
// this oddness.
|
2014-02-11 06:35:32 +00:00
|
|
|
mozilla::SetICUMemoryFunctions();
|
2013-07-20 03:14:34 +00:00
|
|
|
|
|
|
|
// Initialize the JS engine.
|
|
|
|
if (!JS_Init()) {
|
|
|
|
NS_RUNTIMEABORT("JS_Init failed");
|
|
|
|
}
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
rv = nsComponentManagerImpl::gComponentManager->Init();
|
2006-05-01 03:47:02 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
2010-06-11 20:13:26 +00:00
|
|
|
NS_RELEASE(nsComponentManagerImpl::gComponentManager);
|
2006-05-01 03:47:02 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-01-27 23:56:02 +00:00
|
|
|
|
2006-05-01 03:47:02 +00:00
|
|
|
if (result) {
|
2010-06-11 20:13:26 +00:00
|
|
|
NS_ADDREF(*result = nsComponentManagerImpl::gComponentManager);
|
1999-05-18 21:43:13 +00:00
|
|
|
}
|
2000-06-03 09:46:12 +00:00
|
|
|
|
2010-06-10 16:51:43 +00:00
|
|
|
// The iimanager constructor searches and registers XPT files.
|
2010-06-24 00:30:59 +00:00
|
|
|
// (We trigger the singleton's lazy construction here to make that happen.)
|
2013-03-09 02:54:10 +00:00
|
|
|
(void) XPTInterfaceInfoManager::GetSingleton();
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2005-06-07 19:35:20 +00:00
|
|
|
// After autoreg, but before we actually instantiate any components,
|
|
|
|
// add any services listed in the "xpcom-directory-providers" category
|
|
|
|
// to the directory service.
|
|
|
|
nsDirectoryService::gService->RegisterCategoryProviders();
|
|
|
|
|
2013-04-22 20:49:52 +00:00
|
|
|
// Force layout to spin up so that nsContentUtils is available for cx stack
|
|
|
|
// munging.
|
|
|
|
nsCOMPtr<nsISupports> componentLoader = do_GetService("@mozilla.org/moz/jsloader;1");
|
|
|
|
|
2010-08-12 19:37:44 +00:00
|
|
|
mozilla::scache::StartupCache::GetSingleton();
|
2012-04-09 17:53:08 +00:00
|
|
|
mozilla::AvailableMemoryTracker::Activate();
|
2011-12-15 19:48:38 +00:00
|
|
|
|
2002-09-23 21:46:25 +00:00
|
|
|
// Notify observers of xpcom autoregistration start
|
2013-11-19 21:27:37 +00:00
|
|
|
NS_CreateServicesFromCategory(NS_XPCOM_STARTUP_CATEGORY,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr,
|
2002-09-23 21:46:25 +00:00
|
|
|
NS_XPCOM_STARTUP_OBSERVER_ID);
|
2010-10-16 19:58:20 +00:00
|
|
|
#ifdef XP_WIN
|
2012-09-25 00:50:30 +00:00
|
|
|
CreateAnonTempFileRemover();
|
2010-10-16 19:58:20 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-05 03:32:50 +00:00
|
|
|
// We only want the SystemMemoryReporter running in one process, because it
|
|
|
|
// profiles the entire system. The main process is the obvious place for
|
|
|
|
// it.
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
mozilla::SystemMemoryReporter::Init();
|
|
|
|
}
|
|
|
|
|
2013-07-20 03:14:34 +00:00
|
|
|
// The memory reporter manager is up and running -- register a reporter for
|
|
|
|
// ICU's memory usage.
|
2013-11-07 05:35:30 +00:00
|
|
|
RegisterStrongMemoryReporter(new ICUReporter());
|
2013-07-20 03:14:34 +00:00
|
|
|
|
2012-01-10 20:29:58 +00:00
|
|
|
mozilla::Telemetry::Init();
|
|
|
|
|
2012-08-31 19:20:20 +00:00
|
|
|
mozilla::HangMonitor::Startup();
|
2013-11-22 19:17:29 +00:00
|
|
|
mozilla::BackgroundHangMonitor::Startup();
|
2012-08-31 19:20:20 +00:00
|
|
|
|
2014-01-14 16:33:31 +00:00
|
|
|
const MessageLoop* const loop = MessageLoop::current();
|
|
|
|
sMainHangMonitor = new mozilla::BackgroundHangMonitor(
|
|
|
|
loop->thread_name().c_str(),
|
|
|
|
loop->transient_hang_timeout(),
|
|
|
|
loop->permanent_hang_timeout());
|
|
|
|
|
2013-03-28 17:38:05 +00:00
|
|
|
#ifdef MOZ_VISUAL_EVENT_TRACER
|
2012-06-12 17:06:21 +00:00
|
|
|
mozilla::eventtracer::Init();
|
2013-03-28 17:38:05 +00:00
|
|
|
#endif
|
2012-06-12 17:06:21 +00:00
|
|
|
|
2003-08-15 20:37:32 +00:00
|
|
|
return NS_OK;
|
1999-05-18 21:43:13 +00:00
|
|
|
}
|
|
|
|
|
2002-08-12 22:09:25 +00:00
|
|
|
|
1999-07-31 00:07:31 +00:00
|
|
|
//
|
|
|
|
// NS_ShutdownXPCOM()
|
|
|
|
//
|
|
|
|
// The shutdown sequence for xpcom would be
|
|
|
|
//
|
2005-11-30 18:51:27 +00:00
|
|
|
// - Notify "xpcom-shutdown" for modules to release primary (root) references
|
2006-03-03 13:48:25 +00:00
|
|
|
// - Shutdown XPCOM timers
|
2005-11-30 18:51:27 +00:00
|
|
|
// - Notify "xpcom-shutdown-threads" for thread joins
|
2006-01-17 15:41:40 +00:00
|
|
|
// - Shutdown the event queues
|
1999-07-31 00:07:31 +00:00
|
|
|
// - Release the Global Service Manager
|
|
|
|
// - Release all service instances held by the global service manager
|
|
|
|
// - Release the Global Service Manager itself
|
|
|
|
// - Release the Component Manager
|
|
|
|
// - Release all factories cached by the Component Manager
|
2005-11-30 18:51:27 +00:00
|
|
|
// - Notify module loaders to shut down
|
1999-07-31 00:07:31 +00:00
|
|
|
// - Unload Libraries
|
2000-09-13 23:57:52 +00:00
|
|
|
// - Release Contractid Cache held by Component Manager
|
1999-07-31 00:07:31 +00:00
|
|
|
// - Release dll abstraction held by Component Manager
|
|
|
|
// - Release the Registry held by Component Manager
|
|
|
|
// - Finally, release the component manager itself
|
|
|
|
//
|
2005-11-08 18:17:49 +00:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
NS_ShutdownXPCOM(nsIServiceManager* servMgr)
|
2009-06-16 19:36:44 +00:00
|
|
|
{
|
|
|
|
return mozilla::ShutdownXPCOM(servMgr);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2014-02-11 06:35:32 +00:00
|
|
|
void
|
|
|
|
SetICUMemoryFunctions()
|
|
|
|
{
|
|
|
|
static bool sICUReporterInitialized = false;
|
|
|
|
if (!sICUReporterInitialized) {
|
|
|
|
if (!JS_SetICUMemoryFunctions(ICUReporter::Alloc, ICUReporter::Realloc,
|
|
|
|
ICUReporter::Free)) {
|
|
|
|
NS_RUNTIMEABORT("JS_SetICUMemoryFunctions failed.");
|
|
|
|
}
|
|
|
|
sICUReporterInitialized = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-16 19:36:44 +00:00
|
|
|
nsresult
|
|
|
|
ShutdownXPCOM(nsIServiceManager* servMgr)
|
1999-07-28 07:57:39 +00:00
|
|
|
{
|
2011-10-12 17:52:26 +00:00
|
|
|
// Make sure the hang monitor is enabled for shutdown.
|
|
|
|
HangMonitor::NotifyActivity();
|
|
|
|
|
2013-11-19 21:27:37 +00:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_RUNTIMEABORT("Shutdown on wrong thread");
|
|
|
|
}
|
2005-11-30 18:51:27 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsresult rv;
|
2005-11-30 18:51:27 +00:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> moduleLoaders;
|
2002-04-15 22:26:29 +00:00
|
|
|
|
1999-11-09 23:41:24 +00:00
|
|
|
// Notify observers of xpcom shutting down
|
|
|
|
{
|
|
|
|
// Block it so that the COMPtr will get deleted before we hit
|
|
|
|
// servicemanager shutdown
|
2006-01-17 15:41:40 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
nsCOMPtr<nsIThread> thread = do_GetCurrentThread();
|
2013-11-19 21:27:37 +00:00
|
|
|
if (NS_WARN_IF(!thread))
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2006-01-17 15:41:40 +00:00
|
|
|
|
2006-03-21 14:43:56 +00:00
|
|
|
nsRefPtr<nsObserverService> observerService;
|
|
|
|
CallGetService("@mozilla.org/observer-service;1",
|
|
|
|
(nsObserverService**) getter_AddRefs(observerService));
|
2005-11-30 18:51:27 +00:00
|
|
|
|
|
|
|
if (observerService)
|
1999-11-09 23:41:24 +00:00
|
|
|
{
|
2009-11-20 22:25:11 +00:00
|
|
|
(void) observerService->
|
2012-07-30 14:20:58 +00:00
|
|
|
NotifyObservers(nullptr, NS_XPCOM_WILL_SHUTDOWN_OBSERVER_ID,
|
|
|
|
nullptr);
|
2009-11-20 22:25:11 +00:00
|
|
|
|
2001-10-16 03:35:52 +00:00
|
|
|
nsCOMPtr<nsIServiceManager> mgr;
|
|
|
|
rv = NS_GetServiceManager(getter_AddRefs(mgr));
|
1999-11-09 23:41:24 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
2005-11-30 18:51:27 +00:00
|
|
|
(void) observerService->
|
|
|
|
NotifyObservers(mgr, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr);
|
1999-11-09 23:41:24 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-23 14:32:18 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ProcessPendingEvents(thread);
|
2010-08-12 19:37:44 +00:00
|
|
|
mozilla::scache::StartupCache::DeleteSingleton();
|
2005-11-30 18:51:27 +00:00
|
|
|
if (observerService)
|
|
|
|
(void) observerService->
|
2012-07-30 14:20:58 +00:00
|
|
|
NotifyObservers(nullptr, NS_XPCOM_SHUTDOWN_THREADS_OBSERVER_ID,
|
|
|
|
nullptr);
|
2005-11-30 18:51:27 +00:00
|
|
|
|
2013-07-07 20:23:43 +00:00
|
|
|
gXPCOMThreadsShutDown = true;
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ProcessPendingEvents(thread);
|
|
|
|
|
|
|
|
// Shutdown the timer thread and all timers that might still be alive before
|
|
|
|
// shutting down the component manager
|
|
|
|
nsTimerImpl::Shutdown();
|
|
|
|
|
|
|
|
NS_ProcessPendingEvents(thread);
|
2005-11-30 18:51:27 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
// Shutdown all remaining threads. This method does not return until
|
|
|
|
// all threads created using the thread manager (with the exception of
|
|
|
|
// the main thread) have exited.
|
|
|
|
nsThreadManager::get()->Shutdown();
|
2006-01-17 15:41:40 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
NS_ProcessPendingEvents(thread);
|
2006-01-17 15:41:40 +00:00
|
|
|
|
2011-10-12 17:52:26 +00:00
|
|
|
HangMonitor::NotifyActivity();
|
|
|
|
|
2013-11-05 12:45:20 +00:00
|
|
|
// Late-write checks needs to find the profile directory, so it has to
|
2013-02-13 18:53:21 +00:00
|
|
|
// be initialized before mozilla::services::Shutdown or (because of
|
|
|
|
// xpcshell tests replacing the service) modules being unloaded.
|
2013-11-05 12:45:20 +00:00
|
|
|
mozilla::InitLateWriteChecks();
|
2013-02-13 18:53:21 +00:00
|
|
|
|
2005-11-30 18:51:27 +00:00
|
|
|
// We save the "xpcom-shutdown-loaders" observers to notify after
|
|
|
|
// the observerservice is gone.
|
2006-03-21 14:43:56 +00:00
|
|
|
if (observerService) {
|
2005-11-30 18:51:27 +00:00
|
|
|
observerService->
|
|
|
|
EnumerateObservers(NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
|
|
|
|
getter_AddRefs(moduleLoaders));
|
2006-03-21 14:43:56 +00:00
|
|
|
|
|
|
|
observerService->Shutdown();
|
|
|
|
}
|
2005-11-23 20:21:46 +00:00
|
|
|
}
|
2005-11-30 18:51:27 +00:00
|
|
|
|
2012-01-26 20:54:03 +00:00
|
|
|
// Free ClearOnShutdown()'ed smart pointers. This needs to happen *after*
|
|
|
|
// we've finished notifying observers of XPCOM shutdown, because shutdown
|
|
|
|
// observers themselves might call ClearOnShutdown().
|
|
|
|
mozilla::KillClearOnShutdown();
|
|
|
|
|
2001-10-25 21:03:35 +00:00
|
|
|
// XPCOM is officially in shutdown mode NOW
|
|
|
|
// Set this only after the observers have been notified as this
|
|
|
|
// will cause servicemanager to become inaccessible.
|
2010-04-02 18:38:25 +00:00
|
|
|
mozilla::services::Shutdown();
|
2000-01-10 21:26:56 +00:00
|
|
|
|
2002-05-11 21:15:06 +00:00
|
|
|
#ifdef DEBUG_dougt
|
|
|
|
fprintf(stderr, "* * * * XPCOM shutdown. Access will be denied * * * * \n");
|
|
|
|
#endif
|
1999-09-25 20:11:33 +00:00
|
|
|
// We may have AddRef'd for the caller of NS_InitXPCOM, so release it
|
|
|
|
// here again:
|
1999-09-24 06:26:17 +00:00
|
|
|
NS_IF_RELEASE(servMgr);
|
1999-12-08 02:03:25 +00:00
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
// Shutdown global servicemanager
|
|
|
|
if (nsComponentManagerImpl::gComponentManager) {
|
|
|
|
nsComponentManagerImpl::gComponentManager->FreeServices();
|
|
|
|
}
|
|
|
|
|
2000-02-21 21:52:18 +00:00
|
|
|
// Release the directory service
|
2005-06-07 19:35:20 +00:00
|
|
|
NS_IF_RELEASE(nsDirectoryService::gService);
|
1999-10-30 06:45:45 +00:00
|
|
|
|
2005-11-30 18:51:27 +00:00
|
|
|
if (moduleLoaders) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool more;
|
2005-11-30 18:51:27 +00:00
|
|
|
nsCOMPtr<nsISupports> el;
|
|
|
|
while (NS_SUCCEEDED(moduleLoaders->HasMoreElements(&more)) &&
|
|
|
|
more) {
|
|
|
|
moduleLoaders->GetNext(getter_AddRefs(el));
|
|
|
|
|
|
|
|
// Don't worry about weak-reference observers here: there is
|
|
|
|
// no reason for weak-ref observers to register for
|
|
|
|
// xpcom-shutdown-loaders
|
|
|
|
|
2013-03-06 21:04:58 +00:00
|
|
|
// FIXME: This can cause harmless writes from sqlite committing
|
|
|
|
// log files. We have to ignore them before we can move
|
|
|
|
// the mozilla::PoisonWrite call before this point. See bug
|
|
|
|
// 834945 for the details.
|
2005-11-30 18:51:27 +00:00
|
|
|
nsCOMPtr<nsIObserver> obs(do_QueryInterface(el));
|
|
|
|
if (obs)
|
2012-07-30 14:20:58 +00:00
|
|
|
(void) obs->Observe(nullptr,
|
2005-11-30 18:51:27 +00:00
|
|
|
NS_XPCOM_SHUTDOWN_LOADERS_OBSERVER_ID,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr);
|
2005-11-30 18:51:27 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
moduleLoaders = nullptr;
|
2005-11-30 18:51:27 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:42:39 +00:00
|
|
|
nsCycleCollector_shutdown();
|
|
|
|
|
2013-03-16 04:47:02 +00:00
|
|
|
PROFILER_MARKER("Shutdown xpcom");
|
2013-03-06 21:04:58 +00:00
|
|
|
// If we are doing any shutdown checks, poison writes.
|
|
|
|
if (gShutdownChecks != SCM_NOTHING) {
|
2013-11-05 12:45:20 +00:00
|
|
|
// Calling InitIOInterposer or InitPoisonIOInterposer twice doesn't
|
|
|
|
// cause any problems, they'll safely abort the initialization on their
|
|
|
|
// own initiative.
|
|
|
|
mozilla::IOInterposer::Init();
|
|
|
|
mozilla::InitPoisonIOInterposer();
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
mozilla::OnlyReportDirtyWrites();
|
|
|
|
#endif /* XP_MACOSX */
|
|
|
|
mozilla::BeginLateWriteChecks();
|
2013-03-06 21:04:58 +00:00
|
|
|
}
|
|
|
|
|
2000-12-09 04:11:05 +00:00
|
|
|
// Shutdown nsLocalFile string conversion
|
|
|
|
NS_ShutdownLocalFile();
|
2002-06-10 19:44:07 +00:00
|
|
|
#ifdef XP_UNIX
|
2002-06-10 18:50:11 +00:00
|
|
|
NS_ShutdownNativeCharsetUtils();
|
2002-06-10 19:44:07 +00:00
|
|
|
#endif
|
2000-12-09 04:11:05 +00:00
|
|
|
|
1999-10-21 21:34:39 +00:00
|
|
|
// Shutdown xpcom. This will release all loaders and cause others holding
|
|
|
|
// a refcount to the component manager to release it.
|
2002-09-12 19:35:49 +00:00
|
|
|
if (nsComponentManagerImpl::gComponentManager) {
|
|
|
|
rv = (nsComponentManagerImpl::gComponentManager)->Shutdown();
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Component Manager shutdown failed.");
|
2013-07-20 03:14:34 +00:00
|
|
|
} else {
|
2002-09-12 19:35:49 +00:00
|
|
|
NS_WARNING("Component Manager was never created ...");
|
2013-07-20 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shut down the JS engine.
|
|
|
|
JS_ShutDown();
|
1999-10-21 21:34:39 +00:00
|
|
|
|
1999-11-10 00:28:34 +00:00
|
|
|
// Release our own singletons
|
|
|
|
// Do this _after_ shutting down the component manager, because the
|
|
|
|
// JS component loader will use XPConnect to call nsIModule::canUnload,
|
|
|
|
// and that will spin up the InterfaceInfoManager again -- bad mojo
|
2013-03-09 02:54:10 +00:00
|
|
|
XPTInterfaceInfoManager::FreeInterfaceInfoManager();
|
1999-11-10 00:28:34 +00:00
|
|
|
|
1999-09-20 20:53:49 +00:00
|
|
|
// Finally, release the component manager last because it unloads the
|
|
|
|
// libraries:
|
2002-02-14 03:26:19 +00:00
|
|
|
if (nsComponentManagerImpl::gComponentManager) {
|
|
|
|
nsrefcnt cnt;
|
|
|
|
NS_RELEASE2(nsComponentManagerImpl::gComponentManager, cnt);
|
2006-03-30 18:40:56 +00:00
|
|
|
NS_ASSERTION(cnt == 0, "Component Manager being held past XPCOM shutdown.");
|
2002-02-14 03:26:19 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
nsComponentManagerImpl::gComponentManager = nullptr;
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCategoryManager::Destroy();
|
1999-10-07 21:50:20 +00:00
|
|
|
|
2000-07-11 07:31:50 +00:00
|
|
|
NS_PurgeAtomTable();
|
1999-10-05 00:07:39 +00:00
|
|
|
|
2003-08-01 14:40:33 +00:00
|
|
|
NS_IF_RELEASE(gDebug);
|
|
|
|
|
2009-08-28 19:46:21 +00:00
|
|
|
if (sIOThread) {
|
|
|
|
delete sIOThread;
|
2012-07-30 14:20:58 +00:00
|
|
|
sIOThread = nullptr;
|
2009-08-28 19:46:21 +00:00
|
|
|
}
|
2009-07-29 21:11:42 +00:00
|
|
|
if (sMessageLoop) {
|
|
|
|
delete sMessageLoop;
|
2012-07-30 14:20:58 +00:00
|
|
|
sMessageLoop = nullptr;
|
2009-07-29 21:11:42 +00:00
|
|
|
}
|
|
|
|
if (sCommandLineWasInitialized) {
|
|
|
|
CommandLine::Terminate();
|
|
|
|
sCommandLineWasInitialized = false;
|
|
|
|
}
|
|
|
|
if (sExitManager) {
|
|
|
|
delete sExitManager;
|
2012-07-30 14:20:58 +00:00
|
|
|
sExitManager = nullptr;
|
2009-07-29 21:11:42 +00:00
|
|
|
}
|
|
|
|
|
2011-10-12 17:52:26 +00:00
|
|
|
Omnijar::CleanUp();
|
|
|
|
|
|
|
|
HangMonitor::Shutdown();
|
2014-01-14 16:33:31 +00:00
|
|
|
|
|
|
|
if (sMainHangMonitor) {
|
|
|
|
delete sMainHangMonitor;
|
|
|
|
sMainHangMonitor = nullptr;
|
|
|
|
}
|
2013-11-22 19:17:29 +00:00
|
|
|
BackgroundHangMonitor::Shutdown();
|
2010-08-10 22:08:06 +00:00
|
|
|
|
2013-03-28 17:38:05 +00:00
|
|
|
#ifdef MOZ_VISUAL_EVENT_TRACER
|
2012-06-12 17:06:21 +00:00
|
|
|
eventtracer::Shutdown();
|
2013-03-28 17:38:05 +00:00
|
|
|
#endif
|
2012-06-12 17:06:21 +00:00
|
|
|
|
2013-04-18 15:34:49 +00:00
|
|
|
profiler_shutdown();
|
|
|
|
|
2010-03-04 19:50:28 +00:00
|
|
|
NS_LogTerm();
|
|
|
|
|
1999-07-28 07:57:39 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-06-16 19:36:44 +00:00
|
|
|
|
|
|
|
} // namespace mozilla
|