2013-01-18 05:43:21 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set ts=8 sts=4 et sw=4 tw=80: */
|
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-11-06 03:43:54 +00:00
|
|
|
*
|
2000-05-02 22:38:04 +00:00
|
|
|
* This Original Code has been modified by IBM Corporation.
|
|
|
|
* Modifications made by IBM described herein are
|
|
|
|
* Copyright (c) International Business Machines
|
|
|
|
* Corporation, 2000
|
|
|
|
*
|
|
|
|
* Modifications to Mozilla code or documentation
|
|
|
|
* identified per MPL Section 3.3
|
|
|
|
*
|
|
|
|
* Date Modified by Description of modification
|
|
|
|
* 04/20/2000 IBM Corp. Added PR_CALLBACK for Optlink use in OS2
|
1999-03-09 09:44:27 +00:00
|
|
|
*/
|
2011-08-18 13:46:39 +00:00
|
|
|
|
1999-06-22 14:02:58 +00:00
|
|
|
#include <stdlib.h>
|
2000-04-25 05:11:30 +00:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsISupports.h"
|
2001-10-16 03:35:52 +00:00
|
|
|
#include "nspr.h"
|
2002-06-14 21:33:05 +00:00
|
|
|
#include "nsCRT.h" // for atoll
|
2011-08-18 13:46:39 +00:00
|
|
|
|
2002-05-02 21:25:08 +00:00
|
|
|
// Arena used by component manager for storing contractid string, dll
|
|
|
|
// location strings and small objects
|
|
|
|
// CAUTION: Arena align mask needs to be defined before including plarena.h
|
|
|
|
// currently from nsComponentManager.h
|
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK 7
|
2003-03-14 05:07:24 +00:00
|
|
|
#define NS_CM_BLOCK_SIZE (1024 * 8)
|
2002-05-02 21:25:08 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "nsCategoryManager.h"
|
1999-06-22 14:02:58 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "nsComponentManager.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsDirectoryService.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2002-07-18 05:09:10 +00:00
|
|
|
#include "nsCategoryManager.h"
|
2002-03-21 23:43:21 +00:00
|
|
|
#include "nsCategoryManagerUtils.h"
|
2005-11-08 18:17:49 +00:00
|
|
|
#include "xptiprivate.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-03-09 02:54:10 +00:00
|
|
|
#include "mozilla/XPTInterfaceInfoManager.h"
|
2005-12-13 17:55:43 +00:00
|
|
|
#include "nsIConsoleService.h"
|
2012-10-19 12:07:36 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
2005-12-13 17:55:43 +00:00
|
|
|
#include "nsIStringEnumerator.h"
|
2002-09-03 23:36:13 +00:00
|
|
|
#include "nsXPCOM.h"
|
2005-07-21 13:33:43 +00:00
|
|
|
#include "nsXPCOMPrivate.h"
|
1999-08-09 05:02:25 +00:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2006-03-15 04:59:42 +00:00
|
|
|
#include "nsIClassInfo.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "nsLocalFile.h"
|
2003-03-05 03:22:12 +00:00
|
|
|
#include "nsReadableUtils.h"
|
|
|
|
#include "nsString.h"
|
1999-11-10 00:28:34 +00:00
|
|
|
#include "nsXPIDLString.h"
|
1999-03-09 09:44:27 +00:00
|
|
|
#include "prcmon.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
#include "xptinfo.h" // this after nsISupports, to pick up IID so that xpt stuff doesn't try to define it itself...
|
2008-09-04 22:44:41 +00:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "prthread.h"
|
2009-01-08 08:41:55 +00:00
|
|
|
#include "private/pprthred.h"
|
2009-04-03 16:43:08 +00:00
|
|
|
#include "nsTArray.h"
|
2009-11-05 14:08:49 +00:00
|
|
|
#include "prio.h"
|
2010-06-11 20:13:26 +00:00
|
|
|
#include "ManifestParser.h"
|
2011-07-29 09:20:47 +00:00
|
|
|
#include "mozilla/Services.h"
|
2002-06-14 21:33:05 +00:00
|
|
|
|
|
|
|
#include "nsManifestLineReader.h"
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "mozilla/GenericFactory.h"
|
|
|
|
#include "nsSupportsPrimitives.h"
|
|
|
|
#include "nsArrayEnumerator.h"
|
|
|
|
#include "nsStringEnumerator.h"
|
2011-12-08 10:03:36 +00:00
|
|
|
#include "mozilla/FileUtils.h"
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2013-07-12 00:16:41 +00:00
|
|
|
#include <new> // for placement new
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2010-06-15 19:38:46 +00:00
|
|
|
#include "mozilla/Omnijar.h"
|
|
|
|
|
2000-10-28 22:17:53 +00:00
|
|
|
#include "prlog.h"
|
2002-01-29 21:22:13 +00:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 04:29:02 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
PRLogModuleInfo* nsComponentManagerLog = nullptr;
|
1999-06-14 02:07:03 +00:00
|
|
|
|
2013-06-15 09:50:25 +00:00
|
|
|
// defined in nsStaticXULComponents.cpp to contain all the components in
|
|
|
|
// libxul.
|
|
|
|
extern mozilla::Module const *const *const kPStaticModules[];
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
#if 0 || defined (DEBUG_timeless)
|
|
|
|
#define SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
#define SHOW_CI_ON_EXISTING_SERVICE
|
2002-01-10 06:55:18 +00:00
|
|
|
#endif
|
2002-01-10 02:10:37 +00:00
|
|
|
|
2001-11-30 07:50:03 +00:00
|
|
|
// Bloated registry buffer size to improve startup performance -- needs to
|
|
|
|
// be big enough to fit the entire file into memory or it'll thrash.
|
|
|
|
// 512K is big enough to allow for some future growth in the registry.
|
|
|
|
#define BIG_REGISTRY_BUFLEN (512*1024)
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
// Common Key Names
|
2000-02-20 03:12:59 +00:00
|
|
|
const char classIDKeyName[]="classID";
|
2002-01-29 21:22:13 +00:00
|
|
|
const char classesKeyName[]="contractID";
|
|
|
|
const char componentsKeyName[]="components";
|
2000-02-16 07:45:20 +00:00
|
|
|
const char xpcomComponentsKeyName[]="software/mozilla/XPCOM/components";
|
2002-01-29 21:22:13 +00:00
|
|
|
const char xpcomKeyName[]="software/mozilla/XPCOM";
|
1999-04-05 00:07:18 +00:00
|
|
|
|
|
|
|
// Common Value Names
|
2000-02-20 03:12:59 +00:00
|
|
|
const char classIDValueName[]="ClassID";
|
2002-01-29 21:22:13 +00:00
|
|
|
const char classNameValueName[]="ClassName";
|
1999-04-05 00:07:18 +00:00
|
|
|
const char componentCountValueName[]="ComponentsCount";
|
2002-01-29 21:22:13 +00:00
|
|
|
const char componentTypeValueName[]="ComponentType";
|
2000-09-13 23:57:52 +00:00
|
|
|
const char contractIDValueName[]="ContractID";
|
2002-01-29 21:22:13 +00:00
|
|
|
const char fileSizeValueName[]="FileSize";
|
1999-04-05 00:07:18 +00:00
|
|
|
const char inprocServerValueName[]="InprocServer";
|
2002-01-29 21:22:13 +00:00
|
|
|
const char lastModValueName[]="LastModTimeStamp";
|
1999-09-02 07:00:29 +00:00
|
|
|
const char nativeComponentType[]="application/x-mozilla-native";
|
2001-06-20 20:21:49 +00:00
|
|
|
const char staticComponentType[]="application/x-mozilla-static";
|
2010-06-15 19:38:46 +00:00
|
|
|
const char jarComponentType[]="application/x-mozilla-jarjs";
|
2002-01-29 21:22:13 +00:00
|
|
|
const char versionValueName[]="VersionString";
|
1999-04-05 00:07:18 +00:00
|
|
|
|
1999-09-07 05:06:37 +00:00
|
|
|
const static char XPCOM_ABSCOMPONENT_PREFIX[] = "abs:";
|
|
|
|
const static char XPCOM_RELCOMPONENT_PREFIX[] = "rel:";
|
2003-03-05 03:22:12 +00:00
|
|
|
const static char XPCOM_GRECOMPONENT_PREFIX[] = "gre:";
|
1999-09-07 05:06:37 +00:00
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
static const char gIDFormat[] =
|
2003-03-14 05:07:24 +00:00
|
|
|
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
|
|
|
|
|
2001-09-06 21:13:11 +00:00
|
|
|
|
|
|
|
#define NS_EMPTY_IID \
|
|
|
|
{ \
|
|
|
|
0x00000000, \
|
|
|
|
0x0000, \
|
|
|
|
0x0000, \
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DEFINE_CID(kEmptyCID, NS_EMPTY_IID);
|
2002-06-14 21:33:05 +00:00
|
|
|
NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
|
2001-09-06 21:13:11 +00:00
|
|
|
|
2003-03-14 05:07:24 +00:00
|
|
|
#define UID_STRING_LENGTH 39
|
|
|
|
|
2001-09-06 21:13:11 +00:00
|
|
|
nsresult
|
2002-10-05 23:59:57 +00:00
|
|
|
nsGetServiceFromCategory::operator()(const nsIID& aIID, void** aInstancePtr) const
|
2002-03-21 23:43:21 +00:00
|
|
|
{
|
2002-10-05 23:59:57 +00:00
|
|
|
nsresult rv;
|
2002-03-21 23:43:21 +00:00
|
|
|
nsXPIDLCString value;
|
2004-11-24 22:48:45 +00:00
|
|
|
nsCOMPtr<nsICategoryManager> catman;
|
|
|
|
nsComponentManagerImpl *compMgr = nsComponentManagerImpl::gComponentManager;
|
|
|
|
if (!compMgr) {
|
|
|
|
rv = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2002-03-21 23:43:21 +00:00
|
|
|
if (!mCategory || !mEntry) {
|
|
|
|
// when categories have defaults, use that for null mEntry
|
2002-10-05 23:59:57 +00:00
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
2002-03-21 23:43:21 +00:00
|
|
|
goto error;
|
|
|
|
}
|
2004-11-24 22:48:45 +00:00
|
|
|
|
|
|
|
rv = compMgr->nsComponentManagerImpl::GetService(kCategoryManagerCID,
|
|
|
|
NS_GET_IID(nsICategoryManager),
|
|
|
|
getter_AddRefs(catman));
|
|
|
|
if (NS_FAILED(rv)) goto error;
|
|
|
|
|
2002-03-21 23:43:21 +00:00
|
|
|
/* find the contractID for category.entry */
|
2002-10-05 23:59:57 +00:00
|
|
|
rv = catman->GetCategoryEntry(mCategory, mEntry,
|
|
|
|
getter_Copies(value));
|
|
|
|
if (NS_FAILED(rv)) goto error;
|
2002-03-21 23:43:21 +00:00
|
|
|
if (!value) {
|
2004-02-29 08:04:46 +00:00
|
|
|
rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
2002-03-21 23:43:21 +00:00
|
|
|
goto error;
|
2001-10-16 03:35:52 +00:00
|
|
|
}
|
2004-11-24 22:48:45 +00:00
|
|
|
|
|
|
|
rv = compMgr->
|
|
|
|
nsComponentManagerImpl::GetServiceByContractID(value,
|
|
|
|
aIID, aInstancePtr);
|
2002-10-05 23:59:57 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2002-03-21 23:43:21 +00:00
|
|
|
error:
|
2001-10-16 03:35:52 +00:00
|
|
|
*aInstancePtr = 0;
|
|
|
|
}
|
2004-12-17 20:16:50 +00:00
|
|
|
if (mErrorPtr)
|
|
|
|
*mErrorPtr = rv;
|
2002-10-05 23:59:57 +00:00
|
|
|
return rv;
|
2001-09-06 21:13:11 +00:00
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2002-05-02 21:25:08 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Arena helper functions
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2003-03-14 05:07:24 +00:00
|
|
|
char *
|
2012-08-22 15:56:38 +00:00
|
|
|
ArenaStrndup(const char *s, uint32_t len, PLArenaPool *arena)
|
2002-05-02 21:25:08 +00:00
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
// Include trailing null in the len
|
2003-03-14 05:07:24 +00:00
|
|
|
PL_ARENA_ALLOCATE(mem, arena, len+1);
|
2002-05-02 21:25:08 +00:00
|
|
|
if (mem)
|
2003-03-14 05:07:24 +00:00
|
|
|
memcpy(mem, s, len+1);
|
2007-07-08 07:08:04 +00:00
|
|
|
return static_cast<char *>(mem);
|
2002-05-02 21:25:08 +00:00
|
|
|
}
|
|
|
|
|
2003-03-14 05:07:24 +00:00
|
|
|
char*
|
|
|
|
ArenaStrdup(const char *s, PLArenaPool *arena)
|
|
|
|
{
|
|
|
|
return ArenaStrndup(s, strlen(s), arena);
|
|
|
|
}
|
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
// GetService and a few other functions need to exit their mutex mid-function
|
|
|
|
// without reentering it later in the block. This class supports that
|
|
|
|
// style of early-exit that MutexAutoUnlock doesn't.
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-04-12 03:21:40 +00:00
|
|
|
class MOZ_STACK_CLASS MutexLock
|
2013-03-13 20:39:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-03-13 20:39:53 +00:00
|
|
|
MutexLock(SafeMutex& aMutex)
|
2013-03-13 20:39:28 +00:00
|
|
|
: mMutex(aMutex)
|
|
|
|
, mLocked(false)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
~MutexLock()
|
|
|
|
{
|
|
|
|
if (mLocked)
|
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Lock()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mLocked, "Re-entering a mutex");
|
|
|
|
mMutex.Lock();
|
|
|
|
mLocked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Unlock()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mLocked, "Exiting a mutex that isn't held!");
|
|
|
|
mMutex.Unlock();
|
|
|
|
mLocked = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutex& mMutex;
|
2013-03-13 20:39:28 +00:00
|
|
|
bool mLocked;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// this is safe to call during InitXPCOM
|
2012-06-06 02:08:30 +00:00
|
|
|
static already_AddRefed<nsIFile>
|
2010-06-21 17:49:38 +00:00
|
|
|
GetLocationFromDirectoryService(const char* prop)
|
2001-10-23 02:28:12 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMPtr<nsIProperties> directoryService;
|
2012-07-30 14:20:58 +00:00
|
|
|
nsDirectoryService::Create(nullptr,
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_GET_IID(nsIProperties),
|
|
|
|
getter_AddRefs(directoryService));
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!directoryService)
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult rv = directoryService->Get(prop,
|
2012-06-06 02:08:30 +00:00
|
|
|
NS_GET_IID(nsIFile),
|
2010-06-10 18:11:11 +00:00
|
|
|
getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv))
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return file.forget();
|
2001-10-23 02:28:12 +00:00
|
|
|
}
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
static already_AddRefed<nsIFile>
|
|
|
|
CloneAndAppend(nsIFile* aBase, const nsACString& append)
|
2010-06-21 17:49:38 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> f;
|
|
|
|
aBase->Clone(getter_AddRefs(f));
|
|
|
|
if (!f)
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2010-06-21 17:49:38 +00:00
|
|
|
|
|
|
|
f->AppendNative(append);
|
2012-06-06 02:08:30 +00:00
|
|
|
return f.forget();
|
2010-06-21 17:49:38 +00:00
|
|
|
}
|
2001-09-06 21:13:11 +00:00
|
|
|
|
1999-03-09 09:44:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-06-10 18:11:11 +00:00
|
|
|
// nsComponentManagerImpl
|
1999-03-09 09:44:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-02-21 20:39:20 +00:00
|
|
|
|
2013-08-27 23:24:51 +00:00
|
|
|
class XPCOMComponentManagerReporter MOZ_FINAL : public MemoryUniReporter
|
2012-10-19 12:07:36 +00:00
|
|
|
{
|
2013-01-18 05:43:21 +00:00
|
|
|
public:
|
|
|
|
XPCOMComponentManagerReporter()
|
2013-08-27 23:24:51 +00:00
|
|
|
: MemoryUniReporter("explicit/xpcom/component-manager",
|
2013-01-18 05:43:21 +00:00
|
|
|
KIND_HEAP, UNITS_BYTES,
|
|
|
|
"Memory used for the XPCOM component manager.")
|
|
|
|
{}
|
|
|
|
private:
|
|
|
|
int64_t Amount() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return nsComponentManagerImpl::gComponentManager
|
|
|
|
? nsComponentManagerImpl::gComponentManager->SizeOfIncludingThis(
|
|
|
|
MallocSizeOf)
|
|
|
|
: 0;
|
|
|
|
}
|
|
|
|
};
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
2008-02-21 20:39:20 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!gComponentManager)
|
|
|
|
return NS_ERROR_FAILURE;
|
1999-06-14 02:07:03 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return gComponentManager->QueryInterface(aIID, aResult);
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsComponentManagerImpl::nsComponentManagerImpl()
|
2013-03-13 20:39:28 +00:00
|
|
|
: mLock("nsComponentManagerImpl.mLock")
|
2010-06-10 18:11:11 +00:00
|
|
|
, mStatus(NOT_INITIALIZED)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-23 17:36:53 +00:00
|
|
|
#define CONTRACTID_HASHTABLE_INITIAL_SIZE 2048
|
2010-06-10 18:11:11 +00:00
|
|
|
|
|
|
|
nsTArray<const mozilla::Module*>* nsComponentManagerImpl::sStaticModules;
|
2008-02-21 20:39:20 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
/* static */ void
|
|
|
|
nsComponentManagerImpl::InitializeStaticModules()
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
if (sStaticModules)
|
|
|
|
return;
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
sStaticModules = new nsTArray<const mozilla::Module*>;
|
2010-11-07 08:25:38 +00:00
|
|
|
for (const mozilla::Module *const *const *staticModules = kPStaticModules;
|
2010-06-10 18:11:11 +00:00
|
|
|
*staticModules; ++staticModules)
|
2010-11-07 08:25:38 +00:00
|
|
|
sStaticModules->AppendElement(**staticModules);
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
nsTArray<nsComponentManagerImpl::ComponentLocation>*
|
|
|
|
nsComponentManagerImpl::sModuleLocations;
|
2010-06-10 18:11:11 +00:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsComponentManagerImpl::InitializeModuleLocations()
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
if (sModuleLocations)
|
|
|
|
return;
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
sModuleLocations = new nsTArray<ComponentLocation>;
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
2001-06-20 20:21:49 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult nsComponentManagerImpl::Init()
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_ASSERT(NOT_INITIALIZED == mStatus);
|
2004-01-22 01:01:19 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if (nsComponentManagerLog == nullptr)
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
|
|
|
nsComponentManagerLog = PR_NewLogModule("nsComponentManager");
|
2001-06-20 20:21:49 +00:00
|
|
|
}
|
2001-08-31 21:45:58 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// Initialize our arena
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "ComponentManagerArena", NS_CM_BLOCK_SIZE);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
mFactories.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE);
|
|
|
|
mContractIDs.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE);
|
2010-06-11 20:13:26 +00:00
|
|
|
mLoaderMap.Init();
|
2011-11-08 17:18:12 +00:00
|
|
|
mKnownModules.Init();
|
2000-01-24 21:28:28 +00:00
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> greDir =
|
2010-06-21 17:49:38 +00:00
|
|
|
GetLocationFromDirectoryService(NS_GRE_DIR);
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> appDir =
|
2010-06-21 17:49:38 +00:00
|
|
|
GetLocationFromDirectoryService(NS_XPCOM_CURRENT_PROCESS_DIR);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
InitializeStaticModules();
|
|
|
|
InitializeModuleLocations();
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-07-22 14:31:29 +00:00
|
|
|
ComponentLocation* cl = sModuleLocations->InsertElementAt(0);
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> lf = CloneAndAppend(appDir, NS_LITERAL_CSTRING("chrome.manifest"));
|
2010-07-22 14:31:29 +00:00
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
2011-11-08 17:10:51 +00:00
|
|
|
cl->location.Init(lf);
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool equals = false;
|
2010-06-21 17:49:38 +00:00
|
|
|
appDir->Equals(greDir, &equals);
|
2010-06-11 20:13:26 +00:00
|
|
|
if (!equals) {
|
2010-07-22 14:31:29 +00:00
|
|
|
cl = sModuleLocations->InsertElementAt(0);
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
2011-11-08 17:10:51 +00:00
|
|
|
lf = CloneAndAppend(greDir, NS_LITERAL_CSTRING("chrome.manifest"));
|
|
|
|
cl->location.Init(lf);
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: Initialized."));
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult rv = mNativeModuleLoader.Init();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCategoryManager::GetSingleton()->SuppressNotifications(true);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2013-06-14 03:57:47 +00:00
|
|
|
RegisterModule(&kXPCOMModule, nullptr);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < sStaticModules->Length(); ++i)
|
2013-06-14 03:57:47 +00:00
|
|
|
RegisterModule((*sStaticModules)[i], nullptr);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
nsRefPtr<nsZipArchive> appOmnijar = mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
|
2011-02-25 11:53:36 +00:00
|
|
|
if (appOmnijar) {
|
|
|
|
cl = sModuleLocations->InsertElementAt(1); // Insert after greDir
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
2011-11-08 17:10:51 +00:00
|
|
|
cl->location.Init(appOmnijar, "chrome.manifest");
|
2011-02-25 11:53:36 +00:00
|
|
|
}
|
2011-11-08 17:10:51 +00:00
|
|
|
nsRefPtr<nsZipArchive> greOmnijar = mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
|
2011-02-25 11:53:36 +00:00
|
|
|
if (greOmnijar) {
|
|
|
|
cl = sModuleLocations->InsertElementAt(0);
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
2011-11-08 17:10:51 +00:00
|
|
|
cl->location.Init(greOmnijar, "chrome.manifest");
|
2010-09-09 03:37:11 +00:00
|
|
|
}
|
2010-07-02 13:53:19 +00:00
|
|
|
|
2011-12-08 10:03:36 +00:00
|
|
|
RereadChromeManifests(false);
|
2010-09-09 03:37:11 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCategoryManager::GetSingleton()->SuppressNotifications(false);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2013-01-18 05:43:21 +00:00
|
|
|
mReporter = new XPCOMComponentManagerReporter();
|
|
|
|
NS_RegisterMemoryReporter(mReporter);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
|
|
|
// Unfortunately, we can't register the nsCategoryManager memory reporter
|
|
|
|
// in its constructor (which is triggered by the GetSingleton() call
|
|
|
|
// above) because the memory reporter manager isn't initialized at that
|
|
|
|
// point. So we wait until now.
|
|
|
|
nsCategoryManager::GetSingleton()->InitMemoryReporter();
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
mStatus = NORMAL;
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return NS_OK;
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule,
|
2011-11-08 17:10:51 +00:00
|
|
|
FileLocation* aFile)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2013-03-13 20:39:28 +00:00
|
|
|
mLock.AssertNotCurrentThreadOwns();
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
{
|
|
|
|
// Scope the monitor so that we don't hold it while calling into the
|
|
|
|
// category manager.
|
|
|
|
MutexLock lock(mLock);
|
|
|
|
|
|
|
|
KnownModule* m;
|
|
|
|
if (aFile) {
|
|
|
|
nsCString uri;
|
|
|
|
aFile->GetURIString(uri);
|
|
|
|
NS_ASSERTION(!mKnownModules.Get(uri),
|
|
|
|
"Must not register a binary module twice.");
|
|
|
|
|
|
|
|
m = new KnownModule(aModule, *aFile);
|
|
|
|
mKnownModules.Put(uri, m);
|
|
|
|
} else {
|
|
|
|
m = new KnownModule(aModule);
|
|
|
|
mKnownStaticModules.AppendElement(m);
|
|
|
|
}
|
2010-12-03 20:24:22 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
if (aModule->mCIDs) {
|
|
|
|
const mozilla::Module::CIDEntry* entry;
|
|
|
|
for (entry = aModule->mCIDs; entry->cid; ++entry)
|
|
|
|
RegisterCIDEntryLocked(entry, m);
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
if (aModule->mContractIDs) {
|
|
|
|
const mozilla::Module::ContractIDEntry* entry;
|
|
|
|
for (entry = aModule->mContractIDs; entry->contractid; ++entry)
|
|
|
|
RegisterContractIDLocked(entry);
|
|
|
|
MOZ_ASSERT(!entry->cid, "Incorrectly terminated contract list");
|
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (aModule->mCategoryEntries) {
|
|
|
|
const mozilla::Module::CategoryEntry* entry;
|
|
|
|
for (entry = aModule->mCategoryEntries; entry->category; ++entry)
|
|
|
|
nsCategoryManager::GetSingleton()->
|
|
|
|
AddCategoryEntry(entry->category,
|
|
|
|
entry->entry,
|
|
|
|
entry->value);
|
|
|
|
}
|
2010-06-11 16:03:06 +00:00
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
void
|
2013-03-13 20:39:28 +00:00
|
|
|
nsComponentManagerImpl::RegisterCIDEntryLocked(
|
|
|
|
const mozilla::Module::CIDEntry* aEntry,
|
|
|
|
KnownModule* aModule)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2013-03-13 20:39:28 +00:00
|
|
|
mLock.AssertCurrentThreadOwns();
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
|
|
|
|
if (f) {
|
2010-12-03 20:24:22 +00:00
|
|
|
NS_WARNING("Re-registering a CID?");
|
2010-06-28 17:55:57 +00:00
|
|
|
|
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
aEntry->cid->ToProvidedString(idstr);
|
|
|
|
|
|
|
|
nsCString existing;
|
|
|
|
if (f->mModule)
|
|
|
|
existing = f->mModule->Description();
|
|
|
|
else
|
|
|
|
existing = "<unknown module>";
|
|
|
|
|
2010-07-13 17:02:22 +00:00
|
|
|
LogMessage("While registering XPCOM module %s, trying to re-register CID '%s' already registered by %s.",
|
2010-06-28 17:55:57 +00:00
|
|
|
aModule->Description().get(),
|
|
|
|
idstr,
|
|
|
|
existing.get());
|
2010-06-10 18:11:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
f = new nsFactoryEntry(aEntry, aModule);
|
|
|
|
mFactories.Put(*aEntry->cid, f);
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
void
|
2013-03-13 20:39:28 +00:00
|
|
|
nsComponentManagerImpl::RegisterContractIDLocked(
|
|
|
|
const mozilla::Module::ContractIDEntry* aEntry)
|
2003-01-28 22:07:53 +00:00
|
|
|
{
|
2013-03-13 20:39:28 +00:00
|
|
|
mLock.AssertCurrentThreadOwns();
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
|
|
|
|
if (!f) {
|
|
|
|
NS_ERROR("No CID found when attempting to map contract ID");
|
2010-06-28 17:55:57 +00:00
|
|
|
|
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
aEntry->cid->ToProvidedString(idstr);
|
|
|
|
|
|
|
|
LogMessage("Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
|
|
|
|
aEntry->contractid,
|
|
|
|
idstr);
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
mContractIDs.Put(nsDependentCString(aEntry->contractid), f);
|
2003-01-28 22:07:53 +00:00
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-07-02 13:53:19 +00:00
|
|
|
static void
|
|
|
|
CutExtension(nsCString& path)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t dotPos = path.RFindChar('.');
|
2010-07-02 13:53:19 +00:00
|
|
|
if (kNotFound == dotPos)
|
|
|
|
path.Truncate();
|
|
|
|
else
|
|
|
|
path.Cut(0, dotPos + 1);
|
|
|
|
}
|
|
|
|
|
2010-09-09 03:37:11 +00:00
|
|
|
void
|
2011-11-08 17:10:51 +00:00
|
|
|
nsComponentManagerImpl::RegisterManifest(NSLocationType aType,
|
|
|
|
FileLocation &aFile,
|
|
|
|
bool aChromeOnly)
|
2010-09-09 03:37:11 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t len;
|
2011-11-08 17:10:51 +00:00
|
|
|
FileLocation::Data data;
|
|
|
|
nsAutoArrayPtr<char> buf;
|
|
|
|
nsresult rv = aFile.GetData(data);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = data.GetSize(&len);
|
2010-08-12 01:11:18 +00:00
|
|
|
}
|
2011-11-08 17:10:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
buf = new char[len + 1];
|
|
|
|
rv = data.Copy(buf, len);
|
2010-07-02 13:53:19 +00:00
|
|
|
}
|
2011-11-08 17:10:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
buf[len] = '\0';
|
|
|
|
ParseManifest(aType, aFile, buf, aChromeOnly);
|
|
|
|
} else if (NS_BOOTSTRAPPED_LOCATION != aType) {
|
|
|
|
nsCString uri;
|
|
|
|
aFile.GetURIString(uri);
|
|
|
|
LogMessage("Could not read chrome manifest '%s'.", uri.get());
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
2010-08-04 18:09:21 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 14:31:29 +00:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestManifest(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* file = argv[0];
|
2011-11-08 17:10:51 +00:00
|
|
|
FileLocation f(cx.mFile, file);
|
|
|
|
RegisterManifest(cx.mType, f, cx.mChromeOnly);
|
2010-07-22 14:31:29 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
2011-11-08 17:10:51 +00:00
|
|
|
if (cx.mFile.IsZip()) {
|
2010-09-09 03:37:11 +00:00
|
|
|
NS_WARNING("Cannot load binary components from a jar.");
|
2011-11-08 17:10:51 +00:00
|
|
|
LogMessageWithContext(cx.mFile, lineno,
|
2010-09-09 03:37:11 +00:00
|
|
|
"Cannot load binary components from a jar.");
|
2010-07-02 13:53:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
FileLocation f(cx.mFile, argv[0]);
|
|
|
|
nsCString uri;
|
|
|
|
f.GetURIString(uri);
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2011-11-08 17:18:12 +00:00
|
|
|
if (mKnownModules.Get(uri)) {
|
2010-12-03 20:24:22 +00:00
|
|
|
NS_WARNING("Attempting to register a binary component twice.");
|
2011-11-08 17:10:51 +00:00
|
|
|
LogMessageWithContext(cx.mFile, lineno,
|
2010-12-03 20:24:22 +00:00
|
|
|
"Attempting to register a binary component twice.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
const mozilla::Module* m = mNativeModuleLoader.LoadModule(f);
|
2011-06-24 18:08:13 +00:00
|
|
|
// The native module loader should report an error here, we don't have to
|
2010-06-28 17:55:57 +00:00
|
|
|
if (!m)
|
2010-06-11 20:13:26 +00:00
|
|
|
return;
|
2010-06-28 17:55:57 +00:00
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
RegisterModule(m, &f);
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2010-06-25 17:55:46 +00:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestXPT(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
2011-11-08 17:10:51 +00:00
|
|
|
FileLocation f(cx.mFile, argv[0]);
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t len;
|
2011-11-08 17:10:51 +00:00
|
|
|
FileLocation::Data data;
|
|
|
|
nsAutoArrayPtr<char> buf;
|
|
|
|
nsresult rv = f.GetData(data);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = data.GetSize(&len);
|
2010-06-25 17:55:46 +00:00
|
|
|
}
|
2011-11-08 17:10:51 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
buf = new char[len];
|
|
|
|
rv = data.Copy(buf, len);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2013-03-09 02:54:10 +00:00
|
|
|
XPTInterfaceInfoManager::GetSingleton()->RegisterBuffer(buf, len);
|
2011-11-08 17:10:51 +00:00
|
|
|
} else {
|
|
|
|
nsCString uri;
|
|
|
|
f.GetURIString(uri);
|
|
|
|
LogMessage("Could not read '%s'.", uri.get());
|
2010-07-02 13:53:19 +00:00
|
|
|
}
|
2010-06-25 17:55:46 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
2013-03-13 20:39:28 +00:00
|
|
|
mLock.AssertNotCurrentThreadOwns();
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
char* id = argv[0];
|
|
|
|
char* file = argv[1];
|
|
|
|
|
|
|
|
nsID cid;
|
|
|
|
if (!cid.Parse(id)) {
|
2011-11-08 17:10:51 +00:00
|
|
|
LogMessageWithContext(cx.mFile, lineno,
|
2010-07-02 13:53:19 +00:00
|
|
|
"Malformed CID: '%s'.", id);
|
2010-06-11 20:13:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
// Precompute the hash/file data outside of the lock
|
|
|
|
FileLocation fl(cx.mFile, file);
|
|
|
|
nsCString hash;
|
|
|
|
fl.GetURIString(hash);
|
|
|
|
|
|
|
|
MutexLock lock(mLock);
|
2010-06-11 20:13:26 +00:00
|
|
|
nsFactoryEntry* f = mFactories.Get(cid);
|
|
|
|
if (f) {
|
2010-06-28 17:55:57 +00:00
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
cid.ToProvidedString(idstr);
|
|
|
|
|
|
|
|
nsCString existing;
|
|
|
|
if (f->mModule)
|
|
|
|
existing = f->mModule->Description();
|
|
|
|
else
|
|
|
|
existing = "<unknown module>";
|
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
lock.Unlock();
|
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
LogMessageWithContext(cx.mFile, lineno,
|
2010-07-02 13:53:19 +00:00
|
|
|
"Trying to re-register CID '%s' already registered by %s.",
|
2010-06-28 17:55:57 +00:00
|
|
|
idstr,
|
|
|
|
existing.get());
|
2010-06-11 20:13:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-02 13:53:19 +00:00
|
|
|
KnownModule* km;
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
km = mKnownModules.Get(hash);
|
|
|
|
if (!km) {
|
|
|
|
km = new KnownModule(fl);
|
|
|
|
mKnownModules.Put(hash, km);
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
|
|
|
|
void* place;
|
|
|
|
|
|
|
|
PL_ARENA_ALLOCATE(place, &mArena, sizeof(nsCID));
|
|
|
|
nsID* permanentCID = static_cast<nsID*>(place);
|
|
|
|
*permanentCID = cid;
|
|
|
|
|
|
|
|
PL_ARENA_ALLOCATE(place, &mArena, sizeof(mozilla::Module::CIDEntry));
|
|
|
|
mozilla::Module::CIDEntry* e = new (place) mozilla::Module::CIDEntry();
|
|
|
|
e->cid = permanentCID;
|
|
|
|
|
|
|
|
f = new nsFactoryEntry(e, km);
|
|
|
|
mFactories.Put(cid, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestContract(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
2013-03-13 20:39:28 +00:00
|
|
|
mLock.AssertNotCurrentThreadOwns();
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
char* contract = argv[0];
|
|
|
|
char* id = argv[1];
|
|
|
|
|
|
|
|
nsID cid;
|
|
|
|
if (!cid.Parse(id)) {
|
2011-11-08 17:10:51 +00:00
|
|
|
LogMessageWithContext(cx.mFile, lineno,
|
2010-07-02 13:53:19 +00:00
|
|
|
"Malformed CID: '%s'.", id);
|
2010-06-11 20:13:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
MutexLock lock(mLock);
|
2010-06-11 20:13:26 +00:00
|
|
|
nsFactoryEntry* f = mFactories.Get(cid);
|
|
|
|
if (!f) {
|
2013-03-13 20:39:28 +00:00
|
|
|
lock.Unlock();
|
2011-11-08 17:10:51 +00:00
|
|
|
LogMessageWithContext(cx.mFile, lineno,
|
2010-07-02 13:53:19 +00:00
|
|
|
"Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
|
2010-06-28 17:55:57 +00:00
|
|
|
contract, id);
|
2010-06-11 20:13:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mContractIDs.Put(nsDependentCString(contract), f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestCategory(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* category = argv[0];
|
|
|
|
char* key = argv[1];
|
|
|
|
char* value = argv[2];
|
|
|
|
|
|
|
|
nsCategoryManager::GetSingleton()->
|
|
|
|
AddCategoryEntry(category, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-08 10:03:36 +00:00
|
|
|
nsComponentManagerImpl::RereadChromeManifests(bool aChromeOnly)
|
2010-06-11 20:13:26 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < sModuleLocations->Length(); ++i) {
|
2010-06-22 20:24:01 +00:00
|
|
|
ComponentLocation& l = sModuleLocations->ElementAt(i);
|
2011-11-08 17:10:51 +00:00
|
|
|
RegisterManifest(l.type, l.location, aChromeOnly);
|
2010-06-22 20:24:01 +00:00
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsComponentManagerImpl::KnownModule::EnsureLoader()
|
|
|
|
{
|
|
|
|
if (!mLoader) {
|
2010-07-02 13:53:19 +00:00
|
|
|
nsCString extension;
|
2011-11-08 17:10:51 +00:00
|
|
|
mFile.GetURIString(extension);
|
|
|
|
CutExtension(extension);
|
2010-06-11 20:13:26 +00:00
|
|
|
mLoader = nsComponentManagerImpl::gComponentManager->LoaderForExtension(extension);
|
|
|
|
}
|
|
|
|
return !!mLoader;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
bool
|
|
|
|
nsComponentManagerImpl::KnownModule::Load()
|
|
|
|
{
|
|
|
|
if (mFailed)
|
|
|
|
return false;
|
|
|
|
if (!mModule) {
|
2010-06-11 20:13:26 +00:00
|
|
|
if (!EnsureLoader())
|
|
|
|
return false;
|
2010-07-02 13:53:19 +00:00
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
mModule = mLoader->LoadModule(mFile);
|
2010-07-02 13:53:19 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!mModule) {
|
|
|
|
mFailed = true;
|
|
|
|
return false;
|
2003-03-05 03:22:12 +00:00
|
|
|
}
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!mLoaded) {
|
2010-06-21 16:46:26 +00:00
|
|
|
if (mModule->loadProc) {
|
|
|
|
nsresult rv = mModule->loadProc();
|
2010-06-10 18:11:11 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mFailed = true;
|
2012-02-01 10:54:21 +00:00
|
|
|
return false;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mLoaded = true;
|
2003-03-11 21:36:59 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
return true;
|
2005-12-03 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 17:55:57 +00:00
|
|
|
nsCString
|
|
|
|
nsComponentManagerImpl::KnownModule::Description() const
|
|
|
|
{
|
|
|
|
nsCString s;
|
2011-11-08 17:10:51 +00:00
|
|
|
if (mFile)
|
|
|
|
mFile.GetURIString(s);
|
2010-06-28 17:55:57 +00:00
|
|
|
else
|
|
|
|
s = "<static module>";
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
nsresult nsComponentManagerImpl::Shutdown(void)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_ASSERT(NORMAL == mStatus);
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
mStatus = SHUTDOWN_IN_PROGRESS;
|
1999-10-21 21:34:39 +00:00
|
|
|
|
|
|
|
// Shutdown the component manager
|
2003-06-17 17:50:00 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning Shutdown."));
|
1999-07-31 05:55:04 +00:00
|
|
|
|
2013-01-18 05:43:21 +00:00
|
|
|
NS_UnregisterMemoryReporter(mReporter);
|
2012-10-19 12:07:36 +00:00
|
|
|
mReporter = nullptr;
|
|
|
|
|
1999-07-31 05:55:04 +00:00
|
|
|
// Release all cached factories
|
2010-06-10 18:11:11 +00:00
|
|
|
mContractIDs.Clear();
|
|
|
|
mFactories.Clear(); // XXX release the objects, don't just clear
|
2010-06-11 20:13:26 +00:00
|
|
|
mLoaderMap.Clear();
|
2011-11-08 17:18:12 +00:00
|
|
|
mKnownModules.Clear();
|
2010-06-25 14:02:17 +00:00
|
|
|
mKnownStaticModules.Clear();
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-25 21:27:10 +00:00
|
|
|
delete sStaticModules;
|
|
|
|
delete sModuleLocations;
|
|
|
|
|
1999-07-31 05:55:04 +00:00
|
|
|
// Unload libraries
|
2005-12-13 17:55:43 +00:00
|
|
|
mNativeModuleLoader.UnloadLibraries();
|
1999-07-31 05:55:04 +00:00
|
|
|
|
2002-05-02 21:25:08 +00:00
|
|
|
// delete arena for strings and small objects
|
|
|
|
PL_FinishArenaPool(&mArena);
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
mStatus = SHUTDOWN_COMPLETE;
|
1999-07-31 05:55:04 +00:00
|
|
|
|
2003-06-17 17:50:00 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Shutdown complete."));
|
1999-10-21 21:34:39 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsComponentManagerImpl::~nsComponentManagerImpl()
|
|
|
|
{
|
2003-06-17 17:50:00 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning destruction."));
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (SHUTDOWN_COMPLETE != mStatus)
|
1999-10-21 21:34:39 +00:00
|
|
|
Shutdown();
|
|
|
|
|
2003-06-17 17:50:00 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Destroyed."));
|
1999-06-14 02:07:03 +00:00
|
|
|
}
|
|
|
|
|
2013-07-19 02:31:26 +00:00
|
|
|
NS_IMPL_ISUPPORTS5(nsComponentManagerImpl,
|
|
|
|
nsIComponentManager,
|
|
|
|
nsIServiceManager,
|
|
|
|
nsIComponentRegistrar,
|
|
|
|
nsISupportsWeakReference,
|
|
|
|
nsIInterfaceRequestor)
|
2008-02-21 20:39:20 +00:00
|
|
|
|
|
|
|
|
2002-01-29 21:22:13 +00:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::GetInterface(const nsIID & uuid, void **result)
|
|
|
|
{
|
2003-03-05 03:22:12 +00:00
|
|
|
NS_WARNING("This isn't supported");
|
|
|
|
// fall through to QI as anything QIable is a superset of what can be
|
2002-01-29 21:22:13 +00:00
|
|
|
// got via the GetInterface()
|
|
|
|
return QueryInterface(uuid, result);
|
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry *
|
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const char *aContractID,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aContractIDLen)
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
2010-06-10 18:11:11 +00:00
|
|
|
return mContractIDs.Get(nsDependentCString(aContractID, aContractIDLen));
|
|
|
|
}
|
1999-06-14 02:07:03 +00:00
|
|
|
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry *
|
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const nsCID &aClass)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
2010-06-10 18:11:11 +00:00
|
|
|
return mFactories.Get(aClass);
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
already_AddRefed<nsIFactory>
|
|
|
|
nsComponentManagerImpl::FindFactory(const nsCID& aClass)
|
|
|
|
{
|
|
|
|
nsFactoryEntry* e = GetFactoryEntry(aClass);
|
|
|
|
if (!e)
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2010-06-10 18:11:11 +00:00
|
|
|
|
|
|
|
return e->GetFactory();
|
2002-06-14 21:33:05 +00:00
|
|
|
}
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
already_AddRefed<nsIFactory>
|
|
|
|
nsComponentManagerImpl::FindFactory(const char *contractID,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aContractIDLen)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(contractID, aContractIDLen);
|
|
|
|
if (!entry)
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return entry->GetFactory();
|
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
/**
|
|
|
|
* GetClassObject()
|
|
|
|
*
|
|
|
|
* Given a classID, this finds the singleton ClassObject that implements the CID.
|
|
|
|
* Returns an interface of type aIID off the singleton classobject.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
2005-12-13 17:55:43 +00:00
|
|
|
nsresult rv;
|
2001-11-30 07:50:03 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", buf);
|
|
|
|
if (buf)
|
|
|
|
NS_Free(buf);
|
|
|
|
}
|
|
|
|
#endif
|
2001-12-14 01:27:16 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
PR_ASSERT(aResult != nullptr);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMPtr<nsIFactory> factory = FindFactory(aClass);
|
|
|
|
if (!factory)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = factory->QueryInterface(aIID, aResult);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::GetClassObjectByContractID(const char *contractID,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_ARG_POINTER(contractID);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult rv;
|
2002-10-05 23:59:57 +00:00
|
|
|
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG))
|
2002-10-05 23:59:57 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", contractID);
|
2002-10-05 23:59:57 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMPtr<nsIFactory> factory = FindFactory(contractID, strlen(contractID));
|
|
|
|
if (!factory)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = factory->QueryInterface(aIID, aResult);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
/**
|
|
|
|
* CreateInstance()
|
|
|
|
*
|
|
|
|
* Create an instance of an object that implements an interface and belongs
|
|
|
|
* to the implementation aClass using the factory. The factory is immediately
|
|
|
|
* released and not held onto for any longer.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
// test this first, since there's no point in creating a component during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Creating new instance on shutdown. Denied.\n"
|
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if (aResult == nullptr)
|
1999-03-31 07:04:12 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass);
|
2003-03-05 03:22:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2005-12-03 15:27:17 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef SHOW_CI_ON_EXISTING_SERVICE
|
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsXPIDLCString cid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString message;
|
2010-06-10 18:11:11 +00:00
|
|
|
message = NS_LITERAL_CSTRING("You are calling CreateInstance \"") +
|
|
|
|
cid + NS_LITERAL_CSTRING("\" when a service for this CID already exists!");
|
|
|
|
NS_ERROR(message.get());
|
2002-06-14 21:33:05 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFactory> factory = entry->GetFactory();
|
|
|
|
if (factory)
|
2000-05-12 01:24:36 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = factory->CreateInstance(aDelegate, aIID, aResult);
|
|
|
|
if (NS_SUCCEEDED(rv) && !*aResult) {
|
|
|
|
NS_ERROR("Factory did not return an object but returned success!");
|
|
|
|
rv = NS_ERROR_SERVICE_NOT_FOUND;
|
2005-02-27 21:32:52 +00:00
|
|
|
}
|
1999-03-10 09:53:25 +00:00
|
|
|
}
|
2010-09-09 03:37:11 +00:00
|
|
|
else {
|
2010-06-10 18:11:11 +00:00
|
|
|
// Translate error values
|
|
|
|
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
2002-06-14 21:33:05 +00:00
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("nsComponentManager: CreateInstance(%s) %s", buf,
|
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
|
|
|
if (buf)
|
|
|
|
NS_Free(buf);
|
1999-03-10 09:53:25 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
1999-03-31 07:04:12 +00:00
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
return rv;
|
1999-03-09 09:44:27 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
/**
|
|
|
|
* CreateInstanceByContractID()
|
|
|
|
*
|
|
|
|
* A variant of CreateInstance() that creates an instance of the object that
|
|
|
|
* implements the interface aIID and whose implementation has a contractID aContractID.
|
|
|
|
*
|
|
|
|
* This is only a convenience routine that turns around can calls the
|
|
|
|
* CreateInstance() with classid and iid.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::CreateInstanceByContractID(const char *aContractID,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
1999-07-02 03:35:09 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aContractID);
|
2000-09-08 01:51:45 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// test this first, since there's no point in creating a component during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Creating new instance on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2003-05-13 22:50:03 +00:00
|
|
|
}
|
2003-03-14 05:07:24 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if (aResult == nullptr)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2002-06-14 21:33:05 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
1999-07-02 03:35:09 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aContractID, strlen(aContractID));
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
1999-07-02 03:35:09 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef SHOW_CI_ON_EXISTING_SERVICE
|
|
|
|
if (entry->mServiceObject) {
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString message;
|
2010-06-10 18:11:11 +00:00
|
|
|
message =
|
|
|
|
NS_LITERAL_CSTRING("You are calling CreateInstance \"") +
|
|
|
|
nsDependentCString(aContractID) +
|
|
|
|
NS_LITERAL_CSTRING("\" when a service for this CID already exists! "
|
|
|
|
"Add it to abusedContracts to track down the service consumer.");
|
|
|
|
NS_ERROR(message.get());
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFactory> factory = entry->GetFactory();
|
|
|
|
if (factory)
|
|
|
|
{
|
1999-09-07 23:18:47 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
rv = factory->CreateInstance(aDelegate, aIID, aResult);
|
|
|
|
if (NS_SUCCEEDED(rv) && !*aResult) {
|
|
|
|
NS_ERROR("Factory did not return an object but returned success!");
|
|
|
|
rv = NS_ERROR_SERVICE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
2010-09-09 03:37:11 +00:00
|
|
|
else {
|
2010-06-10 18:11:11 +00:00
|
|
|
// Translate error values
|
|
|
|
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("nsComponentManager: CreateInstanceByContractID(%s) %s", aContractID,
|
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2002-10-08 06:12:00 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return rv;
|
2002-06-14 21:33:05 +00:00
|
|
|
}
|
2001-11-16 02:38:23 +00:00
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
static PLDHashOperator
|
2010-06-10 18:11:11 +00:00
|
|
|
FreeFactoryEntries(const nsID& aCID,
|
|
|
|
nsFactoryEntry* aEntry,
|
|
|
|
void* arg)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2013-06-14 03:57:47 +00:00
|
|
|
aEntry->mFactory = nullptr;
|
|
|
|
aEntry->mServiceObject = nullptr;
|
2005-12-13 17:55:43 +00:00
|
|
|
return PL_DHASH_NEXT;
|
2002-06-14 21:33:05 +00:00
|
|
|
}
|
2001-11-30 07:50:03 +00:00
|
|
|
|
2002-06-14 21:33:05 +00:00
|
|
|
nsresult
|
2010-06-10 18:11:11 +00:00
|
|
|
nsComponentManagerImpl::FreeServices()
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_ASSERTION(gXPCOMShuttingDown, "Must be shutting down in order to free all services");
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!gXPCOMShuttingDown)
|
|
|
|
return NS_ERROR_FAILURE;
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2013-06-14 03:57:47 +00:00
|
|
|
mFactories.EnumerateRead(FreeFactoryEntries, nullptr);
|
2010-06-10 18:11:11 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// This should only ever be called within the monitor!
|
|
|
|
nsComponentManagerImpl::PendingServiceInfo*
|
|
|
|
nsComponentManagerImpl::AddPendingService(const nsCID& aServiceCID,
|
|
|
|
PRThread* aThread)
|
|
|
|
{
|
|
|
|
PendingServiceInfo* newInfo = mPendingServices.AppendElement();
|
|
|
|
if (newInfo) {
|
|
|
|
newInfo->cid = &aServiceCID;
|
|
|
|
newInfo->thread = aThread;
|
|
|
|
}
|
|
|
|
return newInfo;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// This should only ever be called within the monitor!
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RemovePendingService(const nsCID& aServiceCID)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t pendingCount = mPendingServices.Length();
|
|
|
|
for (uint32_t index = 0; index < pendingCount; ++index) {
|
2010-06-10 18:11:11 +00:00
|
|
|
const PendingServiceInfo& info = mPendingServices.ElementAt(index);
|
|
|
|
if (info.cid->Equals(aServiceCID)) {
|
|
|
|
mPendingServices.RemoveElementAt(index);
|
|
|
|
return;
|
2003-06-18 11:26:27 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2005-12-03 15:27:17 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// This should only ever be called within the monitor!
|
|
|
|
PRThread*
|
|
|
|
nsComponentManagerImpl::GetPendingServiceThread(const nsCID& aServiceCID) const
|
2005-12-13 17:55:43 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t pendingCount = mPendingServices.Length();
|
|
|
|
for (uint32_t index = 0; index < pendingCount; ++index) {
|
2010-06-10 18:11:11 +00:00
|
|
|
const PendingServiceInfo& info = mPendingServices.ElementAt(index);
|
|
|
|
if (info.cid->Equals(aServiceCID)) {
|
|
|
|
return info.thread;
|
2000-05-15 19:28:12 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2005-12-02 16:34:42 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::GetService(const nsCID& aClass,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void* *result)
|
2009-11-05 14:08:49 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Getting service on shutdown. Denied.\n"
|
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2009-11-05 14:08:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
// `service` must be released after the lock is released, so it must be
|
|
|
|
// declared before the lock in this C++ block.
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
MutexLock lock(mLock);
|
2009-11-05 14:08:49 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry* entry = mFactories.Get(aClass);
|
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2009-11-05 14:08:49 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (entry->mServiceObject) {
|
2013-03-13 20:39:28 +00:00
|
|
|
lock.Unlock();
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, result);
|
2009-11-05 14:08:49 +00:00
|
|
|
}
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
PRThread* currentPRThread = PR_GetCurrentThread();
|
2013-02-08 05:54:20 +00:00
|
|
|
MOZ_ASSERT(currentPRThread, "This should never be null!");
|
2005-12-02 16:34:42 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// Needed to optimize the event loop below.
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIThread* currentThread = nullptr;
|
2009-10-16 06:32:29 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
PRThread* pendingPRThread;
|
|
|
|
while ((pendingPRThread = GetPendingServiceThread(aClass))) {
|
|
|
|
if (pendingPRThread == currentPRThread) {
|
|
|
|
NS_ERROR("Recursive GetService!");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2009-10-16 06:32:29 +00:00
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoUnlock unlockPending(mLock);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!currentThread) {
|
|
|
|
currentThread = NS_GetCurrentThread();
|
2013-02-08 05:54:20 +00:00
|
|
|
MOZ_ASSERT(currentThread, "This should never be null!");
|
2001-11-18 20:19:44 +00:00
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// This will process a single event or yield the thread if no event is
|
|
|
|
// pending.
|
2011-10-17 14:59:28 +00:00
|
|
|
if (!NS_ProcessNextEvent(currentThread, false)) {
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_Sleep(PR_INTERVAL_NO_WAIT);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2000-05-15 19:28:12 +00:00
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// It's still possible that the other thread failed to create the
|
|
|
|
// service so we're not guaranteed to have an entry or service yet.
|
|
|
|
if (entry->mServiceObject) {
|
2013-03-13 20:39:28 +00:00
|
|
|
lock.Unlock();
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, result);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
PendingServiceInfo* newInfo =
|
|
|
|
#endif
|
|
|
|
AddPendingService(aClass, currentPRThread);
|
|
|
|
NS_ASSERTION(newInfo, "Failed to add info to the array!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
// We need to not be holding the service manager's lock while calling
|
2010-06-10 18:11:11 +00:00
|
|
|
// CreateInstance, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager:
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
nsresult rv;
|
|
|
|
{
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoUnlock unlock(mLock);
|
2013-03-13 20:39:28 +00:00
|
|
|
rv = CreateInstance(aClass, nullptr, aIID, getter_AddRefs(service));
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv) && !service) {
|
|
|
|
NS_ERROR("Factory did not return an object but returned success");
|
|
|
|
return NS_ERROR_SERVICE_NOT_FOUND;
|
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
pendingPRThread = GetPendingServiceThread(aClass);
|
2013-02-08 05:54:20 +00:00
|
|
|
MOZ_ASSERT(pendingPRThread == currentPRThread,
|
|
|
|
"Pending service array has been changed!");
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
|
|
|
RemovePendingService(aClass);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_ASSERTION(!entry->mServiceObject, "Created two instances of a service!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
entry->mServiceObject = service.forget();
|
|
|
|
|
|
|
|
lock.Unlock();
|
|
|
|
nsISupports** sresult = reinterpret_cast<nsISupports**>(result);
|
|
|
|
*sresult = entry->mServiceObject;
|
|
|
|
(*sresult)->AddRef();
|
|
|
|
|
|
|
|
return NS_OK;
|
2000-04-18 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 17:09:48 +00:00
|
|
|
NS_IMETHODIMP
|
2010-06-10 18:11:11 +00:00
|
|
|
nsComponentManagerImpl::IsServiceInstantiated(const nsCID & aClass,
|
|
|
|
const nsIID& aIID,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *result)
|
1999-08-09 05:02:25 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
// Now we want to get the service if we already got it. If not, we don't want
|
|
|
|
// to create an instance of it. mmh!
|
|
|
|
|
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Checking for service on shutdown. Denied.\n"
|
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-08-09 05:02:25 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
|
|
|
nsFactoryEntry* entry;
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
2010-06-10 18:11:11 +00:00
|
|
|
entry = mFactories.Get(aClass);
|
2001-10-23 02:28:12 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (entry && entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
|
2012-07-30 14:20:58 +00:00
|
|
|
*result = (service!=nullptr);
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return rv;
|
2001-10-23 02:28:12 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_IMETHODIMP nsComponentManagerImpl::IsServiceInstantiatedByContractID(const char *aContractID,
|
|
|
|
const nsIID& aIID,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *result)
|
2001-10-23 02:28:12 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
// Now we want to get the service if we already got it. If not, we don't want
|
|
|
|
// to create an instance of it. mmh!
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Checking for service on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
|
|
|
nsFactoryEntry *entry;
|
|
|
|
{
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
2010-06-10 18:11:11 +00:00
|
|
|
entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (entry && entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
|
2012-07-30 14:20:58 +00:00
|
|
|
*result = (service!=nullptr);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
return rv;
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
2010-06-10 18:11:11 +00:00
|
|
|
nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void* *result)
|
2001-10-23 02:28:12 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Getting service on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2005-12-02 16:34:42 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
// `service` must be released after the lock is released, so it must be
|
|
|
|
// declared before the lock in this C++ block.
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
MutexLock lock(mLock);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry *entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
// We need to not be holding the service manager's monitor while calling
|
|
|
|
// QueryInterface, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager, or try to grab some other lock/monitor/condvar
|
|
|
|
// and deadlock, e.g. bug 282743.
|
2013-03-13 20:39:28 +00:00
|
|
|
// `entry` is valid until XPCOM shutdown, so we can safely use it after
|
|
|
|
// exiting the lock.
|
|
|
|
lock.Unlock();
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, result);
|
2008-02-21 16:23:06 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
PRThread* currentPRThread = PR_GetCurrentThread();
|
2013-02-08 05:54:20 +00:00
|
|
|
MOZ_ASSERT(currentPRThread, "This should never be null!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// Needed to optimize the event loop below.
|
2012-07-30 14:20:58 +00:00
|
|
|
nsIThread* currentThread = nullptr;
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
PRThread* pendingPRThread;
|
|
|
|
while ((pendingPRThread = GetPendingServiceThread(*entry->mCIDEntry->cid))) {
|
|
|
|
if (pendingPRThread == currentPRThread) {
|
|
|
|
NS_ERROR("Recursive GetService!");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoUnlock unlockPending(mLock);
|
2010-06-10 18:11:11 +00:00
|
|
|
|
|
|
|
if (!currentThread) {
|
|
|
|
currentThread = NS_GetCurrentThread();
|
2013-02-08 05:54:20 +00:00
|
|
|
MOZ_ASSERT(currentThread, "This should never be null!");
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
// This will process a single event or yield the thread if no event is
|
|
|
|
// pending.
|
2011-10-17 14:59:28 +00:00
|
|
|
if (!NS_ProcessNextEvent(currentThread, false)) {
|
2010-06-10 18:11:11 +00:00
|
|
|
PR_Sleep(PR_INTERVAL_NO_WAIT);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (currentThread && entry->mServiceObject) {
|
|
|
|
// If we have a currentThread then we must have waited on another thread
|
|
|
|
// to create the service. Grab it now if that succeeded.
|
2013-03-13 20:39:28 +00:00
|
|
|
lock.Unlock();
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, result);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
PendingServiceInfo* newInfo =
|
|
|
|
#endif
|
|
|
|
AddPendingService(*entry->mCIDEntry->cid, currentPRThread);
|
|
|
|
NS_ASSERTION(newInfo, "Failed to add info to the array!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
// We need to not be holding the service manager's lock while calling
|
2010-06-10 18:11:11 +00:00
|
|
|
// CreateInstance, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager:
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
nsresult rv;
|
|
|
|
{
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoUnlock unlock(mLock);
|
2013-03-13 20:39:28 +00:00
|
|
|
rv = CreateInstanceByContractID(aContractID, nullptr, aIID,
|
|
|
|
getter_AddRefs(service));
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv) && !service) {
|
|
|
|
NS_ERROR("Factory did not return an object but returned success");
|
|
|
|
return NS_ERROR_SERVICE_NOT_FOUND;
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
pendingPRThread = GetPendingServiceThread(*entry->mCIDEntry->cid);
|
2013-02-08 05:54:20 +00:00
|
|
|
MOZ_ASSERT(pendingPRThread == currentPRThread,
|
|
|
|
"Pending service array has been changed!");
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
|
|
|
RemovePendingService(*entry->mCIDEntry->cid);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_ASSERTION(!entry->mServiceObject, "Created two instances of a service!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
entry->mServiceObject = service.forget();
|
|
|
|
|
|
|
|
lock.Unlock();
|
|
|
|
|
|
|
|
nsISupports** sresult = reinterpret_cast<nsISupports**>(result);
|
|
|
|
*sresult = entry->mServiceObject;
|
|
|
|
(*sresult)->AddRef();
|
|
|
|
|
|
|
|
return NS_OK;
|
2001-10-23 02:28:12 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
already_AddRefed<mozilla::ModuleLoader>
|
|
|
|
nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
|
2001-10-23 02:28:12 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMPtr<mozilla::ModuleLoader> loader = mLoaderMap.Get(aExt);
|
|
|
|
if (!loader) {
|
|
|
|
loader = do_GetServiceFromCategory("module-loader",
|
|
|
|
PromiseFlatCString(aExt).get());
|
|
|
|
if (!loader)
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
mLoaderMap.Put(aExt, loader);
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return loader.forget();
|
2001-10-23 02:28:12 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
2010-06-10 18:11:11 +00:00
|
|
|
nsComponentManagerImpl::RegisterFactory(const nsCID& aClass,
|
|
|
|
const char* aName,
|
|
|
|
const char* aContractID,
|
|
|
|
nsIFactory* aFactory)
|
1999-08-09 05:02:25 +00:00
|
|
|
{
|
2010-06-23 19:18:13 +00:00
|
|
|
if (!aFactory) {
|
|
|
|
// If a null factory is passed in, this call just wants to reset
|
|
|
|
// the contract ID to point to an existing CID entry.
|
|
|
|
if (!aContractID)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
2010-06-23 19:18:13 +00:00
|
|
|
nsFactoryEntry* oldf = mFactories.Get(aClass);
|
|
|
|
if (!oldf)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
|
|
|
|
mContractIDs.Put(nsDependentCString(aContractID), oldf);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-25 14:44:35 +00:00
|
|
|
nsAutoPtr<nsFactoryEntry> f(new nsFactoryEntry(aClass, aFactory));
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry* oldf = mFactories.Get(aClass);
|
|
|
|
if (oldf)
|
|
|
|
return NS_ERROR_FACTORY_EXISTS;
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2010-06-23 19:18:13 +00:00
|
|
|
if (aContractID)
|
|
|
|
mContractIDs.Put(nsDependentCString(aContractID), f);
|
|
|
|
|
2010-06-23 20:18:08 +00:00
|
|
|
mFactories.Put(aClass, f.forget());
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return NS_OK;
|
1999-08-09 05:02:25 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
2010-06-10 18:11:11 +00:00
|
|
|
nsComponentManagerImpl::UnregisterFactory(const nsCID& aClass,
|
|
|
|
nsIFactory* aFactory)
|
1999-08-09 05:02:25 +00:00
|
|
|
{
|
2010-06-21 16:46:26 +00:00
|
|
|
// Don't release the dying factory or service object until releasing
|
|
|
|
// the component manager monitor.
|
|
|
|
nsCOMPtr<nsIFactory> dyingFactory;
|
|
|
|
nsCOMPtr<nsISupports> dyingServiceObject;
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2010-06-21 16:46:26 +00:00
|
|
|
{
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
2010-06-21 16:46:26 +00:00
|
|
|
nsFactoryEntry* f = mFactories.Get(aClass);
|
|
|
|
if (!f || f->mFactory != aFactory)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
|
|
|
|
mFactories.Remove(aClass);
|
|
|
|
|
|
|
|
// This might leave a stale contractid -> factory mapping in
|
|
|
|
// place, so null out the factory entry (see
|
|
|
|
// nsFactoryEntry::GetFactory)
|
|
|
|
f->mFactory.swap(dyingFactory);
|
|
|
|
f->mServiceObject.swap(dyingServiceObject);
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2010-06-24 18:31:18 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::AutoRegister(nsIFile* aLocation)
|
|
|
|
{
|
2012-06-06 02:08:30 +00:00
|
|
|
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, aLocation);
|
2010-06-24 18:31:18 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::AutoUnregister(nsIFile* aLocation)
|
|
|
|
{
|
|
|
|
NS_ERROR("AutoUnregister not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::RegisterFactoryLocation(const nsCID& aCID,
|
|
|
|
const char* aClassName,
|
|
|
|
const char* aContractID,
|
|
|
|
nsIFile* aFile,
|
|
|
|
const char* aLoaderStr,
|
|
|
|
const char* aType)
|
|
|
|
{
|
|
|
|
NS_ERROR("RegisterFactoryLocation not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::UnregisterFactoryLocation(const nsCID& aCID,
|
|
|
|
nsIFile* aFile)
|
|
|
|
{
|
|
|
|
NS_ERROR("UnregisterFactoryLocation not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::IsCIDRegistered(const nsCID & aClass,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *_retval)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*_retval = (nullptr != GetFactoryEntry(aClass));
|
2010-06-10 18:11:11 +00:00
|
|
|
return NS_OK;
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
1999-09-05 06:27:42 +00:00
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::IsContractIDRegistered(const char *aClass,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *_retval)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2009-01-08 04:42:15 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aClass);
|
2003-03-14 05:07:24 +00:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass, strlen(aClass));
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2004-04-18 17:35:29 +00:00
|
|
|
if (entry)
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = true;
|
2004-04-18 17:35:29 +00:00
|
|
|
else
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = false;
|
2001-10-23 02:28:12 +00:00
|
|
|
return NS_OK;
|
1999-08-09 05:02:25 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static PLDHashOperator
|
|
|
|
EnumerateCIDHelper(const nsID& id, nsFactoryEntry* entry, void* closure)
|
|
|
|
{
|
|
|
|
nsCOMArray<nsISupports> *array = static_cast<nsCOMArray<nsISupports>*>(closure);
|
|
|
|
nsCOMPtr<nsISupportsID> wrapper = new nsSupportsIDImpl();
|
|
|
|
wrapper->SetData(&id);
|
|
|
|
array->AppendObject(wrapper);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-29 21:22:13 +00:00
|
|
|
nsComponentManagerImpl::EnumerateCIDs(nsISimpleEnumerator **aEnumerator)
|
1999-08-09 05:02:25 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMArray<nsISupports> array;
|
|
|
|
mFactories.EnumerateRead(EnumerateCIDHelper, &array);
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return NS_NewArrayEnumerator(aEnumerator, array);
|
|
|
|
}
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static PLDHashOperator
|
|
|
|
EnumerateContractsHelper(const nsACString& contract, nsFactoryEntry* entry, void* closure)
|
|
|
|
{
|
|
|
|
nsTArray<nsCString>* array = static_cast<nsTArray<nsCString>*>(closure);
|
|
|
|
array->AppendElement(contract);
|
|
|
|
return PL_DHASH_NEXT;
|
1999-08-09 05:02:25 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
2002-01-29 21:22:13 +00:00
|
|
|
nsComponentManagerImpl::EnumerateContractIDs(nsISimpleEnumerator **aEnumerator)
|
1999-08-09 05:02:25 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
nsTArray<nsCString>* array = new nsTArray<nsCString>;
|
|
|
|
mContractIDs.EnumerateRead(EnumerateContractsHelper, array);
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsCOMPtr<nsIUTF8StringEnumerator> e;
|
|
|
|
nsresult rv = NS_NewAdoptingUTF8StringEnumerator(getter_AddRefs(e), array);
|
2002-01-29 21:22:13 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
return CallQueryInterface(e, aEnumerator);
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
2000-01-11 22:54:46 +00:00
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::CIDToContractID(const nsCID & aClass,
|
2002-01-29 21:22:13 +00:00
|
|
|
char **_retval)
|
2000-01-11 22:54:46 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_ERROR("CIDTOContractID not implemented");
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2000-01-11 22:54:46 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::ContractIDToCID(const char *aContractID,
|
2002-01-29 21:22:13 +00:00
|
|
|
nsCID * *_retval)
|
2001-08-30 14:10:41 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry* entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
if (entry) {
|
|
|
|
*_retval = (nsCID*) NS_Alloc(sizeof(nsCID));
|
|
|
|
**_retval = *entry->mCIDEntry->cid;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-04-08 00:18:14 +00:00
|
|
|
}
|
2013-06-14 03:57:47 +00:00
|
|
|
*_retval = nullptr;
|
2010-06-10 18:11:11 +00:00
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2001-08-30 14:10:41 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 12:07:36 +00:00
|
|
|
static size_t
|
|
|
|
SizeOfFactoriesEntryExcludingThis(nsIDHashKey::KeyType aKey,
|
|
|
|
nsFactoryEntry* const &aData,
|
2013-06-23 12:03:39 +00:00
|
|
|
MallocSizeOf aMallocSizeOf,
|
2012-10-19 12:07:36 +00:00
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
return aData->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
SizeOfContractIDsEntryExcludingThis(nsCStringHashKey::KeyType aKey,
|
|
|
|
nsFactoryEntry* const &aData,
|
2013-06-23 12:03:39 +00:00
|
|
|
MallocSizeOf aMallocSizeOf,
|
2012-10-19 12:07:36 +00:00
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
// We don't measure the nsFactoryEntry data because its owned by mFactories
|
|
|
|
// (which measures them in SizeOfFactoriesEntryExcludingThis).
|
|
|
|
return aKey.SizeOfExcludingThisMustBeUnshared(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsComponentManagerImpl::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
|
2012-10-19 12:07:36 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mLoaderMap.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
|
|
|
n += mFactories.SizeOfExcludingThis(SizeOfFactoriesEntryExcludingThis, aMallocSizeOf);
|
|
|
|
n += mContractIDs.SizeOfExcludingThis(SizeOfContractIDsEntryExcludingThis, aMallocSizeOf);
|
|
|
|
|
|
|
|
n += sStaticModules->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
n += sModuleLocations->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
n += mKnownStaticModules.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mKnownModules.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
|
|
|
|
2013-02-12 16:54:38 +00:00
|
|
|
n += PL_SizeOfArenaPoolExcludingPool(&mArena, aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
|
|
|
n += mPendingServices.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mLoaderMap's keys and values
|
|
|
|
// - mMon
|
|
|
|
// - sStaticModules' entries
|
|
|
|
// - sModuleLocations' entries
|
|
|
|
// - mNativeModuleLoader
|
|
|
|
// - mKnownStaticModules' entries?
|
|
|
|
// - mKnownModules' keys and values?
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFactoryEntry
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2001-08-30 14:10:41 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const mozilla::Module::CIDEntry* entry,
|
|
|
|
nsComponentManagerImpl::KnownModule* module)
|
|
|
|
: mCIDEntry(entry)
|
|
|
|
, mModule(module)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-25 14:44:35 +00:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID& aCID, nsIFactory* factory)
|
2013-06-14 03:57:47 +00:00
|
|
|
: mCIDEntry(nullptr)
|
|
|
|
, mModule(nullptr)
|
2010-06-10 18:11:11 +00:00
|
|
|
, mFactory(factory)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2010-06-25 14:44:35 +00:00
|
|
|
mozilla::Module::CIDEntry* e = new mozilla::Module::CIDEntry();
|
|
|
|
nsCID* cid = new nsCID;
|
|
|
|
*cid = aCID;
|
|
|
|
e->cid = cid;
|
|
|
|
mCIDEntry = e;
|
2013-06-14 03:57:47 +00:00
|
|
|
}
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2010-06-25 14:44:35 +00:00
|
|
|
nsFactoryEntry::~nsFactoryEntry()
|
|
|
|
{
|
|
|
|
// If this was a RegisterFactory entry, we own the CIDEntry/CID
|
|
|
|
if (!mModule) {
|
|
|
|
delete mCIDEntry->cid;
|
|
|
|
delete mCIDEntry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
already_AddRefed<nsIFactory>
|
|
|
|
nsFactoryEntry::GetFactory()
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2013-03-13 20:39:28 +00:00
|
|
|
nsComponentManagerImpl::gComponentManager->mLock.AssertNotCurrentThreadOwns();
|
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
if (!mFactory) {
|
2010-06-10 18:11:11 +00:00
|
|
|
// RegisterFactory then UnregisterFactory can leave an entry in mContractIDs
|
|
|
|
// pointing to an unusable nsFactoryEntry.
|
|
|
|
if (!mModule)
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2003-03-05 03:22:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!mModule->Load())
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2003-03-05 03:22:12 +00:00
|
|
|
|
2013-03-13 20:39:28 +00:00
|
|
|
// Don't set mFactory directly, it needs to be locked
|
|
|
|
nsCOMPtr<nsIFactory> factory;
|
|
|
|
|
2010-06-21 16:46:26 +00:00
|
|
|
if (mModule->Module()->getFactoryProc) {
|
2013-03-13 20:39:28 +00:00
|
|
|
factory = mModule->Module()->getFactoryProc(*mModule->Module(),
|
|
|
|
*mCIDEntry);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2010-06-21 16:46:26 +00:00
|
|
|
else if (mCIDEntry->getFactoryProc) {
|
2013-03-13 20:39:28 +00:00
|
|
|
factory = mCIDEntry->getFactoryProc(*mModule->Module(), *mCIDEntry);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
else {
|
2010-06-21 16:46:26 +00:00
|
|
|
NS_ASSERTION(mCIDEntry->constructorProc, "no getfactory or constructor");
|
2013-03-13 20:39:28 +00:00
|
|
|
factory = new mozilla::GenericFactory(mCIDEntry->constructorProc);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2013-03-13 20:39:28 +00:00
|
|
|
if (!factory)
|
2013-06-14 03:57:47 +00:00
|
|
|
return nullptr;
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2013-03-13 20:39:53 +00:00
|
|
|
SafeMutexAutoLock lock(nsComponentManagerImpl::gComponentManager->mLock);
|
2013-03-13 20:39:28 +00:00
|
|
|
// Threads can race to set mFactory
|
|
|
|
if (!mFactory) {
|
|
|
|
factory.swap(mFactory);
|
|
|
|
}
|
2003-03-05 03:22:12 +00:00
|
|
|
}
|
2013-04-22 11:15:59 +00:00
|
|
|
nsCOMPtr<nsIFactory> factory = mFactory;
|
|
|
|
return factory.forget();
|
2002-06-14 21:33:05 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 12:07:36 +00:00
|
|
|
size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsFactoryEntry::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf)
|
2012-10-19 12:07:36 +00:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mCIDEntry;
|
|
|
|
// - mModule;
|
|
|
|
// - mFactory;
|
|
|
|
// - mServiceObject;
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2002-01-29 21:22:13 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Static Access Functions
|
1999-03-09 09:44:27 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-18 13:46:39 +00:00
|
|
|
nsresult
|
2001-12-19 00:12:41 +00:00
|
|
|
NS_GetComponentManager(nsIComponentManager* *result)
|
2001-10-16 03:35:52 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2001-10-16 03:35:52 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_ADDREF(*result = nsComponentManagerImpl::gComponentManager);
|
2001-10-16 03:35:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-18 13:46:39 +00:00
|
|
|
nsresult
|
2001-12-19 00:12:41 +00:00
|
|
|
NS_GetServiceManager(nsIServiceManager* *result)
|
2001-09-06 21:13:11 +00:00
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_ADDREF(*result = nsComponentManagerImpl::gComponentManager);
|
2001-12-19 00:12:41 +00:00
|
|
|
return NS_OK;
|
2001-09-06 21:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-18 13:46:39 +00:00
|
|
|
nsresult
|
2002-01-29 21:22:13 +00:00
|
|
|
NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
|
|
|
|
{
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
NS_ADDREF(*result = nsComponentManagerImpl::gComponentManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
XRE_AddStaticComponent(const mozilla::Module* aComponent)
|
|
|
|
{
|
|
|
|
nsComponentManagerImpl::InitializeStaticModules();
|
|
|
|
nsComponentManagerImpl::sStaticModules->AppendElement(aComponent);
|
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager &&
|
|
|
|
nsComponentManagerImpl::NORMAL == nsComponentManagerImpl::gComponentManager->mStatus)
|
2013-06-14 03:57:47 +00:00
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterModule(aComponent, nullptr);
|
2010-06-10 18:11:11 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-29 09:20:47 +00:00
|
|
|
NS_IMETHODIMP
|
2012-06-06 02:08:30 +00:00
|
|
|
nsComponentManagerImpl::AddBootstrappedManifestLocation(nsIFile* aLocation)
|
2011-07-29 09:20:47 +00:00
|
|
|
{
|
|
|
|
nsString path;
|
|
|
|
nsresult rv = aLocation->GetPath(path);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (Substring(path, path.Length() - 4).Equals(NS_LITERAL_STRING(".xpi"))) {
|
|
|
|
return XRE_AddJarManifestLocation(NS_BOOTSTRAPPED_LOCATION, aLocation);
|
|
|
|
}
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> manifest =
|
2011-07-29 09:20:47 +00:00
|
|
|
CloneAndAppend(aLocation, NS_LITERAL_CSTRING("chrome.manifest"));
|
|
|
|
return XRE_AddManifestLocation(NS_BOOTSTRAPPED_LOCATION, manifest);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-06-06 02:08:30 +00:00
|
|
|
nsComponentManagerImpl::RemoveBootstrappedManifestLocation(nsIFile* aLocation)
|
2011-07-29 09:20:47 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIChromeRegistry> cr = mozilla::services::GetChromeRegistryService();
|
|
|
|
if (!cr)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> manifest;
|
2011-07-29 09:20:47 +00:00
|
|
|
nsString path;
|
|
|
|
nsresult rv = aLocation->GetPath(path);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
nsComponentManagerImpl::ComponentLocation elem;
|
|
|
|
elem.type = NS_BOOTSTRAPPED_LOCATION;
|
|
|
|
|
2011-07-29 09:20:47 +00:00
|
|
|
if (Substring(path, path.Length() - 4).Equals(NS_LITERAL_STRING(".xpi"))) {
|
2011-11-08 17:10:51 +00:00
|
|
|
elem.location.Init(aLocation, "chrome.manifest");
|
2011-07-29 09:20:47 +00:00
|
|
|
} else {
|
2012-06-06 02:08:30 +00:00
|
|
|
nsCOMPtr<nsIFile> lf = CloneAndAppend(aLocation, NS_LITERAL_CSTRING("chrome.manifest"));
|
2011-11-08 17:10:51 +00:00
|
|
|
elem.location.Init(lf);
|
2011-07-29 09:20:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Remove reference.
|
|
|
|
nsComponentManagerImpl::sModuleLocations->RemoveElement(elem, ComponentLocationComparator());
|
|
|
|
|
|
|
|
rv = cr->CheckForNewChrome();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
2012-06-06 02:08:30 +00:00
|
|
|
XRE_AddManifestLocation(NSLocationType aType, nsIFile* aLocation)
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
|
|
|
nsComponentManagerImpl::InitializeModuleLocations();
|
2010-06-11 20:13:26 +00:00
|
|
|
nsComponentManagerImpl::ComponentLocation* c =
|
|
|
|
nsComponentManagerImpl::sModuleLocations->AppendElement();
|
|
|
|
c->type = aType;
|
2011-11-08 17:10:51 +00:00
|
|
|
c->location.Init(aLocation);
|
2010-06-10 18:11:11 +00:00
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager &&
|
|
|
|
nsComponentManagerImpl::NORMAL == nsComponentManagerImpl::gComponentManager->mStatus)
|
2011-11-08 17:10:51 +00:00
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterManifest(aType, c->location, false);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2002-01-29 21:22:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-09 03:37:11 +00:00
|
|
|
|
|
|
|
EXPORT_XPCOM_API(nsresult)
|
2012-06-06 02:08:30 +00:00
|
|
|
XRE_AddJarManifestLocation(NSLocationType aType, nsIFile* aLocation)
|
2010-09-09 03:37:11 +00:00
|
|
|
{
|
|
|
|
nsComponentManagerImpl::InitializeModuleLocations();
|
|
|
|
nsComponentManagerImpl::ComponentLocation* c =
|
|
|
|
nsComponentManagerImpl::sModuleLocations->AppendElement();
|
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
c->type = aType;
|
|
|
|
c->location.Init(aLocation, "chrome.manifest");
|
2010-09-09 03:37:11 +00:00
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
if (nsComponentManagerImpl::gComponentManager &&
|
|
|
|
nsComponentManagerImpl::NORMAL == nsComponentManagerImpl::gComponentManager->mStatus)
|
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterManifest(aType, c->location, false);
|
2010-09-09 03:37:11 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|