Bug 771765 - Support template content process, part 4: Clone IPC protocol objects that will be up when the template process is ready. r=khuey, r=bent

This commit is contained in:
Thinker Lee ext:(%2C%20Cervantes%20Yu%20%3Ccyu%40mozilla.com%3E) 2013-06-03 18:14:37 +08:00
Родитель 42fe4d9b7d
Коммит 32bdb371af
23 изменённых файлов: 278 добавлений и 17 удалений

Просмотреть файл

@ -112,6 +112,24 @@ IndexedDBParent::CheckWritePermission(const nsAString& aDatabaseName)
return CheckPermissionInternal(aDatabaseName, permission);
}
mozilla::ipc::IProtocol*
IndexedDBParent::CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
MOZ_ASSERT(mManagerContent != nullptr);
MOZ_ASSERT(mManagerTab == nullptr);
MOZ_ASSERT(!mDisconnected);
MOZ_ASSERT(IndexedDatabaseManager::Get());
MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess());
ContentParent* contentParent = aCtx->GetContentParent();
nsAutoPtr<PIndexedDBParent> actor(contentParent->AllocPIndexedDBParent());
if (!actor || !contentParent->RecvPIndexedDBConstructor(actor)) {
return nullptr;
}
return actor.forget();
}
bool
IndexedDBParent::CheckPermissionInternal(const nsAString& aDatabaseName,
const nsDependentCString& aPermission)

Просмотреть файл

@ -194,6 +194,10 @@ public:
bool
CheckWritePermission(const nsAString& aDatabaseName);
mozilla::ipc::IProtocol*
CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
protected:
bool
CheckPermissionInternal(const nsAString& aDatabaseName,

Просмотреть файл

@ -39,6 +39,7 @@ class TestShellParent;
namespace jsipc {
class JavaScriptParent;
class PJavaScriptParent;
}
namespace layers {
@ -171,6 +172,39 @@ public:
*/
void FriendlyName(nsAString& aName);
virtual PIndexedDBParent* AllocPIndexedDBParent() MOZ_OVERRIDE;
virtual bool
RecvPIndexedDBConstructor(PIndexedDBParent* aActor) MOZ_OVERRIDE;
virtual PCrashReporterParent*
AllocPCrashReporterParent(const NativeThreadId& tid,
const uint32_t& processType) MOZ_OVERRIDE;
virtual bool
RecvPCrashReporterConstructor(PCrashReporterParent* actor,
const NativeThreadId& tid,
const uint32_t& processType) MOZ_OVERRIDE;
virtual PNeckoParent* AllocPNeckoParent() MOZ_OVERRIDE;
virtual bool RecvPNeckoConstructor(PNeckoParent* aActor) MOZ_OVERRIDE {
return PContentParent::RecvPNeckoConstructor(aActor);
}
virtual PHalParent* AllocPHalParent() MOZ_OVERRIDE;
virtual bool RecvPHalConstructor(PHalParent* aActor) MOZ_OVERRIDE {
return PContentParent::RecvPHalConstructor(aActor);
}
virtual PStorageParent* AllocPStorageParent() MOZ_OVERRIDE;
virtual bool RecvPStorageConstructor(PStorageParent* aActor) MOZ_OVERRIDE {
return PContentParent::RecvPStorageConstructor(aActor);
}
virtual PJavaScriptParent*
AllocPJavaScriptParent() MOZ_OVERRIDE;
virtual bool
RecvPJavaScriptConstructor(PJavaScriptParent* aActor) MOZ_OVERRIDE {
return PContentParent::RecvPJavaScriptConstructor(aActor);
}
protected:
void OnChannelConnected(int32_t pid) MOZ_OVERRIDE;
virtual void ActorDestroy(ActorDestroyReason why);
@ -262,7 +296,6 @@ private:
bool* aIsForBrowser) MOZ_OVERRIDE;
virtual bool RecvGetXPCOMProcessAttributes(bool* aIsOffline) MOZ_OVERRIDE;
virtual mozilla::jsipc::PJavaScriptParent* AllocPJavaScriptParent();
virtual bool DeallocPJavaScriptParent(mozilla::jsipc::PJavaScriptParent*);
virtual PBrowserParent* AllocPBrowserParent(const IPCTabContext& aContext,
@ -275,33 +308,21 @@ private:
virtual PBlobParent* AllocPBlobParent(const BlobConstructorParams& aParams);
virtual bool DeallocPBlobParent(PBlobParent*);
virtual PCrashReporterParent* AllocPCrashReporterParent(const NativeThreadId& tid,
const uint32_t& processType);
virtual bool DeallocPCrashReporterParent(PCrashReporterParent* crashreporter);
virtual bool RecvPCrashReporterConstructor(PCrashReporterParent* actor,
const NativeThreadId& tid,
const uint32_t& processType);
virtual bool RecvGetRandomValues(const uint32_t& length,
InfallibleTArray<uint8_t>* randomValues);
virtual PHalParent* AllocPHalParent() MOZ_OVERRIDE;
virtual bool DeallocPHalParent(PHalParent*) MOZ_OVERRIDE;
virtual PIndexedDBParent* AllocPIndexedDBParent();
virtual bool DeallocPIndexedDBParent(PIndexedDBParent* aActor);
virtual bool
RecvPIndexedDBConstructor(PIndexedDBParent* aActor);
virtual PMemoryReportRequestParent* AllocPMemoryReportRequestParent();
virtual bool DeallocPMemoryReportRequestParent(PMemoryReportRequestParent* actor);
virtual PTestShellParent* AllocPTestShellParent();
virtual bool DeallocPTestShellParent(PTestShellParent* shell);
virtual PNeckoParent* AllocPNeckoParent();
virtual bool DeallocPNeckoParent(PNeckoParent* necko);
virtual PExternalHelperAppParent* AllocPExternalHelperAppParent(
@ -320,7 +341,6 @@ private:
virtual PTelephonyParent* AllocPTelephonyParent();
virtual bool DeallocPTelephonyParent(PTelephonyParent*);
virtual PStorageParent* AllocPStorageParent();
virtual bool DeallocPStorageParent(PStorageParent* aActor);
virtual PBluetoothParent* AllocPBluetoothParent();

Просмотреть файл

@ -4,6 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "CrashReporterParent.h"
#include "mozilla/dom/ContentParent.h"
#include "nsXULAppAPI.h"
#include <time.h>
@ -29,6 +30,29 @@ CrashReporterParent::RecvAppendAppNotes(const nsCString& data)
return true;
}
mozilla::ipc::IProtocol*
CrashReporterParent::CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
ContentParent* contentParent = aCtx->GetContentParent();
CrashReporter::ThreadId childThreadId = contentParent->Pid();
GeckoProcessType childProcessType =
contentParent->Process()->GetProcessType();
nsAutoPtr<PCrashReporterParent> actor(
contentParent->AllocPCrashReporterParent(childThreadId,
childProcessType)
);
if (!actor ||
!contentParent->RecvPCrashReporterConstructor(actor,
childThreadId,
childThreadId)) {
return nullptr;
}
return actor.forget();
}
CrashReporterParent::CrashReporterParent()
:
#ifdef MOZ_CRASHREPORTER

Просмотреть файл

@ -80,6 +80,9 @@ public:
}
virtual bool
RecvAppendAppNotes(const nsCString& data);
virtual mozilla::ipc::IProtocol*
CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext *aCtx) MOZ_OVERRIDE;
#ifdef MOZ_CRASHREPORTER
AnnotationTable mNotes;

Просмотреть файл

@ -8,6 +8,7 @@
#include "DOMStorageManager.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/unused.h"
#include "nsIDiskSpaceWatcher.h"
#include "nsThreadUtils.h"
@ -364,6 +365,18 @@ DOMStorageDBParent::~DOMStorageDBParent()
}
}
mozilla::ipc::IProtocol*
DOMStorageDBParent::CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
ContentParent* contentParent = aCtx->GetContentParent();
nsAutoPtr<PStorageParent> actor(contentParent->AllocPStorageParent());
if (!actor || !contentParent->RecvPStorageConstructor(actor)) {
return nullptr;
}
return actor.forget();
}
DOMStorageDBParent::CacheParentBridge*
DOMStorageDBParent::NewCache(const nsACString& aScope)
{

Просмотреть файл

@ -112,6 +112,10 @@ public:
DOMStorageDBParent();
virtual ~DOMStorageDBParent();
virtual mozilla::ipc::IProtocol*
CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);

Просмотреть файл

@ -49,6 +49,7 @@
#include "mozilla/layers/CompositorD3D9.h"
#endif
#include "GeckoProfiler.h"
#include "mozilla/ipc/ProtocolTypes.h"
using namespace base;
using namespace mozilla;
@ -869,6 +870,12 @@ public:
{}
virtual ~CrossProcessCompositorParent();
// IToplevelProtocol::CloneToplevel()
virtual IToplevelProtocol*
CloneToplevel(const InfallibleTArray<mozilla::ipc::ProtocolFdMapping>& aFds,
base::ProcessHandle aPeerProcess,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
// FIXME/bug 774388: work out what shutdown protocol we need.
@ -931,6 +938,24 @@ CompositorParent::Create(Transport* aTransport, ProcessId aOtherProcess)
return true;
}
IToplevelProtocol*
CompositorParent::CloneToplevel(const InfallibleTArray<mozilla::ipc::ProtocolFdMapping>& aFds,
base::ProcessHandle aPeerProcess,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
for (unsigned int i = 0; i < aFds.Length(); i++) {
if (aFds[i].protocolId() == (unsigned)GetProtocolId()) {
Transport* transport = OpenDescriptor(aFds[i].fd(),
Transport::MODE_SERVER);
PCompositorParent* compositor = Create(transport, base::GetProcId(aPeerProcess));
compositor->CloneManagees(this, aCtx);
compositor->IToplevelProtocol::SetTransport(transport);
return compositor;
}
}
return nullptr;
}
static void
UpdateIndirectTree(uint64_t aId, Layer* aRoot, const TargetConfig& aTargetConfig)
{
@ -1030,5 +1055,24 @@ CrossProcessCompositorParent::~CrossProcessCompositorParent()
new DeleteTask<Transport>(mTransport));
}
IToplevelProtocol*
CrossProcessCompositorParent::CloneToplevel(const InfallibleTArray<mozilla::ipc::ProtocolFdMapping>& aFds,
base::ProcessHandle aPeerProcess,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
for (unsigned int i = 0; i < aFds.Length(); i++) {
if (aFds[i].protocolId() == (unsigned)GetProtocolId()) {
Transport* transport = OpenDescriptor(aFds[i].fd(),
Transport::MODE_SERVER);
PCompositorParent* compositor =
CompositorParent::Create(transport, base::GetProcId(aPeerProcess));
compositor->CloneManagees(this, aCtx);
compositor->IToplevelProtocol::SetTransport(transport);
return compositor;
}
}
return nullptr;
}
} // namespace layers
} // namespace mozilla

Просмотреть файл

@ -73,6 +73,12 @@ public:
virtual ~CompositorParent();
// IToplevelProtocol::CloneToplevel()
virtual IToplevelProtocol*
CloneToplevel(const InfallibleTArray<mozilla::ipc::ProtocolFdMapping>& aFds,
base::ProcessHandle aPeerProcess,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
virtual bool RecvWillStop() MOZ_OVERRIDE;
virtual bool RecvStop() MOZ_OVERRIDE;
virtual bool RecvPause() MOZ_OVERRIDE;

Просмотреть файл

@ -185,5 +185,23 @@ ImageBridgeParent::DeferredDestroy()
// |this| was just destroyed, hands off
}
IToplevelProtocol*
ImageBridgeParent::CloneToplevel(const InfallibleTArray<ProtocolFdMapping>& aFds,
base::ProcessHandle aPeerProcess,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
for (unsigned int i = 0; i < aFds.Length(); i++) {
if (aFds[i].protocolId() == (int)GetProtocolId()) {
Transport* transport = OpenDescriptor(aFds[i].fd(),
Transport::MODE_SERVER);
PImageBridgeParent* bridge = Create(transport, base::GetProcId(aPeerProcess));
bridge->CloneManagees(this, aCtx);
bridge->IToplevelProtocol::SetTransport(transport);
return bridge;
}
}
return nullptr;
}
} // layers
} // mozilla

Просмотреть файл

@ -88,6 +88,12 @@ public:
PImageBridgeParent::DeallocShmem(aShmem);
}
// Overriden from IToplevelProtocol
IToplevelProtocol*
CloneToplevel(const InfallibleTArray<ProtocolFdMapping>& aFds,
base::ProcessHandle aPeerProcess,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
private:
void DeferredDestroy();

Просмотреть файл

@ -7,6 +7,7 @@ include LayersSurfaces;
include LayersMessages;
include protocol PGrallocBuffer;
include protocol PCompositable;
include ProtocolTypes;
include "mozilla/layers/CompositorTypes.h";
include "mozilla/GfxMessageUtils.h";

Просмотреть файл

@ -7,6 +7,7 @@
#include "Hal.h"
#include "mozilla/AppProcessChecker.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/hal_sandbox/PHalChild.h"
#include "mozilla/hal_sandbox/PHalParent.h"
#include "mozilla/dom/TabParent.h"
@ -815,6 +816,18 @@ public:
hal::FactoryReset();
return true;
}
virtual mozilla::ipc::IProtocol*
CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE
{
ContentParent* contentParent = aCtx->GetContentParent();
nsAutoPtr<PHalParent> actor(contentParent->AllocPHalParent());
if (!actor || !contentParent->RecvPHalConstructor(actor)) {
return nullptr;
}
return actor.forget();
}
};
class HalChild : public PHalChild {

Просмотреть файл

@ -93,6 +93,10 @@ public:
return mChildProcessHandle;
}
GeckoProcessType GetProcessType() {
return mProcessType;
}
#ifdef XP_MACOSX
task_t GetChildTask() {
return mChildTask;

Просмотреть файл

@ -20,6 +20,7 @@
namespace mozilla {
namespace ipc {
class FileDescriptor;
typedef IPC::Channel Transport;
@ -29,6 +30,9 @@ bool CreateTransport(base::ProcessHandle aProcOne, base::ProcessHandle aProcTwo,
Transport* OpenDescriptor(const TransportDescriptor& aTd,
Transport::Mode aMode);
Transport* OpenDescriptor(const FileDescriptor& aFd,
Transport::Mode aMode);
void CloseDescriptor(const TransportDescriptor& aTd);
} // namespace ipc

Просмотреть файл

@ -12,6 +12,7 @@
#include "chrome/common/child_process_info.h"
#include "mozilla/ipc/Transport.h"
#include "mozilla/ipc/FileDescriptor.h"
using namespace base;
using namespace std;
@ -44,8 +45,8 @@ CreateTransport(ProcessHandle /*unused*/, ProcessHandle /*unused*/,
return false;
}
aOne->mFd = FileDescriptor(fd1, true/*close after sending*/);
aTwo->mFd = FileDescriptor(fd2, true/*close after sending*/);
aOne->mFd = base::FileDescriptor(fd1, true/*close after sending*/);
aTwo->mFd = base::FileDescriptor(fd2, true/*close after sending*/);
return true;
}
@ -55,6 +56,12 @@ OpenDescriptor(const TransportDescriptor& aTd, Transport::Mode aMode)
return new Transport(aTd.mFd.fd, aMode, nullptr);
}
Transport*
OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode)
{
return new Transport(aFd.PlatformHandle(), aMode, nullptr);
}
void
CloseDescriptor(const TransportDescriptor& aTd)
{

Просмотреть файл

@ -58,6 +58,13 @@ OpenDescriptor(const TransportDescriptor& aTd, Transport::Mode aMode)
return new Transport(aTd.mPipeName, aTd.mServerPipe, aMode, nullptr);
}
Transport*
OpenDescriptor(const FileDescriptor& aFd, Transport::Mode aMode)
{
NS_NOTREACHED("Not implemented!");
return nullptr;
}
void
CloseDescriptor(const TransportDescriptor& aTd)
{

Просмотреть файл

@ -19,6 +19,7 @@ using namespace js;
using namespace JS;
using namespace mozilla;
using namespace mozilla::jsipc;
using namespace mozilla::dom;
JavaScriptParent::JavaScriptParent()
: refcount_(1),
@ -683,3 +684,14 @@ JavaScriptParent::domInstanceOf(JSObject *obj, int prototypeID, int depth, bool
return true;
}
mozilla::ipc::IProtocol*
JavaScriptParent::CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx)
{
ContentParent *contentParent = aCtx->GetContentParent();
nsAutoPtr<PJavaScriptParent> actor(contentParent->AllocPJavaScriptParent());
if (!actor || !contentParent->RecvPJavaScriptConstructor(actor)) {
return nullptr;
}
return actor.forget();
}

Просмотреть файл

@ -77,6 +77,9 @@ class JavaScriptParent
static bool DOMInstanceOf(JSObject *obj, int prototypeID, int depth, bool *bp);
bool domInstanceOf(JSObject *obj, int prototypeID, int depth, bool *bp);
mozilla::ipc::IProtocol*
CloneProtocol(Channel* aChannel, ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
protected:
JSObject *unwrap(JSContext *cx, ObjectId objId);

Просмотреть файл

@ -127,6 +127,18 @@ CookieServiceParent::RecvSetCookieString(const URIParams& aHost,
return true;
}
mozilla::ipc::IProtocol*
CookieServiceParent::CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
NeckoParent* manager = aCtx->GetNeckoParent();
nsAutoPtr<PCookieServiceParent> actor(manager->AllocPCookieServiceParent());
if (!actor || !manager->RecvPCookieServiceConstructor(actor)) {
return nullptr;
}
return actor.forget();
}
}
}

Просмотреть файл

@ -43,6 +43,10 @@ protected:
const IPC::SerializedLoadContext&
loadContext) MOZ_OVERRIDE;
virtual mozilla::ipc::IProtocol*
CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
nsRefPtr<nsCookieService> mCookieService;
};

Просмотреть файл

@ -505,4 +505,24 @@ NeckoParent::RecvCancelHTMLDNSPrefetch(const nsString& hostname,
return true;
}
void
NeckoParent::CloneManagees(ProtocolBase* aSource,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
aCtx->SetNeckoParent(this); // For cloning protocols managed by this.
PNeckoParent::CloneManagees(aSource, aCtx);
}
mozilla::ipc::IProtocol*
NeckoParent::CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx)
{
ContentParent* contentParent = aCtx->GetContentParent();
nsAutoPtr<PNeckoParent> actor(contentParent->AllocPNeckoParent());
if (!actor || !contentParent->RecvPNeckoConstructor(actor)) {
return nullptr;
}
return actor.forget();
}
}} // mozilla::net

Просмотреть файл

@ -57,6 +57,16 @@ public:
const SerializedLoadContext& aSerialized,
nsCOMPtr<nsILoadContext> &aResult);
virtual void
CloneManagees(ProtocolBase* aSource,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
virtual PCookieServiceParent* AllocPCookieServiceParent() MOZ_OVERRIDE;
virtual bool
RecvPCookieServiceConstructor(PCookieServiceParent* aActor) MOZ_OVERRIDE
{
return PNeckoParent::RecvPCookieServiceConstructor(aActor);
}
protected:
virtual PHttpChannelParent*
AllocPHttpChannelParent(PBrowserParent*, const SerializedLoadContext&,
@ -68,7 +78,6 @@ protected:
const SerializedLoadContext& aSerialized,
const HttpChannelCreationArgs& aOpenArgs);
virtual bool DeallocPHttpChannelParent(PHttpChannelParent*);
virtual PCookieServiceParent* AllocPCookieServiceParent();
virtual bool DeallocPCookieServiceParent(PCookieServiceParent*);
virtual PWyciwygChannelParent* AllocPWyciwygChannelParent();
virtual bool DeallocPWyciwygChannelParent(PWyciwygChannelParent*);
@ -112,6 +121,11 @@ protected:
virtual bool RecvCancelHTMLDNSPrefetch(const nsString& hostname,
const uint16_t& flags,
const nsresult& reason);
virtual mozilla::ipc::IProtocol*
CloneProtocol(Channel* aChannel,
mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE;
private:
nsCString mCoreAppsBasePath;
nsCString mWebAppsBasePath;