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
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
#include "IDBDatabase.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-03-15 23:58:50 -07:00
|
|
|
#include "DictionaryHelpers.h"
|
2010-09-09 15:15:40 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "mozilla/storage.h"
|
2012-08-01 23:02:29 -07:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2013-03-26 04:13:17 -07:00
|
|
|
#include "mozilla/dom/quota/Client.h"
|
2012-12-19 09:45:57 -08:00
|
|
|
#include "mozilla/dom/quota/QuotaManager.h"
|
2013-03-15 23:58:50 -07:00
|
|
|
#include "nsContentUtils.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsDOMClassInfo.h"
|
2011-12-15 23:34:24 -08:00
|
|
|
#include "nsDOMLists.h"
|
2010-12-21 08:02:01 -08:00
|
|
|
#include "nsJSUtils.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "nsProxyRelease.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "AsyncConnectionHelper.h"
|
|
|
|
#include "DatabaseInfo.h"
|
|
|
|
#include "IDBEvents.h"
|
2012-08-29 17:50:28 -07:00
|
|
|
#include "IDBFactory.h"
|
2012-06-03 09:33:52 -07:00
|
|
|
#include "IDBFileHandle.h"
|
2010-10-19 10:58:52 -07:00
|
|
|
#include "IDBIndex.h"
|
2010-06-28 11:51:06 -07:00
|
|
|
#include "IDBObjectStore.h"
|
2010-06-28 09:46:21 -07:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-28 09:44:30 -07:00
|
|
|
#include "IDBFactory.h"
|
2013-03-15 23:58:50 -07:00
|
|
|
#include "ProfilerHelpers.h"
|
2010-09-10 12:12:11 -07:00
|
|
|
#include "TransactionThreadPool.h"
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
#include "ipc/IndexedDBChild.h"
|
2012-10-23 09:31:19 -07:00
|
|
|
#include "ipc/IndexedDBParent.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-05-17 18:48:25 -07:00
|
|
|
#include "mozilla/dom/IDBDatabaseBinding.h"
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
USING_INDEXEDDB_NAMESPACE
|
2012-08-01 23:02:29 -07:00
|
|
|
using mozilla::dom::ContentParent;
|
2013-06-05 01:11:23 -07:00
|
|
|
using mozilla::dom::quota::AssertIsOnIOThread;
|
2013-03-26 04:13:17 -07:00
|
|
|
using mozilla::dom::quota::Client;
|
2012-12-19 09:45:57 -08:00
|
|
|
using mozilla::dom::quota::QuotaManager;
|
2013-07-31 08:48:46 -07:00
|
|
|
using mozilla::ErrorResult;
|
2013-05-17 18:48:25 -07:00
|
|
|
using namespace mozilla::dom;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
class NoRequestDatabaseHelper : public AsyncConnectionHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NoRequestDatabaseHelper(IDBTransaction* aTransaction)
|
2012-07-30 07:20:58 -07:00
|
|
|
: AsyncConnectionHelper(aTransaction, nullptr)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
NS_ASSERTION(aTransaction, "Null transaction!");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ChildProcessSendResult
|
2012-10-05 12:09:33 -07:00
|
|
|
SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE;
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
virtual nsresult
|
|
|
|
UnpackResponseFromParentProcess(const ResponseValue& aResponseValue)
|
|
|
|
MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual nsresult OnSuccess() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
virtual void OnError() MOZ_OVERRIDE;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CreateObjectStoreHelper : public NoRequestDatabaseHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-06-28 09:46:21 -07:00
|
|
|
CreateObjectStoreHelper(IDBTransaction* aTransaction,
|
2010-10-19 10:58:52 -07:00
|
|
|
IDBObjectStore* aObjectStore)
|
2012-06-01 10:21:12 -07:00
|
|
|
: NoRequestDatabaseHelper(aTransaction), mObjectStore(aObjectStore)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual nsresult DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
MOZ_OVERRIDE;
|
2011-01-06 22:21:36 -08:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
private:
|
|
|
|
nsRefPtr<IDBObjectStore> mObjectStore;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
class DeleteObjectStoreHelper : public NoRequestDatabaseHelper
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-11-10 15:25:57 -08:00
|
|
|
DeleteObjectStoreHelper(IDBTransaction* aTransaction,
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t aObjectStoreId)
|
2012-06-01 10:21:12 -07:00
|
|
|
: NoRequestDatabaseHelper(aTransaction), mObjectStoreId(aObjectStoreId)
|
2010-06-23 12:46:08 -07:00
|
|
|
{ }
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
virtual nsresult DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
MOZ_OVERRIDE;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
// In-params.
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mObjectStoreId;
|
2010-06-23 12:46:08 -07:00
|
|
|
};
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
class CreateFileHelper : public AsyncConnectionHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CreateFileHelper(IDBDatabase* aDatabase,
|
|
|
|
IDBRequest* aRequest,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsAString& aType)
|
|
|
|
: AsyncConnectionHelper(aDatabase, aRequest),
|
|
|
|
mName(aName), mType(aType)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
~CreateFileHelper()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
|
|
|
nsresult GetSuccessResult(JSContext* aCx,
|
2013-06-21 06:12:46 -07:00
|
|
|
JS::MutableHandle<JS::Value> aVal);
|
2012-06-03 09:33:52 -07:00
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mFileInfo = nullptr;
|
2012-06-03 09:33:52 -07:00
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2012-10-05 12:09:33 -07:00
|
|
|
virtual ChildProcessSendResult SendResponseToChildProcess(
|
2012-06-03 09:33:52 -07:00
|
|
|
nsresult aResultCode)
|
|
|
|
MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return Success_NotSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult UnpackResponseFromParentProcess(
|
|
|
|
const ResponseValue& aResponseValue)
|
|
|
|
MOZ_OVERRIDE
|
|
|
|
{
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Should never get here!");
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// In-params.
|
|
|
|
nsString mName;
|
|
|
|
nsString mType;
|
|
|
|
|
|
|
|
// Out-params.
|
|
|
|
nsRefPtr<FileInfo> mFileInfo;
|
|
|
|
};
|
|
|
|
|
2013-04-11 20:20:18 -07:00
|
|
|
class MOZ_STACK_CLASS AutoRemoveObjectStore
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
|
|
|
public:
|
2011-12-16 16:40:47 -08:00
|
|
|
AutoRemoveObjectStore(DatabaseInfo* aInfo, const nsAString& aName)
|
|
|
|
: mInfo(aInfo), mName(aName)
|
2010-10-19 10:58:52 -07:00
|
|
|
{ }
|
|
|
|
|
|
|
|
~AutoRemoveObjectStore()
|
|
|
|
{
|
2011-12-16 16:40:47 -08:00
|
|
|
if (mInfo) {
|
|
|
|
mInfo->RemoveObjectStore(mName);
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void forget()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mInfo = nullptr;
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-12-16 16:40:47 -08:00
|
|
|
DatabaseInfo* mInfo;
|
2010-10-19 10:58:52 -07:00
|
|
|
nsString mName;
|
|
|
|
};
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// static
|
2010-06-28 09:46:49 -07:00
|
|
|
already_AddRefed<IDBDatabase>
|
2012-01-24 02:03:37 -08:00
|
|
|
IDBDatabase::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
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2012-08-29 17:50:28 -07:00
|
|
|
NS_ASSERTION(aFactory, "Null pointer!");
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_ASSERTION(!aASCIIOrigin.IsEmpty(), "Empty origin!");
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
nsRefPtr<DatabaseInfo> databaseInfo(aDatabaseInfo);
|
|
|
|
NS_ASSERTION(databaseInfo, "Null pointer!");
|
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
nsRefPtr<IDBDatabase> db(new IDBDatabase());
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-03-12 17:56:07 -07:00
|
|
|
db->BindToOwner(aOwnerCache);
|
2012-11-29 14:54:14 -08:00
|
|
|
db->SetScriptOwner(aOwnerCache->GetScriptOwner());
|
2012-08-29 17:50:28 -07:00
|
|
|
db->mFactory = aFactory;
|
2011-11-07 16:15:45 -08:00
|
|
|
db->mDatabaseId = databaseInfo->id;
|
|
|
|
db->mName = databaseInfo->name;
|
|
|
|
db->mFilePath = databaseInfo->filePath;
|
|
|
|
databaseInfo.swap(db->mDatabaseInfo);
|
2010-09-09 15:15:38 -07:00
|
|
|
db->mASCIIOrigin = aASCIIOrigin;
|
2011-12-15 23:34:24 -08:00
|
|
|
db->mFileManager = aFileManager;
|
2012-08-01 23:02:29 -07:00
|
|
|
db->mContentParent = aContentParent;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "This should never be null!");
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
db->mQuotaClient = quotaManager->GetClient(Client::IDB);
|
|
|
|
NS_ASSERTION(db->mQuotaClient, "This shouldn't fail!");
|
|
|
|
|
|
|
|
if (!quotaManager->RegisterStorage(db)) {
|
2010-10-19 10:58:42 -07:00
|
|
|
// Either out of memory or shutting down.
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-09-10 12:12:11 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
db->mRegistered = true;
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
return db.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
// static
|
|
|
|
IDBDatabase*
|
|
|
|
IDBDatabase::FromStorage(nsIOfflineStorage* aStorage)
|
|
|
|
{
|
|
|
|
return aStorage->GetClient()->GetType() == Client::IDB ?
|
|
|
|
static_cast<IDBDatabase*>(aStorage) : nullptr;
|
|
|
|
}
|
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
IDBDatabase::IDBDatabase()
|
2010-09-10 12:12:11 -07:00
|
|
|
: mDatabaseId(0),
|
2012-07-30 07:20:58 -07:00
|
|
|
mActorChild(nullptr),
|
|
|
|
mActorParent(nullptr),
|
2012-08-01 23:02:29 -07:00
|
|
|
mContentParent(nullptr),
|
2012-10-05 12:09:33 -07:00
|
|
|
mInvalidated(false),
|
2010-10-19 10:58:52 -07:00
|
|
|
mRegistered(false),
|
2011-11-07 16:15:45 -08:00
|
|
|
mClosed(false),
|
|
|
|
mRunningVersionChange(false)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2010-09-10 12:12:11 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2013-07-31 08:48:46 -07:00
|
|
|
|
|
|
|
SetIsDOMBinding();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
IDBDatabase::~IDBDatabase()
|
2013-07-09 10:30:58 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IDBDatabase::LastRelease()
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2010-09-10 12:12:11 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
NS_ASSERTION(!mActorParent, "Actor parent owns us, how can we be dying?!");
|
|
|
|
if (mActorChild) {
|
|
|
|
NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
mActorChild->Send__delete__(mActorChild);
|
|
|
|
NS_ASSERTION(!mActorChild, "Should have cleared in Send__delete__!");
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:42 -07:00
|
|
|
if (mRegistered) {
|
2011-11-07 16:15:45 -08:00
|
|
|
CloseInternal(true);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
if (quotaManager) {
|
|
|
|
quotaManager->UnregisterStorage(this);
|
2010-10-19 10:58:42 -07:00
|
|
|
}
|
2013-07-09 10:30:58 -07:00
|
|
|
mRegistered = false;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
2010-09-09 15:15:40 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2010-09-10 12:12:11 -07:00
|
|
|
IDBDatabase::Invalidate()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-10-19 10:58:39 -07:00
|
|
|
|
2012-06-19 18:50:39 -07:00
|
|
|
if (IsInvalidated()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-05 12:09:33 -07:00
|
|
|
mInvalidated = true;
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
// Make sure we're closed too.
|
|
|
|
Close();
|
|
|
|
|
2011-12-03 09:10:21 -08:00
|
|
|
// When the IndexedDatabaseManager needs to invalidate databases, all it has
|
2012-12-19 09:45:57 -08:00
|
|
|
// is an origin, so we call into the quota manager here to cancel any prompts
|
|
|
|
// for our owner.
|
2012-05-16 15:08:18 -07:00
|
|
|
nsPIDOMWindow* owner = GetOwner();
|
|
|
|
if (owner) {
|
2012-12-19 09:45:57 -08:00
|
|
|
QuotaManager::CancelPromptsForWindow(owner);
|
2012-05-16 15:08:18 -07:00
|
|
|
}
|
2010-09-10 12:12:11 -07:00
|
|
|
|
2012-10-23 09:31:19 -07:00
|
|
|
DatabaseInfo::Remove(mDatabaseId);
|
|
|
|
|
|
|
|
// And let the child process know as well.
|
|
|
|
if (mActorParent) {
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
2012-11-09 19:29:07 -08:00
|
|
|
mActorParent->Invalidate();
|
2012-10-23 09:31:19 -07:00
|
|
|
}
|
2012-10-05 12:09:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-09 19:29:07 -08:00
|
|
|
IDBDatabase::DisconnectFromActorParent()
|
2012-10-05 12:09:33 -07:00
|
|
|
{
|
2012-11-09 19:29:07 -08:00
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
2012-10-05 12:09:33 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
// Make sure we're closed too.
|
|
|
|
Close();
|
|
|
|
|
|
|
|
// Kill any outstanding prompts.
|
|
|
|
nsPIDOMWindow* owner = GetOwner();
|
|
|
|
if (owner) {
|
2012-12-19 09:45:57 -08:00
|
|
|
QuotaManager::CancelPromptsForWindow(owner);
|
2012-10-05 12:09:33 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
void
|
2011-11-07 16:15:45 -08:00
|
|
|
IDBDatabase::CloseInternal(bool aIsDead)
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
if (!mClosed) {
|
2012-08-09 18:06:21 -07:00
|
|
|
mClosed = true;
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
// If we're getting called from Unlink, avoid cloning the DatabaseInfo.
|
|
|
|
{
|
|
|
|
nsRefPtr<DatabaseInfo> previousInfo;
|
|
|
|
mDatabaseInfo.swap(previousInfo);
|
|
|
|
|
|
|
|
if (!aIsDead) {
|
|
|
|
nsRefPtr<DatabaseInfo> clonedInfo = previousInfo->Clone();
|
|
|
|
|
|
|
|
clonedInfo.swap(mDatabaseInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
if (quotaManager) {
|
|
|
|
quotaManager->OnStorageClosed(this);
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
// And let the parent process know as well.
|
2012-10-23 09:31:19 -07:00
|
|
|
if (mActorChild && !IsInvalidated()) {
|
2012-06-01 10:21:12 -07:00
|
|
|
NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
mActorChild->SendClose(aIsDead);
|
|
|
|
}
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
IDBDatabase::IsClosed()
|
2010-10-19 10:58:52 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
return mClosed;
|
|
|
|
}
|
|
|
|
|
2011-10-25 05:49:31 -07:00
|
|
|
void
|
|
|
|
IDBDatabase::EnterSetVersionTransaction()
|
|
|
|
{
|
2011-11-07 16:15:45 -08:00
|
|
|
NS_ASSERTION(!mRunningVersionChange, "How did that happen?");
|
2012-06-29 09:48:34 -07:00
|
|
|
|
|
|
|
mPreviousDatabaseInfo = mDatabaseInfo->Clone();
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
mRunningVersionChange = true;
|
2011-10-25 05:49:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IDBDatabase::ExitSetVersionTransaction()
|
|
|
|
{
|
2011-11-07 16:15:45 -08:00
|
|
|
NS_ASSERTION(mRunningVersionChange, "How did that happen?");
|
2012-06-29 09:48:34 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
mPreviousDatabaseInfo = nullptr;
|
2012-06-29 09:48:34 -07:00
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
mRunningVersionChange = false;
|
2011-10-25 05:49:31 -07:00
|
|
|
}
|
|
|
|
|
2012-06-29 09:48:34 -07:00
|
|
|
void
|
|
|
|
IDBDatabase::RevertToPreviousState()
|
|
|
|
{
|
|
|
|
mDatabaseInfo = mPreviousDatabaseInfo;
|
2012-07-30 07:20:58 -07:00
|
|
|
mPreviousDatabaseInfo = nullptr;
|
2012-06-29 09:48:34 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
void
|
|
|
|
IDBDatabase::OnUnlink()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
// We've been unlinked, at the very least we should be able to prevent further
|
|
|
|
// transactions from starting and unblock any other SetVersion callers.
|
2011-11-07 16:15:45 -08:00
|
|
|
CloseInternal(true);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
// No reason for the QuotaManager to track us any longer.
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
if (quotaManager) {
|
|
|
|
quotaManager->UnregisterStorage(this);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
// Don't try to unregister again in the destructor.
|
|
|
|
mRegistered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
already_AddRefed<IDBObjectStore>
|
2012-06-01 10:21:12 -07:00
|
|
|
IDBDatabase::CreateObjectStoreInternal(IDBTransaction* aTransaction,
|
|
|
|
const ObjectStoreInfoGuts& aInfo,
|
2013-07-31 08:48:46 -07:00
|
|
|
ErrorResult& aRv)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(aTransaction, "Null transaction!");
|
|
|
|
|
|
|
|
DatabaseInfo* databaseInfo = aTransaction->DBInfo();
|
|
|
|
|
|
|
|
nsRefPtr<ObjectStoreInfo> newInfo = new ObjectStoreInfo();
|
|
|
|
*static_cast<ObjectStoreInfoGuts*>(newInfo.get()) = aInfo;
|
|
|
|
|
|
|
|
newInfo->nextAutoIncrementId = aInfo.autoIncrement ? 1 : 0;
|
|
|
|
newInfo->comittedAutoIncrementId = newInfo->nextAutoIncrementId;
|
|
|
|
|
|
|
|
if (!databaseInfo->PutObjectStore(newInfo)) {
|
|
|
|
NS_WARNING("Put failed!");
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't leave this in the hash if we fail below!
|
|
|
|
AutoRemoveObjectStore autoRemove(databaseInfo, newInfo->name);
|
|
|
|
|
|
|
|
nsRefPtr<IDBObjectStore> objectStore =
|
|
|
|
aTransaction->GetOrCreateObjectStore(newInfo->name, newInfo, true);
|
2013-07-31 08:48:46 -07:00
|
|
|
if (!objectStore) {
|
|
|
|
NS_WARNING("Failed to get objectStore!");
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
if (IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
nsRefPtr<CreateObjectStoreHelper> helper =
|
|
|
|
new CreateObjectStoreHelper(aTransaction, objectStore);
|
|
|
|
|
|
|
|
nsresult rv = helper->DispatchToTransactionPool();
|
2013-07-31 08:48:46 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to dispatch!");
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
autoRemove.forget();
|
2013-03-15 23:58:50 -07:00
|
|
|
|
|
|
|
IDB_PROFILER_MARK("IndexedDB Pseudo-request: "
|
|
|
|
"database(%s).transaction(%s).createObjectStore(%s)",
|
|
|
|
"MT IDBDatabase.createObjectStore()",
|
|
|
|
IDB_PROFILER_STRING(this),
|
|
|
|
IDB_PROFILER_STRING(aTransaction),
|
|
|
|
IDB_PROFILER_STRING(objectStore));
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
return objectStore.forget();
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFactory)
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
|
2012-08-29 17:50:28 -07:00
|
|
|
// Don't unlink mFactory!
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
// Do some cleanup.
|
|
|
|
tmp->OnUnlink();
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBDatabase)
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFileStorage)
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIOfflineStorage)
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
|
2010-09-09 15:15:38 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBDatabase, IDBWrapperCache)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBDatabase, IDBWrapperCache)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
JSObject*
|
|
|
|
IDBDatabase::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-07-31 08:48:46 -07:00
|
|
|
return IDBDatabaseBinding::Wrap(aCx, aScope, this);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
uint64_t
|
|
|
|
IDBDatabase::Version() const
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2011-11-07 16:06:13 -08:00
|
|
|
DatabaseInfo* info = Info();
|
2013-07-31 08:48:46 -07:00
|
|
|
return info->version;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
already_AddRefed<nsIDOMDOMStringList>
|
|
|
|
IDBDatabase::GetObjectStoreNames(ErrorResult& aRv) const
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-11-07 16:06:13 -08:00
|
|
|
DatabaseInfo* info = Info();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
nsAutoTArray<nsString, 10> objectStoreNames;
|
|
|
|
if (!info->GetObjectStoreNames(objectStoreNames)) {
|
|
|
|
NS_WARNING("Couldn't get names!");
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsDOMStringList> list(new nsDOMStringList());
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = objectStoreNames.Length();
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
2013-07-31 08:48:46 -07:00
|
|
|
if (!list->Add(objectStoreNames[index])) {
|
|
|
|
NS_WARNING("Failed to add element");
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
return list.forget();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
already_AddRefed<IDBObjectStore>
|
|
|
|
IDBDatabase::CreateObjectStore(
|
|
|
|
JSContext* aCx, const nsAString& aName,
|
|
|
|
const IDBObjectStoreParameters& aOptionalParameters,
|
|
|
|
ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction();
|
|
|
|
|
|
|
|
if (!transaction ||
|
2012-03-12 21:44:45 -07:00
|
|
|
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-11-10 15:25:44 -08:00
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
DatabaseInfo* databaseInfo = transaction->DBInfo();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-05-17 18:48:25 -07:00
|
|
|
KeyPath keyPath(0);
|
2013-07-31 08:48:46 -07:00
|
|
|
if (NS_FAILED(KeyPath::Parse(aCx, aOptionalParameters.mKeyPath, &keyPath))) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return nullptr;
|
2010-12-21 08:02:01 -08:00
|
|
|
}
|
|
|
|
|
2011-12-04 09:39:01 -08:00
|
|
|
if (databaseInfo->ContainsStoreName(aName)) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR);
|
|
|
|
return nullptr;
|
2011-12-04 09:39:01 -08:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
if (!keyPath.IsAllowedForObjectStore(aOptionalParameters.mAutoIncrement)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
2011-11-21 06:56:24 -08:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
ObjectStoreInfoGuts guts;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
guts.name = aName;
|
|
|
|
guts.id = databaseInfo->nextObjectStoreId++;
|
|
|
|
guts.keyPath = keyPath;
|
2013-07-31 08:48:46 -07:00
|
|
|
guts.autoIncrement = aOptionalParameters.mAutoIncrement;
|
2010-10-19 10:58:52 -07:00
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
return CreateObjectStoreInternal(transaction, guts, aRv);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
void
|
|
|
|
IDBDatabase::DeleteObjectStore(const nsAString& aName, ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
if (!transaction ||
|
2012-03-12 21:44:45 -07:00
|
|
|
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return;
|
2010-11-10 15:25:44 -08:00
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
DatabaseInfo* info = transaction->DBInfo();
|
|
|
|
ObjectStoreInfo* objectStoreInfo = info->GetObjectStore(aName);
|
|
|
|
if (!objectStoreInfo) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR);
|
|
|
|
return;
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
if (IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
nsRefPtr<DeleteObjectStoreHelper> helper =
|
|
|
|
new DeleteObjectStoreHelper(transaction, objectStoreInfo->id);
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
nsresult rv = helper->DispatchToTransactionPool();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to dispatch!");
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
IndexedDBTransactionChild* actor = transaction->GetActorChild();
|
|
|
|
NS_ASSERTION(actor, "Must have an actor here!");
|
|
|
|
|
|
|
|
actor->SendDeleteObjectStore(nsString(aName));
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
transaction->RemoveObjectStore(aName);
|
2011-12-04 09:39:01 -08:00
|
|
|
|
2013-03-15 23:58:50 -07:00
|
|
|
IDB_PROFILER_MARK("IndexedDB Pseudo-request: "
|
|
|
|
"database(%s).transaction(%s).deleteObjectStore(\"%s\")",
|
|
|
|
"MT IDBDatabase.deleteObjectStore()",
|
|
|
|
IDB_PROFILER_STRING(this),
|
|
|
|
IDB_PROFILER_STRING(transaction),
|
|
|
|
NS_ConvertUTF16toUTF8(aName).get());
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
already_AddRefed<indexedDB::IDBTransaction>
|
|
|
|
IDBDatabase::Transaction(const Sequence<nsString>& aStoreNames,
|
|
|
|
IDBTransactionMode aMode, ErrorResult& aRv)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
if (QuotaManager::IsShuttingDown()) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
2010-10-19 10:58:42 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
if (mClosed) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
if (mRunningVersionChange) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
if (aStoreNames.IsEmpty()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
2011-11-03 08:57:30 -07:00
|
|
|
}
|
2011-11-02 18:03:15 -07:00
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
IDBTransaction::Mode transactionMode = IDBTransaction::READ_ONLY;
|
|
|
|
switch (aMode) {
|
|
|
|
case IDBTransactionMode::Readonly:
|
|
|
|
transactionMode = IDBTransaction::READ_ONLY;
|
|
|
|
break;
|
|
|
|
case IDBTransactionMode::Readwrite:
|
|
|
|
transactionMode = IDBTransaction::READ_WRITE;
|
|
|
|
break;
|
|
|
|
case IDBTransactionMode::Versionchange:
|
|
|
|
transactionMode = IDBTransaction::VERSION_CHANGE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown mode!");
|
2011-11-03 08:57:30 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now check to make sure the object store names we collected actually exist.
|
2011-11-07 16:15:45 -08:00
|
|
|
DatabaseInfo* info = Info();
|
2013-07-31 08:48:46 -07:00
|
|
|
for (uint32_t index = 0; index < aStoreNames.Length(); index++) {
|
|
|
|
if (!info->ContainsStoreName(aStoreNames[index])) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR);
|
|
|
|
return nullptr;
|
2011-11-03 08:57:30 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 09:46:21 -07:00
|
|
|
nsRefPtr<IDBTransaction> transaction =
|
2013-07-31 08:48:46 -07:00
|
|
|
IDBTransaction::Create(this, aStoreNames, transactionMode, false);
|
|
|
|
if (!transaction) {
|
|
|
|
NS_WARNING("Failed to create the transaction!");
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2013-03-15 23:58:50 -07:00
|
|
|
IDB_PROFILER_MARK("IndexedDB Transaction %llu: database(%s).transaction(%s)",
|
|
|
|
"IDBTransaction[%llu] MT Started",
|
|
|
|
transaction->GetSerialNumber(), IDB_PROFILER_STRING(this),
|
|
|
|
IDB_PROFILER_STRING(transaction));
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
return transaction.forget();
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
already_AddRefed<IDBRequest>
|
2012-06-03 09:33:52 -07:00
|
|
|
IDBDatabase::MozCreateFileHandle(const nsAString& aName,
|
2013-07-31 08:48:46 -07:00
|
|
|
const Optional<nsAString>& aType,
|
|
|
|
ErrorResult& aRv)
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-11-08 13:41:23 -08:00
|
|
|
if (!IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
NS_WARNING("Not supported yet!");
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
2012-11-08 13:41:23 -08:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
if (QuotaManager::IsShuttingDown()) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mClosed) {
|
2013-07-31 08:48:46 -07:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
2013-06-20 11:05:33 -07:00
|
|
|
nsRefPtr<IDBRequest> request = IDBRequest::Create(nullptr, this, nullptr);
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
nsRefPtr<CreateFileHelper> helper =
|
2013-07-31 08:48:46 -07:00
|
|
|
new CreateFileHelper(this, request, aName,
|
|
|
|
aType.WasPassed() ? aType.Value() : EmptyString());
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "We should definitely have a manager here");
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
nsresult rv = helper->Dispatch(quotaManager->IOThread());
|
2013-07-31 08:48:46 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("Failed to dispatch!");
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2012-06-03 09:33:52 -07:00
|
|
|
|
2013-07-31 08:48:46 -07:00
|
|
|
return request.forget();
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBDatabase::Close()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
CloseInternal(false);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
NS_ASSERTION(mClosed, "Should have set the closed flag!");
|
2013-07-31 08:48:46 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_IMETHODIMP_(nsIAtom*)
|
|
|
|
IDBDatabase::Id()
|
2012-12-17 11:25:10 -08:00
|
|
|
{
|
2013-03-26 04:13:17 -07:00
|
|
|
return mDatabaseId;
|
2012-12-17 11:25:10 -08:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
IDBDatabase::IsInvalidated()
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
2013-03-26 04:13:17 -07:00
|
|
|
return mInvalidated;
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
IDBDatabase::IsShuttingDown()
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
2013-03-26 04:13:17 -07:00
|
|
|
return QuotaManager::IsShuttingDown();
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2012-06-03 09:33:52 -07:00
|
|
|
IDBDatabase::SetThreadLocals()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(GetOwner(), "Should have owner!");
|
2012-12-19 09:45:57 -08:00
|
|
|
QuotaManager::SetCurrentWindow(GetOwner());
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_IMETHODIMP_(void)
|
2012-06-03 09:33:52 -07:00
|
|
|
IDBDatabase::UnsetThreadLocals()
|
|
|
|
{
|
2012-12-19 09:45:57 -08:00
|
|
|
QuotaManager::SetCurrentWindow(nullptr);
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
2013-03-26 04:13:17 -07:00
|
|
|
NS_IMETHODIMP_(mozilla::dom::quota::Client*)
|
|
|
|
IDBDatabase::GetClient()
|
|
|
|
{
|
|
|
|
return mQuotaClient;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
IDBDatabase::IsOwned(nsPIDOMWindow* aOwner)
|
|
|
|
{
|
|
|
|
return GetOwner() == aOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(const nsACString&)
|
|
|
|
IDBDatabase::Origin()
|
|
|
|
{
|
|
|
|
return mASCIIOrigin;
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:26:03 -08:00
|
|
|
nsresult
|
|
|
|
IDBDatabase::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|
|
|
{
|
2012-06-29 09:48:34 -07:00
|
|
|
return IndexedDatabaseManager::FireWindowOnError(GetOwner(), aVisitor);
|
2010-11-10 15:26:03 -08:00
|
|
|
}
|
|
|
|
|
2012-10-05 12:09:33 -07:00
|
|
|
AsyncConnectionHelper::ChildProcessSendResult
|
|
|
|
NoRequestDatabaseHelper::SendResponseToChildProcess(nsresult aResultCode)
|
2012-06-01 10:21:12 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
return Success_NotSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NoRequestDatabaseHelper::UnpackResponseFromParentProcess(
|
|
|
|
const ResponseValue& aResponseValue)
|
|
|
|
{
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Should never get here!");
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NoRequestDatabaseHelper::OnSuccess()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NoRequestDatabaseHelper::OnError()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
2012-06-29 09:48:34 -07:00
|
|
|
mTransaction->Abort(GetResultCode());
|
2012-06-01 10:21:12 -07:00
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2010-06-23 12:46:08 -07:00
|
|
|
CreateObjectStoreHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
{
|
2013-03-15 23:58:50 -07:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
|
|
|
PROFILER_LABEL("IndexedDB", "CreateObjectStoreHelper::DoDatabaseWork");
|
|
|
|
|
2013-05-10 14:22:01 -07:00
|
|
|
if (IndexedDatabaseManager::InLowDiskSpaceMode()) {
|
|
|
|
NS_WARNING("Refusing to create additional objectStore because disk space "
|
|
|
|
"is low!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt =
|
|
|
|
mTransaction->GetCachedStatement(NS_LITERAL_CSTRING(
|
2011-12-04 09:39:01 -08:00
|
|
|
"INSERT INTO object_store (id, auto_increment, name, key_path) "
|
|
|
|
"VALUES (:id, :auto_increment, :name, :key_path)"
|
2010-10-19 10:58:52 -07:00
|
|
|
));
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("id"),
|
|
|
|
mObjectStore->Id());
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-04 09:39:01 -08:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("auto_increment"),
|
|
|
|
mObjectStore->IsAutoIncrement() ? 1 : 0);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-04 09:39:01 -08:00
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("name"), mObjectStore->Name());
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-21 15:27:13 -07:00
|
|
|
const KeyPath& keyPath = mObjectStore->GetKeyPath();
|
|
|
|
if (keyPath.IsValid()) {
|
|
|
|
nsAutoString keyPathSerialization;
|
|
|
|
keyPath.SerializeToString(keyPathSerialization);
|
2011-12-20 02:59:07 -08:00
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("key_path"),
|
2012-06-21 15:27:13 -07:00
|
|
|
keyPathSerialization);
|
2011-12-20 02:59:07 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = stmt->BindNullByName(NS_LITERAL_CSTRING("key_path"));
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
rv = stmt->Execute();
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
void
|
|
|
|
CreateObjectStoreHelper::ReleaseMainThreadObjects()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mObjectStore = nullptr;
|
2012-06-01 10:21:12 -07:00
|
|
|
NoRequestDatabaseHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
nsresult
|
2010-11-10 15:25:57 -08:00
|
|
|
DeleteObjectStoreHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
2013-03-15 23:58:50 -07:00
|
|
|
NS_ASSERTION(!NS_IsMainThread(), "Wrong thread!");
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
|
|
|
PROFILER_LABEL("IndexedDB", "DeleteObjectStoreHelper::DoDatabaseWork");
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt =
|
|
|
|
mTransaction->GetCachedStatement(NS_LITERAL_CSTRING(
|
2010-06-23 12:46:08 -07:00
|
|
|
"DELETE FROM object_store "
|
2010-10-19 10:58:52 -07:00
|
|
|
"WHERE id = :id "
|
|
|
|
));
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("id"), mObjectStoreId);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
rv = stmt->Execute();
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_OK;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateFileHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
{
|
2013-06-05 01:11:23 -07:00
|
|
|
AssertIsOnIOThread();
|
2013-03-15 23:58:50 -07:00
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
|
|
|
|
PROFILER_LABEL("IndexedDB", "CreateFileHelper::DoDatabaseWork");
|
|
|
|
|
2013-05-10 14:22:01 -07:00
|
|
|
if (IndexedDatabaseManager::InLowDiskSpaceMode()) {
|
|
|
|
NS_WARNING("Refusing to create file because disk space is low!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_QUOTA_ERR;
|
|
|
|
}
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
FileManager* fileManager = mDatabase->Manager();
|
|
|
|
|
|
|
|
mFileInfo = fileManager->GetNewFileInfo();
|
|
|
|
NS_ENSURE_TRUE(mFileInfo, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
const int64_t& fileId = mFileInfo->Id();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> directory = fileManager->EnsureJournalDirectory();
|
|
|
|
NS_ENSURE_TRUE(directory, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> file = fileManager->GetFileForId(directory, fileId);
|
|
|
|
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsresult rv = file->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
directory = fileManager->GetDirectory();
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_ENSURE_TRUE(directory, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
file = fileManager->GetFileForId(directory, fileId);
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_ENSURE_TRUE(file, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2012-08-24 11:51:33 -07:00
|
|
|
rv = file->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateFileHelper::GetSuccessResult(JSContext* aCx,
|
2013-06-21 06:12:46 -07:00
|
|
|
JS::MutableHandle<JS::Value> aVal)
|
2012-06-03 09:33:52 -07:00
|
|
|
{
|
|
|
|
nsRefPtr<IDBFileHandle> fileHandle =
|
|
|
|
IDBFileHandle::Create(mDatabase, mName, mType, mFileInfo.forget());
|
|
|
|
NS_ENSURE_TRUE(fileHandle, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
return WrapNative(aCx, NS_ISUPPORTS_CAST(nsIDOMFileHandle*, fileHandle),
|
|
|
|
aVal);
|
|
|
|
}
|