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"
|
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
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "mozilla/GenericFactory.h"
|
|
|
|
#include "nsSupportsPrimitives.h"
|
2013-07-05 19:20:04 +00:00
|
|
|
#include "nsArray.h"
|
|
|
|
#include "nsIMutableArray.h"
|
2010-06-10 18:11:11 +00:00
|
|
|
#include "nsArrayEnumerator.h"
|
|
|
|
#include "nsStringEnumerator.h"
|
2011-12-08 10:03:36 +00:00
|
|
|
#include "mozilla/FileUtils.h"
|
2013-07-05 19:20:04 +00:00
|
|
|
#include "nsNetUtil.h"
|
2014-07-26 00:52:00 +00:00
|
|
|
#include "nsDataHashtable.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
|
|
|
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
const char xpcomComponentsKeyName[] = "software/mozilla/XPCOM/components";
|
|
|
|
const char xpcomKeyName[] = "software/mozilla/XPCOM";
|
1999-04-05 00:07:18 +00:00
|
|
|
|
|
|
|
// Common Value Names
|
2014-08-02 20:44:06 +00:00
|
|
|
const char fileSizeValueName[] = "FileSize";
|
|
|
|
const char lastModValueName[] = "LastModTimeStamp";
|
|
|
|
const char nativeComponentType[] = "application/x-mozilla-native";
|
|
|
|
const char staticComponentType[] = "application/x-mozilla-static";
|
1999-04-05 00:07:18 +00:00
|
|
|
|
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
|
|
|
|
|
2014-07-26 00:52:00 +00:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
|
|
|
typedef nsDataHashtable<nsCStringHashKey, bool> XPTIInfosBookType;
|
2014-08-02 20:44:06 +00:00
|
|
|
static XPTIInfosBookType* sXPTIInfosBook = nullptr;
|
2014-07-26 00:52:00 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
static XPTIInfosBookType*
|
2014-07-26 00:52:00 +00:00
|
|
|
GetXPTIInfosBook()
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!sXPTIInfosBook) {
|
|
|
|
sXPTIInfosBook = new XPTIInfosBookType;
|
|
|
|
}
|
|
|
|
return sXPTIInfosBook;
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
2014-08-02 20:44:06 +00:00
|
|
|
IsRegisteredXPTIInfo(FileLocation& aFile)
|
2014-07-26 00:52:00 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsAutoCString uri;
|
|
|
|
aFile.GetURIString(uri);
|
|
|
|
return GetXPTIInfosBook()->Get(uri);
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-08-02 20:44:06 +00:00
|
|
|
MarkRegisteredXPTIInfo(FileLocation& aFile)
|
2014-07-26 00:52:00 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsAutoCString uri;
|
|
|
|
aFile.GetURIString(uri);
|
|
|
|
GetXPTIInfosBook()->Put(uri, true);
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
#endif /* MOZ_B2G_LOADER */
|
|
|
|
|
2001-09-06 21:13:11 +00:00
|
|
|
nsresult
|
2014-08-02 20:44:06 +00:00
|
|
|
nsGetServiceFromCategory::operator()(const nsIID& aIID,
|
|
|
|
void** aInstancePtr) const
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsXPIDLCString value;
|
|
|
|
nsCOMPtr<nsICategoryManager> catman;
|
|
|
|
nsComponentManagerImpl* compMgr = nsComponentManagerImpl::gComponentManager;
|
|
|
|
if (!compMgr) {
|
|
|
|
rv = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
goto error;
|
|
|
|
}
|
2004-11-24 22:48:45 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!mCategory || !mEntry) {
|
|
|
|
// when categories have defaults, use that for null mEntry
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto error;
|
|
|
|
}
|
2004-11-24 22:48:45 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
rv = compMgr->nsComponentManagerImpl::GetService(kCategoryManagerCID,
|
|
|
|
NS_GET_IID(nsICategoryManager),
|
|
|
|
getter_AddRefs(catman));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto error;
|
|
|
|
}
|
2004-11-24 22:48:45 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
/* find the contractID for category.entry */
|
|
|
|
rv = catman->GetCategoryEntry(mCategory, mEntry,
|
|
|
|
getter_Copies(value));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!value) {
|
|
|
|
rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = compMgr->nsComponentManagerImpl::GetServiceByContractID(value,
|
|
|
|
aIID,
|
|
|
|
aInstancePtr);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
error:
|
|
|
|
*aInstancePtr = 0;
|
|
|
|
}
|
|
|
|
if (mErrorPtr) {
|
|
|
|
*mErrorPtr = rv;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2014-08-02 20:44:06 +00:00
|
|
|
char*
|
|
|
|
ArenaStrndup(const char* aStr, uint32_t aLen, PLArenaPool* aArena)
|
2002-05-02 21:25:08 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
void* mem;
|
|
|
|
// Include trailing null in the aLen
|
|
|
|
PL_ARENA_ALLOCATE(mem, aArena, aLen + 1);
|
|
|
|
if (mem) {
|
|
|
|
memcpy(mem, aStr, aLen + 1);
|
|
|
|
}
|
|
|
|
return static_cast<char*>(mem);
|
2002-05-02 21:25:08 +00:00
|
|
|
}
|
|
|
|
|
2003-03-14 05:07:24 +00:00
|
|
|
char*
|
2014-08-02 20:44:06 +00:00
|
|
|
ArenaStrdup(const char* aStr, PLArenaPool* aArena)
|
2003-03-14 05:07:24 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
return ArenaStrndup(aStr, strlen(aStr), aArena);
|
2003-03-14 05:07:24 +00:00
|
|
|
}
|
|
|
|
|
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:
|
2014-08-05 13:21:27 +00:00
|
|
|
explicit MutexLock(SafeMutex& aMutex)
|
2014-08-02 20:44:06 +00:00
|
|
|
: mMutex(aMutex)
|
|
|
|
, mLocked(false)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
}
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
~MutexLock()
|
|
|
|
{
|
|
|
|
if (mLocked) {
|
|
|
|
Unlock();
|
2013-03-13 20:39:28 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
void Lock()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mLocked, "Re-entering a mutex");
|
|
|
|
mMutex.Lock();
|
|
|
|
mLocked = true;
|
|
|
|
}
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
void Unlock()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mLocked, "Exiting a mutex that isn't held!");
|
|
|
|
mMutex.Unlock();
|
|
|
|
mLocked = false;
|
|
|
|
}
|
2013-03-13 20:39:28 +00:00
|
|
|
|
|
|
|
private:
|
2014-08-02 20:44:06 +00:00
|
|
|
SafeMutex& mMutex;
|
|
|
|
bool mLocked;
|
2013-03-13 20:39:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // 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>
|
2014-08-02 20:44:06 +00:00
|
|
|
GetLocationFromDirectoryService(const char* aProp)
|
2001-10-23 02:28:12 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMPtr<nsIProperties> directoryService;
|
|
|
|
nsDirectoryService::Create(nullptr,
|
|
|
|
NS_GET_IID(nsIProperties),
|
|
|
|
getter_AddRefs(directoryService));
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!directoryService) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
nsresult rv = directoryService->Get(aProp,
|
|
|
|
NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +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>
|
2014-08-02 20:44:06 +00:00
|
|
|
CloneAndAppend(nsIFile* aBase, const nsACString& aAppend)
|
2010-06-21 17:49:38 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMPtr<nsIFile> f;
|
|
|
|
aBase->Clone(getter_AddRefs(f));
|
|
|
|
if (!f) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-06-21 17:49:38 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
f->AppendNative(aAppend);
|
|
|
|
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
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsresult
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::Create(nsISupports* aOuter, REFNSIID aIID,
|
|
|
|
void** aResult)
|
2008-02-21 20:39:20 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (aOuter) {
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
}
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!gComponentManager) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
1999-06-14 02:07:03 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return gComponentManager->QueryInterface(aIID, aResult);
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2013-09-02 08:41:57 +00:00
|
|
|
static const int CONTRACTID_HASHTABLE_INITIAL_SIZE = 2048;
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsComponentManagerImpl::nsComponentManagerImpl()
|
2014-08-02 20:44:06 +00:00
|
|
|
: mFactories(CONTRACTID_HASHTABLE_INITIAL_SIZE)
|
|
|
|
, mContractIDs(CONTRACTID_HASHTABLE_INITIAL_SIZE)
|
|
|
|
, mLock("nsComponentManagerImpl.mLock")
|
|
|
|
, mStatus(NOT_INITIALIZED)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
nsTArray<const mozilla::Module*>* nsComponentManagerImpl::sStaticModules;
|
2008-02-21 20:39:20 +00:00
|
|
|
|
2013-11-19 04:45:31 +00:00
|
|
|
NSMODULE_DEFN(start_kPStaticModules);
|
|
|
|
NSMODULE_DEFN(end_kPStaticModules);
|
|
|
|
|
|
|
|
/* The content between start_kPStaticModules and end_kPStaticModules is gathered
|
|
|
|
* by the linker from various objects containing symbols in a specific section.
|
|
|
|
* ASAN considers (rightfully) the use of this content as a global buffer
|
|
|
|
* overflow. But this is a deliberate and well-considered choice, with no proper
|
|
|
|
* way to make ASAN happy. */
|
|
|
|
MOZ_ASAN_BLACKLIST
|
2010-06-10 18:11:11 +00:00
|
|
|
/* static */ void
|
|
|
|
nsComponentManagerImpl::InitializeStaticModules()
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (sStaticModules) {
|
|
|
|
return;
|
|
|
|
}
|
1999-08-31 21:40:21 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
sStaticModules = new nsTArray<const mozilla::Module*>;
|
|
|
|
for (const mozilla::Module * const* staticModules =
|
|
|
|
&NSMODULE_NAME(start_kPStaticModules) + 1;
|
|
|
|
staticModules < &NSMODULE_NAME(end_kPStaticModules); ++staticModules)
|
|
|
|
if (*staticModules) { // ASAN adds padding
|
|
|
|
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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (sModuleLocations) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
sModuleLocations = new nsTArray<ComponentLocation>;
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
2001-06-20 20:21:49 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::Init()
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_ASSERT(NOT_INITIALIZED == mStatus);
|
2004-01-22 01:01:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!nsComponentManagerLog) {
|
|
|
|
nsComponentManagerLog = PR_NewLogModule("nsComponentManager");
|
|
|
|
}
|
2001-08-31 21:45:58 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// Initialize our arena
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "ComponentManagerArena", NS_CM_BLOCK_SIZE);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMPtr<nsIFile> greDir =
|
|
|
|
GetLocationFromDirectoryService(NS_GRE_DIR);
|
|
|
|
nsCOMPtr<nsIFile> appDir =
|
|
|
|
GetLocationFromDirectoryService(NS_XPCOM_CURRENT_PROCESS_DIR);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
InitializeStaticModules();
|
|
|
|
InitializeModuleLocations();
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
ComponentLocation* cl = sModuleLocations->InsertElementAt(0);
|
|
|
|
nsCOMPtr<nsIFile> lf = CloneAndAppend(appDir,
|
|
|
|
NS_LITERAL_CSTRING("chrome.manifest"));
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
|
|
|
cl->location.Init(lf);
|
|
|
|
|
|
|
|
bool equals = false;
|
|
|
|
appDir->Equals(greDir, &equals);
|
|
|
|
if (!equals) {
|
|
|
|
cl = sModuleLocations->InsertElementAt(0);
|
2010-07-22 14:31:29 +00:00
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
2014-08-02 20:44:06 +00:00
|
|
|
lf = CloneAndAppend(greDir, NS_LITERAL_CSTRING("chrome.manifest"));
|
2011-11-08 17:10:51 +00:00
|
|
|
cl->location.Init(lf);
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: Initialized."));
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv = mNativeModuleLoader.Init();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCategoryManager::GetSingleton()->SuppressNotifications(true);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
RegisterModule(&kXPCOMModule, nullptr);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
for (uint32_t i = 0; i < sStaticModules->Length(); ++i) {
|
|
|
|
RegisterModule((*sStaticModules)[i], nullptr);
|
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsRefPtr<nsZipArchive> appOmnijar =
|
|
|
|
mozilla::Omnijar::GetReader(mozilla::Omnijar::APP);
|
|
|
|
if (appOmnijar) {
|
|
|
|
cl = sModuleLocations->InsertElementAt(1); // Insert after greDir
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
|
|
|
cl->location.Init(appOmnijar, "chrome.manifest");
|
|
|
|
}
|
|
|
|
nsRefPtr<nsZipArchive> greOmnijar =
|
|
|
|
mozilla::Omnijar::GetReader(mozilla::Omnijar::GRE);
|
|
|
|
if (greOmnijar) {
|
|
|
|
cl = sModuleLocations->InsertElementAt(0);
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
|
|
|
cl->location.Init(greOmnijar, "chrome.manifest");
|
|
|
|
}
|
2010-07-02 13:53:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
RereadChromeManifests(false);
|
2010-09-09 03:37:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCategoryManager::GetSingleton()->SuppressNotifications(false);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
RegisterWeakMemoryReporter(this);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +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();
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mStatus = NORMAL;
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
mLock.AssertNotCurrentThreadOwns();
|
|
|
|
|
|
|
|
{
|
|
|
|
// 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);
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (aModule->mCIDs) {
|
|
|
|
const mozilla::Module::CIDEntry* entry;
|
|
|
|
for (entry = aModule->mCIDs; entry->cid; ++entry) {
|
|
|
|
RegisterCIDEntryLocked(entry, m);
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2014-02-10 00:11:37 +00:00
|
|
|
static bool
|
2014-08-02 20:44:06 +00:00
|
|
|
ProcessSelectorMatches(Module::ProcessSelector aSelector)
|
2014-02-10 00:11:37 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (aSelector == Module::ANY_PROCESS) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-10 00:11:37 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
GeckoProcessType type = XRE_GetProcessType();
|
|
|
|
switch (aSelector) {
|
|
|
|
case Module::MAIN_PROCESS_ONLY:
|
|
|
|
return type == GeckoProcessType_Default;
|
|
|
|
case Module::CONTENT_PROCESS_ONLY:
|
|
|
|
return type == GeckoProcessType_Content;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("invalid process aSelector");
|
|
|
|
}
|
2014-02-10 00:11:37 +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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
mLock.AssertCurrentThreadOwns();
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!ProcessSelectorMatches(aEntry->processSelector)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 00:11:37 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
|
|
|
|
if (f) {
|
|
|
|
NS_WARNING("Re-registering a CID?");
|
|
|
|
|
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
aEntry->cid->ToProvidedString(idstr);
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCString existing;
|
|
|
|
if (f->mModule) {
|
|
|
|
existing = f->mModule->Description();
|
|
|
|
} else {
|
|
|
|
existing = "<unknown module>";
|
|
|
|
}
|
|
|
|
SafeMutexAutoUnlock unlock(mLock);
|
|
|
|
LogMessage("While registering XPCOM module %s, trying to re-register CID '%s' already registered by %s.",
|
|
|
|
aModule->Description().get(),
|
|
|
|
idstr,
|
|
|
|
existing.get());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
mLock.AssertCurrentThreadOwns();
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!ProcessSelectorMatches(aEntry->processSelector)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 00:11:37 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
aEntry->cid->ToProvidedString(idstr);
|
2010-06-28 17:55:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
LogMessage("Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
|
|
|
|
aEntry->contractid,
|
|
|
|
idstr);
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
CutExtension(nsCString& aPath)
|
2010-07-02 13:53:19 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
int32_t dotPos = aPath.RFindChar('.');
|
|
|
|
if (kNotFound == dotPos) {
|
|
|
|
aPath.Truncate();
|
|
|
|
} else {
|
|
|
|
aPath.Cut(0, dotPos + 1);
|
|
|
|
}
|
2010-07-02 13:53:19 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 00:52:00 +00:00
|
|
|
static void
|
|
|
|
DoRegisterManifest(NSLocationType aType,
|
2014-08-02 20:44:06 +00:00
|
|
|
FileLocation& aFile,
|
2014-07-26 00:52:00 +00:00
|
|
|
bool aChromeOnly,
|
|
|
|
bool aXPTOnly)
|
2010-09-09 03:37:11 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
MOZ_ASSERT(!aXPTOnly || !nsComponentManagerImpl::gComponentManager);
|
|
|
|
uint32_t len;
|
|
|
|
FileLocation::Data data;
|
|
|
|
nsAutoArrayPtr<char> buf;
|
|
|
|
nsresult rv = aFile.GetData(data);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = data.GetSize(&len);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
buf = new char[len + 1];
|
|
|
|
rv = data.Copy(buf, len);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
buf[len] = '\0';
|
|
|
|
ParseManifest(aType, aFile, buf, aChromeOnly, aXPTOnly);
|
|
|
|
} else if (NS_BOOTSTRAPPED_LOCATION != aType) {
|
|
|
|
nsCString uri;
|
|
|
|
aFile.GetURIString(uri);
|
|
|
|
LogMessage("Could not read chrome manifest '%s'.", uri.get());
|
|
|
|
}
|
2010-08-04 18:09:21 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 00:52:00 +00:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RegisterManifest(NSLocationType aType,
|
2014-08-02 20:44:06 +00:00
|
|
|
FileLocation& aFile,
|
2014-07-26 00:52:00 +00:00
|
|
|
bool aChromeOnly)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
DoRegisterManifest(aType, aFile, aChromeOnly, false);
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
|
2010-07-22 14:31:29 +00:00
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::ManifestManifest(ManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv)
|
2010-07-22 14:31:29 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
char* file = aArgv[0];
|
|
|
|
FileLocation f(aCx.mFile, file);
|
|
|
|
RegisterManifest(aCx.mType, f, aCx.mChromeOnly);
|
2010-07-22 14:31:29 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& aCx,
|
|
|
|
int aLineNo,
|
|
|
|
char* const* aArgv)
|
|
|
|
{
|
|
|
|
if (aCx.mFile.IsZip()) {
|
|
|
|
NS_WARNING("Cannot load binary components from a jar.");
|
|
|
|
LogMessageWithContext(aCx.mFile, aLineNo,
|
|
|
|
"Cannot load binary components from a jar.");
|
|
|
|
return;
|
|
|
|
}
|
2010-07-02 13:53:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
FileLocation f(aCx.mFile, aArgv[0]);
|
|
|
|
nsCString uri;
|
|
|
|
f.GetURIString(uri);
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (mKnownModules.Get(uri)) {
|
|
|
|
NS_WARNING("Attempting to register a binary component twice.");
|
|
|
|
LogMessageWithContext(aCx.mFile, aLineNo,
|
|
|
|
"Attempting to register a binary component twice.");
|
|
|
|
return;
|
|
|
|
}
|
2010-12-03 20:24:22 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
const mozilla::Module* m = mNativeModuleLoader.LoadModule(f);
|
|
|
|
// The native module loader should report an error here, we don't have to
|
|
|
|
if (!m) {
|
|
|
|
return;
|
|
|
|
}
|
2010-06-28 17:55:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
RegisterModule(m, &f);
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 00:52:00 +00:00
|
|
|
static void
|
2014-08-02 20:44:06 +00:00
|
|
|
DoRegisterXPT(FileLocation& aFile)
|
2010-06-25 17:55:46 +00:00
|
|
|
{
|
2014-07-26 00:52:00 +00:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
2014-08-02 20:44:06 +00:00
|
|
|
if (IsRegisteredXPTIInfo(aFile)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-07-26 00:52:00 +00:00
|
|
|
#endif
|
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
uint32_t len;
|
|
|
|
FileLocation::Data data;
|
|
|
|
nsAutoArrayPtr<char> buf;
|
|
|
|
nsresult rv = aFile.GetData(data);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = data.GetSize(&len);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
buf = new char[len];
|
|
|
|
rv = data.Copy(buf, len);
|
|
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
XPTInterfaceInfoManager::GetSingleton()->RegisterBuffer(buf, len);
|
2014-07-26 00:52:00 +00:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
2014-08-02 20:44:06 +00:00
|
|
|
MarkRegisteredXPTIInfo(aFile);
|
2014-07-26 00:52:00 +00:00
|
|
|
#endif
|
2014-08-02 20:44:06 +00:00
|
|
|
} else {
|
|
|
|
nsCString uri;
|
|
|
|
aFile.GetURIString(uri);
|
|
|
|
LogMessage("Could not read '%s'.", uri.get());
|
|
|
|
}
|
2010-06-25 17:55:46 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 00:52:00 +00:00
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::ManifestXPT(ManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv)
|
2014-07-26 00:52:00 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
FileLocation f(aCx.mFile, aArgv[0]);
|
|
|
|
DoRegisterXPT(f);
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
|
2010-06-11 20:13:26 +00:00
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv)
|
2010-06-11 20:13:26 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
mLock.AssertNotCurrentThreadOwns();
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
char* id = aArgv[0];
|
|
|
|
char* file = aArgv[1];
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsID cid;
|
|
|
|
if (!cid.Parse(id)) {
|
|
|
|
LogMessageWithContext(aCx.mFile, aLineNo,
|
|
|
|
"Malformed CID: '%s'.", id);
|
|
|
|
return;
|
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// Precompute the hash/file data outside of the lock
|
|
|
|
FileLocation fl(aCx.mFile, file);
|
|
|
|
nsCString hash;
|
|
|
|
fl.GetURIString(hash);
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
MutexLock lock(mLock);
|
|
|
|
nsFactoryEntry* f = mFactories.Get(cid);
|
|
|
|
if (f) {
|
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
cid.ToProvidedString(idstr);
|
|
|
|
|
|
|
|
nsCString existing;
|
|
|
|
if (f->mModule) {
|
|
|
|
existing = f->mModule->Description();
|
|
|
|
} else {
|
|
|
|
existing = "<unknown module>";
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
lock.Unlock();
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
LogMessageWithContext(aCx.mFile, aLineNo,
|
|
|
|
"Trying to re-register CID '%s' already registered by %s.",
|
|
|
|
idstr,
|
|
|
|
existing.get());
|
|
|
|
return;
|
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
KnownModule* km;
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
km = mKnownModules.Get(hash);
|
|
|
|
if (!km) {
|
|
|
|
km = new KnownModule(fl);
|
|
|
|
mKnownModules.Put(hash, km);
|
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
void* place;
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
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);
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::ManifestContract(ManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv)
|
2010-06-11 20:13:26 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
mLock.AssertNotCurrentThreadOwns();
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
char* contract = aArgv[0];
|
|
|
|
char* id = aArgv[1];
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsID cid;
|
|
|
|
if (!cid.Parse(id)) {
|
|
|
|
LogMessageWithContext(aCx.mFile, aLineNo,
|
|
|
|
"Malformed CID: '%s'.", id);
|
|
|
|
return;
|
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
MutexLock lock(mLock);
|
|
|
|
nsFactoryEntry* f = mFactories.Get(cid);
|
|
|
|
if (!f) {
|
|
|
|
lock.Unlock();
|
|
|
|
LogMessageWithContext(aCx.mFile, aLineNo,
|
|
|
|
"Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
|
|
|
|
contract, id);
|
|
|
|
return;
|
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mContractIDs.Put(nsDependentCString(contract), f);
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::ManifestCategory(ManifestProcessingContext& aCx,
|
|
|
|
int aLineNo, char* const* aArgv)
|
2010-06-11 20:13:26 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
char* category = aArgv[0];
|
|
|
|
char* key = aArgv[1];
|
|
|
|
char* value = aArgv[2];
|
2010-06-11 20:13:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCategoryManager::GetSingleton()->
|
|
|
|
AddCategoryEntry(category, key, value);
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-12-08 10:03:36 +00:00
|
|
|
nsComponentManagerImpl::RereadChromeManifests(bool aChromeOnly)
|
2010-06-11 20:13:26 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
for (uint32_t i = 0; i < sModuleLocations->Length(); ++i) {
|
|
|
|
ComponentLocation& l = sModuleLocations->ElementAt(i);
|
|
|
|
RegisterManifest(l.type, l.location, aChromeOnly);
|
|
|
|
}
|
2010-06-11 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsComponentManagerImpl::KnownModule::EnsureLoader()
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!mLoader) {
|
|
|
|
nsCString extension;
|
|
|
|
mFile.GetURIString(extension);
|
|
|
|
CutExtension(extension);
|
|
|
|
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()
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (mFailed) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!mModule) {
|
|
|
|
if (!EnsureLoader()) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-02 13:53:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mModule = mLoader->LoadModule(mFile);
|
2010-07-02 13:53:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!mModule) {
|
|
|
|
mFailed = true;
|
|
|
|
return false;
|
2003-03-05 03:22:12 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
|
|
|
if (!mLoaded) {
|
|
|
|
if (mModule->loadProc) {
|
|
|
|
nsresult rv = mModule->loadProc();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mFailed = true;
|
|
|
|
return false;
|
|
|
|
}
|
2003-03-11 21:36:59 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +00:00
|
|
|
mLoaded = true;
|
|
|
|
}
|
|
|
|
return true;
|
2005-12-03 15:27:17 +00:00
|
|
|
}
|
|
|
|
|
2010-06-28 17:55:57 +00:00
|
|
|
nsCString
|
|
|
|
nsComponentManagerImpl::KnownModule::Description() const
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCString s;
|
|
|
|
if (mFile) {
|
|
|
|
mFile.GetURIString(s);
|
|
|
|
} else {
|
|
|
|
s = "<static module>";
|
|
|
|
}
|
|
|
|
return s;
|
2010-06-28 17:55:57 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
nsresult nsComponentManagerImpl::Shutdown(void)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_ASSERT(NORMAL == mStatus);
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mStatus = SHUTDOWN_IN_PROGRESS;
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// Shutdown the component manager
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: Beginning Shutdown."));
|
1999-07-31 05:55:04 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
UnregisterWeakMemoryReporter(this);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// Release all cached factories
|
|
|
|
mContractIDs.Clear();
|
|
|
|
mFactories.Clear(); // XXX release the objects, don't just clear
|
|
|
|
mLoaderMap.Clear();
|
|
|
|
mKnownModules.Clear();
|
|
|
|
mKnownStaticModules.Clear();
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
delete sStaticModules;
|
|
|
|
delete sModuleLocations;
|
2014-07-26 00:52:00 +00:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
2014-08-02 20:44:06 +00:00
|
|
|
delete sXPTIInfosBook;
|
|
|
|
sXPTIInfosBook = nullptr;
|
2014-07-26 00:52:00 +00:00
|
|
|
#endif
|
2010-06-25 21:27:10 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// Unload libraries
|
|
|
|
mNativeModuleLoader.UnloadLibraries();
|
1999-07-31 05:55:04 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// delete arena for strings and small objects
|
|
|
|
PL_FinishArenaPool(&mArena);
|
2002-05-02 21:25:08 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mStatus = SHUTDOWN_COMPLETE;
|
1999-07-31 05:55:04 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: Shutdown complete."));
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_OK;
|
1999-10-21 21:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsComponentManagerImpl::~nsComponentManagerImpl()
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: Beginning destruction."));
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (SHUTDOWN_COMPLETE != mStatus) {
|
|
|
|
Shutdown();
|
|
|
|
}
|
1999-10-21 21:34:39 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: Destroyed."));
|
1999-06-14 02:07:03 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsComponentManagerImpl,
|
|
|
|
nsIComponentManager,
|
|
|
|
nsIServiceManager,
|
|
|
|
nsIComponentRegistrar,
|
|
|
|
nsISupportsWeakReference,
|
|
|
|
nsIInterfaceRequestor,
|
|
|
|
nsIMemoryReporter)
|
2008-02-21 20:39:20 +00:00
|
|
|
|
2002-01-29 21:22:13 +00:00
|
|
|
nsresult
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::GetInterface(const nsIID& aUuid, void** aResult)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_WARNING("This isn't supported");
|
|
|
|
// fall through to QI as anything QIable is a superset of what can be
|
|
|
|
// got via the GetInterface()
|
|
|
|
return QueryInterface(aUuid, aResult);
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 20:44:06 +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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
|
|
|
return mContractIDs.Get(nsDependentCString(aContractID, aContractIDLen));
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
1999-06-14 02:07:03 +00:00
|
|
|
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry*
|
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const nsCID& aClass)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
|
|
|
return mFactories.Get(aClass);
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
already_AddRefed<nsIFactory>
|
|
|
|
nsComponentManagerImpl::FindFactory(const nsCID& aClass)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* e = GetFactoryEntry(aClass);
|
|
|
|
if (!e) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +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>
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::FindFactory(const char* aContractID,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aContractIDLen)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* entry = GetFactoryEntry(aContractID, aContractIDLen);
|
|
|
|
if (!entry) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return entry->GetFactory();
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::GetClassObject(const nsCID& aClass, const nsIID& aIID,
|
|
|
|
void** aResult)
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv;
|
2001-11-30 07:50:03 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef PR_LOGGING
|
2014-08-02 20:44:06 +00:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG)) {
|
|
|
|
char* buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", buf);
|
|
|
|
if (buf) {
|
|
|
|
NS_Free(buf);
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
2001-12-14 01:27:16 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_ASSERT(aResult != nullptr);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMPtr<nsIFactory> factory = FindFactory(aClass);
|
|
|
|
if (!factory) {
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
rv = factory->QueryInterface(aIID, aResult);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return rv;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::GetClassObjectByContractID(const char* aContractID,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void** aResult)
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (NS_WARN_IF(!aResult) ||
|
|
|
|
NS_WARN_IF(!aContractID)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv;
|
2002-10-05 23:59:57 +00:00
|
|
|
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef PR_LOGGING
|
2014-08-02 20:44:06 +00:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG)) {
|
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", aContractID);
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMPtr<nsIFactory> factory = FindFactory(aContractID, strlen(aContractID));
|
|
|
|
if (!factory) {
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
rv = factory->QueryInterface(aIID, aResult);
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return rv;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
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
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
2014-08-02 20:44:06 +00:00
|
|
|
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());
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = nullptr;
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* entry = GetFactoryEntry(aClass);
|
2003-03-05 03:22:12 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
2014-08-02 20:44:06 +00:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsXPIDLCString cid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
nsAutoCString message;
|
|
|
|
message = NS_LITERAL_CSTRING("You are calling CreateInstance \"") +
|
|
|
|
cid +
|
|
|
|
NS_LITERAL_CSTRING("\" when a service for this CID already exists!");
|
|
|
|
NS_ERROR(message.get());
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
1999-03-09 09:44:27 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFactory> factory = entry->GetFactory();
|
|
|
|
if (factory) {
|
|
|
|
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;
|
2002-06-14 21:33:05 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +00:00
|
|
|
} else {
|
|
|
|
// 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
|
|
|
#ifdef PR_LOGGING
|
2014-08-02 20:44:06 +00:00
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING)) {
|
|
|
|
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
|
|
|
}
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
1999-03-31 07:04:12 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::CreateInstanceByContractID(const char* aContractID,
|
|
|
|
nsISupports* aDelegate,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void** aResult)
|
|
|
|
{
|
|
|
|
if (NS_WARN_IF(!aContractID)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
2014-08-02 20:44:06 +00:00
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Creating new instance on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2003-03-14 05:07:24 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!aResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = nullptr;
|
1999-07-02 03:35:09 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* entry = GetFactoryEntry(aContractID, strlen(aContractID));
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
2014-08-02 20:44:06 +00:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsAutoCString message;
|
|
|
|
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());
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFactory> factory = entry->GetFactory();
|
|
|
|
if (factory) {
|
1999-09-07 23:18:47 +00:00
|
|
|
|
2014-08-02 20:44:06 +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-06-10 18:11:11 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +00:00
|
|
|
} else {
|
|
|
|
// Translate error values
|
|
|
|
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
|
|
|
2014-08-02 20:44:06 +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,
|
2014-08-02 20:44:06 +00:00
|
|
|
void* aArg)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
aEntry->mFactory = nullptr;
|
|
|
|
aEntry->mServiceObject = nullptr;
|
|
|
|
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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ASSERTION(gXPCOMShuttingDown,
|
|
|
|
"Must be shutting down in order to free all services");
|
2002-06-14 21:33:05 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!gXPCOMShuttingDown) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2003-06-18 23:03:08 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mFactories.EnumerateRead(FreeFactoryEntries, nullptr);
|
|
|
|
return NS_OK;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
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,
|
2014-08-02 20:44:06 +00:00
|
|
|
void** aResult)
|
2009-11-05 14:08:49 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +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
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
2014-08-02 20:44:06 +00:00
|
|
|
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());
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2009-11-05 14:08:49 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* entry = mFactories.Get(aClass);
|
|
|
|
if (!entry) {
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
lock.Unlock();
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, aResult);
|
|
|
|
}
|
2005-12-02 16:34:42 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PRThread* currentPRThread = PR_GetCurrentThread();
|
|
|
|
MOZ_ASSERT(currentPRThread, "This should never be null!");
|
2009-10-16 06:32:29 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// Needed to optimize the event loop below.
|
|
|
|
nsIThread* currentThread = nullptr;
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PRThread* pendingPRThread;
|
|
|
|
while ((pendingPRThread = GetPendingServiceThread(aClass))) {
|
|
|
|
if (pendingPRThread == currentPRThread) {
|
|
|
|
NS_ERROR("Recursive GetService!");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
SafeMutexAutoUnlock unlockPending(mLock);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!currentThread) {
|
|
|
|
currentThread = NS_GetCurrentThread();
|
|
|
|
MOZ_ASSERT(currentThread, "This should never be null!");
|
2000-05-15 19:28:12 +00:00
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// This will process a single event or yield the thread if no event is
|
|
|
|
// pending.
|
|
|
|
if (!NS_ProcessNextEvent(currentThread, false)) {
|
|
|
|
PR_Sleep(PR_INTERVAL_NO_WAIT);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +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) {
|
|
|
|
lock.Unlock();
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, aResult);
|
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef DEBUG
|
2014-08-02 20:44:06 +00:00
|
|
|
PendingServiceInfo* newInfo =
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
|
|
|
AddPendingService(aClass, currentPRThread);
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ASSERTION(newInfo, "Failed to add info to the array!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// We need to not be holding the service manager's lock while calling
|
|
|
|
// CreateInstance, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager:
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv;
|
|
|
|
{
|
|
|
|
SafeMutexAutoUnlock unlock(mLock);
|
|
|
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
pendingPRThread = GetPendingServiceThread(aClass);
|
|
|
|
MOZ_ASSERT(pendingPRThread == currentPRThread,
|
|
|
|
"Pending service array has been changed!");
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
2014-08-02 20:44:06 +00:00
|
|
|
RemovePendingService(aClass);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ASSERTION(!entry->mServiceObject, "Created two instances of a service!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
entry->mServiceObject = service.forget();
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
lock.Unlock();
|
|
|
|
nsISupports** sresult = reinterpret_cast<nsISupports**>(aResult);
|
|
|
|
*sresult = entry->mServiceObject;
|
|
|
|
(*sresult)->AddRef();
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_OK;
|
2000-04-18 05:25:05 +00:00
|
|
|
}
|
|
|
|
|
2006-04-10 17:09:48 +00:00
|
|
|
NS_IMETHODIMP
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::IsServiceInstantiated(const nsCID& aClass,
|
2010-06-10 18:11:11 +00:00
|
|
|
const nsIID& aIID,
|
2014-08-02 20:44:06 +00:00
|
|
|
bool* aResult)
|
1999-08-09 05:02:25 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +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!
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
2014-08-02 20:44:06 +00:00
|
|
|
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());
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
|
|
|
nsFactoryEntry* entry;
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
{
|
|
|
|
SafeMutexAutoLock lock(mLock);
|
|
|
|
entry = mFactories.Get(aClass);
|
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (entry && entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
|
|
|
|
*aResult = (service != nullptr);
|
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return rv;
|
2001-10-23 02:28:12 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::IsServiceInstantiatedByContractID(
|
|
|
|
const char* aContractID,
|
|
|
|
const nsIID& aIID,
|
|
|
|
bool* aResult)
|
|
|
|
{
|
|
|
|
// 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
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
2014-08-02 20:44:06 +00:00
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Checking for service on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
|
|
|
nsFactoryEntry* entry;
|
|
|
|
{
|
|
|
|
SafeMutexAutoLock lock(mLock);
|
|
|
|
entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
}
|
2001-10-23 02:28:12 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (entry && entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
|
|
|
|
*aResult = (service != nullptr);
|
|
|
|
}
|
|
|
|
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,
|
2014-08-02 20:44:06 +00:00
|
|
|
void** aResult)
|
2001-10-23 02:28:12 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +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
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
2014-08-02 20:44:06 +00:00
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Getting service on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2005-12-02 16:34:42 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
if (!entry) {
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
2008-02-21 16:23:06 +00:00
|
|
|
|
2014-08-02 20:44:06 +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.
|
|
|
|
// `entry` is valid until XPCOM shutdown, so we can safely use it after
|
|
|
|
// exiting the lock.
|
|
|
|
lock.Unlock();
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, aResult);
|
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PRThread* currentPRThread = PR_GetCurrentThread();
|
|
|
|
MOZ_ASSERT(currentPRThread, "This should never be null!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// Needed to optimize the event loop below.
|
|
|
|
nsIThread* currentThread = nullptr;
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
PRThread* pendingPRThread;
|
|
|
|
while ((pendingPRThread = GetPendingServiceThread(*entry->mCIDEntry->cid))) {
|
|
|
|
if (pendingPRThread == currentPRThread) {
|
|
|
|
NS_ERROR("Recursive GetService!");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
SafeMutexAutoUnlock unlockPending(mLock);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!currentThread) {
|
|
|
|
currentThread = NS_GetCurrentThread();
|
|
|
|
MOZ_ASSERT(currentThread, "This should never be null!");
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// This will process a single event or yield the thread if no event is
|
|
|
|
// pending.
|
|
|
|
if (!NS_ProcessNextEvent(currentThread, false)) {
|
|
|
|
PR_Sleep(PR_INTERVAL_NO_WAIT);
|
2005-12-13 17:55:43 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +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.
|
|
|
|
lock.Unlock();
|
|
|
|
return entry->mServiceObject->QueryInterface(aIID, aResult);
|
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
#ifdef DEBUG
|
2014-08-02 20:44:06 +00:00
|
|
|
PendingServiceInfo* newInfo =
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
|
|
|
AddPendingService(*entry->mCIDEntry->cid, currentPRThread);
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ASSERTION(newInfo, "Failed to add info to the array!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// We need to not be holding the service manager's lock while calling
|
|
|
|
// CreateInstance, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager:
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsresult rv;
|
|
|
|
{
|
|
|
|
SafeMutexAutoUnlock unlock(mLock);
|
|
|
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
pendingPRThread = GetPendingServiceThread(*entry->mCIDEntry->cid);
|
|
|
|
MOZ_ASSERT(pendingPRThread == currentPRThread,
|
|
|
|
"Pending service array has been changed!");
|
2010-06-10 18:11:11 +00:00
|
|
|
#endif
|
2014-08-02 20:44:06 +00:00
|
|
|
RemovePendingService(*entry->mCIDEntry->cid);
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ASSERTION(!entry->mServiceObject, "Created two instances of a service!");
|
2005-12-13 17:55:43 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
entry->mServiceObject = service.forget();
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
lock.Unlock();
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsISupports** sresult = reinterpret_cast<nsISupports**>(aResult);
|
|
|
|
*sresult = entry->mServiceObject;
|
|
|
|
(*sresult)->AddRef();
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMPtr<mozilla::ModuleLoader> loader = mLoaderMap.Get(aExt);
|
|
|
|
if (!loader) {
|
|
|
|
loader = do_GetServiceFromCategory("module-loader",
|
|
|
|
PromiseFlatCString(aExt).get());
|
2010-06-10 18:11:11 +00:00
|
|
|
if (!loader) {
|
2014-08-02 20:44:06 +00:00
|
|
|
return nullptr;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mLoaderMap.Put(aExt, loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-08-02 20:44:06 +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;
|
2010-06-23 19:18:13 +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);
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!oldf) {
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mContractIDs.Put(nsDependentCString(aContractID), oldf);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-06-23 19:18:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsAutoPtr<nsFactoryEntry> f(new nsFactoryEntry(aClass, aFactory));
|
2010-06-23 20:18:08 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
SafeMutexAutoLock lock(mLock);
|
|
|
|
nsFactoryEntry* oldf = mFactories.Get(aClass);
|
|
|
|
if (oldf) {
|
|
|
|
return NS_ERROR_FACTORY_EXISTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aContractID) {
|
|
|
|
mContractIDs.Put(nsDependentCString(aContractID), f);
|
|
|
|
}
|
|
|
|
|
|
|
|
mFactories.Put(aClass, f.forget());
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2014-08-02 20:44:06 +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
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
{
|
|
|
|
SafeMutexAutoLock lock(mLock);
|
|
|
|
nsFactoryEntry* f = mFactories.Get(aClass);
|
|
|
|
if (!f || f->mFactory != aFactory) {
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
2010-06-21 16:46:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
mFactories.Remove(aClass);
|
2010-06-21 16:46:26 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// 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
|
|
|
|
2014-08-02 20:44:06 +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)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, aLocation);
|
|
|
|
return NS_OK;
|
2010-06-24 18:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::AutoUnregister(nsIFile* aLocation)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ERROR("AutoUnregister not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2010-06-24 18:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::RegisterFactoryLocation(const nsCID& aCID,
|
|
|
|
const char* aClassName,
|
|
|
|
const char* aContractID,
|
|
|
|
nsIFile* aFile,
|
|
|
|
const char* aLoaderStr,
|
|
|
|
const char* aType)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ERROR("RegisterFactoryLocation not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2010-06-24 18:31:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::UnregisterFactoryLocation(const nsCID& aCID,
|
|
|
|
nsIFile* aFile)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ERROR("UnregisterFactoryLocation not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2010-06-24 18:31:18 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::IsCIDRegistered(const nsCID& aClass,
|
|
|
|
bool* aResult)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
*aResult = (nullptr != GetFactoryEntry(aClass));
|
|
|
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::IsContractIDRegistered(const char* aClass,
|
|
|
|
bool* aResult)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (NS_WARN_IF(!aClass)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2013-11-19 21:27:37 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* entry = GetFactoryEntry(aClass, strlen(aClass));
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (entry) {
|
|
|
|
*aResult = true;
|
|
|
|
} else {
|
|
|
|
*aResult = false;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-08-09 05:02:25 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static PLDHashOperator
|
2014-08-02 20:44:06 +00:00
|
|
|
EnumerateCIDHelper(const nsID& aId, nsFactoryEntry* aEntry, void* aClosure)
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMArray<nsISupports>* array =
|
|
|
|
static_cast<nsCOMArray<nsISupports>*>(aClosure);
|
|
|
|
nsCOMPtr<nsISupportsID> wrapper = new nsSupportsIDImpl();
|
|
|
|
wrapper->SetData(&aId);
|
|
|
|
array->AppendObject(wrapper);
|
|
|
|
return PL_DHASH_NEXT;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::EnumerateCIDs(nsISimpleEnumerator** aEnumerator)
|
1999-08-09 05:02:25 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMArray<nsISupports> array;
|
|
|
|
mFactories.EnumerateRead(EnumerateCIDHelper, &array);
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_NewArrayEnumerator(aEnumerator, array);
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
static PLDHashOperator
|
2014-08-02 20:44:06 +00:00
|
|
|
EnumerateContractsHelper(const nsACString& aContract, nsFactoryEntry* aEntry,
|
|
|
|
void* aClosure)
|
2010-06-10 18:11:11 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsTArray<nsCString>* array = static_cast<nsTArray<nsCString>*>(aClosure);
|
|
|
|
array->AppendElement(aContract);
|
|
|
|
return PL_DHASH_NEXT;
|
1999-08-09 05:02:25 +00:00
|
|
|
}
|
|
|
|
|
2003-06-18 23:03:08 +00:00
|
|
|
NS_IMETHODIMP
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::EnumerateContractIDs(nsISimpleEnumerator** aEnumerator)
|
1999-08-09 05:02:25 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsTArray<nsCString>* array = new nsTArray<nsCString>;
|
|
|
|
mContractIDs.EnumerateRead(EnumerateContractsHelper, array);
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsCOMPtr<nsIUTF8StringEnumerator> e;
|
|
|
|
nsresult rv = NS_NewAdoptingUTF8StringEnumerator(getter_AddRefs(e), array);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
1999-08-09 05:02:25 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::CIDToContractID(const nsCID& aClass,
|
|
|
|
char** aResult)
|
2000-01-11 22:54:46 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +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
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::ContractIDToCID(const char* aContractID,
|
|
|
|
nsCID** aResult)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SafeMutexAutoLock lock(mLock);
|
|
|
|
nsFactoryEntry* entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
if (entry) {
|
|
|
|
*aResult = (nsCID*)NS_Alloc(sizeof(nsCID));
|
|
|
|
**aResult = *entry->mCIDEntry->cid;
|
|
|
|
return NS_OK;
|
2002-04-08 00:18:14 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
|
|
|
*aResult = nullptr;
|
|
|
|
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,
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* const& aData,
|
2013-06-23 12:03:39 +00:00
|
|
|
MallocSizeOf aMallocSizeOf,
|
2012-10-19 12:07:36 +00:00
|
|
|
void* aUserArg)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
return aData->SizeOfIncludingThis(aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
SizeOfContractIDsEntryExcludingThis(nsCStringHashKey::KeyType aKey,
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry* const& aData,
|
2013-06-23 12:03:39 +00:00
|
|
|
MallocSizeOf aMallocSizeOf,
|
2012-10-19 12:07:36 +00:00
|
|
|
void* aUserArg)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
// We don't measure the nsFactoryEntry data because its owned by mFactories
|
|
|
|
// (which measures them in SizeOfFactoriesEntryExcludingThis).
|
|
|
|
return aKey.SizeOfExcludingThisMustBeUnshared(aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
2013-12-08 06:09:10 +00:00
|
|
|
MOZ_DEFINE_MALLOC_SIZE_OF(ComponentManagerMallocSizeOf)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::CollectReports(nsIHandleReportCallback* aHandleReport,
|
2014-05-21 06:06:54 +00:00
|
|
|
nsISupports* aData, bool aAnonymize)
|
2013-11-07 05:35:30 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
return MOZ_COLLECT_REPORT("explicit/xpcom/component-manager",
|
|
|
|
KIND_HEAP, UNITS_BYTES,
|
|
|
|
SizeOfIncludingThis(ComponentManagerMallocSizeOf),
|
|
|
|
"Memory used for the XPCOM component manager.");
|
2013-11-07 05:35:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-19 12:07:36 +00:00
|
|
|
size_t
|
2013-11-07 05:35:30 +00:00
|
|
|
nsComponentManagerImpl::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
2012-10-19 12:07:36 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mLoaderMap.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
|
|
|
n += mFactories.SizeOfExcludingThis(SizeOfFactoriesEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
|
|
|
n += mContractIDs.SizeOfExcludingThis(SizeOfContractIDsEntryExcludingThis,
|
|
|
|
aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
n += sStaticModules->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
n += sModuleLocations->SizeOfIncludingThis(aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
n += mKnownStaticModules.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mKnownModules.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
n += PL_SizeOfArenaPoolExcludingPool(&mArena, aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
n += mPendingServices.SizeOfExcludingThis(aMallocSizeOf);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// 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?
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return n;
|
2012-10-19 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
2005-12-13 17:55:43 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFactoryEntry
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2001-08-30 14:10:41 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const mozilla::Module::CIDEntry* aEntry,
|
|
|
|
nsComponentManagerImpl::KnownModule* aModule)
|
|
|
|
: mCIDEntry(aEntry)
|
|
|
|
, mModule(aModule)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID& aCID, nsIFactory* aFactory)
|
|
|
|
: mCIDEntry(nullptr)
|
|
|
|
, mModule(nullptr)
|
|
|
|
, mFactory(aFactory)
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +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()
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
// If this was a RegisterFactory entry, we own the CIDEntry/CID
|
|
|
|
if (!mModule) {
|
|
|
|
delete mCIDEntry->cid;
|
|
|
|
delete mCIDEntry;
|
|
|
|
}
|
2010-06-25 14:44:35 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:11 +00:00
|
|
|
already_AddRefed<nsIFactory>
|
|
|
|
nsFactoryEntry::GetFactory()
|
2002-06-14 21:33:05 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::gComponentManager->mLock.AssertNotCurrentThreadOwns();
|
|
|
|
|
|
|
|
if (!mFactory) {
|
|
|
|
// RegisterFactory then UnregisterFactory can leave an entry in mContractIDs
|
|
|
|
// pointing to an unusable nsFactoryEntry.
|
|
|
|
if (!mModule) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mModule->Load()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't set mFactory directly, it needs to be locked
|
|
|
|
nsCOMPtr<nsIFactory> factory;
|
2013-03-13 20:39:28 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (mModule->Module()->getFactoryProc) {
|
|
|
|
factory = mModule->Module()->getFactoryProc(*mModule->Module(),
|
|
|
|
*mCIDEntry);
|
|
|
|
} else if (mCIDEntry->getFactoryProc) {
|
|
|
|
factory = mCIDEntry->getFactoryProc(*mModule->Module(), *mCIDEntry);
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(mCIDEntry->constructorProc, "no getfactory or constructor");
|
|
|
|
factory = new mozilla::GenericFactory(mCIDEntry->constructorProc);
|
|
|
|
}
|
|
|
|
if (!factory) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
SafeMutexAutoLock lock(nsComponentManagerImpl::gComponentManager->mLock);
|
|
|
|
// Threads can race to set mFactory
|
2005-12-13 17:55:43 +00:00
|
|
|
if (!mFactory) {
|
2014-08-02 20:44:06 +00:00
|
|
|
factory.swap(mFactory);
|
2003-03-05 03:22:12 +00:00
|
|
|
}
|
2014-08-02 20:44:06 +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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
size_t n = aMallocSizeOf(this);
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mCIDEntry;
|
|
|
|
// - mModule;
|
|
|
|
// - mFactory;
|
|
|
|
// - mServiceObject;
|
2012-10-19 12:07:36 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return n;
|
2012-10-19 12:07:36 +00:00
|
|
|
}
|
|
|
|
|
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
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_GetComponentManager(nsIComponentManager** aResult)
|
2001-10-16 03:35:52 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2001-10-16 03:35:52 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ADDREF(*aResult = nsComponentManagerImpl::gComponentManager);
|
|
|
|
return NS_OK;
|
2001-10-16 03:35:52 +00:00
|
|
|
}
|
|
|
|
|
2011-08-18 13:46:39 +00:00
|
|
|
nsresult
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_GetServiceManager(nsIServiceManager** aResult)
|
2001-09-06 21:13:11 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ADDREF(*aResult = nsComponentManagerImpl::gComponentManager);
|
|
|
|
return NS_OK;
|
2001-09-06 21:13:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-18 13:46:39 +00:00
|
|
|
nsresult
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_GetComponentRegistrar(nsIComponentRegistrar** aResult)
|
2002-01-29 21:22:13 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2002-01-29 21:22:13 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
NS_ADDREF(*aResult = nsComponentManagerImpl::gComponentManager);
|
|
|
|
return NS_OK;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::InitializeStaticModules();
|
|
|
|
nsComponentManagerImpl::sStaticModules->AppendElement(aComponent);
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (nsComponentManagerImpl::gComponentManager &&
|
|
|
|
nsComponentManagerImpl::NORMAL ==
|
|
|
|
nsComponentManagerImpl::gComponentManager->mStatus) {
|
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterModule(aComponent,
|
|
|
|
nullptr);
|
|
|
|
}
|
2010-06-10 18:11:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_OK;
|
2010-06-10 18:11:11 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2014-08-02 20:44:06 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-07-29 09:20:47 +00:00
|
|
|
return rv;
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2011-07-29 09:20:47 +00:00
|
|
|
|
2014-05-22 03:48:51 +00:00
|
|
|
if (Substring(path, path.Length() - 4).EqualsLiteral(".xpi")) {
|
2011-07-29 09:20:47 +00:00
|
|
|
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();
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!cr) {
|
2011-07-29 09:20:47 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2011-07-29 09:20:47 +00:00
|
|
|
|
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);
|
2014-08-02 20:44:06 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-07-29 09:20:47 +00:00
|
|
|
return rv;
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2011-07-29 09:20:47 +00:00
|
|
|
|
2011-11-08 17:10:51 +00:00
|
|
|
nsComponentManagerImpl::ComponentLocation elem;
|
|
|
|
elem.type = NS_BOOTSTRAPPED_LOCATION;
|
|
|
|
|
2014-05-22 03:48:51 +00:00
|
|
|
if (Substring(path, path.Length() - 4).EqualsLiteral(".xpi")) {
|
2011-11-08 17:10:51 +00:00
|
|
|
elem.location.Init(aLocation, "chrome.manifest");
|
2011-07-29 09:20:47 +00:00
|
|
|
} else {
|
2014-08-02 20:44:06 +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.
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::sModuleLocations->RemoveElement(elem,
|
|
|
|
ComponentLocationComparator());
|
2011-07-29 09:20:47 +00:00
|
|
|
|
|
|
|
rv = cr->CheckForNewChrome();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2013-07-05 19:20:04 +00:00
|
|
|
NS_IMETHODIMP
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::GetManifestLocations(nsIArray** aLocations)
|
2013-07-05 19:20:04 +00:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLocations);
|
|
|
|
*aLocations = nullptr;
|
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
if (!sModuleLocations) {
|
2013-07-05 19:20:04 +00:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2013-07-05 19:20:04 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIMutableArray> locations = nsArray::Create();
|
|
|
|
nsresult rv;
|
|
|
|
for (uint32_t i = 0; i < sModuleLocations->Length(); ++i) {
|
|
|
|
ComponentLocation& l = sModuleLocations->ElementAt(i);
|
|
|
|
FileLocation loc = l.location;
|
|
|
|
nsCString uriString;
|
|
|
|
loc.GetURIString(uriString);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
rv = NS_NewURI(getter_AddRefs(uri), uriString);
|
2014-08-02 20:44:06 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2013-07-05 19:20:04 +00:00
|
|
|
locations->AppendElement(uri, false);
|
2014-08-02 20:44:06 +00:00
|
|
|
}
|
2013-07-05 19:20:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
locations.forget(aLocations);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-07-26 00:52:00 +00:00
|
|
|
#ifdef MOZ_B2G_LOADER
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::XPTOnlyManifestManifest(
|
|
|
|
XPTOnlyManifestProcessingContext& aCx, int aLineNo, char* const* aArgv)
|
2014-07-26 00:52:00 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
char* file = aArgv[0];
|
|
|
|
FileLocation f(aCx.mFile, file);
|
2014-07-26 00:52:00 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
DoRegisterManifest(NS_COMPONENT_LOCATION, f, false, true);
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::XPTOnlyManifestXPT(
|
|
|
|
XPTOnlyManifestProcessingContext& aCx, int aLineNo, char* const* aArgv)
|
2014-07-26 00:52:00 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
FileLocation f(aCx.mFile, aArgv[0]);
|
|
|
|
DoRegisterXPT(f);
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* To load XPT Interface Information before the component manager is ready.
|
|
|
|
*
|
|
|
|
* With this function, B2G loader could XPT interface info. as earier
|
|
|
|
* as possible to gain benefit of shared memory model of the kernel.
|
|
|
|
*/
|
|
|
|
/* static */ void
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::PreloadXPT(nsIFile* aFile)
|
2014-07-26 00:52:00 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
MOZ_ASSERT(!nsComponentManagerImpl::gComponentManager);
|
|
|
|
FileLocation location(aFile, "chrome.manifest");
|
2014-07-26 00:52:00 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
DoRegisterManifest(NS_COMPONENT_LOCATION, location,
|
|
|
|
false, true /* aXPTOnly */);
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-08-02 20:44:06 +00:00
|
|
|
PreloadXPT(nsIFile* aOmnijarFile)
|
2014-07-26 00:52:00 +00:00
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::PreloadXPT(aOmnijarFile);
|
2014-07-26 00:52:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MOZ_B2G_LOADER */
|
|
|
|
|
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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::InitializeModuleLocations();
|
|
|
|
nsComponentManagerImpl::ComponentLocation* c =
|
|
|
|
nsComponentManagerImpl::sModuleLocations->AppendElement();
|
|
|
|
c->type = aType;
|
|
|
|
c->location.Init(aLocation);
|
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager &&
|
|
|
|
nsComponentManagerImpl::NORMAL ==
|
|
|
|
nsComponentManagerImpl::gComponentManager->mStatus) {
|
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterManifest(aType,
|
|
|
|
c->location,
|
|
|
|
false);
|
|
|
|
}
|
2002-10-05 23:59:57 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_OK;
|
2002-01-29 21:22:13 +00:00
|
|
|
}
|
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
|
|
|
{
|
2014-08-02 20:44:06 +00:00
|
|
|
nsComponentManagerImpl::InitializeModuleLocations();
|
|
|
|
nsComponentManagerImpl::ComponentLocation* c =
|
|
|
|
nsComponentManagerImpl::sModuleLocations->AppendElement();
|
2010-09-09 03:37:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
c->type = aType;
|
|
|
|
c->location.Init(aLocation, "chrome.manifest");
|
2010-09-09 03:37:11 +00:00
|
|
|
|
2014-08-02 20:44:06 +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
|
|
|
|
2014-08-02 20:44:06 +00:00
|
|
|
return NS_OK;
|
2010-09-09 03:37:11 +00:00
|
|
|
}
|
|
|
|
|