2012-08-02 10:02:29 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_ipc_Blob_h
|
|
|
|
#define mozilla_dom_ipc_Blob_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/dom/PBlobChild.h"
|
|
|
|
#include "mozilla/dom/PBlobParent.h"
|
|
|
|
#include "mozilla/dom/PBlobStreamChild.h"
|
|
|
|
#include "mozilla/dom/PBlobStreamParent.h"
|
2012-08-16 08:02:32 +04:00
|
|
|
#include "mozilla/dom/PContent.h"
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2012-08-16 08:02:32 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2012-08-02 10:02:29 +04:00
|
|
|
|
|
|
|
class nsIDOMBlob;
|
2012-08-16 08:02:32 +04:00
|
|
|
class nsIIPCSerializableInputStream;
|
|
|
|
class nsIInputStream;
|
2012-08-02 10:02:29 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-01-24 06:39:27 +04:00
|
|
|
|
|
|
|
class ContentParent;
|
|
|
|
class ContentChild;
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
enum ActorFlavorEnum
|
|
|
|
{
|
|
|
|
Parent = 0,
|
|
|
|
Child
|
|
|
|
};
|
|
|
|
|
|
|
|
template <ActorFlavorEnum>
|
2013-01-18 00:17:33 +04:00
|
|
|
struct BlobTraits;
|
2012-08-02 10:02:29 +04:00
|
|
|
|
|
|
|
template <>
|
|
|
|
struct BlobTraits<Parent>
|
|
|
|
{
|
2012-08-16 08:02:32 +04:00
|
|
|
typedef mozilla::dom::PBlobParent ProtocolType;
|
2012-08-02 10:02:29 +04:00
|
|
|
typedef mozilla::dom::PBlobStreamParent StreamType;
|
2013-01-18 00:17:33 +04:00
|
|
|
typedef mozilla::dom::ParentBlobConstructorParams ConstructorParamsType;
|
|
|
|
typedef mozilla::dom::ChildBlobConstructorParams
|
|
|
|
OtherSideConstructorParamsType;
|
2013-01-24 06:39:27 +04:00
|
|
|
typedef mozilla::dom::ContentParent ConcreteContentManagerType;
|
2012-08-16 08:02:32 +04:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// the files are actually opened and closed on a background thread before we
|
|
|
|
// can send their file handles across to the child. The child process could
|
|
|
|
// crash during this process so we need to make sure we cancel the intended
|
|
|
|
// response in such a case. We do that by holding an array of
|
|
|
|
// nsRevocableEventPtr. If the child crashes then this actor will be destroyed
|
|
|
|
// and the nsRevocableEventPtr destructor will cancel any stream events that
|
|
|
|
// are currently in flight.
|
|
|
|
class BaseType : public ProtocolType
|
|
|
|
{
|
2013-01-18 00:17:33 +04:00
|
|
|
public:
|
|
|
|
static const ChildBlobConstructorParams&
|
|
|
|
GetBlobConstructorParams(const ConstructorParamsType& aParams)
|
|
|
|
{
|
|
|
|
return aParams.blobParams();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetBlobConstructorParams(ConstructorParamsType& aParams,
|
|
|
|
const ChildBlobConstructorParams& aBlobParams)
|
|
|
|
{
|
|
|
|
aParams.blobParams() = aBlobParams;
|
|
|
|
aParams.optionalInputStreamParams() = mozilla::void_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetBlobConstructorParams(OtherSideConstructorParamsType& aParams,
|
|
|
|
const ChildBlobConstructorParams& aBlobParams)
|
|
|
|
{
|
|
|
|
aParams = aBlobParams;
|
|
|
|
}
|
|
|
|
|
2012-08-16 08:02:32 +04:00
|
|
|
protected:
|
2013-07-08 19:48:40 +04:00
|
|
|
virtual StreamType*
|
|
|
|
AllocPBlobStreamParent() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DeallocPBlobStreamParent(StreamType* aActor) MOZ_OVERRIDE;
|
|
|
|
|
2012-10-25 22:45:15 +04:00
|
|
|
BaseType();
|
|
|
|
virtual ~BaseType();
|
2012-08-16 08:02:32 +04:00
|
|
|
|
2012-10-25 22:45:15 +04:00
|
|
|
class OpenStreamRunnable;
|
2012-08-16 08:02:32 +04:00
|
|
|
friend class OpenStreamRunnable;
|
|
|
|
|
|
|
|
void
|
|
|
|
NoteRunnableCompleted(OpenStreamRunnable* aRunnable);
|
|
|
|
|
|
|
|
nsTArray<nsRevocableEventPtr<OpenStreamRunnable> > mOpenStreamRunnables;
|
|
|
|
};
|
2012-08-02 10:02:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct BlobTraits<Child>
|
|
|
|
{
|
2012-08-16 08:02:32 +04:00
|
|
|
typedef mozilla::dom::PBlobChild ProtocolType;
|
2012-08-02 10:02:29 +04:00
|
|
|
typedef mozilla::dom::PBlobStreamChild StreamType;
|
2013-01-18 00:17:33 +04:00
|
|
|
typedef mozilla::dom::ChildBlobConstructorParams ConstructorParamsType;
|
|
|
|
typedef mozilla::dom::ParentBlobConstructorParams
|
|
|
|
OtherSideConstructorParamsType;
|
2013-01-24 06:39:27 +04:00
|
|
|
typedef mozilla::dom::ContentChild ConcreteContentManagerType;
|
2013-01-18 00:17:33 +04:00
|
|
|
|
2012-08-16 08:02:32 +04:00
|
|
|
|
|
|
|
class BaseType : public ProtocolType
|
|
|
|
{
|
2013-01-18 00:17:33 +04:00
|
|
|
public:
|
|
|
|
static const ChildBlobConstructorParams&
|
|
|
|
GetBlobConstructorParams(const ConstructorParamsType& aParams)
|
|
|
|
{
|
|
|
|
return aParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetBlobConstructorParams(ConstructorParamsType& aParams,
|
|
|
|
const ChildBlobConstructorParams& aBlobParams)
|
|
|
|
{
|
|
|
|
aParams = aBlobParams;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetBlobConstructorParams(OtherSideConstructorParamsType& aParams,
|
|
|
|
const ChildBlobConstructorParams& aBlobParams)
|
|
|
|
{
|
|
|
|
aParams.blobParams() = aBlobParams;
|
|
|
|
aParams.optionalInputStreamParams() = mozilla::void_t();
|
|
|
|
}
|
|
|
|
|
2012-08-16 08:02:32 +04:00
|
|
|
protected:
|
2013-07-08 19:48:40 +04:00
|
|
|
virtual StreamType*
|
|
|
|
AllocPBlobStreamChild() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual bool
|
|
|
|
DeallocPBlobStreamChild(StreamType* aActor) MOZ_OVERRIDE;
|
|
|
|
|
2012-08-16 08:02:32 +04:00
|
|
|
BaseType()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual ~BaseType()
|
|
|
|
{ }
|
|
|
|
};
|
2012-08-02 10:02:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <ActorFlavorEnum>
|
|
|
|
class RemoteBlob;
|
|
|
|
|
|
|
|
template <ActorFlavorEnum ActorFlavor>
|
|
|
|
class Blob : public BlobTraits<ActorFlavor>::BaseType
|
|
|
|
{
|
2013-01-18 00:17:33 +04:00
|
|
|
friend class RemoteBlob<ActorFlavor>;
|
2012-08-03 10:25:30 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
public:
|
2013-07-17 00:07:09 +04:00
|
|
|
typedef typename BlobTraits<ActorFlavor>::ConcreteContentManagerType ContentManager;
|
2012-08-16 08:02:32 +04:00
|
|
|
typedef typename BlobTraits<ActorFlavor>::ProtocolType ProtocolType;
|
2012-08-02 10:02:29 +04:00
|
|
|
typedef typename BlobTraits<ActorFlavor>::StreamType StreamType;
|
2013-01-18 00:17:33 +04:00
|
|
|
typedef typename BlobTraits<ActorFlavor>::ConstructorParamsType
|
|
|
|
ConstructorParamsType;
|
|
|
|
typedef typename BlobTraits<ActorFlavor>::OtherSideConstructorParamsType
|
|
|
|
OtherSideConstructorParamsType;
|
2012-08-16 08:02:32 +04:00
|
|
|
typedef typename BlobTraits<ActorFlavor>::BaseType BaseType;
|
2012-08-02 10:02:29 +04:00
|
|
|
typedef RemoteBlob<ActorFlavor> RemoteBlobType;
|
|
|
|
typedef mozilla::ipc::IProtocolManager<
|
|
|
|
mozilla::ipc::RPCChannel::RPCListener>::ActorDestroyReason
|
|
|
|
ActorDestroyReason;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsIDOMBlob* mBlob;
|
|
|
|
RemoteBlobType* mRemoteBlob;
|
|
|
|
bool mOwnsBlob;
|
2012-08-03 10:25:30 +04:00
|
|
|
bool mBlobIsFile;
|
2012-08-02 10:02:29 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
// This create function is called on the sending side.
|
|
|
|
static Blob*
|
2013-07-17 00:07:09 +04:00
|
|
|
Create(ContentManager* aManager, nsIDOMBlob* aBlob)
|
2012-08-02 10:02:29 +04:00
|
|
|
{
|
2013-07-17 00:07:09 +04:00
|
|
|
return new Blob(aManager, aBlob);
|
2012-08-02 10:02:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This create function is called on the receiving side.
|
|
|
|
static Blob*
|
2013-07-17 00:07:09 +04:00
|
|
|
Create(ContentManager* aManager, const ConstructorParamsType& aParams);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2012-08-03 10:25:30 +04:00
|
|
|
// Get the blob associated with this actor. This may always be called on the
|
|
|
|
// sending side. It may also be called on the receiving side unless this is a
|
|
|
|
// "mystery" blob that has not yet received a SetMysteryBlobInfo() call.
|
2012-08-02 10:02:29 +04:00
|
|
|
already_AddRefed<nsIDOMBlob>
|
|
|
|
GetBlob();
|
|
|
|
|
2012-08-03 10:25:30 +04:00
|
|
|
// Use this for files.
|
|
|
|
bool
|
|
|
|
SetMysteryBlobInfo(const nsString& aName, const nsString& aContentType,
|
2012-10-18 22:29:32 +04:00
|
|
|
uint64_t aLength, uint64_t aLastModifiedDate);
|
2012-08-03 10:25:30 +04:00
|
|
|
|
|
|
|
// Use this for non-file blobs.
|
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2013-07-17 00:07:09 +04:00
|
|
|
ContentManager* Manager()
|
|
|
|
{
|
|
|
|
return mManager;
|
|
|
|
}
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
private:
|
|
|
|
// This constructor is called on the sending side.
|
2013-07-17 00:07:09 +04:00
|
|
|
Blob(ContentManager* aManager, nsIDOMBlob* aBlob);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2013-01-18 00:17:33 +04:00
|
|
|
// This constructor is called on the receiving side.
|
2013-07-17 00:07:09 +04:00
|
|
|
Blob(ContentManager* aManager, const ConstructorParamsType& aParams);
|
2013-01-18 00:17:33 +04:00
|
|
|
|
|
|
|
static already_AddRefed<RemoteBlobType>
|
|
|
|
CreateRemoteBlob(const ConstructorParamsType& aParams);
|
2012-08-03 10:25:30 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
NoteDyingRemoteBlob();
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
// These methods are only called by the IPDL message machinery.
|
|
|
|
virtual void
|
|
|
|
ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
|
|
|
|
|
2012-08-03 10:25:30 +04:00
|
|
|
virtual bool
|
|
|
|
RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE;
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
virtual bool
|
|
|
|
RecvPBlobStreamConstructor(StreamType* aActor) MOZ_OVERRIDE;
|
2013-07-17 00:07:09 +04:00
|
|
|
|
|
|
|
nsRefPtr<ContentManager> mManager;
|
2012-08-02 10:02:29 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
|
|
|
|
typedef mozilla::dom::ipc::Blob<mozilla::dom::ipc::Child> BlobChild;
|
|
|
|
typedef mozilla::dom::ipc::Blob<mozilla::dom::ipc::Parent> BlobParent;
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-07-08 19:48:40 +04:00
|
|
|
#endif // mozilla_dom_ipc_Blob_h
|