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: */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Indexed Database.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Ben Turner <bent.mozilla@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
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"
|
|
|
|
#include "nsDOMClassInfo.h"
|
2011-12-16 11:34:24 +04:00
|
|
|
#include "nsDOMLists.h"
|
2010-11-11 02:26:03 +03:00
|
|
|
#include "nsEventDispatcher.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"
|
2010-09-10 02:15:40 +04:00
|
|
|
#include "CheckQuotaHelper.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "DatabaseInfo.h"
|
|
|
|
#include "IDBEvents.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 "IndexedDatabaseManager.h"
|
|
|
|
#include "TransactionThreadPool.h"
|
2011-12-27 22:01:28 +04:00
|
|
|
#include "DictionaryHelpers.h"
|
2012-02-08 06:53:33 +04:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
USING_INDEXEDDB_NAMESPACE
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class CreateObjectStoreHelper : public AsyncConnectionHelper
|
|
|
|
{
|
|
|
|
public:
|
2010-06-28 20:46:21 +04:00
|
|
|
CreateObjectStoreHelper(IDBTransaction* aTransaction,
|
2010-10-19 21:58:52 +04:00
|
|
|
IDBObjectStore* aObjectStore)
|
|
|
|
: AsyncConnectionHelper(aTransaction, nsnull), mObjectStore(aObjectStore)
|
2010-06-23 23:46:08 +04:00
|
|
|
{ }
|
|
|
|
|
2010-11-11 02:25:44 +03:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
2011-01-07 09:21:36 +03:00
|
|
|
|
|
|
|
nsresult OnSuccess()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnError()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mTransaction->IsAborted(), "How else can this fail?!");
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
void ReleaseMainThreadObjects()
|
|
|
|
{
|
|
|
|
mObjectStore = nsnull;
|
|
|
|
AsyncConnectionHelper::ReleaseMainThreadObjects();
|
|
|
|
}
|
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
|
|
|
};
|
|
|
|
|
2010-11-11 02:25:57 +03:00
|
|
|
class DeleteObjectStoreHelper : public AsyncConnectionHelper
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2010-11-11 02:25:57 +03:00
|
|
|
DeleteObjectStoreHelper(IDBTransaction* aTransaction,
|
2010-10-19 21:58:52 +04:00
|
|
|
PRInt64 aObjectStoreId)
|
|
|
|
: AsyncConnectionHelper(aTransaction, nsnull), mObjectStoreId(aObjectStoreId)
|
2010-06-23 23:46:08 +04:00
|
|
|
{ }
|
|
|
|
|
2010-11-11 02:25:44 +03:00
|
|
|
nsresult DoDatabaseWork(mozIStorageConnection* aConnection);
|
2011-01-07 09:21:36 +03:00
|
|
|
|
|
|
|
nsresult OnSuccess()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnError()
|
|
|
|
{
|
2012-05-17 02:12:11 +04:00
|
|
|
NS_ASSERTION(mTransaction->IsAborted(), "How else can this fail?!");
|
2011-01-07 09:21:36 +03:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// In-params.
|
2010-10-19 21:58:52 +04:00
|
|
|
PRInt64 mObjectStoreId;
|
2010-06-23 23:46:08 +04:00
|
|
|
};
|
|
|
|
|
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()
|
|
|
|
{
|
2011-12-17 04:40:47 +04:00
|
|
|
mInfo = nsnull;
|
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,
|
2011-11-08 04:15:45 +04:00
|
|
|
already_AddRefed<DatabaseInfo> aDatabaseInfo,
|
2011-12-16 11:34:24 +04:00
|
|
|
const nsACString& aASCIIOrigin,
|
|
|
|
FileManager* aFileManager)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
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-02-27 20:52:19 +04:00
|
|
|
if (!db->SetScriptOwner(aOwnerCache->GetScriptOwner())) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
2010-09-10 02:15:38 +04:00
|
|
|
|
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;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:33 +04:00
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
|
2010-09-10 23:12:11 +04:00
|
|
|
NS_ASSERTION(mgr, "This should never be null!");
|
|
|
|
|
|
|
|
if (!mgr->RegisterDatabase(db)) {
|
2010-10-19 21:58:42 +04:00
|
|
|
// Either out of memory or shutting down.
|
2010-09-10 23:12:11 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
return db.forget();
|
|
|
|
}
|
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
IDBDatabase::IDBDatabase()
|
2010-09-10 23:12:11 +04:00
|
|
|
: mDatabaseId(0),
|
2010-10-19 21:58:42 +04:00
|
|
|
mInvalidated(0),
|
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!");
|
|
|
|
|
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
|
|
|
|
2010-10-19 21:58:42 +04:00
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->UnregisterDatabase(this);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
2012-01-24 14:03:37 +04:00
|
|
|
|
|
|
|
nsContentUtils::ReleaseWrapper(static_cast<nsIDOMEventTarget*>(this), this);
|
2010-09-10 02:15:40 +04:00
|
|
|
}
|
|
|
|
|
2010-09-10 23:12:11 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::Invalidate()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2010-10-19 21:58:39 +04:00
|
|
|
|
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
|
|
|
|
// is an origin, so we call back into the manager to cancel any prompts for
|
|
|
|
// our owner.
|
2012-05-17 02:08:18 +04:00
|
|
|
nsPIDOMWindow* owner = GetOwner();
|
|
|
|
if (owner) {
|
|
|
|
IndexedDatabaseManager::CancelPromptsForWindow(owner);
|
|
|
|
}
|
2010-10-19 21:58:39 +04:00
|
|
|
|
2011-11-08 04:15:45 +04:00
|
|
|
mInvalidated = true;
|
2010-09-10 23:12:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IDBDatabase::IsInvalidated()
|
|
|
|
{
|
|
|
|
return !!mInvalidated;
|
|
|
|
}
|
|
|
|
|
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) {
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
IndexedDatabaseManager* mgr = IndexedDatabaseManager::Get();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->OnDatabaseClosed(this);
|
|
|
|
}
|
|
|
|
mClosed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IDBDatabase::IsClosed()
|
|
|
|
{
|
|
|
|
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?");
|
|
|
|
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?");
|
|
|
|
mRunningVersionChange = false;
|
2011-10-25 16:49:31 +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
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-10 02:15:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBDatabase)
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2012-01-24 14:03:37 +04: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-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)
|
|
|
|
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(abort)
|
|
|
|
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(error)
|
|
|
|
NS_CYCLE_COLLECTION_UNLINK_EVENT_HANDLER(versionchange)
|
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)
|
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
|
|
|
|
2012-01-24 14:03:37 +04:00
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, abort);
|
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, error);
|
|
|
|
NS_IMPL_EVENT_HANDLER(IDBDatabase, versionchange);
|
|
|
|
|
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
|
2011-10-20 20:10:56 +04:00
|
|
|
IDBDatabase::GetVersion(PRUint64* 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());
|
|
|
|
PRUint32 count = objectStoreNames.Length();
|
|
|
|
for (PRUint32 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
|
|
|
|
2011-12-27 22:01:28 +04:00
|
|
|
mozilla::dom::IDBObjectStoreParameters params;
|
2010-12-21 19:02:01 +03:00
|
|
|
nsString keyPath;
|
2011-12-04 21:39:01 +04:00
|
|
|
keyPath.SetIsVoid(true);
|
2011-12-20 14:59:07 +04:00
|
|
|
nsTArray<nsString> keyPathArray;
|
2010-12-21 19:02:01 +03:00
|
|
|
|
|
|
|
if (!JSVAL_IS_VOID(aOptions) && !JSVAL_IS_NULL(aOptions)) {
|
2011-12-27 22:01:28 +04:00
|
|
|
nsresult rv = params.Init(aCx, &aOptions);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-12-21 19:02:01 +03:00
|
|
|
|
2011-12-20 14:59:07 +04:00
|
|
|
// Get keyPath
|
2011-12-27 22:01:28 +04:00
|
|
|
jsval val = params.keyPath;
|
2011-11-08 10:25:51 +04:00
|
|
|
if (!JSVAL_IS_VOID(val) && !JSVAL_IS_NULL(val)) {
|
2011-12-20 14:59:07 +04:00
|
|
|
if (!JSVAL_IS_PRIMITIVE(val) &&
|
|
|
|
JS_IsArrayObject(aCx, JSVAL_TO_OBJECT(val))) {
|
|
|
|
|
|
|
|
JSObject* obj = JSVAL_TO_OBJECT(val);
|
|
|
|
|
2012-03-07 03:52:55 +04:00
|
|
|
uint32_t length;
|
2011-12-20 14:59:07 +04:00
|
|
|
if (!JS_GetArrayLength(aCx, obj, &length)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!length) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyPathArray.SetCapacity(length);
|
|
|
|
|
2012-03-07 03:52:55 +04:00
|
|
|
for (uint32_t index = 0; index < length; index++) {
|
2011-12-20 14:59:07 +04:00
|
|
|
jsval val;
|
|
|
|
JSString* jsstr;
|
|
|
|
nsDependentJSString str;
|
|
|
|
if (!JS_GetElement(aCx, obj, index, &val) ||
|
|
|
|
!(jsstr = JS_ValueToString(aCx, val)) ||
|
|
|
|
!str.init(aCx, jsstr)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IDBObjectStore::IsValidKeyPath(aCx, str)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyPathArray.AppendElement(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!keyPathArray.IsEmpty(), "This shouldn't have happened!");
|
2010-12-21 19:02:01 +03:00
|
|
|
}
|
2011-12-20 14:59:07 +04:00
|
|
|
else {
|
|
|
|
JSString* jsstr;
|
|
|
|
nsDependentJSString str;
|
|
|
|
if (!(jsstr = JS_ValueToString(aCx, val)) ||
|
|
|
|
!str.init(aCx, jsstr)) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IDBObjectStore::IsValidKeyPath(aCx, str)) {
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
keyPath = str;
|
2010-12-21 19:02:01 +03:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-27 22:01:28 +04:00
|
|
|
if (params.autoIncrement &&
|
2011-12-20 14:59:07 +04:00
|
|
|
((!keyPath.IsVoid() && keyPath.IsEmpty()) || !keyPathArray.IsEmpty())) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
2011-11-21 18:56:24 +04:00
|
|
|
}
|
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
nsRefPtr<ObjectStoreInfo> newInfo(new ObjectStoreInfo());
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
newInfo->name = aName;
|
|
|
|
newInfo->id = databaseInfo->nextObjectStoreId++;
|
|
|
|
newInfo->keyPath = keyPath;
|
2011-12-20 14:59:07 +04:00
|
|
|
newInfo->keyPathArray = keyPathArray;
|
2011-12-27 22:01:28 +04:00
|
|
|
newInfo->nextAutoIncrementId = params.autoIncrement ? 1 : 0;
|
2011-12-17 04:40:47 +04:00
|
|
|
newInfo->comittedAutoIncrementId = newInfo->nextAutoIncrementId;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2011-12-17 04:40:47 +04:00
|
|
|
if (!databaseInfo->PutObjectStore(newInfo)) {
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_WARNING("Put failed!");
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Don't leave this in the hash if we fail below!
|
2011-12-17 04:40:47 +04:00
|
|
|
AutoRemoveObjectStore autoRemove(databaseInfo, aName);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
|
|
|
nsRefPtr<IDBObjectStore> objectStore =
|
2011-12-17 04:40:47 +04:00
|
|
|
transaction->GetOrCreateObjectStore(aName, newInfo);
|
2010-11-11 02:25:44 +03:00
|
|
|
NS_ENSURE_TRUE(objectStore, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
2010-08-27 00:57:25 +04:00
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
nsRefPtr<CreateObjectStoreHelper> helper =
|
2010-10-19 21:58:52 +04:00
|
|
|
new CreateObjectStoreHelper(transaction, objectStore);
|
|
|
|
|
2010-06-23 23:46:08 +04:00
|
|
|
nsresult rv = helper->DispatchToTransactionPool();
|
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
|
|
|
autoRemove.forget();
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-11-11 02:25:57 +03:00
|
|
|
nsRefPtr<DeleteObjectStoreHelper> helper =
|
|
|
|
new DeleteObjectStoreHelper(transaction, objectStoreInfo->id);
|
2010-06-23 23:46:08 +04:00
|
|
|
nsresult rv = helper->DispatchToTransactionPool();
|
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-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,
|
2010-06-28 20:46:49 +04:00
|
|
|
PRUint8 aOptionalArgCount,
|
|
|
|
nsIIDBTransaction** _retval)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
2010-10-19 21:58:42 +04:00
|
|
|
if (IndexedDatabaseManager::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) {
|
|
|
|
PRUint32 length;
|
|
|
|
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
|
|
|
|
2011-11-03 19:57:30 +04:00
|
|
|
for (PRUint32 index = 0; index < length; index++) {
|
|
|
|
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();
|
2011-11-03 19:57:30 +04:00
|
|
|
for (PRUint32 index = 0; index < storesToOpen.Length(); index++) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
nsresult
|
|
|
|
IDBDatabase::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(aVisitor.mDOMEvent, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2012-05-17 02:08:18 +04:00
|
|
|
nsPIDOMWindow* owner = GetOwner();
|
|
|
|
if (!owner) {
|
2012-01-03 19:27:39 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
if (aVisitor.mEventStatus != nsEventStatus_eConsumeNoDefault) {
|
2011-01-07 09:21:36 +03:00
|
|
|
nsString type;
|
|
|
|
nsresult rv = aVisitor.mDOMEvent->GetType(type);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (type.EqualsLiteral(ERROR_EVT_STR)) {
|
2011-11-23 18:15:15 +04:00
|
|
|
nsRefPtr<nsDOMEvent> duplicateEvent =
|
|
|
|
CreateGenericEvent(type, eDoesNotBubble, eNotCancelable);
|
2011-01-07 09:21:36 +03:00
|
|
|
NS_ENSURE_STATE(duplicateEvent);
|
2010-11-11 02:26:03 +03:00
|
|
|
|
2012-05-17 02:08:18 +04:00
|
|
|
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(owner));
|
2010-11-11 02:26:03 +03:00
|
|
|
NS_ASSERTION(target, "How can this happen?!");
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dummy;
|
2011-01-07 09:21:36 +03:00
|
|
|
rv = target->DispatchEvent(duplicateEvent, &dummy);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-11-11 02:26:03 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-12-20 14:59:07 +04:00
|
|
|
if (mObjectStore->UsesKeyPathArray()) {
|
|
|
|
// We use a comma in the beginning to indicate that it's an array of
|
|
|
|
// key paths. This is to be able to tell a string-keypath from an
|
|
|
|
// array-keypath which contains only one item.
|
|
|
|
// It also makes serializing easier :-)
|
|
|
|
nsAutoString keyPath;
|
|
|
|
const nsTArray<nsString>& keyPaths = mObjectStore->KeyPathArray();
|
|
|
|
for (PRUint32 i = 0; i < keyPaths.Length(); ++i) {
|
|
|
|
keyPath.Append(NS_LITERAL_STRING(",") + keyPaths[i]);
|
|
|
|
}
|
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("key_path"),
|
|
|
|
keyPath);
|
|
|
|
NS_ENSURE_SUCCESS(rv, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
}
|
|
|
|
else if (mObjectStore->HasKeyPath()) {
|
|
|
|
rv = stmt->BindStringByName(NS_LITERAL_CSTRING("key_path"),
|
|
|
|
mObjectStore->KeyPath());
|
|
|
|
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-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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|