B2G/gecko/xpcom/build/XPCOM.h
B2G/gecko/xpcom/build/XPCOMInit.cpp
B2G/gecko/xpcom/components/nsComponentManager.h
B2G/gecko/xpcom/glue/nsServiceManagerUtils.h
B2G/gecko/xpcom/glue/standalone/nsXPCOMGlue.cpp
B2G/gecko/xpcom/io/nsDirectoryServiceUtils.h
B2G/gecko/xpcom/io/nsLocalFileCommon.cpp
B2G/gecko/xpcom/io/nsUnicharInputStream.cpp
B2G/gecko/xpcom/reflect/xptinfo/xptiprivate.h
B2G/gecko/xpcom/threads/TimerThread.cpp
B2G/gecko/xpfe/appshell/nsAppShellService.cpp
B2G/gecko/xpfe/appshell/nsChromeTreeOwner.cpp
B2G/gecko/xpfe/appshell/nsContentTreeOwner.cpp
B2G/gecko/xpfe/appshell/nsWebShellWindow.cpp
B2G/gecko/xpfe/appshell/nsWindowMediator.cpp
B2G/gecko/xpfe/appshell/nsXULWindow.cpp
B2G/gecko/xpfe/components/directory/nsDirectoryViewer.cpp
B2G/gecko/xpfe/components/windowds/nsWindowDataSource.cpp
gecko/xpcom/components/nsComponentManager.h(/.cpp 省略2000lines)
#ifndef nsComponentManager_h__
#define nsComponentManager_h__
#include "nsXPCOM.h"
#include "xpcom-private.h"
#include "nsIComponentManager.h"
#include "nsIComponentRegistrar.h"
#include "nsIMemoryReporter.h"
#include "nsIServiceManager.h"
#include "nsIFile.h"
#include "mozilla/Atomics.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/Module.h"
#include "mozilla/ModuleLoader.h"
#include "mozilla/Mutex.h"
#include "nsXULAppAPI.h"
#include "nsNativeModuleLoader.h"
#include "nsIFactory.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "PLDHashTable.h"
#include "prtime.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsWeakReference.h"
#include "plarena.h"
#include "nsCOMArray.h"
#include "nsDataHashtable.h"
#include "nsInterfaceHashtable.h"
#include "nsClassHashtable.h"
#include "nsTArray.h"
#include "mozilla/Omnijar.h"
#include "mozilla/Attributes.h"
#ifdef MOZ_B2G_LOADER
#include "mozilla/FileLocation.h"
#endif
struct nsFactoryEntry;
class nsIServiceManager;
struct PRThread;
#define NS_COMPONENTMANAGER_CID \
{ /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
0x91775d60, \
0xd5dc, \
0x11d2, \
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
}
/* keys for registry use */
extern const char xpcomKeyName[];
extern const char xpcomComponentsKeyName[];
extern const char lastModValueName[];
extern const char fileSizeValueName[];
extern const char nativeComponentType[];
extern const char staticComponentType[];
#ifdef DEBUG
#define XPCOM_CHECK_PENDING_CIDS
#endif
#if defined(MOZILLA_XPCOMRT_API)
extern const mozilla::Module kXPCOMRTModule;
extern const mozilla::Module kNeckoStandaloneModule;
extern const mozilla::Module kStunUDPSocketFilterHandlerModule;
#else
extern const mozilla::Module kXPCOMModule;
#endif
/**
* This is a wrapper around mozilla::Mutex which provides runtime
* checking for a deadlock where the same thread tries to lock a mutex while
* it is already locked. This checking is present in both debug and release
* builds.
*/
class SafeMutex
{
public:
explicit SafeMutex(const char* aName)
: mMutex(aName)
, mOwnerThread(nullptr)
{
}
~SafeMutex() {}
void Lock()
{
AssertNotCurrentThreadOwns();
mMutex.Lock();
MOZ_ASSERT(mOwnerThread == nullptr);
mOwnerThread = PR_GetCurrentThread();
}
void Unlock()
{
MOZ_ASSERT(mOwnerThread == PR_GetCurrentThread());
mOwnerThread = nullptr;
mMutex.Unlock();
}
void AssertCurrentThreadOwns() const
{
// This method is a debug-only check
MOZ_ASSERT(mOwnerThread == PR_GetCurrentThread());
}
MOZ_NEVER_INLINE void AssertNotCurrentThreadOwns() const
{
// This method is a release-mode check
if (PR_GetCurrentThread() == mOwnerThread) {
MOZ_CRASH();
}
}
private:
mozilla::Mutex mMutex;
mozilla::Atomic<PRThread*, mozilla::Relaxed> mOwnerThread;
};
typedef mozilla::BaseAutoLock<SafeMutex> SafeMutexAutoLock;
typedef mozilla::BaseAutoUnlock<SafeMutex> SafeMutexAutoUnlock;
class nsComponentManagerImpl final
: public nsIComponentManager
, public nsIServiceManager
, public nsSupportsWeakReference
, public nsIComponentRegistrar
, public nsIInterfaceRequestor
, public nsIMemoryReporter
{
public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSICOMPONENTMANAGER
NS_DECL_NSICOMPONENTREGISTRAR
NS_DECL_NSIMEMORYREPORTER
static nsresult Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);
nsresult RegistryLocationForFile(nsIFile* aFile,
nsCString& aResult);
nsresult FileForRegistryLocation(const nsCString& aLocation,
nsIFile** aSpec);
NS_DECL_NSISERVICEMANAGER
// nsComponentManagerImpl methods:
nsComponentManagerImpl();
static nsComponentManagerImpl* gComponentManager;
nsresult Init();
nsresult Shutdown(void);
nsresult FreeServices();
already_AddRefed<mozilla::ModuleLoader> LoaderForExtension(const nsACString& aExt);
nsInterfaceHashtable<nsCStringHashKey, mozilla::ModuleLoader> mLoaderMap;
already_AddRefed<nsIFactory> FindFactory(const nsCID& aClass);
already_AddRefed<nsIFactory> FindFactory(const char* aContractID,
uint32_t aContractIDLen);
already_AddRefed<nsIFactory> LoadFactory(nsFactoryEntry* aEntry);
nsFactoryEntry* GetFactoryEntry(const char* aContractID,
uint32_t aContractIDLen);
nsFactoryEntry* GetFactoryEntry(const nsCID& aClass);
nsDataHashtable<nsIDHashKey, nsFactoryEntry*> mFactories;
nsDataHashtable<nsCStringHashKey, nsFactoryEntry*> mContractIDs;
SafeMutex mLock;
static void InitializeStaticModules();
static void InitializeModuleLocations();
struct ComponentLocation
{
NSLocationType type;
mozilla::FileLocation location;
};
class ComponentLocationComparator
{
public:
bool Equals(const ComponentLocation& aA, const ComponentLocation& aB) const
{
return (aA.type == aB.type && aA.location.Equals(aB.location));
}
};
static nsTArray<const mozilla::Module*>* sStaticModules;
static nsTArray<ComponentLocation>* sModuleLocations;
nsNativeModuleLoader mNativeModuleLoader;
class KnownModule
{
public:
/**
* Static or binary module.
*/
KnownModule(const mozilla::Module* aModule, mozilla::FileLocation& aFile)
: mModule(aModule)
, mFile(aFile)
, mLoaded(false)
, mFailed(false)
{
}
explicit KnownModule(const mozilla::Module* aModule)
: mModule(aModule)
, mLoaded(false)
, mFailed(false)
{
}
explicit KnownModule(mozilla::FileLocation& aFile)
: mModule(nullptr)
, mFile(aFile)
, mLoader(nullptr)
, mLoaded(false)
, mFailed(false)
{
}
~KnownModule()
{
if (mLoaded && mModule->unloadProc) {
mModule->unloadProc();
}
}
bool EnsureLoader();
bool Load();
const mozilla::Module* Module() const { return mModule; }
/**
* For error logging, get a description of this module, either the
* file path, or <static module>.
*/
nsCString Description() const;
private:
const mozilla::Module* mModule;
mozilla::FileLocation mFile;
nsCOMPtr<mozilla::ModuleLoader> mLoader;
bool mLoaded;
bool mFailed;
};
// The KnownModule is kept alive by these members, it is
// referenced by pointer from the factory entries.
nsTArray<nsAutoPtr<KnownModule>> mKnownStaticModules;
// The key is the URI string of the module
nsClassHashtable<nsCStringHashKey, KnownModule> mKnownModules;
// Mutex not held
void RegisterModule(const mozilla::Module* aModule,
mozilla::FileLocation* aFile);
// Mutex held
void RegisterCIDEntryLocked(const mozilla::Module::CIDEntry* aEntry,
KnownModule* aModule);
void RegisterContractIDLocked(const mozilla::Module::ContractIDEntry* aEntry);
// Mutex not held
void RegisterManifest(NSLocationType aType, mozilla::FileLocation& aFile,
bool aChromeOnly);
struct ManifestProcessingContext
{
ManifestProcessingContext(NSLocationType aType,
mozilla::FileLocation& aFile, bool aChromeOnly)
: mType(aType)
, mFile(aFile)
, mChromeOnly(aChromeOnly)
{
}
~ManifestProcessingContext() {}
NSLocationType mType;
mozilla::FileLocation mFile;
bool mChromeOnly;
};
void ManifestManifest(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void ManifestBinaryComponent(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void ManifestXPT(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void ManifestComponent(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void ManifestContract(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void ManifestCategory(ManifestProcessingContext& aCx, int aLineNo,
char* const* aArgv);
void RereadChromeManifests(bool aChromeOnly = true);
// Shutdown
enum
{
NOT_INITIALIZED,
NORMAL,
SHUTDOWN_IN_PROGRESS,
SHUTDOWN_COMPLETE
} mStatus;
PLArenaPool mArena;
struct PendingServiceInfo
{
const nsCID* cid;
PRThread* thread;
};
inline PendingServiceInfo* AddPendingService(const nsCID& aServiceCID,
PRThread* aThread);
inline void RemovePendingService(const nsCID& aServiceCID);
inline PRThread* GetPendingServiceThread(const nsCID& aServiceCID) const;
nsTArray<PendingServiceInfo> mPendingServices;
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
#ifdef MOZ_B2G_LOADER
// Preload XPT interface info for B2G loader.
// This function is called before XPCOM has been initialized.
static void PreloadXPT(nsIFile* aFile);
#endif
#ifdef MOZ_B2G_LOADER
// Parsing functions of directives of manifest for XPT only parsing.
struct XPTOnlyManifestProcessingContext
{
XPTOnlyManifestProcessingContext(mozilla::FileLocation& aFile)
: mFile(aFile)
{
}
~XPTOnlyManifestProcessingContext() {}
mozilla::FileLocation mFile;
};
static void XPTOnlyManifestManifest(XPTOnlyManifestProcessingContext& aCx,
int aLineNo, char* const* aArgv);
static void XPTOnlyManifestXPT(XPTOnlyManifestProcessingContext& aCx,
int aLineNo, char* const* aArgv);
#endif
private:
~nsComponentManagerImpl();
};
#define NS_MAX_FILENAME_LEN 1024
#define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
struct nsFactoryEntry
{
nsFactoryEntry(const mozilla::Module::CIDEntry* aEntry,
nsComponentManagerImpl::KnownModule* aModule);
// nsIComponentRegistrar.registerFactory support
nsFactoryEntry(const nsCID& aClass, nsIFactory* aFactory);
~nsFactoryEntry();
already_AddRefed<nsIFactory> GetFactory();
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf);
const mozilla::Module::CIDEntry* mCIDEntry;
nsComponentManagerImpl::KnownModule* mModule;
nsCOMPtr<nsIFactory> mFactory;
nsCOMPtr<nsISupports> mServiceObject;
};
#endif // nsComponentManager_h__
...
gecko/xpcom/glue/nsServiceManagerUtils.h
#ifndef nsServiceManagerUtils_h__
#define nsServiceManagerUtils_h__
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
inline const nsGetServiceByCID
do_GetService(const nsCID& aCID)
{
return nsGetServiceByCID(aCID);
}
inline const nsGetServiceByCIDWithError
do_GetService(const nsCID& aCID, nsresult* aError)
{
return nsGetServiceByCIDWithError(aCID, aError);
}
inline const nsGetServiceByContractID
do_GetService(const char* aContractID)
{
return nsGetServiceByContractID(aContractID);
}
inline const nsGetServiceByContractIDWithError
do_GetService(const char* aContractID, nsresult* aError)
{
return nsGetServiceByContractIDWithError(aContractID, aError);
}
class MOZ_STACK_CLASS nsGetServiceFromCategory final : public nsCOMPtr_helper
{
public:
nsGetServiceFromCategory(const char* aCategory, const char* aEntry,
nsresult* aErrorPtr)
: mCategory(aCategory)
, mEntry(aEntry)
, mErrorPtr(aErrorPtr)
{
}
virtual nsresult NS_FASTCALL operator()(const nsIID&, void**) const
override;
protected:
const char* mCategory;
const char* mEntry;
nsresult* mErrorPtr;
};
inline const nsGetServiceFromCategory
do_GetServiceFromCategory(const char* aCategory, const char* aEntry,
nsresult* aError = 0)
{
return nsGetServiceFromCategory(aCategory, aEntry, aError);
}
nsresult CallGetService(const nsCID& aClass, const nsIID& aIID, void** aResult);
nsresult CallGetService(const char* aContractID, const nsIID& aIID,
void** aResult);
// type-safe shortcuts for calling |GetService|
template<class DestinationType>
inline nsresult
CallGetService(const nsCID& aClass,
DestinationType** aDestination)
{
NS_PRECONDITION(aDestination, "null parameter");
return CallGetService(aClass,
NS_GET_TEMPLATE_IID(DestinationType),
reinterpret_cast<void**>(aDestination));
}
template<class DestinationType>
inline nsresult
CallGetService(const char* aContractID,
DestinationType** aDestination)
{
NS_PRECONDITION(aContractID, "null parameter");
NS_PRECONDITION(aDestination, "null parameter");
return CallGetService(aContractID,
NS_GET_TEMPLATE_IID(DestinationType),
reinterpret_cast<void**>(aDestination));
}
#endif
rv = mScopedXPCOM->Initialize()--->
gecko/toolkit/xre/nsAppRunner.cpp:1571, Fuc:Initialize ----------------------------------
gecko/toolkit/xre/nsAppRunner.cpp:1575, Fuc:Initialize ---here ,startup xpcom---
gecko/toolkit/xre/nsAppRunner.cpp:1576, Fuc:Initialize ScopedXPCOMStartup::Initialize,call NS_InitXPCOM2-->
gecko/xpcom/build/XPCOMInit.cpp:512, Fuc:NS_InitXPCOM2 ----------------------------------
gecko/xpcom/build/XPCOMInit.cpp:513, Fuc:NS_InitXPCOM2 the whole process: main()->RunProcesses()->b2g_main()->do_main()->XRE_main->ScopedXPCOMStartup::Initialize()->NS_InitXPCOM2()
gecko/xpcom/build/XPCOMInit.cpp:514, Fuc:NS_InitXPCOM2 ----------------------------------
gecko/xpcom/build/XPCOMInit.cpp:560, Fuc:NS_InitXPCOM2 MessageLoop::current = false
gecko/xpcom/build/XPCOMInit.cpp:570, Fuc:NS_InitXPCOM2 in XRE_IsParentProcess io thread for what?---
gecko/xpcom/build/XPCOMInit.cpp:583, Fuc:NS_InitXPCOM2 Establish the main thread here.
gecko/xpcom/build/XPCOMInit.cpp:584, Fuc:NS_InitXPCOM2 rv = nsThreadManager::get()->Init()--->
gecko/xpcom/build/XPCOMInit.cpp:607, Fuc:NS_InitXPCOM2 call NS_StartupLocalFile()--->
gecko/xpcom/build/XPCOMInit.cpp:618, Fuc:NS_InitXPCOM2 aBinDirectory = true --
gecko/xpcom/build/XPCOMInit.cpp:626, Fuc:NS_InitXPCOM2 aAppFileLocationProvider = true,call RegisterProvider()-->
gecko/xpcom/build/XPCOMInit.cpp:634, Fuc:NS_InitXPCOM2 nsDirectoryService::gService->Get()--->
gecko/xpcom/build/XPCOMInit.cpp:646, Fuc:NS_InitXPCOM2 nsDirectoryService::gService->Set(NS_XPCOM_LIBRARY_FILE, xpcomLib)-->
gecko/xpcom/build/XPCOMInit.cpp:650, Fuc:NS_InitXPCOM2 mozilla::Omnijar::IsInitialized = false,call mozilla::Omnijar::Init()--->
gecko/xpcom/build/XPCOMInit.cpp:689, Fuc:NS_InitXPCOM2 Create the Component/Service Manage----
gecko/xpcom/build/XPCOMInit.cpp:690, Fuc:NS_InitXPCOM2 nsComponentManagerImpl::gComponentManager = new nsComponentManagerImpl()--->
gecko/xpcom/build/XPCOMInit.cpp:700, Fuc:NS_InitXPCOM2 call nsCycleCollector_startup()--->
gecko/xpcom/build/XPCOMInit.cpp:737, Fuc:NS_InitXPCOM2 ----- Initialize the JS engine -----
gecko/xpcom/build/XPCOMInit.cpp:738, Fuc:NS_InitXPCOM2 if (!JS_Init()),call JS_Init()--->
gecko/xpcom/build/XPCOMInit.cpp:742, Fuc:NS_InitXPCOM2 call rv = nsComponentManagerImpl::gComponentManager->Init()--->
gecko/xpcom/build/XPCOMInit.cpp:755, Fuc:NS_InitXPCOM2 The iimanager constructor searches and registers XPT files.---
gecko/xpcom/build/XPCOMInit.cpp:756, Fuc:NS_InitXPCOM2 (void)XPTInterfaceInfoManager::GetSingleton()--->
gecko/xpcom/build/XPCOMInit.cpp:762, Fuc:NS_InitXPCOM2 nsDirectoryService::gService->RegisterCategoryProviders()-->
gecko/xpcom/build/XPCOMInit.cpp:766, Fuc:NS_InitXPCOM2 init SharedThreadPool ,by call SharedThreadPool::InitStatics()--->
gecko/xpcom/build/XPCOMInit.cpp:770, Fuc:NS_InitXPCOM2 AbstractThread::InitStatics()--->
gecko/xpcom/build/XPCOMInit.cpp:775, Fuc:NS_InitXPCOM2 do_GetService of jsloader----
gecko/xpcom/build/XPCOMInit.cpp:776, Fuc:NS_InitXPCOM2 componentLoader = do_GetService('@mozilla.org/moz/jsloader;1')--->
gecko/xpcom/build/XPCOMInit.cpp:784, Fuc:NS_InitXPCOM2 // Notify observers of xpcom autoregistration star//
gecko/xpcom/build/XPCOMInit.cpp:785, Fuc:NS_InitXPCOM2 NS_CreateServicesFromCategory(NS_XPCOM_STARTUP_CATEGORY,nullptr,NS_XPCOM_STARTUP_OBSERVER_ID) --->
gecko/xpcom/build/XPCOMInit.cpp:797, Fuc:NS_InitXPCOM2 XRE_IsParentProcess =true,call mozilla::SystemMemoryReporter::Init()--->
gecko/xpcom/build/XPCOMInit.cpp:811, Fuc:NS_InitXPCOM2 mozilla::Telemetry::Init()--->
gecko/xpcom/build/XPCOMInit.cpp:813, Fuc:NS_InitXPCOM2 mozilla::HangMonitor::Startup()--->
gecko/xpcom/build/XPCOMInit.cpp:815, Fuc:NS_InitXPCOM2 mozilla::BackgroundHangMonitor::Startup()--->
gecko/xpcom/build/XPCOMInit.cpp:817, Fuc:NS_InitXPCOM2 const MessageLoop* const loop = MessageLoop::current()--->
gecko/xpcom/build/XPCOMInit.cpp:819, Fuc:NS_InitXPCOM2 sMainHangMonitor = new mozilla::BackgroundHangMonitor(loop->thread_name().c_str(),loop->transient_hang_timeout(),loop->permanent_hang_timeout())