dom/indexedDB/ipc/IndexedDBParent.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial