dom/indexedDB/IDBDatabase.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 et sw=2 tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef mozilla_dom_indexeddb_idbdatabase_h__
michael@0 8 #define mozilla_dom_indexeddb_idbdatabase_h__
michael@0 9
michael@0 10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
michael@0 11
michael@0 12 #include "nsIDocument.h"
michael@0 13 #include "nsIFileStorage.h"
michael@0 14 #include "nsIOfflineStorage.h"
michael@0 15
michael@0 16 #include "mozilla/Attributes.h"
michael@0 17 #include "mozilla/DOMEventTargetHelper.h"
michael@0 18 #include "mozilla/dom/IDBObjectStoreBinding.h"
michael@0 19 #include "mozilla/dom/IDBTransactionBinding.h"
michael@0 20 #include "mozilla/dom/quota/PersistenceType.h"
michael@0 21
michael@0 22 #include "mozilla/dom/indexedDB/FileManager.h"
michael@0 23 #include "mozilla/dom/indexedDB/IDBRequest.h"
michael@0 24 #include "mozilla/dom/indexedDB/IDBWrapperCache.h"
michael@0 25
michael@0 26 class nsIScriptContext;
michael@0 27 class nsPIDOMWindow;
michael@0 28
michael@0 29 namespace mozilla {
michael@0 30 class EventChainPostVisitor;
michael@0 31 namespace dom {
michael@0 32 class ContentParent;
michael@0 33 namespace quota {
michael@0 34 class Client;
michael@0 35 }
michael@0 36 }
michael@0 37 }
michael@0 38
michael@0 39 BEGIN_INDEXEDDB_NAMESPACE
michael@0 40
michael@0 41 class AsyncConnectionHelper;
michael@0 42 struct DatabaseInfo;
michael@0 43 class IDBFactory;
michael@0 44 class IDBIndex;
michael@0 45 class IDBObjectStore;
michael@0 46 class IDBTransaction;
michael@0 47 class IndexedDatabaseManager;
michael@0 48 class IndexedDBDatabaseChild;
michael@0 49 class IndexedDBDatabaseParent;
michael@0 50 struct ObjectStoreInfoGuts;
michael@0 51
michael@0 52 class IDBDatabase : public IDBWrapperCache,
michael@0 53 public nsIOfflineStorage
michael@0 54 {
michael@0 55 friend class AsyncConnectionHelper;
michael@0 56 friend class IndexedDatabaseManager;
michael@0 57 friend class IndexedDBDatabaseParent;
michael@0 58 friend class IndexedDBDatabaseChild;
michael@0 59
michael@0 60 public:
michael@0 61 NS_DECL_ISUPPORTS_INHERITED
michael@0 62 NS_DECL_NSIFILESTORAGE
michael@0 63 NS_DECL_NSIOFFLINESTORAGE
michael@0 64
michael@0 65 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache)
michael@0 66
michael@0 67 static already_AddRefed<IDBDatabase>
michael@0 68 Create(IDBWrapperCache* aOwnerCache,
michael@0 69 IDBFactory* aFactory,
michael@0 70 already_AddRefed<DatabaseInfo> aDatabaseInfo,
michael@0 71 const nsACString& aASCIIOrigin,
michael@0 72 FileManager* aFileManager,
michael@0 73 mozilla::dom::ContentParent* aContentParent);
michael@0 74
michael@0 75 static IDBDatabase*
michael@0 76 FromStorage(nsIOfflineStorage* aStorage);
michael@0 77
michael@0 78 static IDBDatabase*
michael@0 79 FromStorage(nsIFileStorage* aStorage)
michael@0 80 {
michael@0 81 nsCOMPtr<nsIOfflineStorage> storage = do_QueryInterface(aStorage);
michael@0 82 return storage ? FromStorage(storage) : nullptr;
michael@0 83 }
michael@0 84
michael@0 85 // nsIDOMEventTarget
michael@0 86 virtual nsresult PostHandleEvent(
michael@0 87 EventChainPostVisitor& aVisitor) MOZ_OVERRIDE;
michael@0 88
michael@0 89 DatabaseInfo* Info() const
michael@0 90 {
michael@0 91 return mDatabaseInfo;
michael@0 92 }
michael@0 93
michael@0 94 const nsString& Name() const
michael@0 95 {
michael@0 96 return mName;
michael@0 97 }
michael@0 98
michael@0 99 const nsString& FilePath() const
michael@0 100 {
michael@0 101 return mFilePath;
michael@0 102 }
michael@0 103
michael@0 104 already_AddRefed<nsIDocument> GetOwnerDocument()
michael@0 105 {
michael@0 106 if (!GetOwner()) {
michael@0 107 return nullptr;
michael@0 108 }
michael@0 109
michael@0 110 nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
michael@0 111 return doc.forget();
michael@0 112 }
michael@0 113
michael@0 114 void DisconnectFromActorParent();
michael@0 115
michael@0 116 void CloseInternal(bool aIsDead);
michael@0 117
michael@0 118 void EnterSetVersionTransaction();
michael@0 119 void ExitSetVersionTransaction();
michael@0 120
michael@0 121 // Called when a versionchange transaction is aborted to reset the
michael@0 122 // DatabaseInfo.
michael@0 123 void RevertToPreviousState();
michael@0 124
michael@0 125 FileManager* Manager() const
michael@0 126 {
michael@0 127 return mFileManager;
michael@0 128 }
michael@0 129
michael@0 130 void
michael@0 131 SetActor(IndexedDBDatabaseChild* aActorChild)
michael@0 132 {
michael@0 133 NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
michael@0 134 mActorChild = aActorChild;
michael@0 135 }
michael@0 136
michael@0 137 void
michael@0 138 SetActor(IndexedDBDatabaseParent* aActorParent)
michael@0 139 {
michael@0 140 NS_ASSERTION(!aActorParent || !mActorParent,
michael@0 141 "Shouldn't have more than one!");
michael@0 142 mActorParent = aActorParent;
michael@0 143 }
michael@0 144
michael@0 145 IndexedDBDatabaseChild*
michael@0 146 GetActorChild() const
michael@0 147 {
michael@0 148 return mActorChild;
michael@0 149 }
michael@0 150
michael@0 151 IndexedDBDatabaseParent*
michael@0 152 GetActorParent() const
michael@0 153 {
michael@0 154 return mActorParent;
michael@0 155 }
michael@0 156
michael@0 157 mozilla::dom::ContentParent*
michael@0 158 GetContentParent() const
michael@0 159 {
michael@0 160 return mContentParent;
michael@0 161 }
michael@0 162
michael@0 163 already_AddRefed<IDBObjectStore>
michael@0 164 CreateObjectStoreInternal(IDBTransaction* aTransaction,
michael@0 165 const ObjectStoreInfoGuts& aInfo,
michael@0 166 ErrorResult& aRv);
michael@0 167
michael@0 168 IDBFactory*
michael@0 169 Factory() const
michael@0 170 {
michael@0 171 return mFactory;
michael@0 172 }
michael@0 173
michael@0 174 // nsWrapperCache
michael@0 175 virtual JSObject*
michael@0 176 WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 177
michael@0 178 // WebIDL
michael@0 179 nsPIDOMWindow*
michael@0 180 GetParentObject() const
michael@0 181 {
michael@0 182 return GetOwner();
michael@0 183 }
michael@0 184
michael@0 185 void
michael@0 186 GetName(nsString& aName) const
michael@0 187 {
michael@0 188 NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
michael@0 189 aName.Assign(mName);
michael@0 190 }
michael@0 191
michael@0 192 uint64_t
michael@0 193 Version() const;
michael@0 194
michael@0 195 already_AddRefed<mozilla::dom::DOMStringList>
michael@0 196 GetObjectStoreNames(ErrorResult& aRv) const;
michael@0 197
michael@0 198 already_AddRefed<IDBObjectStore>
michael@0 199 CreateObjectStore(JSContext* aCx, const nsAString& aName,
michael@0 200 const IDBObjectStoreParameters& aOptionalParameters,
michael@0 201 ErrorResult& aRv);
michael@0 202
michael@0 203 void
michael@0 204 DeleteObjectStore(const nsAString& name, ErrorResult& aRv);
michael@0 205
michael@0 206 already_AddRefed<indexedDB::IDBTransaction>
michael@0 207 Transaction(const nsAString& aStoreName, IDBTransactionMode aMode,
michael@0 208 ErrorResult& aRv)
michael@0 209 {
michael@0 210 Sequence<nsString> list;
michael@0 211 list.AppendElement(aStoreName);
michael@0 212 return Transaction(list, aMode, aRv);
michael@0 213 }
michael@0 214
michael@0 215 already_AddRefed<indexedDB::IDBTransaction>
michael@0 216 Transaction(const Sequence<nsString>& aStoreNames, IDBTransactionMode aMode,
michael@0 217 ErrorResult& aRv);
michael@0 218
michael@0 219 IMPL_EVENT_HANDLER(abort)
michael@0 220 IMPL_EVENT_HANDLER(error)
michael@0 221 IMPL_EVENT_HANDLER(versionchange)
michael@0 222
michael@0 223 mozilla::dom::StorageType
michael@0 224 Storage() const
michael@0 225 {
michael@0 226 return PersistenceTypeToStorage(mPersistenceType);
michael@0 227 }
michael@0 228
michael@0 229 already_AddRefed<IDBRequest>
michael@0 230 MozCreateFileHandle(const nsAString& aName, const Optional<nsAString>& aType,
michael@0 231 ErrorResult& aRv);
michael@0 232
michael@0 233 virtual void LastRelease() MOZ_OVERRIDE;
michael@0 234
michael@0 235 private:
michael@0 236 IDBDatabase(IDBWrapperCache* aOwnerCache);
michael@0 237 ~IDBDatabase();
michael@0 238
michael@0 239 void OnUnlink();
michael@0 240 void InvalidateInternal(bool aIsDead);
michael@0 241
michael@0 242 // The factory must be kept alive when IndexedDB is used in multiple
michael@0 243 // processes. If it dies then the entire actor tree will be destroyed with it
michael@0 244 // and the world will explode.
michael@0 245 nsRefPtr<IDBFactory> mFactory;
michael@0 246
michael@0 247 nsRefPtr<DatabaseInfo> mDatabaseInfo;
michael@0 248
michael@0 249 // Set to a copy of the existing DatabaseInfo when starting a versionchange
michael@0 250 // transaction.
michael@0 251 nsRefPtr<DatabaseInfo> mPreviousDatabaseInfo;
michael@0 252 nsCString mDatabaseId;
michael@0 253 nsString mName;
michael@0 254 nsString mFilePath;
michael@0 255 nsCString mASCIIOrigin;
michael@0 256
michael@0 257 nsRefPtr<FileManager> mFileManager;
michael@0 258
michael@0 259 IndexedDBDatabaseChild* mActorChild;
michael@0 260 IndexedDBDatabaseParent* mActorParent;
michael@0 261
michael@0 262 mozilla::dom::ContentParent* mContentParent;
michael@0 263
michael@0 264 nsRefPtr<mozilla::dom::quota::Client> mQuotaClient;
michael@0 265
michael@0 266 bool mInvalidated;
michael@0 267 bool mRegistered;
michael@0 268 bool mClosed;
michael@0 269 bool mRunningVersionChange;
michael@0 270 };
michael@0 271
michael@0 272 END_INDEXEDDB_NAMESPACE
michael@0 273
michael@0 274 #endif // mozilla_dom_indexeddb_idbdatabase_h__

mercurial