gecko/dom/ipc/此模块承担的工作是什么:
dom/ipc如下,每个ipdl文件对应3个头文件,

ipdl的生成文件,

几个类的继承关系
两个系列:PContent 和PNuwa,Process系,三个系
一 PContent系
PContent.ipdl生成三个文件:
objdir-gecko/ipc/ipdl/_ipdlheaders/mozilla/dom/PContent.h
objdir-gecko/ipc/ipdl/_ipdlheaders/mozilla/dom/PContentParent.h
objdir-gecko/ipc/ipdl/_ipdlheaders/mozilla/dom/PContentChild.h
dom/ipc/PContent.ipdl包罗万象,总之被另外两个自动生成的头文件继承实现了,之后,那两个头文件分别被手动写的实现文件继承。
乱七八糟。。。
ContentParnet.h
ContentChild.h
ContentProces.h是PContent.ipdl生成文件的继承后的实现?错,对了一部分。它只用了PContentChild.h部分,所以在Nuwa一侧?
关系,
(1)
PContent.ipdl
|
./ipc/ipdl/_ipdlheaders/mozilla/dom/PContentChild.h
#include "mozilla/dom/PContent.h"
#ifdef DEBUG
#include "prenv.h"
#endif // DEBUG
#include "base/id_map.h"
#include "mozilla/ipc/MessageChannel.h"
class PContentChild :
public mozilla::ipc::IProtocol,
protected mozilla::ipc::IProtocolManager<mozilla::ipc::IProtocol>,
public mozilla::ipc::IToplevelProtocol
{
friend class mozilla::media::PMediaChild;
|
dom/ipc/ContentChild.h
#include "mozilla/Attributes.h"
#include "mozilla/dom/ContentBridgeParent.h"
#include "mozilla/dom/nsIContentChild.h"
#include "mozilla/dom/PBrowserOrId.h"
#include "mozilla/dom/PContentChild.h"
#include "nsHashKeys.h"
#include "nsIObserver.h"
#include "nsTHashtable.h"
#include "nsWeakPtr.h"
#include "nsIWindowProvider.h"
class ContentChild final : public PContentChild
, public nsIWindowProvider
, public nsIContentChild
{
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
typedef mozilla::ipc::OptionalURIParams OptionalURIParams;
typedef mozilla::ipc::PFileDescriptorSetChild PFileDescriptorSetChild;
typedef mozilla::ipc::URIParams URIParams;
|
并列
gecko/ipc/glue/ProcessChild.h 单独用
#include "base/message_loop.h"
#include "base/process.h"
#include "chrome/common/child_process.h"
// ProcessChild is the base class for all subprocesses of the main
// browser process. Its code runs on the thread that started in
// main().
namespace mozilla {
namespace ipc {
class ProcessChild : public ChildProcess {
protected:
typedef base::ProcessId ProcessId;
public:
explicit ProcessChild(ProcessId aParentPid);
virtual ~ProcessChild();
virtual bool Init() = 0;
virtual void CleanUp()
{ }
static MessageLoop* message_loop() {
return gProcessChild->mUILoop;
}
protected:
static ProcessChild* current() {
return gProcessChild;
}
ProcessId ParentPid() {
return mParentPid;
}
private:
static ProcessChild* gProcessChild;
MessageLoop* mUILoop;
ProcessId mParentPid;
DISALLOW_EVIL_CONSTRUCTORS(ProcessChild);
};
} // namespace ipc
} // namespace mozilla
|
gecko/dom/ipc/ContentProces.h如下
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/ipc/ScopedXREEmbed.h"
#include "ContentChild.h"
namespace mozilla {
namespace dom {
/**
* ContentProcess is a singleton on the content process which represents
* the main thread where tab instances live.
*/
class ContentProcess : public mozilla::ipc::ProcessChild
{
typedef mozilla::ipc::ProcessChild ProcessChild;
public:
explicit ContentProcess(ProcessId aParentPid)
: ProcessChild(aParentPid)
{ }
~ContentProcess()
{ }
virtual bool Init() override;
virtual void CleanUp() override;
|
ContentProces.h是对ProcessChild.h,ContentChild.h"等的统合使用。
ContentProcess最后把Child支系的全收了,在此处进行大综合(即使用)。
目的是什么?gecko/ipc/glue/ProcessChild.h的作用是messageloop,获取当前线程ioloop等
ipdl的本质工作即是让parent端与child端能通信。相互搞些事情。
(2)
PContent.ipdl
|
./ipc/ipdl/_ipdlheaders/mozilla/dom/PContentParent.h
#include "mozilla/dom/PContent.h"
#ifdef DEBUG
#include "prenv.h"
#endif // DEBUG
#include "base/id_map.h"
#include "mozilla/ipc/MessageChannel.h"
c
namespace mozilla {
namespace dom {
class PContentParent :
public mozilla::ipc::IProtocol,
protected mozilla::ipc::IProtocolManager<mozilla::ipc::IProtocol>,
public mozilla::ipc::IToplevelProtocol
{
friend class mozilla::media::PMediaParent;
friend class mozilla::jsipc::PJavaScriptParent;
|
dom/ipc/ContentParent.h
#include "mozilla/dom/NuwaParent.h"
#include "mozilla/dom/PContentParent.h"
#include "mozilla/dom/nsIContentParent.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/Attributes.h"
#include "mozilla/FileUtils.h"
#include "mozilla/HalTypes.h"
#include "mozilla/LinkedList.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/UniquePtr.h"
#include "nsDataHashtable.h"
#include "nsFrameMessageManager.h"
#include "nsHashKeys.h"
#include "nsIObserver.h"
#include "nsIThreadInternal.h"
#include "nsIDOMGeoPositionCallback.h"
#include "nsIDOMGeoPositionErrorCallback.h"
#include "PermissionMessageUtils.h"
#include "DriverCrashGuard.h"
class ContentParent final : public PContentParent
, public nsIContentParent
, public nsIObserver
, public nsIDOMGeoPositionCallback
, public nsIDOMGeoPositionErrorCallback
, public mozilla::LinkedListElement<ContentParent>
{
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
typedef mozilla::ipc::OptionalURIParams OptionalURIParams;
typedef mozilla::ipc::PFileDescriptorSetParent PFileDescriptorSetParent;
typedef mozilla::ipc::TestShellParent TestShellParent;
typedef mozilla::ipc::URIParams URIParams;
typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
public:
#ifdef MOZ_NUWA_PROCESS
static int32_t NuwaPid() {
return sNuwaPid;
}
static bool IsNuwaReady() {
return sNuwaReady;
}
#endif
virtual bool IsContentParent() override { return true; }
/**
|
ContentParnet.h是对PNuwa系,PContent系中的引用,换句话说就是使用。,
下面是简洁版:
./ipc/ipdl/_ipdlheaders/mozilla/dom/PContent.h
//-----------------------------------------------------------------------------
// Code common to PContentChild and PContentParent
//
namespace mozilla {
namespace dom {
namespace PContent {
enum State {
__Dead,
__Null,
__Error,
__Dying,
__Start = __Null
};
enum MessageType {
PContentStart = PContentMsgStart << 16,
Msg_P.。。。
|
1.3w+行,,,,很多message 类型,很多类,,,声明等
(1)
PContent.ipdl
./ipc/ipdl/_ipdlheaders/mozilla/dom/PContentChild.h
class PContentChild :
public mozilla::ipc::IProtocol,
protected mozilla::ipc::IProtocolManager<mozilla::ipc::IProtocol>,
public mozilla::ipc::IToplevelProtocol
{
|
dom/ipc/ContentChild.h
class ContentChild final : public PContentChild
, public nsIWindowProvider
, public nsIContentChild
{ |
PContentChild > ContentChild
(2)
PContent.ipdl
./ipc/ipdl/_ipdlheaders/mozilla/dom/PContentParent.h
class PContentParent :
public mozilla::ipc::IProtocol,
protected mozilla::ipc::IProtocolManager<mozilla::ipc::IProtocol>,
public mozilla::ipc::IToplevelProtocol
{
|
dom/ipc/ContentParent.h
class ContentParent final : public PContentParent
, public nsIContentParent
, public nsIObserver
, public nsIDOMGeoPositionCallback
, public nsIDOMGeoPositionErrorCallback
, public mozilla::LinkedListElement<ContentParent>
{ |
PContentParent > ContentParent

二PNuwa系
PNuwa.ipdl系,生成三个头文件,其继承关系如下:
PNuwa.h
PNuwaParent.h
PNuwaChild.h
在NuwaParent.h NuwaChild.h里面来实现各接口的功能。
gecko/dom/ipc/PNuwa.ipdl
sync protocol PNuwa
{
manager PBackground;
child:
// Ask the Nuwa process to create a new child process.
async Fork();
// This message will be sent to non-Nuwa process, or to Nuwa process during
// test.
async __delete__();
parent:
async NotifyReady();
sync AddNewProcess(uint32_t pid, ProtocolFdMapping[] aFds);
};
|
./ipc/ipdl/_ipdlheaders/mozilla/dom/PNuwa.h 几个消息类型的类,其他ipdl文件也一样
▶ MessageType : enum
▶ State : enum
▶ Msg_AddNewProcess : class
▶ Msg_Fork : class
▶ Msg_NotifyReady : class
▶ Msg___delete__ : class
▶ Reply_AddNewProcess : class
▶ Reply___delete__ : class |
(1)
./ipc/ipdl/_ipdlheaders/mozilla/dom/PNuwaChild.h
#include "mozilla/dom/PNuwa.h"
#ifdef DEBUG
#include "prenv.h"
#endif // DEBUG
#include "base/id_map.h"
#include "mozilla/ipc/MessageChannel.h"
class PNuwaChild :
public mozilla::ipc::IProtocol,
protected mozilla::ipc::IProtocolManager<mozilla::ipc::IProtocol>
{
friend class mozilla::ipc::PBackgroundChild;
protected:
typedef mozilla::ipc::ActorHandle ActorHandle;.
。。。
virtual bool RecvFork() = 0;
virtual bool Recv__delete__();
virtual void ActorDestroy(ActorDestroyReason aWhy);
public:
。。。。
public:
MOZ_IMPLICIT PNuwaChild();
virtual ~PNuwaChild();
PBackgroundChild*
Manager() const;
PNuwa::State
state();
bool SendNotifyReady();
bool SendAddNewProcess(
const uint32_t& pid,
const nsTArray<ProtocolFdMapping>& aFds);
virtual int32_t
Registe。。。
|
gecko/dom/ipc/NuwaChild.h
#include "mozilla/Assertions.h"
#include "mozilla/dom/PNuwaChild.h"
#include "nsThreadUtils.h"
namespace mozilla {
namespace dom {
class NuwaChild: public mozilla::dom::PNuwaChild
{
public:
virtual bool RecvFork() override;
virtual void ActorDestroy(ActorDestroyReason aWhy) override
{ }
static NuwaChild* GetSingleton();
private:
static NuwaChild* sSingleton;
};
} // namespace dom
} // namespace mozilla
|
(2)
./ipc/ipdl/_ipdlheaders/mozilla/dom/PNuwaParent.h
#include "mozilla/dom/PNuwa.h"
#ifdef DEBUG
#include "prenv.h"
#endif // DEBUG
#include "base/id_map.h"
#include "mozilla/ipc/MessageChannel.h"
class PNuwaParent :
public mozilla::ipc::IProtocol,
protected mozilla::ipc::IProtocolManager<mozilla::ipc::IProtocol>
{
friend class mozilla::ipc::PBackgroundParent;
protected:
typedef mozilla::ipc::ActorHandle ActorHandle;
typedef mo
|
gecko/dom/ipc/NuwaParent .h对接口进行实现
#include "base/message_loop.h"
#include "mozilla/dom/PNuwaParent.h"
#include "...
namespace mozilla {
namespace dom {
class ContentParent;
class NuwaParent : public mozilla::dom::PNuwaParent
{
public:
explicit NuwaParent();
// Called on the main thread.
bool ForkNewProcess(uint32_t& aPid,
UniquePtr<nsTArray<ProtocolFdMapping>>&& aFds,
bool aBlocking);
// Called on the background thread.
bool ActorConstructed();
// Both the worker thread and the main thread hold a ref to this.
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NuwaParent)
// Functions to be invoked by the manager of this actor to alloc/dealloc the
// actor.
static NuwaParent* Alloc();
...
protected:
virtual ~NuwaParent();
virtual bool RecvNotifyReady() override;
virtual bool RecvAddNewProcess(const uint32_t& aPid,
nsTArray<ProtocolFdMapping>&& aFds) override;
virtual mozilla::ipc::IProtocol*
CloneProtocol(Channel* aChannel,
ProtocolCloneContext* aCtx) override;
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
private:
...
};
} // namespace dom
} // namespace mozilla
|
三Process 系
Process 系是对前面两个系的使用?没有ProcessParent,但承担此角色的可能是ProcessUtils_linux.h等?可能不是
gecko/ipc/chromium/src/chrome/common/child_process.h
// Base class for child processes of the browser process (i.e. renderer and
// plugin host). This is a singleton object for each child process.
class ChildProcess {
public:
// Child processes should have an object that derives from this class. The
// constructor will return once ChildThread has started.
explicit ChildProcess(ChildThread* child_thread);
virtual ~ChildProcess();
// Getter for this process' main thread.
ChildThread* child_thread() { return child_thread_.get(); }
// A global event object that is signalled when the main thread's message
// loop exits
|
gecko/ipc/glue/ProcessChild.h
#include "base/message_loop.h"
#include "base/process.h"
#include "chrome/common/child_process.h"
// ProcessChild is the base class for all subprocesses of the main
// browser process. Its code runs on the thread that started in
// main().
namespace mozilla {
namespace ipc {
class ProcessChild : public ChildProcess {
protected:
typedef base::ProcessId ProcessId;
public:
explicit ProcessChild(ProcessId aParentPid);
virtual ~ProcessChild();
。。。
|
gecko/dom/ipc/ContentProcess.h
/**
* ContentProcess is a singleton on the content process which represents
* the main thread where tab instances live.
*/
class ContentProcess : public mozilla::ipc::ProcessChild
{
typedef mozilla::ipc::ProcessChild ProcessChild;
public:
explicit ContentProcess(ProcessId aParentPid)
: ProcessChild(aParentPid)
{ }
~ContentProcess()
{ }
virtual bool Init() override;
virtual void CleanUp() override;
void SetAppDir(const nsACString& aPath);
private:
ContentChild mContent;
mozilla::ipc::ScopedXREEmbed mXREEmbed;
DISALLOW_EVIL_CONSTRUCTORS(ContentProcess);
};
|
gecko/ipc/glue/ProcessChild.cpp
创建实例时将同时创建io子线程,开启uimessageloop获取当前的消息循环队列,传入父id,
ProcessChild::ProcessChild(ProcessId aParentPid)
: ChildProcess(new IOThreadChild())
, mUILoop(MessageLoop::current())
, mParentPid(aParentPid)
{
MOZ_ASSERT(mUILoop, "UILoop should be created by now");
MOZ_ASSERT(!gProcessChild, "should only be one ProcessChild");
gProcessChild = this;
}
|
继承关系:ChildProcess > ProcessChild > ContentProcess
主要要看gecko/dom/ipc/ContentProcess.cpp。源码表明,其作用主要是初始化contentprocess进程,初始化xpcom,初始化显示设备数据。设置app目录。
void
ContentProcess::SetAppDir(const nsACString& aPath)
{
mXREEmbed.SetAppDir(aPath);
}
bool
ContentProcess::Init()
{
mContent.Init(IOThreadChild::message_loop(),
ParentPid(),
IOThreadChild::channel());
mXREEmbed.Start();
mContent.InitXPCOM();
mContent.InitGraphicsDeviceData();
#if defined(XP_WIN) && defined(MOZ_CONTENT_SANDBOX)
SetUpSandboxEnvironment();
#endif
return true;
}
|
三系的关系:没有关系?