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
|
|
|
#include "mozilla/Omnijar.h"
|
2010-09-08 20:37:11 -07:00
|
|
|
#include "nsJAR.h"
|
2010-06-15 12:38:46 -07:00
|
|
|
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
|
|
|
|
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*>;
|
2010-07-13 07:24:58 -07:00
|
|
|
#ifdef MOZ_ENABLE_LIBXUL
|
2010-11-07 01:25:38 -07:00
|
|
|
for (const mozilla::Module *const *const *staticModules = kPStaticModules;
|
2010-06-10 11:11:11 -07:00
|
|
|
*staticModules; ++staticModules)
|
2010-11-07 01:25:38 -07:00
|
|
|
sStaticModules->AppendElement(**staticModules);
|
2010-07-02 11:23:41 -07:00
|
|
|
#endif
|
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();
|
2010-07-02 06:53:19 -07:00
|
|
|
mKnownJARModules.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-07-22 07:31:29 -07:00
|
|
|
ComponentLocation* cl = sModuleLocations->InsertElementAt(0);
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
|
|
|
cl->location = CloneAndAppend(appDir, NS_LITERAL_CSTRING("chrome.manifest"));
|
2010-09-08 20:37:11 -07:00
|
|
|
cl->jar = false;
|
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-07-22 07:31:29 -07:00
|
|
|
cl = sModuleLocations->InsertElementAt(0);
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
|
|
|
cl->location = CloneAndAppend(greDir, NS_LITERAL_CSTRING("chrome.manifest"));
|
2010-09-08 20:37:11 -07:00
|
|
|
cl->jar = 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
|
|
|
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-07-02 06:53:19 -07:00
|
|
|
#ifdef MOZ_OMNIJAR
|
2010-09-08 20:37:11 -07:00
|
|
|
if (mozilla::OmnijarPath()) {
|
|
|
|
nsCOMPtr<nsIZipReader> omnijarReader = new nsJAR();
|
|
|
|
rv = omnijarReader->Open(mozilla::OmnijarPath());
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
RegisterJarManifest(omnijarReader, "chrome.manifest", false);
|
|
|
|
}
|
2010-07-02 06:53:19 -07:00
|
|
|
#endif
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
|
|
|
|
ComponentLocation& l = sModuleLocations->ElementAt(i);
|
2010-09-08 20:37:11 -07:00
|
|
|
if (!l.jar) {
|
|
|
|
RegisterManifestFile(l.type, l.location, false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
|
|
|
|
rv = reader->Open(l.location);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
RegisterJarManifest(reader, "chrome.manifest", false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_OMNIJAR
|
|
|
|
if (mozilla::OmnijarPath()) {
|
|
|
|
cl = sModuleLocations->InsertElementAt(0);
|
|
|
|
cl->type = NS_COMPONENT_LOCATION;
|
|
|
|
cl->location = mozilla::OmnijarPath();
|
|
|
|
cl->jar = true;
|
2010-06-11 13:13:26 -07:00
|
|
|
}
|
2010-09-08 20:37:11 -07:00
|
|
|
#endif
|
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);
|
2010-12-03 12:24:22 -08:00
|
|
|
NS_ASSERTION(!mKnownFileModules.Get(h),
|
|
|
|
"Must not register a binary module twice.");
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
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) {
|
2010-12-03 12:24:22 -08:00
|
|
|
NS_WARNING("Re-registering a CID?");
|
2010-06-28 10:55:57 -07:00
|
|
|
|
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
aEntry->cid->ToProvidedString(idstr);
|
|
|
|
|
|
|
|
nsCString existing;
|
|
|
|
if (f->mModule)
|
|
|
|
existing = f->mModule->Description();
|
|
|
|
else
|
|
|
|
existing = "<unknown module>";
|
|
|
|
|
2010-07-13 10:02:22 -07:00
|
|
|
LogMessage("While registering XPCOM module %s, trying to re-register CID '%s' already registered by %s.",
|
2010-06-28 10:55:57 -07:00
|
|
|
aModule->Description().get(),
|
|
|
|
idstr,
|
|
|
|
existing.get());
|
2010-06-10 11:11:11 -07:00
|
|
|
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");
|
2010-06-28 10:55:57 -07:00
|
|
|
|
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
aEntry->cid->ToProvidedString(idstr);
|
|
|
|
|
|
|
|
LogMessage("Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
|
|
|
|
aEntry->contractid,
|
|
|
|
idstr);
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
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-07-02 06:53:19 -07:00
|
|
|
static void
|
|
|
|
CutExtension(nsCString& path)
|
|
|
|
{
|
|
|
|
PRInt32 dotPos = path.RFindChar('.');
|
|
|
|
if (kNotFound == dotPos)
|
|
|
|
path.Truncate();
|
|
|
|
else
|
|
|
|
path.Cut(0, dotPos + 1);
|
|
|
|
}
|
|
|
|
|
2010-06-29 15:16:48 -07:00
|
|
|
static nsCString
|
|
|
|
GetExtension(nsILocalFile* file)
|
|
|
|
{
|
|
|
|
nsCString extension;
|
|
|
|
file->GetNativePath(extension);
|
2010-07-02 06:53:19 -07:00
|
|
|
CutExtension(extension);
|
2010-06-29 15:16:48 -07:00
|
|
|
return extension;
|
|
|
|
}
|
|
|
|
|
2010-09-08 20:37:11 -07:00
|
|
|
static already_AddRefed<nsIInputStream>
|
|
|
|
LoadEntry(nsIZipReader* aReader, const char* aName)
|
2010-07-02 06:53:19 -07:00
|
|
|
{
|
2010-09-08 20:37:11 -07:00
|
|
|
if (!aReader)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> is;
|
|
|
|
nsresult rv = aReader->GetInputStream(aName, getter_AddRefs(is));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return is.forget();
|
|
|
|
}
|
2010-08-10 15:18:40 -07:00
|
|
|
|
2010-09-08 20:37:11 -07:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RegisterJarManifest(nsIZipReader* aReader,
|
|
|
|
const char* aPath, bool aChromeOnly)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIInputStream> is = LoadEntry(aReader, aPath);
|
2010-08-11 18:11:18 -07:00
|
|
|
if (!is) {
|
2010-09-08 20:37:11 -07:00
|
|
|
LogMessage("Could not find jar manifest entry '%s'.", aPath);
|
2010-08-11 18:11:18 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-07-02 06:53:19 -07:00
|
|
|
|
|
|
|
PRUint32 flen;
|
2010-07-22 07:31:29 -07:00
|
|
|
is->Available(&flen);
|
2010-07-02 06:53:19 -07:00
|
|
|
|
|
|
|
nsAutoArrayPtr<char> whole(new char[flen + 1]);
|
|
|
|
if (!whole)
|
2010-08-04 11:09:21 -07:00
|
|
|
return;
|
2010-07-02 06:53:19 -07:00
|
|
|
|
|
|
|
for (PRUint32 totalRead = 0; totalRead < flen; ) {
|
|
|
|
PRUint32 avail;
|
|
|
|
PRUint32 read;
|
|
|
|
|
2010-07-22 07:31:29 -07:00
|
|
|
if (NS_FAILED(is->Available(&avail)))
|
2010-08-04 11:09:21 -07:00
|
|
|
return;
|
2010-07-02 06:53:19 -07:00
|
|
|
|
|
|
|
if (avail > flen)
|
2010-08-04 11:09:21 -07:00
|
|
|
return;
|
2010-07-02 06:53:19 -07:00
|
|
|
|
2010-07-22 07:31:29 -07:00
|
|
|
if (NS_FAILED(is->Read(whole + totalRead, avail, &read)))
|
2010-08-04 11:09:21 -07:00
|
|
|
return;
|
2010-07-02 06:53:19 -07:00
|
|
|
|
|
|
|
totalRead += read;
|
|
|
|
}
|
|
|
|
|
|
|
|
whole[flen] = '\0';
|
|
|
|
|
2010-09-08 20:37:11 -07:00
|
|
|
ParseManifest(NS_COMPONENT_LOCATION, aReader, aPath,
|
|
|
|
whole, aChromeOnly);
|
2010-07-02 06:53:19 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
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);
|
2010-07-22 07:31:29 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
nsCAutoString path;
|
|
|
|
aFile->GetNativePath(path);
|
|
|
|
LogMessage("Could not read chrome manifest file '%s'.", path.get());
|
2010-06-11 13:13:26 -07:00
|
|
|
return;
|
2010-07-22 07:31:29 -07:00
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-06-25 10:55:46 -07:00
|
|
|
#if defined(XP_WIN) || defined(XP_OS2)
|
|
|
|
#define TRANSLATE_SLASHES
|
|
|
|
static void
|
|
|
|
TranslateSlashes(char* path)
|
|
|
|
{
|
|
|
|
for (; *path; ++path) {
|
|
|
|
if ('/' == *path)
|
|
|
|
*path = '\\';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-04 11:09:21 -07:00
|
|
|
static void
|
|
|
|
AppendFileToManifestPath(nsCString& path,
|
|
|
|
const char* file)
|
|
|
|
{
|
|
|
|
PRInt32 i = path.RFindChar('/');
|
|
|
|
if (kNotFound == i)
|
|
|
|
path.Truncate(0);
|
|
|
|
else
|
|
|
|
path.Truncate(i + 1);
|
|
|
|
|
|
|
|
path.Append(file);
|
|
|
|
}
|
|
|
|
|
2010-07-22 07:31:29 -07:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestManifest(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* file = argv[0];
|
|
|
|
|
|
|
|
if (cx.mPath) {
|
|
|
|
nsCAutoString manifest(cx.mPath);
|
|
|
|
AppendFileToManifestPath(manifest, file);
|
|
|
|
|
2010-09-08 20:37:11 -07:00
|
|
|
RegisterJarManifest(cx.mReader, manifest.get(), cx.mChromeOnly);
|
2010-07-22 07:31:29 -07:00
|
|
|
}
|
2010-09-08 20:37:11 -07:00
|
|
|
else {
|
2010-08-11 18:11:18 -07:00
|
|
|
#ifdef TRANSLATE_SLASHES
|
|
|
|
TranslateSlashes(file);
|
|
|
|
#endif
|
2010-07-22 07:31:29 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegisterManifestFile(cx.mType, clfile, cx.mChromeOnly);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestBinaryComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
2010-07-02 06:53:19 -07:00
|
|
|
if (cx.mPath) {
|
2010-09-08 20:37:11 -07:00
|
|
|
NS_WARNING("Cannot load binary components from a jar.");
|
2010-07-02 06:53:19 -07:00
|
|
|
LogMessageWithContext(cx.mFile, cx.mPath, lineno,
|
2010-09-08 20:37:11 -07:00
|
|
|
"Cannot load binary components from a jar.");
|
2010-07-02 06:53:19 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
char* file = argv[0];
|
|
|
|
|
2010-06-25 10:55:46 -07:00
|
|
|
#ifdef TRANSLATE_SLASHES
|
|
|
|
TranslateSlashes(file);
|
|
|
|
#endif
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
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
|
|
|
|
2010-12-03 12:24:22 -08:00
|
|
|
nsCOMPtr<nsIHashable> h = do_QueryInterface(clfile);
|
|
|
|
NS_ASSERTION(h, "nsILocalFile doesn't implement nsIHashable");
|
|
|
|
if (mKnownFileModules.Get(h)) {
|
|
|
|
NS_WARNING("Attempting to register a binary component twice.");
|
|
|
|
LogMessageWithContext(cx.mFile, cx.mPath, lineno,
|
|
|
|
"Attempting to register a binary component twice.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
const mozilla::Module* m = mNativeModuleLoader.LoadModule(clfile);
|
2010-06-28 10:55:57 -07:00
|
|
|
if (!m)
|
2010-06-11 13:13:26 -07:00
|
|
|
return;
|
2010-06-28 10:55:57 -07:00
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
RegisterModule(m, clfile);
|
|
|
|
}
|
|
|
|
|
2010-06-25 10:55:46 -07:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestXPT(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* file = argv[0];
|
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
if (cx.mPath) {
|
|
|
|
nsCAutoString manifest(cx.mPath);
|
|
|
|
AppendFileToManifestPath(manifest, file);
|
|
|
|
|
2010-08-04 11:09:21 -07:00
|
|
|
nsCOMPtr<nsIInputStream> stream =
|
2010-09-08 20:37:11 -07:00
|
|
|
LoadEntry(cx.mReader, manifest.get());
|
2010-08-04 11:09:21 -07:00
|
|
|
if (!stream) {
|
2010-09-08 20:37:11 -07:00
|
|
|
NS_WARNING("Failed to load XPT file in a jar.");
|
2010-07-02 06:53:19 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-06-25 10:55:46 -07:00
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
xptiInterfaceInfoManager::GetSingleton()
|
|
|
|
->RegisterInputStream(stream);
|
2010-06-25 10:55:46 -07:00
|
|
|
}
|
2010-09-08 20:37:11 -07:00
|
|
|
else {
|
2010-08-11 18:11:18 -07:00
|
|
|
#ifdef TRANSLATE_SLASHES
|
|
|
|
TranslateSlashes(file);
|
|
|
|
#endif
|
2010-07-02 06:53:19 -07:00
|
|
|
nsCOMPtr<nsIFile> cfile;
|
|
|
|
cx.mFile->GetParent(getter_AddRefs(cfile));
|
|
|
|
nsCOMPtr<nsILocalFile> clfile = do_QueryInterface(cfile);
|
2010-06-25 10:55:46 -07:00
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
nsresult rv = clfile->AppendRelativeNativePath(nsDependentCString(file));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Couldn't append relative path?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xptiInterfaceInfoManager::GetSingleton()
|
|
|
|
->RegisterFile(clfile);
|
|
|
|
}
|
2010-06-25 10:55:46 -07:00
|
|
|
}
|
|
|
|
|
2010-06-11 13:13:26 -07:00
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestComponent(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* id = argv[0];
|
|
|
|
char* file = argv[1];
|
|
|
|
|
|
|
|
nsID cid;
|
|
|
|
if (!cid.Parse(id)) {
|
2010-07-02 06:53:19 -07:00
|
|
|
LogMessageWithContext(cx.mFile, cx.mPath, lineno,
|
|
|
|
"Malformed CID: '%s'.", id);
|
2010-06-11 13:13:26 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsFactoryEntry* f = mFactories.Get(cid);
|
|
|
|
if (f) {
|
2010-06-28 10:55:57 -07:00
|
|
|
char idstr[NSID_LENGTH];
|
|
|
|
cid.ToProvidedString(idstr);
|
|
|
|
|
|
|
|
nsCString existing;
|
|
|
|
if (f->mModule)
|
|
|
|
existing = f->mModule->Description();
|
|
|
|
else
|
|
|
|
existing = "<unknown module>";
|
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
LogMessageWithContext(cx.mFile, cx.mPath, lineno,
|
|
|
|
"Trying to re-register CID '%s' already registered by %s.",
|
2010-06-28 10:55:57 -07:00
|
|
|
idstr,
|
|
|
|
existing.get());
|
2010-06-11 13:13:26 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
KnownModule* km;
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
if (cx.mPath) {
|
|
|
|
nsCAutoString manifest(cx.mPath);
|
|
|
|
AppendFileToManifestPath(manifest, file);
|
|
|
|
|
2010-09-08 20:37:11 -07:00
|
|
|
nsCAutoString hash;
|
|
|
|
cx.mFile->GetNativePath(hash);
|
|
|
|
hash.AppendLiteral("|");
|
|
|
|
hash.Append(manifest);
|
|
|
|
|
|
|
|
km = mKnownJARModules.Get(hash);
|
2010-07-02 06:53:19 -07:00
|
|
|
if (!km) {
|
2010-09-08 20:37:11 -07:00
|
|
|
km = new KnownModule(cx.mFile, manifest);
|
|
|
|
mKnownJARModules.Put(hash, km);
|
2010-07-02 06:53:19 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-09-08 20:37:11 -07:00
|
|
|
else {
|
2010-08-11 18:11:18 -07:00
|
|
|
#ifdef TRANSLATE_SLASHES
|
|
|
|
TranslateSlashes(file);
|
|
|
|
#endif
|
2010-07-02 06:53:19 -07:00
|
|
|
nsCOMPtr<nsIFile> cfile;
|
|
|
|
cx.mFile->GetParent(getter_AddRefs(cfile));
|
|
|
|
nsCOMPtr<nsILocalFile> clfile = do_QueryInterface(cfile);
|
2010-06-11 13:13:26 -07:00
|
|
|
|
2010-07-02 06:53:19 -07:00
|
|
|
nsresult rv = clfile->AppendRelativeNativePath(nsDependentCString(file));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Couldn't append relative path?");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHashable> h = do_QueryInterface(clfile);
|
|
|
|
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)) {
|
2010-07-02 06:53:19 -07:00
|
|
|
LogMessageWithContext(cx.mFile, cx.mPath, lineno,
|
|
|
|
"Malformed CID: '%s'.", id);
|
2010-06-11 13:13:26 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoMonitor mon(mMon);
|
|
|
|
nsFactoryEntry* f = mFactories.Get(cid);
|
|
|
|
if (!f) {
|
2010-07-02 06:53:19 -07:00
|
|
|
LogMessageWithContext(cx.mFile, cx.mPath, lineno,
|
|
|
|
"Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
|
2010-06-28 10:55:57 -07:00
|
|
|
contract, id);
|
2010-06-11 13:13:26 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mContractIDs.Put(nsDependentCString(contract), f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::ManifestCategory(ManifestProcessingContext& cx, int lineno, char *const * argv)
|
|
|
|
{
|
|
|
|
char* category = argv[0];
|
|
|
|
char* key = argv[1];
|
|
|
|
char* value = argv[2];
|
|
|
|
|
|
|
|
nsCategoryManager::GetSingleton()->
|
|
|
|
AddCategoryEntry(category, key, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsComponentManagerImpl::RereadChromeManifests()
|
|
|
|
{
|
2010-06-22 13:24:01 -07:00
|
|
|
for (PRUint32 i = 0; i < sModuleLocations->Length(); ++i) {
|
|
|
|
ComponentLocation& l = sModuleLocations->ElementAt(i);
|
2010-09-08 20:37:11 -07:00
|
|
|
if (!l.jar) {
|
|
|
|
RegisterManifestFile(l.type, l.location, true);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = reader->Open(l.location);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
RegisterJarManifest(reader, "chrome.manifest", true);
|
2010-06-22 13:24:01 -07:00
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsComponentManagerImpl::KnownModule::EnsureLoader()
|
|
|
|
{
|
|
|
|
if (!mLoader) {
|
2010-07-02 06:53:19 -07:00
|
|
|
nsCString extension;
|
|
|
|
if (!mPath.IsEmpty()) {
|
|
|
|
extension = mPath;
|
|
|
|
CutExtension(extension);
|
|
|
|
}
|
2010-09-08 20:37:11 -07:00
|
|
|
else {
|
2010-07-02 06:53:19 -07:00
|
|
|
extension = GetExtension(mFile);
|
|
|
|
}
|
2010-06-11 13:13:26 -07:00
|
|
|
|
|
|
|
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-07-02 06:53:19 -07:00
|
|
|
|
|
|
|
if (!mPath.IsEmpty())
|
2010-09-08 20:37:11 -07:00
|
|
|
mModule = mLoader->LoadModuleFromJAR(mFile, mPath);
|
2010-07-02 06:53:19 -07:00
|
|
|
else
|
|
|
|
mModule = mLoader->LoadModule(mFile);
|
|
|
|
|
2010-06-10 11:11:11 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-06-28 10:55:57 -07:00
|
|
|
nsCString
|
|
|
|
nsComponentManagerImpl::KnownModule::Description() const
|
|
|
|
{
|
|
|
|
nsCString s;
|
2010-07-02 06:53:19 -07:00
|
|
|
if (!mPath.IsEmpty()) {
|
2010-09-08 20:37:11 -07:00
|
|
|
mFile->GetNativePath(s);
|
|
|
|
s.Insert(NS_LITERAL_CSTRING("jar:"), 0);
|
|
|
|
s.AppendLiteral("!/");
|
2010-07-02 06:53:19 -07:00
|
|
|
s.Append(mPath);
|
|
|
|
}
|
2010-09-08 20:37:11 -07:00
|
|
|
else if (mFile)
|
2010-06-28 10:55:57 -07:00
|
|
|
mFile->GetNativePath(s);
|
|
|
|
else
|
|
|
|
s = "<static module>";
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
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();
|
2010-07-02 06:53:19 -07:00
|
|
|
mKnownJARModules.Clear();
|
2010-06-11 13:13:26 -07:00
|
|
|
mKnownFileModules.Clear();
|
2010-06-25 07:02:17 -07:00
|
|
|
mKnownStaticModules.Clear();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mLoaderData.Clear();
|
|
|
|
|
2010-06-25 14:27:10 -07:00
|
|
|
delete sStaticModules;
|
|
|
|
delete sModuleLocations;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// 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-09-08 20:37:11 -07:00
|
|
|
else {
|
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;
|
|
|
|
}
|
|
|
|
}
|
2010-09-08 20:37:11 -07:00
|
|
|
else {
|
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
|
|
|
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;
|
|
|
|
|
2010-06-27 18:26:38 -07:00
|
|
|
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, lf);
|
2010-06-24 11:31:18 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::AutoUnregister(nsIFile* aLocation)
|
|
|
|
{
|
|
|
|
NS_ERROR("AutoUnregister not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::RegisterFactoryLocation(const nsCID& aCID,
|
|
|
|
const char* aClassName,
|
|
|
|
const char* aContractID,
|
|
|
|
nsIFile* aFile,
|
|
|
|
const char* aLoaderStr,
|
|
|
|
const char* aType)
|
|
|
|
{
|
|
|
|
NS_ERROR("RegisterFactoryLocation not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsComponentManagerImpl::UnregisterFactoryLocation(const nsCID& aCID,
|
|
|
|
nsIFile* aFile)
|
|
|
|
{
|
|
|
|
NS_ERROR("UnregisterFactoryLocation not implemented.");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
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-27 18:26:38 -07:00
|
|
|
XRE_AddManifestLocation(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-09-08 20:37:11 -07:00
|
|
|
c->jar = false;
|
2010-06-10 11:11:11 -07:00
|
|
|
|
|
|
|
if (nsComponentManagerImpl::gComponentManager &&
|
|
|
|
nsComponentManagerImpl::NORMAL == nsComponentManagerImpl::gComponentManager->mStatus)
|
2010-07-22 07:31:29 -07:00
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterManifestFile(aType, aLocation, false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-09-08 20:37:11 -07:00
|
|
|
|
|
|
|
EXPORT_XPCOM_API(nsresult)
|
|
|
|
XRE_AddJarManifestLocation(NSLocationType aType, nsILocalFile* aLocation)
|
|
|
|
{
|
|
|
|
nsComponentManagerImpl::InitializeModuleLocations();
|
|
|
|
nsComponentManagerImpl::ComponentLocation* c =
|
|
|
|
nsComponentManagerImpl::sModuleLocations->AppendElement();
|
|
|
|
c->type = aType;
|
|
|
|
c->location = aLocation;
|
|
|
|
c->jar = true;
|
|
|
|
|
|
|
|
if (!nsComponentManagerImpl::gComponentManager ||
|
|
|
|
nsComponentManagerImpl::NORMAL != nsComponentManagerImpl::gComponentManager->mStatus)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIZipReader> reader = do_CreateInstance(kZipReaderCID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = reader->Open(c->location);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
nsComponentManagerImpl::gComponentManager->RegisterJarManifest(reader, "chrome.manifest", false);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|