зеркало из https://github.com/mozilla/gecko-dev.git
Backout 1391e924e9ee (bug 806503) for mochitest-1 failures on a CLOSED TREE
This commit is contained in:
Родитель
57ae058d44
Коммит
2e694dc42e
|
@ -48,8 +48,6 @@ public:
|
|||
virtual const nsTArray<nsCOMPtr<nsIDOMBlob> >*
|
||||
GetSubBlobs() const { return nullptr; }
|
||||
|
||||
virtual bool IsMemoryBacked() const { return false; }
|
||||
|
||||
NS_DECL_NSIDOMBLOB
|
||||
NS_DECL_NSIDOMFILE
|
||||
NS_DECL_NSIXHRSENDABLE
|
||||
|
@ -352,9 +350,8 @@ public:
|
|||
nsDOMMemoryFile(void *aMemoryBuffer,
|
||||
uint64_t aLength,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType,
|
||||
uint64_t aModDate = UINT64_MAX)
|
||||
: nsDOMFile(aName, aContentType, aLength, aModDate),
|
||||
const nsAString& aContentType)
|
||||
: nsDOMFile(aName, aContentType, aLength, UINT64_MAX),
|
||||
mDataOwner(new DataOwner(aMemoryBuffer, aLength))
|
||||
{
|
||||
NS_ASSERTION(mDataOwner && mDataOwner->mData, "must have data");
|
||||
|
@ -372,10 +369,6 @@ public:
|
|||
|
||||
NS_IMETHOD GetInternalStream(nsIInputStream**);
|
||||
|
||||
virtual bool IsMemoryBacked() const { return true; }
|
||||
void* GetData() const { return mDataOwner->mData; }
|
||||
uint64_t GetLength() const { return mDataOwner->mLength; }
|
||||
|
||||
protected:
|
||||
// Create slice
|
||||
nsDOMMemoryFile(const nsDOMMemoryFile* aOther, uint64_t aStart,
|
||||
|
|
|
@ -145,7 +145,7 @@ nsDOMMultipartFile::CreateSlice(uint64_t aStart, uint64_t aLength,
|
|||
nsDOMMultipartFile::NewFile(const nsAString& aName, nsISupports* *aNewObject)
|
||||
{
|
||||
nsCOMPtr<nsISupports> file =
|
||||
do_QueryObject(new nsDOMMultipartFile(aName, EmptyString()));
|
||||
do_QueryObject(new nsDOMMultipartFile(aName));
|
||||
file.forget(aNewObject);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ nsDOMMultipartFile::NewFile(const nsAString& aName, nsISupports* *aNewObject)
|
|||
/* static */ nsresult
|
||||
nsDOMMultipartFile::NewBlob(nsISupports* *aNewObject)
|
||||
{
|
||||
nsCOMPtr<nsISupports> file = do_QueryObject(new nsDOMMultipartFile(EmptyString()));
|
||||
nsCOMPtr<nsISupports> file = do_QueryObject(new nsDOMMultipartFile());
|
||||
file.forget(aNewObject);
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class nsDOMMultipartFile : public nsDOMFile,
|
|||
{
|
||||
public:
|
||||
// Create as a file
|
||||
nsDOMMultipartFile(nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs,
|
||||
nsDOMMultipartFile(nsTArray<nsCOMPtr<nsIDOMBlob> > aBlobs,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMFile(aName, aContentType, UINT64_MAX),
|
||||
|
@ -33,15 +33,14 @@ public:
|
|||
}
|
||||
|
||||
// Create as a file to be later initialized
|
||||
nsDOMMultipartFile(const nsAString& aName,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMFile(aName, aContentType, UINT64_MAX)
|
||||
nsDOMMultipartFile(const nsAString& aName)
|
||||
: nsDOMFile(aName, EmptyString(), UINT64_MAX)
|
||||
{
|
||||
}
|
||||
|
||||
// Create as a blob to be later initialized
|
||||
nsDOMMultipartFile(const nsAString& aContentType)
|
||||
: nsDOMFile(aContentType, UINT64_MAX)
|
||||
nsDOMMultipartFile()
|
||||
: nsDOMFile(EmptyString(), UINT64_MAX)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -89,12 +88,6 @@ public:
|
|||
virtual const nsTArray<nsCOMPtr<nsIDOMBlob> >*
|
||||
GetSubBlobs() const { return &mBlobs; }
|
||||
|
||||
void
|
||||
AddBlob(nsIDOMBlob* aBlob)
|
||||
{
|
||||
mBlobs.AppendElement(aBlob);
|
||||
}
|
||||
|
||||
protected:
|
||||
nsTArray<nsCOMPtr<nsIDOMBlob> > mBlobs;
|
||||
};
|
||||
|
|
553
dom/ipc/Blob.cpp
553
dom/ipc/Blob.cpp
|
@ -21,7 +21,6 @@
|
|||
#include "mozilla/unused.h"
|
||||
#include "mozilla/ipc/InputStreamUtils.h"
|
||||
#include "nsDOMFile.h"
|
||||
#include "nsDOMBlobBuilder.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include "ContentChild.h"
|
||||
|
@ -631,51 +630,17 @@ BlobTraits<Parent>::BaseType::NoteRunnableCompleted(
|
|||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
class RemoteBlobBase : public nsIRemoteBlob
|
||||
class RemoteBlob : public nsDOMFile,
|
||||
public nsIRemoteBlob
|
||||
{
|
||||
public:
|
||||
typedef RemoteBlob<ActorFlavor> SelfType;
|
||||
typedef Blob<ActorFlavor> ActorType;
|
||||
typedef InputStreamActor<ActorFlavor> StreamActorType;
|
||||
|
||||
void
|
||||
SetPBlob(void* aActor) MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_ASSERT(!aActor || !mActor);
|
||||
mActor = static_cast<ActorType*>(aActor);
|
||||
}
|
||||
|
||||
virtual void*
|
||||
GetPBlob() MOZ_OVERRIDE
|
||||
{
|
||||
return static_cast<typename ActorType::ProtocolType*>(mActor);
|
||||
}
|
||||
|
||||
private:
|
||||
ActorType* mActor;
|
||||
|
||||
protected:
|
||||
RemoteBlobBase()
|
||||
: mActor(nullptr)
|
||||
{ }
|
||||
|
||||
virtual
|
||||
~RemoteBlobBase()
|
||||
{
|
||||
if (mActor) {
|
||||
mActor->NoteDyingRemoteBlob();
|
||||
}
|
||||
}
|
||||
|
||||
ActorType* Actor() const { return mActor; }
|
||||
};
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
class RemoteBlob : public nsDOMFile,
|
||||
public RemoteBlobBase<ActorFlavor>
|
||||
{
|
||||
typedef Blob<ActorFlavor> ActorType;
|
||||
public:
|
||||
class StreamHelper : public nsRunnable
|
||||
{
|
||||
typedef Blob<ActorFlavor> ActorType;
|
||||
|
@ -792,7 +757,6 @@ public:
|
|||
{
|
||||
// This may be created on any thread.
|
||||
MOZ_ASSERT(aActor);
|
||||
MOZ_ASSERT(aActor->HasManager());
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -859,11 +823,8 @@ public:
|
|||
normalParams.contentType() = mContentType;
|
||||
normalParams.length() = mLength;
|
||||
|
||||
BlobConstructorNoMultipartParams params(normalParams);
|
||||
|
||||
ActorType* newActor = ActorType::Create(params);
|
||||
ActorType* newActor = ActorType::Create(normalParams);
|
||||
MOZ_ASSERT(newActor);
|
||||
mActor->PropagateManager(newActor);
|
||||
|
||||
SlicedBlobConstructorParams slicedParams;
|
||||
slicedParams.contentType() = mContentType;
|
||||
|
@ -871,8 +832,7 @@ public:
|
|||
slicedParams.end() = mStart + mLength;
|
||||
SetBlobOnParams(mActor, slicedParams);
|
||||
|
||||
BlobConstructorNoMultipartParams params2(slicedParams);
|
||||
if (mActor->ConstructPBlobOnManager(newActor, params2)) {
|
||||
if (mActor->Manager()->SendPBlobConstructor(newActor, slicedParams)) {
|
||||
mSlice = newActor->GetBlob();
|
||||
}
|
||||
|
||||
|
@ -894,40 +854,54 @@ public:
|
|||
|
||||
RemoteBlob(const nsAString& aName, const nsAString& aContentType,
|
||||
uint64_t aLength, uint64_t aModDate)
|
||||
: nsDOMFile(aName, aContentType, aLength, aModDate)
|
||||
: nsDOMFile(aName, aContentType, aLength, aModDate), mActor(nullptr)
|
||||
{
|
||||
mImmutable = true;
|
||||
}
|
||||
|
||||
RemoteBlob(const nsAString& aName, const nsAString& aContentType,
|
||||
uint64_t aLength)
|
||||
: nsDOMFile(aName, aContentType, aLength)
|
||||
: nsDOMFile(aName, aContentType, aLength), mActor(nullptr)
|
||||
{
|
||||
mImmutable = true;
|
||||
}
|
||||
|
||||
RemoteBlob(const nsAString& aContentType, uint64_t aLength)
|
||||
: nsDOMFile(aContentType, aLength)
|
||||
: nsDOMFile(aContentType, aLength), mActor(nullptr)
|
||||
{
|
||||
mImmutable = true;
|
||||
}
|
||||
|
||||
RemoteBlob()
|
||||
: nsDOMFile(EmptyString(), EmptyString(), UINT64_MAX, UINT64_MAX)
|
||||
, mActor(nullptr)
|
||||
{
|
||||
mImmutable = true;
|
||||
}
|
||||
|
||||
virtual ~RemoteBlob()
|
||||
{
|
||||
if (mActor) {
|
||||
mActor->NoteDyingRemoteBlob();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SetActor(ActorType* aActor)
|
||||
{
|
||||
MOZ_ASSERT(!aActor || !mActor);
|
||||
mActor = aActor;
|
||||
}
|
||||
|
||||
virtual already_AddRefed<nsIDOMBlob>
|
||||
CreateSlice(uint64_t aStart, uint64_t aLength, const nsAString& aContentType)
|
||||
MOZ_OVERRIDE
|
||||
{
|
||||
ActorType* actor = RemoteBlobBase<ActorFlavor>::Actor();
|
||||
if (!actor) {
|
||||
if (!mActor) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsRefPtr<SliceHelper> helper = new SliceHelper(actor);
|
||||
nsRefPtr<SliceHelper> helper = new SliceHelper(mActor);
|
||||
|
||||
nsCOMPtr<nsIDOMBlob> slice;
|
||||
nsresult rv =
|
||||
|
@ -940,100 +914,18 @@ public:
|
|||
NS_IMETHOD
|
||||
GetInternalStream(nsIInputStream** aStream) MOZ_OVERRIDE
|
||||
{
|
||||
ActorType* actor = RemoteBlobBase<ActorFlavor>::Actor();
|
||||
if (!actor) {
|
||||
if (!mActor) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
nsRefPtr<StreamHelper> helper = new StreamHelper(actor, this);
|
||||
nsRefPtr<StreamHelper> helper = new StreamHelper(mActor, this);
|
||||
return helper->GetStream(aStream);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
GetLastModifiedDate(JSContext* cx, JS::Value* aLastModifiedDate)
|
||||
virtual void*
|
||||
GetPBlob() MOZ_OVERRIDE
|
||||
{
|
||||
if (IsDateUnknown()) {
|
||||
aLastModifiedDate->setNull();
|
||||
} else {
|
||||
JSObject* date = JS_NewDateObjectMsec(cx, mLastModificationDate);
|
||||
if (!date) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
aLastModifiedDate->setObject(*date);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
class RemoteMemoryBlob : public nsDOMMemoryFile,
|
||||
public RemoteBlobBase<ActorFlavor>
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
RemoteMemoryBlob(void* aMemoryBuffer,
|
||||
uint64_t aLength,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType,
|
||||
uint64_t aModDate)
|
||||
: nsDOMMemoryFile(aMemoryBuffer, aLength, aName, aContentType, aModDate)
|
||||
{
|
||||
mImmutable = true;
|
||||
}
|
||||
|
||||
RemoteMemoryBlob(void* aMemoryBuffer,
|
||||
uint64_t aLength,
|
||||
const nsAString& aName,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMMemoryFile(aMemoryBuffer, aLength, aName, aContentType)
|
||||
{
|
||||
mImmutable = true;
|
||||
}
|
||||
|
||||
RemoteMemoryBlob(void* aMemoryBuffer,
|
||||
uint64_t aLength,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMMemoryFile(aMemoryBuffer, aLength, EmptyString(), aContentType)
|
||||
{
|
||||
mImmutable = true;
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
GetLastModifiedDate(JSContext* cx, JS::Value* aLastModifiedDate)
|
||||
{
|
||||
if (IsDateUnknown()) {
|
||||
aLastModifiedDate->setNull();
|
||||
} else {
|
||||
JSObject* date = JS_NewDateObjectMsec(cx, mLastModificationDate);
|
||||
if (!date) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
aLastModifiedDate->setObject(*date);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
class RemoteMultipartBlob : public nsDOMMultipartFile,
|
||||
public RemoteBlobBase<ActorFlavor>
|
||||
{
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
RemoteMultipartBlob(const nsAString& aName,
|
||||
const nsAString& aContentType)
|
||||
: nsDOMMultipartFile(aName, aContentType)
|
||||
{
|
||||
mImmutable = true;
|
||||
}
|
||||
|
||||
RemoteMultipartBlob(const nsAString& aName)
|
||||
: nsDOMMultipartFile(aName)
|
||||
{
|
||||
mImmutable = true;
|
||||
return static_cast<typename ActorType::ProtocolType*>(mActor);
|
||||
}
|
||||
|
||||
NS_IMETHOD
|
||||
|
@ -1054,9 +946,7 @@ public:
|
|||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
Blob<ActorFlavor>::Blob(nsIDOMBlob* aBlob)
|
||||
: mBlob(aBlob), mRemoteBlob(nullptr), mRemoteMemoryBlob(nullptr),
|
||||
mRemoteMultipartBlob(nullptr), mContentManager(nullptr),
|
||||
mBlobManager(nullptr), mOwnsBlob(true), mBlobIsFile(false)
|
||||
: mBlob(aBlob), mRemoteBlob(nullptr), mOwnsBlob(true), mBlobIsFile(false)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aBlob);
|
||||
|
@ -1067,70 +957,44 @@ Blob<ActorFlavor>::Blob(nsIDOMBlob* aBlob)
|
|||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
Blob<ActorFlavor>::Blob(nsRefPtr<RemoteBlobType>& aBlob,
|
||||
bool aBlobIsFile)
|
||||
: mBlob(nullptr), mRemoteBlob(nullptr), mRemoteMemoryBlob(nullptr),
|
||||
mRemoteMultipartBlob(nullptr), mContentManager(nullptr),
|
||||
mBlobManager(nullptr), mOwnsBlob(true), mBlobIsFile(aBlobIsFile)
|
||||
Blob<ActorFlavor>::Blob(const BlobConstructorParams& aParams)
|
||||
: mBlob(nullptr), mRemoteBlob(nullptr), mOwnsBlob(false), mBlobIsFile(false)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mBlob);
|
||||
MOZ_ASSERT(!mRemoteBlob);
|
||||
MOZ_ASSERT(aBlob);
|
||||
|
||||
if (NS_FAILED(aBlob->SetMutable(false))) {
|
||||
MOZ_NOT_REACHED("Failed to make remote blob immutable!");
|
||||
nsRefPtr<RemoteBlobType> remoteBlob;
|
||||
|
||||
switch (aParams.type()) {
|
||||
case BlobConstructorParams::TNormalBlobConstructorParams: {
|
||||
const NormalBlobConstructorParams& params =
|
||||
aParams.get_NormalBlobConstructorParams();
|
||||
remoteBlob = new RemoteBlobType(params.contentType(), params.length());
|
||||
break;
|
||||
}
|
||||
|
||||
case BlobConstructorParams::TFileBlobConstructorParams: {
|
||||
const FileBlobConstructorParams& params =
|
||||
aParams.get_FileBlobConstructorParams();
|
||||
remoteBlob =
|
||||
new RemoteBlobType(params.name(), params.contentType(),
|
||||
params.length(), params.modDate());
|
||||
mBlobIsFile = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case BlobConstructorParams::TMysteryBlobConstructorParams: {
|
||||
remoteBlob = new RemoteBlobType();
|
||||
mBlobIsFile = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
MOZ_NOT_REACHED("Unknown params!");
|
||||
}
|
||||
|
||||
aBlob->SetPBlob(this);
|
||||
aBlob.forget(&mRemoteBlob);
|
||||
MOZ_ASSERT(remoteBlob);
|
||||
|
||||
mBlob = mRemoteBlob;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
Blob<ActorFlavor>::Blob(nsRefPtr<RemoteMemoryBlobType>& aBlob,
|
||||
bool aBlobIsFile)
|
||||
: mBlob(nullptr), mRemoteBlob(nullptr), mRemoteMemoryBlob(nullptr),
|
||||
mRemoteMultipartBlob(nullptr), mContentManager(nullptr),
|
||||
mBlobManager(nullptr), mOwnsBlob(true), mBlobIsFile(aBlobIsFile)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mBlob);
|
||||
MOZ_ASSERT(!mRemoteMemoryBlob);
|
||||
MOZ_ASSERT(aBlob);
|
||||
|
||||
if (NS_FAILED(aBlob->SetMutable(false))) {
|
||||
MOZ_NOT_REACHED("Failed to make remote blob immutable!");
|
||||
}
|
||||
|
||||
aBlob->SetPBlob(this);
|
||||
aBlob.forget(&mRemoteMemoryBlob);
|
||||
|
||||
mBlob = mRemoteMemoryBlob;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
Blob<ActorFlavor>::Blob(nsRefPtr<RemoteMultipartBlobType>& aBlob,
|
||||
bool aBlobIsFile)
|
||||
: mBlob(nullptr), mRemoteBlob(nullptr), mRemoteMemoryBlob(nullptr),
|
||||
mRemoteMultipartBlob(nullptr), mContentManager(nullptr),
|
||||
mBlobManager(nullptr), mOwnsBlob(true), mBlobIsFile(aBlobIsFile)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mBlob);
|
||||
MOZ_ASSERT(!mRemoteMultipartBlob);
|
||||
MOZ_ASSERT(!mOwnsBlob);
|
||||
MOZ_ASSERT(aBlob);
|
||||
|
||||
if (NS_FAILED(aBlob->SetMutable(false))) {
|
||||
MOZ_NOT_REACHED("Failed to make remote blob immutable!");
|
||||
}
|
||||
|
||||
aBlob->SetPBlob(this);
|
||||
aBlob.forget(&mRemoteMultipartBlob);
|
||||
|
||||
mBlob = mRemoteMultipartBlob;
|
||||
SetRemoteBlob(remoteBlob);
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
|
@ -1140,156 +1004,25 @@ Blob<ActorFlavor>::Create(const BlobConstructorParams& aParams)
|
|||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
switch (aParams.type()) {
|
||||
case BlobConstructorParams::TBlobConstructorNoMultipartParams: {
|
||||
const BlobConstructorNoMultipartParams& params =
|
||||
aParams.get_BlobConstructorNoMultipartParams();
|
||||
case BlobConstructorParams::TNormalBlobConstructorParams:
|
||||
case BlobConstructorParams::TFileBlobConstructorParams:
|
||||
case BlobConstructorParams::TMysteryBlobConstructorParams:
|
||||
return new Blob<ActorFlavor>(aParams);
|
||||
|
||||
switch (params.type()) {
|
||||
case BlobConstructorNoMultipartParams::TBlobOrFileConstructorParams: {
|
||||
const BlobOrFileConstructorParams& fileParams =
|
||||
params.get_BlobOrFileConstructorParams();
|
||||
nsRefPtr<RemoteBlobType> remoteBlob;
|
||||
bool isFile = false;
|
||||
case BlobConstructorParams::TSlicedBlobConstructorParams: {
|
||||
const SlicedBlobConstructorParams& params =
|
||||
aParams.get_SlicedBlobConstructorParams();
|
||||
|
||||
switch (fileParams.type()) {
|
||||
case BlobOrFileConstructorParams::TNormalBlobConstructorParams: {
|
||||
const NormalBlobConstructorParams& normalParams =
|
||||
fileParams.get_NormalBlobConstructorParams();
|
||||
remoteBlob = new RemoteBlobType(normalParams.contentType(),
|
||||
normalParams.length());
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMBlob> source = GetBlobFromParams<ActorFlavor>(params);
|
||||
MOZ_ASSERT(source);
|
||||
|
||||
case BlobOrFileConstructorParams::TFileBlobConstructorParams: {
|
||||
const FileBlobConstructorParams& fbParams =
|
||||
fileParams.get_FileBlobConstructorParams();
|
||||
remoteBlob =
|
||||
new RemoteBlobType(fbParams.name(), fbParams.contentType(),
|
||||
fbParams.length(), fbParams.modDate());
|
||||
isFile = true;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMBlob> slice;
|
||||
nsresult rv =
|
||||
source->Slice(params.begin(), params.end(), params.contentType(), 3,
|
||||
getter_AddRefs(slice));
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
default:
|
||||
MOZ_NOT_REACHED("Unknown params!");
|
||||
}
|
||||
|
||||
return new Blob<ActorFlavor>(remoteBlob, isFile);
|
||||
}
|
||||
case BlobConstructorNoMultipartParams::TMemoryBlobOrFileConstructorParams: {
|
||||
const MemoryBlobOrFileConstructorParams& memoryParams =
|
||||
params.get_MemoryBlobOrFileConstructorParams();
|
||||
const BlobOrFileConstructorParams& internalParams =
|
||||
memoryParams.constructorParams();
|
||||
nsRefPtr<RemoteMemoryBlobType> remoteMemoryBlob;
|
||||
bool isFile = false;
|
||||
|
||||
switch (internalParams.type()) {
|
||||
case BlobOrFileConstructorParams::TNormalBlobConstructorParams: {
|
||||
const NormalBlobConstructorParams& normalParams =
|
||||
internalParams.get_NormalBlobConstructorParams();
|
||||
MOZ_ASSERT(normalParams.length() == memoryParams.data().Length());
|
||||
|
||||
void* data =
|
||||
BlobTraits<ActorFlavor>::Allocate(memoryParams.data().Length());
|
||||
if (!data) {
|
||||
return nullptr;
|
||||
}
|
||||
memcpy(data,
|
||||
memoryParams.data().Elements(),
|
||||
memoryParams.data().Length());
|
||||
remoteMemoryBlob =
|
||||
new RemoteMemoryBlobType(data,
|
||||
memoryParams.data().Length(),
|
||||
normalParams.contentType());
|
||||
break;
|
||||
}
|
||||
|
||||
case BlobOrFileConstructorParams::TFileBlobConstructorParams: {
|
||||
const FileBlobConstructorParams& fbParams =
|
||||
internalParams.get_FileBlobConstructorParams();
|
||||
MOZ_ASSERT(fbParams.length() == memoryParams.data().Length());
|
||||
|
||||
void* data =
|
||||
BlobTraits<ActorFlavor>::Allocate(memoryParams.data().Length());
|
||||
if (!data) {
|
||||
return nullptr;
|
||||
}
|
||||
memcpy(data,
|
||||
memoryParams.data().Elements(),
|
||||
memoryParams.data().Length());
|
||||
remoteMemoryBlob =
|
||||
new RemoteMemoryBlobType(data,
|
||||
memoryParams.data().Length(),
|
||||
fbParams.name(),
|
||||
fbParams.contentType(),
|
||||
fbParams.modDate());
|
||||
isFile = true;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
MOZ_NOT_REACHED("Unknown params!");
|
||||
}
|
||||
|
||||
return new Blob<ActorFlavor>(remoteMemoryBlob, isFile);
|
||||
}
|
||||
case BlobConstructorNoMultipartParams::TMysteryBlobConstructorParams: {
|
||||
nsRefPtr<RemoteBlobType> remoteBlob = new RemoteBlobType();
|
||||
return new Blob<ActorFlavor>(remoteBlob, true);
|
||||
}
|
||||
|
||||
case BlobConstructorNoMultipartParams::TSlicedBlobConstructorParams: {
|
||||
const SlicedBlobConstructorParams& slicedParams =
|
||||
params.get_SlicedBlobConstructorParams();
|
||||
|
||||
nsCOMPtr<nsIDOMBlob> source =
|
||||
GetBlobFromParams<ActorFlavor>(slicedParams);
|
||||
MOZ_ASSERT(source);
|
||||
|
||||
nsCOMPtr<nsIDOMBlob> slice;
|
||||
nsresult rv =
|
||||
source->Slice(slicedParams.begin(), slicedParams.end(),
|
||||
slicedParams.contentType(), 3,
|
||||
getter_AddRefs(slice));
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
return new Blob<ActorFlavor>(slice);
|
||||
}
|
||||
|
||||
default:
|
||||
MOZ_NOT_REACHED("Unknown params!");
|
||||
}
|
||||
}
|
||||
|
||||
case BlobConstructorParams::TMultipartBlobOrFileConstructorParams: {
|
||||
const MultipartBlobOrFileConstructorParams& params =
|
||||
aParams.get_MultipartBlobOrFileConstructorParams();
|
||||
|
||||
nsRefPtr<RemoteMultipartBlobType> file;
|
||||
const BlobOrFileConstructorParams& internalParams =
|
||||
params.constructorParams();
|
||||
switch (internalParams.type()) {
|
||||
case BlobOrFileConstructorParams::TNormalBlobConstructorParams: {
|
||||
const NormalBlobConstructorParams& normalParams =
|
||||
internalParams.get_NormalBlobConstructorParams();
|
||||
file = new RemoteMultipartBlobType(normalParams.contentType());
|
||||
break;
|
||||
}
|
||||
|
||||
case BlobOrFileConstructorParams::TFileBlobConstructorParams: {
|
||||
const FileBlobConstructorParams& fbParams =
|
||||
internalParams.get_FileBlobConstructorParams();
|
||||
file = new RemoteMultipartBlobType(fbParams.name(),
|
||||
fbParams.contentType());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
MOZ_NOT_REACHED("Unknown params!");
|
||||
}
|
||||
|
||||
return new Blob<ActorFlavor>(file);
|
||||
return new Blob<ActorFlavor>(slice);
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -1311,8 +1044,7 @@ Blob<ActorFlavor>::GetBlob()
|
|||
// Remote blobs are held alive until the first call to GetBlob. Thereafter we
|
||||
// only hold a weak reference. Normal blobs are held alive until the actor is
|
||||
// destroyed.
|
||||
if (mOwnsBlob &&
|
||||
(mRemoteBlob || mRemoteMemoryBlob || mRemoteMultipartBlob)) {
|
||||
if (mRemoteBlob && mOwnsBlob) {
|
||||
blob = dont_AddRef(mBlob);
|
||||
mOwnsBlob = false;
|
||||
}
|
||||
|
@ -1367,53 +1099,24 @@ Blob<ActorFlavor>::SetMysteryBlobInfo(const nsString& aContentType,
|
|||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
typename Blob<ActorFlavor>::ProtocolType*
|
||||
Blob<ActorFlavor>::ConstructPBlobOnManager(ProtocolType* aActor,
|
||||
const BlobConstructorParams& aParams)
|
||||
void
|
||||
Blob<ActorFlavor>::SetRemoteBlob(nsRefPtr<RemoteBlobType>& aRemoteBlob)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(HasManager());
|
||||
MOZ_ASSERT(!mBlob);
|
||||
MOZ_ASSERT(!mRemoteBlob);
|
||||
MOZ_ASSERT(!mOwnsBlob);
|
||||
MOZ_ASSERT(aRemoteBlob);
|
||||
|
||||
if (mContentManager) {
|
||||
return mContentManager->SendPBlobConstructor(aActor, aParams);
|
||||
if (NS_FAILED(aRemoteBlob->SetMutable(false))) {
|
||||
MOZ_NOT_REACHED("Failed to make remote blob immutable!");
|
||||
}
|
||||
|
||||
if (mBlobManager) {
|
||||
return mBlobManager->SendPBlobConstructor(aActor, aParams);
|
||||
}
|
||||
aRemoteBlob->SetActor(this);
|
||||
aRemoteBlob.forget(&mRemoteBlob);
|
||||
|
||||
MOZ_NOT_REACHED("Why don't I have a manager?!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
void
|
||||
Blob<ActorFlavor>::SetManager(ContentManagerType* aManager)
|
||||
{
|
||||
MOZ_ASSERT(!mContentManager && !mBlobManager);
|
||||
MOZ_ASSERT(aManager);
|
||||
|
||||
mContentManager = aManager;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
void
|
||||
Blob<ActorFlavor>::SetManager(BlobManagerType* aManager)
|
||||
{
|
||||
MOZ_ASSERT(!mContentManager && !mBlobManager);
|
||||
MOZ_ASSERT(aManager);
|
||||
|
||||
mBlobManager = aManager;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
void
|
||||
Blob<ActorFlavor>::PropagateManager(Blob<ActorFlavor>* aActor) const
|
||||
{
|
||||
MOZ_ASSERT(HasManager());
|
||||
|
||||
aActor->mContentManager = mContentManager;
|
||||
aActor->mBlobManager = mBlobManager;
|
||||
mBlob = mRemoteBlob;
|
||||
mOwnsBlob = true;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
|
@ -1421,7 +1124,7 @@ void
|
|||
Blob<ActorFlavor>::NoteDyingRemoteBlob()
|
||||
{
|
||||
MOZ_ASSERT(mBlob);
|
||||
MOZ_ASSERT(mRemoteBlob || mRemoteMemoryBlob || mRemoteMultipartBlob);
|
||||
MOZ_ASSERT(mRemoteBlob);
|
||||
MOZ_ASSERT(!mOwnsBlob);
|
||||
|
||||
// This may be called on any thread due to the fact that RemoteBlob is
|
||||
|
@ -1441,8 +1144,6 @@ Blob<ActorFlavor>::NoteDyingRemoteBlob()
|
|||
// Must do this before calling Send__delete__ or we'll crash there trying to
|
||||
// access a dangling pointer.
|
||||
mRemoteBlob = nullptr;
|
||||
mRemoteMemoryBlob = nullptr;
|
||||
mRemoteMultipartBlob = nullptr;
|
||||
|
||||
mozilla::unused << ProtocolType::Send__delete__(this);
|
||||
}
|
||||
|
@ -1455,15 +1156,7 @@ Blob<ActorFlavor>::ActorDestroy(ActorDestroyReason aWhy)
|
|||
MOZ_ASSERT(mBlob);
|
||||
|
||||
if (mRemoteBlob) {
|
||||
mRemoteBlob->SetPBlob(nullptr);
|
||||
}
|
||||
|
||||
if (mRemoteMemoryBlob) {
|
||||
mRemoteMemoryBlob->SetPBlob(nullptr);
|
||||
}
|
||||
|
||||
if (mRemoteMultipartBlob) {
|
||||
mRemoteMultipartBlob->SetPBlob(nullptr);
|
||||
mRemoteBlob->SetActor(nullptr);
|
||||
}
|
||||
|
||||
if (mOwnsBlob) {
|
||||
|
@ -1478,8 +1171,6 @@ Blob<ActorFlavor>::RecvResolveMystery(const ResolveMysteryParams& aParams)
|
|||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mBlob);
|
||||
MOZ_ASSERT(!mRemoteBlob);
|
||||
MOZ_ASSERT(!mRemoteMemoryBlob);
|
||||
MOZ_ASSERT(!mRemoteMultipartBlob);
|
||||
MOZ_ASSERT(mOwnsBlob);
|
||||
|
||||
if (!mBlobIsFile) {
|
||||
|
@ -1522,8 +1213,6 @@ Blob<Parent>::RecvPBlobStreamConstructor(StreamType* aActor)
|
|||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mBlob);
|
||||
MOZ_ASSERT(!mRemoteBlob);
|
||||
MOZ_ASSERT(!mRemoteMemoryBlob);
|
||||
MOZ_ASSERT(!mRemoteMultipartBlob);
|
||||
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
nsresult rv = mBlob->GetInternalStream(getter_AddRefs(stream));
|
||||
|
@ -1579,8 +1268,6 @@ Blob<Child>::RecvPBlobStreamConstructor(StreamType* aActor)
|
|||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(mBlob);
|
||||
MOZ_ASSERT(!mRemoteBlob);
|
||||
MOZ_ASSERT(!mRemoteMemoryBlob);
|
||||
MOZ_ASSERT(!mRemoteMultipartBlob);
|
||||
|
||||
nsCOMPtr<nsIInputStream> stream;
|
||||
nsresult rv = mBlob->GetInternalStream(getter_AddRefs(stream));
|
||||
|
@ -1601,25 +1288,6 @@ Blob<Child>::RecvPBlobStreamConstructor(StreamType* aActor)
|
|||
return aActor->Send__delete__(aActor, params);
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
bool
|
||||
Blob<ActorFlavor>::RecvPBlobConstructor(ProtocolType* aActor,
|
||||
const BlobConstructorParams& aParams)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
Blob<ActorFlavor>* subBlobActor = static_cast<Blob<ActorFlavor>*>(aActor);
|
||||
|
||||
if (!subBlobActor->ManagerIs(this)) {
|
||||
// Somebody screwed up!
|
||||
return false;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMBlob> blob = subBlobActor->GetBlob();
|
||||
static_cast<nsDOMMultipartFile*>(mBlob)->AddBlob(blob);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
typename Blob<ActorFlavor>::StreamType*
|
||||
Blob<ActorFlavor>::AllocPBlobStream()
|
||||
|
@ -1637,23 +1305,6 @@ Blob<ActorFlavor>::DeallocPBlobStream(StreamType* aActor)
|
|||
return true;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
typename Blob<ActorFlavor>::ProtocolType*
|
||||
Blob<ActorFlavor>::AllocPBlob(const BlobConstructorParams& aParams)
|
||||
{
|
||||
Blob<ActorFlavor>* actor = Blob<ActorFlavor>::Create(aParams);
|
||||
actor->SetManager(this);
|
||||
return actor;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
bool
|
||||
Blob<ActorFlavor>::DeallocPBlob(ProtocolType* aActor)
|
||||
{
|
||||
delete aActor;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
NS_IMPL_ADDREF_INHERITED(RemoteBlob<ActorFlavor>, nsDOMFile)
|
||||
|
||||
|
@ -1664,26 +1315,6 @@ template <ActorFlavorEnum ActorFlavor>
|
|||
NS_IMPL_QUERY_INTERFACE_INHERITED1(RemoteBlob<ActorFlavor>, nsDOMFile,
|
||||
nsIRemoteBlob)
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
NS_IMPL_ADDREF_INHERITED(RemoteMemoryBlob<ActorFlavor>, nsDOMMemoryFile)
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
NS_IMPL_RELEASE_INHERITED(RemoteMemoryBlob<ActorFlavor>, nsDOMMemoryFile)
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
NS_IMPL_QUERY_INTERFACE_INHERITED1(RemoteMemoryBlob<ActorFlavor>, nsDOMMemoryFile,
|
||||
nsIRemoteBlob)
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
NS_IMPL_ADDREF_INHERITED(RemoteMultipartBlob<ActorFlavor>, nsDOMMultipartFile)
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
NS_IMPL_RELEASE_INHERITED(RemoteMultipartBlob<ActorFlavor>, nsDOMMultipartFile)
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
NS_IMPL_QUERY_INTERFACE_INHERITED1(RemoteMultipartBlob<ActorFlavor>, nsDOMMultipartFile,
|
||||
nsIRemoteBlob)
|
||||
|
||||
// Explicit instantiation of both classes.
|
||||
template class Blob<Parent>;
|
||||
template class Blob<Child>;
|
||||
|
|
|
@ -42,8 +42,6 @@ struct BlobTraits<Parent>
|
|||
{
|
||||
typedef mozilla::dom::PBlobParent ProtocolType;
|
||||
typedef mozilla::dom::PBlobStreamParent StreamType;
|
||||
typedef mozilla::dom::PContentParent ContentManagerType;
|
||||
typedef ProtocolType BlobManagerType;
|
||||
|
||||
// BaseType on the parent side is a bit more complicated than for the child
|
||||
// side. In the case of nsIInputStreams backed by files we need to ensure that
|
||||
|
@ -68,13 +66,6 @@ struct BlobTraits<Parent>
|
|||
|
||||
nsTArray<nsRevocableEventPtr<OpenStreamRunnable> > mOpenStreamRunnables;
|
||||
};
|
||||
|
||||
static void*
|
||||
Allocate(size_t aSize)
|
||||
{
|
||||
// We want fallible allocation in the parent.
|
||||
return moz_malloc(aSize);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
|
@ -82,8 +73,6 @@ struct BlobTraits<Child>
|
|||
{
|
||||
typedef mozilla::dom::PBlobChild ProtocolType;
|
||||
typedef mozilla::dom::PBlobStreamChild StreamType;
|
||||
typedef mozilla::dom::PContentChild ContentManagerType;
|
||||
typedef ProtocolType BlobManagerType;
|
||||
|
||||
class BaseType : public ProtocolType
|
||||
{
|
||||
|
@ -94,38 +83,21 @@ struct BlobTraits<Child>
|
|||
virtual ~BaseType()
|
||||
{ }
|
||||
};
|
||||
|
||||
static void*
|
||||
Allocate(size_t aSize)
|
||||
{
|
||||
// We want infallible allocation in the child.
|
||||
return moz_xmalloc(aSize);
|
||||
}
|
||||
};
|
||||
|
||||
template <ActorFlavorEnum>
|
||||
class RemoteBlobBase;
|
||||
template <ActorFlavorEnum>
|
||||
class RemoteBlob;
|
||||
template <ActorFlavorEnum>
|
||||
class RemoteMemoryBlob;
|
||||
template <ActorFlavorEnum>
|
||||
class RemoteMultipartBlob;
|
||||
|
||||
template <ActorFlavorEnum ActorFlavor>
|
||||
class Blob : public BlobTraits<ActorFlavor>::BaseType
|
||||
{
|
||||
friend class RemoteBlobBase<ActorFlavor>;
|
||||
friend class RemoteBlob<ActorFlavor>;
|
||||
|
||||
public:
|
||||
typedef typename BlobTraits<ActorFlavor>::ProtocolType ProtocolType;
|
||||
typedef typename BlobTraits<ActorFlavor>::StreamType StreamType;
|
||||
typedef typename BlobTraits<ActorFlavor>::BaseType BaseType;
|
||||
typedef typename BlobTraits<ActorFlavor>::ContentManagerType ContentManagerType;
|
||||
typedef typename BlobTraits<ActorFlavor>::BlobManagerType BlobManagerType;
|
||||
typedef RemoteBlob<ActorFlavor> RemoteBlobType;
|
||||
typedef RemoteMemoryBlob<ActorFlavor> RemoteMemoryBlobType;
|
||||
typedef RemoteMultipartBlob<ActorFlavor> RemoteMultipartBlobType;
|
||||
typedef mozilla::ipc::IProtocolManager<
|
||||
mozilla::ipc::RPCChannel::RPCListener>::ActorDestroyReason
|
||||
ActorDestroyReason;
|
||||
|
@ -134,12 +106,6 @@ public:
|
|||
protected:
|
||||
nsIDOMBlob* mBlob;
|
||||
RemoteBlobType* mRemoteBlob;
|
||||
RemoteMemoryBlobType* mRemoteMemoryBlob;
|
||||
RemoteMultipartBlobType* mRemoteMultipartBlob;
|
||||
|
||||
ContentManagerType* mContentManager;
|
||||
BlobManagerType* mBlobManager;
|
||||
|
||||
bool mOwnsBlob;
|
||||
bool mBlobIsFile;
|
||||
|
||||
|
@ -170,49 +136,15 @@ public:
|
|||
bool
|
||||
SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength);
|
||||
|
||||
ProtocolType*
|
||||
ConstructPBlobOnManager(ProtocolType* aActor,
|
||||
const BlobConstructorParams& aParams);
|
||||
|
||||
bool
|
||||
ManagerIs(const ContentManagerType* aManager) const
|
||||
{
|
||||
return aManager == mContentManager;
|
||||
}
|
||||
|
||||
bool
|
||||
ManagerIs(const BlobManagerType* aManager) const
|
||||
{
|
||||
return aManager == mBlobManager;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
bool
|
||||
HasManager() const
|
||||
{
|
||||
return !!mContentManager || !!mBlobManager;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
SetManager(ContentManagerType* aManager);
|
||||
void
|
||||
SetManager(BlobManagerType* aManager);
|
||||
|
||||
void
|
||||
PropagateManager(Blob<ActorFlavor>* aActor) const;
|
||||
|
||||
private:
|
||||
// This constructor is called on the sending side.
|
||||
Blob(nsIDOMBlob* aBlob);
|
||||
|
||||
// These constructors are called on the receiving side.
|
||||
Blob(nsRefPtr<RemoteBlobType>& aBlob,
|
||||
bool aIsFile);
|
||||
Blob(nsRefPtr<RemoteMemoryBlobType>& aBlob,
|
||||
bool aIsFile);
|
||||
Blob(nsRefPtr<RemoteMultipartBlobType>& aBlob,
|
||||
bool aIsFile);
|
||||
// This constructor is called on the receiving side.
|
||||
Blob(const BlobConstructorParams& aParams);
|
||||
|
||||
void
|
||||
SetRemoteBlob(nsRefPtr<RemoteBlobType>& aRemoteBlob);
|
||||
|
||||
void
|
||||
NoteDyingRemoteBlob();
|
||||
|
@ -227,21 +159,11 @@ private:
|
|||
virtual bool
|
||||
RecvPBlobStreamConstructor(StreamType* aActor) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
RecvPBlobConstructor(ProtocolType* aActor,
|
||||
const BlobConstructorParams& aParams) MOZ_OVERRIDE;
|
||||
|
||||
virtual StreamType*
|
||||
AllocPBlobStream() MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
DeallocPBlobStream(StreamType* aActor) MOZ_OVERRIDE;
|
||||
|
||||
virtual ProtocolType*
|
||||
AllocPBlob(const BlobConstructorParams& params) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool
|
||||
DeallocPBlob(ProtocolType* actor) MOZ_OVERRIDE;
|
||||
};
|
||||
|
||||
} // namespace ipc
|
||||
|
|
|
@ -546,9 +546,7 @@ ContentChild::DeallocPBrowser(PBrowserChild* iframe)
|
|||
PBlobChild*
|
||||
ContentChild::AllocPBlob(const BlobConstructorParams& aParams)
|
||||
{
|
||||
BlobChild* actor = BlobChild::Create(aParams);
|
||||
actor->SetManager(this);
|
||||
return actor;
|
||||
return BlobChild::Create(aParams);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -558,42 +556,53 @@ ContentChild::DeallocPBlob(PBlobChild* aActor)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::GetParamsForBlob(nsDOMFileBase* aBlob,
|
||||
BlobConstructorParams* aOutParams)
|
||||
BlobChild*
|
||||
ContentChild::GetOrCreateActorForBlob(nsIDOMBlob* aBlob)
|
||||
{
|
||||
BlobConstructorParams resultParams;
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(aBlob, "Null pointer!");
|
||||
|
||||
if (!(aBlob->IsMemoryBacked() || aBlob->GetSubBlobs()) &&
|
||||
(aBlob->IsSizeUnknown() || aBlob->IsDateUnknown())) {
|
||||
nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(aBlob);
|
||||
if (remoteBlob) {
|
||||
BlobChild* actor =
|
||||
static_cast<BlobChild*>(static_cast<PBlobChild*>(remoteBlob->GetPBlob()));
|
||||
NS_ASSERTION(actor, "Null actor?!");
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
// XXX This is only safe so long as all blob implementations in our tree
|
||||
// inherit nsDOMFileBase. If that ever changes then this will need to grow
|
||||
// a real interface or something.
|
||||
const nsDOMFileBase* blob = static_cast<nsDOMFileBase*>(aBlob);
|
||||
|
||||
BlobConstructorParams params;
|
||||
|
||||
if (blob->IsSizeUnknown() || blob->IsDateUnknown()) {
|
||||
// We don't want to call GetSize or GetLastModifiedDate
|
||||
// yet since that may stat a file on the main thread
|
||||
// here. Instead we'll learn the size lazily from the
|
||||
// other process.
|
||||
resultParams = MysteryBlobConstructorParams();
|
||||
params = MysteryBlobConstructorParams();
|
||||
}
|
||||
else {
|
||||
BlobOrFileConstructorParams params;
|
||||
|
||||
nsString contentType;
|
||||
nsresult rv = aBlob->GetType(contentType);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
uint64_t length;
|
||||
rv = aBlob->GetSize(&length);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
nsCOMPtr<nsIDOMFile> file;
|
||||
static_cast<nsIDOMBlob*>(aBlob)->QueryInterface(NS_GET_IID(nsIDOMFile),
|
||||
(void**)getter_AddRefs(file));
|
||||
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(aBlob);
|
||||
if (file) {
|
||||
FileBlobConstructorParams fileParams;
|
||||
|
||||
rv = file->GetName(fileParams.name());
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
rv = file->GetMozLastModifiedDate(&fileParams.modDate());
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
fileParams.contentType() = contentType;
|
||||
fileParams.length() = length;
|
||||
|
@ -605,81 +614,13 @@ ContentChild::GetParamsForBlob(nsDOMFileBase* aBlob,
|
|||
blobParams.length() = length;
|
||||
params = blobParams;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!(aBlob->IsMemoryBacked() &&
|
||||
aBlob->GetSubBlobs()), "Can't be both!");
|
||||
|
||||
if (aBlob->IsMemoryBacked()) {
|
||||
const nsDOMMemoryFile* memoryBlob =
|
||||
static_cast<const nsDOMMemoryFile*>(aBlob);
|
||||
|
||||
InfallibleTArray<uint8_t> data;
|
||||
data.SetLength(memoryBlob->GetLength());
|
||||
memcpy(data.Elements(), memoryBlob->GetData(), memoryBlob->GetLength());
|
||||
|
||||
MemoryBlobOrFileConstructorParams memoryParams(params, data);
|
||||
resultParams = memoryParams;
|
||||
}
|
||||
else if (aBlob->GetSubBlobs()) {
|
||||
MultipartBlobOrFileConstructorParams multipartParams(params);
|
||||
resultParams = multipartParams;
|
||||
}
|
||||
else {
|
||||
resultParams = BlobConstructorNoMultipartParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
*aOutParams = resultParams;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BlobChild*
|
||||
ContentChild::GetOrCreateActorForBlob(nsIDOMBlob* aBlob)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(aBlob, "Null pointer!");
|
||||
|
||||
// XXX This is only safe so long as all blob implementations in our tree
|
||||
// inherit nsDOMFileBase. If that ever changes then this will need to grow
|
||||
// a real interface or something.
|
||||
nsDOMFileBase* blob = static_cast<nsDOMFileBase*>(aBlob);
|
||||
|
||||
nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(aBlob);
|
||||
if (remoteBlob) {
|
||||
BlobChild* actor =
|
||||
static_cast<BlobChild*>(static_cast<PBlobChild*>(remoteBlob->GetPBlob()));
|
||||
NS_ASSERTION(actor, "Null actor?!");
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
BlobConstructorParams params;
|
||||
if (!GetParamsForBlob(blob, ¶ms)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BlobChild* actor = BlobChild::Create(aBlob);
|
||||
NS_ENSURE_TRUE(actor, nullptr);
|
||||
|
||||
SendPBlobConstructor(actor, params);
|
||||
|
||||
actor->SetManager(this);
|
||||
|
||||
if (const nsTArray<nsCOMPtr<nsIDOMBlob> >* subBlobs = blob->GetSubBlobs()) {
|
||||
for (uint32_t i = 0; i < subBlobs->Length(); ++i) {
|
||||
BlobConstructorParams subParams;
|
||||
nsDOMFileBase* subBlob =
|
||||
static_cast<nsDOMFileBase*>(subBlobs->ElementAt(i).get());
|
||||
if (!GetParamsForBlob(subBlob, &subParams)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BlobChild* subActor = BlobChild::Create(aBlob);
|
||||
actor->SendPBlobConstructor(subActor, subParams);
|
||||
|
||||
subActor->SetManager(actor);
|
||||
}
|
||||
if (!SendPBlobConstructor(actor, params)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return actor;
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
struct ChromePackage;
|
||||
class nsIDOMBlob;
|
||||
class nsDOMFileBase;
|
||||
class nsIObserver;
|
||||
struct ResourceMapping;
|
||||
struct OverrideMapping;
|
||||
|
@ -199,8 +198,6 @@ public:
|
|||
|
||||
uint64_t GetID() { return mID; }
|
||||
|
||||
bool GetParamsForBlob(nsDOMFileBase* aBlob,
|
||||
BlobConstructorParams* aOutParams);
|
||||
BlobChild* GetOrCreateActorForBlob(nsIDOMBlob* aBlob);
|
||||
|
||||
private:
|
||||
|
|
|
@ -1418,9 +1418,7 @@ ContentParent::DeallocPDeviceStorageRequest(PDeviceStorageRequestParent* doomed)
|
|||
PBlobParent*
|
||||
ContentParent::AllocPBlob(const BlobConstructorParams& aParams)
|
||||
{
|
||||
BlobParent* actor = BlobParent::Create(aParams);
|
||||
actor->SetManager(this);
|
||||
return actor;
|
||||
return BlobParent::Create(aParams);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -1430,42 +1428,56 @@ ContentParent::DeallocPBlob(PBlobParent* aActor)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::GetParamsForBlob(nsDOMFileBase* aBlob,
|
||||
BlobConstructorParams* aOutParams)
|
||||
BlobParent*
|
||||
ContentParent::GetOrCreateActorForBlob(nsIDOMBlob* aBlob)
|
||||
{
|
||||
BlobConstructorParams resultParams;
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(aBlob, "Null pointer!");
|
||||
|
||||
if (!(aBlob->IsMemoryBacked() || aBlob->GetSubBlobs()) &&
|
||||
(aBlob->IsSizeUnknown() || aBlob->IsDateUnknown())) {
|
||||
nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(aBlob);
|
||||
if (remoteBlob) {
|
||||
BlobParent* actor =
|
||||
static_cast<BlobParent*>(
|
||||
static_cast<PBlobParent*>(remoteBlob->GetPBlob()));
|
||||
NS_ASSERTION(actor, "Null actor?!");
|
||||
|
||||
if (static_cast<ContentParent*>(actor->Manager()) == this) {
|
||||
return actor;
|
||||
}
|
||||
}
|
||||
|
||||
// XXX This is only safe so long as all blob implementations in our tree
|
||||
// inherit nsDOMFileBase. If that ever changes then this will need to grow
|
||||
// a real interface or something.
|
||||
const nsDOMFileBase* blob = static_cast<nsDOMFileBase*>(aBlob);
|
||||
|
||||
BlobConstructorParams params;
|
||||
|
||||
if (blob->IsSizeUnknown() || blob->IsDateUnknown()) {
|
||||
// We don't want to call GetSize or GetLastModifiedDate
|
||||
// yet since that may stat a file on the main thread
|
||||
// here. Instead we'll learn the size lazily from the
|
||||
// other process.
|
||||
resultParams = MysteryBlobConstructorParams();
|
||||
params = MysteryBlobConstructorParams();
|
||||
}
|
||||
else {
|
||||
BlobOrFileConstructorParams params;
|
||||
|
||||
nsString contentType;
|
||||
nsresult rv = aBlob->GetType(contentType);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
uint64_t length;
|
||||
rv = aBlob->GetSize(&length);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
nsCOMPtr<nsIDOMFile> file;
|
||||
static_cast<nsIDOMBlob*>(aBlob)->QueryInterface(NS_GET_IID(nsIDOMFile),
|
||||
(void**)getter_AddRefs(file));
|
||||
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(aBlob);
|
||||
if (file) {
|
||||
FileBlobConstructorParams fileParams;
|
||||
|
||||
rv = file->GetName(fileParams.name());
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
rv = file->GetMozLastModifiedDate(&fileParams.modDate());
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
rv = file->GetName(fileParams.name());
|
||||
NS_ENSURE_SUCCESS(rv, nullptr);
|
||||
|
||||
fileParams.contentType() = contentType;
|
||||
fileParams.length() = length;
|
||||
|
@ -1477,63 +1489,6 @@ ContentParent::GetParamsForBlob(nsDOMFileBase* aBlob,
|
|||
blobParams.length() = length;
|
||||
params = blobParams;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(!(aBlob->IsMemoryBacked() &&
|
||||
aBlob->GetSubBlobs()), "Can't be both!");
|
||||
|
||||
if (aBlob->IsMemoryBacked()) {
|
||||
const nsDOMMemoryFile* memoryBlob =
|
||||
static_cast<const nsDOMMemoryFile*>(aBlob);
|
||||
|
||||
FallibleTArray<uint8_t> data;
|
||||
if (!data.SetLength(memoryBlob->GetLength())) {
|
||||
return false;
|
||||
}
|
||||
memcpy(data.Elements(), memoryBlob->GetData(), memoryBlob->GetLength());
|
||||
|
||||
MemoryBlobOrFileConstructorParams memoryParams(params, data);
|
||||
resultParams = memoryParams;
|
||||
}
|
||||
else if (aBlob->GetSubBlobs()) {
|
||||
MultipartBlobOrFileConstructorParams multipartParams(params);
|
||||
resultParams = multipartParams;
|
||||
}
|
||||
else {
|
||||
resultParams = BlobConstructorNoMultipartParams(params);
|
||||
}
|
||||
}
|
||||
|
||||
*aOutParams = resultParams;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
BlobParent*
|
||||
ContentParent::GetOrCreateActorForBlob(nsIDOMBlob* aBlob)
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
NS_ASSERTION(aBlob, "Null pointer!");
|
||||
|
||||
// XXX This is only safe so long as all blob implementations in our tree
|
||||
// inherit nsDOMFileBase. If that ever changes then this will need to grow
|
||||
// a real interface or something.
|
||||
nsDOMFileBase* blob = static_cast<nsDOMFileBase*>(aBlob);
|
||||
|
||||
nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(aBlob);
|
||||
if (remoteBlob) {
|
||||
BlobParent* actor =
|
||||
static_cast<BlobParent*>(
|
||||
static_cast<PBlobParent*>(remoteBlob->GetPBlob()));
|
||||
NS_ASSERTION(actor, "Null actor?!");
|
||||
|
||||
if (actor->ManagerIs(this)) {
|
||||
return actor;
|
||||
}
|
||||
}
|
||||
|
||||
BlobConstructorParams params;
|
||||
if (!GetParamsForBlob(blob, ¶ms)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BlobParent* actor = BlobParent::Create(aBlob);
|
||||
|
@ -1543,26 +1498,6 @@ ContentParent::GetOrCreateActorForBlob(nsIDOMBlob* aBlob)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
actor->SetManager(this);
|
||||
|
||||
if (const nsTArray<nsCOMPtr<nsIDOMBlob> >* subBlobs = blob->GetSubBlobs()) {
|
||||
for (uint32_t i = 0; i < subBlobs->Length(); ++i) {
|
||||
BlobConstructorParams subParams;
|
||||
nsDOMFileBase* subBlob =
|
||||
static_cast<nsDOMFileBase*>(subBlobs->ElementAt(i).get());
|
||||
if (!GetParamsForBlob(subBlob, &subParams)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
BlobParent* subActor = BlobParent::Create(aBlob);
|
||||
if (!actor->SendPBlobConstructor(subActor, subParams)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
subActor->SetManager(actor);
|
||||
}
|
||||
}
|
||||
|
||||
return actor;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
class mozIApplication;
|
||||
class nsConsoleService;
|
||||
class nsIDOMBlob;
|
||||
class nsDOMFileBase;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
|
@ -131,9 +130,8 @@ public:
|
|||
return mSendPermissionUpdates;
|
||||
}
|
||||
|
||||
bool GetParamsForBlob(nsDOMFileBase* aBlob,
|
||||
BlobConstructorParams* aOutParams);
|
||||
BlobParent* GetOrCreateActorForBlob(nsIDOMBlob* aBlob);
|
||||
|
||||
/**
|
||||
* Kill our subprocess and make sure it dies. Should only be used
|
||||
* in emergency situations since it bypasses the normal shutdown
|
||||
|
|
|
@ -31,49 +31,5 @@ struct FileBlobConstructorParams
|
|||
uint64_t modDate;
|
||||
};
|
||||
|
||||
union BlobOrFileConstructorParams
|
||||
{
|
||||
NormalBlobConstructorParams;
|
||||
FileBlobConstructorParams;
|
||||
};
|
||||
|
||||
struct MemoryBlobOrFileConstructorParams
|
||||
{
|
||||
BlobOrFileConstructorParams constructorParams;
|
||||
uint8_t[] data;
|
||||
};
|
||||
|
||||
struct SlicedBlobConstructorParams
|
||||
{
|
||||
PBlob source;
|
||||
uint64_t begin;
|
||||
uint64_t end;
|
||||
nsString contentType;
|
||||
};
|
||||
|
||||
struct MysteryBlobConstructorParams
|
||||
{
|
||||
// Nothing is known about this type of blob.
|
||||
};
|
||||
|
||||
union BlobConstructorNoMultipartParams
|
||||
{
|
||||
BlobOrFileConstructorParams;
|
||||
MemoryBlobOrFileConstructorParams;
|
||||
SlicedBlobConstructorParams;
|
||||
MysteryBlobConstructorParams;
|
||||
};
|
||||
|
||||
struct MultipartBlobOrFileConstructorParams
|
||||
{
|
||||
BlobOrFileConstructorParams constructorParams;
|
||||
};
|
||||
|
||||
union BlobConstructorParams
|
||||
{
|
||||
BlobConstructorNoMultipartParams;
|
||||
MultipartBlobOrFileConstructorParams;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
@ -18,14 +18,12 @@ union ResolveMysteryParams
|
|||
|
||||
protocol PBlob
|
||||
{
|
||||
manager PContent or PBlob;
|
||||
manager PContent;
|
||||
manages PBlobStream;
|
||||
manages PBlob;
|
||||
|
||||
both:
|
||||
__delete__();
|
||||
|
||||
PBlob(BlobConstructorParams params);
|
||||
PBlobStream();
|
||||
|
||||
ResolveMystery(ResolveMysteryParams params);
|
||||
|
|
|
@ -117,6 +117,27 @@ union DeviceStorageParams
|
|||
DeviceStorageStatParams;
|
||||
};
|
||||
|
||||
struct SlicedBlobConstructorParams
|
||||
{
|
||||
PBlob source;
|
||||
uint64_t begin;
|
||||
uint64_t end;
|
||||
nsString contentType;
|
||||
};
|
||||
|
||||
struct MysteryBlobConstructorParams
|
||||
{
|
||||
// Nothing is known about this type of blob.
|
||||
};
|
||||
|
||||
union BlobConstructorParams
|
||||
{
|
||||
NormalBlobConstructorParams;
|
||||
FileBlobConstructorParams;
|
||||
SlicedBlobConstructorParams;
|
||||
MysteryBlobConstructorParams;
|
||||
};
|
||||
|
||||
// An IPCTabContext which corresponds to a PBrowser opened by a child when it
|
||||
// receives window.open().
|
||||
//
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#endif
|
||||
|
||||
#define NS_IREMOTEBLOB_IID \
|
||||
{0x1f569fbc, 0xf588, 0x41c5, {0xa0, 0x73, 0x92, 0x0d, 0xf5, 0x9f, 0x1b, 0xdb}}
|
||||
{0x74ce3cdd, 0xbfc9, 0x4edb, {0x98, 0x26, 0x50, 0xcf, 0x00, 0x26, 0x58, 0x70}}
|
||||
|
||||
class NS_NO_VTABLE nsIRemoteBlob : public nsISupports
|
||||
{
|
||||
|
@ -21,8 +21,6 @@ public:
|
|||
|
||||
// This will either return a PBlobChild or PBlobParent.
|
||||
virtual void* GetPBlob() = 0;
|
||||
|
||||
virtual void SetPBlob(void* aActor) = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIRemoteBlob, NS_IREMOTEBLOB_IID)
|
||||
|
|
|
@ -87,7 +87,7 @@ private:
|
|||
static JSBool
|
||||
Construct(JSContext* aCx, unsigned aArgc, jsval* aVp)
|
||||
{
|
||||
nsRefPtr<nsDOMMultipartFile> file = new nsDOMMultipartFile(EmptyString());
|
||||
nsRefPtr<nsDOMMultipartFile> file = new nsDOMMultipartFile();
|
||||
nsresult rv = file->InitBlob(aCx, aArgc, JS_ARGV(aCx, aVp), Unwrap);
|
||||
if (NS_FAILED(rv)) {
|
||||
ThrowDOMExceptionForNSResult(aCx, rv);
|
||||
|
|
Загрузка…
Ссылка в новой задаче