dom/ipc/Blob.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/ipc/Blob.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,196 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef mozilla_dom_ipc_Blob_h
     1.9 +#define mozilla_dom_ipc_Blob_h
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "mozilla/dom/PBlobChild.h"
    1.13 +#include "mozilla/dom/PBlobParent.h"
    1.14 +#include "nsAutoPtr.h"
    1.15 +#include "nsTArray.h"
    1.16 +
    1.17 +class nsIDOMBlob;
    1.18 +class nsString;
    1.19 +template <class> class nsRevocableEventPtr;
    1.20 +
    1.21 +namespace mozilla {
    1.22 +namespace dom {
    1.23 +
    1.24 +class ContentChild;
    1.25 +class ContentParent;
    1.26 +class PBlobStreamChild;
    1.27 +class PBlobStreamParent;
    1.28 +
    1.29 +class BlobChild MOZ_FINAL
    1.30 +  : public PBlobChild
    1.31 +{
    1.32 +  friend class ContentChild;
    1.33 +
    1.34 +  class RemoteBlob;
    1.35 +  friend class RemoteBlob;
    1.36 +
    1.37 +  nsIDOMBlob* mBlob;
    1.38 +  RemoteBlob* mRemoteBlob;
    1.39 +  nsRefPtr<ContentChild> mStrongManager;
    1.40 +
    1.41 +  bool mOwnsBlob;
    1.42 +  bool mBlobIsFile;
    1.43 +
    1.44 +public:
    1.45 +  // This create function is called on the sending side.
    1.46 +  static BlobChild*
    1.47 +  Create(ContentChild* aManager, nsIDOMBlob* aBlob)
    1.48 +  {
    1.49 +    return new BlobChild(aManager, aBlob);
    1.50 +  }
    1.51 +
    1.52 +  // Get the blob associated with this actor. This may always be called on the
    1.53 +  // sending side. It may also be called on the receiving side unless this is a
    1.54 +  // "mystery" blob that has not yet received a SetMysteryBlobInfo() call.
    1.55 +  already_AddRefed<nsIDOMBlob>
    1.56 +  GetBlob();
    1.57 +
    1.58 +  // Use this for files.
    1.59 +  bool
    1.60 +  SetMysteryBlobInfo(const nsString& aName,
    1.61 +                     const nsString& aContentType,
    1.62 +                     uint64_t aLength,
    1.63 +                     uint64_t aLastModifiedDate);
    1.64 +
    1.65 +  // Use this for non-file blobs.
    1.66 +  bool
    1.67 +  SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength);
    1.68 +
    1.69 +private:
    1.70 +  // This constructor is called on the sending side.
    1.71 +  BlobChild(ContentChild* aManager, nsIDOMBlob* aBlob);
    1.72 +
    1.73 +  // This constructor is called on the receiving side.
    1.74 +  BlobChild(ContentChild* aManager, const ChildBlobConstructorParams& aParams);
    1.75 +
    1.76 +  // Only destroyed by ContentChild.
    1.77 +  ~BlobChild();
    1.78 +
    1.79 +  // This create function is called on the receiving side by ContentChild.
    1.80 +  static BlobChild*
    1.81 +  Create(ContentChild* aManager, const ChildBlobConstructorParams& aParams);
    1.82 +
    1.83 +  static already_AddRefed<RemoteBlob>
    1.84 +  CreateRemoteBlob(const ChildBlobConstructorParams& aParams);
    1.85 +
    1.86 +  void
    1.87 +  NoteDyingRemoteBlob();
    1.88 +
    1.89 +  // These methods are only called by the IPDL message machinery.
    1.90 +  virtual void
    1.91 +  ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
    1.92 +
    1.93 +  virtual bool
    1.94 +  RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE;
    1.95 +
    1.96 +  virtual PBlobStreamChild*
    1.97 +  AllocPBlobStreamChild() MOZ_OVERRIDE;
    1.98 +
    1.99 +  virtual bool
   1.100 +  RecvPBlobStreamConstructor(PBlobStreamChild* aActor) MOZ_OVERRIDE;
   1.101 +
   1.102 +  virtual bool
   1.103 +  DeallocPBlobStreamChild(PBlobStreamChild* aActor) MOZ_OVERRIDE;
   1.104 +};
   1.105 +
   1.106 +class BlobParent MOZ_FINAL
   1.107 +  : public PBlobParent
   1.108 +{
   1.109 +  friend class ContentParent;
   1.110 +
   1.111 +  class OpenStreamRunnable;
   1.112 +  friend class OpenStreamRunnable;
   1.113 +
   1.114 +  class RemoteBlob;
   1.115 +  friend class RemoteBlob;
   1.116 +
   1.117 +  nsIDOMBlob* mBlob;
   1.118 +  RemoteBlob* mRemoteBlob;
   1.119 +  nsRefPtr<ContentParent> mStrongManager;
   1.120 +
   1.121 +  // nsIInputStreams backed by files must ensure that the files are actually
   1.122 +  // opened and closed on a background thread before we can send their file
   1.123 +  // handles across to the child. The child process could crash during this
   1.124 +  // process so we need to make sure we cancel the intended response in such a
   1.125 +  // case. We do that by holding an array of nsRevocableEventPtr. If the child
   1.126 +  // crashes then this actor will be destroyed and the nsRevocableEventPtr
   1.127 +  // destructor will cancel any stream events that are currently in flight.
   1.128 +  nsTArray<nsRevocableEventPtr<OpenStreamRunnable>> mOpenStreamRunnables;
   1.129 +
   1.130 +  bool mOwnsBlob;
   1.131 +  bool mBlobIsFile;
   1.132 +
   1.133 +public:
   1.134 +  // This create function is called on the sending side.
   1.135 +  static BlobParent*
   1.136 +  Create(ContentParent* aManager, nsIDOMBlob* aBlob)
   1.137 +  {
   1.138 +    return new BlobParent(aManager, aBlob);
   1.139 +  }
   1.140 +
   1.141 +  // Get the blob associated with this actor. This may always be called on the
   1.142 +  // sending side. It may also be called on the receiving side unless this is a
   1.143 +  // "mystery" blob that has not yet received a SetMysteryBlobInfo() call.
   1.144 +  already_AddRefed<nsIDOMBlob>
   1.145 +  GetBlob();
   1.146 +
   1.147 +  // Use this for files.
   1.148 +  bool
   1.149 +  SetMysteryBlobInfo(const nsString& aName, const nsString& aContentType,
   1.150 +                     uint64_t aLength, uint64_t aLastModifiedDate);
   1.151 +
   1.152 +  // Use this for non-file blobs.
   1.153 +  bool
   1.154 +  SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength);
   1.155 +
   1.156 +private:
   1.157 +  // This constructor is called on the sending side.
   1.158 +  BlobParent(ContentParent* aManager, nsIDOMBlob* aBlob);
   1.159 +
   1.160 +  // This constructor is called on the receiving side.
   1.161 +  BlobParent(ContentParent* aManager,
   1.162 +             const ParentBlobConstructorParams& aParams);
   1.163 +
   1.164 +  ~BlobParent();
   1.165 +
   1.166 +  // This create function is called on the receiving side by ContentParent.
   1.167 +  static BlobParent*
   1.168 +  Create(ContentParent* aManager, const ParentBlobConstructorParams& aParams);
   1.169 +
   1.170 +  static already_AddRefed<RemoteBlob>
   1.171 +  CreateRemoteBlob(const ParentBlobConstructorParams& aParams);
   1.172 +
   1.173 +  void
   1.174 +  NoteDyingRemoteBlob();
   1.175 +
   1.176 +  void
   1.177 +  NoteRunnableCompleted(OpenStreamRunnable* aRunnable);
   1.178 +
   1.179 +  // These methods are only called by the IPDL message machinery.
   1.180 +  virtual void
   1.181 +  ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
   1.182 +
   1.183 +  virtual PBlobStreamParent*
   1.184 +  AllocPBlobStreamParent() MOZ_OVERRIDE;
   1.185 +
   1.186 +  virtual bool
   1.187 +  RecvPBlobStreamConstructor(PBlobStreamParent* aActor) MOZ_OVERRIDE;
   1.188 +
   1.189 +  virtual bool
   1.190 +  DeallocPBlobStreamParent(PBlobStreamParent* aActor) MOZ_OVERRIDE;
   1.191 +
   1.192 +  virtual bool
   1.193 +  RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE;
   1.194 +};
   1.195 +
   1.196 +} // namespace dom
   1.197 +} // namespace mozilla
   1.198 +
   1.199 +#endif // mozilla_dom_ipc_Blob_h

mercurial