bug 700693 - OCSP stapling PSM changes r=bsmith
[gecko.git] / dom / indexedDB / IDBFactory.h
blob8d8b74e8b728f8bb6cfc0ca7d34b3412e31fb083
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_idbfactory_h__
8 #define mozilla_dom_indexeddb_idbfactory_h__
10 #include "mozilla/dom/indexedDB/IndexedDatabase.h"
12 #include "mozIStorageConnection.h"
14 #include "mozilla/dom/BindingUtils.h"
15 #include "nsCycleCollectionParticipant.h"
16 #include "nsWrapperCache.h"
18 class nsIAtom;
19 class nsIFile;
20 class nsIFileURL;
21 class nsIIDBOpenDBRequest;
22 class nsPIDOMWindow;
24 namespace mozilla {
25 namespace dom {
26 class ContentParent;
30 BEGIN_INDEXEDDB_NAMESPACE
32 struct DatabaseInfo;
33 class IDBDatabase;
34 class IDBOpenDBRequest;
35 class IndexedDBChild;
36 class IndexedDBParent;
38 struct ObjectStoreInfo;
40 class IDBFactory MOZ_FINAL : public nsISupports,
41 public nsWrapperCache
43 typedef mozilla::dom::ContentParent ContentParent;
44 typedef nsTArray<nsRefPtr<ObjectStoreInfo> > ObjectStoreInfoArray;
46 public:
47 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
48 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory)
50 // Called when using IndexedDB from a window in a different process.
51 static nsresult Create(nsPIDOMWindow* aWindow,
52 const nsACString& aASCIIOrigin,
53 ContentParent* aContentParent,
54 IDBFactory** aFactory);
56 // Called when using IndexedDB from a window in the current process.
57 static nsresult Create(nsPIDOMWindow* aWindow,
58 ContentParent* aContentParent,
59 IDBFactory** aFactory)
61 return Create(aWindow, EmptyCString(), aContentParent, aFactory);
64 // Called when using IndexedDB from a JS component or a JSM in the current
65 // process.
66 static nsresult Create(JSContext* aCx,
67 JS::Handle<JSObject*> aOwningObject,
68 ContentParent* aContentParent,
69 IDBFactory** aFactory);
71 // Called when using IndexedDB from a JS component or a JSM in a different
72 // process.
73 static nsresult Create(ContentParent* aContentParent,
74 IDBFactory** aFactory);
76 static already_AddRefed<nsIFileURL>
77 GetDatabaseFileURL(nsIFile* aDatabaseFile, const nsACString& aOrigin);
79 static already_AddRefed<mozIStorageConnection>
80 GetConnection(const nsAString& aDatabaseFilePath,
81 const nsACString& aOrigin);
83 static nsresult
84 SetDefaultPragmas(mozIStorageConnection* aConnection);
86 static nsresult
87 LoadDatabaseInformation(mozIStorageConnection* aConnection,
88 nsIAtom* aDatabaseId,
89 uint64_t* aVersion,
90 ObjectStoreInfoArray& aObjectStores);
92 static nsresult
93 SetDatabaseMetadata(DatabaseInfo* aDatabaseInfo,
94 uint64_t aVersion,
95 ObjectStoreInfoArray& aObjectStores);
97 nsresult
98 OpenInternal(const nsAString& aName,
99 int64_t aVersion,
100 const nsACString& aASCIIOrigin,
101 bool aDeleting,
102 IDBOpenDBRequest** _retval);
104 nsresult
105 OpenInternal(const nsAString& aName,
106 int64_t aVersion,
107 bool aDeleting,
108 IDBOpenDBRequest** _retval)
110 return OpenInternal(aName, aVersion, mASCIIOrigin, aDeleting, _retval);
113 void
114 SetActor(IndexedDBChild* aActorChild)
116 NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
117 mActorChild = aActorChild;
120 void
121 SetActor(IndexedDBParent* aActorParent)
123 NS_ASSERTION(!aActorParent || !mActorParent, "Shouldn't have more than one!");
124 mActorParent = aActorParent;
127 const nsCString&
128 GetASCIIOrigin() const
130 return mASCIIOrigin;
133 // WrapperCache
134 nsPIDOMWindow* GetParentObject() const
136 return mWindow;
139 virtual JSObject* WrapObject(JSContext* aCx,
140 JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
142 // WebIDL
143 already_AddRefed<nsIIDBOpenDBRequest>
144 Open(const NonNull<nsAString>& aName, const Optional<uint64_t>& aVersion,
145 ErrorResult& aRv)
147 return Open(nullptr, aName, aVersion, false, aRv);
150 already_AddRefed<nsIIDBOpenDBRequest>
151 DeleteDatabase(const NonNull<nsAString>& aName, ErrorResult& aRv)
153 return Open(nullptr, aName, Optional<uint64_t>(), true, aRv);
156 int16_t
157 Cmp(JSContext* aCx, JS::Handle<JS::Value> aFirst,
158 JS::Handle<JS::Value> aSecond, ErrorResult& aRv);
160 already_AddRefed<nsIIDBOpenDBRequest>
161 OpenForPrincipal(nsIPrincipal* aPrincipal, const NonNull<nsAString>& aName,
162 const Optional<uint64_t>& aVersion, ErrorResult& aRv);
164 already_AddRefed<nsIIDBOpenDBRequest>
165 DeleteForPrincipal(nsIPrincipal* aPrincipal, const NonNull<nsAString>& aName,
166 ErrorResult& aRv);
168 private:
169 IDBFactory();
170 ~IDBFactory();
172 already_AddRefed<nsIIDBOpenDBRequest>
173 Open(nsIPrincipal* aPrincipal, const nsAString& aName,
174 const Optional<uint64_t>& aVersion, bool aDelete, ErrorResult& aRv);
176 nsCString mASCIIOrigin;
178 // If this factory lives on a window then mWindow must be non-null. Otherwise
179 // mOwningObject must be non-null.
180 nsCOMPtr<nsPIDOMWindow> mWindow;
181 JS::Heap<JSObject*> mOwningObject;
183 IndexedDBChild* mActorChild;
184 IndexedDBParent* mActorParent;
186 mozilla::dom::ContentParent* mContentParent;
188 bool mRootedOwningObject;
191 END_INDEXEDDB_NAMESPACE
193 #endif // mozilla_dom_indexeddb_idbfactory_h__