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