2010-06-23 23:46:08 +04: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 15:12:37 +04: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 23:46:08 +04:00
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
#ifndef mozilla_dom_indexeddb_idbdatabase_h__
|
|
|
|
#define mozilla_dom_indexeddb_idbdatabase_h__
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-06-05 20:15:48 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2010-09-10 02:15:38 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IndexedDatabase.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
#include "nsIDocument.h"
|
2012-06-03 20:33:52 +04:00
|
|
|
#include "nsIFileStorage.h"
|
2010-06-28 20:46:49 +04:00
|
|
|
#include "nsIIDBDatabase.h"
|
2013-03-26 15:13:17 +04:00
|
|
|
#include "nsIOfflineStorage.h"
|
|
|
|
|
2012-02-08 06:53:33 +04:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
#include "mozilla/dom/indexedDB/FileManager.h"
|
2013-03-26 15:13:17 +04:00
|
|
|
#include "mozilla/dom/indexedDB/IDBWrapperCache.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-09-10 02:15:38 +04:00
|
|
|
class nsIScriptContext;
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class ContentParent;
|
2013-03-26 15:13:17 +04:00
|
|
|
namespace quota {
|
|
|
|
class Client;
|
|
|
|
}
|
2012-08-02 10:02:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
BEGIN_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
class AsyncConnectionHelper;
|
|
|
|
struct DatabaseInfo;
|
2012-08-30 04:50:28 +04:00
|
|
|
class IDBFactory;
|
2010-10-19 21:58:52 +04:00
|
|
|
class IDBIndex;
|
|
|
|
class IDBObjectStore;
|
2010-06-28 20:46:21 +04:00
|
|
|
class IDBTransaction;
|
2010-10-19 21:58:42 +04:00
|
|
|
class IndexedDatabaseManager;
|
2012-06-01 21:21:12 +04:00
|
|
|
class IndexedDBDatabaseChild;
|
|
|
|
class IndexedDBDatabaseParent;
|
|
|
|
struct ObjectStoreInfoGuts;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
class IDBDatabase : public IDBWrapperCache,
|
2012-06-03 20:33:52 +04:00
|
|
|
public nsIIDBDatabase,
|
2013-03-26 15:13:17 +04:00
|
|
|
public nsIOfflineStorage
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
friend class AsyncConnectionHelper;
|
2010-10-19 21:58:42 +04:00
|
|
|
friend class IndexedDatabaseManager;
|
2012-06-29 20:48:34 +04:00
|
|
|
friend class IndexedDBDatabaseChild;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
public:
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_DECL_NSIIDBDATABASE
|
2012-06-03 20:33:52 +04:00
|
|
|
NS_DECL_NSIFILESTORAGE
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_DECL_NSIOFFLINESTORAGE_NOCLOSE
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache)
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
static already_AddRefed<IDBDatabase>
|
2012-01-24 14:03:37 +04:00
|
|
|
Create(IDBWrapperCache* aOwnerCache,
|
2012-08-30 04:50:28 +04:00
|
|
|
IDBFactory* aFactory,
|
2011-11-08 04:15:45 +04:00
|
|
|
already_AddRefed<DatabaseInfo> aDatabaseInfo,
|
2011-12-16 11:34:24 +04:00
|
|
|
const nsACString& aASCIIOrigin,
|
2012-08-02 10:02:29 +04:00
|
|
|
FileManager* aFileManager,
|
|
|
|
mozilla::dom::ContentParent* aContentParent);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
static IDBDatabase*
|
|
|
|
FromStorage(nsIOfflineStorage* aStorage);
|
2010-11-11 02:26:03 +03:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
static IDBDatabase*
|
|
|
|
FromStorage(nsIFileStorage* aStorage)
|
2010-09-10 02:15:38 +04:00
|
|
|
{
|
2013-03-26 15:13:17 +04:00
|
|
|
nsCOMPtr<nsIOfflineStorage> storage = do_QueryInterface(aStorage);
|
|
|
|
return storage ? FromStorage(storage) : nullptr;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
// nsIDOMEventTarget
|
2013-06-05 20:15:48 +04:00
|
|
|
virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor) MOZ_OVERRIDE;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
DatabaseInfo* Info() const
|
|
|
|
{
|
|
|
|
return mDatabaseInfo;
|
|
|
|
}
|
2011-11-08 04:06:13 +04:00
|
|
|
|
2012-10-23 20:31:19 +04:00
|
|
|
const nsString& Name() const
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
|
|
|
return mName;
|
|
|
|
}
|
|
|
|
|
2012-10-23 20:31:19 +04:00
|
|
|
const nsString& FilePath() const
|
2010-09-10 02:15:38 +04:00
|
|
|
{
|
2010-06-23 23:46:08 +04:00
|
|
|
return mFilePath;
|
|
|
|
}
|
|
|
|
|
2010-11-24 00:24:57 +03:00
|
|
|
already_AddRefed<nsIDocument> GetOwnerDocument()
|
|
|
|
{
|
2012-03-13 04:56:07 +04:00
|
|
|
if (!GetOwner()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2012-01-03 19:27:39 +04:00
|
|
|
}
|
|
|
|
|
2013-04-24 08:22:37 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetOwner()->GetExtantDoc();
|
2010-11-24 00:24:57 +03:00
|
|
|
return doc.forget();
|
|
|
|
}
|
|
|
|
|
2012-11-10 07:29:07 +04:00
|
|
|
void DisconnectFromActorParent();
|
2012-10-05 23:09:33 +04:00
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
void CloseInternal(bool aIsDead);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2011-10-25 16:49:31 +04:00
|
|
|
void EnterSetVersionTransaction();
|
|
|
|
void ExitSetVersionTransaction();
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
// Called when a versionchange transaction is aborted to reset the
|
|
|
|
// DatabaseInfo.
|
|
|
|
void RevertToPreviousState();
|
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
FileManager* Manager() const
|
|
|
|
{
|
|
|
|
return mFileManager;
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04: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-10 07:29:07 +04:00
|
|
|
IndexedDBDatabaseParent*
|
|
|
|
GetActorParent() const
|
|
|
|
{
|
|
|
|
return mActorParent;
|
|
|
|
}
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
mozilla::dom::ContentParent*
|
|
|
|
GetContentParent() const
|
|
|
|
{
|
|
|
|
return mContentParent;
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
nsresult
|
|
|
|
CreateObjectStoreInternal(IDBTransaction* aTransaction,
|
|
|
|
const ObjectStoreInfoGuts& aInfo,
|
|
|
|
IDBObjectStore** _retval);
|
|
|
|
|
2010-09-10 02:15:38 +04:00
|
|
|
private:
|
2010-06-28 20:46:49 +04:00
|
|
|
IDBDatabase();
|
|
|
|
~IDBDatabase();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
void OnUnlink();
|
|
|
|
|
2012-08-30 04:50:28 +04: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-08 04:15:45 +04:00
|
|
|
nsRefPtr<DatabaseInfo> mDatabaseInfo;
|
2012-08-30 04:50:28 +04:00
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
// Set to a copy of the existing DatabaseInfo when starting a versionchange
|
|
|
|
// transaction.
|
|
|
|
nsRefPtr<DatabaseInfo> mPreviousDatabaseInfo;
|
2011-11-02 16:53:12 +04:00
|
|
|
nsCOMPtr<nsIAtom> mDatabaseId;
|
2010-06-23 23:46:08 +04:00
|
|
|
nsString mName;
|
|
|
|
nsString mFilePath;
|
2010-09-10 02:15:38 +04:00
|
|
|
nsCString mASCIIOrigin;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2011-12-16 11:34:24 +04:00
|
|
|
nsRefPtr<FileManager> mFileManager;
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
IndexedDBDatabaseChild* mActorChild;
|
|
|
|
IndexedDBDatabaseParent* mActorParent;
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
mozilla::dom::ContentParent* mContentParent;
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
nsRefPtr<mozilla::dom::quota::Client> mQuotaClient;
|
|
|
|
|
2012-10-05 23:09:33 +04:00
|
|
|
bool mInvalidated;
|
2012-06-01 21:21:12 +04:00
|
|
|
bool mRegistered;
|
|
|
|
bool mClosed;
|
|
|
|
bool mRunningVersionChange;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
END_INDEXEDDB_NAMESPACE
|
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
#endif // mozilla_dom_indexeddb_idbdatabase_h__
|