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
|
|
|
|
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"
|
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"
|
2010-09-09 15:15:40 -07:00
|
|
|
#include "CheckQuotaHelper.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
#include "DatabaseInfo.h"
|
|
|
|
#include "IDBEvents.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"
|
2010-09-10 12:12:11 -07:00
|
|
|
#include "IndexedDatabaseManager.h"
|
|
|
|
#include "TransactionThreadPool.h"
|
2011-12-27 10:01:28 -08:00
|
|
|
#include "DictionaryHelpers.h"
|
2012-07-01 16:45:59 -07:00
|
|
|
#include "nsContentUtils.h"
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
#include "ipc/IndexedDBChild.h"
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
USING_INDEXEDDB_NAMESPACE
|
2012-08-01 23:02:29 -07:00
|
|
|
using mozilla::dom::ContentParent;
|
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
|
|
|
|
MaybeSendResponseToChildProcess(nsresult aResultCode) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
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,
|
|
|
|
jsval* aVal);
|
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
mFileInfo = nullptr;
|
2012-06-03 09:33:52 -07:00
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ChildProcessSendResult MaybeSendResponseToChildProcess(
|
|
|
|
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 10:58:52 -07:00
|
|
|
NS_STACK_CLASS
|
|
|
|
class AutoRemoveObjectStore
|
|
|
|
{
|
|
|
|
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,
|
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!");
|
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-02-27 08:52:19 -08:00
|
|
|
if (!db->SetScriptOwner(aOwnerCache->GetScriptOwner())) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2012-02-27 08:52:19 -08:00
|
|
|
}
|
2010-09-09 15:15:38 -07:00
|
|
|
|
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
|
|
|
|
2010-10-19 10:58:33 -07:00
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
|
2010-09-10 12:12:11 -07:00
|
|
|
NS_ASSERTION(mgr, "This should never be null!");
|
|
|
|
|
|
|
|
if (!mgr->RegisterDatabase(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
|
|
|
}
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
return db.forget();
|
|
|
|
}
|
|
|
|
|
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),
|
2010-10-19 10:58:42 -07:00
|
|
|
mInvalidated(0),
|
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!");
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
IDBDatabase::~IDBDatabase()
|
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
|
|
|
|
2010-10-19 10:58:42 -07:00
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->UnregisterDatabase(this);
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
2012-01-24 02:03:37 -08:00
|
|
|
|
|
|
|
nsContentUtils::ReleaseWrapper(static_cast<nsIDOMEventTarget*>(this), this);
|
2010-09-09 15:15:40 -07:00
|
|
|
}
|
|
|
|
|
2010-09-10 12:12:11 -07:00
|
|
|
void
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
// is an origin, so we call back into the manager to cancel any prompts for
|
|
|
|
// our owner.
|
2012-05-16 15:08:18 -07:00
|
|
|
nsPIDOMWindow* owner = GetOwner();
|
|
|
|
if (owner) {
|
|
|
|
IndexedDatabaseManager::CancelPromptsForWindow(owner);
|
|
|
|
}
|
2010-10-19 10:58:39 -07:00
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
mInvalidated = true;
|
2010-09-10 12:12:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IDBDatabase::IsInvalidated()
|
|
|
|
{
|
|
|
|
return !!mInvalidated;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->OnDatabaseClosed(this);
|
|
|
|
}
|
2012-06-01 10:21:12 -07:00
|
|
|
|
|
|
|
// And let the parent process know as well.
|
|
|
|
if (mActorChild) {
|
|
|
|
NS_ASSERTION(!IndexedDatabaseManager::IsMainProcess(), "Wrong process!");
|
|
|
|
mActorChild->SendClose(aIsDead);
|
|
|
|
}
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IDBDatabase::IsClosed()
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
// No reason for the IndexedDatabaseManager to track us any longer.
|
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->UnregisterDatabase(this);
|
|
|
|
|
|
|
|
// Don't try to unregister again in the destructor.
|
|
|
|
mRegistered = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:21:12 -07: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;
|
|
|
|
}
|
|
|
|
|
2010-09-09 15:15:38 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBDatabase)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
|
|
|
|
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(abort)
|
|
|
|
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(error)
|
|
|
|
NS_CYCLE_COLLECTION_TRAVERSE_EVENT_HANDLER(versionchange)
|
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)
|
|
|
|
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(abort)
|
|
|
|
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(error)
|
|
|
|
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(versionchange)
|
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)
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIIDBDatabase)
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIFileStorage)
|
2010-06-28 09:46:49 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(IDBDatabase)
|
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
|
|
|
|
2010-06-28 09:46:49 -07:00
|
|
|
DOMCI_DATA(IDBDatabase, IDBDatabase)
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-01-24 02:03:37 -08:00
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, abort);
|
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, error);
|
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, versionchange);
|
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
NS_IMETHODIMP
|
2010-06-28 09:46:49 -07:00
|
|
|
IDBDatabase::GetName(nsAString& aName)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
aName.Assign(mName);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
IDBDatabase::GetVersion(uint64_t* aVersion)
|
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();
|
2011-10-20 09:10:56 -07:00
|
|
|
*aVersion = info->version;
|
2011-11-07 16:06:13 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-28 09:46:49 -07:00
|
|
|
IDBDatabase::GetObjectStoreNames(nsIDOMDOMStringList** aObjectStores)
|
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!");
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
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++) {
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(list->Add(objectStoreNames[index]),
|
|
|
|
NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
list.forget(aObjectStores);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-06-28 09:46:49 -07:00
|
|
|
IDBDatabase::CreateObjectStore(const nsAString& aName,
|
2010-12-21 08:02:01 -08:00
|
|
|
const jsval& aOptions,
|
|
|
|
JSContext* aCx,
|
2010-10-19 10:58:52 -07:00
|
|
|
nsIIDBObjectStore** _retval)
|
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) {
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
DatabaseInfo* databaseInfo = transaction->DBInfo();
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-12-27 10:01:28 -08:00
|
|
|
mozilla::dom::IDBObjectStoreParameters params;
|
2012-06-21 15:27:13 -07:00
|
|
|
KeyPath keyPath(0);
|
2011-12-20 02:59:07 -08:00
|
|
|
nsTArray<nsString> keyPathArray;
|
2010-12-21 08:02:01 -08:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsresult rv;
|
|
|
|
|
2010-12-21 08:02:01 -08:00
|
|
|
if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
|
2012-06-01 10:21:12 -07:00
|
|
|
rv = params.Init(aCx, &aOptions);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2010-12-21 08:02:01 -08:00
|
|
|
|
2012-06-21 15:27:13 -07: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 10:21:12 -07:00
|
|
|
|
2012-06-21 15:27:13 -07:00
|
|
|
if (NS_FAILED(KeyPath::Parse(aCx, hasProp ? params.keyPath : JSVAL_NULL,
|
|
|
|
&keyPath))) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2011-11-07 22:25:51 -08:00
|
|
|
}
|
2010-12-21 08:02:01 -08:00
|
|
|
}
|
|
|
|
|
2011-12-04 09:39:01 -08:00
|
|
|
if (databaseInfo->ContainsStoreName(aName)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
|
|
|
|
}
|
|
|
|
|
2012-06-21 15:27:13 -07:00
|
|
|
if (!keyPath.IsAllowedForObjectStore(params.autoIncrement)) {
|
2011-12-20 02:59:07 -08:00
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
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;
|
|
|
|
guts.autoIncrement = params.autoIncrement;
|
2010-08-26 13:57:25 -07:00
|
|
|
|
2012-06-01 10:21:12 -07:00
|
|
|
nsRefPtr<IDBObjectStore> objectStore;
|
|
|
|
rv = CreateObjectStoreInternal(transaction, guts,
|
|
|
|
getter_AddRefs(objectStore));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-10-19 10:58:52 -07:00
|
|
|
|
|
|
|
objectStore.forget(_retval);
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-11-10 15:25:57 -08:00
|
|
|
IDBDatabase::DeleteObjectStore(const nsAString& aName)
|
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) {
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
DatabaseInfo* info = transaction->DBInfo();
|
|
|
|
ObjectStoreInfo* objectStoreInfo = info->GetObjectStore(aName);
|
|
|
|
if (!objectStoreInfo) {
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-06-01 10:21:12 -07: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 12:46:08 -07:00
|
|
|
|
2011-12-16 16:40:47 -08:00
|
|
|
transaction->RemoveObjectStore(aName);
|
2011-12-04 09:39:01 -08:00
|
|
|
|
2010-06-23 12:46:08 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-11-03 08:57:30 -07:00
|
|
|
IDBDatabase::Transaction(const jsval& aStoreNames,
|
2012-03-12 21:44:45 -07:00
|
|
|
const nsAString& aMode,
|
2010-08-26 13:57:25 -07:00
|
|
|
JSContext* aCx,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t aOptionalArgCount,
|
2010-06-28 09:46:49 -07:00
|
|
|
nsIIDBTransaction** _retval)
|
2010-06-23 12:46:08 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-10-19 10:58:42 -07:00
|
|
|
if (IndexedDatabaseManager::IsShuttingDown()) {
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2010-10-19 10:58:42 -07:00
|
|
|
}
|
|
|
|
|
2010-10-19 10:58:52 -07:00
|
|
|
if (mClosed) {
|
2010-11-10 15:25:44 -08:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2010-10-19 10:58:52 -07:00
|
|
|
}
|
|
|
|
|
2011-11-07 16:15:45 -08:00
|
|
|
if (mRunningVersionChange) {
|
2011-11-03 08:57:30 -07:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2012-03-12 21:44:45 -07:00
|
|
|
IDBTransaction::Mode transactionMode = IDBTransaction::READ_ONLY;
|
2010-06-23 12:46:08 -07:00
|
|
|
if (aOptionalArgCount) {
|
2012-03-12 21:44:45 -07:00
|
|
|
if (aMode.EqualsLiteral("readwrite")) {
|
|
|
|
transactionMode = IDBTransaction::READ_WRITE;
|
|
|
|
}
|
|
|
|
else if (!aMode.EqualsLiteral("readonly")) {
|
2012-04-11 14:55:21 -07:00
|
|
|
return NS_ERROR_TYPE_ERR;
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
nsresult rv;
|
2011-11-02 18:57:48 -07:00
|
|
|
nsTArray<nsString> storesToOpen;
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!JSVAL_IS_PRIMITIVE(aStoreNames)) {
|
|
|
|
JSObject* obj = JSVAL_TO_OBJECT(aStoreNames);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
// See if this is a JS array.
|
|
|
|
if (JS_IsArrayObject(aCx, obj)) {
|
2012-03-06 15:52:55 -08:00
|
|
|
uint32_t length;
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!JS_GetArrayLength(aCx, obj, &length)) {
|
2011-11-02 18:57:48 -07:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!length) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
2011-11-02 18:03:15 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
storesToOpen.SetCapacity(length);
|
2011-11-02 18:03:15 -07:00
|
|
|
|
2012-03-06 15:52:55 -08:00
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2011-11-03 08:57:30 -07: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-02 18:57:48 -07:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
2011-11-03 08:57:30 -07:00
|
|
|
|
|
|
|
storesToOpen.AppendElement(str);
|
2011-11-02 18:57:48 -07:00
|
|
|
}
|
2011-11-03 08:57:30 -07: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-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-11-03 08:57:30 -07:00
|
|
|
if (wrapper) {
|
|
|
|
nsISupports* wrappedObject = wrapper->Native();
|
|
|
|
NS_ENSURE_TRUE(wrappedObject, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
// We only accept DOMStringList.
|
|
|
|
nsCOMPtr<nsIDOMDOMStringList> list = do_QueryInterface(wrappedObject);
|
|
|
|
if (list) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t length;
|
2011-11-03 08:57:30 -07:00
|
|
|
rv = list->GetLength(&length);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!length) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2011-11-03 08:57:30 -07:00
|
|
|
storesToOpen.SetCapacity(length);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2011-11-03 08:57:30 -07:00
|
|
|
nsString* item = storesToOpen.AppendElement();
|
|
|
|
NS_ASSERTION(item, "This should never fail!");
|
2011-11-02 18:03:15 -07:00
|
|
|
|
2011-11-03 08:57:30 -07: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 12:46:08 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 08:57:30 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-02 18:03:15 -07:00
|
|
|
|
2011-11-03 08:57:30 -07: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-07 16:15:45 -08:00
|
|
|
DatabaseInfo* info = Info();
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t index = 0; index < storesToOpen.Length(); index++) {
|
2011-11-03 08:57:30 -07:00
|
|
|
if (!info->ContainsStoreName(storesToOpen[index])) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
|
|
|
|
}
|
2010-06-23 12:46:08 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 09:46:21 -07:00
|
|
|
nsRefPtr<IDBTransaction> transaction =
|
2012-03-12 21:44:45 -07:00
|
|
|
IDBTransaction::Create(this, storesToOpen, transactionMode, false);
|
2010-11-10 15:25:44 -08:00
|
|
|
NS_ENSURE_TRUE(transaction, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-06-23 12:46:08 -07:00
|
|
|
|
|
|
|
transaction.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBDatabase::MozCreateFileHandle(const nsAString& aName,
|
|
|
|
const nsAString& aType,
|
2012-06-29 09:48:34 -07:00
|
|
|
JSContext* aCx,
|
2012-06-03 09:33:52 -07:00
|
|
|
nsIIDBRequest** _retval)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
if (IndexedDatabaseManager::IsShuttingDown()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mClosed) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
nsRefPtr<IDBRequest> request = IDBRequest::Create(nullptr, this, nullptr, aCx);
|
2012-06-03 09:33:52 -07:00
|
|
|
|
|
|
|
nsRefPtr<CreateFileHelper> helper =
|
|
|
|
new CreateFileHelper(this, request, aName, aType);
|
|
|
|
|
|
|
|
IndexedDatabaseManager* manager = IndexedDatabaseManager::Get();
|
|
|
|
NS_ASSERTION(manager, "We should definitely have a manager here");
|
|
|
|
|
|
|
|
nsresult rv = helper->Dispatch(manager->IOThread());
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
|
|
|
|
request.forget(_retval);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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!");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-03 09:33:52 -07:00
|
|
|
nsISupports*
|
|
|
|
IDBDatabase::StorageId()
|
|
|
|
{
|
|
|
|
return Id();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IDBDatabase::IsStorageInvalidated()
|
|
|
|
{
|
|
|
|
return IsInvalidated();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IDBDatabase::IsStorageShuttingDown()
|
|
|
|
{
|
|
|
|
return IndexedDatabaseManager::IsShuttingDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IDBDatabase::SetThreadLocals()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(GetOwner(), "Should have owner!");
|
|
|
|
IndexedDatabaseManager::SetCurrentWindow(GetOwner());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IDBDatabase::UnsetThreadLocals()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
IndexedDatabaseManager::SetCurrentWindow(nullptr);
|
2012-06-03 09:33:52 -07:00
|
|
|
}
|
|
|
|
|
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-06-01 10:21:12 -07:00
|
|
|
HelperBase::ChildProcessSendResult
|
|
|
|
NoRequestDatabaseHelper::MaybeSendResponseToChildProcess(nsresult aResultCode)
|
|
|
|
{
|
|
|
|
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 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)
|
|
|
|
{
|
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
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
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);
|
|
|
|
}
|