Bug 613442, part 4: Library support of |opens| API. r=bent

This commit is contained in:
Chris Jones 2011-06-03 13:33:56 -05:00
parent cc130518ca
commit 109cb23caa
2 changed files with 42 additions and 1 deletions

View File

@ -45,6 +45,7 @@
#include "mozilla/ipc/Transport.h"
using namespace base;
using namespace IPC;
namespace mozilla {
namespace ipc {
@ -111,9 +112,44 @@ Bridge(const PrivateIPDLInterface&,
return true;
}
bool
Open(const PrivateIPDLInterface&,
AsyncChannel* aOpenerChannel, ProcessHandle aOtherProcess,
Transport::Mode aOpenerMode,
ProtocolId aProtocol)
{
bool isParent = (Transport::MODE_SERVER == aOpenerMode);
ProcessHandle thisHandle = GetCurrentProcessHandle();
ProcessHandle parentHandle = isParent ? thisHandle : aOtherProcess;
ProcessHandle childHandle = !isParent ? thisHandle : aOtherProcess;
ProcessId parentId = GetProcId(parentHandle);
ProcessId childId = GetProcId(childHandle);
if (!parentId || !childId) {
return false;
}
TransportDescriptor parentSide, childSide;
if (!CreateTransport(parentHandle, childHandle,
&parentSide, &childSide)) {
return false;
}
Message* parentMsg = new ChannelOpened(parentSide, childId, aProtocol);
Message* childMsg = new ChannelOpened(childSide, parentId, aProtocol);
nsAutoPtr<Message> messageForUs(isParent ? parentMsg : childMsg);
nsAutoPtr<Message> messageForOtherSide(!isParent ? parentMsg : childMsg);
if (!aOpenerChannel->Echo(messageForUs.forget()) ||
!aOpenerChannel->Send(messageForOtherSide.forget())) {
CloseDescriptor(parentSide);
CloseDescriptor(childSide);
return false;
}
return true;
}
bool
UnpackChannelOpened(const PrivateIPDLInterface&,
const IPC::Message& aMsg,
const Message& aMsg,
TransportDescriptor* aTransport,
ProcessId* aOtherProcess,
ProtocolId* aProtocol)

View File

@ -153,6 +153,11 @@ Bridge(const PrivateIPDLInterface&,
AsyncChannel*, base::ProcessHandle, AsyncChannel*, base::ProcessHandle,
ProtocolId);
bool
Open(const PrivateIPDLInterface&,
AsyncChannel*, base::ProcessHandle, Transport::Mode,
ProtocolId);
bool
UnpackChannelOpened(const PrivateIPDLInterface&,
const IPC::Message&,