Bug 1093934 - Create a XPCOM library that can be used to support standalone WebRTC. r=nfroyd
This commit is contained in:
@@ -58,7 +58,10 @@
|
||||
#include "private/pprthred.h"
|
||||
#include "nsTArray.h"
|
||||
#include "prio.h"
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
#include "ManifestParser.h"
|
||||
#include "nsNetUtil.h"
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#include "mozilla/GenericFactory.h"
|
||||
@@ -68,7 +71,6 @@
|
||||
#include "nsArrayEnumerator.h"
|
||||
#include "nsStringEnumerator.h"
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsDataHashtable.h"
|
||||
|
||||
#include <new> // for placement new
|
||||
@@ -250,6 +252,7 @@ private:
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
// this is safe to call during InitXPCOM
|
||||
static already_AddRefed<nsIFile>
|
||||
GetLocationFromDirectoryService(const char* aProp)
|
||||
@@ -286,6 +289,7 @@ CloneAndAppend(nsIFile* aBase, const nsACString& aAppend)
|
||||
f->AppendNative(aAppend);
|
||||
return f.forget();
|
||||
}
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsComponentManagerImpl
|
||||
@@ -318,8 +322,10 @@ nsComponentManagerImpl::nsComponentManagerImpl()
|
||||
|
||||
nsTArray<const mozilla::Module*>* nsComponentManagerImpl::sStaticModules;
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
NSMODULE_DEFN(start_kPStaticModules);
|
||||
NSMODULE_DEFN(end_kPStaticModules);
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
|
||||
/* The content between start_kPStaticModules and end_kPStaticModules is gathered
|
||||
* by the linker from various objects containing symbols in a specific section.
|
||||
@@ -335,12 +341,14 @@ nsComponentManagerImpl::InitializeStaticModules()
|
||||
}
|
||||
|
||||
sStaticModules = new nsTArray<const mozilla::Module*>;
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
for (const mozilla::Module * const* staticModules =
|
||||
&NSMODULE_NAME(start_kPStaticModules) + 1;
|
||||
staticModules < &NSMODULE_NAME(end_kPStaticModules); ++staticModules)
|
||||
if (*staticModules) { // ASAN adds padding
|
||||
sStaticModules->AppendElement(*staticModules);
|
||||
}
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
}
|
||||
|
||||
nsTArray<nsComponentManagerImpl::ComponentLocation>*
|
||||
@@ -368,26 +376,35 @@ nsComponentManagerImpl::Init()
|
||||
// Initialize our arena
|
||||
PL_INIT_ARENA_POOL(&mArena, "ComponentManagerArena", NS_CM_BLOCK_SIZE);
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
nsCOMPtr<nsIFile> greDir =
|
||||
GetLocationFromDirectoryService(NS_GRE_DIR);
|
||||
nsCOMPtr<nsIFile> appDir =
|
||||
GetLocationFromDirectoryService(NS_XPCOM_CURRENT_PROCESS_DIR);
|
||||
#endif
|
||||
|
||||
InitializeStaticModules();
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
nsresult rv = mNativeModuleLoader.Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCategoryManager::GetSingleton()->SuppressNotifications(true);
|
||||
#endif
|
||||
|
||||
#if defined(MOZILLA_XPCOMRT_API)
|
||||
RegisterModule(&kXPCOMRTModule, nullptr);
|
||||
#else
|
||||
RegisterModule(&kXPCOMModule, nullptr);
|
||||
#endif // defined(MOZILLA_XPCOMRT_API)
|
||||
|
||||
for (uint32_t i = 0; i < sStaticModules->Length(); ++i) {
|
||||
RegisterModule((*sStaticModules)[i], nullptr);
|
||||
}
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
// The overall order in which chrome.manifests are expected to be treated
|
||||
// is the following:
|
||||
// - greDir
|
||||
@@ -432,6 +449,7 @@ nsComponentManagerImpl::Init()
|
||||
nsCategoryManager::GetSingleton()->SuppressNotifications(false);
|
||||
|
||||
RegisterWeakMemoryReporter(this);
|
||||
#endif
|
||||
|
||||
// Unfortunately, we can't register the nsCategoryManager memory reporter
|
||||
// in its constructor (which is triggered by the GetSingleton() call
|
||||
@@ -540,10 +558,12 @@ nsComponentManagerImpl::RegisterCIDEntryLocked(
|
||||
existing = "<unknown module>";
|
||||
}
|
||||
SafeMutexAutoUnlock unlock(mLock);
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
LogMessage("While registering XPCOM module %s, trying to re-register CID '%s' already registered by %s.",
|
||||
aModule->Description().get(),
|
||||
idstr,
|
||||
existing.get());
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -569,9 +589,11 @@ nsComponentManagerImpl::RegisterContractIDLocked(
|
||||
aEntry->cid->ToProvidedString(idstr);
|
||||
|
||||
SafeMutexAutoUnlock unlock(mLock);
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
LogMessage("Could not map contract ID '%s' to CID %s because no implementation of the CID is registered.",
|
||||
aEntry->contractid,
|
||||
idstr);
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -579,6 +601,7 @@ nsComponentManagerImpl::RegisterContractIDLocked(
|
||||
mContractIDs.Put(nsDependentCString(aEntry->contractid), f);
|
||||
}
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
static void
|
||||
CutExtension(nsCString& aPath)
|
||||
{
|
||||
@@ -821,10 +844,12 @@ nsComponentManagerImpl::RereadChromeManifests(bool aChromeOnly)
|
||||
RegisterManifest(l.type, l.location, aChromeOnly);
|
||||
}
|
||||
}
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
|
||||
bool
|
||||
nsComponentManagerImpl::KnownModule::EnsureLoader()
|
||||
{
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
if (!mLoader) {
|
||||
nsCString extension;
|
||||
mFile.GetURIString(extension);
|
||||
@@ -832,6 +857,7 @@ nsComponentManagerImpl::KnownModule::EnsureLoader()
|
||||
mLoader =
|
||||
nsComponentManagerImpl::gComponentManager->LoaderForExtension(extension);
|
||||
}
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
return !!mLoader;
|
||||
}
|
||||
|
||||
@@ -888,7 +914,9 @@ nsresult nsComponentManagerImpl::Shutdown(void)
|
||||
PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG,
|
||||
("nsComponentManager: Beginning Shutdown."));
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
UnregisterWeakMemoryReporter(this);
|
||||
#endif
|
||||
|
||||
// Release all cached factories
|
||||
mContractIDs.Clear();
|
||||
@@ -904,8 +932,10 @@ nsresult nsComponentManagerImpl::Shutdown(void)
|
||||
sXPTIInfosBook = nullptr;
|
||||
#endif
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
// Unload libraries
|
||||
mNativeModuleLoader.UnloadLibraries();
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
|
||||
// delete arena for strings and small objects
|
||||
PL_FinishArenaPool(&mArena);
|
||||
@@ -1589,6 +1619,7 @@ nsComponentManagerImpl::GetServiceByContractID(const char* aContractID,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
already_AddRefed<mozilla::ModuleLoader>
|
||||
nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
|
||||
{
|
||||
@@ -1605,6 +1636,7 @@ nsComponentManagerImpl::LoaderForExtension(const nsACString& aExt)
|
||||
|
||||
return loader.forget();
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::RegisterFactory(const nsCID& aClass,
|
||||
@@ -1677,8 +1709,12 @@ nsComponentManagerImpl::UnregisterFactory(const nsCID& aClass,
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::AutoRegister(nsIFile* aLocation)
|
||||
{
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
XRE_AddManifestLocation(NS_COMPONENT_LOCATION, aLocation);
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@@ -2014,6 +2050,7 @@ XRE_AddStaticComponent(const mozilla::Module* aComponent)
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::AddBootstrappedManifestLocation(nsIFile* aLocation)
|
||||
{
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
nsString path;
|
||||
nsresult rv = aLocation->GetPath(path);
|
||||
if (NS_FAILED(rv)) {
|
||||
@@ -2027,11 +2064,15 @@ nsComponentManagerImpl::AddBootstrappedManifestLocation(nsIFile* aLocation)
|
||||
nsCOMPtr<nsIFile> manifest =
|
||||
CloneAndAppend(aLocation, NS_LITERAL_CSTRING("chrome.manifest"));
|
||||
return XRE_AddManifestLocation(NS_BOOTSTRAPPED_LOCATION, manifest);
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::RemoveBootstrappedManifestLocation(nsIFile* aLocation)
|
||||
{
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
nsCOMPtr<nsIChromeRegistry> cr = mozilla::services::GetChromeRegistryService();
|
||||
if (!cr) {
|
||||
return NS_ERROR_FAILURE;
|
||||
@@ -2061,11 +2102,15 @@ nsComponentManagerImpl::RemoveBootstrappedManifestLocation(nsIFile* aLocation)
|
||||
|
||||
rv = cr->CheckForNewChrome();
|
||||
return rv;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComponentManagerImpl::GetManifestLocations(nsIArray** aLocations)
|
||||
{
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
NS_ENSURE_ARG_POINTER(aLocations);
|
||||
*aLocations = nullptr;
|
||||
|
||||
@@ -2089,6 +2134,9 @@ nsComponentManagerImpl::GetManifestLocations(nsIArray** aLocations)
|
||||
|
||||
locations.forget(aLocations);
|
||||
return NS_OK;
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
}
|
||||
|
||||
#ifdef MOZ_B2G_LOADER
|
||||
@@ -2137,6 +2185,7 @@ PreloadXPT(nsIFile* aOmnijarFile)
|
||||
|
||||
#endif /* MOZ_B2G_LOADER */
|
||||
|
||||
#if !defined(MOZILLA_XPCOMRT_API)
|
||||
EXPORT_XPCOM_API(nsresult)
|
||||
XRE_AddManifestLocation(NSLocationType aType, nsIFile* aLocation)
|
||||
{
|
||||
@@ -2177,4 +2226,5 @@ XRE_AddJarManifestLocation(NSLocationType aType, nsIFile* aLocation)
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
#endif // !defined(MOZILLA_XPCOMRT_API)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user