michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_ipc_Blob_h michael@0: #define mozilla_dom_ipc_Blob_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/dom/PBlobChild.h" michael@0: #include "mozilla/dom/PBlobParent.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsTArray.h" michael@0: michael@0: class nsIDOMBlob; michael@0: class nsString; michael@0: template class nsRevocableEventPtr; michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: class ContentChild; michael@0: class ContentParent; michael@0: class PBlobStreamChild; michael@0: class PBlobStreamParent; michael@0: michael@0: class BlobChild MOZ_FINAL michael@0: : public PBlobChild michael@0: { michael@0: friend class ContentChild; michael@0: michael@0: class RemoteBlob; michael@0: friend class RemoteBlob; michael@0: michael@0: nsIDOMBlob* mBlob; michael@0: RemoteBlob* mRemoteBlob; michael@0: nsRefPtr mStrongManager; michael@0: michael@0: bool mOwnsBlob; michael@0: bool mBlobIsFile; michael@0: michael@0: public: michael@0: // This create function is called on the sending side. michael@0: static BlobChild* michael@0: Create(ContentChild* aManager, nsIDOMBlob* aBlob) michael@0: { michael@0: return new BlobChild(aManager, aBlob); michael@0: } michael@0: michael@0: // Get the blob associated with this actor. This may always be called on the michael@0: // sending side. It may also be called on the receiving side unless this is a michael@0: // "mystery" blob that has not yet received a SetMysteryBlobInfo() call. michael@0: already_AddRefed michael@0: GetBlob(); michael@0: michael@0: // Use this for files. michael@0: bool michael@0: SetMysteryBlobInfo(const nsString& aName, michael@0: const nsString& aContentType, michael@0: uint64_t aLength, michael@0: uint64_t aLastModifiedDate); michael@0: michael@0: // Use this for non-file blobs. michael@0: bool michael@0: SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength); michael@0: michael@0: private: michael@0: // This constructor is called on the sending side. michael@0: BlobChild(ContentChild* aManager, nsIDOMBlob* aBlob); michael@0: michael@0: // This constructor is called on the receiving side. michael@0: BlobChild(ContentChild* aManager, const ChildBlobConstructorParams& aParams); michael@0: michael@0: // Only destroyed by ContentChild. michael@0: ~BlobChild(); michael@0: michael@0: // This create function is called on the receiving side by ContentChild. michael@0: static BlobChild* michael@0: Create(ContentChild* aManager, const ChildBlobConstructorParams& aParams); michael@0: michael@0: static already_AddRefed michael@0: CreateRemoteBlob(const ChildBlobConstructorParams& aParams); michael@0: michael@0: void michael@0: NoteDyingRemoteBlob(); michael@0: michael@0: // These methods are only called by the IPDL message machinery. michael@0: virtual void michael@0: ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE; michael@0: michael@0: virtual PBlobStreamChild* michael@0: AllocPBlobStreamChild() MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: RecvPBlobStreamConstructor(PBlobStreamChild* aActor) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: DeallocPBlobStreamChild(PBlobStreamChild* aActor) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: class BlobParent MOZ_FINAL michael@0: : public PBlobParent michael@0: { michael@0: friend class ContentParent; michael@0: michael@0: class OpenStreamRunnable; michael@0: friend class OpenStreamRunnable; michael@0: michael@0: class RemoteBlob; michael@0: friend class RemoteBlob; michael@0: michael@0: nsIDOMBlob* mBlob; michael@0: RemoteBlob* mRemoteBlob; michael@0: nsRefPtr mStrongManager; michael@0: michael@0: // nsIInputStreams backed by files must ensure that the files are actually michael@0: // opened and closed on a background thread before we can send their file michael@0: // handles across to the child. The child process could crash during this michael@0: // process so we need to make sure we cancel the intended response in such a michael@0: // case. We do that by holding an array of nsRevocableEventPtr. If the child michael@0: // crashes then this actor will be destroyed and the nsRevocableEventPtr michael@0: // destructor will cancel any stream events that are currently in flight. michael@0: nsTArray> mOpenStreamRunnables; michael@0: michael@0: bool mOwnsBlob; michael@0: bool mBlobIsFile; michael@0: michael@0: public: michael@0: // This create function is called on the sending side. michael@0: static BlobParent* michael@0: Create(ContentParent* aManager, nsIDOMBlob* aBlob) michael@0: { michael@0: return new BlobParent(aManager, aBlob); michael@0: } michael@0: michael@0: // Get the blob associated with this actor. This may always be called on the michael@0: // sending side. It may also be called on the receiving side unless this is a michael@0: // "mystery" blob that has not yet received a SetMysteryBlobInfo() call. michael@0: already_AddRefed michael@0: GetBlob(); michael@0: michael@0: // Use this for files. michael@0: bool michael@0: SetMysteryBlobInfo(const nsString& aName, const nsString& aContentType, michael@0: uint64_t aLength, uint64_t aLastModifiedDate); michael@0: michael@0: // Use this for non-file blobs. michael@0: bool michael@0: SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength); michael@0: michael@0: private: michael@0: // This constructor is called on the sending side. michael@0: BlobParent(ContentParent* aManager, nsIDOMBlob* aBlob); michael@0: michael@0: // This constructor is called on the receiving side. michael@0: BlobParent(ContentParent* aManager, michael@0: const ParentBlobConstructorParams& aParams); michael@0: michael@0: ~BlobParent(); michael@0: michael@0: // This create function is called on the receiving side by ContentParent. michael@0: static BlobParent* michael@0: Create(ContentParent* aManager, const ParentBlobConstructorParams& aParams); michael@0: michael@0: static already_AddRefed michael@0: CreateRemoteBlob(const ParentBlobConstructorParams& aParams); michael@0: michael@0: void michael@0: NoteDyingRemoteBlob(); michael@0: michael@0: void michael@0: NoteRunnableCompleted(OpenStreamRunnable* aRunnable); michael@0: michael@0: // These methods are only called by the IPDL message machinery. michael@0: virtual void michael@0: ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; michael@0: michael@0: virtual PBlobStreamParent* michael@0: AllocPBlobStreamParent() MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: RecvPBlobStreamConstructor(PBlobStreamParent* aActor) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: DeallocPBlobStreamParent(PBlobStreamParent* aActor) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_dom_ipc_Blob_h