2010-06-23 23:46:08 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=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
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#ifndef mozilla_dom_idbdatabase_h__
|
|
|
|
#define mozilla_dom_idbdatabase_h__
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/dom/IDBTransactionBinding.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/StorageTypeBinding.h"
|
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
2019-03-29 21:05:11 +03:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
|
2017-01-13 11:40:58 +03:00
|
|
|
class nsIEventTarget;
|
2019-03-29 21:05:11 +03:00
|
|
|
class nsIGlobalObject;
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
namespace mozilla {
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
class ErrorResult;
|
2014-03-18 08:48:20 +04:00
|
|
|
class EventChainPostVisitor;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2015-05-12 15:09:51 +03:00
|
|
|
class Blob;
|
2014-09-27 03:21:57 +04:00
|
|
|
class DOMStringList;
|
2016-02-17 00:46:08 +03:00
|
|
|
class IDBFactory;
|
|
|
|
class IDBMutableFile;
|
|
|
|
class IDBObjectStore;
|
2014-09-27 03:21:57 +04:00
|
|
|
struct IDBObjectStoreParameters;
|
2016-02-17 00:46:08 +03:00
|
|
|
class IDBOpenDBRequest;
|
|
|
|
class IDBRequest;
|
|
|
|
class IDBTransaction;
|
2015-01-26 09:30:09 +03:00
|
|
|
template <class>
|
|
|
|
class Optional;
|
|
|
|
class StringOrStringSequence;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace indexedDB {
|
|
|
|
class BackgroundDatabaseChild;
|
|
|
|
class DatabaseSpec;
|
|
|
|
class PBackgroundIDBDatabaseFileChild;
|
2016-02-17 00:46:08 +03:00
|
|
|
} // namespace indexedDB
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2019-03-29 21:05:11 +03:00
|
|
|
class IDBDatabase final : public DOMEventTargetHelper {
|
2016-02-17 00:46:08 +03:00
|
|
|
typedef mozilla::dom::indexedDB::DatabaseSpec DatabaseSpec;
|
2014-09-27 03:21:57 +04:00
|
|
|
typedef mozilla::dom::StorageType StorageType;
|
|
|
|
typedef mozilla::dom::quota::PersistenceType PersistenceType;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
class Observer;
|
|
|
|
friend class Observer;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
friend class IDBObjectStore;
|
|
|
|
friend class IDBIndex;
|
|
|
|
|
2014-09-27 03:21:57 +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.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBFactory> mFactory;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsAutoPtr<DatabaseSpec> mSpec;
|
|
|
|
|
|
|
|
// Normally null except during a versionchange transaction.
|
|
|
|
nsAutoPtr<DatabaseSpec> mPreviousSpec;
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundDatabaseChild* mBackgroundActor;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
nsTHashtable<nsPtrHashKey<IDBTransaction>> mTransactions;
|
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
nsDataHashtable<nsISupportsHashKey,
|
|
|
|
indexedDB::PBackgroundIDBDatabaseFileChild*>
|
2014-09-27 03:21:57 +04:00
|
|
|
mFileActors;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Observer> mObserver;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
// Weak refs, IDBMutableFile strongly owns this IDBDatabase object.
|
|
|
|
nsTArray<IDBMutableFile*> mLiveMutableFiles;
|
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
const bool mFileHandleDisabled;
|
2014-09-27 03:21:57 +04:00
|
|
|
bool mClosed;
|
|
|
|
bool mInvalidated;
|
2016-04-21 07:53:30 +03:00
|
|
|
bool mQuotaExceeded;
|
2017-06-16 14:06:36 +03:00
|
|
|
bool mIncreasedActiveDatabaseCount;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
public:
|
2010-06-28 20:46:49 +04:00
|
|
|
static already_AddRefed<IDBDatabase> Create(
|
2015-09-09 14:15:05 +03:00
|
|
|
IDBOpenDBRequest* aRequest, IDBFactory* aFactory,
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundDatabaseChild* aActor, DatabaseSpec* aSpec);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
void AssertIsOnOwningThread() const
|
2017-06-07 08:55:00 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
2014-09-27 03:21:57 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
2010-11-11 02:26:03 +03:00
|
|
|
|
2017-01-13 11:40:58 +03:00
|
|
|
nsIEventTarget* EventTarget() const;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsString& Name() const;
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void GetName(nsAString& aName) const {
|
|
|
|
AssertIsOnOwningThread();
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
aName = Name();
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
uint64_t Version() const;
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
already_AddRefed<Document> GetOwnerDocument() const;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
void Close() {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
CloseInternal();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool IsClosed() const {
|
|
|
|
AssertIsOnOwningThread();
|
2012-01-03 19:27:39 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return mClosed;
|
2010-11-24 00:24:57 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void Invalidate();
|
|
|
|
|
2014-05-07 18:33:02 +04:00
|
|
|
// Whether or not the database has been invalidated. If it has then no further
|
2014-09-27 03:21:57 +04:00
|
|
|
// transactions for this database will be allowed to run.
|
|
|
|
bool IsInvalidated() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2014-05-07 18:33:02 +04:00
|
|
|
return mInvalidated;
|
|
|
|
}
|
|
|
|
|
2016-04-21 07:53:30 +03:00
|
|
|
void SetQuotaExceeded() { mQuotaExceeded = true; }
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void EnterSetVersionTransaction(uint64_t aNewVersion);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void ExitSetVersionTransaction();
|
2011-10-25 16:49:31 +04:00
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
// Called when a versionchange transaction is aborted to reset the
|
|
|
|
// DatabaseInfo.
|
2014-09-27 03:21:57 +04:00
|
|
|
void RevertToPreviousState();
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBFactory* Factory() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mFactory;
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void RegisterTransaction(IDBTransaction* aTransaction);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void UnregisterTransaction(IDBTransaction* aTransaction);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-11-14 05:20:38 +03:00
|
|
|
void AbortTransactions(bool aShouldWarn);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::PBackgroundIDBDatabaseFileChild* GetOrCreateFileActorForBlob(
|
2015-05-12 15:09:51 +03:00
|
|
|
Blob* aBlob);
|
2012-11-10 07:29:07 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
void NoteFinishedFileActor(
|
|
|
|
indexedDB::PBackgroundIDBDatabaseFileChild* aFileActor);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
void NoteActiveTransaction();
|
|
|
|
|
|
|
|
void NoteInactiveTransaction();
|
2013-11-04 16:57:53 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// XXX This doesn't really belong here... It's only needed for IDBMutableFile
|
2015-09-09 14:15:05 +03:00
|
|
|
// serialization and should be removed or fixed someday.
|
2014-09-27 03:21:57 +04:00
|
|
|
nsresult GetQuotaInfo(nsACString& aOrigin, PersistenceType* aPersistenceType);
|
2013-07-31 19:48:46 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
bool IsFileHandleDisabled() const { return mFileHandleDisabled; }
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void NoteLiveMutableFile(IDBMutableFile* aMutableFile);
|
2013-07-31 19:48:46 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void NoteFinishedMutableFile(IDBMutableFile* aMutableFile);
|
2013-07-31 19:48:46 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<DOMStringList> ObjectStoreNames() const;
|
2013-07-31 19:48:46 +04:00
|
|
|
|
|
|
|
already_AddRefed<IDBObjectStore> CreateObjectStore(
|
2014-12-11 21:07:44 +03:00
|
|
|
const nsAString& aName,
|
2013-07-31 19:48:46 +04:00
|
|
|
const IDBObjectStoreParameters& aOptionalParameters, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void DeleteObjectStore(const nsAString& name, ErrorResult& aRv);
|
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
// This will be called from the DOM.
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBTransaction> Transaction(
|
2016-03-23 18:02:57 +03:00
|
|
|
JSContext* aCx, const StringOrStringSequence& aStoreNames,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransactionMode aMode, ErrorResult& aRv);
|
2013-07-31 19:48:46 +04:00
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
// This can be called from C++ to avoid JS exception.
|
2016-03-23 18:02:57 +03:00
|
|
|
nsresult Transaction(JSContext* aCx,
|
|
|
|
const StringOrStringSequence& aStoreNames,
|
2015-01-26 09:30:09 +03:00
|
|
|
IDBTransactionMode aMode, IDBTransaction** aTransaction);
|
2013-07-31 19:48:46 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
StorageType Storage() const;
|
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
IMPL_EVENT_HANDLER(abort)
|
2016-05-31 13:08:20 +03:00
|
|
|
IMPL_EVENT_HANDLER(close)
|
2013-07-31 19:48:46 +04:00
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
IMPL_EVENT_HANDLER(versionchange)
|
|
|
|
|
2014-06-12 07:35:29 +04:00
|
|
|
already_AddRefed<IDBRequest> CreateMutableFile(
|
2014-09-27 03:21:57 +04:00
|
|
|
JSContext* aCx, const nsAString& aName, const Optional<nsAString>& aType,
|
2014-06-12 07:35:29 +04:00
|
|
|
ErrorResult& aRv);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
already_AddRefed<IDBRequest> MozCreateFileHandle(
|
2014-09-27 03:21:57 +04:00
|
|
|
JSContext* aCx, const nsAString& aName, const Optional<nsAString>& aType,
|
2014-06-12 07:35:29 +04:00
|
|
|
ErrorResult& aRv) {
|
2016-03-23 18:02:57 +03:00
|
|
|
return CreateMutableFile(aCx, aName, aType, aRv);
|
2014-06-12 07:35:29 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void ClearBackgroundActor() {
|
|
|
|
AssertIsOnOwningThread();
|
2011-12-16 11:34:24 +04:00
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
// Decrease the number of active databases if it was not done in
|
|
|
|
// CloseInternal().
|
|
|
|
MaybeDecreaseActiveDatabaseCount();
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mBackgroundActor = nullptr;
|
|
|
|
}
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const DatabaseSpec* Spec() const { return mSpec; }
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2019-03-29 21:05:11 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, DOMEventTargetHelper)
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2018-04-04 03:10:17 +03:00
|
|
|
// DOMEventTargetHelper
|
|
|
|
void DisconnectFromOwner() override;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void LastRelease() override;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// nsWrapperCache
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
private:
|
2015-09-09 14:15:05 +03:00
|
|
|
IDBDatabase(IDBOpenDBRequest* aRequest, IDBFactory* aFactory,
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundDatabaseChild* aActor, DatabaseSpec* aSpec);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
~IDBDatabase();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void CloseInternal();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void InvalidateInternal();
|
|
|
|
|
|
|
|
bool RunningVersionChangeTransaction() const {
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return !!mPreviousSpec;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RefreshSpec(bool aMayDelete);
|
|
|
|
|
|
|
|
void ExpireFileActors(bool aExpireAll);
|
|
|
|
|
|
|
|
void InvalidateMutableFiles();
|
2014-11-14 05:20:38 +03:00
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
void NoteInactiveTransactionDelayed();
|
|
|
|
|
2014-11-14 05:20:38 +03:00
|
|
|
void LogWarning(const char* aMessageName, const nsAString& aFilename,
|
2015-09-02 04:01:02 +03:00
|
|
|
uint32_t aLineNumber, uint32_t aColumnNumber);
|
2016-03-30 06:04:56 +03:00
|
|
|
|
|
|
|
// Only accessed by IDBObjectStore.
|
|
|
|
nsresult RenameObjectStore(int64_t aObjectStoreId, const nsAString& aName);
|
|
|
|
|
|
|
|
// Only accessed by IDBIndex.
|
|
|
|
nsresult RenameIndex(int64_t aObjectStoreId, int64_t aIndexId,
|
|
|
|
const nsAString& aName);
|
2017-06-16 14:06:36 +03:00
|
|
|
|
|
|
|
void IncreaseActiveDatabaseCount();
|
|
|
|
|
|
|
|
void MaybeDecreaseActiveDatabaseCount();
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
#endif // mozilla_dom_idbdatabase_h__
|