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"
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "nsIOfflineStorage.h"
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-03-31 23:13:50 -07:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2013-07-31 08:48:46 -07:00
|
|
|
#include "mozilla/dom/IDBObjectStoreBinding.h"
|
|
|
|
#include "mozilla/dom/IDBTransactionBinding.h"
|
2013-09-10 21:18:36 -07:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
2013-03-26 04:13:17 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
#include "mozilla/dom/indexedDB/FileManager.h"
|
2013-07-31 08:48:46 -07:00
|
|
|
#include "mozilla/dom/indexedDB/IDBRequest.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 {
|
2014-03-17 21:48:20 -07:00
|
|
|
class EventChainPostVisitor;
|
2012-08-01 23:02:29 -07:00
|
|
|
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,
|
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
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_DECL_NSIFILESTORAGE
|
2013-07-31 08:48:46 -07:00
|
|
|
NS_DECL_NSIOFFLINESTORAGE
|
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
|
2014-03-17 21:48:20 -07:00
|
|
|
virtual nsresult PostHandleEvent(
|
|
|
|
EventChainPostVisitor& aVisitor) MOZ_OVERRIDE;
|
2013-03-26 04:13:17 -07:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2012-06-01 10:21:12 -07:00
|
|
|
CreateObjectStoreInternal(IDBTransaction* aTransaction,
|
|
|
|
const ObjectStoreInfoGuts& aInfo,
|
2013-07-31 08:48:46 -07:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-11-04 04:57:53 -08:00
|
|
|
IDBFactory*
|
|
|
|
Factory() const
|
|
|
|
{
|
|
|
|
return mFactory;
|
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2013-07-31 08:48:46 -07:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
nsPIDOMWindow*
|
|
|
|
GetParentObject() const
|
|
|
|
{
|
|
|
|
return GetOwner();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
GetName(nsString& aName) const
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
aName.Assign(mName);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
Version() const;
|
|
|
|
|
2013-07-09 10:54:21 -07:00
|
|
|
already_AddRefed<mozilla::dom::DOMStringList>
|
2013-07-31 08:48:46 -07:00
|
|
|
GetObjectStoreNames(ErrorResult& aRv) const;
|
|
|
|
|
|
|
|
already_AddRefed<IDBObjectStore>
|
|
|
|
CreateObjectStore(JSContext* aCx, const nsAString& aName,
|
|
|
|
const IDBObjectStoreParameters& aOptionalParameters,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
|
|
|
DeleteObjectStore(const nsAString& name, ErrorResult& aRv);
|
|
|
|
|
|
|
|
already_AddRefed<indexedDB::IDBTransaction>
|
|
|
|
Transaction(const nsAString& aStoreName, IDBTransactionMode aMode,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
Sequence<nsString> list;
|
|
|
|
list.AppendElement(aStoreName);
|
|
|
|
return Transaction(list, aMode, aRv);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<indexedDB::IDBTransaction>
|
|
|
|
Transaction(const Sequence<nsString>& aStoreNames, IDBTransactionMode aMode,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
IMPL_EVENT_HANDLER(versionchange)
|
|
|
|
|
2013-09-10 21:18:36 -07:00
|
|
|
mozilla::dom::StorageType
|
|
|
|
Storage() const
|
|
|
|
{
|
|
|
|
return PersistenceTypeToStorage(mPersistenceType);
|
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
|
|
|
MozCreateFileHandle(const nsAString& aName, const Optional<nsAString>& aType,
|
|
|
|
ErrorResult& aRv);
|
2012-06-01 10:21:12 -07:00
|
|
|
|
2013-07-09 10:30:58 -07:00
|
|
|
virtual void LastRelease() MOZ_OVERRIDE;
|
2013-11-04 04:57:53 -08:00
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
private:
|
2014-01-06 21:32:20 -08:00
|
|
|
IDBDatabase(IDBWrapperCache* aOwnerCache);
|
2010-06-28 09:46:49 -07:00
|
|
|
~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;
|
2013-11-25 08:53:48 -08:00
|
|
|
nsCString 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__
|