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"
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "nsIOfflineStorage.h"
|
|
|
|
|
2012-02-07 18:53:33 -08:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2013-03-26 04:13:17 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
#include "mozilla/dom/indexedDB/FileManager.h"
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "mozilla/dom/indexedDB/IDBWrapperCache.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class ContentParent;
|
2013-03-26 04:13:17 -07:00
|
|
|
namespace quota {
|
|
|
|
class Client;
|
|
|
|
}
|
2012-08-01 23:02:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
class AsyncConnectionHelper;
|
|
|
|
struct DatabaseInfo;
|
2012-08-29 17:50:28 -07:00
|
|
|
class IDBFactory;
|
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,
|
2013-03-26 04:13:17 -07:00
|
|
|
public nsIOfflineStorage
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
friend class AsyncConnectionHelper;
|
2010-10-19 10:58:42 -07:00
|
|
|
friend class IndexedDatabaseManager;
|
2012-06-29 09:48:34 -07:00
|
|
|
friend class IndexedDBDatabaseChild;
|
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
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_DECL_NSIOFFLINESTORAGE_NOCLOSE
|
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,
|
2012-08-29 17:50:28 -07:00
|
|
|
IDBFactory* aFactory,
|
2011-11-07 16:15:45 -08:00
|
|
|
already_AddRefed<DatabaseInfo> aDatabaseInfo,
|
2011-12-15 23:34:24 -08:00
|
|
|
const nsACString& aASCIIOrigin,
|
2012-08-01 23:02:29 -07:00
|
|
|
FileManager* aFileManager,
|
|
|
|
mozilla::dom::ContentParent* aContentParent);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
static IDBDatabase*
|
|
|
|
FromStorage(nsIOfflineStorage* aStorage);
|
2010-11-10 15:26:03 -08:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
static IDBDatabase*
|
|
|
|
FromStorage(nsIFileStorage* aStorage)
|
2010-09-09 15:15:38 -07:00
|
|
|
{
|
2013-03-26 04:13:17 -07:00
|
|
|
nsCOMPtr<nsIOfflineStorage> storage = do_QueryInterface(aStorage);
|
|
|
|
return storage ? FromStorage(storage) : nullptr;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
// nsIDOMEventTarget
|
|
|
|
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
DatabaseInfo* Info() const
|
|
|
|
{
|
|
|
|
return mDatabaseInfo;
|
|
|
|
}
|
2011-11-07 16:06:13 -08:00
|
|
|
|
2012-10-23 09:31:19 -07:00
|
|
|
const nsString& Name() const
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
2012-10-23 09:31:19 -07:00
|
|
|
const nsString& FilePath() const
|
2010-09-09 15:15:38 -07:00
|
|
|
{
|
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-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-01-03 07:27:39 -08:00
|
|
|
}
|
|
|
|
|
2013-04-23 21:22:37 -07:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
|
2010-11-23 13:24:57 -08:00
|
|
|
return doc.forget();
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:29:07 -08:00
|
|
|
void DisconnectFromActorParent();
|
2012-10-05 12:09:33 -07:00
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
void CloseInternal(bool aIsDead);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2011-10-25 05:49:31 -07:00
|
|
|
void EnterSetVersionTransaction();
|
|
|
|
void ExitSetVersionTransaction();
|
|
|
|
|
2012-06-29 09:48:34 -07:00
|
|
|
// Called when a versionchange transaction is aborted to reset the
|
|
|
|
// DatabaseInfo.
|
|
|
|
void RevertToPreviousState();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-09 19:29:07 -08:00
|
|
|
IndexedDBDatabaseParent*
|
|
|
|
GetActorParent() const
|
|
|
|
{
|
|
|
|
return mActorParent;
|
|
|
|
}
|
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
mozilla::dom::ContentParent*
|
|
|
|
GetContentParent() const
|
|
|
|
{
|
|
|
|
return mContentParent;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
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();
|
|
|
|
|
2012-08-29 17:50:28 -07:00
|
|
|
// The factory must be kept alive when IndexedDB is used in multiple
|
|
|
|
// processes. If it dies then the entire actor tree will be destroyed with it
|
|
|
|
// and the world will explode.
|
|
|
|
nsRefPtr<IDBFactory> mFactory;
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
nsRefPtr<DatabaseInfo> mDatabaseInfo;
|
2012-08-29 17:50:28 -07:00
|
|
|
|
2012-06-29 09:48:34 -07:00
|
|
|
// Set to a copy of the existing DatabaseInfo when starting a versionchange
|
|
|
|
// transaction.
|
|
|
|
nsRefPtr<DatabaseInfo> mPreviousDatabaseInfo;
|
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;
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
IndexedDBDatabaseChild* mActorChild;
|
|
|
|
IndexedDBDatabaseParent* mActorParent;
|
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
mozilla::dom::ContentParent* mContentParent;
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
nsRefPtr<mozilla::dom::quota::Client> mQuotaClient;
|
|
|
|
|
2012-10-05 12:09:33 -07:00
|
|
|
bool mInvalidated;
|
2012-06-01 10:21:12 -07:00
|
|
|
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__
|