|
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 file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef mozilla_dom_indexeddb_ipc_indexeddbparent_h__ |
|
6 #define mozilla_dom_indexeddb_ipc_indexeddbparent_h__ |
|
7 |
|
8 #include "mozilla/Attributes.h" |
|
9 #include "mozilla/DebugOnly.h" |
|
10 |
|
11 #include "mozilla/dom/indexedDB/IndexedDatabase.h" |
|
12 |
|
13 #include "mozilla/dom/indexedDB/PIndexedDBParent.h" |
|
14 #include "mozilla/dom/indexedDB/PIndexedDBCursorParent.h" |
|
15 #include "mozilla/dom/indexedDB/PIndexedDBDatabaseParent.h" |
|
16 #include "mozilla/dom/indexedDB/PIndexedDBDeleteDatabaseRequestParent.h" |
|
17 #include "mozilla/dom/indexedDB/PIndexedDBIndexParent.h" |
|
18 #include "mozilla/dom/indexedDB/PIndexedDBObjectStoreParent.h" |
|
19 #include "mozilla/dom/indexedDB/PIndexedDBRequestParent.h" |
|
20 #include "mozilla/dom/indexedDB/PIndexedDBTransactionParent.h" |
|
21 |
|
22 #include "nsIDOMEventListener.h" |
|
23 |
|
24 namespace mozilla { |
|
25 namespace dom { |
|
26 class ContentParent; |
|
27 class PBlobParent; |
|
28 class TabParent; |
|
29 } |
|
30 } |
|
31 |
|
32 class nsIDOMBlob; |
|
33 class nsIDOMEvent; |
|
34 |
|
35 BEGIN_INDEXEDDB_NAMESPACE |
|
36 |
|
37 class IDBCursor; |
|
38 class IDBDatabase; |
|
39 class IDBFactory; |
|
40 class IDBIndex; |
|
41 class IDBObjectStore; |
|
42 class IDBOpenDBRequest; |
|
43 class IDBTransaction; |
|
44 |
|
45 class IndexedDBCursorParent; |
|
46 class IndexedDBDatabaseParent; |
|
47 class IndexedDBDeleteDatabaseRequestParent; |
|
48 class IndexedDBIndexParent; |
|
49 class IndexedDBObjectStoreParent; |
|
50 class IndexedDBTransactionParent; |
|
51 class IndexedDBVersionChangeTransactionParent; |
|
52 class IndexedDBVersionChangeObjectStoreParent; |
|
53 |
|
54 /******************************************************************************* |
|
55 * AutoSetCurrentTransaction |
|
56 ******************************************************************************/ |
|
57 |
|
58 class AutoSetCurrentTransaction |
|
59 { |
|
60 public: |
|
61 AutoSetCurrentTransaction(IDBTransaction* aTransaction); |
|
62 ~AutoSetCurrentTransaction(); |
|
63 }; |
|
64 |
|
65 /******************************************************************************* |
|
66 * WeakEventListener |
|
67 ******************************************************************************/ |
|
68 |
|
69 class WeakEventListenerBase : public nsIDOMEventListener |
|
70 { |
|
71 public: |
|
72 NS_DECL_ISUPPORTS |
|
73 NS_DECL_NSIDOMEVENTLISTENER |
|
74 |
|
75 protected: |
|
76 WeakEventListenerBase() |
|
77 { } |
|
78 |
|
79 virtual ~WeakEventListenerBase() |
|
80 { } |
|
81 }; |
|
82 |
|
83 template <class T> |
|
84 class WeakEventListener : public WeakEventListenerBase |
|
85 { |
|
86 T* mActor; |
|
87 |
|
88 public: |
|
89 WeakEventListener(T* aActor) |
|
90 : mActor(aActor) |
|
91 { } |
|
92 |
|
93 void |
|
94 NoteDyingActor() |
|
95 { |
|
96 mActor = nullptr; |
|
97 } |
|
98 |
|
99 NS_IMETHOD |
|
100 HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE |
|
101 { |
|
102 return mActor ? mActor->HandleEvent(aEvent) : NS_OK; |
|
103 } |
|
104 |
|
105 protected: |
|
106 virtual ~WeakEventListener() |
|
107 { } |
|
108 }; |
|
109 |
|
110 template <class T> |
|
111 class AutoWeakEventListener |
|
112 { |
|
113 nsRefPtr<WeakEventListener<T> > mEventListener; |
|
114 |
|
115 public: |
|
116 AutoWeakEventListener(T* aActor) |
|
117 { |
|
118 mEventListener = new WeakEventListener<T>(aActor); |
|
119 } |
|
120 |
|
121 ~AutoWeakEventListener() |
|
122 { |
|
123 mEventListener->NoteDyingActor(); |
|
124 } |
|
125 |
|
126 template <class U> |
|
127 operator U*() |
|
128 { |
|
129 return mEventListener; |
|
130 } |
|
131 |
|
132 T* |
|
133 operator ->() |
|
134 { |
|
135 return mEventListener; |
|
136 } |
|
137 }; |
|
138 |
|
139 /******************************************************************************* |
|
140 * IndexedDBParent |
|
141 ******************************************************************************/ |
|
142 |
|
143 class IndexedDBParent : private PIndexedDBParent |
|
144 { |
|
145 friend class mozilla::dom::ContentParent; |
|
146 friend class mozilla::dom::TabParent; |
|
147 friend class IndexedDBDatabaseParent; |
|
148 friend class IndexedDBDeleteDatabaseRequestParent; |
|
149 |
|
150 nsRefPtr<IDBFactory> mFactory; |
|
151 nsCString mASCIIOrigin; |
|
152 |
|
153 ContentParent* mManagerContent; |
|
154 TabParent* mManagerTab; |
|
155 |
|
156 bool mDisconnected; |
|
157 |
|
158 public: |
|
159 IndexedDBParent(ContentParent* aContentParent); |
|
160 IndexedDBParent(TabParent* aTabParent); |
|
161 |
|
162 virtual ~IndexedDBParent(); |
|
163 |
|
164 const nsCString& |
|
165 GetASCIIOrigin() const |
|
166 { |
|
167 return mASCIIOrigin; |
|
168 } |
|
169 |
|
170 void |
|
171 Disconnect(); |
|
172 |
|
173 bool |
|
174 IsDisconnected() const |
|
175 { |
|
176 return mDisconnected; |
|
177 } |
|
178 |
|
179 ContentParent* |
|
180 GetManagerContent() const |
|
181 { |
|
182 return mManagerContent; |
|
183 } |
|
184 |
|
185 TabParent* |
|
186 GetManagerTab() const |
|
187 { |
|
188 return mManagerTab; |
|
189 } |
|
190 |
|
191 bool |
|
192 CheckReadPermission(const nsAString& aDatabaseName); |
|
193 |
|
194 bool |
|
195 CheckWritePermission(const nsAString& aDatabaseName); |
|
196 |
|
197 mozilla::ipc::IProtocol* |
|
198 CloneProtocol(Channel* aChannel, |
|
199 mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE; |
|
200 |
|
201 protected: |
|
202 bool |
|
203 CheckPermissionInternal(const nsAString& aDatabaseName, |
|
204 const nsACString& aPermission); |
|
205 |
|
206 virtual void |
|
207 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
208 |
|
209 virtual bool |
|
210 RecvPIndexedDBDatabaseConstructor(PIndexedDBDatabaseParent* aActor, |
|
211 const nsString& aName, |
|
212 const uint64_t& aVersion, |
|
213 const PersistenceType& aPersistenceType) |
|
214 MOZ_OVERRIDE; |
|
215 |
|
216 virtual bool |
|
217 RecvPIndexedDBDeleteDatabaseRequestConstructor( |
|
218 PIndexedDBDeleteDatabaseRequestParent* aActor, |
|
219 const nsString& aName, |
|
220 const PersistenceType& aPersistenceType) |
|
221 MOZ_OVERRIDE; |
|
222 |
|
223 virtual PIndexedDBDatabaseParent* |
|
224 AllocPIndexedDBDatabaseParent(const nsString& aName, const uint64_t& aVersion, |
|
225 const PersistenceType& aPersistenceType) |
|
226 MOZ_OVERRIDE; |
|
227 |
|
228 virtual bool |
|
229 DeallocPIndexedDBDatabaseParent(PIndexedDBDatabaseParent* aActor) MOZ_OVERRIDE; |
|
230 |
|
231 virtual PIndexedDBDeleteDatabaseRequestParent* |
|
232 AllocPIndexedDBDeleteDatabaseRequestParent( |
|
233 const nsString& aName, |
|
234 const PersistenceType& aPersistenceType) |
|
235 MOZ_OVERRIDE; |
|
236 |
|
237 virtual bool |
|
238 DeallocPIndexedDBDeleteDatabaseRequestParent( |
|
239 PIndexedDBDeleteDatabaseRequestParent* aActor) |
|
240 MOZ_OVERRIDE; |
|
241 }; |
|
242 |
|
243 /******************************************************************************* |
|
244 * IndexedDBDatabaseParent |
|
245 ******************************************************************************/ |
|
246 |
|
247 class IndexedDBDatabaseParent : private PIndexedDBDatabaseParent |
|
248 { |
|
249 friend class IndexedDBParent; |
|
250 friend class IndexedDBTransactionParent; |
|
251 friend class IndexedDBVersionChangeTransactionParent; |
|
252 |
|
253 AutoWeakEventListener<IndexedDBDatabaseParent> mEventListener; |
|
254 |
|
255 nsRefPtr<IDBOpenDBRequest> mOpenRequest; |
|
256 nsRefPtr<IDBDatabase> mDatabase; |
|
257 |
|
258 public: |
|
259 IndexedDBDatabaseParent(); |
|
260 virtual ~IndexedDBDatabaseParent(); |
|
261 |
|
262 nsresult |
|
263 SetOpenRequest(IDBOpenDBRequest* aRequest); |
|
264 |
|
265 nsresult |
|
266 HandleEvent(nsIDOMEvent* aEvent); |
|
267 |
|
268 void |
|
269 Disconnect(); |
|
270 |
|
271 bool |
|
272 IsDisconnected() const |
|
273 { |
|
274 return static_cast<IndexedDBParent*>(Manager())->IsDisconnected(); |
|
275 } |
|
276 |
|
277 bool |
|
278 CheckWritePermission(const nsAString& aDatabaseName); |
|
279 |
|
280 void |
|
281 Invalidate(); |
|
282 |
|
283 protected: |
|
284 nsresult |
|
285 HandleRequestEvent(nsIDOMEvent* aEvent, const nsAString& aType); |
|
286 |
|
287 nsresult |
|
288 HandleDatabaseEvent(nsIDOMEvent* aEvent, const nsAString& aType); |
|
289 |
|
290 virtual void |
|
291 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
292 |
|
293 virtual bool |
|
294 RecvClose(const bool& aUnlinked) MOZ_OVERRIDE; |
|
295 |
|
296 virtual bool |
|
297 RecvPIndexedDBTransactionConstructor(PIndexedDBTransactionParent* aActor, |
|
298 const TransactionParams& aParams) |
|
299 MOZ_OVERRIDE; |
|
300 |
|
301 virtual PIndexedDBTransactionParent* |
|
302 AllocPIndexedDBTransactionParent(const TransactionParams& aParams) MOZ_OVERRIDE; |
|
303 |
|
304 virtual bool |
|
305 DeallocPIndexedDBTransactionParent(PIndexedDBTransactionParent* aActor) |
|
306 MOZ_OVERRIDE; |
|
307 }; |
|
308 |
|
309 /******************************************************************************* |
|
310 * IndexedDBTransactionParent |
|
311 ******************************************************************************/ |
|
312 |
|
313 class IndexedDBTransactionParent : protected PIndexedDBTransactionParent |
|
314 { |
|
315 friend class IndexedDBCursorParent; |
|
316 friend class IndexedDBDatabaseParent; |
|
317 friend class IndexedDBObjectStoreParent; |
|
318 |
|
319 protected: |
|
320 AutoWeakEventListener<IndexedDBTransactionParent> mEventListener; |
|
321 |
|
322 nsRefPtr<IDBTransaction> mTransaction; |
|
323 |
|
324 bool mArtificialRequestCount; |
|
325 |
|
326 public: |
|
327 IndexedDBTransactionParent(); |
|
328 virtual ~IndexedDBTransactionParent(); |
|
329 |
|
330 bool |
|
331 IsDisconnected() const |
|
332 { |
|
333 return static_cast<IndexedDBDatabaseParent*>(Manager())->IsDisconnected(); |
|
334 } |
|
335 |
|
336 nsresult |
|
337 SetTransaction(IDBTransaction* aTransaction); |
|
338 |
|
339 IDBTransaction* |
|
340 GetTransaction() const |
|
341 { |
|
342 return mTransaction; |
|
343 } |
|
344 |
|
345 nsresult |
|
346 HandleEvent(nsIDOMEvent* aEvent); |
|
347 |
|
348 protected: |
|
349 virtual void |
|
350 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
351 |
|
352 virtual bool |
|
353 RecvAbort(const nsresult& aAbortCode) MOZ_OVERRIDE; |
|
354 |
|
355 virtual bool |
|
356 RecvAllRequestsFinished() MOZ_OVERRIDE; |
|
357 |
|
358 virtual bool |
|
359 RecvDeleteObjectStore(const nsString& aName) MOZ_OVERRIDE; |
|
360 |
|
361 virtual bool |
|
362 RecvPIndexedDBObjectStoreConstructor( |
|
363 PIndexedDBObjectStoreParent* aActor, |
|
364 const ObjectStoreConstructorParams& aParams) |
|
365 MOZ_OVERRIDE; |
|
366 |
|
367 virtual PIndexedDBObjectStoreParent* |
|
368 AllocPIndexedDBObjectStoreParent(const ObjectStoreConstructorParams& aParams) |
|
369 MOZ_OVERRIDE; |
|
370 |
|
371 virtual bool |
|
372 DeallocPIndexedDBObjectStoreParent(PIndexedDBObjectStoreParent* aActor) |
|
373 MOZ_OVERRIDE; |
|
374 }; |
|
375 |
|
376 /******************************************************************************* |
|
377 * IndexedDBVersionChangeTransactionParent |
|
378 ******************************************************************************/ |
|
379 |
|
380 class IndexedDBVersionChangeTransactionParent : |
|
381 public IndexedDBTransactionParent |
|
382 { |
|
383 friend class IndexedDBVersionChangeObjectStoreParent; |
|
384 |
|
385 public: |
|
386 IndexedDBVersionChangeTransactionParent(); |
|
387 virtual ~IndexedDBVersionChangeTransactionParent(); |
|
388 |
|
389 bool |
|
390 IsDisconnected() const |
|
391 { |
|
392 return static_cast<IndexedDBDatabaseParent*>(Manager())->IsDisconnected(); |
|
393 } |
|
394 |
|
395 protected: |
|
396 virtual bool |
|
397 RecvDeleteObjectStore(const nsString& aName) MOZ_OVERRIDE; |
|
398 |
|
399 virtual bool |
|
400 RecvPIndexedDBObjectStoreConstructor( |
|
401 PIndexedDBObjectStoreParent* aActor, |
|
402 const ObjectStoreConstructorParams& aParams) |
|
403 MOZ_OVERRIDE; |
|
404 |
|
405 virtual PIndexedDBObjectStoreParent* |
|
406 AllocPIndexedDBObjectStoreParent(const ObjectStoreConstructorParams& aParams) |
|
407 MOZ_OVERRIDE; |
|
408 }; |
|
409 |
|
410 /******************************************************************************* |
|
411 * IndexedDBCursorParent |
|
412 ******************************************************************************/ |
|
413 |
|
414 class IndexedDBCursorParent : private PIndexedDBCursorParent |
|
415 { |
|
416 friend class IndexedDBIndexParent; |
|
417 friend class IndexedDBObjectStoreParent; |
|
418 |
|
419 nsRefPtr<IDBCursor> mCursor; |
|
420 |
|
421 public: |
|
422 IDBCursor* |
|
423 GetCursor() const |
|
424 { |
|
425 return mCursor; |
|
426 } |
|
427 |
|
428 bool |
|
429 IsDisconnected() const; |
|
430 |
|
431 protected: |
|
432 IndexedDBCursorParent(IDBCursor* aCursor); |
|
433 virtual ~IndexedDBCursorParent(); |
|
434 |
|
435 virtual void |
|
436 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
437 |
|
438 virtual bool |
|
439 RecvPIndexedDBRequestConstructor(PIndexedDBRequestParent* aActor, |
|
440 const CursorRequestParams& aParams) |
|
441 MOZ_OVERRIDE; |
|
442 |
|
443 virtual PIndexedDBRequestParent* |
|
444 AllocPIndexedDBRequestParent(const CursorRequestParams& aParams) MOZ_OVERRIDE; |
|
445 |
|
446 virtual bool |
|
447 DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) MOZ_OVERRIDE; |
|
448 }; |
|
449 |
|
450 /******************************************************************************* |
|
451 * IndexedDBObjectStoreParent |
|
452 ******************************************************************************/ |
|
453 |
|
454 class IndexedDBObjectStoreParent : protected PIndexedDBObjectStoreParent |
|
455 { |
|
456 friend class IndexedDBIndexParent; |
|
457 friend class IndexedDBTransactionParent; |
|
458 friend class IndexedDBVersionChangeTransactionParent; |
|
459 |
|
460 typedef mozilla::dom::indexedDB::ipc::OpenCursorResponse OpenCursorResponse; |
|
461 |
|
462 protected: |
|
463 nsRefPtr<IDBObjectStore> mObjectStore; |
|
464 |
|
465 public: |
|
466 IndexedDBObjectStoreParent(); |
|
467 virtual ~IndexedDBObjectStoreParent(); |
|
468 |
|
469 void |
|
470 SetObjectStore(IDBObjectStore* aObjectStore); |
|
471 |
|
472 IDBObjectStore* |
|
473 GetObjectStore() const |
|
474 { |
|
475 return mObjectStore; |
|
476 } |
|
477 |
|
478 bool |
|
479 IsDisconnected() const |
|
480 { |
|
481 IndexedDBTransactionParent* manager = |
|
482 static_cast<IndexedDBTransactionParent*>(Manager()); |
|
483 return manager->IsDisconnected(); |
|
484 } |
|
485 |
|
486 // Ordinarily callers could just do this manually using |
|
487 // PIndexedDBObjectStoreParent::SendPIndexedDBCursorConstructor but we're |
|
488 // inheriting the abstract protocol class privately to prevent outside code |
|
489 // from sending messages without checking the disconnected state. Therefore |
|
490 // we need a helper method. |
|
491 bool |
|
492 OpenCursor(IDBCursor* aCursor, |
|
493 const ObjectStoreCursorConstructorParams& aParams, |
|
494 OpenCursorResponse& aResponse) NS_WARN_UNUSED_RESULT |
|
495 { |
|
496 if (IsDisconnected()) { |
|
497 return true; |
|
498 } |
|
499 |
|
500 IndexedDBCursorParent* cursorActor = new IndexedDBCursorParent(aCursor); |
|
501 |
|
502 if (!SendPIndexedDBCursorConstructor(cursorActor, aParams)) { |
|
503 return false; |
|
504 } |
|
505 |
|
506 aResponse = cursorActor; |
|
507 return true; |
|
508 } |
|
509 |
|
510 protected: |
|
511 virtual void |
|
512 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
513 |
|
514 virtual bool |
|
515 RecvDeleteIndex(const nsString& aName) MOZ_OVERRIDE; |
|
516 |
|
517 virtual bool |
|
518 RecvPIndexedDBRequestConstructor(PIndexedDBRequestParent* aActor, |
|
519 const ObjectStoreRequestParams& aParams) |
|
520 MOZ_OVERRIDE; |
|
521 |
|
522 virtual bool |
|
523 RecvPIndexedDBIndexConstructor(PIndexedDBIndexParent* aActor, |
|
524 const IndexConstructorParams& aParams) |
|
525 MOZ_OVERRIDE; |
|
526 |
|
527 virtual PIndexedDBRequestParent* |
|
528 AllocPIndexedDBRequestParent(const ObjectStoreRequestParams& aParams) MOZ_OVERRIDE; |
|
529 |
|
530 virtual bool |
|
531 DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) MOZ_OVERRIDE; |
|
532 |
|
533 virtual PIndexedDBIndexParent* |
|
534 AllocPIndexedDBIndexParent(const IndexConstructorParams& aParams) MOZ_OVERRIDE; |
|
535 |
|
536 virtual bool |
|
537 DeallocPIndexedDBIndexParent(PIndexedDBIndexParent* aActor) MOZ_OVERRIDE; |
|
538 |
|
539 virtual PIndexedDBCursorParent* |
|
540 AllocPIndexedDBCursorParent(const ObjectStoreCursorConstructorParams& aParams) |
|
541 MOZ_OVERRIDE; |
|
542 |
|
543 virtual bool |
|
544 DeallocPIndexedDBCursorParent(PIndexedDBCursorParent* aActor) MOZ_OVERRIDE; |
|
545 }; |
|
546 |
|
547 /******************************************************************************* |
|
548 * IndexedDBVersionChangeObjectStoreParent |
|
549 ******************************************************************************/ |
|
550 |
|
551 class IndexedDBVersionChangeObjectStoreParent : |
|
552 public IndexedDBObjectStoreParent |
|
553 { |
|
554 friend class IndexedDBVersionChangeTransactionParent; |
|
555 |
|
556 public: |
|
557 IndexedDBVersionChangeObjectStoreParent(); |
|
558 virtual ~IndexedDBVersionChangeObjectStoreParent(); |
|
559 |
|
560 protected: |
|
561 bool |
|
562 IsDisconnected() const |
|
563 { |
|
564 IndexedDBVersionChangeTransactionParent* manager = |
|
565 static_cast<IndexedDBVersionChangeTransactionParent*>(Manager()); |
|
566 return manager->IsDisconnected(); |
|
567 } |
|
568 |
|
569 virtual bool |
|
570 RecvDeleteIndex(const nsString& aName) MOZ_OVERRIDE; |
|
571 |
|
572 virtual bool |
|
573 RecvPIndexedDBIndexConstructor(PIndexedDBIndexParent* aActor, |
|
574 const IndexConstructorParams& aParams) |
|
575 MOZ_OVERRIDE; |
|
576 }; |
|
577 |
|
578 /******************************************************************************* |
|
579 * IndexedDBIndexParent |
|
580 ******************************************************************************/ |
|
581 |
|
582 class IndexedDBIndexParent : private PIndexedDBIndexParent |
|
583 { |
|
584 friend class IndexedDBObjectStoreParent; |
|
585 friend class IndexedDBVersionChangeObjectStoreParent; |
|
586 |
|
587 typedef mozilla::dom::indexedDB::ipc::OpenCursorResponse OpenCursorResponse; |
|
588 |
|
589 nsRefPtr<IDBIndex> mIndex; |
|
590 |
|
591 public: |
|
592 IndexedDBIndexParent(); |
|
593 virtual ~IndexedDBIndexParent(); |
|
594 |
|
595 void |
|
596 SetIndex(IDBIndex* aObjectStore); |
|
597 |
|
598 IDBIndex* |
|
599 GetIndex() const |
|
600 { |
|
601 return mIndex; |
|
602 } |
|
603 |
|
604 // Ordinarily callers could just do this manually using |
|
605 // PIndexedDBIndexParent::SendPIndexedDBCursorConstructor but we're |
|
606 // inheriting the abstract protocol class privately to prevent outside code |
|
607 // from sending messages without checking the disconnected state. Therefore |
|
608 // we need a helper method. |
|
609 bool |
|
610 OpenCursor(IDBCursor* aCursor, const IndexCursorConstructorParams& aParams, |
|
611 OpenCursorResponse& aResponse) NS_WARN_UNUSED_RESULT |
|
612 { |
|
613 if (IsDisconnected()) { |
|
614 return true; |
|
615 } |
|
616 |
|
617 IndexedDBCursorParent* cursorActor = new IndexedDBCursorParent(aCursor); |
|
618 |
|
619 if (!SendPIndexedDBCursorConstructor(cursorActor, aParams)) { |
|
620 return false; |
|
621 } |
|
622 |
|
623 aResponse = cursorActor; |
|
624 return true; |
|
625 } |
|
626 |
|
627 bool |
|
628 IsDisconnected() const |
|
629 { |
|
630 IndexedDBObjectStoreParent* manager = |
|
631 static_cast<IndexedDBObjectStoreParent*>(Manager()); |
|
632 return manager->IsDisconnected(); |
|
633 } |
|
634 |
|
635 protected: |
|
636 virtual void |
|
637 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
638 |
|
639 virtual bool |
|
640 RecvPIndexedDBRequestConstructor(PIndexedDBRequestParent* aActor, |
|
641 const IndexRequestParams& aParams) |
|
642 MOZ_OVERRIDE; |
|
643 |
|
644 virtual PIndexedDBRequestParent* |
|
645 AllocPIndexedDBRequestParent(const IndexRequestParams& aParams) MOZ_OVERRIDE; |
|
646 |
|
647 virtual bool |
|
648 DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) MOZ_OVERRIDE; |
|
649 |
|
650 virtual PIndexedDBCursorParent* |
|
651 AllocPIndexedDBCursorParent(const IndexCursorConstructorParams& aParams) |
|
652 MOZ_OVERRIDE; |
|
653 |
|
654 virtual bool |
|
655 DeallocPIndexedDBCursorParent(PIndexedDBCursorParent* aActor) MOZ_OVERRIDE; |
|
656 }; |
|
657 |
|
658 /******************************************************************************* |
|
659 * IndexedDBRequestParentBase |
|
660 ******************************************************************************/ |
|
661 |
|
662 class IndexedDBRequestParentBase : public PIndexedDBRequestParent |
|
663 { |
|
664 public: |
|
665 bool |
|
666 SendResponse(const ResponseValue& aResponse) NS_WARN_UNUSED_RESULT |
|
667 { |
|
668 if (IsDisconnected()) { |
|
669 return true; |
|
670 } |
|
671 |
|
672 return Send__delete__(this, aResponse); |
|
673 } |
|
674 |
|
675 protected: |
|
676 // Don't let anyone call this directly, instead go through SendResponse. |
|
677 using PIndexedDBRequestParent::Send__delete__; |
|
678 |
|
679 typedef ipc::ResponseValue ResponseValue; |
|
680 typedef PIndexedDBRequestParent::PBlobParent PBlobParent; |
|
681 |
|
682 nsRefPtr<IDBRequest> mRequest; |
|
683 |
|
684 IndexedDBRequestParentBase(); |
|
685 virtual ~IndexedDBRequestParentBase(); |
|
686 |
|
687 virtual void |
|
688 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; |
|
689 |
|
690 virtual bool |
|
691 IsDisconnected() = 0; |
|
692 }; |
|
693 |
|
694 /******************************************************************************* |
|
695 * IndexedDBObjectStoreRequestParent |
|
696 ******************************************************************************/ |
|
697 |
|
698 class IndexedDBObjectStoreRequestParent : public IndexedDBRequestParentBase |
|
699 { |
|
700 friend class IndexedDBObjectStoreParent; |
|
701 |
|
702 nsRefPtr<IDBObjectStore> mObjectStore; |
|
703 |
|
704 typedef ipc::ObjectStoreRequestParams ParamsUnionType; |
|
705 typedef ParamsUnionType::Type RequestType; |
|
706 DebugOnly<RequestType> mRequestType; |
|
707 |
|
708 typedef ipc::AddParams AddParams; |
|
709 typedef ipc::PutParams PutParams; |
|
710 typedef ipc::ClearParams ClearParams; |
|
711 typedef ipc::DeleteParams DeleteParams; |
|
712 typedef ipc::GetParams GetParams; |
|
713 typedef ipc::GetAllParams GetAllParams; |
|
714 typedef ipc::GetAllKeysParams GetAllKeysParams; |
|
715 typedef ipc::CountParams CountParams; |
|
716 typedef ipc::OpenCursorParams OpenCursorParams; |
|
717 typedef ipc::OpenKeyCursorParams OpenKeyCursorParams; |
|
718 |
|
719 public: |
|
720 IndexedDBObjectStoreRequestParent(IDBObjectStore* aObjectStore, |
|
721 RequestType aRequestType); |
|
722 virtual ~IndexedDBObjectStoreRequestParent(); |
|
723 |
|
724 bool |
|
725 Get(const GetParams& aParams); |
|
726 |
|
727 bool |
|
728 GetAll(const GetAllParams& aParams); |
|
729 |
|
730 bool |
|
731 GetAllKeys(const GetAllKeysParams& aParams); |
|
732 |
|
733 bool |
|
734 Add(const AddParams& aParams); |
|
735 |
|
736 bool |
|
737 Put(const PutParams& aParams); |
|
738 |
|
739 bool |
|
740 Delete(const DeleteParams& aParams); |
|
741 |
|
742 bool |
|
743 Clear(const ClearParams& aParams); |
|
744 |
|
745 bool |
|
746 Count(const CountParams& aParams); |
|
747 |
|
748 bool |
|
749 OpenCursor(const OpenCursorParams& aParams); |
|
750 |
|
751 bool |
|
752 OpenKeyCursor(const OpenKeyCursorParams& aParams); |
|
753 |
|
754 protected: |
|
755 void |
|
756 ConvertBlobActors(const InfallibleTArray<PBlobParent*>& aActors, |
|
757 nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs); |
|
758 |
|
759 private: |
|
760 virtual bool |
|
761 IsDisconnected() MOZ_OVERRIDE; |
|
762 }; |
|
763 |
|
764 /******************************************************************************* |
|
765 * IndexedDBIndexRequestParent |
|
766 ******************************************************************************/ |
|
767 |
|
768 class IndexedDBIndexRequestParent : public IndexedDBRequestParentBase |
|
769 { |
|
770 friend class IndexedDBIndexParent; |
|
771 |
|
772 nsRefPtr<IDBIndex> mIndex; |
|
773 |
|
774 typedef ipc::IndexRequestParams ParamsUnionType; |
|
775 typedef ParamsUnionType::Type RequestType; |
|
776 DebugOnly<RequestType> mRequestType; |
|
777 |
|
778 typedef ipc::GetKeyParams GetKeyParams; |
|
779 typedef ipc::GetAllKeysParams GetAllKeysParams; |
|
780 typedef ipc::OpenKeyCursorParams OpenKeyCursorParams; |
|
781 typedef ipc::GetParams GetParams; |
|
782 typedef ipc::GetAllParams GetAllParams; |
|
783 typedef ipc::CountParams CountParams; |
|
784 typedef ipc::OpenCursorParams OpenCursorParams; |
|
785 |
|
786 public: |
|
787 IndexedDBIndexRequestParent(IDBIndex* aIndex, RequestType aRequestType); |
|
788 virtual ~IndexedDBIndexRequestParent(); |
|
789 |
|
790 bool |
|
791 Get(const GetParams& aParams); |
|
792 |
|
793 bool |
|
794 GetKey(const GetKeyParams& aParams); |
|
795 |
|
796 bool |
|
797 GetAll(const GetAllParams& aParams); |
|
798 |
|
799 bool |
|
800 GetAllKeys(const GetAllKeysParams& aParams); |
|
801 |
|
802 bool |
|
803 Count(const CountParams& aParams); |
|
804 |
|
805 bool |
|
806 OpenCursor(const OpenCursorParams& aParams); |
|
807 |
|
808 bool |
|
809 OpenKeyCursor(const OpenKeyCursorParams& aParams); |
|
810 |
|
811 private: |
|
812 virtual bool |
|
813 IsDisconnected() MOZ_OVERRIDE; |
|
814 }; |
|
815 |
|
816 /******************************************************************************* |
|
817 * IndexedDBCursorRequestParent |
|
818 ******************************************************************************/ |
|
819 |
|
820 class IndexedDBCursorRequestParent : public IndexedDBRequestParentBase |
|
821 { |
|
822 friend class IndexedDBCursorParent; |
|
823 |
|
824 nsRefPtr<IDBCursor> mCursor; |
|
825 |
|
826 typedef ipc::CursorRequestParams ParamsUnionType; |
|
827 typedef ParamsUnionType::Type RequestType; |
|
828 DebugOnly<RequestType> mRequestType; |
|
829 |
|
830 typedef ipc::ContinueParams ContinueParams; |
|
831 |
|
832 public: |
|
833 IndexedDBCursorRequestParent(IDBCursor* aCursor, RequestType aRequestType); |
|
834 virtual ~IndexedDBCursorRequestParent(); |
|
835 |
|
836 bool |
|
837 Continue(const ContinueParams& aParams); |
|
838 |
|
839 private: |
|
840 virtual bool |
|
841 IsDisconnected() MOZ_OVERRIDE; |
|
842 }; |
|
843 |
|
844 /******************************************************************************* |
|
845 * IndexedDBDeleteDatabaseRequestParent |
|
846 ******************************************************************************/ |
|
847 |
|
848 class IndexedDBDeleteDatabaseRequestParent : |
|
849 private PIndexedDBDeleteDatabaseRequestParent |
|
850 { |
|
851 friend class IndexedDBParent; |
|
852 |
|
853 AutoWeakEventListener<IndexedDBDeleteDatabaseRequestParent> mEventListener; |
|
854 |
|
855 nsRefPtr<IDBFactory> mFactory; |
|
856 nsRefPtr<IDBOpenDBRequest> mOpenRequest; |
|
857 |
|
858 public: |
|
859 nsresult |
|
860 HandleEvent(nsIDOMEvent* aEvent); |
|
861 |
|
862 protected: |
|
863 IndexedDBDeleteDatabaseRequestParent(IDBFactory* aFactory); |
|
864 virtual ~IndexedDBDeleteDatabaseRequestParent(); |
|
865 |
|
866 nsresult |
|
867 SetOpenRequest(IDBOpenDBRequest* aOpenRequest); |
|
868 |
|
869 bool |
|
870 IsDisconnected() const |
|
871 { |
|
872 return static_cast<IndexedDBParent*>(Manager())->IsDisconnected(); |
|
873 } |
|
874 }; |
|
875 |
|
876 END_INDEXEDDB_NAMESPACE |
|
877 |
|
878 #endif // mozilla_dom_indexeddb_ipc_indexeddbparent_h__ |