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
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
#include "mozIStorageConnection.h"
|
|
|
|
|
2013-03-31 01:18:30 -07:00
|
|
|
#include "mozilla/dom/BindingUtils.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
|
|
|
|
2012-01-23 08:18:14 -08:00
|
|
|
class nsIAtom;
|
2012-12-17 11:25:10 -08:00
|
|
|
class nsIFile;
|
|
|
|
class nsIFileURL;
|
2013-03-31 01:18:30 -07:00
|
|
|
class nsIIDBOpenDBRequest;
|
2012-01-24 02:03:37 -08:00
|
|
|
class nsPIDOMWindow;
|
2011-01-26 17:53:02 -08:00
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class ContentParent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
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;
|
2011-12-16 16:40:47 -08:00
|
|
|
typedef nsTArray<nsRefPtr<ObjectStoreInfo> > ObjectStoreInfoArray;
|
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,
|
|
|
|
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-03-31 01:18:30 -07:00
|
|
|
return Create(aWindow, 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>
|
|
|
|
GetDatabaseFileURL(nsIFile* aDatabaseFile, const nsACString& aOrigin);
|
|
|
|
|
2010-09-09 15:15:40 -07:00
|
|
|
static already_AddRefed<mozIStorageConnection>
|
2012-12-17 11:25:10 -08:00
|
|
|
GetConnection(const nsAString& aDatabaseFilePath,
|
|
|
|
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,
|
|
|
|
const nsACString& aASCIIOrigin,
|
|
|
|
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,
|
|
|
|
bool aDeleting,
|
|
|
|
IDBOpenDBRequest** _retval)
|
2012-10-29 23:11:58 -07:00
|
|
|
{
|
2013-06-20 11:05:33 -07:00
|
|
|
return OpenInternal(aName, aVersion, mASCIIOrigin, 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-03-31 01:18:30 -07:00
|
|
|
// WrapperCache
|
|
|
|
nsPIDOMWindow* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mWindow;
|
|
|
|
}
|
|
|
|
|
2013-04-25 09:29:54 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
2013-03-31 01:18:30 -07:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
already_AddRefed<nsIIDBOpenDBRequest>
|
2013-06-20 11:05:33 -07:00
|
|
|
Open(const NonNull<nsAString>& aName, const Optional<uint64_t>& aVersion,
|
|
|
|
ErrorResult& aRv)
|
2013-03-31 01:18:30 -07:00
|
|
|
{
|
2013-06-20 11:05:33 -07:00
|
|
|
return Open(nullptr, aName, aVersion, false, aRv);
|
2013-03-31 01:18:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIIDBOpenDBRequest>
|
2013-06-20 11:05:33 -07:00
|
|
|
DeleteDatabase(const NonNull<nsAString>& aName, ErrorResult& aRv)
|
2013-03-31 01:18:30 -07:00
|
|
|
{
|
2013-06-20 11:05:33 -07:00
|
|
|
return Open(nullptr, aName, Optional<uint64_t>(), true, 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
|
|
|
|
|
|
|
already_AddRefed<nsIIDBOpenDBRequest>
|
2013-06-20 11:05:33 -07:00
|
|
|
OpenForPrincipal(nsIPrincipal* aPrincipal, const NonNull<nsAString>& aName,
|
2013-03-31 01:18:30 -07:00
|
|
|
const Optional<uint64_t>& aVersion, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<nsIIDBOpenDBRequest>
|
2013-06-20 11:05:33 -07:00
|
|
|
DeleteForPrincipal(nsIPrincipal* aPrincipal, const NonNull<nsAString>& aName,
|
|
|
|
ErrorResult& aRv);
|
2013-03-31 01:18:30 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
private:
|
|
|
|
IDBFactory();
|
|
|
|
~IDBFactory();
|
|
|
|
|
2013-03-31 01:18:30 -07:00
|
|
|
already_AddRefed<nsIIDBOpenDBRequest>
|
2013-06-20 11:05:33 -07:00
|
|
|
Open(nsIPrincipal* aPrincipal, const nsAString& aName,
|
2013-03-31 01:18:30 -07:00
|
|
|
const Optional<uint64_t>& aVersion, bool aDelete, ErrorResult& aRv);
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsCString mASCIIOrigin;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-06-28 09:44:30 -07:00
|
|
|
#endif // mozilla_dom_indexeddb_idbfactory_h__
|