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"
21 class nsIIDBOpenDBRequest
;
30 BEGIN_INDEXEDDB_NAMESPACE
34 class IDBOpenDBRequest
;
36 class IndexedDBParent
;
38 struct ObjectStoreInfo
;
40 class IDBFactory MOZ_FINAL
: public nsISupports
,
43 typedef mozilla::dom::ContentParent ContentParent
;
44 typedef nsTArray
<nsRefPtr
<ObjectStoreInfo
> > ObjectStoreInfoArray
;
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
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
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
);
84 SetDefaultPragmas(mozIStorageConnection
* aConnection
);
87 LoadDatabaseInformation(mozIStorageConnection
* aConnection
,
90 ObjectStoreInfoArray
& aObjectStores
);
93 SetDatabaseMetadata(DatabaseInfo
* aDatabaseInfo
,
95 ObjectStoreInfoArray
& aObjectStores
);
98 OpenInternal(const nsAString
& aName
,
100 const nsACString
& aASCIIOrigin
,
102 IDBOpenDBRequest
** _retval
);
105 OpenInternal(const nsAString
& aName
,
108 IDBOpenDBRequest
** _retval
)
110 return OpenInternal(aName
, aVersion
, mASCIIOrigin
, aDeleting
, _retval
);
114 SetActor(IndexedDBChild
* aActorChild
)
116 NS_ASSERTION(!aActorChild
|| !mActorChild
, "Shouldn't have more than one!");
117 mActorChild
= aActorChild
;
121 SetActor(IndexedDBParent
* aActorParent
)
123 NS_ASSERTION(!aActorParent
|| !mActorParent
, "Shouldn't have more than one!");
124 mActorParent
= aActorParent
;
128 GetASCIIOrigin() const
134 nsPIDOMWindow
* GetParentObject() const
139 virtual JSObject
* WrapObject(JSContext
* aCx
,
140 JS::Handle
<JSObject
*> aScope
) MOZ_OVERRIDE
;
143 already_AddRefed
<nsIIDBOpenDBRequest
>
144 Open(const NonNull
<nsAString
>& aName
, const Optional
<uint64_t>& aVersion
,
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
);
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
,
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__