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:46:49 -07:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbdatabase_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbdatabase_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
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
#include "nsIDocument.h"
|
2012-06-03 09:33:52 -07:00
|
|
|
#include "nsIFileStorage.h"
|
2010-06-28 09:46:49 -07:00
|
|
|
#include "nsIIDBDatabase.h"
|
2012-02-07 18:53:33 -08:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2012-01-24 02:03:37 -08:00
|
|
|
#include "mozilla/dom/indexedDB/IDBWrapperCache.h"
|
|
|
|
#include "mozilla/dom/indexedDB/FileManager.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
class AsyncConnectionHelper;
|
|
|
|
struct DatabaseInfo;
|
2010-10-19 10:58:52 -07:00
|
|
|
class IDBIndex;
|
|
|
|
class IDBObjectStore;
|
2010-06-28 09:46:21 -07:00
|
|
|
class IDBTransaction;
|
2010-10-19 10:58:42 -07:00
|
|
|
class IndexedDatabaseManager;
|
2012-06-01 10:21:12 -07:00
|
|
|
class IndexedDBDatabaseChild;
|
|
|
|
class IndexedDBDatabaseParent;
|
|
|
|
struct ObjectStoreInfoGuts;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
class IDBDatabase : public IDBWrapperCache,
|
2012-06-03 09:33:52 -07:00
|
|
|
public nsIIDBDatabase,
|
|
|
|
public nsIFileStorage
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
friend class AsyncConnectionHelper;
|
2010-10-19 10:58:42 -07:00
|
|
|
friend class IndexedDatabaseManager;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
public:
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_DECL_NSIIDBDATABASE
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_DECL_NSIFILESTORAGE
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache)
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
static already_AddRefed<IDBDatabase>
|
2012-01-24 02:03:37 -08:00
|
|
|
Create(IDBWrapperCache* aOwnerCache,
|
2011-11-07 16:15:45 -08:00
|
|
|
already_AddRefed<DatabaseInfo> aDatabaseInfo,
|
2011-12-15 23:34:24 -08:00
|
|
|
const nsACString& aASCIIOrigin,
|
|
|
|
FileManager* aFileManager);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-06-23 19:18:00 -07:00
|
|
|
// nsIDOMEventTarget
|
2010-11-10 15:26:03 -08:00
|
|
|
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
|
|
|
|
|
2011-11-07 16:06:13 -08:00
|
|
|
nsIAtom* Id() const
|
2010-09-09 15:15:38 -07:00
|
|
|
{
|
2010-06-23 12:46:08 -07:00
|
|
|
return mDatabaseId;
|
|
|
|
}
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
DatabaseInfo* Info() const
|
|
|
|
{
|
|
|
|
return mDatabaseInfo;
|
|
|
|
}
|
2011-11-07 16:06:13 -08:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
const nsString& Name()
|
|
|
|
{
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
const nsString& FilePath()
|
|
|
|
{
|
2010-06-23 12:46:08 -07:00
|
|
|
return mFilePath;
|
|
|
|
}
|
|
|
|
|
2010-11-23 13:24:57 -08:00
|
|
|
already_AddRefed<nsIDocument> GetOwnerDocument()
|
|
|
|
{
|
2012-03-12 17:56:07 -07:00
|
|
|
if (!GetOwner()) {
|
2012-01-03 07:27:39 -08:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2012-03-12 17:56:07 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc =
|
|
|
|
do_QueryInterface(GetOwner()->GetExtantDocument());
|
2010-11-23 13:24:57 -08:00
|
|
|
return doc.forget();
|
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:40 -07:00
|
|
|
nsCString& Origin()
|
|
|
|
{
|
|
|
|
return mASCIIOrigin;
|
|
|
|
}
|
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
void Invalidate();
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
// Whether or not the database has been invalidated. If it has then no further
|
|
|
|
// transactions for this database will be allowed to run.
|
2010-09-10 12:12:11 -07:00
|
|
|
bool IsInvalidated();
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
void CloseInternal(bool aIsDead);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
// Whether or not the database has had Close called on it.
|
|
|
|
bool IsClosed();
|
|
|
|
|
2011-10-25 05:49:31 -07:00
|
|
|
void EnterSetVersionTransaction();
|
|
|
|
void ExitSetVersionTransaction();
|
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
FileManager* Manager() const
|
|
|
|
{
|
|
|
|
return mFileManager;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
void
|
|
|
|
SetActor(IndexedDBDatabaseChild* aActorChild)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorChild || !mActorChild, "Shouldn't have more than one!");
|
|
|
|
mActorChild = aActorChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetActor(IndexedDBDatabaseParent* aActorParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!aActorParent || !mActorParent,
|
|
|
|
"Shouldn't have more than one!");
|
|
|
|
mActorParent = aActorParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
IndexedDBDatabaseChild*
|
|
|
|
GetActorChild() const
|
|
|
|
{
|
|
|
|
return mActorChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateObjectStoreInternal(IDBTransaction* aTransaction,
|
|
|
|
const ObjectStoreInfoGuts& aInfo,
|
|
|
|
IDBObjectStore** _retval);
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
private:
|
2010-06-28 09:46:49 -07:00
|
|
|
IDBDatabase();
|
|
|
|
~IDBDatabase();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
void OnUnlink();
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
nsRefPtr<DatabaseInfo> mDatabaseInfo;
|
2011-11-02 05:53:12 -07:00
|
|
|
nsCOMPtr<nsIAtom> mDatabaseId;
|
2010-06-23 12:46:08 -07:00
|
|
|
nsString mName;
|
|
|
|
nsString mFilePath;
|
2010-09-09 15:15:38 -07:00
|
|
|
nsCString mASCIIOrigin;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-12-15 23:34:24 -08:00
|
|
|
nsRefPtr<FileManager> mFileManager;
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
// Only touched on the main thread.
|
2012-01-28 12:03:35 -08:00
|
|
|
NS_DECL_EVENT_HANDLER(abort)
|
|
|
|
NS_DECL_EVENT_HANDLER(error)
|
|
|
|
NS_DECL_EVENT_HANDLER(versionchange)
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
IndexedDBDatabaseChild* mActorChild;
|
|
|
|
IndexedDBDatabaseParent* mActorParent;
|
|
|
|
|
|
|
|
PRInt32 mInvalidated;
|
|
|
|
bool mRegistered;
|
|
|
|
bool mClosed;
|
|
|
|
bool mRunningVersionChange;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
#endif // mozilla_dom_indexeddb_idbdatabase_h__
|