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_idbtransaction_h__
|
|
|
|
#define mozilla_dom_idbtransaction_h__
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-06-05 20:15:48 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-07-29 21:12:21 +04:00
|
|
|
#include "mozilla/dom/IDBTransactionBinding.h"
|
2016-02-17 00:46:08 +03:00
|
|
|
#include "mozilla/dom/IDBWrapperCache.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsIRunnable.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2012-01-24 14:03:37 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-03-18 08:48:19 +04:00
|
|
|
namespace mozilla {
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
class ErrorResult;
|
2014-03-18 08:48:19 +04:00
|
|
|
class EventChainPreVisitor;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace dom {
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
class DOMError;
|
|
|
|
class DOMStringList;
|
2016-02-17 00:46:08 +03:00
|
|
|
class IDBDatabase;
|
|
|
|
class IDBObjectStore;
|
|
|
|
class IDBOpenDBRequest;
|
|
|
|
class IDBRequest;
|
2011-10-20 20:10:56 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace indexedDB {
|
|
|
|
class BackgroundCursorChild;
|
|
|
|
class BackgroundRequestChild;
|
|
|
|
class BackgroundTransactionChild;
|
|
|
|
class BackgroundVersionChangeTransactionChild;
|
|
|
|
class IndexMetadata;
|
|
|
|
class ObjectStoreSpec;
|
|
|
|
class OpenCursorParams;
|
|
|
|
class RequestParams;
|
2016-02-17 00:46:08 +03:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class IDBTransaction final
|
2014-09-27 03:21:57 +04:00
|
|
|
: public IDBWrapperCache
|
|
|
|
, public nsIRunnable
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2016-02-17 00:46:08 +03:00
|
|
|
friend class indexedDB::BackgroundCursorChild;
|
|
|
|
friend class indexedDB::BackgroundRequestChild;
|
2015-03-19 00:20:59 +03:00
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
class WorkerHolder;
|
|
|
|
friend class WorkerHolder;
|
2014-12-17 09:26:15 +03:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
public:
|
2012-03-13 08:44:45 +04:00
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
READ_ONLY = 0,
|
|
|
|
READ_WRITE,
|
2015-01-26 09:30:09 +03:00
|
|
|
READ_WRITE_FLUSH,
|
2016-03-15 09:00:37 +03:00
|
|
|
CLEANUP,
|
2012-06-01 21:21:12 +04:00
|
|
|
VERSION_CHANGE,
|
|
|
|
|
|
|
|
// Only needed for IPC serialization helper, should never be used in code.
|
|
|
|
MODE_INVALID
|
2012-03-13 08:44:45 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
enum ReadyState
|
|
|
|
{
|
|
|
|
INITIAL = 0,
|
|
|
|
LOADING,
|
|
|
|
COMMITTING,
|
|
|
|
DONE
|
|
|
|
};
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
private:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBDatabase> mDatabase;
|
|
|
|
RefPtr<DOMError> mError;
|
2014-09-27 03:21:57 +04:00
|
|
|
nsTArray<nsString> mObjectStoreNames;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<IDBObjectStore>> mObjectStores;
|
|
|
|
nsTArray<RefPtr<IDBObjectStore>> mDeletedObjectStores;
|
2016-06-23 11:53:14 +03:00
|
|
|
nsAutoPtr<WorkerHolder> mWorkerHolder;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Tagged with mMode. If mMode is VERSION_CHANGE then mBackgroundActor will be
|
|
|
|
// a BackgroundVersionChangeTransactionChild. Otherwise it will be a
|
|
|
|
// BackgroundTransactionChild.
|
|
|
|
union {
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundTransactionChild* mNormalBackgroundActor;
|
|
|
|
indexedDB::BackgroundVersionChangeTransactionChild* mVersionChangeBackgroundActor;
|
2014-09-27 03:21:57 +04:00
|
|
|
} mBackgroundActor;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
const int64_t mLoggingSerialNumber;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Only used for VERSION_CHANGE transactions.
|
|
|
|
int64_t mNextObjectStoreId;
|
|
|
|
int64_t mNextIndexId;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsresult mAbortCode;
|
|
|
|
uint32_t mPendingRequestCount;
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-11-14 05:20:38 +03:00
|
|
|
nsString mFilename;
|
|
|
|
uint32_t mLineNo;
|
2015-09-02 04:01:02 +03:00
|
|
|
uint32_t mColumn;
|
2014-11-14 05:20:38 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
ReadyState mReadyState;
|
|
|
|
Mode mMode;
|
|
|
|
|
|
|
|
bool mCreating;
|
2014-12-17 09:26:15 +03:00
|
|
|
bool mRegistered;
|
2014-09-27 03:21:57 +04:00
|
|
|
bool mAbortedByScript;
|
2017-06-16 14:06:36 +03:00
|
|
|
bool mNotedActiveTransaction;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool mSentCommitOrAbort;
|
|
|
|
bool mFiredCompleteOrAbort;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<IDBTransaction>
|
|
|
|
CreateVersionChange(IDBDatabase* aDatabase,
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundVersionChangeTransactionChild* aActor,
|
2014-11-14 05:20:38 +03:00
|
|
|
IDBOpenDBRequest* aOpenRequest,
|
2014-09-27 03:21:57 +04:00
|
|
|
int64_t aNextObjectStoreId,
|
|
|
|
int64_t aNextIndexId);
|
|
|
|
|
|
|
|
static already_AddRefed<IDBTransaction>
|
2016-03-23 18:02:57 +03:00
|
|
|
Create(JSContext* aCx, IDBDatabase* aDatabase,
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode);
|
|
|
|
|
|
|
|
static IDBTransaction*
|
|
|
|
GetCurrent();
|
|
|
|
|
|
|
|
void
|
|
|
|
AssertIsOnOwningThread() const
|
|
|
|
#ifdef DEBUG
|
|
|
|
;
|
|
|
|
#else
|
|
|
|
{ }
|
|
|
|
#endif
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2016-02-17 00:46:08 +03:00
|
|
|
SetBackgroundActor(indexedDB::BackgroundTransactionChild* aBackgroundActor);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
ClearBackgroundActor()
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (mMode == VERSION_CHANGE) {
|
|
|
|
mBackgroundActor.mVersionChangeBackgroundActor = nullptr;
|
|
|
|
} else {
|
|
|
|
mBackgroundActor.mNormalBackgroundActor = nullptr;
|
|
|
|
}
|
2017-06-16 14:06:36 +03:00
|
|
|
|
|
|
|
// Note inactive transaction here if we didn't receive the Complete message
|
|
|
|
// from the parent.
|
|
|
|
MaybeNoteInactiveTransaction();
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2016-02-17 00:46:08 +03:00
|
|
|
indexedDB::BackgroundRequestChild*
|
|
|
|
StartRequest(IDBRequest* aRequest, const indexedDB::RequestParams& aParams);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
void
|
2016-02-17 00:46:08 +03:00
|
|
|
OpenCursor(indexedDB::BackgroundCursorChild* aBackgroundActor,
|
|
|
|
const indexedDB::OpenCursorParams& aParams);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
RefreshSpec(bool aMayDelete);
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsOpen() const;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool
|
2015-06-26 01:22:59 +03:00
|
|
|
IsCommittingOrDone() const
|
2012-06-26 19:09:25 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2015-06-26 01:22:59 +03:00
|
|
|
|
|
|
|
return mReadyState == COMMITTING || mReadyState == DONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsDone() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
return mReadyState == DONE;
|
2012-06-26 19:09:25 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool
|
|
|
|
IsWriteAllowed() const
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2015-01-26 09:30:09 +03:00
|
|
|
return mMode == READ_WRITE ||
|
|
|
|
mMode == READ_WRITE_FLUSH ||
|
2016-03-15 09:00:37 +03:00
|
|
|
mMode == CLEANUP ||
|
2015-01-26 09:30:09 +03:00
|
|
|
mMode == VERSION_CHANGE;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
bool
|
|
|
|
IsAborted() const
|
2010-12-16 00:21:17 +03:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
return NS_FAILED(mAbortCode);
|
2010-12-16 00:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-11-20 06:03:01 +03:00
|
|
|
nsresult
|
|
|
|
AbortCode() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mAbortCode;
|
|
|
|
}
|
|
|
|
|
2014-11-14 05:20:38 +03:00
|
|
|
void
|
2015-09-02 04:01:02 +03:00
|
|
|
GetCallerLocation(nsAString& aFilename, uint32_t* aLineNo,
|
|
|
|
uint32_t* aColumn) const;
|
2014-11-14 05:20:38 +03:00
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
// 'Get' prefix is to avoid name collisions with the enum
|
2014-09-27 03:21:57 +04:00
|
|
|
Mode
|
|
|
|
GetMode() const
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-10-19 21:58:52 +04:00
|
|
|
return mMode;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase*
|
|
|
|
Database() const
|
2010-08-27 00:57:25 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-09-10 02:15:38 +04:00
|
|
|
return mDatabase;
|
2010-08-27 00:57:25 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase*
|
|
|
|
Db() const
|
2011-12-17 04:40:47 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
return Database();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<nsString>&
|
|
|
|
ObjectStoreNamesInternal() const
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
return mObjectStoreNames;
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2012-11-10 07:29:07 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2016-02-17 00:46:08 +03:00
|
|
|
CreateObjectStore(const indexedDB::ObjectStoreSpec& aSpec);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2014-09-13 20:12:19 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
DeleteObjectStore(int64_t aObjectStoreId);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
void
|
|
|
|
RenameObjectStore(int64_t aObjectStoreId, const nsAString& aName);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2016-02-17 00:46:08 +03:00
|
|
|
CreateIndex(IDBObjectStore* aObjectStore, const indexedDB::IndexMetadata& aMetadata);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
DeleteIndex(IDBObjectStore* aObjectStore, int64_t aIndexId);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
void
|
|
|
|
RenameIndex(IDBObjectStore* aObjectStore, int64_t aIndexId, const nsAString& aName);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2012-06-29 20:48:34 +04:00
|
|
|
Abort(IDBRequest* aRequest);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2012-06-29 20:48:34 +04:00
|
|
|
Abort(nsresult aAbortCode);
|
2012-06-25 23:15:17 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
int64_t
|
|
|
|
LoggingSerialNumber() const
|
2013-03-16 10:58:50 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-10-16 08:56:52 +04:00
|
|
|
|
|
|
|
return mLoggingSerialNumber;
|
2013-03-16 10:58:50 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2014-09-27 03:21:57 +04:00
|
|
|
GetParentObject() const;
|
2013-07-29 21:12:21 +04:00
|
|
|
|
|
|
|
IDBTransactionMode
|
|
|
|
GetMode(ErrorResult& aRv) const;
|
|
|
|
|
|
|
|
DOMError*
|
2014-05-20 21:39:31 +04:00
|
|
|
GetError() const;
|
2013-07-29 21:12:21 +04:00
|
|
|
|
2013-07-31 19:48:36 +04:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2013-07-29 21:12:21 +04:00
|
|
|
ObjectStore(const nsAString& aName, ErrorResult& aRv);
|
|
|
|
|
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
Abort(ErrorResult& aRv);
|
2013-07-29 21:12:21 +04:00
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(abort)
|
|
|
|
IMPL_EVENT_HANDLER(complete)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2013-07-09 21:54:21 +04:00
|
|
|
already_AddRefed<DOMStringList>
|
2015-08-25 23:30:18 +03:00
|
|
|
ObjectStoreNames() const;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
FireCompleteOrAbortEvents(nsresult aResult);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Only for VERSION_CHANGE transactions.
|
|
|
|
int64_t
|
|
|
|
NextObjectStoreId();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Only for VERSION_CHANGE transactions.
|
|
|
|
int64_t
|
|
|
|
NextIndexId();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_DECL_NSIRUNNABLE
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(IDBTransaction, IDBWrapperCache)
|
2010-06-23 23:46:08 +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-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// nsIDOMEventTarget
|
|
|
|
virtual nsresult
|
2016-10-21 05:11:07 +03:00
|
|
|
GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
|
2014-09-18 03:36:01 +04:00
|
|
|
|
|
|
|
private:
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransaction(IDBDatabase* aDatabase,
|
|
|
|
const nsTArray<nsString>& aObjectStoreNames,
|
|
|
|
Mode aMode);
|
|
|
|
~IDBTransaction();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
AbortInternal(nsresult aAbortCode, already_AddRefed<DOMError> aError);
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
SendCommit();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
SendAbort(nsresult aResultCode);
|
2015-03-19 00:20:59 +03:00
|
|
|
|
2017-06-16 14:06:36 +03:00
|
|
|
void
|
|
|
|
NoteActiveTransaction();
|
|
|
|
|
|
|
|
void
|
|
|
|
MaybeNoteInactiveTransaction();
|
|
|
|
|
2015-03-19 00:20:59 +03:00
|
|
|
void
|
|
|
|
OnNewRequest();
|
|
|
|
|
|
|
|
void
|
|
|
|
OnRequestFinished(bool aActorDestroyedNormally);
|
2014-09-18 03:36:01 +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_idbtransaction_h__
|