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_idbindex_h__ michael@0: #define mozilla_dom_indexeddb_idbindex_h__ michael@0: michael@0: #include "mozilla/dom/indexedDB/IndexedDatabase.h" michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/dom/IDBCursorBinding.h" michael@0: #include "mozilla/ErrorResult.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsWrapperCache.h" michael@0: michael@0: #include "mozilla/dom/indexedDB/IDBObjectStore.h" michael@0: #include "mozilla/dom/indexedDB/IDBRequest.h" michael@0: #include "mozilla/dom/indexedDB/KeyPath.h" michael@0: michael@0: class nsIScriptContext; michael@0: class nsPIDOMWindow; michael@0: michael@0: BEGIN_INDEXEDDB_NAMESPACE michael@0: michael@0: class AsyncConnectionHelper; michael@0: class IDBCursor; michael@0: class IDBKeyRange; michael@0: class IDBObjectStore; michael@0: class IDBRequest; michael@0: class IndexedDBIndexChild; michael@0: class IndexedDBIndexParent; michael@0: class Key; michael@0: michael@0: struct IndexInfo; michael@0: michael@0: class IDBIndex MOZ_FINAL : public nsISupports, michael@0: public nsWrapperCache michael@0: { michael@0: public: michael@0: NS_DECL_CYCLE_COLLECTING_ISUPPORTS michael@0: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBIndex) michael@0: michael@0: static already_AddRefed michael@0: Create(IDBObjectStore* aObjectStore, michael@0: const IndexInfo* aIndexInfo, michael@0: bool aCreating); michael@0: michael@0: IDBObjectStore* ObjectStore() michael@0: { michael@0: return mObjectStore; michael@0: } michael@0: michael@0: const int64_t Id() const michael@0: { michael@0: return mId; michael@0: } michael@0: michael@0: const nsString& Name() const michael@0: { michael@0: return mName; michael@0: } michael@0: michael@0: bool IsUnique() const michael@0: { michael@0: return mUnique; michael@0: } michael@0: michael@0: bool IsMultiEntry() const michael@0: { michael@0: return mMultiEntry; michael@0: } michael@0: michael@0: const KeyPath& GetKeyPath() const michael@0: { michael@0: return mKeyPath; michael@0: } michael@0: michael@0: void michael@0: SetActor(IndexedDBIndexChild* 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(IndexedDBIndexParent* 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: IndexedDBIndexChild* michael@0: GetActorChild() const michael@0: { michael@0: return mActorChild; michael@0: } michael@0: michael@0: IndexedDBIndexParent* michael@0: GetActorParent() const michael@0: { michael@0: return mActorParent; michael@0: } michael@0: michael@0: already_AddRefed michael@0: GetInternal(IDBKeyRange* aKeyRange, michael@0: ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: GetKeyInternal(IDBKeyRange* aKeyRange, michael@0: ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: GetAllInternal(IDBKeyRange* aKeyRange, michael@0: uint32_t aLimit, michael@0: ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: GetAllKeysInternal(IDBKeyRange* aKeyRange, michael@0: uint32_t aLimit, michael@0: ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: CountInternal(IDBKeyRange* aKeyRange, michael@0: ErrorResult& aRv); michael@0: michael@0: nsresult OpenCursorFromChildProcess( michael@0: IDBRequest* aRequest, michael@0: size_t aDirection, michael@0: const Key& aKey, michael@0: const Key& aObjectKey, michael@0: IDBCursor** _retval); michael@0: michael@0: already_AddRefed michael@0: OpenKeyCursorInternal(IDBKeyRange* aKeyRange, michael@0: size_t aDirection, michael@0: ErrorResult& aRv); michael@0: michael@0: nsresult OpenCursorInternal(IDBKeyRange* aKeyRange, michael@0: size_t aDirection, michael@0: IDBRequest** _retval); michael@0: michael@0: nsresult OpenCursorFromChildProcess( michael@0: IDBRequest* aRequest, michael@0: size_t aDirection, michael@0: const Key& aKey, michael@0: const Key& aObjectKey, michael@0: const SerializedStructuredCloneReadInfo& aCloneInfo, michael@0: nsTArray& aBlobs, michael@0: IDBCursor** _retval); michael@0: michael@0: // nsWrapperCache michael@0: virtual JSObject* michael@0: WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // WebIDL michael@0: IDBObjectStore* michael@0: GetParentObject() const michael@0: { michael@0: return mObjectStore; 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: IDBObjectStore* michael@0: ObjectStore() const michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: return mObjectStore; michael@0: } michael@0: michael@0: void michael@0: GetKeyPath(JSContext* aCx, JS::MutableHandle aResult, michael@0: ErrorResult& aRv); michael@0: michael@0: bool michael@0: MultiEntry() const michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: return mMultiEntry; michael@0: } michael@0: michael@0: bool michael@0: Unique() const michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: return mUnique; michael@0: } michael@0: michael@0: already_AddRefed michael@0: OpenCursor(JSContext* aCx, JS::Handle aRange, michael@0: IDBCursorDirection aDirection, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: OpenKeyCursor(JSContext* aCx, JS::Handle aRange, michael@0: IDBCursorDirection aDirection, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: Get(JSContext* aCx, JS::Handle aKey, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: GetKey(JSContext* aCx, JS::Handle aKey, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: Count(JSContext* aCx, JS::Handle aKey, michael@0: ErrorResult& aRv); michael@0: michael@0: void michael@0: GetStoreName(nsString& aStoreName) const michael@0: { michael@0: NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); michael@0: mObjectStore->GetName(aStoreName); michael@0: } michael@0: michael@0: already_AddRefed michael@0: GetAll(JSContext* aCx, JS::Handle aKey, michael@0: const Optional& aLimit, ErrorResult& aRv); michael@0: michael@0: already_AddRefed michael@0: GetAllKeys(JSContext* aCx, JS::Handle aKey, michael@0: const Optional& aLimit, ErrorResult& aRv); michael@0: michael@0: private: michael@0: IDBIndex(); michael@0: ~IDBIndex(); michael@0: michael@0: nsRefPtr mObjectStore; michael@0: michael@0: int64_t mId; michael@0: nsString mName; michael@0: KeyPath mKeyPath; michael@0: JS::Heap mCachedKeyPath; michael@0: michael@0: IndexedDBIndexChild* mActorChild; michael@0: IndexedDBIndexParent* mActorParent; michael@0: michael@0: bool mUnique; michael@0: bool mMultiEntry; michael@0: bool mRooted; michael@0: }; michael@0: michael@0: END_INDEXEDDB_NAMESPACE michael@0: michael@0: #endif // mozilla_dom_indexeddb_idbindex_h__