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"
|
2016-02-17 00:46:08 +03:00
|
|
|
#include "mozilla/dom/IDBWrapperCache.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/quota/PersistenceType.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
|
|
|
|
class nsIDocument;
|
2017-01-13 11:40:58 +03:00
|
|
|
class nsIEventTarget;
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
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
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class IDBDatabase final
|
2014-09-27 03:21:57 +04:00
|
|
|
: public IDBWrapperCache
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
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>
|
2015-09-09 14:15:05 +03:00
|
|
|
Create(IDBOpenDBRequest* aRequest,
|
2012-08-30 04:50:28 +04:00
|
|
|
IDBFactory* aFactory,
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundDatabaseChild* aActor,
|
2014-09-27 03:21:57 +04:00
|
|
|
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
|
2011-11-08 04:15:45 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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;
|
|
|
|
|
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
GetOwnerDocument() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
Close()
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
CloseInternal();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool
|
|
|
|
IsClosed() const
|
2010-11-24 00:24:57 +03:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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
|
2014-05-07 18:33:02 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
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
|
2011-12-16 11:34:24 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mFactory;
|
2011-12-16 11:34:24 +04:00
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
RegisterTransaction(IDBTransaction* aTransaction);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
UnregisterTransaction(IDBTransaction* aTransaction);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2014-11-14 05:20:38 +03:00
|
|
|
AbortTransactions(bool aShouldWarn);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::PBackgroundIDBDatabaseFileChild*
|
2015-05-12 15:09:51 +03:00
|
|
|
GetOrCreateFileActorForBlob(Blob* aBlob);
|
2012-11-10 07:29:07 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2016-02-17 00:46:08 +03:00
|
|
|
NoteFinishedFileActor(indexedDB::PBackgroundIDBDatabaseFileChild* aFileActor);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2017-06-16 14:06:36 +03:00
|
|
|
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
|
|
|
|
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
NoteFinishedMutableFile(IDBMutableFile* aMutableFile);
|
2013-07-31 19:48:46 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2014-09-27 03:21:57 +04:00
|
|
|
GetParentObject() const;
|
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>
|
2014-12-11 21:07:44 +03:00
|
|
|
CreateObjectStore(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>
|
2016-03-23 18:02:57 +03:00
|
|
|
Transaction(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.
|
|
|
|
nsresult
|
2016-03-23 18:02:57 +03:00
|
|
|
Transaction(JSContext* aCx,
|
|
|
|
const StringOrStringSequence& aStoreNames,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransactionMode aMode,
|
2015-01-26 09:30:09 +03:00
|
|
|
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>
|
2016-03-23 18:02:57 +03:00
|
|
|
CreateMutableFile(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
2014-09-27 03:21:57 +04:00
|
|
|
const Optional<nsAString>& aType,
|
2014-06-12 07:35:29 +04:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
MozCreateFileHandle(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
2014-09-27 03:21:57 +04:00
|
|
|
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
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBDatabase, IDBWrapperCache)
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2018-04-04 03:10:17 +03:00
|
|
|
// DOMEventTargetHelper
|
|
|
|
void
|
|
|
|
DisconnectFromOwner() override;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
virtual void
|
2015-03-21 19:28:04 +03:00
|
|
|
LastRelease() override;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
virtual nsresult
|
2015-03-21 19:28:04 +03:00
|
|
|
PostHandleEvent(EventChainPostVisitor& aVisitor) override;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// nsWrapperCache
|
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
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,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBFactory* aFactory,
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundDatabaseChild* aActor,
|
2014-09-27 03:21:57 +04:00
|
|
|
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__
|