2010-06-23 23:46:08 +04: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 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
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
#include "IDBDatabase.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-09-10 02:15:40 +04:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "mozilla/storage.h"
|
2012-08-02 10:02:29 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2013-03-26 15:13:17 +04:00
|
|
|
#include "mozilla/dom/quota/Client.h"
|
2012-12-19 21:45:57 +04:00
|
|
|
#include "mozilla/dom/quota/QuotaManager.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "nsDOMClassInfo.h"
|
2011-12-16 11:34:24 +04:00
|
|
|
#include "nsDOMLists.h"
|
2010-12-21 19:02:01 +03:00
|
|
|
#include "nsJSUtils.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "nsProxyRelease.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
|
|
|
|
#include "AsyncConnectionHelper.h"
|
|
|
|
#include "DatabaseInfo.h"
|
|
|
|
#include "IDBEvents.h"
|
2012-08-30 04:50:28 +04:00
|
|
|
#include "IDBFactory.h"
|
2012-06-03 20:33:52 +04:00
|
|
|
#include "IDBFileHandle.h"
|
2010-10-19 21:58:52 +04:00
|
|
|
#include "IDBIndex.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBObjectStore.h"
|
2010-06-28 20:46:21 +04:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-28 20:44:30 +04:00
|
|
|
#include "IDBFactory.h"
|
2010-09-10 23:12:11 +04:00
|
|
|
#include "TransactionThreadPool.h"
|
2011-12-27 22:01:28 +04:00
|
|
|
#include "DictionaryHelpers.h"
|
2012-07-02 03:45:59 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
#include "ipc/IndexedDBChild.h"
|
2012-10-23 20:31:19 +04:00
|
|
|
#include "ipc/IndexedDBParent.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
USING_INDEXEDDB_NAMESPACE
|
2012-08-02 10:02:29 +04:00
|
|
|
using mozilla::dom::ContentParent;
|
2013-03-26 15:13:17 +04:00
|
|
|
using mozilla::dom::quota::Client;
|
2012-12-19 21:45:57 +04:00
|
|
|
using mozilla::dom::quota::QuotaManager;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
class NoRequestDatabaseHelper : public AsyncConnectionHelper
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NoRequestDatabaseHelper(IDBTransaction* aTransaction)
|
2012-07-30 18:20:58 +04:00
|
|
|
: AsyncConnectionHelper(aTransaction, nullptr)
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
NS_ASSERTION(aTransaction, "Null transaction!");
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ChildProcessSendResult
|
2012-10-05 23:09:33 +04:00
|
|
|
SendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE;
|
2012-06-01 21:21:12 +04: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 23:46:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2010-06-28 20:46:21 +04:00
|
|
|
CreateObjectStoreHelper(IDBTransaction* aTransaction,
|
2010-10-19 21:58:52 +04:00
|
|
|
IDBObjectStore* aObjectStore)
|
2012-06-01 21:21:12 +04:00
|
|
|
: NoRequestDatabaseHelper(aTransaction), mObjectStore(aObjectStore)
|
2010-06-23 23:46:08 +04:00
|
|
|
{ }
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
virtual nsresult DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
MOZ_OVERRIDE;
|
2011-01-07 09:21:36 +03:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
virtual void ReleaseMainThreadObjects() MOZ_OVERRIDE;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
private:
|
|
|
|
nsRefPtr<IDBObjectStore> mObjectStore;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
class DeleteObjectStoreHelper : public NoRequestDatabaseHelper
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2010-11-11 02:25:57 +03:00
|
|
|
DeleteObjectStoreHelper(IDBTransaction* aTransaction,
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t aObjectStoreId)
|
2012-06-01 21:21:12 +04:00
|
|
|
: NoRequestDatabaseHelper(aTransaction), mObjectStoreId(aObjectStoreId)
|
2010-06-23 23:46:08 +04:00
|
|
|
{ }
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
virtual nsresult DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
MOZ_OVERRIDE;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// In-params.
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mObjectStoreId;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
2012-06-03 20:33:52 +04: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,
|
|
|
|
jsval* aVal);
|
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mFileInfo = nullptr;
|
2012-06-03 20:33:52 +04:00
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2012-10-05 23:09:33 +04:00
|
|
|
virtual ChildProcessSendResult SendResponseToChildProcess(
|
2012-06-03 20:33:52 +04:00
|
|
|
nsresult aResultCode)
|
|
|
|
MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return Success_NotSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual nsresult UnpackResponseFromParentProcess(
|
|
|
|
const ResponseValue& aResponseValue)
|
|
|
|
MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
MOZ_NOT_REACHED("Should never get here!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// In-params.
|
|
|
|
nsString mName;
|
|
|
|
nsString mType;
|
|
|
|
|
|
|
|
// Out-params.
|
|
|
|
nsRefPtr<FileInfo> mFileInfo;
|
|
|
|
};
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
NS_STACK_CLASS
|
|
|
|
class AutoRemoveObjectStore
|
|
|
|
{
|
|
|
|
public:
|
2011-12-17 04:40:47 +04:00
|
|
|
AutoRemoveObjectStore(DatabaseInfo* aInfo, const nsAString& aName)
|
|
|
|
: mInfo(aInfo), mName(aName)
|
2010-10-19 21:58:52 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
~AutoRemoveObjectStore()
|
|
|
|
{
|
2011-12-17 04:40:47 +04:00
|
|
|
if (mInfo) {
|
|
|
|
mInfo->RemoveObjectStore(mName);
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void forget()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mInfo = nullptr;
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-12-17 04:40:47 +04:00
|
|
|
DatabaseInfo* mInfo;
|
2010-10-19 21:58:52 +04:00
|
|
|
nsString mName;
|
|
|
|
};
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
// static
|
2010-06-28 20:46:49 +04:00
|
|
|
already_AddRefed<IDBDatabase>
|
2012-01-24 14:03:37 +04:00
|
|
|
IDBDatabase::Create(IDBWrapperCache* aOwnerCache,
|
2012-08-30 04:50:28 +04:00
|
|
|
IDBFactory* aFactory,
|
2011-11-08 04:15:45 +04:00
|
|
|
already_AddRefed<DatabaseInfo> aDatabaseInfo,
|
2011-12-16 11:34:24 +04:00
|
|
|
const nsACString& aASCIIOrigin,
|
2012-08-02 10:02:29 +04:00
|
|
|
FileManager* aFileManager,
|
|
|
|
mozilla::dom::ContentParent* aContentParent)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2012-08-30 04:50:28 +04:00
|
|
|
NS_ASSERTION(aFactory, "Null pointer!");
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_ASSERTION(!aASCIIOrigin.IsEmpty(), "Empty origin!");
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
nsRefPtr<DatabaseInfo> databaseInfo(aDatabaseInfo);
|
|
|
|
NS_ASSERTION(databaseInfo, "Null pointer!");
|
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
nsRefPtr<IDBDatabase> db(new IDBDatabase());
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-03-13 04:56:07 +04:00
|
|
|
db->BindToOwner(aOwnerCache);
|
2012-11-30 02:54:14 +04:00
|
|
|
db->SetScriptOwner(aOwnerCache->GetScriptOwner());
|
2012-08-30 04:50:28 +04:00
|
|
|
db->mFactory = aFactory;
|
2011-11-08 04:15:45 +04:00
|
|
|
db->mDatabaseId = databaseInfo->id;
|
|
|
|
db->mName = databaseInfo->name;
|
|
|
|
db->mFilePath = databaseInfo->filePath;
|
|
|
|
databaseInfo.swap(db->mDatabaseInfo);
|
2010-09-10 02:15:38 +04:00
|
|
|
db->mASCIIOrigin = aASCIIOrigin;
|
2011-12-16 11:34:24 +04:00
|
|
|
db->mFileManager = aFileManager;
|
2012-08-02 10:02:29 +04:00
|
|
|
db->mContentParent = aContentParent;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "This should never be null!");
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
db->mQuotaClient = quotaManager->GetClient(Client::IDB);
|
|
|
|
NS_ASSERTION(db->mQuotaClient, "This shouldn't fail!");
|
|
|
|
|
|
|
|
if (!quotaManager->RegisterStorage(db)) {
|
2010-10-19 21:58:42 +04:00
|
|
|
// Either out of memory or shutting down.
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-09-10 23:12:11 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
db->mRegistered = true;
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
return db.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
// static
|
|
|
|
IDBDatabase*
|
|
|
|
IDBDatabase::FromStorage(nsIOfflineStorage* aStorage)
|
|
|
|
{
|
|
|
|
return aStorage->GetClient()->GetType() == Client::IDB ?
|
|
|
|
static_cast<IDBDatabase*>(aStorage) : nullptr;
|
|
|
|
}
|
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
IDBDatabase::IDBDatabase()
|
2010-09-10 23:12:11 +04:00
|
|
|
: mDatabaseId(0),
|
2012-07-30 18:20:58 +04:00
|
|
|
mActorChild(nullptr),
|
|
|
|
mActorParent(nullptr),
|
2012-08-02 10:02:29 +04:00
|
|
|
mContentParent(nullptr),
|
2012-10-05 23:09:33 +04:00
|
|
|
mInvalidated(false),
|
2010-10-19 21:58:52 +04:00
|
|
|
mRegistered(false),
|
2011-11-08 04:15:45 +04:00
|
|
|
mClosed(false),
|
|
|
|
mRunningVersionChange(false)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2010-09-10 23:12:11 +04:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
IDBDatabase::~IDBDatabase()
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2010-09-10 23:12:11 +04:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-06-01 21:21:12 +04: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 21:58:42 +04:00
|
|
|
if (mRegistered) {
|
2011-11-08 04:15:45 +04:00
|
|
|
CloseInternal(true);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
if (quotaManager) {
|
|
|
|
quotaManager->UnregisterStorage(this);
|
2010-10-19 21:58:42 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
2010-09-10 02:15:40 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2010-09-10 23:12:11 +04:00
|
|
|
IDBDatabase::Invalidate()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-10-19 21:58:39 +04:00
|
|
|
|
2012-06-20 05:50:39 +04:00
|
|
|
if (IsInvalidated()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-05 23:09:33 +04:00
|
|
|
mInvalidated = true;
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
// Make sure we're closed too.
|
|
|
|
Close();
|
|
|
|
|
2011-12-03 21:10:21 +04:00
|
|
|
// When the IndexedDatabaseManager needs to invalidate databases, all it has
|
2012-12-19 21:45:57 +04:00
|
|
|
// is an origin, so we call into the quota manager here to cancel any prompts
|
|
|
|
// for our owner.
|
2012-05-17 02:08:18 +04:00
|
|
|
nsPIDOMWindow* owner = GetOwner();
|
|
|
|
if (owner) {
|
2012-12-19 21:45:57 +04:00
|
|
|
QuotaManager::CancelPromptsForWindow(owner);
|
2012-05-17 02:08:18 +04:00
|
|
|
}
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2012-10-23 20:31:19 +04:00
|
|
|
DatabaseInfo::Remove(mDatabaseId);
|
|
|
|
|
|
|
|
// And let the child process know as well.
|
|
|
|
if (mActorParent) {
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
2012-11-10 07:29:07 +04:00
|
|
|
mActorParent->Invalidate();
|
2012-10-23 20:31:19 +04:00
|
|
|
}
|
2012-10-05 23:09:33 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-10 07:29:07 +04:00
|
|
|
IDBDatabase::DisconnectFromActorParent()
|
2012-10-05 23:09:33 +04:00
|
|
|
{
|
2012-11-10 07:29:07 +04:00
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
2012-10-05 23:09:33 +04: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 21:45:57 +04:00
|
|
|
QuotaManager::CancelPromptsForWindow(owner);
|
2012-10-05 23:09:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
void
|
2011-11-08 04:15:45 +04:00
|
|
|
IDBDatabase::CloseInternal(bool aIsDead)
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
if (!mClosed) {
|
2012-08-10 05:06:21 +04:00
|
|
|
mClosed = true;
|
|
|
|
|
2011-11-08 04:15:45 +04: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 15:13:17 +04:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
if (quotaManager) {
|
|
|
|
quotaManager->OnStorageClosed(this);
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
|
|
|
// And let the parent process know as well.
|
2012-10-23 20:31:19 +04:00
|
|
|
if (mActorChild && !IsInvalidated()) {
|
2012-06-01 21:21:12 +04:00
|
|
|
NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
mActorChild->SendClose(aIsDead);
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
IDBDatabase::IsClosed()
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
return mClosed;
|
|
|
|
}
|
|
|
|
|
2011-10-25 16:49:31 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::EnterSetVersionTransaction()
|
|
|
|
{
|
2011-11-08 04:15:45 +04:00
|
|
|
NS_ASSERTION(!mRunningVersionChange, "How did that happen?");
|
2012-06-29 20:48:34 +04:00
|
|
|
|
|
|
|
mPreviousDatabaseInfo = mDatabaseInfo->Clone();
|
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
mRunningVersionChange = true;
|
2011-10-25 16:49:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IDBDatabase::ExitSetVersionTransaction()
|
|
|
|
{
|
2011-11-08 04:15:45 +04:00
|
|
|
NS_ASSERTION(mRunningVersionChange, "How did that happen?");
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mPreviousDatabaseInfo = nullptr;
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
mRunningVersionChange = false;
|
2011-10-25 16:49:31 +04:00
|
|
|
}
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::RevertToPreviousState()
|
|
|
|
{
|
|
|
|
mDatabaseInfo = mPreviousDatabaseInfo;
|
2012-07-30 18:20:58 +04:00
|
|
|
mPreviousDatabaseInfo = nullptr;
|
2012-06-29 20:48:34 +04:00
|
|
|
}
|
|
|
|
|
2010-10-19 21:58:52 +04: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-08 04:15:45 +04:00
|
|
|
CloseInternal(true);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
// No reason for the QuotaManager to track us any longer.
|
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
if (quotaManager) {
|
|
|
|
quotaManager->UnregisterStorage(this);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
|
|
|
// Don't try to unregister again in the destructor.
|
|
|
|
mRegistered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
nsresult
|
|
|
|
IDBDatabase::CreateObjectStoreInternal(IDBTransaction* aTransaction,
|
|
|
|
const ObjectStoreInfoGuts& aInfo,
|
|
|
|
IDBObjectStore** _retval)
|
|
|
|
{
|
|
|
|
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!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
NS_ENSURE_TRUE(objectStore, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
if (IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
nsRefPtr<CreateObjectStoreHelper> helper =
|
|
|
|
new CreateObjectStoreHelper(aTransaction, objectStore);
|
|
|
|
|
|
|
|
nsresult rv = helper->DispatchToTransactionPool();
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
autoRemove.forget();
|
|
|
|
objectStore.forget(_retval);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFactory)
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
|
2012-08-30 04:50:28 +04:00
|
|
|
// Don't unlink mFactory!
|
2010-10-19 21:58:52 +04:00
|
|
|
|
|
|
|
// Do some cleanup.
|
|
|
|
tmp->OnUnlink();
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBDatabase)
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIIDBDatabase)
|
2012-06-03 20:33:52 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFileStorage)
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIOfflineStorage)
|
2010-06-28 20:46:49 +04:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBDatabase)
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
|
2010-09-10 02:15:38 +04:00
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBDatabase, IDBWrapperCache)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBDatabase, IDBWrapperCache)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
DOMCI_DATA(IDBDatabase, IDBDatabase)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-01-11 14:14:04 +04:00
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, abort)
|
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, error)
|
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, versionchange)
|
2012-01-24 14:03:37 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
NS_IMETHODIMP
|
2010-06-28 20:46:49 +04:00
|
|
|
IDBDatabase::GetName(nsAString& aName)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
aName.Assign(mName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
IDBDatabase::GetVersion(uint64_t* aVersion)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2011-11-08 04:06:13 +04:00
|
|
|
|
|
|
|
DatabaseInfo* info = Info();
|
2011-10-20 20:10:56 +04:00
|
|
|
*aVersion = info->version;
|
2011-11-08 04:06:13 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-28 20:46:49 +04:00
|
|
|
IDBDatabase::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-11-08 04:06:13 +04:00
|
|
|
DatabaseInfo* info = Info();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
nsAutoTArray<nsString, 10> objectStoreNames;
|
|
|
|
if (!info->GetObjectStoreNames(objectStoreNames)) {
|
|
|
|
NS_WARNING("Couldn't get names!");
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsDOMStringList> list(new nsDOMStringList());
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = objectStoreNames.Length();
|
|
|
|
for (uint32_t index = 0; index < count; index++) {
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_TRUE(list->Add(objectStoreNames[index]),
|
|
|
|
NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
list.forget(aObjectStores);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-28 20:46:49 +04:00
|
|
|
IDBDatabase::CreateObjectStore(const nsAString& aName,
|
2010-12-21 19:02:01 +03:00
|
|
|
const jsval& aOptions,
|
|
|
|
JSContext* aCx,
|
2010-10-19 21:58:52 +04:00
|
|
|
nsIIDBObjectStore** _retval)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-11-11 02:25:44 +03:00
|
|
|
IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction();
|
|
|
|
|
|
|
|
if (!transaction ||
|
2012-03-13 08:44:45 +04:00
|
|
|
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
DatabaseInfo* databaseInfo = transaction->DBInfo();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-02-11 23:37:50 +04:00
|
|
|
mozilla::idl::IDBObjectStoreParameters params;
|
2012-06-22 02:27:13 +04:00
|
|
|
KeyPath keyPath(0);
|
2010-12-21 19:02:01 +03:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2010-12-21 19:02:01 +03:00
|
|
|
if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
|
2012-06-01 21:21:12 +04:00
|
|
|
rv = params.Init(aCx, &aOptions);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2010-12-21 19:02:01 +03:00
|
|
|
|
2012-06-22 02:27:13 +04:00
|
|
|
// We need a default value here, which the XPIDL dictionary stuff doesn't
|
|
|
|
// support. WebIDL shall save us all!
|
|
|
|
JSBool hasProp = false;
|
|
|
|
JSObject* obj = JSVAL_TO_OBJECT(aOptions);
|
|
|
|
if (!JS_HasProperty(aCx, obj, "keyPath", &hasProp)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2012-06-22 02:27:13 +04:00
|
|
|
if (NS_FAILED(KeyPath::Parse(aCx, hasProp ? params.keyPath : JSVAL_NULL,
|
|
|
|
&keyPath))) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2011-11-08 10:25:51 +04:00
|
|
|
}
|
2010-12-21 19:02:01 +03:00
|
|
|
}
|
|
|
|
|
2011-12-04 21:39:01 +04:00
|
|
|
if (databaseInfo->ContainsStoreName(aName)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
|
|
|
|
}
|
|
|
|
|
2012-06-22 02:27:13 +04:00
|
|
|
if (!keyPath.IsAllowedForObjectStore(params.autoIncrement)) {
|
2011-12-20 14:59:07 +04:00
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
2011-11-21 18:56:24 +04:00
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
ObjectStoreInfoGuts guts;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
guts.name = aName;
|
|
|
|
guts.id = databaseInfo->nextObjectStoreId++;
|
|
|
|
guts.keyPath = keyPath;
|
|
|
|
guts.autoIncrement = params.autoIncrement;
|
2010-08-27 00:57:25 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
nsRefPtr<IDBObjectStore> objectStore;
|
|
|
|
rv = CreateObjectStoreInternal(transaction, guts,
|
|
|
|
getter_AddRefs(objectStore));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
|
|
|
objectStore.forget(_retval);
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-11-11 02:25:57 +03:00
|
|
|
IDBDatabase::DeleteObjectStore(const nsAString& aName)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
IDBTransaction* transaction = AsyncConnectionHelper::GetCurrentTransaction();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
if (!transaction ||
|
2012-03-13 08:44:45 +04:00
|
|
|
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
DatabaseInfo* info = transaction->DBInfo();
|
|
|
|
ObjectStoreInfo* objectStoreInfo = info->GetObjectStore(aName);
|
|
|
|
if (!objectStoreInfo) {
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
nsRefPtr<DeleteObjectStoreHelper> helper =
|
|
|
|
new DeleteObjectStoreHelper(transaction, objectStoreInfo->id);
|
|
|
|
|
|
|
|
rv = helper->DispatchToTransactionPool();
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
IndexedDBTransactionChild* actor = transaction->GetActorChild();
|
|
|
|
NS_ASSERTION(actor, "Must have an actor here!");
|
|
|
|
|
|
|
|
actor->SendDeleteObjectStore(nsString(aName));
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
transaction->RemoveObjectStore(aName);
|
2011-12-04 21:39:01 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-11-03 19:57:30 +04:00
|
|
|
IDBDatabase::Transaction(const jsval& aStoreNames,
|
2012-03-13 08:44:45 +04:00
|
|
|
const nsAString& aMode,
|
2010-08-27 00:57:25 +04:00
|
|
|
JSContext* aCx,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aOptionalArgCount,
|
2010-06-28 20:46:49 +04:00
|
|
|
nsIIDBTransaction** _retval)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
if (QuotaManager::IsShuttingDown()) {
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2010-10-19 21:58:42 +04:00
|
|
|
}
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
if (mClosed) {
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
if (mRunningVersionChange) {
|
2011-11-03 19:57:30 +04:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2012-03-13 08:44:45 +04:00
|
|
|
IDBTransaction::Mode transactionMode = IDBTransaction::READ_ONLY;
|
2010-06-23 23:46:08 +04:00
|
|
|
if (aOptionalArgCount) {
|
2012-03-13 08:44:45 +04:00
|
|
|
if (aMode.EqualsLiteral("readwrite")) {
|
|
|
|
transactionMode = IDBTransaction::READ_WRITE;
|
|
|
|
}
|
|
|
|
else if (!aMode.EqualsLiteral("readonly")) {
|
2012-04-12 01:55:21 +04:00
|
|
|
return NS_ERROR_TYPE_ERR;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
nsresult rv;
|
2011-11-03 05:57:48 +04:00
|
|
|
nsTArray<nsString> storesToOpen;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!JSVAL_IS_PRIMITIVE(aStoreNames)) {
|
|
|
|
JSObject* obj = JSVAL_TO_OBJECT(aStoreNames);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
// See if this is a JS array.
|
|
|
|
if (JS_IsArrayObject(aCx, obj)) {
|
2012-03-07 03:52:55 +04:00
|
|
|
uint32_t length;
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!JS_GetArrayLength(aCx, obj, &length)) {
|
2011-11-03 05:57:48 +04:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!length) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
2011-11-03 05:03:15 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
storesToOpen.SetCapacity(length);
|
2011-11-03 05:03:15 +04:00
|
|
|
|
2012-03-07 03:52:55 +04:00
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2011-11-03 19:57:30 +04:00
|
|
|
jsval val;
|
|
|
|
JSString* jsstr;
|
|
|
|
nsDependentJSString str;
|
|
|
|
if (!JS_GetElement(aCx, obj, index, &val) ||
|
|
|
|
!(jsstr = JS_ValueToString(aCx, val)) ||
|
|
|
|
!str.init(aCx, jsstr)) {
|
2011-11-03 05:57:48 +04:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2011-11-03 19:57:30 +04:00
|
|
|
|
|
|
|
storesToOpen.AppendElement(str);
|
2011-11-03 05:57:48 +04:00
|
|
|
}
|
2011-11-03 19:57:30 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(!storesToOpen.IsEmpty(),
|
|
|
|
"Must have something here or else code below will "
|
|
|
|
"misbehave!");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Perhaps some kind of wrapped object?
|
|
|
|
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
|
|
|
NS_ASSERTION(xpc, "This should never be null!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
|
|
|
|
rv = xpc->GetWrappedNativeOfJSObject(aCx, obj, getter_AddRefs(wrapper));
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
if (wrapper) {
|
|
|
|
nsISupports* wrappedObject = wrapper->Native();
|
|
|
|
NS_ENSURE_TRUE(wrappedObject, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
// We only accept DOMStringList.
|
|
|
|
nsCOMPtr<nsIDOMDOMStringList> list = do_QueryInterface(wrappedObject);
|
|
|
|
if (list) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t length;
|
2011-11-03 19:57:30 +04:00
|
|
|
rv = list->GetLength(&length);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!length) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
storesToOpen.SetCapacity(length);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2011-11-03 19:57:30 +04:00
|
|
|
nsString* item = storesToOpen.AppendElement();
|
|
|
|
NS_ASSERTION(item, "This should never fail!");
|
2011-11-03 05:03:15 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
rv = list->Item(index, *item);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!storesToOpen.IsEmpty(),
|
|
|
|
"Must have something here or else code below will "
|
|
|
|
"misbehave!");
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 19:57:30 +04:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 05:03:15 +04:00
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
// If our list is empty here then the argument must have been an object that
|
|
|
|
// we don't support or a primitive. Either way we convert to a string.
|
|
|
|
if (storesToOpen.IsEmpty()) {
|
|
|
|
JSString* jsstr;
|
|
|
|
nsDependentJSString str;
|
|
|
|
if (!(jsstr = JS_ValueToString(aCx, aStoreNames)) ||
|
|
|
|
!str.init(aCx, jsstr)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
storesToOpen.AppendElement(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now check to make sure the object store names we collected actually exist.
|
2011-11-08 04:15:45 +04:00
|
|
|
DatabaseInfo* info = Info();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t index = 0; index < storesToOpen.Length(); index++) {
|
2011-11-03 19:57:30 +04:00
|
|
|
if (!info->ContainsStoreName(storesToOpen[index])) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-06-28 20:46:21 +04:00
|
|
|
nsRefPtr<IDBTransaction> transaction =
|
2012-03-13 08:44:45 +04:00
|
|
|
IDBTransaction::Create(this, storesToOpen, transactionMode, false);
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_TRUE(transaction, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
transaction.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-03 20:33:52 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBDatabase::MozCreateFileHandle(const nsAString& aName,
|
|
|
|
const nsAString& aType,
|
2012-06-29 20:48:34 +04:00
|
|
|
JSContext* aCx,
|
2012-06-03 20:33:52 +04:00
|
|
|
nsIIDBRequest** _retval)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2012-11-09 01:41:23 +04:00
|
|
|
if (!IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
NS_WARNING("Not supported yet!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
if (QuotaManager::IsShuttingDown()) {
|
2012-06-03 20:33:52 +04:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mClosed) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsRefPtr<IDBRequest> request = IDBRequest::Create(nullptr, this, nullptr, aCx);
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
nsRefPtr<CreateFileHelper> helper =
|
|
|
|
new CreateFileHelper(this, request, aName, aType);
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
QuotaManager* quotaManager = QuotaManager::Get();
|
|
|
|
NS_ASSERTION(quotaManager, "We should definitely have a manager here");
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
nsresult rv = helper->Dispatch(quotaManager->IOThread());
|
2012-06-03 20:33:52 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBDatabase::Close()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
CloseInternal(false);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(mClosed, "Should have set the closed flag!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_IMETHODIMP_(nsIAtom*)
|
|
|
|
IDBDatabase::Id()
|
2012-12-17 23:25:10 +04:00
|
|
|
{
|
2013-03-26 15:13:17 +04:00
|
|
|
return mDatabaseId;
|
2012-12-17 23:25:10 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
IDBDatabase::IsInvalidated()
|
2012-06-03 20:33:52 +04:00
|
|
|
{
|
2013-03-26 15:13:17 +04:00
|
|
|
return mInvalidated;
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
|
|
|
IDBDatabase::IsShuttingDown()
|
2012-06-03 20:33:52 +04:00
|
|
|
{
|
2013-03-26 15:13:17 +04:00
|
|
|
return QuotaManager::IsShuttingDown();
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2012-06-03 20:33:52 +04:00
|
|
|
IDBDatabase::SetThreadLocals()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(GetOwner(), "Should have owner!");
|
2012-12-19 21:45:57 +04:00
|
|
|
QuotaManager::SetCurrentWindow(GetOwner());
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
2012-06-03 20:33:52 +04:00
|
|
|
IDBDatabase::UnsetThreadLocals()
|
|
|
|
{
|
2012-12-19 21:45:57 +04:00
|
|
|
QuotaManager::SetCurrentWindow(nullptr);
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
|
|
|
|
2013-03-26 15:13:17 +04: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-11 02:26:03 +03:00
|
|
|
nsresult
|
|
|
|
IDBDatabase::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|
|
|
{
|
2012-06-29 20:48:34 +04:00
|
|
|
return IndexedDatabaseManager::FireWindowOnError(GetOwner(), aVisitor);
|
2010-11-11 02:26:03 +03:00
|
|
|
}
|
|
|
|
|
2012-10-05 23:09:33 +04:00
|
|
|
AsyncConnectionHelper::ChildProcessSendResult
|
|
|
|
NoRequestDatabaseHelper::SendResponseToChildProcess(nsresult aResultCode)
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
return Success_NotSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NoRequestDatabaseHelper::UnpackResponseFromParentProcess(
|
|
|
|
const ResponseValue& aResponseValue)
|
|
|
|
{
|
|
|
|
MOZ_NOT_REACHED("Should never get here!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NoRequestDatabaseHelper::OnSuccess()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
NoRequestDatabaseHelper::OnError()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
2012-06-29 20:48:34 +04:00
|
|
|
mTransaction->Abort(GetResultCode());
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2010-11-11 02:25:44 +03:00
|
|
|
nsresult
|
2010-06-23 23:46:08 +04:00
|
|
|
CreateObjectStoreHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
{
|
2010-10-19 21:58:52 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt =
|
|
|
|
mTransaction->GetCachedStatement(NS_LITERAL_CSTRING(
|
2011-12-04 21:39:01 +04:00
|
|
|
"INSERT INTO object_store (id, auto_increment, name, key_path) "
|
|
|
|
"VALUES (:id, :auto_increment, :name, :key_path)"
|
2010-10-19 21:58:52 +04:00
|
|
|
));
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("id"),
|
|
|
|
mObjectStore->Id());
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-12-04 21:39:01 +04:00
|
|
|
rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("auto_increment"),
|
|
|
|
mObjectStore->IsAutoIncrement() ? 1 : 0);
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2011-12-04 21:39:01 +04:00
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("name"), mObjectStore->Name());
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-06-22 02:27:13 +04:00
|
|
|
const KeyPath& keyPath = mObjectStore->GetKeyPath();
|
|
|
|
if (keyPath.IsValid()) {
|
|
|
|
nsAutoString keyPathSerialization;
|
|
|
|
keyPath.SerializeToString(keyPathSerialization);
|
2011-12-20 14:59:07 +04:00
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("key_path"),
|
2012-06-22 02:27:13 +04:00
|
|
|
keyPathSerialization);
|
2011-12-20 14:59:07 +04: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 21:58:52 +04:00
|
|
|
rv = stmt->Execute();
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_OK;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2012-06-01 21:21:12 +04:00
|
|
|
void
|
|
|
|
CreateObjectStoreHelper::ReleaseMainThreadObjects()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mObjectStore = nullptr;
|
2012-06-01 21:21:12 +04:00
|
|
|
NoRequestDatabaseHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
2010-11-11 02:25:44 +03:00
|
|
|
nsresult
|
2010-11-11 02:25:57 +03:00
|
|
|
DeleteObjectStoreHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2010-10-19 21:58:52 +04:00
|
|
|
nsCOMPtr<mozIStorageStatement> stmt =
|
|
|
|
mTransaction->GetCachedStatement(NS_LITERAL_CSTRING(
|
2010-06-23 23:46:08 +04:00
|
|
|
"DELETE FROM object_store "
|
2010-10-19 21:58:52 +04:00
|
|
|
"WHERE id = :id "
|
|
|
|
));
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_TRUE(stmt, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
mozStorageStatementScoper scoper(stmt);
|
|
|
|
|
|
|
|
nsresult rv = stmt->BindInt64ByName(NS_LITERAL_CSTRING("id"), mObjectStoreId);
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
rv = stmt->Execute();
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-11-11 02:25:44 +03:00
|
|
|
return NS_OK;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
2012-06-03 20:33:52 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateFileHelper::DoDatabaseWork(mozIStorageConnection* aConnection)
|
|
|
|
{
|
|
|
|
FileManager* fileManager = mDatabase->Manager();
|
|
|
|
|
|
|
|
mFileInfo = fileManager->GetNewFileInfo();
|
|
|
|
NS_ENSURE_TRUE(mFileInfo, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2012-08-24 22:51:33 +04: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 20:33:52 +04:00
|
|
|
NS_ENSURE_TRUE(directory, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2012-08-24 22:51:33 +04:00
|
|
|
file = fileManager->GetFileForId(directory, fileId);
|
2012-06-03 20:33:52 +04:00
|
|
|
NS_ENSURE_TRUE(file, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
2012-08-24 22:51:33 +04:00
|
|
|
rv = file->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
|
2012-06-03 20:33:52 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
CreateFileHelper::GetSuccessResult(JSContext* aCx,
|
|
|
|
jsval* aVal)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|