1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/ipc/IndexedDBParent.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,878 @@ 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 file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifndef mozilla_dom_indexeddb_ipc_indexeddbparent_h__ 1.9 +#define mozilla_dom_indexeddb_ipc_indexeddbparent_h__ 1.10 + 1.11 +#include "mozilla/Attributes.h" 1.12 +#include "mozilla/DebugOnly.h" 1.13 + 1.14 +#include "mozilla/dom/indexedDB/IndexedDatabase.h" 1.15 + 1.16 +#include "mozilla/dom/indexedDB/PIndexedDBParent.h" 1.17 +#include "mozilla/dom/indexedDB/PIndexedDBCursorParent.h" 1.18 +#include "mozilla/dom/indexedDB/PIndexedDBDatabaseParent.h" 1.19 +#include "mozilla/dom/indexedDB/PIndexedDBDeleteDatabaseRequestParent.h" 1.20 +#include "mozilla/dom/indexedDB/PIndexedDBIndexParent.h" 1.21 +#include "mozilla/dom/indexedDB/PIndexedDBObjectStoreParent.h" 1.22 +#include "mozilla/dom/indexedDB/PIndexedDBRequestParent.h" 1.23 +#include "mozilla/dom/indexedDB/PIndexedDBTransactionParent.h" 1.24 + 1.25 +#include "nsIDOMEventListener.h" 1.26 + 1.27 +namespace mozilla { 1.28 +namespace dom { 1.29 +class ContentParent; 1.30 +class PBlobParent; 1.31 +class TabParent; 1.32 +} 1.33 +} 1.34 + 1.35 +class nsIDOMBlob; 1.36 +class nsIDOMEvent; 1.37 + 1.38 +BEGIN_INDEXEDDB_NAMESPACE 1.39 + 1.40 +class IDBCursor; 1.41 +class IDBDatabase; 1.42 +class IDBFactory; 1.43 +class IDBIndex; 1.44 +class IDBObjectStore; 1.45 +class IDBOpenDBRequest; 1.46 +class IDBTransaction; 1.47 + 1.48 +class IndexedDBCursorParent; 1.49 +class IndexedDBDatabaseParent; 1.50 +class IndexedDBDeleteDatabaseRequestParent; 1.51 +class IndexedDBIndexParent; 1.52 +class IndexedDBObjectStoreParent; 1.53 +class IndexedDBTransactionParent; 1.54 +class IndexedDBVersionChangeTransactionParent; 1.55 +class IndexedDBVersionChangeObjectStoreParent; 1.56 + 1.57 +/******************************************************************************* 1.58 + * AutoSetCurrentTransaction 1.59 + ******************************************************************************/ 1.60 + 1.61 +class AutoSetCurrentTransaction 1.62 +{ 1.63 +public: 1.64 + AutoSetCurrentTransaction(IDBTransaction* aTransaction); 1.65 + ~AutoSetCurrentTransaction(); 1.66 +}; 1.67 + 1.68 +/******************************************************************************* 1.69 + * WeakEventListener 1.70 + ******************************************************************************/ 1.71 + 1.72 +class WeakEventListenerBase : public nsIDOMEventListener 1.73 +{ 1.74 +public: 1.75 + NS_DECL_ISUPPORTS 1.76 + NS_DECL_NSIDOMEVENTLISTENER 1.77 + 1.78 +protected: 1.79 + WeakEventListenerBase() 1.80 + { } 1.81 + 1.82 + virtual ~WeakEventListenerBase() 1.83 + { } 1.84 +}; 1.85 + 1.86 +template <class T> 1.87 +class WeakEventListener : public WeakEventListenerBase 1.88 +{ 1.89 + T* mActor; 1.90 + 1.91 +public: 1.92 + WeakEventListener(T* aActor) 1.93 + : mActor(aActor) 1.94 + { } 1.95 + 1.96 + void 1.97 + NoteDyingActor() 1.98 + { 1.99 + mActor = nullptr; 1.100 + } 1.101 + 1.102 + NS_IMETHOD 1.103 + HandleEvent(nsIDOMEvent* aEvent) MOZ_OVERRIDE 1.104 + { 1.105 + return mActor ? mActor->HandleEvent(aEvent) : NS_OK; 1.106 + } 1.107 + 1.108 +protected: 1.109 + virtual ~WeakEventListener() 1.110 + { } 1.111 +}; 1.112 + 1.113 +template <class T> 1.114 +class AutoWeakEventListener 1.115 +{ 1.116 + nsRefPtr<WeakEventListener<T> > mEventListener; 1.117 + 1.118 +public: 1.119 + AutoWeakEventListener(T* aActor) 1.120 + { 1.121 + mEventListener = new WeakEventListener<T>(aActor); 1.122 + } 1.123 + 1.124 + ~AutoWeakEventListener() 1.125 + { 1.126 + mEventListener->NoteDyingActor(); 1.127 + } 1.128 + 1.129 + template <class U> 1.130 + operator U*() 1.131 + { 1.132 + return mEventListener; 1.133 + } 1.134 + 1.135 + T* 1.136 + operator ->() 1.137 + { 1.138 + return mEventListener; 1.139 + } 1.140 +}; 1.141 + 1.142 +/******************************************************************************* 1.143 + * IndexedDBParent 1.144 + ******************************************************************************/ 1.145 + 1.146 +class IndexedDBParent : private PIndexedDBParent 1.147 +{ 1.148 + friend class mozilla::dom::ContentParent; 1.149 + friend class mozilla::dom::TabParent; 1.150 + friend class IndexedDBDatabaseParent; 1.151 + friend class IndexedDBDeleteDatabaseRequestParent; 1.152 + 1.153 + nsRefPtr<IDBFactory> mFactory; 1.154 + nsCString mASCIIOrigin; 1.155 + 1.156 + ContentParent* mManagerContent; 1.157 + TabParent* mManagerTab; 1.158 + 1.159 + bool mDisconnected; 1.160 + 1.161 +public: 1.162 + IndexedDBParent(ContentParent* aContentParent); 1.163 + IndexedDBParent(TabParent* aTabParent); 1.164 + 1.165 + virtual ~IndexedDBParent(); 1.166 + 1.167 + const nsCString& 1.168 + GetASCIIOrigin() const 1.169 + { 1.170 + return mASCIIOrigin; 1.171 + } 1.172 + 1.173 + void 1.174 + Disconnect(); 1.175 + 1.176 + bool 1.177 + IsDisconnected() const 1.178 + { 1.179 + return mDisconnected; 1.180 + } 1.181 + 1.182 + ContentParent* 1.183 + GetManagerContent() const 1.184 + { 1.185 + return mManagerContent; 1.186 + } 1.187 + 1.188 + TabParent* 1.189 + GetManagerTab() const 1.190 + { 1.191 + return mManagerTab; 1.192 + } 1.193 + 1.194 + bool 1.195 + CheckReadPermission(const nsAString& aDatabaseName); 1.196 + 1.197 + bool 1.198 + CheckWritePermission(const nsAString& aDatabaseName); 1.199 + 1.200 + mozilla::ipc::IProtocol* 1.201 + CloneProtocol(Channel* aChannel, 1.202 + mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE; 1.203 + 1.204 +protected: 1.205 + bool 1.206 + CheckPermissionInternal(const nsAString& aDatabaseName, 1.207 + const nsACString& aPermission); 1.208 + 1.209 + virtual void 1.210 + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; 1.211 + 1.212 + virtual bool 1.213 + RecvPIndexedDBDatabaseConstructor(PIndexedDBDatabaseParent* aActor, 1.214 + const nsString& aName, 1.215 + const uint64_t& aVersion, 1.216 + const PersistenceType& aPersistenceType) 1.217 + MOZ_OVERRIDE; 1.218 + 1.219 + virtual bool 1.220 + RecvPIndexedDBDeleteDatabaseRequestConstructor( 1.221 + PIndexedDBDeleteDatabaseRequestParent* aActor, 1.222 + const nsString& aName, 1.223 + const PersistenceType& aPersistenceType) 1.224 + MOZ_OVERRIDE; 1.225 + 1.226 + virtual PIndexedDBDatabaseParent* 1.227 + AllocPIndexedDBDatabaseParent(const nsString& aName, const uint64_t& aVersion, 1.228 + const PersistenceType& aPersistenceType) 1.229 + MOZ_OVERRIDE; 1.230 + 1.231 + virtual bool 1.232 + DeallocPIndexedDBDatabaseParent(PIndexedDBDatabaseParent* aActor) MOZ_OVERRIDE; 1.233 + 1.234 + virtual PIndexedDBDeleteDatabaseRequestParent* 1.235 + AllocPIndexedDBDeleteDatabaseRequestParent( 1.236 + const nsString& aName, 1.237 + const PersistenceType& aPersistenceType) 1.238 + MOZ_OVERRIDE; 1.239 + 1.240 + virtual bool 1.241 + DeallocPIndexedDBDeleteDatabaseRequestParent( 1.242 + PIndexedDBDeleteDatabaseRequestParent* aActor) 1.243 + MOZ_OVERRIDE; 1.244 +}; 1.245 + 1.246 +/******************************************************************************* 1.247 + * IndexedDBDatabaseParent 1.248 + ******************************************************************************/ 1.249 + 1.250 +class IndexedDBDatabaseParent : private PIndexedDBDatabaseParent 1.251 +{ 1.252 + friend class IndexedDBParent; 1.253 + friend class IndexedDBTransactionParent; 1.254 + friend class IndexedDBVersionChangeTransactionParent; 1.255 + 1.256 + AutoWeakEventListener<IndexedDBDatabaseParent> mEventListener; 1.257 + 1.258 + nsRefPtr<IDBOpenDBRequest> mOpenRequest; 1.259 + nsRefPtr<IDBDatabase> mDatabase; 1.260 + 1.261 +public: 1.262 + IndexedDBDatabaseParent(); 1.263 + virtual ~IndexedDBDatabaseParent(); 1.264 + 1.265 + nsresult 1.266 + SetOpenRequest(IDBOpenDBRequest* aRequest); 1.267 + 1.268 + nsresult 1.269 + HandleEvent(nsIDOMEvent* aEvent); 1.270 + 1.271 + void 1.272 + Disconnect(); 1.273 + 1.274 + bool 1.275 + IsDisconnected() const 1.276 + { 1.277 + return static_cast<IndexedDBParent*>(Manager())->IsDisconnected(); 1.278 + } 1.279 + 1.280 + bool 1.281 + CheckWritePermission(const nsAString& aDatabaseName); 1.282 + 1.283 + void 1.284 + Invalidate(); 1.285 + 1.286 +protected: 1.287 + nsresult 1.288 + HandleRequestEvent(nsIDOMEvent* aEvent, const nsAString& aType); 1.289 + 1.290 + nsresult 1.291 + HandleDatabaseEvent(nsIDOMEvent* aEvent, const nsAString& aType); 1.292 + 1.293 + virtual void 1.294 + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; 1.295 + 1.296 + virtual bool 1.297 + RecvClose(const bool& aUnlinked) MOZ_OVERRIDE; 1.298 + 1.299 + virtual bool 1.300 + RecvPIndexedDBTransactionConstructor(PIndexedDBTransactionParent* aActor, 1.301 + const TransactionParams& aParams) 1.302 + MOZ_OVERRIDE; 1.303 + 1.304 + virtual PIndexedDBTransactionParent* 1.305 + AllocPIndexedDBTransactionParent(const TransactionParams& aParams) MOZ_OVERRIDE; 1.306 + 1.307 + virtual bool 1.308 + DeallocPIndexedDBTransactionParent(PIndexedDBTransactionParent* aActor) 1.309 + MOZ_OVERRIDE; 1.310 +}; 1.311 + 1.312 +/******************************************************************************* 1.313 + * IndexedDBTransactionParent 1.314 + ******************************************************************************/ 1.315 + 1.316 +class IndexedDBTransactionParent : protected PIndexedDBTransactionParent 1.317 +{ 1.318 + friend class IndexedDBCursorParent; 1.319 + friend class IndexedDBDatabaseParent; 1.320 + friend class IndexedDBObjectStoreParent; 1.321 + 1.322 +protected: 1.323 + AutoWeakEventListener<IndexedDBTransactionParent> mEventListener; 1.324 + 1.325 + nsRefPtr<IDBTransaction> mTransaction; 1.326 + 1.327 + bool mArtificialRequestCount; 1.328 + 1.329 +public: 1.330 + IndexedDBTransactionParent(); 1.331 + virtual ~IndexedDBTransactionParent(); 1.332 + 1.333 + bool 1.334 + IsDisconnected() const 1.335 + { 1.336 + return static_cast<IndexedDBDatabaseParent*>(Manager())->IsDisconnected(); 1.337 + } 1.338 + 1.339 + nsresult 1.340 + SetTransaction(IDBTransaction* aTransaction); 1.341 + 1.342 + IDBTransaction* 1.343 + GetTransaction() const 1.344 + { 1.345 + return mTransaction; 1.346 + } 1.347 + 1.348 + nsresult 1.349 + HandleEvent(nsIDOMEvent* aEvent); 1.350 + 1.351 +protected: 1.352 + virtual void 1.353 + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; 1.354 + 1.355 + virtual bool 1.356 + RecvAbort(const nsresult& aAbortCode) MOZ_OVERRIDE; 1.357 + 1.358 + virtual bool 1.359 + RecvAllRequestsFinished() MOZ_OVERRIDE; 1.360 + 1.361 + virtual bool 1.362 + RecvDeleteObjectStore(const nsString& aName) MOZ_OVERRIDE; 1.363 + 1.364 + virtual bool 1.365 + RecvPIndexedDBObjectStoreConstructor( 1.366 + PIndexedDBObjectStoreParent* aActor, 1.367 + const ObjectStoreConstructorParams& aParams) 1.368 + MOZ_OVERRIDE; 1.369 + 1.370 + virtual PIndexedDBObjectStoreParent* 1.371 + AllocPIndexedDBObjectStoreParent(const ObjectStoreConstructorParams& aParams) 1.372 + MOZ_OVERRIDE; 1.373 + 1.374 + virtual bool 1.375 + DeallocPIndexedDBObjectStoreParent(PIndexedDBObjectStoreParent* aActor) 1.376 + MOZ_OVERRIDE; 1.377 +}; 1.378 + 1.379 +/******************************************************************************* 1.380 + * IndexedDBVersionChangeTransactionParent 1.381 + ******************************************************************************/ 1.382 + 1.383 +class IndexedDBVersionChangeTransactionParent : 1.384 + public IndexedDBTransactionParent 1.385 +{ 1.386 + friend class IndexedDBVersionChangeObjectStoreParent; 1.387 + 1.388 +public: 1.389 + IndexedDBVersionChangeTransactionParent(); 1.390 + virtual ~IndexedDBVersionChangeTransactionParent(); 1.391 + 1.392 + bool 1.393 + IsDisconnected() const 1.394 + { 1.395 + return static_cast<IndexedDBDatabaseParent*>(Manager())->IsDisconnected(); 1.396 + } 1.397 + 1.398 +protected: 1.399 + virtual bool 1.400 + RecvDeleteObjectStore(const nsString& aName) MOZ_OVERRIDE; 1.401 + 1.402 + virtual bool 1.403 + RecvPIndexedDBObjectStoreConstructor( 1.404 + PIndexedDBObjectStoreParent* aActor, 1.405 + const ObjectStoreConstructorParams& aParams) 1.406 + MOZ_OVERRIDE; 1.407 + 1.408 + virtual PIndexedDBObjectStoreParent* 1.409 + AllocPIndexedDBObjectStoreParent(const ObjectStoreConstructorParams& aParams) 1.410 + MOZ_OVERRIDE; 1.411 +}; 1.412 + 1.413 +/******************************************************************************* 1.414 + * IndexedDBCursorParent 1.415 + ******************************************************************************/ 1.416 + 1.417 +class IndexedDBCursorParent : private PIndexedDBCursorParent 1.418 +{ 1.419 + friend class IndexedDBIndexParent; 1.420 + friend class IndexedDBObjectStoreParent; 1.421 + 1.422 + nsRefPtr<IDBCursor> mCursor; 1.423 + 1.424 +public: 1.425 + IDBCursor* 1.426 + GetCursor() const 1.427 + { 1.428 + return mCursor; 1.429 + } 1.430 + 1.431 + bool 1.432 + IsDisconnected() const; 1.433 + 1.434 +protected: 1.435 + IndexedDBCursorParent(IDBCursor* aCursor); 1.436 + virtual ~IndexedDBCursorParent(); 1.437 + 1.438 + virtual void 1.439 + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; 1.440 + 1.441 + virtual bool 1.442 + RecvPIndexedDBRequestConstructor(PIndexedDBRequestParent* aActor, 1.443 + const CursorRequestParams& aParams) 1.444 + MOZ_OVERRIDE; 1.445 + 1.446 + virtual PIndexedDBRequestParent* 1.447 + AllocPIndexedDBRequestParent(const CursorRequestParams& aParams) MOZ_OVERRIDE; 1.448 + 1.449 + virtual bool 1.450 + DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) MOZ_OVERRIDE; 1.451 +}; 1.452 + 1.453 +/******************************************************************************* 1.454 + * IndexedDBObjectStoreParent 1.455 + ******************************************************************************/ 1.456 + 1.457 +class IndexedDBObjectStoreParent : protected PIndexedDBObjectStoreParent 1.458 +{ 1.459 + friend class IndexedDBIndexParent; 1.460 + friend class IndexedDBTransactionParent; 1.461 + friend class IndexedDBVersionChangeTransactionParent; 1.462 + 1.463 + typedef mozilla::dom::indexedDB::ipc::OpenCursorResponse OpenCursorResponse; 1.464 + 1.465 +protected: 1.466 + nsRefPtr<IDBObjectStore> mObjectStore; 1.467 + 1.468 +public: 1.469 + IndexedDBObjectStoreParent(); 1.470 + virtual ~IndexedDBObjectStoreParent(); 1.471 + 1.472 + void 1.473 + SetObjectStore(IDBObjectStore* aObjectStore); 1.474 + 1.475 + IDBObjectStore* 1.476 + GetObjectStore() const 1.477 + { 1.478 + return mObjectStore; 1.479 + } 1.480 + 1.481 + bool 1.482 + IsDisconnected() const 1.483 + { 1.484 + IndexedDBTransactionParent* manager = 1.485 + static_cast<IndexedDBTransactionParent*>(Manager()); 1.486 + return manager->IsDisconnected(); 1.487 + } 1.488 + 1.489 + // Ordinarily callers could just do this manually using 1.490 + // PIndexedDBObjectStoreParent::SendPIndexedDBCursorConstructor but we're 1.491 + // inheriting the abstract protocol class privately to prevent outside code 1.492 + // from sending messages without checking the disconnected state. Therefore 1.493 + // we need a helper method. 1.494 + bool 1.495 + OpenCursor(IDBCursor* aCursor, 1.496 + const ObjectStoreCursorConstructorParams& aParams, 1.497 + OpenCursorResponse& aResponse) NS_WARN_UNUSED_RESULT 1.498 + { 1.499 + if (IsDisconnected()) { 1.500 + return true; 1.501 + } 1.502 + 1.503 + IndexedDBCursorParent* cursorActor = new IndexedDBCursorParent(aCursor); 1.504 + 1.505 + if (!SendPIndexedDBCursorConstructor(cursorActor, aParams)) { 1.506 + return false; 1.507 + } 1.508 + 1.509 + aResponse = cursorActor; 1.510 + return true; 1.511 + } 1.512 + 1.513 +protected: 1.514 + virtual void 1.515 + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; 1.516 + 1.517 + virtual bool 1.518 + RecvDeleteIndex(const nsString& aName) MOZ_OVERRIDE; 1.519 + 1.520 + virtual bool 1.521 + RecvPIndexedDBRequestConstructor(PIndexedDBRequestParent* aActor, 1.522 + const ObjectStoreRequestParams& aParams) 1.523 + MOZ_OVERRIDE; 1.524 + 1.525 + virtual bool 1.526 + RecvPIndexedDBIndexConstructor(PIndexedDBIndexParent* aActor, 1.527 + const IndexConstructorParams& aParams) 1.528 + MOZ_OVERRIDE; 1.529 + 1.530 + virtual PIndexedDBRequestParent* 1.531 + AllocPIndexedDBRequestParent(const ObjectStoreRequestParams& aParams) MOZ_OVERRIDE; 1.532 + 1.533 + virtual bool 1.534 + DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) MOZ_OVERRIDE; 1.535 + 1.536 + virtual PIndexedDBIndexParent* 1.537 + AllocPIndexedDBIndexParent(const IndexConstructorParams& aParams) MOZ_OVERRIDE; 1.538 + 1.539 + virtual bool 1.540 + DeallocPIndexedDBIndexParent(PIndexedDBIndexParent* aActor) MOZ_OVERRIDE; 1.541 + 1.542 + virtual PIndexedDBCursorParent* 1.543 + AllocPIndexedDBCursorParent(const ObjectStoreCursorConstructorParams& aParams) 1.544 + MOZ_OVERRIDE; 1.545 + 1.546 + virtual bool 1.547 + DeallocPIndexedDBCursorParent(PIndexedDBCursorParent* aActor) MOZ_OVERRIDE; 1.548 +}; 1.549 + 1.550 +/******************************************************************************* 1.551 + * IndexedDBVersionChangeObjectStoreParent 1.552 + ******************************************************************************/ 1.553 + 1.554 +class IndexedDBVersionChangeObjectStoreParent : 1.555 + public IndexedDBObjectStoreParent 1.556 +{ 1.557 + friend class IndexedDBVersionChangeTransactionParent; 1.558 + 1.559 +public: 1.560 + IndexedDBVersionChangeObjectStoreParent(); 1.561 + virtual ~IndexedDBVersionChangeObjectStoreParent(); 1.562 + 1.563 +protected: 1.564 + bool 1.565 + IsDisconnected() const 1.566 + { 1.567 + IndexedDBVersionChangeTransactionParent* manager = 1.568 + static_cast<IndexedDBVersionChangeTransactionParent*>(Manager()); 1.569 + return manager->IsDisconnected(); 1.570 + } 1.571 + 1.572 + virtual bool 1.573 + RecvDeleteIndex(const nsString& aName) MOZ_OVERRIDE; 1.574 + 1.575 + virtual bool 1.576 + RecvPIndexedDBIndexConstructor(PIndexedDBIndexParent* aActor, 1.577 + const IndexConstructorParams& aParams) 1.578 + MOZ_OVERRIDE; 1.579 +}; 1.580 + 1.581 +/******************************************************************************* 1.582 + * IndexedDBIndexParent 1.583 + ******************************************************************************/ 1.584 + 1.585 +class IndexedDBIndexParent : private PIndexedDBIndexParent 1.586 +{ 1.587 + friend class IndexedDBObjectStoreParent; 1.588 + friend class IndexedDBVersionChangeObjectStoreParent; 1.589 + 1.590 + typedef mozilla::dom::indexedDB::ipc::OpenCursorResponse OpenCursorResponse; 1.591 + 1.592 + nsRefPtr<IDBIndex> mIndex; 1.593 + 1.594 +public: 1.595 + IndexedDBIndexParent(); 1.596 + virtual ~IndexedDBIndexParent(); 1.597 + 1.598 + void 1.599 + SetIndex(IDBIndex* aObjectStore); 1.600 + 1.601 + IDBIndex* 1.602 + GetIndex() const 1.603 + { 1.604 + return mIndex; 1.605 + } 1.606 + 1.607 + // Ordinarily callers could just do this manually using 1.608 + // PIndexedDBIndexParent::SendPIndexedDBCursorConstructor but we're 1.609 + // inheriting the abstract protocol class privately to prevent outside code 1.610 + // from sending messages without checking the disconnected state. Therefore 1.611 + // we need a helper method. 1.612 + bool 1.613 + OpenCursor(IDBCursor* aCursor, const IndexCursorConstructorParams& aParams, 1.614 + OpenCursorResponse& aResponse) NS_WARN_UNUSED_RESULT 1.615 + { 1.616 + if (IsDisconnected()) { 1.617 + return true; 1.618 + } 1.619 + 1.620 + IndexedDBCursorParent* cursorActor = new IndexedDBCursorParent(aCursor); 1.621 + 1.622 + if (!SendPIndexedDBCursorConstructor(cursorActor, aParams)) { 1.623 + return false; 1.624 + } 1.625 + 1.626 + aResponse = cursorActor; 1.627 + return true; 1.628 + } 1.629 + 1.630 + bool 1.631 + IsDisconnected() const 1.632 + { 1.633 + IndexedDBObjectStoreParent* manager = 1.634 + static_cast<IndexedDBObjectStoreParent*>(Manager()); 1.635 + return manager->IsDisconnected(); 1.636 + } 1.637 + 1.638 +protected: 1.639 + virtual void 1.640 + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; 1.641 + 1.642 + virtual bool 1.643 + RecvPIndexedDBRequestConstructor(PIndexedDBRequestParent* aActor, 1.644 + const IndexRequestParams& aParams) 1.645 + MOZ_OVERRIDE; 1.646 + 1.647 + virtual PIndexedDBRequestParent* 1.648 + AllocPIndexedDBRequestParent(const IndexRequestParams& aParams) MOZ_OVERRIDE; 1.649 + 1.650 + virtual bool 1.651 + DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) MOZ_OVERRIDE; 1.652 + 1.653 + virtual PIndexedDBCursorParent* 1.654 + AllocPIndexedDBCursorParent(const IndexCursorConstructorParams& aParams) 1.655 + MOZ_OVERRIDE; 1.656 + 1.657 + virtual bool 1.658 + DeallocPIndexedDBCursorParent(PIndexedDBCursorParent* aActor) MOZ_OVERRIDE; 1.659 +}; 1.660 + 1.661 +/******************************************************************************* 1.662 + * IndexedDBRequestParentBase 1.663 + ******************************************************************************/ 1.664 + 1.665 +class IndexedDBRequestParentBase : public PIndexedDBRequestParent 1.666 +{ 1.667 +public: 1.668 + bool 1.669 + SendResponse(const ResponseValue& aResponse) NS_WARN_UNUSED_RESULT 1.670 + { 1.671 + if (IsDisconnected()) { 1.672 + return true; 1.673 + } 1.674 + 1.675 + return Send__delete__(this, aResponse); 1.676 + } 1.677 + 1.678 +protected: 1.679 + // Don't let anyone call this directly, instead go through SendResponse. 1.680 + using PIndexedDBRequestParent::Send__delete__; 1.681 + 1.682 + typedef ipc::ResponseValue ResponseValue; 1.683 + typedef PIndexedDBRequestParent::PBlobParent PBlobParent; 1.684 + 1.685 + nsRefPtr<IDBRequest> mRequest; 1.686 + 1.687 + IndexedDBRequestParentBase(); 1.688 + virtual ~IndexedDBRequestParentBase(); 1.689 + 1.690 + virtual void 1.691 + ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE; 1.692 + 1.693 + virtual bool 1.694 + IsDisconnected() = 0; 1.695 +}; 1.696 + 1.697 +/******************************************************************************* 1.698 + * IndexedDBObjectStoreRequestParent 1.699 + ******************************************************************************/ 1.700 + 1.701 +class IndexedDBObjectStoreRequestParent : public IndexedDBRequestParentBase 1.702 +{ 1.703 + friend class IndexedDBObjectStoreParent; 1.704 + 1.705 + nsRefPtr<IDBObjectStore> mObjectStore; 1.706 + 1.707 + typedef ipc::ObjectStoreRequestParams ParamsUnionType; 1.708 + typedef ParamsUnionType::Type RequestType; 1.709 + DebugOnly<RequestType> mRequestType; 1.710 + 1.711 + typedef ipc::AddParams AddParams; 1.712 + typedef ipc::PutParams PutParams; 1.713 + typedef ipc::ClearParams ClearParams; 1.714 + typedef ipc::DeleteParams DeleteParams; 1.715 + typedef ipc::GetParams GetParams; 1.716 + typedef ipc::GetAllParams GetAllParams; 1.717 + typedef ipc::GetAllKeysParams GetAllKeysParams; 1.718 + typedef ipc::CountParams CountParams; 1.719 + typedef ipc::OpenCursorParams OpenCursorParams; 1.720 + typedef ipc::OpenKeyCursorParams OpenKeyCursorParams; 1.721 + 1.722 +public: 1.723 + IndexedDBObjectStoreRequestParent(IDBObjectStore* aObjectStore, 1.724 + RequestType aRequestType); 1.725 + virtual ~IndexedDBObjectStoreRequestParent(); 1.726 + 1.727 + bool 1.728 + Get(const GetParams& aParams); 1.729 + 1.730 + bool 1.731 + GetAll(const GetAllParams& aParams); 1.732 + 1.733 + bool 1.734 + GetAllKeys(const GetAllKeysParams& aParams); 1.735 + 1.736 + bool 1.737 + Add(const AddParams& aParams); 1.738 + 1.739 + bool 1.740 + Put(const PutParams& aParams); 1.741 + 1.742 + bool 1.743 + Delete(const DeleteParams& aParams); 1.744 + 1.745 + bool 1.746 + Clear(const ClearParams& aParams); 1.747 + 1.748 + bool 1.749 + Count(const CountParams& aParams); 1.750 + 1.751 + bool 1.752 + OpenCursor(const OpenCursorParams& aParams); 1.753 + 1.754 + bool 1.755 + OpenKeyCursor(const OpenKeyCursorParams& aParams); 1.756 + 1.757 +protected: 1.758 + void 1.759 + ConvertBlobActors(const InfallibleTArray<PBlobParent*>& aActors, 1.760 + nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs); 1.761 + 1.762 +private: 1.763 + virtual bool 1.764 + IsDisconnected() MOZ_OVERRIDE; 1.765 +}; 1.766 + 1.767 +/******************************************************************************* 1.768 + * IndexedDBIndexRequestParent 1.769 + ******************************************************************************/ 1.770 + 1.771 +class IndexedDBIndexRequestParent : public IndexedDBRequestParentBase 1.772 +{ 1.773 + friend class IndexedDBIndexParent; 1.774 + 1.775 + nsRefPtr<IDBIndex> mIndex; 1.776 + 1.777 + typedef ipc::IndexRequestParams ParamsUnionType; 1.778 + typedef ParamsUnionType::Type RequestType; 1.779 + DebugOnly<RequestType> mRequestType; 1.780 + 1.781 + typedef ipc::GetKeyParams GetKeyParams; 1.782 + typedef ipc::GetAllKeysParams GetAllKeysParams; 1.783 + typedef ipc::OpenKeyCursorParams OpenKeyCursorParams; 1.784 + typedef ipc::GetParams GetParams; 1.785 + typedef ipc::GetAllParams GetAllParams; 1.786 + typedef ipc::CountParams CountParams; 1.787 + typedef ipc::OpenCursorParams OpenCursorParams; 1.788 + 1.789 +public: 1.790 + IndexedDBIndexRequestParent(IDBIndex* aIndex, RequestType aRequestType); 1.791 + virtual ~IndexedDBIndexRequestParent(); 1.792 + 1.793 + bool 1.794 + Get(const GetParams& aParams); 1.795 + 1.796 + bool 1.797 + GetKey(const GetKeyParams& aParams); 1.798 + 1.799 + bool 1.800 + GetAll(const GetAllParams& aParams); 1.801 + 1.802 + bool 1.803 + GetAllKeys(const GetAllKeysParams& aParams); 1.804 + 1.805 + bool 1.806 + Count(const CountParams& aParams); 1.807 + 1.808 + bool 1.809 + OpenCursor(const OpenCursorParams& aParams); 1.810 + 1.811 + bool 1.812 + OpenKeyCursor(const OpenKeyCursorParams& aParams); 1.813 + 1.814 +private: 1.815 + virtual bool 1.816 + IsDisconnected() MOZ_OVERRIDE; 1.817 +}; 1.818 + 1.819 +/******************************************************************************* 1.820 + * IndexedDBCursorRequestParent 1.821 + ******************************************************************************/ 1.822 + 1.823 +class IndexedDBCursorRequestParent : public IndexedDBRequestParentBase 1.824 +{ 1.825 + friend class IndexedDBCursorParent; 1.826 + 1.827 + nsRefPtr<IDBCursor> mCursor; 1.828 + 1.829 + typedef ipc::CursorRequestParams ParamsUnionType; 1.830 + typedef ParamsUnionType::Type RequestType; 1.831 + DebugOnly<RequestType> mRequestType; 1.832 + 1.833 + typedef ipc::ContinueParams ContinueParams; 1.834 + 1.835 +public: 1.836 + IndexedDBCursorRequestParent(IDBCursor* aCursor, RequestType aRequestType); 1.837 + virtual ~IndexedDBCursorRequestParent(); 1.838 + 1.839 + bool 1.840 + Continue(const ContinueParams& aParams); 1.841 + 1.842 +private: 1.843 + virtual bool 1.844 + IsDisconnected() MOZ_OVERRIDE; 1.845 +}; 1.846 + 1.847 +/******************************************************************************* 1.848 + * IndexedDBDeleteDatabaseRequestParent 1.849 + ******************************************************************************/ 1.850 + 1.851 +class IndexedDBDeleteDatabaseRequestParent : 1.852 + private PIndexedDBDeleteDatabaseRequestParent 1.853 +{ 1.854 + friend class IndexedDBParent; 1.855 + 1.856 + AutoWeakEventListener<IndexedDBDeleteDatabaseRequestParent> mEventListener; 1.857 + 1.858 + nsRefPtr<IDBFactory> mFactory; 1.859 + nsRefPtr<IDBOpenDBRequest> mOpenRequest; 1.860 + 1.861 +public: 1.862 + nsresult 1.863 + HandleEvent(nsIDOMEvent* aEvent); 1.864 + 1.865 +protected: 1.866 + IndexedDBDeleteDatabaseRequestParent(IDBFactory* aFactory); 1.867 + virtual ~IndexedDBDeleteDatabaseRequestParent(); 1.868 + 1.869 + nsresult 1.870 + SetOpenRequest(IDBOpenDBRequest* aOpenRequest); 1.871 + 1.872 + bool 1.873 + IsDisconnected() const 1.874 + { 1.875 + return static_cast<IndexedDBParent*>(Manager())->IsDisconnected(); 1.876 + } 1.877 +}; 1.878 + 1.879 +END_INDEXEDDB_NAMESPACE 1.880 + 1.881 +#endif // mozilla_dom_indexeddb_ipc_indexeddbparent_h__