1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/IDBIndex.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,251 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_indexeddb_idbindex_h__ 1.11 +#define mozilla_dom_indexeddb_idbindex_h__ 1.12 + 1.13 +#include "mozilla/dom/indexedDB/IndexedDatabase.h" 1.14 + 1.15 +#include "mozilla/Attributes.h" 1.16 +#include "mozilla/dom/IDBCursorBinding.h" 1.17 +#include "mozilla/ErrorResult.h" 1.18 +#include "nsCycleCollectionParticipant.h" 1.19 +#include "nsWrapperCache.h" 1.20 + 1.21 +#include "mozilla/dom/indexedDB/IDBObjectStore.h" 1.22 +#include "mozilla/dom/indexedDB/IDBRequest.h" 1.23 +#include "mozilla/dom/indexedDB/KeyPath.h" 1.24 + 1.25 +class nsIScriptContext; 1.26 +class nsPIDOMWindow; 1.27 + 1.28 +BEGIN_INDEXEDDB_NAMESPACE 1.29 + 1.30 +class AsyncConnectionHelper; 1.31 +class IDBCursor; 1.32 +class IDBKeyRange; 1.33 +class IDBObjectStore; 1.34 +class IDBRequest; 1.35 +class IndexedDBIndexChild; 1.36 +class IndexedDBIndexParent; 1.37 +class Key; 1.38 + 1.39 +struct IndexInfo; 1.40 + 1.41 +class IDBIndex MOZ_FINAL : public nsISupports, 1.42 + public nsWrapperCache 1.43 +{ 1.44 +public: 1.45 + NS_DECL_CYCLE_COLLECTING_ISUPPORTS 1.46 + NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBIndex) 1.47 + 1.48 + static already_AddRefed<IDBIndex> 1.49 + Create(IDBObjectStore* aObjectStore, 1.50 + const IndexInfo* aIndexInfo, 1.51 + bool aCreating); 1.52 + 1.53 + IDBObjectStore* ObjectStore() 1.54 + { 1.55 + return mObjectStore; 1.56 + } 1.57 + 1.58 + const int64_t Id() const 1.59 + { 1.60 + return mId; 1.61 + } 1.62 + 1.63 + const nsString& Name() const 1.64 + { 1.65 + return mName; 1.66 + } 1.67 + 1.68 + bool IsUnique() const 1.69 + { 1.70 + return mUnique; 1.71 + } 1.72 + 1.73 + bool IsMultiEntry() const 1.74 + { 1.75 + return mMultiEntry; 1.76 + } 1.77 + 1.78 + const KeyPath& GetKeyPath() const 1.79 + { 1.80 + return mKeyPath; 1.81 + } 1.82 + 1.83 + void 1.84 + SetActor(IndexedDBIndexChild* aActorChild) 1.85 + { 1.86 + NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!"); 1.87 + mActorChild = aActorChild; 1.88 + } 1.89 + 1.90 + void 1.91 + SetActor(IndexedDBIndexParent* aActorParent) 1.92 + { 1.93 + NS_ASSERTION(!aActorParent || !mActorParent, 1.94 + "Shouldn't have more than one!"); 1.95 + mActorParent = aActorParent; 1.96 + } 1.97 + 1.98 + IndexedDBIndexChild* 1.99 + GetActorChild() const 1.100 + { 1.101 + return mActorChild; 1.102 + } 1.103 + 1.104 + IndexedDBIndexParent* 1.105 + GetActorParent() const 1.106 + { 1.107 + return mActorParent; 1.108 + } 1.109 + 1.110 + already_AddRefed<IDBRequest> 1.111 + GetInternal(IDBKeyRange* aKeyRange, 1.112 + ErrorResult& aRv); 1.113 + 1.114 + already_AddRefed<IDBRequest> 1.115 + GetKeyInternal(IDBKeyRange* aKeyRange, 1.116 + ErrorResult& aRv); 1.117 + 1.118 + already_AddRefed<IDBRequest> 1.119 + GetAllInternal(IDBKeyRange* aKeyRange, 1.120 + uint32_t aLimit, 1.121 + ErrorResult& aRv); 1.122 + 1.123 + already_AddRefed<IDBRequest> 1.124 + GetAllKeysInternal(IDBKeyRange* aKeyRange, 1.125 + uint32_t aLimit, 1.126 + ErrorResult& aRv); 1.127 + 1.128 + already_AddRefed<IDBRequest> 1.129 + CountInternal(IDBKeyRange* aKeyRange, 1.130 + ErrorResult& aRv); 1.131 + 1.132 + nsresult OpenCursorFromChildProcess( 1.133 + IDBRequest* aRequest, 1.134 + size_t aDirection, 1.135 + const Key& aKey, 1.136 + const Key& aObjectKey, 1.137 + IDBCursor** _retval); 1.138 + 1.139 + already_AddRefed<IDBRequest> 1.140 + OpenKeyCursorInternal(IDBKeyRange* aKeyRange, 1.141 + size_t aDirection, 1.142 + ErrorResult& aRv); 1.143 + 1.144 + nsresult OpenCursorInternal(IDBKeyRange* aKeyRange, 1.145 + size_t aDirection, 1.146 + IDBRequest** _retval); 1.147 + 1.148 + nsresult OpenCursorFromChildProcess( 1.149 + IDBRequest* aRequest, 1.150 + size_t aDirection, 1.151 + const Key& aKey, 1.152 + const Key& aObjectKey, 1.153 + const SerializedStructuredCloneReadInfo& aCloneInfo, 1.154 + nsTArray<StructuredCloneFile>& aBlobs, 1.155 + IDBCursor** _retval); 1.156 + 1.157 + // nsWrapperCache 1.158 + virtual JSObject* 1.159 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.160 + 1.161 + // WebIDL 1.162 + IDBObjectStore* 1.163 + GetParentObject() const 1.164 + { 1.165 + return mObjectStore; 1.166 + } 1.167 + 1.168 + void 1.169 + GetName(nsString& aName) const 1.170 + { 1.171 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.172 + aName.Assign(mName); 1.173 + } 1.174 + 1.175 + IDBObjectStore* 1.176 + ObjectStore() const 1.177 + { 1.178 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.179 + return mObjectStore; 1.180 + } 1.181 + 1.182 + void 1.183 + GetKeyPath(JSContext* aCx, JS::MutableHandle<JS::Value> aResult, 1.184 + ErrorResult& aRv); 1.185 + 1.186 + bool 1.187 + MultiEntry() const 1.188 + { 1.189 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.190 + return mMultiEntry; 1.191 + } 1.192 + 1.193 + bool 1.194 + Unique() const 1.195 + { 1.196 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.197 + return mUnique; 1.198 + } 1.199 + 1.200 + already_AddRefed<IDBRequest> 1.201 + OpenCursor(JSContext* aCx, JS::Handle<JS::Value> aRange, 1.202 + IDBCursorDirection aDirection, ErrorResult& aRv); 1.203 + 1.204 + already_AddRefed<IDBRequest> 1.205 + OpenKeyCursor(JSContext* aCx, JS::Handle<JS::Value> aRange, 1.206 + IDBCursorDirection aDirection, ErrorResult& aRv); 1.207 + 1.208 + already_AddRefed<IDBRequest> 1.209 + Get(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv); 1.210 + 1.211 + already_AddRefed<IDBRequest> 1.212 + GetKey(JSContext* aCx, JS::Handle<JS::Value> aKey, ErrorResult& aRv); 1.213 + 1.214 + already_AddRefed<IDBRequest> 1.215 + Count(JSContext* aCx, JS::Handle<JS::Value> aKey, 1.216 + ErrorResult& aRv); 1.217 + 1.218 + void 1.219 + GetStoreName(nsString& aStoreName) const 1.220 + { 1.221 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.222 + mObjectStore->GetName(aStoreName); 1.223 + } 1.224 + 1.225 + already_AddRefed<IDBRequest> 1.226 + GetAll(JSContext* aCx, JS::Handle<JS::Value> aKey, 1.227 + const Optional<uint32_t>& aLimit, ErrorResult& aRv); 1.228 + 1.229 + already_AddRefed<IDBRequest> 1.230 + GetAllKeys(JSContext* aCx, JS::Handle<JS::Value> aKey, 1.231 + const Optional<uint32_t>& aLimit, ErrorResult& aRv); 1.232 + 1.233 +private: 1.234 + IDBIndex(); 1.235 + ~IDBIndex(); 1.236 + 1.237 + nsRefPtr<IDBObjectStore> mObjectStore; 1.238 + 1.239 + int64_t mId; 1.240 + nsString mName; 1.241 + KeyPath mKeyPath; 1.242 + JS::Heap<JS::Value> mCachedKeyPath; 1.243 + 1.244 + IndexedDBIndexChild* mActorChild; 1.245 + IndexedDBIndexParent* mActorParent; 1.246 + 1.247 + bool mUnique; 1.248 + bool mMultiEntry; 1.249 + bool mRooted; 1.250 +}; 1.251 + 1.252 +END_INDEXEDDB_NAMESPACE 1.253 + 1.254 +#endif // mozilla_dom_indexeddb_idbindex_h__