michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_idbdatabase_h__ michael@0: #define mozilla_dom_indexeddb_idbdatabase_h__ michael@0: michael@0: #include "mozilla/dom/indexedDB/IndexedDatabase.h" michael@0: michael@0: #include "nsIDocument.h" michael@0: #include "nsIFileStorage.h" michael@0: #include "nsIOfflineStorage.h" michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/dom/IDBObjectStoreBinding.h" michael@0: #include "mozilla/dom/IDBTransactionBinding.h" michael@0: #include "mozilla/dom/quota/PersistenceType.h" michael@0: michael@0: #include "mozilla/dom/indexedDB/FileManager.h" michael@0: #include "mozilla/dom/indexedDB/IDBRequest.h" michael@0: #include "mozilla/dom/indexedDB/IDBWrapperCache.h" michael@0: michael@0: class nsIScriptContext; michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: class EventChainPostVisitor; michael@0: namespace dom { michael@0: class ContentParent; michael@0: namespace quota { michael@0: class Client; michael@0: } michael@0: } michael@0: } michael@0: michael@0: BEGIN_INDEXEDDB_NAMESPACE michael@0: michael@0: class AsyncConnectionHelper; michael@0: struct DatabaseInfo; michael@0: class IDBFactory; michael@0: class IDBIndex; michael@0: class IDBObjectStore; michael@0: class IDBTransaction; michael@0: class IndexedDatabaseManager; michael@0: class IndexedDBDatabaseChild; michael@0: class IndexedDBDatabaseParent; michael@0: struct ObjectStoreInfoGuts; michael@0: michael@0: class IDBDatabase : public IDBWrapperCache, michael@0: public nsIOfflineStorage michael@0: { michael@0: friend class AsyncConnectionHelper; michael@0: friend class IndexedDatabaseManager; michael@0: friend class IndexedDBDatabaseParent; michael@0: friend class IndexedDBDatabaseChild; michael@0: michael@0: public: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSIFILESTORAGE michael@0: NS_DECL_NSIOFFLINESTORAGE michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache) michael@0: michael@0: static already_AddRefed michael@0: Create(IDBWrapperCache* aOwnerCache, michael@0: IDBFactory* aFactory, michael@0: already_AddRefed aDatabaseInfo, michael@0: const nsACString& aASCIIOrigin, michael@0: FileManager* aFileManager, michael@0: mozilla::dom::ContentParent* aContentParent); michael@0: michael@0: static IDBDatabase* michael@0: FromStorage(nsIOfflineStorage* aStorage); michael@0: michael@0: static IDBDatabase* michael@0: FromStorage(nsIFileStorage* aStorage) michael@0: { michael@0: nsCOMPtr storage = do_QueryInterface(aStorage); michael@0: return storage ? FromStorage(storage) : nullptr; michael@0: } michael@0: michael@0: // nsIDOMEventTarget michael@0: virtual nsresult PostHandleEvent( michael@0: EventChainPostVisitor& aVisitor) MOZ_OVERRIDE; michael@0: michael@0: DatabaseInfo* Info() const michael@0: { michael@0: return mDatabaseInfo; michael@0: } michael@0: michael@0: const nsString& Name() const michael@0: { michael@0: return mName; michael@0: } michael@0: michael@0: const nsString& FilePath() const michael@0: { michael@0: return mFilePath; michael@0: } michael@0: michael@0: already_AddRefed GetOwnerDocument() michael@0: { michael@0: if (!GetOwner()) { michael@0: return nullptr; michael@0: } michael@0: michael@0: nsCOMPtr doc = GetOwner()->GetExtantDoc(); michael@0: return doc.forget(); michael@0: } michael@0: michael@0: void DisconnectFromActorParent(); michael@0: michael@0: void CloseInternal(bool aIsDead); michael@0: michael@0: void EnterSetVersionTransaction(); michael@0: void ExitSetVersionTransaction(); michael@0: michael@0: // Called when a versionchange transaction is aborted to reset the michael@0: // DatabaseInfo. michael@0: void RevertToPreviousState(); michael@0: michael@0: FileManager* Manager() const michael@0: { michael@0: return mFileManager; michael@0: } michael@0: michael@0: void michael@0: SetActor(IndexedDBDatabaseChild* aActorChild) michael@0: { michael@0: NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!"); michael@0: mActorChild = aActorChild; michael@0: } michael@0: michael@0: void michael@0: SetActor(IndexedDBDatabaseParent* aActorParent) michael@0: { michael@0: NS_ASSERTION(!aActorParent || !mActorParent, michael@0: "Shouldn't have more than one!"); michael@0: mActorParent = aActorParent; michael@0: } michael@0: michael@0: IndexedDBDatabaseChild* michael@0: GetActorChild() const michael@0: { michael@0: return mActorChild; michael@0: } michael@0: michael@0: IndexedDBDatabaseParent* michael@0: GetActorParent() const michael@0: { michael@0: return mActorParent; michael@0: } michael@0: michael@0: mozilla::dom::ContentParent* michael@0: GetContentParent() const michael@0: { michael@0: return mContentParent; michael@0: } michael@0: michael@0: already_AddRefed michael@0: CreateObjectStoreInternal(IDBTransaction* aTransaction, michael@0: const ObjectStoreInfoGuts& aInfo, michael@0: ErrorResult& aRv); michael@0: michael@0: IDBFactory* michael@0: Factory() const michael@0: { michael@0: return mFactory; michael@0: } michael@0: michael@0: // nsWrapperCache michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: nsPIDOMWindow* michael@0: GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: void michael@0: GetName(nsString& aName) const michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: aName.Assign(mName); michael@0: } michael@0: michael@0: uint64_t michael@0: Version() const; michael@0: michael@0: already_AddRefed michael@0: GetObjectStoreNames(ErrorResult& aRv) const; michael@0: michael@0: already_AddRefed michael@0: CreateObjectStore(JSContext* aCx, const nsAString& aName, michael@0: const IDBObjectStoreParameters& aOptionalParameters, michael@0: ErrorResult& aRv); michael@0: michael@0: void michael@0: DeleteObjectStore(const nsAString& name, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: Transaction(const nsAString& aStoreName, IDBTransactionMode aMode, michael@0: ErrorResult& aRv) michael@0: { michael@0: Sequence list; michael@0: list.AppendElement(aStoreName); michael@0: return Transaction(list, aMode, aRv); michael@0: } michael@0: michael@0: already_AddRefed michael@0: Transaction(const Sequence& aStoreNames, IDBTransactionMode aMode, michael@0: ErrorResult& aRv); michael@0: michael@0: IMPL_EVENT_HANDLER(abort) michael@0: IMPL_EVENT_HANDLER(error) michael@0: IMPL_EVENT_HANDLER(versionchange) michael@0: michael@0: mozilla::dom::StorageType michael@0: Storage() const michael@0: { michael@0: return PersistenceTypeToStorage(mPersistenceType); michael@0: } michael@0: michael@0: already_AddRefed michael@0: MozCreateFileHandle(const nsAString& aName, const Optional& aType, michael@0: ErrorResult& aRv); michael@0: michael@0: virtual void LastRelease() MOZ_OVERRIDE; michael@0: michael@0: private: michael@0: IDBDatabase(IDBWrapperCache* aOwnerCache); michael@0: ~IDBDatabase(); michael@0: michael@0: void OnUnlink(); michael@0: void InvalidateInternal(bool aIsDead); michael@0: michael@0: // The factory must be kept alive when IndexedDB is used in multiple michael@0: // processes. If it dies then the entire actor tree will be destroyed with it michael@0: // and the world will explode. michael@0: nsRefPtr mFactory; michael@0: michael@0: nsRefPtr mDatabaseInfo; michael@0: michael@0: // Set to a copy of the existing DatabaseInfo when starting a versionchange michael@0: // transaction. michael@0: nsRefPtr mPreviousDatabaseInfo; michael@0: nsCString mDatabaseId; michael@0: nsString mName; michael@0: nsString mFilePath; michael@0: nsCString mASCIIOrigin; michael@0: michael@0: nsRefPtr mFileManager; michael@0: michael@0: IndexedDBDatabaseChild* mActorChild; michael@0: IndexedDBDatabaseParent* mActorParent; michael@0: michael@0: mozilla::dom::ContentParent* mContentParent; michael@0: michael@0: nsRefPtr mQuotaClient; michael@0: michael@0: bool mInvalidated; michael@0: bool mRegistered; michael@0: bool mClosed; michael@0: bool mRunningVersionChange; michael@0: }; michael@0: michael@0: END_INDEXEDDB_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_indexeddb_idbdatabase_h__