2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nspr.h"
|
|
|
|
#include "nsCRT.h" // for atoll
|
|
|
|
// 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
|
|
|
|
#define NS_CM_BLOCK_SIZE (1024 * 8)
|
|
|
|
|
|
|
|
#include "nsAutoLock.h"
|
2010-06-10 11:11:11 -07:00
|
|
|
#include "nsCategoryManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsComponentManager.h"
|
|
|
|
#include "nsDirectoryService.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsCategoryManager.h"
|
|
|
|
#include "nsCategoryManagerUtils.h"
|
|
|
|
#include "nsIEnumerator.h"
|
|
|
|
#include "xptiprivate.h"
|
|
|
|
#include "nsIConsoleService.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsIStringEnumerator.h"
|
|
|
|
#include "nsXPCOM.h"
|
|
|
|
#include "nsXPCOMPrivate.h"
|
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIClassInfo.h"
|
|
|
|
#include "nsLocalFile.h"
|
|
|
|
#include "nsReadableUtils.h"
|
2010-06-10 11:11:11 -07:00
|
|
|
#include "nsStaticComponents.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "prcmon.h"
|
|
|
|
#include "xptinfo.h" // this after nsISupports, to pick up IID so that xpt stuff doesn't try to define it itself...
|
2008-09-04 15:44:41 -07:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "prthread.h"
|
2009-01-08 00:41:55 -08:00
|
|
|
#include "private/pprthred.h"
|
2009-04-03 09:43:08 -07:00
|
|
|
#include "nsTArray.h"
|
2009-11-05 06:08:49 -08:00
|
|
|
#include "prio.h"
|
2010-05-19 16:22:19 -07:00
|
|
|
#include "mozilla/FunctionTimer.h"
|
2010-06-11 13:13:26 -07:00
|
|
|
#include "ManifestParser.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsInt64.h"
|
|
|
|
#include "nsManifestLineReader.h"
|
2010-06-10 11:11:11 -07:00
|
|
|
#include "mozilla/GenericFactory.h"
|
|
|
|
#include "nsSupportsPrimitives.h"
|
|
|
|
#include "nsArrayEnumerator.h"
|
|
|
|
#include "nsStringEnumerator.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include NEW_H // for placement new
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef XP_BEOS
|
|
|
|
#include <FindDirectory.h>
|
|
|
|
#include <Path.h>
|
|
|
|
#endif
|
|
|
|
|
2010-06-15 12:38:46 -07:00
|
|
|
#ifdef MOZ_OMNIJAR
|
|
|
|
#include "nsIZipReader.h"
|
|
|
|
#include "mozilla/Omnijar.h"
|
|
|
|
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "prlog.h"
|
|
|
|
|
|
|
|
NS_COM PRLogModuleInfo* nsComponentManagerLog = nsnull;
|
|
|
|
|
|
|
|
#if 0 || defined (DEBUG_timeless)
|
|
|
|
#define SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
#define SHOW_CI_ON_EXISTING_SERVICE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
|
|
// Common Key Names
|
|
|
|
const char classIDKeyName[]="classID";
|
|
|
|
const char classesKeyName[]="contractID";
|
|
|
|
const char componentsKeyName[]="components";
|
|
|
|
const char xpcomComponentsKeyName[]="software/mozilla/XPCOM/components";
|
|
|
|
const char xpcomKeyName[]="software/mozilla/XPCOM";
|
|
|
|
|
|
|
|
// Common Value Names
|
|
|
|
const char classIDValueName[]="ClassID";
|
|
|
|
const char classNameValueName[]="ClassName";
|
|
|
|
const char componentCountValueName[]="ComponentsCount";
|
|
|
|
const char componentTypeValueName[]="ComponentType";
|
|
|
|
const char contractIDValueName[]="ContractID";
|
|
|
|
const char fileSizeValueName[]="FileSize";
|
|
|
|
const char inprocServerValueName[]="InprocServer";
|
|
|
|
const char lastModValueName[]="LastModTimeStamp";
|
|
|
|
const char nativeComponentType[]="application/x-mozilla-native";
|
|
|
|
const char staticComponentType[]="application/x-mozilla-static";
|
2010-06-15 12:38:46 -07:00
|
|
|
const char jarComponentType[]="application/x-mozilla-jarjs";
|
2007-03-22 10:30:00 -07:00
|
|
|
const char versionValueName[]="VersionString";
|
|
|
|
|
|
|
|
const static char XPCOM_ABSCOMPONENT_PREFIX[] = "abs:";
|
|
|
|
const static char XPCOM_RELCOMPONENT_PREFIX[] = "rel:";
|
|
|
|
const static char XPCOM_GRECOMPONENT_PREFIX[] = "gre:";
|
|
|
|
|
|
|
|
static const char gIDFormat[] =
|
|
|
|
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
|
|
|
|
|
|
|
|
|
|
|
|
#define NS_EMPTY_IID \
|
|
|
|
{ \
|
|
|
|
0x00000000, \
|
|
|
|
0x0000, \
|
|
|
|
0x0000, \
|
|
|
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_DEFINE_CID(kEmptyCID, NS_EMPTY_IID);
|
|
|
|
NS_DEFINE_CID(kCategoryManagerCID, NS_CATEGORYMANAGER_CID);
|
|
|
|
|
|
|
|
#define UID_STRING_LENGTH 39
|
|
|
|
|
2010-05-19 16:22:19 -07:00
|
|
|
#ifdef NS_FUNCTION_TIMER
|
|
|
|
#define COMPMGR_TIME_FUNCTION_CID(cid) \
|
|
|
|
char cid_buf__[NSID_LENGTH] = { '\0' }; \
|
|
|
|
cid.ToProvidedString(cid_buf__); \
|
|
|
|
NS_TIME_FUNCTION_MIN_FMT(5, "%s (line %d) (cid: %s)", MOZ_FUNCTION_NAME, \
|
|
|
|
__LINE__, cid_buf__)
|
|
|
|
#define COMPMGR_TIME_FUNCTION_CONTRACTID(cid) \
|
|
|
|
NS_TIME_FUNCTION_MIN_FMT(5, "%s (line %d) (contractid: %s)", MOZ_FUNCTION_NAME, \
|
|
|
|
__LINE__, (cid))
|
|
|
|
#else
|
|
|
|
#define COMPMGR_TIME_FUNCTION_CID(cid) do {} while (0)
|
|
|
|
#define COMPMGR_TIME_FUNCTION_CONTRACTID(cid) do {} while (0)
|
|
|
|
#endif
|
|
|
|
|
2010-06-15 12:38:46 -07:00
|
|
|
#define kOMNIJAR_PREFIX NS_LITERAL_CSTRING("resource:///")
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mCategory || !mEntry) {
|
|
|
|
// when categories have defaults, use that for null mEntry
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = compMgr->nsComponentManagerImpl::GetService(kCategoryManagerCID,
|
|
|
|
NS_GET_IID(nsICategoryManager),
|
|
|
|
getter_AddRefs(catman));
|
|
|
|
if (NS_FAILED(rv)) goto error;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Arena helper functions
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
char *
|
|
|
|
ArenaStrndup(const char *s, PRUint32 len, PLArenaPool *arena)
|
|
|
|
{
|
|
|
|
void *mem;
|
|
|
|
// Include trailing null in the len
|
|
|
|
PL_ARENA_ALLOCATE(mem, arena, len+1);
|
|
|
|
if (mem)
|
|
|
|
memcpy(mem, s, len+1);
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<char *>(mem);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
ArenaStrdup(const char *s, PLArenaPool *arena)
|
|
|
|
{
|
|
|
|
return ArenaStrndup(s, strlen(s), arena);
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// this is safe to call during InitXPCOM
|
|
|
|
static already_AddRefed<nsILocalFile>
|
2010-06-21 10:49:38 -07:00
|
|
|
GetLocationFromDirectoryService(const char* prop)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsIProperties> directoryService;
|
|
|
|
nsDirectoryService::Create(nsnull,
|
|
|
|
NS_GET_IID(nsIProperties),
|
|
|
|
getter_AddRefs(directoryService));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!directoryService)
|
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsILocalFile> file;
|
|
|
|
nsresult rv = directoryService->Get(prop,
|
|
|
|
NS_GET_IID(nsILocalFile),
|
|
|
|
getter_AddRefs(file));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return file.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-21 10:49:38 -07:00
|
|
|
static already_AddRefed<nsILocalFile>
|
|
|
|
CloneAndAppend(nsILocalFile* aBase, const nsACString& append)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> f;
|
|
|
|
aBase->Clone(getter_AddRefs(f));
|
|
|
|
if (!f)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> lf = do_QueryInterface(f);
|
|
|
|
f->AppendNative(append);
|
|
|
|
return lf.forget();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-06-10 11:11:11 -07:00
|
|
|
// nsComponentManagerImpl
|
2007-03-22 10:30:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2008-02-21 12:39:20 -08:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::Create(nsISupports* aOuter, REFNSIID aIID, void** aResult)
|
2008-02-21 12:39:20 -08:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!gComponentManager)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return gComponentManager->QueryInterface(aIID, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsComponentManagerImpl::nsComponentManagerImpl()
|
|
|
|
: mMon(NULL)
|
|
|
|
, mStatus(NOT_INITIALIZED)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-23 10:36:53 -07:00
|
|
|
#define CONTRACTID_HASHTABLE_INITIAL_SIZE 2048
|
2010-06-10 11:11:11 -07:00
|
|
|
|
|
|
|
nsTArray<const mozilla::Module*>* nsComponentManagerImpl::sStaticModules;
|
2008-02-21 12:39:20 -08:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
/* static */ void
|
|
|
|
nsComponentManagerImpl::InitializeStaticModules()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
if (sStaticModules)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
sStaticModules = new nsTArray<const mozilla::Module*>;
|
|
|
|
for (const mozilla::Module *const *staticModules = kPStaticModules;
|
|
|
|
*staticModules; ++staticModules)
|
|
|
|
sStaticModules->AppendElement(*staticModules);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
nsTArray<nsComponentManagerImpl::ComponentLocation>*
|
|
|
|
nsComponentManagerImpl::sModuleLocations;
|
2010-06-10 11:11:11 -07:00
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
nsComponentManagerImpl::InitializeModuleLocations()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
if (sModuleLocations)
|
|
|
|
return;
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
sModuleLocations = new nsTArray<ComponentLocation>;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult nsComponentManagerImpl::Init()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_TIME_FUNCTION;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_ASSERT(NOT_INITIALIZED == mStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (nsComponentManagerLog == nsnull)
|
|
|
|
{
|
|
|
|
nsComponentManagerLog = PR_NewLogModule("nsComponentManager");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// Initialize our arena
|
|
|
|
NS_TIME_FUNCTION_MARK("Next: init component manager arena");
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "ComponentManagerArena", NS_CM_BLOCK_SIZE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mFactories.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE);
|
|
|
|
mContractIDs.Init(CONTRACTID_HASHTABLE_INITIAL_SIZE);
|
2010-06-11 13:13:26 -07:00
|
|
|
mLoaderMap.Init();
|
|
|
|
mKnownFileModules.Init();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mMon = nsAutoMonitor::NewMonitor("nsComponentManagerImpl");
|
|
|
|
if (mMon == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-21 10:49:38 -07:00
|
|
|
nsCOMPtr<nsILocalFile> greDir =
|
|
|
|
GetLocationFromDirectoryService(NS_GRE_DIR);
|
|
|
|
nsCOMPtr<nsILocalFile> appDir =
|
|
|
|
GetLocationFromDirectoryService(NS_XPCOM_CURRENT_PROCESS_DIR);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
InitializeStaticModules();
|
|
|
|
InitializeModuleLocations();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-21 10:49:38 -07:00
|
|
|
NS_NAMED_LITERAL_CSTRING(strComponents, "components");
|
|
|
|
NS_NAMED_LITERAL_CSTRING(strChrome, "chrome");
|
|
|
|
|
|
|
|
ComponentLocation appLocations[2] = {
|
|
|
|
{ NS_COMPONENT_LOCATION, CloneAndAppend(appDir, strComponents) },
|
|
|
|
{ NS_COMPONENT_LOCATION, CloneAndAppend(appDir, strChrome) },
|
|
|
|
};
|
|
|
|
sModuleLocations->
|
|
|
|
InsertElementsAt(0, appLocations, NS_ARRAY_LENGTH(appLocations));
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PRBool equals = PR_FALSE;
|
2010-06-21 10:49:38 -07:00
|
|
|
appDir->Equals(greDir, &equals);
|
2010-06-11 13:13:26 -07:00
|
|
|
if (!equals) {
|
2010-06-21 10:49:38 -07:00
|
|
|
ComponentLocation greLocations[2] = {
|
|
|
|
{ NS_COMPONENT_LOCATION, CloneAndAppend(greDir, strComponents) },
|
|
|
|
{ NS_COMPONENT_LOCATION, CloneAndAppend(greDir, strChrome) },
|
|
|
|
};
|
|
|
|
sModuleLocations->
|
|
|
|
InsertElementsAt(0, greLocations, NS_ARRAY_LENGTH(greLocations));
|
2010-06-11 13:13:26 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
|
|
|
("nsComponentManager: Initialized."));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_TIME_FUNCTION_MARK("Next: init native module loader");
|
|
|
|
nsresult rv = mNativeModuleLoader.Init();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCategoryManager::GetSingleton()->SuppressNotifications(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
RegisterModule(&kXPCOMModule, NULL);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
for (PRUint32 i = 0; i < sStaticModules->Length(); ++i)
|
|
|
|
RegisterModule((*sStaticModules)[i], NULL);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
|
|
|
|
ComponentLocation& l = sModuleLocations->ElementAt(i);
|
2010-06-22 13:24:01 -07:00
|
|
|
RegisterLocation(l.type, l.location, false);
|
2010-06-11 13:13:26 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCategoryManager::GetSingleton()->SuppressNotifications(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mStatus = NORMAL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule,
|
|
|
|
nsILocalFile* aFile)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
nsAutoMonitor mon(mMon);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
KnownModule* m = new KnownModule(aModule, aFile);
|
2010-06-11 13:13:26 -07:00
|
|
|
if (aFile) {
|
|
|
|
nsCOMPtr<nsIHashable> h = do_QueryInterface(aFile);
|
|
|
|
mKnownFileModules.Put(h, m);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mKnownStaticModules.AppendElement(m);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (aModule->mCIDs) {
|
|
|
|
const mozilla::Module::CIDEntry* entry;
|
|
|
|
for (entry = aModule->mCIDs; entry->cid; ++entry)
|
|
|
|
RegisterCIDEntry(entry, m);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (aModule->mContractIDs) {
|
|
|
|
const mozilla::Module::ContractIDEntry* entry;
|
|
|
|
for (entry = aModule->mContractIDs; entry->contractid; ++entry)
|
|
|
|
RegisterContractID(entry);
|
|
|
|
NS_ASSERTION(!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 09:03:06 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RegisterCIDEntry(const mozilla::Module::CIDEntry* aEntry,
|
|
|
|
KnownModule* aModule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMon);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
|
|
|
|
if (f) {
|
|
|
|
NS_ERROR("Re-registering a CID?");
|
|
|
|
// XXX REPORT ERROR, we don't override CIDs
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
f = new nsFactoryEntry(aEntry, aModule);
|
|
|
|
mFactories.Put(*aEntry->cid, f);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RegisterContractID(const mozilla::Module::ContractIDEntry* aEntry)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_ASSERT_CURRENT_THREAD_IN_MONITOR(mMon);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
|
|
|
|
if (!f) {
|
|
|
|
NS_ERROR("No CID found when attempting to map contract ID");
|
|
|
|
// XXX REPORT ERROR, CID isn't registered
|
|
|
|
return;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mContractIDs.Put(nsDependentCString(aEntry->contractid), f);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
void
|
2010-06-11 13:13:26 -07:00
|
|
|
nsComponentManagerImpl::RegisterLocation(NSLocationType aType,
|
2010-06-22 13:24:01 -07:00
|
|
|
nsILocalFile* aLocation,
|
|
|
|
bool aChromeOnly)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-11 13:13:26 -07:00
|
|
|
nsCOMArray<nsILocalFile> manifests;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PRBool directory = PR_FALSE;
|
|
|
|
aLocation->IsDirectory(&directory);
|
|
|
|
if (directory)
|
2010-06-22 13:24:01 -07:00
|
|
|
RegisterDirectory(aType, aLocation, manifests, aChromeOnly);
|
2010-06-10 11:11:11 -07:00
|
|
|
else
|
2010-06-22 13:24:01 -07:00
|
|
|
RegisterFile(aType, aLocation, manifests, aChromeOnly);
|
2010-06-11 13:13:26 -07:00
|
|
|
|
|
|
|
for (PRInt32 i = 0; i < manifests.Count(); ++i)
|
2010-06-22 13:24:01 -07:00
|
|
|
RegisterManifestFile(aType, manifests[i], aChromeOnly);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
void
|
2010-06-11 13:13:26 -07:00
|
|
|
nsComponentManagerImpl::RegisterDirectory(NSLocationType aType,
|
|
|
|
nsILocalFile* aDirectory,
|
2010-06-22 13:24:01 -07:00
|
|
|
nsCOMArray<nsILocalFile>& aManifests,
|
|
|
|
bool aChromeOnly)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> entries;
|
|
|
|
aDirectory->GetDirectoryEntries(getter_AddRefs(entries));
|
|
|
|
if (!entries)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PRBool more;
|
|
|
|
while (NS_SUCCEEDED(entries->HasMoreElements(&more)) && more) {
|
|
|
|
nsCOMPtr<nsISupports> supp;
|
|
|
|
entries->GetNext(getter_AddRefs(supp));
|
|
|
|
nsCOMPtr<nsILocalFile> f = do_QueryInterface(supp);
|
|
|
|
if (!f)
|
|
|
|
continue;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-22 13:24:01 -07:00
|
|
|
RegisterFile(aType, f, aManifests, aChromeOnly);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
static void
|
|
|
|
GetExtension(nsILocalFile* file, nsCString& extension)
|
2010-06-10 11:11:11 -07:00
|
|
|
{
|
2010-06-11 13:13:26 -07:00
|
|
|
file->GetNativePath(extension);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PRInt32 dotPos = extension.RFindChar('.');
|
|
|
|
if (kNotFound == dotPos)
|
2010-06-11 13:13:26 -07:00
|
|
|
extension.Truncate();
|
|
|
|
else
|
|
|
|
extension.Cut(0, dotPos + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RegisterFile(NSLocationType aType,
|
|
|
|
nsILocalFile* aFile,
|
2010-06-22 13:24:01 -07:00
|
|
|
nsCOMArray<nsILocalFile>& aManifests,
|
|
|
|
bool aChromeOnly)
|
2010-06-11 13:13:26 -07:00
|
|
|
{
|
|
|
|
nsCString extension;
|
|
|
|
GetExtension(aFile, extension);
|
|
|
|
|
2010-06-22 13:24:01 -07:00
|
|
|
if (NS_COMPONENT_LOCATION == aType && !aChromeOnly) {
|
2010-06-11 13:13:26 -07:00
|
|
|
if (extension.EqualsLiteral("xpt")) {
|
|
|
|
xptiInterfaceInfoManager::GetSingleton()
|
|
|
|
->RegisterFile(aFile,
|
|
|
|
xptiInterfaceInfoManager::XPT);
|
|
|
|
}
|
|
|
|
else if (extension.EqualsLiteral("jar")) {
|
|
|
|
xptiInterfaceInfoManager::GetSingleton()
|
|
|
|
->RegisterFile(aFile,
|
|
|
|
xptiInterfaceInfoManager::ZIP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (extension.LowerCaseEqualsLiteral("manifest"))
|
|
|
|
aManifests.AppendObject(aFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct AutoCloseFD
|
|
|
|
{
|
|
|
|
AutoCloseFD()
|
|
|
|
: mFD(NULL)
|
|
|
|
{ }
|
|
|
|
~AutoCloseFD() {
|
|
|
|
if (mFD)
|
|
|
|
PR_Close(mFD);
|
|
|
|
}
|
|
|
|
operator PRFileDesc*() {
|
|
|
|
return mFD;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRFileDesc** operator&() {
|
|
|
|
NS_ASSERTION(!mFD, "Re-opening a file");
|
|
|
|
return &mFD;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRFileDesc* mFD;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RegisterManifestFile(NSLocationType aType,
|
2010-06-22 13:24:01 -07:00
|
|
|
nsILocalFile* aFile,
|
|
|
|
bool aChromeOnly)
|
2010-06-11 13:13:26 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
AutoCloseFD fd;
|
|
|
|
rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &fd);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRFileInfo64 fileInfo;
|
|
|
|
if (PR_SUCCESS != PR_GetOpenFileInfo64(fd, &fileInfo))
|
2010-06-10 11:11:11 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
if (fileInfo.size > PRInt64(PR_INT32_MAX))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsAutoArrayPtr<char> data(new char[PRInt32(fileInfo.size + 1)]);
|
|
|
|
|
|
|
|
for (PRInt32 totalRead = 0; totalRead < fileInfo.size; ) {
|
|
|
|
PRInt32 read = PR_Read(fd, data + totalRead, PRInt32(fileInfo.size));
|
|
|
|
if (read < 0)
|
2010-06-10 11:11:11 -07:00
|
|
|
return;
|
2010-06-11 13:13:26 -07:00
|
|
|
totalRead += read;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
|
|
|
|
data[fileInfo.size] = '\0';
|
2010-06-22 13:24:01 -07:00
|
|
|
ParseManifest(aType, aFile, data, aChromeOnly);
|
2010-06-11 13:13:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* file = argv[0];
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> cfile;
|
|
|
|
cx.mFile->GetParent(getter_AddRefs(cfile));
|
|
|
|
nsCOMPtr<nsILocalFile> clfile = do_QueryInterface(cfile);
|
|
|
|
|
|
|
|
nsresult rv = clfile->AppendRelativeNativePath(nsDependentCString(file));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Couldn't append relative path?");
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
|
|
|
|
const mozilla::Module* m = mNativeModuleLoader.LoadModule(clfile);
|
|
|
|
if (!m) {
|
|
|
|
// XXX report load error
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
RegisterModule(m, clfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* id = argv[0];
|
|
|
|
char* file = argv[1];
|
|
|
|
|
|
|
|
nsID cid;
|
|
|
|
if (!cid.Parse(id)) {
|
|
|
|
// XXX report parse error
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsFactoryEntry* f = mFactories.Get(cid);
|
|
|
|
if (f) {
|
|
|
|
// XXX report double-register error
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> cfile;
|
|
|
|
cx.mFile->GetParent(getter_AddRefs(cfile));
|
|
|
|
nsCOMPtr<nsILocalFile> clfile = do_QueryInterface(cfile);
|
|
|
|
|
|
|
|
nsresult rv = clfile->AppendRelativeNativePath(nsDependentCString(file));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Couldn't append relative path?");
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIHashable> h = do_QueryInterface(clfile);
|
|
|
|
KnownModule* km = mKnownFileModules.Get(h);
|
|
|
|
if (!km) {
|
|
|
|
km = new KnownModule(clfile);
|
|
|
|
mKnownFileModules.Put(h, km);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
|
|
|
|
void* place;
|
|
|
|
|
|
|
|
PL_ARENA_ALLOCATE(place, &mArena, sizeof(nsCID));
|
|
|
|
nsID* permanentCID = static_cast<nsID*>(place);
|
|
|
|
*permanentCID = cid;
|
|
|
|
|
|
|
|
PL_ARENA_ALLOCATE(place, &mArena, sizeof(mozilla::Module::CIDEntry));
|
|
|
|
mozilla::Module::CIDEntry* e = new (place) mozilla::Module::CIDEntry();
|
|
|
|
e->cid = permanentCID;
|
|
|
|
|
|
|
|
f = new nsFactoryEntry(e, km);
|
|
|
|
mFactories.Put(cid, f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestContract(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* contract = argv[0];
|
|
|
|
char* id = argv[1];
|
|
|
|
|
|
|
|
nsID cid;
|
|
|
|
if (!cid.Parse(id)) {
|
|
|
|
// XXX report parse error
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsFactoryEntry* f = mFactories.Get(cid);
|
|
|
|
if (!f) {
|
|
|
|
// XXX report unregistered CID
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mContractIDs.Put(nsDependentCString(contract), f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestCategory(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* category = argv[0];
|
|
|
|
char* key = argv[1];
|
|
|
|
char* value = argv[2];
|
|
|
|
|
|
|
|
nsCategoryManager::GetSingleton()->
|
|
|
|
AddCategoryEntry(category, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RereadChromeManifests()
|
|
|
|
{
|
2010-06-22 13:24:01 -07:00
|
|
|
for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
|
|
|
|
ComponentLocation& l = sModuleLocations->ElementAt(i);
|
|
|
|
RegisterLocation(l.type, l.location, true);
|
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsComponentManagerImpl::KnownModule::EnsureLoader()
|
|
|
|
{
|
|
|
|
if (!mLoader) {
|
|
|
|
nsCString extension;
|
|
|
|
GetExtension(mFile, extension);
|
|
|
|
|
|
|
|
mLoader = nsComponentManagerImpl::gComponentManager->LoaderForExtension(extension);
|
|
|
|
}
|
|
|
|
return !!mLoader;
|
2010-06-10 11:11:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
bool
|
|
|
|
nsComponentManagerImpl::KnownModule::Load()
|
|
|
|
{
|
|
|
|
if (mFailed)
|
|
|
|
return false;
|
|
|
|
if (!mModule) {
|
2010-06-11 13:13:26 -07:00
|
|
|
if (!EnsureLoader())
|
|
|
|
return false;
|
2010-06-10 11:11:11 -07:00
|
|
|
mModule = mLoader->LoadModule(mFile);
|
|
|
|
if (!mModule) {
|
|
|
|
mFailed = true;
|
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!mLoaded) {
|
2010-06-21 09:46:26 -07:00
|
|
|
if (mModule->loadProc) {
|
|
|
|
nsresult rv = mModule->loadProc();
|
2010-06-10 11:11:11 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mFailed = true;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mLoaded = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsComponentManagerImpl::Shutdown(void)
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_ASSERT(NORMAL == mStatus);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mStatus = SHUTDOWN_IN_PROGRESS;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Shutdown the component manager
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning Shutdown."));
|
|
|
|
|
|
|
|
// Release all cached factories
|
2010-06-10 11:11:11 -07:00
|
|
|
mContractIDs.Clear();
|
|
|
|
mFactories.Clear(); // XXX release the objects, don't just clear
|
2010-06-11 13:13:26 -07:00
|
|
|
mLoaderMap.Clear();
|
|
|
|
mKnownFileModules.Clear();
|
2010-06-25 07:02:17 -07:00
|
|
|
mKnownStaticModules.Clear();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mLoaderData.Clear();
|
|
|
|
|
|
|
|
// Unload libraries
|
|
|
|
mNativeModuleLoader.UnloadLibraries();
|
|
|
|
|
|
|
|
// delete arena for strings and small objects
|
|
|
|
PL_FinishArenaPool(&mArena);
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mStatus = SHUTDOWN_COMPLETE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Shutdown complete."));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsComponentManagerImpl::~nsComponentManagerImpl()
|
|
|
|
{
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Beginning destruction."));
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (SHUTDOWN_COMPLETE != mStatus)
|
2007-03-22 10:30:00 -07:00
|
|
|
Shutdown();
|
|
|
|
|
|
|
|
if (mMon) {
|
|
|
|
nsAutoMonitor::DestroyMonitor(mMon);
|
|
|
|
}
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Destroyed."));
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS5(nsComponentManagerImpl,
|
2008-02-21 12:39:20 -08:00
|
|
|
nsIComponentManager,
|
|
|
|
nsIServiceManager,
|
|
|
|
nsIComponentRegistrar,
|
2010-06-10 11:11:11 -07:00
|
|
|
nsISupportsWeakReference,
|
|
|
|
nsIInterfaceRequestor)
|
2008-02-21 12:39:20 -08:00
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
nsComponentManagerImpl::GetInterface(const nsIID & uuid, void **result)
|
|
|
|
{
|
|
|
|
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(uuid, result);
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry *
|
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const char *aContractID,
|
|
|
|
PRUint32 aContractIDLen)
|
|
|
|
{
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
return mContractIDs.Get(nsDependentCString(aContractID, aContractIDLen));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry *
|
|
|
|
nsComponentManagerImpl::GetFactoryEntry(const nsCID &aClass)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
return mFactories.Get(aClass);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
already_AddRefed<nsIFactory>
|
|
|
|
nsComponentManagerImpl::FindFactory(const nsCID& aClass)
|
|
|
|
{
|
|
|
|
nsFactoryEntry* e = GetFactoryEntry(aClass);
|
|
|
|
if (!e)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return e->GetFactory();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
already_AddRefed<nsIFactory>
|
|
|
|
nsComponentManagerImpl::FindFactory(const char *contractID,
|
|
|
|
PRUint32 aContractIDLen)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(contractID, aContractIDLen);
|
|
|
|
if (!entry)
|
|
|
|
return NULL;
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return entry->GetFactory();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
/**
|
|
|
|
* GetClassObject()
|
|
|
|
*
|
|
|
|
* Given a classID, this finds the singleton ClassObject that implements the CID.
|
|
|
|
* Returns an interface of type aIID off the singleton classobject.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::GetClassObject(const nsCID &aClass, const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG))
|
|
|
|
{
|
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", buf);
|
|
|
|
if (buf)
|
|
|
|
NS_Free(buf);
|
|
|
|
}
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_ASSERT(aResult != nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsIFactory> factory = FindFactory(aClass);
|
|
|
|
if (!factory)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
rv = factory->QueryInterface(aIID, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::GetClassObjectByContractID(const char *contractID,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
NS_ENSURE_ARG_POINTER(contractID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_DEBUG))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_LogPrint("nsComponentManager: GetClassObject(%s)", contractID);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsIFactory> factory = FindFactory(contractID, strlen(contractID));
|
|
|
|
if (!factory)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
rv = factory->QueryInterface(aIID, aResult);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("\t\tGetClassObject() %s", NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return rv;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
/**
|
|
|
|
* CreateInstance()
|
|
|
|
*
|
|
|
|
* Create an instance of an object that implements an interface and belongs
|
|
|
|
* to the implementation aClass using the factory. The factory is immediately
|
|
|
|
* released and not held onto for any longer.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::CreateInstance(const nsCID &aClass,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
COMPMGR_TIME_FUNCTION_CID(aClass);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// test this first, since there's no point in creating a component during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Creating new instance on shutdown. Denied.\n"
|
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (aResult == nsnull)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
*aResult = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#ifdef SHOW_CI_ON_EXISTING_SERVICE
|
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsXPIDLCString cid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
nsCAutoString 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());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFactory> factory = entry->GetFactory();
|
|
|
|
if (factory)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07: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;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
else
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
// Translate error values
|
|
|
|
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
if (PR_LOG_TEST(nsComponentManagerLog, PR_LOG_WARNING))
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
char *buf = aClass.ToString();
|
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("nsComponentManager: CreateInstance(%s) %s", buf,
|
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
|
|
|
if (buf)
|
|
|
|
NS_Free(buf);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
/**
|
|
|
|
* CreateInstanceByContractID()
|
|
|
|
*
|
|
|
|
* A variant of CreateInstance() that creates an instance of the object that
|
|
|
|
* implements the interface aIID and whose implementation has a contractID aContractID.
|
|
|
|
*
|
|
|
|
* This is only a convenience routine that turns around can calls the
|
|
|
|
* CreateInstance() with classid and iid.
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::CreateInstanceByContractID(const char *aContractID,
|
|
|
|
nsISupports *aDelegate,
|
|
|
|
const nsIID &aIID,
|
|
|
|
void **aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
COMPMGR_TIME_FUNCTION_CONTRACTID(aContractID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aContractID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// test this first, since there's no point in creating a component during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Creating new instance on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (aResult == nsnull)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
*aResult = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aContractID, strlen(aContractID));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#ifdef SHOW_CI_ON_EXISTING_SERVICE
|
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsCAutoString 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());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIFactory> factory = entry->GetFactory();
|
|
|
|
if (factory)
|
|
|
|
{
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Translate error values
|
|
|
|
rv = NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PR_LOG(nsComponentManagerLog, PR_LOG_WARNING,
|
|
|
|
("nsComponentManager: CreateInstanceByContractID(%s) %s", aContractID,
|
|
|
|
NS_SUCCEEDED(rv) ? "succeeded" : "FAILED"));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2010-06-10 11:11:11 -07:00
|
|
|
FreeFactoryEntries(const nsID& aCID,
|
|
|
|
nsFactoryEntry* aEntry,
|
|
|
|
void* arg)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
aEntry->mFactory = NULL;
|
|
|
|
aEntry->mServiceObject = NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-06-10 11:11:11 -07:00
|
|
|
nsComponentManagerImpl::FreeServices()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ASSERTION(gXPCOMShuttingDown, "Must be shutting down in order to free all services");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!gXPCOMShuttingDown)
|
|
|
|
return NS_ERROR_FAILURE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mFactories.EnumerateRead(FreeFactoryEntries, NULL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07: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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// This should only ever be called within the monitor!
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RemovePendingService(const nsCID& aServiceCID)
|
|
|
|
{
|
|
|
|
PRUint32 pendingCount = mPendingServices.Length();
|
|
|
|
for (PRUint32 index = 0; index < pendingCount; ++index) {
|
|
|
|
const PendingServiceInfo& info = mPendingServices.ElementAt(index);
|
|
|
|
if (info.cid->Equals(aServiceCID)) {
|
|
|
|
mPendingServices.RemoveElementAt(index);
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// This should only ever be called within the monitor!
|
|
|
|
PRThread*
|
|
|
|
nsComponentManagerImpl::GetPendingServiceThread(const nsCID& aServiceCID) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
PRUint32 pendingCount = mPendingServices.Length();
|
|
|
|
for (PRUint32 index = 0; index < pendingCount; ++index) {
|
|
|
|
const PendingServiceInfo& info = mPendingServices.ElementAt(index);
|
|
|
|
if (info.cid->Equals(aServiceCID)) {
|
|
|
|
return info.thread;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
}
|
|
|
|
return nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::GetService(const nsCID& aClass,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void* *result)
|
2009-11-05 06:08:49 -08:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Getting service on shutdown. Denied.\n"
|
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2009-11-05 06:08:49 -08:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsAutoMonitor mon(mMon);
|
2009-11-05 06:08:49 -08:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry* entry = mFactories.Get(aClass);
|
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2009-11-05 06:08:49 -08:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> supports = entry->mServiceObject;
|
|
|
|
mon.Exit();
|
|
|
|
return supports->QueryInterface(aIID, result);
|
2009-11-05 06:08:49 -08:00
|
|
|
}
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// We only care about time when we create the service.
|
|
|
|
COMPMGR_TIME_FUNCTION_CID(aClass);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PRThread* currentPRThread = PR_GetCurrentThread();
|
|
|
|
NS_ASSERTION(currentPRThread, "This should never be null!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// Needed to optimize the event loop below.
|
|
|
|
nsIThread* currentThread = nsnull;
|
2009-10-15 23:32:29 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PRThread* pendingPRThread;
|
|
|
|
while ((pendingPRThread = GetPendingServiceThread(aClass))) {
|
|
|
|
if (pendingPRThread == currentPRThread) {
|
|
|
|
NS_ERROR("Recursive GetService!");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2009-10-15 23:32:29 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mon.Exit();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!currentThread) {
|
|
|
|
currentThread = NS_GetCurrentThread();
|
|
|
|
NS_ASSERTION(currentThread, "This should never be null!");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// This will process a single event or yield the thread if no event is
|
|
|
|
// pending.
|
|
|
|
if (!NS_ProcessNextEvent(currentThread, PR_FALSE)) {
|
|
|
|
PR_Sleep(PR_INTERVAL_NO_WAIT);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mon.Enter();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07: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) {
|
|
|
|
nsCOMPtr<nsISupports> supports = entry->mServiceObject;
|
|
|
|
mon.Exit();
|
|
|
|
return supports->QueryInterface(aIID, result);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
PendingServiceInfo* newInfo =
|
|
|
|
#endif
|
|
|
|
AddPendingService(aClass, currentPRThread);
|
|
|
|
NS_ASSERTION(newInfo, "Failed to add info to the array!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
// We need to not be holding the service manager's monitor while calling
|
|
|
|
// CreateInstance, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager:
|
|
|
|
mon.Exit();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult rv = CreateInstance(aClass, nsnull, aIID, getter_AddRefs(service));
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mon.Enter();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
pendingPRThread = GetPendingServiceThread(aClass);
|
|
|
|
NS_ASSERTION(pendingPRThread == currentPRThread,
|
|
|
|
"Pending service array has been changed!");
|
|
|
|
#endif
|
|
|
|
RemovePendingService(aClass);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ASSERTION(!entry->mServiceObject, "Created two instances of a service!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
entry->mServiceObject = service;
|
|
|
|
*result = service.get();
|
|
|
|
if (!*result) {
|
|
|
|
NS_ERROR("Factory did not return an object but returned success!");
|
|
|
|
return NS_ERROR_SERVICE_NOT_FOUND;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ADDREF(static_cast<nsISupports*>((*result)));
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-10 11:11:11 -07:00
|
|
|
nsComponentManagerImpl::IsServiceInstantiated(const nsCID & aClass,
|
|
|
|
const nsIID& aIID,
|
|
|
|
PRBool *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
COMPMGR_TIME_FUNCTION_CID(aClass);
|
|
|
|
|
|
|
|
// Now we want to get the service if we already got it. If not, we don't want
|
|
|
|
// to create an instance of it. mmh!
|
|
|
|
|
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString cid, iid;
|
|
|
|
cid.Adopt(aClass.ToString());
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Checking for service on shutdown. Denied.\n"
|
|
|
|
" CID: %s\n IID: %s\n", cid.get(), iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
|
|
|
nsFactoryEntry* entry;
|
2010-05-19 16:22:19 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
entry = mFactories.Get(aClass);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (entry && entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
|
|
|
|
*result = (service!=nsnull);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_IMETHODIMP nsComponentManagerImpl::IsServiceInstantiatedByContractID(const char *aContractID,
|
|
|
|
const nsIID& aIID,
|
|
|
|
PRBool *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
COMPMGR_TIME_FUNCTION_CONTRACTID(aContractID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07: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!
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Checking for service on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
|
|
|
|
nsFactoryEntry *entry;
|
|
|
|
{
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (entry && entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
rv = entry->mServiceObject->QueryInterface(aIID, getter_AddRefs(service));
|
|
|
|
*result = (service!=nsnull);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-10 11:11:11 -07:00
|
|
|
nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
|
|
|
|
const nsIID& aIID,
|
|
|
|
void* *result)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
// test this first, since there's no point in returning a service during
|
|
|
|
// shutdown -- whether it's available or not would depend on the order it
|
|
|
|
// occurs in the list
|
|
|
|
if (gXPCOMShuttingDown) {
|
|
|
|
// When processing shutdown, don't process new GetService() requests
|
|
|
|
#ifdef SHOW_DENIED_ON_SHUTDOWN
|
|
|
|
nsXPIDLCString iid;
|
|
|
|
iid.Adopt(aIID.ToString());
|
|
|
|
fprintf(stderr, "Getting service on shutdown. Denied.\n"
|
|
|
|
" ContractID: %s\n IID: %s\n", aContractID, iid.get());
|
|
|
|
#endif /* SHOW_DENIED_ON_SHUTDOWN */
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsAutoMonitor mon(mMon);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry *entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
if (!entry)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (entry->mServiceObject) {
|
|
|
|
nsCOMPtr<nsISupports> serviceObject = entry->mServiceObject;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// 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.
|
|
|
|
mon.Exit();
|
|
|
|
return serviceObject->QueryInterface(aIID, result);
|
2008-02-21 08:23:06 -08:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// We only care about time when we create the service.
|
|
|
|
COMPMGR_TIME_FUNCTION_CONTRACTID(aContractID);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PRThread* currentPRThread = PR_GetCurrentThread();
|
|
|
|
NS_ASSERTION(currentPRThread, "This should never be null!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// Needed to optimize the event loop below.
|
|
|
|
nsIThread* currentThread = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
PRThread* pendingPRThread;
|
|
|
|
while ((pendingPRThread = GetPendingServiceThread(*entry->mCIDEntry->cid))) {
|
|
|
|
if (pendingPRThread == currentPRThread) {
|
|
|
|
NS_ERROR("Recursive GetService!");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mon.Exit();
|
|
|
|
|
|
|
|
if (!currentThread) {
|
|
|
|
currentThread = NS_GetCurrentThread();
|
|
|
|
NS_ASSERTION(currentThread, "This should never be null!");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
// This will process a single event or yield the thread if no event is
|
|
|
|
// pending.
|
|
|
|
if (!NS_ProcessNextEvent(currentThread, PR_FALSE)) {
|
|
|
|
PR_Sleep(PR_INTERVAL_NO_WAIT);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mon.Enter();
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
nsCOMPtr<nsISupports> serviceObject = entry->mServiceObject;
|
|
|
|
mon.Exit();
|
|
|
|
return serviceObject->QueryInterface(aIID, result);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
PendingServiceInfo* newInfo =
|
|
|
|
#endif
|
|
|
|
AddPendingService(*entry->mCIDEntry->cid, currentPRThread);
|
|
|
|
NS_ASSERTION(newInfo, "Failed to add info to the array!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsISupports> service;
|
|
|
|
// We need to not be holding the service manager's monitor while calling
|
|
|
|
// CreateInstance, because it invokes user code which could try to re-enter
|
|
|
|
// the service manager:
|
|
|
|
mon.Exit();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsresult rv = CreateInstanceByContractID(aContractID, nsnull, aIID,
|
|
|
|
getter_AddRefs(service));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mon.Enter();
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
pendingPRThread = GetPendingServiceThread(*entry->mCIDEntry->cid);
|
|
|
|
NS_ASSERTION(pendingPRThread == currentPRThread,
|
|
|
|
"Pending service array has been changed!");
|
|
|
|
#endif
|
|
|
|
RemovePendingService(*entry->mCIDEntry->cid);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ASSERTION(!entry->mServiceObject, "Created two instances of a service!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
entry->mServiceObject = service;
|
|
|
|
*result = service.get();
|
|
|
|
NS_ADDREF(static_cast<nsISupports*>(*result));
|
2007-03-22 10:30:00 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
already_AddRefed<mozilla::ModuleLoader>
|
|
|
|
nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<mozilla::ModuleLoader> loader = mLoaderMap.Get(aExt);
|
|
|
|
if (!loader) {
|
|
|
|
loader = do_GetServiceFromCategory("module-loader",
|
|
|
|
PromiseFlatCString(aExt).get());
|
|
|
|
if (!loader)
|
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
mLoaderMap.Put(aExt, loader);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return loader.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-10 11:11:11 -07:00
|
|
|
nsComponentManagerImpl::RegisterFactory(const nsCID& aClass,
|
|
|
|
const char* aName,
|
|
|
|
const char* aContractID,
|
|
|
|
nsIFactory* aFactory)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-23 12:18:13 -07: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;
|
|
|
|
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsFactoryEntry* oldf = mFactories.Get(aClass);
|
|
|
|
if (!oldf)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
|
|
|
|
mContractIDs.Put(nsDependentCString(aContractID), oldf);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-25 07:44:35 -07:00
|
|
|
nsAutoPtr<nsFactoryEntry> f(new nsFactoryEntry(aClass, aFactory));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsFactoryEntry* oldf = mFactories.Get(aClass);
|
|
|
|
if (oldf)
|
|
|
|
return NS_ERROR_FACTORY_EXISTS;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-23 12:18:13 -07:00
|
|
|
if (aContractID)
|
|
|
|
mContractIDs.Put(nsDependentCString(aContractID), f);
|
|
|
|
|
2010-06-23 13:18:08 -07:00
|
|
|
mFactories.Put(aClass, f.forget());
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-10 11:11:11 -07:00
|
|
|
nsComponentManagerImpl::UnregisterFactory(const nsCID& aClass,
|
|
|
|
nsIFactory* aFactory)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-21 09:46:26 -07: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 11:11:11 -07:00
|
|
|
|
2010-06-21 09:46:26 -07:00
|
|
|
{
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsFactoryEntry* f = mFactories.Get(aClass);
|
|
|
|
if (!f || f->mFactory != aFactory)
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
|
|
|
|
|
|
|
mFactories.Remove(aClass);
|
|
|
|
|
|
|
|
// This might leave a stale contractid -> factory mapping in
|
|
|
|
// place, so null out the factory entry (see
|
|
|
|
// nsFactoryEntry::GetFactory)
|
|
|
|
f->mFactory.swap(dyingFactory);
|
|
|
|
f->mServiceObject.swap(dyingServiceObject);
|
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-24 11:31:18 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::AutoRegister(nsIFile* aLocation)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsILocalFile> lf = do_QueryInterface(aLocation);
|
|
|
|
if (!lf)
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
|
|
|
|
XRE_AddComponentLocation(NS_COMPONENT_LOCATION, lf);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::AutoUnregister(nsIFile* aLocation)
|
|
|
|
{
|
|
|
|
NS_ERROR("AutoUnregister not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::RegisterFactoryLocation(const nsCID& aCID,
|
|
|
|
const char* aClassName,
|
|
|
|
const char* aContractID,
|
|
|
|
nsIFile* aFile,
|
|
|
|
const char* aLoaderStr,
|
|
|
|
const char* aType)
|
|
|
|
{
|
|
|
|
NS_ERROR("RegisterFactoryLocation not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::UnregisterFactoryLocation(const nsCID& aCID,
|
|
|
|
nsIFile* aFile)
|
|
|
|
{
|
|
|
|
NS_ERROR("UnregisterFactoryLocation not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::IsCIDRegistered(const nsCID & aClass,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
*_retval = (nsnull != GetFactoryEntry(aClass));
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::IsContractIDRegistered(const char *aClass,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
2009-01-07 20:42:15 -08:00
|
|
|
NS_ENSURE_ARG_POINTER(aClass);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsFactoryEntry *entry = GetFactoryEntry(aClass, strlen(aClass));
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
else
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
static PLDHashOperator
|
|
|
|
EnumerateCIDHelper(const nsID& id, nsFactoryEntry* entry, void* closure)
|
|
|
|
{
|
|
|
|
nsCOMArray<nsISupports> *array = static_cast<nsCOMArray<nsISupports>*>(closure);
|
|
|
|
nsCOMPtr<nsISupportsID> wrapper = new nsSupportsIDImpl();
|
|
|
|
wrapper->SetData(&id);
|
|
|
|
array->AppendObject(wrapper);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::EnumerateCIDs(nsISimpleEnumerator **aEnumerator)
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMArray<nsISupports> array;
|
|
|
|
mFactories.EnumerateRead(EnumerateCIDHelper, &array);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return NS_NewArrayEnumerator(aEnumerator, array);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
static PLDHashOperator
|
|
|
|
EnumerateContractsHelper(const nsACString& contract, nsFactoryEntry* entry, void* closure)
|
|
|
|
{
|
|
|
|
nsTArray<nsCString>* array = static_cast<nsTArray<nsCString>*>(closure);
|
|
|
|
array->AppendElement(contract);
|
|
|
|
return PL_DHASH_NEXT;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::EnumerateContractIDs(nsISimpleEnumerator **aEnumerator)
|
|
|
|
{
|
2010-05-19 16:22:19 -07:00
|
|
|
NS_TIME_FUNCTION;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsTArray<nsCString>* array = new nsTArray<nsCString>;
|
|
|
|
mContractIDs.EnumerateRead(EnumerateContractsHelper, array);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsCOMPtr<nsIUTF8StringEnumerator> e;
|
|
|
|
nsresult rv = NS_NewAdoptingUTF8StringEnumerator(getter_AddRefs(e), array);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
return CallQueryInterface(e, aEnumerator);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::CIDToContractID(const nsCID & aClass,
|
|
|
|
char **_retval)
|
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ERROR("CIDTOContractID not implemented");
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::ContractIDToCID(const char *aContractID,
|
|
|
|
nsCID * *_retval)
|
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
{
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsFactoryEntry* entry = mContractIDs.Get(nsDependentCString(aContractID));
|
|
|
|
if (entry) {
|
|
|
|
*_retval = (nsCID*) NS_Alloc(sizeof(nsCID));
|
|
|
|
**_retval = *entry->mCIDEntry->cid;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
*_retval = NULL;
|
|
|
|
return NS_ERROR_FACTORY_NOT_REGISTERED;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsFactoryEntry
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const mozilla::Module::CIDEntry* entry,
|
|
|
|
nsComponentManagerImpl::KnownModule* module)
|
|
|
|
: mCIDEntry(entry)
|
|
|
|
, mModule(module)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-25 07:44:35 -07:00
|
|
|
nsFactoryEntry::nsFactoryEntry(const nsCID& aCID, nsIFactory* factory)
|
2010-06-10 11:11:11 -07:00
|
|
|
: mCIDEntry(NULL)
|
|
|
|
, mModule(NULL)
|
|
|
|
, mFactory(factory)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-06-25 07:44:35 -07:00
|
|
|
mozilla::Module::CIDEntry* e = new mozilla::Module::CIDEntry();
|
|
|
|
nsCID* cid = new nsCID;
|
|
|
|
*cid = aCID;
|
|
|
|
e->cid = cid;
|
|
|
|
mCIDEntry = e;
|
2010-06-10 11:11:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-25 07:44:35 -07:00
|
|
|
nsFactoryEntry::~nsFactoryEntry()
|
|
|
|
{
|
|
|
|
// If this was a RegisterFactory entry, we own the CIDEntry/CID
|
|
|
|
if (!mModule) {
|
|
|
|
delete mCIDEntry->cid;
|
|
|
|
delete mCIDEntry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
already_AddRefed<nsIFactory>
|
|
|
|
nsFactoryEntry::GetFactory()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mFactory) {
|
2010-06-10 11:11:11 -07:00
|
|
|
// RegisterFactory then UnregisterFactory can leave an entry in mContractIDs
|
|
|
|
// pointing to an unusable nsFactoryEntry.
|
|
|
|
if (!mModule)
|
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!mModule->Load())
|
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-21 09:46:26 -07:00
|
|
|
if (mModule->Module()->getFactoryProc) {
|
|
|
|
mFactory = mModule->Module()->getFactoryProc(*mModule->Module(),
|
|
|
|
*mCIDEntry);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-21 09:46:26 -07:00
|
|
|
else if (mCIDEntry->getFactoryProc) {
|
|
|
|
mFactory = mCIDEntry->getFactoryProc(*mModule->Module(), *mCIDEntry);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
else {
|
2010-06-21 09:46:26 -07:00
|
|
|
NS_ASSERTION(mCIDEntry->constructorProc, "no getfactory or constructor");
|
|
|
|
mFactory = new mozilla::GenericFactory(mCIDEntry->constructorProc);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (!mFactory)
|
2010-06-10 11:11:11 -07:00
|
|
|
return NULL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ADDREF(mFactory);
|
|
|
|
return mFactory.get();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Static Access Functions
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_COM nsresult
|
|
|
|
NS_GetComponentManager(nsIComponentManager* *result)
|
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ADDREF(*result = nsComponentManagerImpl::gComponentManager);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_COM nsresult
|
|
|
|
NS_GetServiceManager(nsIServiceManager* *result)
|
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ADDREF(*result = nsComponentManagerImpl::gComponentManager);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_COM nsresult
|
|
|
|
NS_GetComponentRegistrar(nsIComponentRegistrar* *result)
|
|
|
|
{
|
2010-06-10 11:11:11 -07:00
|
|
|
if (!nsComponentManagerImpl::gComponentManager)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
NS_ADDREF(*result = nsComponentManagerImpl::gComponentManager);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
XRE_AddStaticComponent(const mozilla::Module* aComponent)
|
|
|
|
{
|
|
|
|
nsComponentManagerImpl::InitializeStaticModules();
|
|
|
|
nsComponentManagerImpl::sStaticModules->AppendElement(aComponent);
|
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager &&
|
|
|
|
nsComponentManagerImpl::NORMAL == nsComponentManagerImpl::gComponentManager->mStatus)
|
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterModule(aComponent, NULL);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_XPCOM_API(nsresult)
|
2010-06-11 13:13:26 -07:00
|
|
|
XRE_AddComponentLocation(NSLocationType aType, nsILocalFile* aLocation)
|
2010-06-10 11:11:11 -07:00
|
|
|
{
|
|
|
|
nsComponentManagerImpl::InitializeModuleLocations();
|
2010-06-11 13:13:26 -07:00
|
|
|
nsComponentManagerImpl::ComponentLocation* c =
|
|
|
|
nsComponentManagerImpl::sModuleLocations->AppendElement();
|
|
|
|
c->type = aType;
|
|
|
|
c->location = aLocation;
|
2010-06-10 11:11:11 -07:00
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager &&
|
|
|
|
nsComponentManagerImpl::NORMAL == nsComponentManagerImpl::gComponentManager->mStatus)
|
2010-06-22 13:24:01 -07:00
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterLocation(aType, aLocation, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|