|
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/. */ |
|
4 |
|
5 #ifndef mozilla_dom_ipc_Blob_h |
|
6 #define mozilla_dom_ipc_Blob_h |
|
7 |
|
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" |
|
13 |
|
14 class nsIDOMBlob; |
|
15 class nsString; |
|
16 template <class> class nsRevocableEventPtr; |
|
17 |
|
18 namespace mozilla { |
|
19 namespace dom { |
|
20 |
|
21 class ContentChild; |
|
22 class ContentParent; |
|
23 class PBlobStreamChild; |
|
24 class PBlobStreamParent; |
|
25 |
|
26 class BlobChild MOZ_FINAL |
|
27 : public PBlobChild |
|
28 { |
|
29 friend class ContentChild; |
|
30 |
|
31 class RemoteBlob; |
|
32 friend class RemoteBlob; |
|
33 |
|
34 nsIDOMBlob* mBlob; |
|
35 RemoteBlob* mRemoteBlob; |
|
36 nsRefPtr<ContentChild> mStrongManager; |
|
37 |
|
38 bool mOwnsBlob; |
|
39 bool mBlobIsFile; |
|
40 |
|
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 } |
|
48 |
|
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(); |
|
54 |
|
55 // Use this for files. |
|
56 bool |
|
57 SetMysteryBlobInfo(const nsString& aName, |
|
58 const nsString& aContentType, |
|
59 uint64_t aLength, |
|
60 uint64_t aLastModifiedDate); |
|
61 |
|
62 // Use this for non-file blobs. |
|
63 bool |
|
64 SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength); |
|
65 |
|
66 private: |
|
67 // This constructor is called on the sending side. |
|
68 BlobChild(ContentChild* aManager, nsIDOMBlob* aBlob); |
|
69 |
|
70 // This constructor is called on the receiving side. |
|
71 BlobChild(ContentChild* aManager, const ChildBlobConstructorParams& aParams); |
|
72 |
|
73 // Only destroyed by ContentChild. |
|
74 ~BlobChild(); |
|
75 |
|
76 // This create function is called on the receiving side by ContentChild. |
|
77 static BlobChild* |
|
78 Create(ContentChild* aManager, const ChildBlobConstructorParams& aParams); |
|
79 |
|
80 static already_AddRefed<RemoteBlob> |
|
81 CreateRemoteBlob(const ChildBlobConstructorParams& aParams); |
|
82 |
|
83 void |
|
84 NoteDyingRemoteBlob(); |
|
85 |
|
86 // These methods are only called by the IPDL message machinery. |
|
87 virtual void |
|
88 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
89 |
|
90 virtual bool |
|
91 RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE; |
|
92 |
|
93 virtual PBlobStreamChild* |
|
94 AllocPBlobStreamChild() MOZ_OVERRIDE; |
|
95 |
|
96 virtual bool |
|
97 RecvPBlobStreamConstructor(PBlobStreamChild* aActor) MOZ_OVERRIDE; |
|
98 |
|
99 virtual bool |
|
100 DeallocPBlobStreamChild(PBlobStreamChild* aActor) MOZ_OVERRIDE; |
|
101 }; |
|
102 |
|
103 class BlobParent MOZ_FINAL |
|
104 : public PBlobParent |
|
105 { |
|
106 friend class ContentParent; |
|
107 |
|
108 class OpenStreamRunnable; |
|
109 friend class OpenStreamRunnable; |
|
110 |
|
111 class RemoteBlob; |
|
112 friend class RemoteBlob; |
|
113 |
|
114 nsIDOMBlob* mBlob; |
|
115 RemoteBlob* mRemoteBlob; |
|
116 nsRefPtr<ContentParent> mStrongManager; |
|
117 |
|
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; |
|
126 |
|
127 bool mOwnsBlob; |
|
128 bool mBlobIsFile; |
|
129 |
|
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 } |
|
137 |
|
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(); |
|
143 |
|
144 // Use this for files. |
|
145 bool |
|
146 SetMysteryBlobInfo(const nsString& aName, const nsString& aContentType, |
|
147 uint64_t aLength, uint64_t aLastModifiedDate); |
|
148 |
|
149 // Use this for non-file blobs. |
|
150 bool |
|
151 SetMysteryBlobInfo(const nsString& aContentType, uint64_t aLength); |
|
152 |
|
153 private: |
|
154 // This constructor is called on the sending side. |
|
155 BlobParent(ContentParent* aManager, nsIDOMBlob* aBlob); |
|
156 |
|
157 // This constructor is called on the receiving side. |
|
158 BlobParent(ContentParent* aManager, |
|
159 const ParentBlobConstructorParams& aParams); |
|
160 |
|
161 ~BlobParent(); |
|
162 |
|
163 // This create function is called on the receiving side by ContentParent. |
|
164 static BlobParent* |
|
165 Create(ContentParent* aManager, const ParentBlobConstructorParams& aParams); |
|
166 |
|
167 static already_AddRefed<RemoteBlob> |
|
168 CreateRemoteBlob(const ParentBlobConstructorParams& aParams); |
|
169 |
|
170 void |
|
171 NoteDyingRemoteBlob(); |
|
172 |
|
173 void |
|
174 NoteRunnableCompleted(OpenStreamRunnable* aRunnable); |
|
175 |
|
176 // These methods are only called by the IPDL message machinery. |
|
177 virtual void |
|
178 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
179 |
|
180 virtual PBlobStreamParent* |
|
181 AllocPBlobStreamParent() MOZ_OVERRIDE; |
|
182 |
|
183 virtual bool |
|
184 RecvPBlobStreamConstructor(PBlobStreamParent* aActor) MOZ_OVERRIDE; |
|
185 |
|
186 virtual bool |
|
187 DeallocPBlobStreamParent(PBlobStreamParent* aActor) MOZ_OVERRIDE; |
|
188 |
|
189 virtual bool |
|
190 RecvResolveMystery(const ResolveMysteryParams& aParams) MOZ_OVERRIDE; |
|
191 }; |
|
192 |
|
193 } // namespace dom |
|
194 } // namespace mozilla |
|
195 |
|
196 #endif // mozilla_dom_ipc_Blob_h |