1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/indexedDB/IDBDatabase.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,274 @@ 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_idbdatabase_h__ 1.11 +#define mozilla_dom_indexeddb_idbdatabase_h__ 1.12 + 1.13 +#include "mozilla/dom/indexedDB/IndexedDatabase.h" 1.14 + 1.15 +#include "nsIDocument.h" 1.16 +#include "nsIFileStorage.h" 1.17 +#include "nsIOfflineStorage.h" 1.18 + 1.19 +#include "mozilla/Attributes.h" 1.20 +#include "mozilla/DOMEventTargetHelper.h" 1.21 +#include "mozilla/dom/IDBObjectStoreBinding.h" 1.22 +#include "mozilla/dom/IDBTransactionBinding.h" 1.23 +#include "mozilla/dom/quota/PersistenceType.h" 1.24 + 1.25 +#include "mozilla/dom/indexedDB/FileManager.h" 1.26 +#include "mozilla/dom/indexedDB/IDBRequest.h" 1.27 +#include "mozilla/dom/indexedDB/IDBWrapperCache.h" 1.28 + 1.29 +class nsIScriptContext; 1.30 +class nsPIDOMWindow; 1.31 + 1.32 +namespace mozilla { 1.33 +class EventChainPostVisitor; 1.34 +namespace dom { 1.35 +class ContentParent; 1.36 +namespace quota { 1.37 +class Client; 1.38 +} 1.39 +} 1.40 +} 1.41 + 1.42 +BEGIN_INDEXEDDB_NAMESPACE 1.43 + 1.44 +class AsyncConnectionHelper; 1.45 +struct DatabaseInfo; 1.46 +class IDBFactory; 1.47 +class IDBIndex; 1.48 +class IDBObjectStore; 1.49 +class IDBTransaction; 1.50 +class IndexedDatabaseManager; 1.51 +class IndexedDBDatabaseChild; 1.52 +class IndexedDBDatabaseParent; 1.53 +struct ObjectStoreInfoGuts; 1.54 + 1.55 +class IDBDatabase : public IDBWrapperCache, 1.56 + public nsIOfflineStorage 1.57 +{ 1.58 + friend class AsyncConnectionHelper; 1.59 + friend class IndexedDatabaseManager; 1.60 + friend class IndexedDBDatabaseParent; 1.61 + friend class IndexedDBDatabaseChild; 1.62 + 1.63 +public: 1.64 + NS_DECL_ISUPPORTS_INHERITED 1.65 + NS_DECL_NSIFILESTORAGE 1.66 + NS_DECL_NSIOFFLINESTORAGE 1.67 + 1.68 + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache) 1.69 + 1.70 + static already_AddRefed<IDBDatabase> 1.71 + Create(IDBWrapperCache* aOwnerCache, 1.72 + IDBFactory* aFactory, 1.73 + already_AddRefed<DatabaseInfo> aDatabaseInfo, 1.74 + const nsACString& aASCIIOrigin, 1.75 + FileManager* aFileManager, 1.76 + mozilla::dom::ContentParent* aContentParent); 1.77 + 1.78 + static IDBDatabase* 1.79 + FromStorage(nsIOfflineStorage* aStorage); 1.80 + 1.81 + static IDBDatabase* 1.82 + FromStorage(nsIFileStorage* aStorage) 1.83 + { 1.84 + nsCOMPtr<nsIOfflineStorage> storage = do_QueryInterface(aStorage); 1.85 + return storage ? FromStorage(storage) : nullptr; 1.86 + } 1.87 + 1.88 + // nsIDOMEventTarget 1.89 + virtual nsresult PostHandleEvent( 1.90 + EventChainPostVisitor& aVisitor) MOZ_OVERRIDE; 1.91 + 1.92 + DatabaseInfo* Info() const 1.93 + { 1.94 + return mDatabaseInfo; 1.95 + } 1.96 + 1.97 + const nsString& Name() const 1.98 + { 1.99 + return mName; 1.100 + } 1.101 + 1.102 + const nsString& FilePath() const 1.103 + { 1.104 + return mFilePath; 1.105 + } 1.106 + 1.107 + already_AddRefed<nsIDocument> GetOwnerDocument() 1.108 + { 1.109 + if (!GetOwner()) { 1.110 + return nullptr; 1.111 + } 1.112 + 1.113 + nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc(); 1.114 + return doc.forget(); 1.115 + } 1.116 + 1.117 + void DisconnectFromActorParent(); 1.118 + 1.119 + void CloseInternal(bool aIsDead); 1.120 + 1.121 + void EnterSetVersionTransaction(); 1.122 + void ExitSetVersionTransaction(); 1.123 + 1.124 + // Called when a versionchange transaction is aborted to reset the 1.125 + // DatabaseInfo. 1.126 + void RevertToPreviousState(); 1.127 + 1.128 + FileManager* Manager() const 1.129 + { 1.130 + return mFileManager; 1.131 + } 1.132 + 1.133 + void 1.134 + SetActor(IndexedDBDatabaseChild* aActorChild) 1.135 + { 1.136 + NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!"); 1.137 + mActorChild = aActorChild; 1.138 + } 1.139 + 1.140 + void 1.141 + SetActor(IndexedDBDatabaseParent* aActorParent) 1.142 + { 1.143 + NS_ASSERTION(!aActorParent || !mActorParent, 1.144 + "Shouldn't have more than one!"); 1.145 + mActorParent = aActorParent; 1.146 + } 1.147 + 1.148 + IndexedDBDatabaseChild* 1.149 + GetActorChild() const 1.150 + { 1.151 + return mActorChild; 1.152 + } 1.153 + 1.154 + IndexedDBDatabaseParent* 1.155 + GetActorParent() const 1.156 + { 1.157 + return mActorParent; 1.158 + } 1.159 + 1.160 + mozilla::dom::ContentParent* 1.161 + GetContentParent() const 1.162 + { 1.163 + return mContentParent; 1.164 + } 1.165 + 1.166 + already_AddRefed<IDBObjectStore> 1.167 + CreateObjectStoreInternal(IDBTransaction* aTransaction, 1.168 + const ObjectStoreInfoGuts& aInfo, 1.169 + ErrorResult& aRv); 1.170 + 1.171 + IDBFactory* 1.172 + Factory() const 1.173 + { 1.174 + return mFactory; 1.175 + } 1.176 + 1.177 + // nsWrapperCache 1.178 + virtual JSObject* 1.179 + WrapObject(JSContext* aCx) MOZ_OVERRIDE; 1.180 + 1.181 + // WebIDL 1.182 + nsPIDOMWindow* 1.183 + GetParentObject() const 1.184 + { 1.185 + return GetOwner(); 1.186 + } 1.187 + 1.188 + void 1.189 + GetName(nsString& aName) const 1.190 + { 1.191 + NS_ASSERTION(NS_IsMainThread(), "Wrong thread!"); 1.192 + aName.Assign(mName); 1.193 + } 1.194 + 1.195 + uint64_t 1.196 + Version() const; 1.197 + 1.198 + already_AddRefed<mozilla::dom::DOMStringList> 1.199 + GetObjectStoreNames(ErrorResult& aRv) const; 1.200 + 1.201 + already_AddRefed<IDBObjectStore> 1.202 + CreateObjectStore(JSContext* aCx, const nsAString& aName, 1.203 + const IDBObjectStoreParameters& aOptionalParameters, 1.204 + ErrorResult& aRv); 1.205 + 1.206 + void 1.207 + DeleteObjectStore(const nsAString& name, ErrorResult& aRv); 1.208 + 1.209 + already_AddRefed<indexedDB::IDBTransaction> 1.210 + Transaction(const nsAString& aStoreName, IDBTransactionMode aMode, 1.211 + ErrorResult& aRv) 1.212 + { 1.213 + Sequence<nsString> list; 1.214 + list.AppendElement(aStoreName); 1.215 + return Transaction(list, aMode, aRv); 1.216 + } 1.217 + 1.218 + already_AddRefed<indexedDB::IDBTransaction> 1.219 + Transaction(const Sequence<nsString>& aStoreNames, IDBTransactionMode aMode, 1.220 + ErrorResult& aRv); 1.221 + 1.222 + IMPL_EVENT_HANDLER(abort) 1.223 + IMPL_EVENT_HANDLER(error) 1.224 + IMPL_EVENT_HANDLER(versionchange) 1.225 + 1.226 + mozilla::dom::StorageType 1.227 + Storage() const 1.228 + { 1.229 + return PersistenceTypeToStorage(mPersistenceType); 1.230 + } 1.231 + 1.232 + already_AddRefed<IDBRequest> 1.233 + MozCreateFileHandle(const nsAString& aName, const Optional<nsAString>& aType, 1.234 + ErrorResult& aRv); 1.235 + 1.236 + virtual void LastRelease() MOZ_OVERRIDE; 1.237 + 1.238 +private: 1.239 + IDBDatabase(IDBWrapperCache* aOwnerCache); 1.240 + ~IDBDatabase(); 1.241 + 1.242 + void OnUnlink(); 1.243 + void InvalidateInternal(bool aIsDead); 1.244 + 1.245 + // The factory must be kept alive when IndexedDB is used in multiple 1.246 + // processes. If it dies then the entire actor tree will be destroyed with it 1.247 + // and the world will explode. 1.248 + nsRefPtr<IDBFactory> mFactory; 1.249 + 1.250 + nsRefPtr<DatabaseInfo> mDatabaseInfo; 1.251 + 1.252 + // Set to a copy of the existing DatabaseInfo when starting a versionchange 1.253 + // transaction. 1.254 + nsRefPtr<DatabaseInfo> mPreviousDatabaseInfo; 1.255 + nsCString mDatabaseId; 1.256 + nsString mName; 1.257 + nsString mFilePath; 1.258 + nsCString mASCIIOrigin; 1.259 + 1.260 + nsRefPtr<FileManager> mFileManager; 1.261 + 1.262 + IndexedDBDatabaseChild* mActorChild; 1.263 + IndexedDBDatabaseParent* mActorParent; 1.264 + 1.265 + mozilla::dom::ContentParent* mContentParent; 1.266 + 1.267 + nsRefPtr<mozilla::dom::quota::Client> mQuotaClient; 1.268 + 1.269 + bool mInvalidated; 1.270 + bool mRegistered; 1.271 + bool mClosed; 1.272 + bool mRunningVersionChange; 1.273 +}; 1.274 + 1.275 +END_INDEXEDDB_NAMESPACE 1.276 + 1.277 +#endif // mozilla_dom_indexeddb_idbdatabase_h__