Bug 834106 - consolidate ClonedMessageData building code into MessageManagerCallback; r=smaug

This commit is contained in:
Nathan Froyd 2013-01-23 21:39:27 -05:00
Родитель 1f0dea6a9d
Коммит 157648b3fe
6 изменённых файлов: 98 добавлений и 103 удалений

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

@ -2248,30 +2248,10 @@ nsFrameLoader::DoSendAsyncMessage(const nsAString& aMessage,
PBrowserParent* tabParent = GetRemoteBrowser();
if (tabParent) {
ClonedMessageData data;
SerializedStructuredCloneBuffer& buffer = data.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
InfallibleTArray<PBlobParent*>& blobParents = data.blobsParent();
uint32_t length = blobs.Length();
blobParents.SetCapacity(length);
ContentParent* cp = static_cast<ContentParent*>(tabParent->Manager());
for (uint32_t i = 0; i < length; ++i) {
BlobParent* blobParent = cp->GetOrCreateActorForBlob(blobs[i]);
if (!blobParent) {
return false;
}
blobParents.AppendElement(blobParent);
}
ContentParent* cp = static_cast<ContentParent*>(tabParent->Manager());
if (!BuildClonedMessageDataForParent(cp, aData, data)) {
return false;
}
return tabParent->SendAsyncMessage(nsString(aMessage), data);
}

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

@ -119,6 +119,74 @@ NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameMessageManager)
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameMessageManager)
template<ActorFlavorEnum>
struct DataBlobs
{ };
template<>
struct DataBlobs<Parent>
{
typedef BlobTraits<Parent>::ProtocolType ProtocolType;
static InfallibleTArray<ProtocolType*>& Blobs(ClonedMessageData& aData)
{
return aData.blobsParent();
}
};
template<>
struct DataBlobs<Child>
{
typedef BlobTraits<Child>::ProtocolType ProtocolType;
static InfallibleTArray<ProtocolType*>& Blobs(ClonedMessageData& aData)
{
return aData.blobsChild();
}
};
template<ActorFlavorEnum Flavor>
static bool
BuildClonedMessageData(typename BlobTraits<Flavor>::ConcreteContentManagerType* aManager,
const StructuredCloneData& aData,
ClonedMessageData& aClonedData)
{
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
InfallibleTArray<ProtocolType*>& blobList = DataBlobs<Flavor>::Blobs(aClonedData);
uint32_t length = blobs.Length();
blobList.SetCapacity(length);
for (uint32_t i = 0; i < length; ++i) {
Blob<Flavor>* protocolActor = aManager->GetOrCreateActorForBlob(blobs[i]);
if (!protocolActor) {
return false;
}
blobList.AppendElement(protocolActor);
}
}
return true;
}
bool
MessageManagerCallback::BuildClonedMessageDataForParent(ContentParent* aParent,
const StructuredCloneData& aData,
ClonedMessageData& aClonedData)
{
return BuildClonedMessageData<Parent>(aParent, aData, aClonedData);
}
bool
MessageManagerCallback::BuildClonedMessageDataForChild(ContentChild* aChild,
const StructuredCloneData& aData,
ClonedMessageData& aClonedData)
{
return BuildClonedMessageData<Child>(aChild, aData, aClonedData);
}
// nsIMessageListenerManager
NS_IMETHODIMP
@ -1179,21 +1247,8 @@ public:
return true;
}
ClonedMessageData data;
SerializedStructuredCloneBuffer& buffer = data.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
InfallibleTArray<PBlobChild*>& blobChildList = data.blobsChild();
uint32_t length = blobs.Length();
blobChildList.SetCapacity(length);
for (uint32_t i = 0; i < length; ++i) {
BlobChild* blobChild = cc->GetOrCreateActorForBlob(blobs[i]);
if (!blobChild) {
return false;
}
blobChildList.AppendElement(blobChild);
}
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
return false;
}
return cc->SendSyncMessage(nsString(aMessage), data, aJSONRetVal);
}
@ -1207,21 +1262,8 @@ public:
return true;
}
ClonedMessageData data;
SerializedStructuredCloneBuffer& buffer = data.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
InfallibleTArray<PBlobChild*>& blobChildList = data.blobsChild();
uint32_t length = blobs.Length();
blobChildList.SetCapacity(length);
for (uint32_t i = 0; i < length; ++i) {
BlobChild* blobChild = cc->GetOrCreateActorForBlob(blobs[i]);
if (!blobChild) {
return false;
}
blobChildList.AppendElement(blobChild);
}
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
return false;
}
return cc->SendAsyncMessage(nsString(aMessage), data);
}

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

@ -1,4 +1,4 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
@ -26,7 +26,9 @@ namespace mozilla {
namespace dom {
class ContentParent;
class ContentChild;
struct StructuredCloneData;
class ClonedMessageData;
namespace ipc {
@ -76,6 +78,14 @@ public:
{
return false;
}
protected:
bool BuildClonedMessageDataForParent(ContentParent* aParent,
const StructuredCloneData& aData,
ClonedMessageData& aClonedData);
bool BuildClonedMessageDataForChild(ContentChild* aChild,
const StructuredCloneData& aData,
ClonedMessageData& aClonedData);
};
} // namespace ipc

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

@ -25,6 +25,10 @@ class nsIInputStream;
namespace mozilla {
namespace dom {
class ContentParent;
class ContentChild;
namespace ipc {
enum ActorFlavorEnum
@ -43,6 +47,7 @@ struct BlobTraits<Parent>
typedef mozilla::dom::PBlobParent ProtocolType;
typedef mozilla::dom::PBlobStreamParent StreamType;
typedef mozilla::dom::PContentParent ContentManagerType;
typedef mozilla::dom::ContentParent ConcreteContentManagerType;
typedef ProtocolType BlobManagerType;
// BaseType on the parent side is a bit more complicated than for the child
@ -83,6 +88,7 @@ struct BlobTraits<Child>
typedef mozilla::dom::PBlobChild ProtocolType;
typedef mozilla::dom::PBlobStreamChild StreamType;
typedef mozilla::dom::PContentChild ContentManagerType;
typedef mozilla::dom::ContentChild ConcreteContentManagerType;
typedef ProtocolType BlobManagerType;
class BaseType : public ProtocolType

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

@ -2323,23 +2323,9 @@ ContentParent::DoSendAsyncMessage(const nsAString& aMessage,
const mozilla::dom::StructuredCloneData& aData)
{
ClonedMessageData data;
SerializedStructuredCloneBuffer& buffer = data.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
InfallibleTArray<PBlobParent*>& blobParents = data.blobsParent();
uint32_t length = blobs.Length();
blobParents.SetCapacity(length);
for (uint32_t i = 0; i < length; ++i) {
BlobParent* blobParent = GetOrCreateActorForBlob(blobs[i]);
if (!blobParent) {
return false;
}
blobParents.AppendElement(blobParent);
}
if (!BuildClonedMessageDataForParent(this, aData, data)) {
return false;
}
return SendAsyncMessage(nsString(aMessage), data);
}

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

@ -2018,22 +2018,8 @@ TabChild::DoSendSyncMessage(const nsAString& aMessage,
{
ContentChild* cc = static_cast<ContentChild*>(Manager());
ClonedMessageData data;
SerializedStructuredCloneBuffer& buffer = data.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
InfallibleTArray<PBlobChild*>& blobChildList = data.blobsChild();
uint32_t length = blobs.Length();
blobChildList.SetCapacity(length);
for (uint32_t i = 0; i < length; ++i) {
BlobChild* blobChild = cc->GetOrCreateActorForBlob(blobs[i]);
if (!blobChild) {
return false;
}
blobChildList.AppendElement(blobChild);
}
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
return false;
}
return SendSyncMessage(nsString(aMessage), data, aJSONRetVal);
}
@ -2044,24 +2030,9 @@ TabChild::DoSendAsyncMessage(const nsAString& aMessage,
{
ContentChild* cc = static_cast<ContentChild*>(Manager());
ClonedMessageData data;
SerializedStructuredCloneBuffer& buffer = data.data();
buffer.data = aData.mData;
buffer.dataLength = aData.mDataLength;
const nsTArray<nsCOMPtr<nsIDOMBlob> >& blobs = aData.mClosure.mBlobs;
if (!blobs.IsEmpty()) {
InfallibleTArray<PBlobChild*>& blobChildList = data.blobsChild();
uint32_t length = blobs.Length();
blobChildList.SetCapacity(length);
for (uint32_t i = 0; i < length; ++i) {
BlobChild* blobChild = cc->GetOrCreateActorForBlob(blobs[i]);
if (!blobChild) {
return false;
}
blobChildList.AppendElement(blobChild);
}
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
return false;
}
return SendAsyncMessage(nsString(aMessage), data);
}