Bug 966467 - Allow static modules to choose whether to be loaded in content process (r=bsmedberg)

This commit is contained in:
Bill McCloskey 2014-02-09 16:11:37 -08:00
parent ab75b2309f
commit f457e42df0
2 changed files with 39 additions and 0 deletions

View File

@ -35,6 +35,17 @@ struct Module
typedef nsresult (*LoadFuncPtr)();
typedef void (*UnloadFuncPtr)();
/**
* This selector allows CIDEntrys to be marked so that they're only loaded
* into certain kinds of processes.
*/
enum ProcessSelector
{
ANY_PROCESS = 0,
MAIN_PROCESS_ONLY,
CONTENT_PROCESS_ONLY
};
/**
* The constructor callback is an implementation detail of the default binary
* loader and may be null.
@ -45,12 +56,14 @@ struct Module
bool service;
GetFactoryProcPtr getFactoryProc;
ConstructorProcPtr constructorProc;
ProcessSelector processSelector;
};
struct ContractIDEntry
{
const char* contractid;
nsID const * cid;
ProcessSelector processSelector;
};
struct CategoryEntry

View File

@ -429,6 +429,24 @@ nsComponentManagerImpl::RegisterModule(const mozilla::Module* aModule,
}
}
static bool
ProcessSelectorMatches(Module::ProcessSelector selector)
{
if (selector == Module::ANY_PROCESS) {
return true;
}
GeckoProcessType type = XRE_GetProcessType();
switch (selector) {
case Module::MAIN_PROCESS_ONLY:
return type == GeckoProcessType_Default;
case Module::CONTENT_PROCESS_ONLY:
return type == GeckoProcessType_Content;
default:
MOZ_CRASH("invalid process selector");
}
}
void
nsComponentManagerImpl::RegisterCIDEntryLocked(
const mozilla::Module::CIDEntry* aEntry,
@ -436,6 +454,10 @@ nsComponentManagerImpl::RegisterCIDEntryLocked(
{
mLock.AssertCurrentThreadOwns();
if (!ProcessSelectorMatches(aEntry->processSelector)) {
return;
}
nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
if (f) {
NS_WARNING("Re-registering a CID?");
@ -466,6 +488,10 @@ nsComponentManagerImpl::RegisterContractIDLocked(
{
mLock.AssertCurrentThreadOwns();
if (!ProcessSelectorMatches(aEntry->processSelector)) {
return;
}
nsFactoryEntry* f = mFactories.Get(*aEntry->cid);
if (!f) {
NS_ERROR("No CID found when attempting to map contract ID");