2010-06-23 12:46:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 09:44:30 -07:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbfactory_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbfactory_h__
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-09-05 23:43:23 -07:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h" // for Optional
|
2013-09-10 21:18:36 -07:00
|
|
|
#include "mozilla/dom/StorageTypeBinding.h"
|
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
|
|
|
#include "mozilla/dom/quota/StoragePrivilege.h"
|
2013-09-05 23:43:23 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2012-01-24 02:03:37 -08:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-03-31 01:18:30 -07:00
|
|
|
#include "nsWrapperCache.h"
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2013-09-05 23:43:23 -07:00
|
|
|
class mozIStorageConnection;
|
2012-01-23 08:18:14 -08:00
|
|
|
class nsIAtom;
|
2012-12-17 11:25:10 -08:00
|
|
|
class nsIFile;
|
|
|
|
class nsIFileURL;
|
2013-09-05 23:43:23 -07:00
|
|
|
class nsIPrincipal;
|
2012-01-24 02:03:37 -08:00
|
|
|
class nsPIDOMWindow;
|
2013-09-05 23:43:23 -07:00
|
|
|
template<typename> class nsRefPtr;
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
namespace mozilla {
|
2013-09-05 23:43:23 -07:00
|
|
|
class ErrorResult;
|
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
namespace dom {
|
|
|
|
class ContentParent;
|
2013-09-10 21:18:36 -07:00
|
|
|
class IDBOpenDBOptions;
|
2012-08-01 23:02:29 -07:00
|
|
|
|
2013-09-05 23:43:23 -07:00
|
|
|
namespace indexedDB {
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
struct DatabaseInfo;
|
2010-09-09 15:15:40 -07:00
|
|
|
class IDBDatabase;
|
2012-06-01 10:21:12 -07:00
|
|
|
class IDBOpenDBRequest;
|
|
|
|
class IndexedDBChild;
|
|
|
|
class IndexedDBParent;
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
struct ObjectStoreInfo;
|
2010-09-09 15:15:40 -07:00
|
|
|
|
2013-03-31 01:18:30 -07:00
|
|
|
class IDBFactory MOZ_FINAL : public nsISupports,
|
|
|
|
public nsWrapperCache
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2012-08-01 23:02:29 -07:00
|
|
|
typedef mozilla::dom::ContentParent ContentParent;
|
2013-09-10 21:18:36 -07:00
|
|
|
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
2011-12-16 16:40:47 -08:00
|
|
|
typedef nsTArray<nsRefPtr<ObjectStoreInfo> > ObjectStoreInfoArray;
|
2013-09-10 21:18:36 -07:00
|
|
|
typedef mozilla::dom::quota::StoragePrivilege StoragePrivilege;
|
2012-01-24 02:03:37 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
public:
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(IDBFactory)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-07-14 04:24:20 -07:00
|
|
|
// Called when using IndexedDB from a window in a different process.
|
2012-06-01 10:21:12 -07:00
|
|
|
static nsresult Create(nsPIDOMWindow* aWindow,
|
2013-09-10 21:18:36 -07:00
|
|
|
const nsACString& aGroup,
|
2012-06-01 10:21:12 -07:00
|
|
|
const nsACString& aASCIIOrigin,
|
2012-08-01 23:02:29 -07:00
|
|
|
ContentParent* aContentParent,
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBFactory** aFactory);
|
|
|
|
|
2012-07-14 04:24:20 -07:00
|
|
|
// Called when using IndexedDB from a window in the current process.
|
2012-06-01 10:21:12 -07:00
|
|
|
static nsresult Create(nsPIDOMWindow* aWindow,
|
2012-08-01 23:02:29 -07:00
|
|
|
ContentParent* aContentParent,
|
2013-03-31 01:18:30 -07:00
|
|
|
IDBFactory** aFactory)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
2013-09-10 21:18:36 -07:00
|
|
|
return Create(aWindow, EmptyCString(), EmptyCString(), aContentParent,
|
|
|
|
aFactory);
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2012-07-14 04:24:20 -07:00
|
|
|
// Called when using IndexedDB from a JS component or a JSM in the current
|
|
|
|
// process.
|
2012-06-01 10:21:12 -07:00
|
|
|
static nsresult Create(JSContext* aCx,
|
2013-05-10 19:39:45 -07:00
|
|
|
JS::Handle<JSObject*> aOwningObject,
|
2012-08-01 23:02:29 -07:00
|
|
|
ContentParent* aContentParent,
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBFactory** aFactory);
|
2012-01-24 02:03:37 -08:00
|
|
|
|
2012-07-14 04:24:20 -07:00
|
|
|
// Called when using IndexedDB from a JS component or a JSM in a different
|
|
|
|
// process.
|
2012-08-01 23:02:29 -07:00
|
|
|
static nsresult Create(ContentParent* aContentParent,
|
|
|
|
IDBFactory** aFactory);
|
2012-07-14 04:24:20 -07:00
|
|
|
|
2012-12-17 11:25:10 -08:00
|
|
|
static already_AddRefed<nsIFileURL>
|
2013-09-10 21:18:36 -07:00
|
|
|
GetDatabaseFileURL(nsIFile* aDatabaseFile,
|
|
|
|
PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
|
|
|
const nsACString& aOrigin);
|
2012-12-17 11:25:10 -08:00
|
|
|
|
2010-09-09 15:15:40 -07:00
|
|
|
static already_AddRefed<mozIStorageConnection>
|
2012-12-17 11:25:10 -08:00
|
|
|
GetConnection(const nsAString& aDatabaseFilePath,
|
2013-09-10 21:18:36 -07:00
|
|
|
PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
2012-12-17 11:25:10 -08:00
|
|
|
const nsACString& aOrigin);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-04-08 12:47:13 -07:00
|
|
|
static nsresult
|
|
|
|
SetDefaultPragmas(mozIStorageConnection* aConnection);
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
static nsresult
|
|
|
|
LoadDatabaseInformation(mozIStorageConnection* aConnection,
|
2011-11-02 05:53:12 -07:00
|
|
|
nsIAtom* aDatabaseId,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t* aVersion,
|
2010-10-19 10:58:52 -07:00
|
|
|
ObjectStoreInfoArray& aObjectStores);
|
|
|
|
|
|
|
|
static nsresult
|
2011-12-16 16:40:47 -08:00
|
|
|
SetDatabaseMetadata(DatabaseInfo* aDatabaseInfo,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t aVersion,
|
2011-12-16 16:40:47 -08:00
|
|
|
ObjectStoreInfoArray& aObjectStores);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
nsresult
|
2013-03-31 01:18:30 -07:00
|
|
|
OpenInternal(const nsAString& aName,
|
|
|
|
int64_t aVersion,
|
2013-09-10 21:18:36 -07:00
|
|
|
PersistenceType aPersistenceType,
|
|
|
|
const nsACString& aGroup,
|
2013-03-31 01:18:30 -07:00
|
|
|
const nsACString& aASCIIOrigin,
|
2013-09-10 21:18:36 -07:00
|
|
|
StoragePrivilege aStoragePrivilege,
|
2013-03-31 01:18:30 -07:00
|
|
|
bool aDeleting,
|
|
|
|
IDBOpenDBRequest** _retval);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2012-10-29 23:11:58 -07:00
|
|
|
nsresult
|
2013-03-31 01:18:30 -07:00
|
|
|
OpenInternal(const nsAString& aName,
|
|
|
|
int64_t aVersion,
|
2013-09-10 21:18:36 -07:00
|
|
|
PersistenceType aPersistenceType,
|
2013-03-31 01:18:30 -07:00
|
|
|
bool aDeleting,
|
|
|
|
IDBOpenDBRequest** _retval)
|
2012-10-29 23:11:58 -07:00
|
|
|
{
|
2013-09-10 21:18:36 -07:00
|
|
|
return OpenInternal(aName, aVersion, aPersistenceType, mGroup, mASCIIOrigin,
|
|
|
|
mPrivilege, aDeleting, _retval);
|
2012-10-29 23:11:58 -07:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
void
|
|
|
|
SetActor(IndexedDBChild* aActorChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
|
|
|
|
mActorChild = aActorChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetActor(IndexedDBParent* aActorParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorParent || !mActorParent, "Shouldn't have more than one!");
|
|
|
|
mActorParent = aActorParent;
|
|
|
|
}
|
|
|
|
|
2012-07-14 04:24:20 -07:00
|
|
|
const nsCString&
|
|
|
|
GetASCIIOrigin() const
|
|
|
|
{
|
|
|
|
return mASCIIOrigin;
|
|
|
|
}
|
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const
|
2013-03-31 01:18:30 -07:00
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:15 -07:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2013-09-10 21:18:36 -07:00
|
|
|
Open(const nsAString& aName, uint64_t aVersion, ErrorResult& aRv)
|
2013-03-31 01:18:30 -07:00
|
|
|
{
|
2013-09-10 21:18:36 -07:00
|
|
|
return Open(nullptr, aName, Optional<uint64_t>(aVersion),
|
|
|
|
Optional<mozilla::dom::StorageType>(), false, aRv);
|
2013-03-31 01:18:30 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 15:28:15 -07:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2013-09-10 21:18:36 -07:00
|
|
|
Open(const nsAString& aName, const IDBOpenDBOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
|
|
DeleteDatabase(const nsAString& aName, const IDBOpenDBOptions& aOptions,
|
|
|
|
ErrorResult& aRv);
|
2013-03-31 01:18:30 -07:00
|
|
|
|
|
|
|
int16_t
|
2013-05-10 19:39:45 -07:00
|
|
|
Cmp(JSContext* aCx, JS::Handle<JS::Value> aFirst,
|
|
|
|
JS::Handle<JS::Value> aSecond, ErrorResult& aRv);
|
2013-03-31 01:18:30 -07:00
|
|
|
|
2013-07-31 15:28:15 -07:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2013-07-22 05:15:43 -07:00
|
|
|
OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
|
2013-09-10 21:18:36 -07:00
|
|
|
uint64_t aVersion, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
|
|
|
OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
|
|
|
|
const IDBOpenDBOptions& aOptions, ErrorResult& aRv);
|
2013-03-31 01:18:30 -07:00
|
|
|
|
2013-07-31 15:28:15 -07:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2013-07-22 05:15:43 -07:00
|
|
|
DeleteForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
|
2013-09-10 21:18:36 -07:00
|
|
|
const IDBOpenDBOptions& aOptions, ErrorResult& aRv);
|
2013-03-31 01:18:30 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
private:
|
|
|
|
IDBFactory();
|
|
|
|
~IDBFactory();
|
|
|
|
|
2013-07-31 15:28:15 -07:00
|
|
|
already_AddRefed<IDBOpenDBRequest>
|
2013-06-20 11:05:33 -07:00
|
|
|
Open(nsIPrincipal* aPrincipal, const nsAString& aName,
|
2013-09-10 21:18:36 -07:00
|
|
|
const Optional<uint64_t>& aVersion,
|
|
|
|
const Optional<mozilla::dom::StorageType>& aStorageType, bool aDelete,
|
|
|
|
ErrorResult& aRv);
|
2013-03-31 01:18:30 -07:00
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
nsCString mGroup;
|
2012-06-01 10:21:12 -07:00
|
|
|
nsCString mASCIIOrigin;
|
2013-09-10 21:18:36 -07:00
|
|
|
StoragePrivilege mPrivilege;
|
|
|
|
PersistenceType mDefaultPersistenceType;
|
2011-11-07 16:15:45 -08:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
// If this factory lives on a window then mWindow must be non-null. Otherwise
|
|
|
|
// mOwningObject must be non-null.
|
|
|
|
nsCOMPtr<nsPIDOMWindow> mWindow;
|
2013-06-18 03:00:38 -07:00
|
|
|
JS::Heap<JSObject*> mOwningObject;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
IndexedDBChild* mActorChild;
|
|
|
|
IndexedDBParent* mActorParent;
|
2012-07-14 04:24:20 -07:00
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
mozilla::dom::ContentParent* mContentParent;
|
|
|
|
|
2012-07-14 04:24:20 -07:00
|
|
|
bool mRootedOwningObject;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2013-09-05 23:43:23 -07:00
|
|
|
} // namespace indexedDB
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-06-28 09:44:30 -07:00
|
|
|
#endif // mozilla_dom_indexeddb_idbfactory_h__
|