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