dom/ipc/Blob.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 #ifndef mozilla_dom_ipc_Blob_h
     6 #define mozilla_dom_ipc_Blob_h
     8 #include "mozilla/Attributes.h"
     9 #include "mozilla/dom/PBlobChild.h"
    10 #include "mozilla/dom/PBlobParent.h"
    11 #include "nsAutoPtr.h"
    12 #include "nsTArray.h"
    14 class nsIDOMBlob;
    15 class nsString;
    16 template <class> class nsRevocableEventPtr;
    18 namespace mozilla {
    19 namespace dom {
    21 class ContentChild;
    22 class ContentParent;
    23 class PBlobStreamChild;
    24 class PBlobStreamParent;
    26 class BlobChild MOZ_FINAL
    27   : public PBlobChild
    28 {
    29   friend class ContentChild;
    31   class RemoteBlob;
    32   friend class RemoteBlob;
    34   nsIDOMBlob* mBlob;
    35   RemoteBlob* mRemoteBlob;
    36   nsRefPtr<ContentChild> mStrongManager;
    38   bool mOwnsBlob;
    39   bool mBlobIsFile;
    41 public:
    42   // This create function is called on the sending side.
    43   static BlobChild*
    44   Create(ContentChild* aManager, nsIDOMBlob* aBlob)
    45   {
    46     return new BlobChild(aManager, aBlob);
    47   }
    49   // Get the blob associated with this actor. This may always be called on the
    50   // sending side. It may also be called on the receiving side unless this is a
    51   // "mystery" blob that has not yet received a SetMysteryBlobInfo() call.
    52   already_AddRefed<nsIDOMBlob>
    53   GetBlob();
    55   // Use this for files.
    56   bool
    57   SetMysteryBlobInfo(const nsString& aName,
    58                      const nsString& aContentType,
    59                      uint64_t aLength,
    60                      uint64_t aLastModifiedDate);
    62   // Use this for non-file blobs.
    63   bool
    64   SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength);
    66 private:
    67   // This constructor is called on the sending side.
    68   BlobChild(ContentChild* aManager, nsIDOMBlob* aBlob);
    70   // This constructor is called on the receiving side.
    71   BlobChild(ContentChild* aManager, const ChildBlobConstructorParams& aParams);
    73   // Only destroyed by ContentChild.
    74   ~BlobChild();
    76   // This create function is called on the receiving side by ContentChild.
    77   static BlobChild*
    78   Create(ContentChild* aManager, const ChildBlobConstructorParams& aParams);
    80   static already_AddRefed<RemoteBlob>
    81   CreateRemoteBlob(const ChildBlobConstructorParams& aParams);
    83   void
    84   NoteDyingRemoteBlob();
    86   // These methods are only called by the IPDL message machinery.
    87   virtual void
    88   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
    90   virtual bool
    91   RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE;
    93   virtual PBlobStreamChild*
    94   AllocPBlobStreamChild() MOZ_OVERRIDE;
    96   virtual bool
    97   RecvPBlobStreamConstructor(PBlobStreamChild* aActor) MOZ_OVERRIDE;
    99   virtual bool
   100   DeallocPBlobStreamChild(PBlobStreamChild* aActor) MOZ_OVERRIDE;
   101 };
   103 class BlobParent MOZ_FINAL
   104   : public PBlobParent
   105 {
   106   friend class ContentParent;
   108   class OpenStreamRunnable;
   109   friend class OpenStreamRunnable;
   111   class RemoteBlob;
   112   friend class RemoteBlob;
   114   nsIDOMBlob* mBlob;
   115   RemoteBlob* mRemoteBlob;
   116   nsRefPtr<ContentParent> mStrongManager;
   118   // nsIInputStreams backed by files must ensure that the files are actually
   119   // opened and closed on a background thread before we can send their file
   120   // handles across to the child. The child process could crash during this
   121   // process so we need to make sure we cancel the intended response in such a
   122   // case. We do that by holding an array of nsRevocableEventPtr. If the child
   123   // crashes then this actor will be destroyed and the nsRevocableEventPtr
   124   // destructor will cancel any stream events that are currently in flight.
   125   nsTArray<nsRevocableEventPtr<OpenStreamRunnable>> mOpenStreamRunnables;
   127   bool mOwnsBlob;
   128   bool mBlobIsFile;
   130 public:
   131   // This create function is called on the sending side.
   132   static BlobParent*
   133   Create(ContentParent* aManager, nsIDOMBlob* aBlob)
   134   {
   135     return new BlobParent(aManager, aBlob);
   136   }
   138   // Get the blob associated with this actor. This may always be called on the
   139   // sending side. It may also be called on the receiving side unless this is a
   140   // "mystery" blob that has not yet received a SetMysteryBlobInfo() call.
   141   already_AddRefed<nsIDOMBlob>
   142   GetBlob();
   144   // Use this for files.
   145   bool
   146   SetMysteryBlobInfo(const nsString& aName, const nsString& aContentType,
   147                      uint64_t aLength, uint64_t aLastModifiedDate);
   149   // Use this for non-file blobs.
   150   bool
   151   SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength);
   153 private:
   154   // This constructor is called on the sending side.
   155   BlobParent(ContentParent* aManager, nsIDOMBlob* aBlob);
   157   // This constructor is called on the receiving side.
   158   BlobParent(ContentParent* aManager,
   159              const ParentBlobConstructorParams& aParams);
   161   ~BlobParent();
   163   // This create function is called on the receiving side by ContentParent.
   164   static BlobParent*
   165   Create(ContentParent* aManager, const ParentBlobConstructorParams& aParams);
   167   static already_AddRefed<RemoteBlob>
   168   CreateRemoteBlob(const ParentBlobConstructorParams& aParams);
   170   void
   171   NoteDyingRemoteBlob();
   173   void
   174   NoteRunnableCompleted(OpenStreamRunnable* aRunnable);
   176   // These methods are only called by the IPDL message machinery.
   177   virtual void
   178   ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
   180   virtual PBlobStreamParent*
   181   AllocPBlobStreamParent() MOZ_OVERRIDE;
   183   virtual bool
   184   RecvPBlobStreamConstructor(PBlobStreamParent* aActor) MOZ_OVERRIDE;
   186   virtual bool
   187   DeallocPBlobStreamParent(PBlobStreamParent* aActor) MOZ_OVERRIDE;
   189   virtual bool
   190   RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE;
   191 };
   193 } // namespace dom
   194 } // namespace mozilla
   196 #endif // mozilla_dom_ipc_Blob_h

mercurial