2010-06-23 23:46:08 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
#include "IDBDatabase.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "FileInfo.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
#include "IDBEvents.h"
|
2012-08-30 04:50:28 +04:00
|
|
|
#include "IDBFactory.h"
|
2010-10-19 21:58:52 +04:00
|
|
|
#include "IDBIndex.h"
|
2014-06-12 07:35:29 +04:00
|
|
|
#include "IDBMutableFile.h"
|
2010-06-28 22:51:06 +04:00
|
|
|
#include "IDBObjectStore.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IDBRequest.h"
|
2010-06-28 20:46:21 +04:00
|
|
|
#include "IDBTransaction.h"
|
2010-06-28 20:44:30 +04:00
|
|
|
#include "IDBFactory.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "IndexedDatabaseManager.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/EventDispatcher.h"
|
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/storage.h"
|
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
|
|
|
#include "mozilla/dom/DOMStringList.h"
|
|
|
|
#include "mozilla/dom/DOMStringListBinding.h"
|
2015-01-26 09:30:09 +03:00
|
|
|
#include "mozilla/dom/Exceptions.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/IDBDatabaseBinding.h"
|
|
|
|
#include "mozilla/dom/IDBObjectStoreBinding.h"
|
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBDatabaseFileChild.h"
|
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBSharedTypes.h"
|
|
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
|
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
|
|
|
#include "mozilla/dom/ipc/nsIRemoteBlob.h"
|
|
|
|
#include "mozilla/dom/quota/QuotaManager.h"
|
|
|
|
#include "mozilla/ipc/FileDescriptor.h"
|
|
|
|
#include "mozilla/ipc/InputStreamParams.h"
|
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsIObserverService.h"
|
2014-11-14 05:20:38 +03:00
|
|
|
#include "nsIScriptError.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsThreadUtils.h"
|
2013-03-16 10:58:50 +04:00
|
|
|
#include "ProfilerHelpers.h"
|
2014-01-28 04:37:05 +04:00
|
|
|
#include "ReportInternalError.h"
|
2016-03-16 10:12:17 +03:00
|
|
|
#include "ScriptErrorHelper.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Include this last to avoid path problems on Windows.
|
|
|
|
#include "ActorsChild.h"
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2013-05-18 05:48:25 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
using namespace mozilla::dom::quota;
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::services;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const char kCycleCollectionObserverTopic[] = "cycle-collector-end";
|
|
|
|
const char kMemoryPressureObserverTopic[] = "memory-pressure";
|
|
|
|
const char kWindowObserverTopic[] = "inner-window-destroyed";
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class CancelableRunnableWrapper final
|
2016-04-11 21:40:06 +03:00
|
|
|
: public CancelableRunnable
|
2014-12-17 09:26:15 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> mRunnable;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit
|
|
|
|
CancelableRunnableWrapper(nsIRunnable* aRunnable)
|
|
|
|
: mRunnable(aRunnable)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aRunnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
~CancelableRunnableWrapper()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
2016-04-11 21:40:06 +03:00
|
|
|
nsresult Cancel() override;
|
2014-12-17 09:26:15 +03:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class DatabaseFile final
|
2014-09-27 03:21:57 +04:00
|
|
|
: public PBackgroundIDBDatabaseFileChild
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase* mDatabase;
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
public:
|
|
|
|
explicit DatabaseFile(IDBDatabase* aDatabase)
|
|
|
|
: mDatabase(aDatabase)
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
MOZ_COUNT_CTOR(DatabaseFile);
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
private:
|
|
|
|
~DatabaseFile()
|
2014-09-13 20:12:19 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(!mDatabase);
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(DatabaseFile);
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
virtual void
|
2015-03-21 19:28:04 +03:00
|
|
|
ActorDestroy(ActorDestroyReason aWhy) override
|
2014-09-27 03:21:57 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mDatabase);
|
|
|
|
mDatabase->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (aWhy != Deletion) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBDatabase> database = mDatabase;
|
2014-09-27 03:21:57 +04:00
|
|
|
database->NoteFinishedFileActor(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
mDatabase = nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class IDBDatabase::Observer final
|
2014-09-27 03:21:57 +04:00
|
|
|
: public nsIObserver
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase* mWeakDatabase;
|
|
|
|
const uint64_t mWindowId;
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
public:
|
|
|
|
Observer(IDBDatabase* aDatabase, uint64_t aWindowId)
|
|
|
|
: mWeakDatabase(aDatabase)
|
|
|
|
, mWindowId(aWindowId)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
Revoke()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mWeakDatabase = nullptr;
|
|
|
|
}
|
2013-03-26 15:13:17 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
private:
|
|
|
|
~Observer()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!mWeakDatabase);
|
2010-09-10 23:12:11 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
IDBDatabase::IDBDatabase(IDBOpenDBRequest* aRequest,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBFactory* aFactory,
|
|
|
|
BackgroundDatabaseChild* aActor,
|
|
|
|
DatabaseSpec* aSpec)
|
2015-09-09 14:15:05 +03:00
|
|
|
: IDBWrapperCache(aRequest)
|
2014-09-27 03:21:57 +04:00
|
|
|
, mFactory(aFactory)
|
|
|
|
, mSpec(aSpec)
|
|
|
|
, mBackgroundActor(aActor)
|
2015-09-09 14:15:05 +03:00
|
|
|
, mFileHandleDisabled(aRequest->IsFileHandleDisabled())
|
2014-09-27 03:21:57 +04:00
|
|
|
, mClosed(false)
|
|
|
|
, mInvalidated(false)
|
2016-04-21 07:53:30 +03:00
|
|
|
, mQuotaExceeded(false)
|
2013-03-26 15:13:17 +04:00
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
MOZ_ASSERT(aRequest);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
aFactory->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(aSpec);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2010-06-28 20:46:49 +04:00
|
|
|
IDBDatabase::~IDBDatabase()
|
2013-07-09 21:30:58 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mBackgroundActor);
|
2013-07-09 21:30:58 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// static
|
|
|
|
already_AddRefed<IDBDatabase>
|
2015-09-09 14:15:05 +03:00
|
|
|
IDBDatabase::Create(IDBOpenDBRequest* aRequest,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBFactory* aFactory,
|
|
|
|
BackgroundDatabaseChild* aActor,
|
|
|
|
DatabaseSpec* aSpec)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
MOZ_ASSERT(aRequest);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aFactory);
|
|
|
|
aFactory->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
MOZ_ASSERT(aSpec);
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBDatabase> db =
|
2015-09-09 14:15:05 +03:00
|
|
|
new IDBDatabase(aRequest, aFactory, aActor, aSpec);
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
db->SetScriptOwner(aRequest->GetScriptOwner());
|
2010-10-19 21:58:39 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (NS_IsMainThread()) {
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowInner* window = aFactory->GetParentObject()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
uint64_t windowId = window->WindowID();
|
2012-06-20 05:50:39 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Observer> observer = new Observer(db, windowId);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = GetObserverService();
|
|
|
|
MOZ_ASSERT(obsSvc);
|
2010-09-10 23:12:11 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// This topic must be successfully registered.
|
|
|
|
if (NS_WARN_IF(NS_FAILED(
|
|
|
|
obsSvc->AddObserver(observer, kWindowObserverTopic, false)))) {
|
|
|
|
observer->Revoke();
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// These topics are not crucial.
|
|
|
|
if (NS_FAILED(obsSvc->AddObserver(observer,
|
|
|
|
kCycleCollectionObserverTopic,
|
|
|
|
false)) ||
|
|
|
|
NS_FAILED(obsSvc->AddObserver(observer,
|
|
|
|
kMemoryPressureObserverTopic,
|
|
|
|
false))) {
|
|
|
|
NS_WARNING("Failed to add additional memory observers!");
|
|
|
|
}
|
2012-10-23 20:31:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
db->mObserver.swap(observer);
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2012-10-05 23:09:33 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return db.forget();
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
|
2012-10-05 23:09:33 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase::AssertIsOnOwningThread() const
|
2012-10-05 23:09:33 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(mFactory);
|
|
|
|
mFactory->AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
PRThread*
|
|
|
|
IDBDatabase::OwningThread() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mFactory);
|
|
|
|
return mFactory->OwningThread();
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
#endif // DEBUG
|
|
|
|
|
2010-10-19 21:58:52 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase::CloseInternal()
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-10-19 21:58:52 +04:00
|
|
|
|
|
|
|
if (!mClosed) {
|
2012-08-10 05:06:21 +04:00
|
|
|
mClosed = true;
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
ExpireFileActors(/* aExpireAll */ true);
|
|
|
|
|
|
|
|
if (mObserver) {
|
|
|
|
mObserver->Revoke();
|
2011-11-08 04:15:45 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = GetObserverService();
|
|
|
|
if (obsSvc) {
|
|
|
|
// These might not have been registered.
|
|
|
|
obsSvc->RemoveObserver(mObserver, kCycleCollectionObserverTopic);
|
|
|
|
obsSvc->RemoveObserver(mObserver, kMemoryPressureObserverTopic);
|
|
|
|
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(
|
|
|
|
obsSvc->RemoveObserver(mObserver, kWindowObserverTopic));
|
2011-11-08 04:15:45 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mObserver = nullptr;
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mBackgroundActor && !mInvalidated) {
|
|
|
|
mBackgroundActor->SendClose();
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::InvalidateInternal()
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
InvalidateMutableFiles();
|
2014-11-14 05:20:38 +03:00
|
|
|
AbortTransactions(/* aShouldWarn */ true);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
CloseInternal();
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
2011-10-25 16:49:31 +04:00
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase::EnterSetVersionTransaction(uint64_t aNewVersion)
|
2011-10-25 16:49:31 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aNewVersion);
|
|
|
|
MOZ_ASSERT(!RunningVersionChangeTransaction());
|
|
|
|
MOZ_ASSERT(mSpec);
|
|
|
|
MOZ_ASSERT(!mPreviousSpec);
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mPreviousSpec = new DatabaseSpec(*mSpec);
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mSpec->metadata().version() = aNewVersion;
|
2011-10-25 16:49:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IDBDatabase::ExitSetVersionTransaction()
|
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (mPreviousSpec) {
|
|
|
|
mPreviousSpec = nullptr;
|
|
|
|
}
|
2011-10-25 16:49:31 +04:00
|
|
|
}
|
|
|
|
|
2012-06-29 20:48:34 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::RevertToPreviousState()
|
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(RunningVersionChangeTransaction());
|
|
|
|
MOZ_ASSERT(mPreviousSpec);
|
2012-06-29 20:48:34 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Hold the current spec alive until RefreshTransactionsSpecEnumerator has
|
|
|
|
// finished!
|
|
|
|
nsAutoPtr<DatabaseSpec> currentSpec(mSpec.forget());
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mSpec = mPreviousSpec.forget();
|
2014-09-18 03:36:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
RefreshSpec(/* aMayDelete */ true);
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::RefreshSpec(bool aMayDelete)
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2015-07-21 04:48:54 +03:00
|
|
|
for (auto iter = mTransactions.Iter(); !iter.Done(); iter.Next()) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBTransaction> transaction = iter.Get()->GetKey();
|
2015-07-21 04:48:54 +03:00
|
|
|
MOZ_ASSERT(transaction);
|
|
|
|
transaction->AssertIsOnOwningThread();
|
|
|
|
transaction->RefreshSpec(aMayDelete);
|
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner*
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase::GetParentObject() const
|
|
|
|
{
|
|
|
|
return mFactory->GetParentObject();
|
|
|
|
}
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsString&
|
|
|
|
IDBDatabase::Name() const
|
2014-09-18 03:36:01 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mSpec);
|
|
|
|
|
|
|
|
return mSpec->metadata().name();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
uint64_t
|
|
|
|
IDBDatabase::Version() const
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mSpec);
|
|
|
|
|
|
|
|
return mSpec->metadata().version();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 21:54:21 +04:00
|
|
|
already_AddRefed<DOMStringList>
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase::ObjectStoreNames() const
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mSpec);
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<ObjectStoreSpec>& objectStores = mSpec->objectStores();
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DOMStringList> list = new DOMStringList();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
if (!objectStores.IsEmpty()) {
|
|
|
|
nsTArray<nsString>& listNames = list->StringArray();
|
|
|
|
listNames.SetCapacity(objectStores.Length());
|
|
|
|
|
|
|
|
for (uint32_t index = 0; index < objectStores.Length(); index++) {
|
|
|
|
listNames.InsertElementSorted(objectStores[index].metadata().name());
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
return list.forget();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<nsIDocument>
|
|
|
|
IDBDatabase::GetOwnerDocument() const
|
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowInner* window = GetOwner()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
|
|
|
|
return doc.forget();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
already_AddRefed<IDBObjectStore>
|
|
|
|
IDBDatabase::CreateObjectStore(
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsAString& aName,
|
2013-07-31 19:48:46 +04:00
|
|
|
const IDBObjectStoreParameters& aOptionalParameters,
|
|
|
|
ErrorResult& aRv)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransaction* transaction = IDBTransaction::GetCurrent();
|
2010-11-11 02:25:44 +03:00
|
|
|
if (!transaction ||
|
2015-02-07 02:25:33 +03:00
|
|
|
transaction->Database() != this ||
|
2012-03-13 08:44:45 +04:00
|
|
|
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
|
2013-07-31 19:48:46 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2010-11-11 02:25:44 +03:00
|
|
|
}
|
|
|
|
|
2015-06-20 19:09:27 +03:00
|
|
|
if (!transaction->IsOpen()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2013-05-18 05:48:25 +04:00
|
|
|
KeyPath keyPath(0);
|
2014-12-11 21:07:44 +03:00
|
|
|
if (NS_FAILED(KeyPath::Parse(aOptionalParameters.mKeyPath, &keyPath))) {
|
2013-07-31 19:48:46 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
|
|
|
|
return nullptr;
|
2010-12-21 19:02:01 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsTArray<ObjectStoreSpec>& objectStores = mSpec->objectStores();
|
|
|
|
for (uint32_t count = objectStores.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
if (aName == objectStores[index].metadata().name()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-12-04 21:39:01 +04:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
if (!keyPath.IsAllowedForObjectStore(aOptionalParameters.mAutoIncrement)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
2011-11-21 18:56:24 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const ObjectStoreSpec* oldSpecElements =
|
|
|
|
objectStores.IsEmpty() ? nullptr : objectStores.Elements();
|
|
|
|
|
|
|
|
ObjectStoreSpec* newSpec = objectStores.AppendElement();
|
|
|
|
newSpec->metadata() =
|
|
|
|
ObjectStoreMetadata(transaction->NextObjectStoreId(), nsString(aName),
|
|
|
|
keyPath, aOptionalParameters.mAutoIncrement);
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (oldSpecElements &&
|
|
|
|
oldSpecElements != objectStores.Elements()) {
|
|
|
|
MOZ_ASSERT(objectStores.Length() > 1);
|
|
|
|
|
|
|
|
// Array got moved, update the spec pointers for all live objectStores and
|
|
|
|
// indexes.
|
|
|
|
RefreshSpec(/* aMayDelete */ false);
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBObjectStore> objectStore =
|
2014-09-27 03:21:57 +04:00
|
|
|
transaction->CreateObjectStore(*newSpec);
|
|
|
|
MOZ_ASSERT(objectStore);
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
// Don't do this in the macro because we always need to increment the serial
|
|
|
|
// number to keep in sync with the parent.
|
|
|
|
const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
|
|
|
|
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).createObjectStore(%s)",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: "
|
|
|
|
"IDBDatabase.createObjectStore()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
requestSerialNumber,
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
IDB_LOG_STRINGIFY(objectStore));
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return objectStore.forget();
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::DeleteObjectStore(const nsAString& aName, ErrorResult& aRv)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransaction* transaction = IDBTransaction::GetCurrent();
|
2010-10-19 21:58:52 +04:00
|
|
|
if (!transaction ||
|
2015-02-07 02:25:33 +03:00
|
|
|
transaction->Database() != this ||
|
2012-03-13 08:44:45 +04:00
|
|
|
transaction->GetMode() != IDBTransaction::VERSION_CHANGE) {
|
2013-07-31 19:48:46 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return;
|
2010-11-11 02:25:44 +03:00
|
|
|
}
|
|
|
|
|
2015-06-20 19:09:27 +03:00
|
|
|
if (!transaction->IsOpen()) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_TRANSACTION_INACTIVE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
nsTArray<ObjectStoreSpec>& specArray = mSpec->objectStores();
|
|
|
|
|
|
|
|
int64_t objectStoreId = 0;
|
2012-06-01 21:21:12 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
for (uint32_t specCount = specArray.Length(), specIndex = 0;
|
|
|
|
specIndex < specCount;
|
|
|
|
specIndex++) {
|
|
|
|
const ObjectStoreMetadata& metadata = specArray[specIndex].metadata();
|
|
|
|
MOZ_ASSERT(metadata.id());
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (aName == metadata.name()) {
|
|
|
|
objectStoreId = metadata.id();
|
|
|
|
|
|
|
|
// Must do this before altering the metadata array!
|
|
|
|
transaction->DeleteObjectStore(objectStoreId);
|
|
|
|
|
|
|
|
specArray.RemoveElementAt(specIndex);
|
|
|
|
|
|
|
|
RefreshSpec(/* aMayDelete */ false);
|
|
|
|
break;
|
2013-07-31 19:48:46 +04:00
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!objectStoreId) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR);
|
|
|
|
return;
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
// Don't do this in the macro because we always need to increment the serial
|
|
|
|
// number to keep in sync with the parent.
|
|
|
|
const uint64_t requestSerialNumber = IDBRequest::NextSerialNumber();
|
|
|
|
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld] Request[%llu]: "
|
|
|
|
"database(%s).transaction(%s).deleteObjectStore(\"%s\")",
|
|
|
|
"IndexedDB %s: C T[%lld] R[%llu]: "
|
|
|
|
"IDBDatabase.deleteObjectStore()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
requestSerialNumber,
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(transaction),
|
|
|
|
NS_ConvertUTF16toUTF8(aName).get());
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
already_AddRefed<IDBTransaction>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBDatabase::Transaction(JSContext* aCx,
|
|
|
|
const StringOrStringSequence& aStoreNames,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransactionMode aMode,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2016-03-15 09:00:37 +03:00
|
|
|
if ((aMode == IDBTransactionMode::Readwriteflush ||
|
|
|
|
aMode == IDBTransactionMode::Cleanup) &&
|
2015-01-26 09:30:09 +03:00
|
|
|
!IndexedDatabaseManager::ExperimentalFeaturesEnabled()) {
|
|
|
|
// Pretend that this mode doesn't exist. We don't have a way to annotate
|
|
|
|
// certain enum values as depending on preferences so we just duplicate the
|
|
|
|
// normal exception generation here.
|
2016-03-23 18:02:57 +03:00
|
|
|
aRv.ThrowTypeError<MSG_INVALID_ENUM_VALUE>(
|
|
|
|
NS_LITERAL_STRING("Argument 2 of IDBDatabase.transaction"),
|
|
|
|
NS_LITERAL_STRING("readwriteflush"),
|
|
|
|
NS_LITERAL_STRING("IDBTransactionMode"));
|
2015-01-26 09:30:09 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBTransaction> transaction;
|
2016-03-23 18:02:57 +03:00
|
|
|
aRv = Transaction(aCx, aStoreNames, aMode, getter_AddRefs(transaction));
|
2015-01-26 09:30:09 +03:00
|
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
2014-09-27 03:21:57 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
return transaction.forget();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
nsresult
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBDatabase::Transaction(JSContext* aCx,
|
|
|
|
const StringOrStringSequence& aStoreNames,
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBTransactionMode aMode,
|
2015-01-26 09:30:09 +03:00
|
|
|
IDBTransaction** aTransaction)
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2016-03-15 09:00:37 +03:00
|
|
|
if (NS_WARN_IF((aMode == IDBTransactionMode::Readwriteflush ||
|
|
|
|
aMode == IDBTransactionMode::Cleanup) &&
|
2015-01-26 09:30:09 +03:00
|
|
|
!IndexedDatabaseManager::ExperimentalFeaturesEnabled())) {
|
2015-01-26 09:30:09 +03:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
2015-01-26 09:30:09 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
if (QuotaManager::IsShuttingDown()) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2015-03-29 22:55:11 +03:00
|
|
|
}
|
2011-11-03 05:03:15 +04:00
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
if (mClosed || RunningVersionChangeTransaction()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR;
|
2015-03-31 05:45:56 +03:00
|
|
|
}
|
2011-11-03 19:57:30 +04:00
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<nsString, 1> stackSequence;
|
2015-01-26 09:30:09 +03:00
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
if (aStoreNames.IsString()) {
|
|
|
|
stackSequence.AppendElement(aStoreNames.GetAsString());
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(aStoreNames.IsStringSequence());
|
|
|
|
if (aStoreNames.GetAsStringSequence().IsEmpty()) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
2015-03-31 05:45:56 +03:00
|
|
|
}
|
2015-01-26 09:30:09 +03:00
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
const nsTArray<nsString>& storeNames =
|
|
|
|
aStoreNames.IsString() ?
|
|
|
|
stackSequence :
|
|
|
|
static_cast<const nsTArray<nsString>&>(aStoreNames.GetAsStringSequence());
|
|
|
|
MOZ_ASSERT(!storeNames.IsEmpty());
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
const nsTArray<ObjectStoreSpec>& objectStores = mSpec->objectStores();
|
2015-01-26 09:30:09 +03:00
|
|
|
const uint32_t nameCount = storeNames.Length();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
nsTArray<nsString> sortedStoreNames;
|
|
|
|
sortedStoreNames.SetCapacity(nameCount);
|
|
|
|
|
|
|
|
// Check to make sure the object store names we collected actually exist.
|
|
|
|
for (uint32_t nameIndex = 0; nameIndex < nameCount; nameIndex++) {
|
2015-01-26 09:30:09 +03:00
|
|
|
const nsString& name = storeNames[nameIndex];
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
for (uint32_t objCount = objectStores.Length(), objIndex = 0;
|
|
|
|
objIndex < objCount;
|
|
|
|
objIndex++) {
|
|
|
|
if (objectStores[objIndex].metadata().name() == name) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2015-01-26 09:30:09 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR;
|
2011-11-03 19:57:30 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
sortedStoreNames.InsertElementSorted(name);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Remove any duplicates.
|
|
|
|
for (uint32_t nameIndex = nameCount - 1; nameIndex > 0; nameIndex--) {
|
|
|
|
if (sortedStoreNames[nameIndex] == sortedStoreNames[nameIndex - 1]) {
|
|
|
|
sortedStoreNames.RemoveElementAt(nameIndex);
|
|
|
|
}
|
2014-09-18 03:36:01 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
IDBTransaction::Mode mode;
|
|
|
|
switch (aMode) {
|
|
|
|
case IDBTransactionMode::Readonly:
|
|
|
|
mode = IDBTransaction::READ_ONLY;
|
|
|
|
break;
|
|
|
|
case IDBTransactionMode::Readwrite:
|
2016-04-21 07:53:30 +03:00
|
|
|
if (mQuotaExceeded) {
|
|
|
|
mode = IDBTransaction::CLEANUP;
|
|
|
|
mQuotaExceeded = false;
|
|
|
|
} else {
|
|
|
|
mode = IDBTransaction::READ_WRITE;
|
|
|
|
}
|
2015-01-26 09:30:09 +03:00
|
|
|
break;
|
|
|
|
case IDBTransactionMode::Readwriteflush:
|
|
|
|
mode = IDBTransaction::READ_WRITE_FLUSH;
|
|
|
|
break;
|
2016-03-15 09:00:37 +03:00
|
|
|
case IDBTransactionMode::Cleanup:
|
|
|
|
mode = IDBTransaction::CLEANUP;
|
2016-04-21 07:53:30 +03:00
|
|
|
mQuotaExceeded = false;
|
2016-03-15 09:00:37 +03:00
|
|
|
break;
|
2015-01-26 09:30:09 +03:00
|
|
|
case IDBTransactionMode::Versionchange:
|
2016-04-28 12:38:21 +03:00
|
|
|
return NS_ERROR_DOM_TYPE_ERR;
|
2015-01-26 09:30:09 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown mode!");
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBTransaction> transaction =
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBTransaction::Create(aCx, this, sortedStoreNames, mode);
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(!transaction)) {
|
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
2015-01-26 09:30:09 +03:00
|
|
|
return NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR;
|
2014-12-17 09:26:15 +03:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
BackgroundTransactionChild* actor =
|
|
|
|
new BackgroundTransactionChild(transaction);
|
|
|
|
|
2014-10-16 08:56:52 +04:00
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Transaction[%lld]: "
|
|
|
|
"database(%s).transaction(%s)",
|
|
|
|
"IndexedDB %s: C T[%lld]: IDBDatabase.transaction()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
transaction->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
IDB_LOG_STRINGIFY(transaction));
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ALWAYS_TRUE(
|
|
|
|
mBackgroundActor->SendPBackgroundIDBTransactionConstructor(actor,
|
|
|
|
sortedStoreNames,
|
|
|
|
mode));
|
|
|
|
|
|
|
|
transaction->SetBackgroundActor(actor);
|
|
|
|
|
2016-04-21 07:53:30 +03:00
|
|
|
if (mode == IDBTransaction::CLEANUP) {
|
2016-03-15 09:00:37 +03:00
|
|
|
ExpireFileActors(/* aExpireAll */ true);
|
|
|
|
}
|
|
|
|
|
2015-01-26 09:30:09 +03:00
|
|
|
transaction.forget(aTransaction);
|
|
|
|
return NS_OK;
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
StorageType
|
|
|
|
IDBDatabase::Storage() const
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mSpec);
|
|
|
|
|
|
|
|
return PersistenceTypeToStorage(mSpec->metadata().persistenceType());
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
already_AddRefed<IDBRequest>
|
2016-03-23 18:02:57 +03:00
|
|
|
IDBDatabase::CreateMutableFile(JSContext* aCx,
|
|
|
|
const nsAString& aName,
|
2014-06-12 07:35:29 +04:00
|
|
|
const Optional<nsAString>& aType,
|
|
|
|
ErrorResult& aRv)
|
2012-06-03 20:33:52 +04:00
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2012-11-09 01:41:23 +04:00
|
|
|
|
2013-03-26 15:13:17 +04:00
|
|
|
if (QuotaManager::IsShuttingDown()) {
|
2014-01-28 04:37:05 +04:00
|
|
|
IDB_REPORT_INTERNAL_ERR();
|
2013-07-31 19:48:46 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR);
|
|
|
|
return nullptr;
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
if (mClosed || mFileHandleDisabled) {
|
2013-07-31 19:48:46 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INDEXEDDB_NOT_ALLOWED_ERR);
|
|
|
|
return nullptr;
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsString type;
|
|
|
|
if (aType.WasPassed()) {
|
|
|
|
type = aType.Value();
|
|
|
|
}
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
CreateFileParams params(nsString(aName), type);
|
2014-10-16 08:56:52 +04:00
|
|
|
|
2016-03-23 18:02:57 +03:00
|
|
|
RefPtr<IDBRequest> request = IDBRequest::Create(aCx, this, nullptr);
|
2015-09-09 14:15:05 +03:00
|
|
|
MOZ_ASSERT(request);
|
|
|
|
|
|
|
|
BackgroundDatabaseRequestChild* actor =
|
|
|
|
new BackgroundDatabaseRequestChild(this, request);
|
|
|
|
|
|
|
|
IDB_LOG_MARK("IndexedDB %s: Child Request[%llu]: "
|
|
|
|
"database(%s).createMutableFile(%s)",
|
|
|
|
"IndexedDB %s: C R[%llu]: IDBDatabase.createMutableFile()",
|
|
|
|
IDB_LOG_ID_STRING(),
|
|
|
|
request->LoggingSerialNumber(),
|
|
|
|
IDB_LOG_STRINGIFY(this),
|
|
|
|
NS_ConvertUTF16toUTF8(aName).get());
|
|
|
|
|
|
|
|
mBackgroundActor->SendPBackgroundIDBDatabaseRequestConstructor(actor, params);
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2013-07-31 19:48:46 +04:00
|
|
|
return request.forget();
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::RegisterTransaction(IDBTransaction* aTransaction)
|
2010-10-19 21:58:52 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aTransaction);
|
|
|
|
aTransaction->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(!mTransactions.Contains(aTransaction));
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mTransactions.PutEntry(aTransaction);
|
|
|
|
}
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::UnregisterTransaction(IDBTransaction* aTransaction)
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aTransaction);
|
|
|
|
aTransaction->AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(mTransactions.Contains(aTransaction));
|
2013-07-31 19:48:46 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
mTransactions.RemoveEntry(aTransaction);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-11-14 05:20:38 +03:00
|
|
|
IDBDatabase::AbortTransactions(bool aShouldWarn)
|
2014-09-27 03:21:57 +04:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class MOZ_STACK_CLASS Helper final
|
2014-09-27 03:21:57 +04:00
|
|
|
{
|
2016-02-02 18:36:30 +03:00
|
|
|
typedef AutoTArray<RefPtr<IDBTransaction>, 20> StrongTransactionArray;
|
|
|
|
typedef AutoTArray<IDBTransaction*, 20> WeakTransactionArray;
|
2015-06-26 01:22:59 +03:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
public:
|
|
|
|
static void
|
2015-06-26 01:22:59 +03:00
|
|
|
AbortTransactions(IDBDatabase* aDatabase, const bool aShouldWarn)
|
2014-09-27 03:21:57 +04:00
|
|
|
{
|
2015-06-26 01:22:59 +03:00
|
|
|
MOZ_ASSERT(aDatabase);
|
|
|
|
aDatabase->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
nsTHashtable<nsPtrHashKey<IDBTransaction>>& transactionTable =
|
|
|
|
aDatabase->mTransactions;
|
|
|
|
|
|
|
|
if (!transactionTable.Count()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-06-26 01:22:59 +03:00
|
|
|
StrongTransactionArray transactionsToAbort;
|
|
|
|
transactionsToAbort.SetCapacity(transactionTable.Count());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-07-21 04:48:54 +03:00
|
|
|
for (auto iter = transactionTable.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
IDBTransaction* transaction = iter.Get()->GetKey();
|
|
|
|
MOZ_ASSERT(transaction);
|
|
|
|
|
|
|
|
transaction->AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
// Transactions that are already done can simply be ignored. Otherwise
|
|
|
|
// there is a race here and it's possible that the transaction has not
|
|
|
|
// been successfully committed yet so we will warn the user.
|
|
|
|
if (!transaction->IsDone()) {
|
|
|
|
transactionsToAbort.AppendElement(transaction);
|
|
|
|
}
|
|
|
|
}
|
2015-06-26 01:22:59 +03:00
|
|
|
MOZ_ASSERT(transactionsToAbort.Length() <= transactionTable.Count());
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-06-26 01:22:59 +03:00
|
|
|
if (transactionsToAbort.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We want to abort transactions as soon as possible so we iterate the
|
|
|
|
// transactions once and abort them all first, collecting the transactions
|
|
|
|
// that need to have a warning issued along the way. Those that need a
|
|
|
|
// warning will be a subset of those that are aborted, so we don't need
|
|
|
|
// additional strong references here.
|
|
|
|
WeakTransactionArray transactionsThatNeedWarning;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
for (RefPtr<IDBTransaction>& transaction : transactionsToAbort) {
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(transaction);
|
2015-06-26 01:22:59 +03:00
|
|
|
MOZ_ASSERT(!transaction->IsDone());
|
|
|
|
|
|
|
|
if (aShouldWarn) {
|
|
|
|
switch (transaction->GetMode()) {
|
|
|
|
// We ignore transactions that could not have written any data.
|
|
|
|
case IDBTransaction::READ_ONLY:
|
|
|
|
break;
|
|
|
|
|
|
|
|
// We warn for any transactions that could have written data.
|
|
|
|
case IDBTransaction::READ_WRITE:
|
|
|
|
case IDBTransaction::READ_WRITE_FLUSH:
|
2016-03-15 09:00:37 +03:00
|
|
|
case IDBTransaction::CLEANUP:
|
2015-06-26 01:22:59 +03:00
|
|
|
case IDBTransaction::VERSION_CHANGE:
|
|
|
|
transactionsThatNeedWarning.AppendElement(transaction);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown mode!");
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2016-05-31 13:08:20 +03:00
|
|
|
transaction->Abort(NS_ERROR_DOM_INDEXEDDB_ABORT_ERR);
|
2015-06-26 01:22:59 +03:00
|
|
|
}
|
2014-11-14 05:20:38 +03:00
|
|
|
|
2015-06-26 01:22:59 +03:00
|
|
|
static const char kWarningMessage[] =
|
|
|
|
"IndexedDBTransactionAbortNavigation";
|
|
|
|
|
|
|
|
for (IDBTransaction* transaction : transactionsThatNeedWarning) {
|
|
|
|
MOZ_ASSERT(transaction);
|
|
|
|
|
|
|
|
nsString filename;
|
2015-09-02 04:01:02 +03:00
|
|
|
uint32_t lineNo, column;
|
|
|
|
transaction->GetCallerLocation(filename, &lineNo, &column);
|
2015-06-26 01:22:59 +03:00
|
|
|
|
2015-09-02 04:01:02 +03:00
|
|
|
aDatabase->LogWarning(kWarningMessage, filename, lineNo, column);
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-26 01:22:59 +03:00
|
|
|
Helper::AbortTransactions(this, aShouldWarn);
|
2010-10-19 21:58:52 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
PBackgroundIDBDatabaseFileChild*
|
2015-05-12 15:09:51 +03:00
|
|
|
IDBDatabase::GetOrCreateFileActorForBlob(Blob* aBlob)
|
2012-12-17 23:25:10 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBlob);
|
|
|
|
MOZ_ASSERT(mBackgroundActor);
|
|
|
|
|
2014-10-08 20:15:23 +04:00
|
|
|
// We use the File's nsIWeakReference as the key to the table because
|
2014-09-27 03:21:57 +04:00
|
|
|
// a) it is unique per blob, b) it is reference-counted so that we can
|
2014-10-08 20:15:23 +04:00
|
|
|
// guarantee that it stays alive, and c) it doesn't hold the actual File
|
2014-09-27 03:21:57 +04:00
|
|
|
// alive.
|
2014-10-08 20:15:22 +04:00
|
|
|
nsCOMPtr<nsIDOMBlob> blob = aBlob;
|
|
|
|
nsCOMPtr<nsIWeakReference> weakRef = do_GetWeakReference(blob);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(weakRef);
|
|
|
|
|
|
|
|
PBackgroundIDBDatabaseFileChild* actor = nullptr;
|
|
|
|
|
|
|
|
if (!mFileActors.Get(weakRef, &actor)) {
|
2015-05-12 15:11:03 +03:00
|
|
|
BlobImpl* blobImpl = aBlob->Impl();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(blobImpl);
|
|
|
|
|
|
|
|
if (mReceivedBlobs.GetEntry(weakRef)) {
|
|
|
|
// This blob was previously retrieved from the database.
|
|
|
|
nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryObject(blobImpl);
|
|
|
|
MOZ_ASSERT(remoteBlob);
|
|
|
|
|
|
|
|
BlobChild* blobChild = remoteBlob->GetBlobChild();
|
|
|
|
MOZ_ASSERT(blobChild);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
PBackgroundChild* backgroundManager = blobChild->GetBackgroundManager();
|
|
|
|
MOZ_ASSERT(backgroundManager);
|
|
|
|
|
|
|
|
PBackgroundChild* thisManager = mBackgroundActor->Manager()->Manager();
|
|
|
|
MOZ_ASSERT(thisManager);
|
|
|
|
|
|
|
|
MOZ_ASSERT(thisManager == backgroundManager);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
auto* dbFile = new DatabaseFile(this);
|
|
|
|
|
|
|
|
actor =
|
|
|
|
mBackgroundActor->SendPBackgroundIDBDatabaseFileConstructor(dbFile,
|
|
|
|
blobChild);
|
|
|
|
if (NS_WARN_IF(!actor)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Make sure that the input stream we get here is one that can actually be
|
|
|
|
// serialized to PBackground.
|
|
|
|
PBackgroundChild* backgroundManager =
|
|
|
|
mBackgroundActor->Manager()->Manager();
|
|
|
|
MOZ_ASSERT(backgroundManager);
|
|
|
|
|
|
|
|
auto* blobChild =
|
|
|
|
static_cast<BlobChild*>(
|
|
|
|
BackgroundChild::GetOrCreateActorForBlob(backgroundManager, aBlob));
|
|
|
|
MOZ_ASSERT(blobChild);
|
|
|
|
|
|
|
|
auto* dbFile = new DatabaseFile(this);
|
|
|
|
|
|
|
|
actor =
|
|
|
|
mBackgroundActor->SendPBackgroundIDBDatabaseFileConstructor(dbFile,
|
|
|
|
blobChild);
|
|
|
|
if (NS_WARN_IF(!actor)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(actor);
|
|
|
|
|
|
|
|
mFileActors.Put(weakRef, actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(actor);
|
|
|
|
|
|
|
|
return actor;
|
2012-12-17 23:25:10 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::NoteFinishedFileActor(PBackgroundIDBDatabaseFileChild* aFileActor)
|
2013-03-26 15:13:17 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aFileActor);
|
|
|
|
|
2015-11-25 03:54:27 +03:00
|
|
|
for (auto iter = mFileActors.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
MOZ_ASSERT(iter.Key());
|
|
|
|
PBackgroundIDBDatabaseFileChild* actor = iter.Data();
|
|
|
|
MOZ_ASSERT(actor);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-11-25 03:54:27 +03:00
|
|
|
if (actor == aFileActor) {
|
|
|
|
iter.Remove();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2015-11-25 03:54:27 +03:00
|
|
|
}
|
2013-03-26 15:13:17 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
2015-05-12 15:09:51 +03:00
|
|
|
IDBDatabase::NoteReceivedBlob(Blob* aBlob)
|
2013-03-26 15:13:17 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aBlob);
|
|
|
|
MOZ_ASSERT(mBackgroundActor);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BlobImpl> blobImpl = aBlob->Impl();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(blobImpl);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryObject(blobImpl);
|
|
|
|
MOZ_ASSERT(remoteBlob);
|
|
|
|
|
|
|
|
BlobChild* blobChild = remoteBlob->GetBlobChild();
|
|
|
|
MOZ_ASSERT(blobChild);
|
|
|
|
|
|
|
|
PBackgroundChild* backgroundManager = blobChild->GetBackgroundManager();
|
|
|
|
MOZ_ASSERT(backgroundManager);
|
|
|
|
|
|
|
|
PBackgroundChild* thisManager = mBackgroundActor->Manager()->Manager();
|
|
|
|
MOZ_ASSERT(thisManager);
|
|
|
|
|
|
|
|
MOZ_ASSERT(thisManager == backgroundManager);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-08 20:15:22 +04:00
|
|
|
nsCOMPtr<nsIDOMBlob> blob = aBlob;
|
|
|
|
nsCOMPtr<nsIWeakReference> weakRef = do_GetWeakReference(blob);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(weakRef);
|
|
|
|
|
|
|
|
// It's ok if this entry already exists in the table.
|
|
|
|
mReceivedBlobs.PutEntry(weakRef);
|
2013-03-26 15:13:17 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::DelayedMaybeExpireFileActors()
|
2013-03-26 15:13:17 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
|
|
|
if (!mBackgroundActor || !mFileActors.Count()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2016-05-05 11:45:00 +03:00
|
|
|
NewRunnableMethod<bool>(this,
|
|
|
|
&IDBDatabase::ExpireFileActors,
|
|
|
|
/* aExpireAll */ false);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(runnable);
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
// Wrap as a nsICancelableRunnable to make workers happy.
|
|
|
|
nsCOMPtr<nsIRunnable> cancelable = new CancelableRunnableWrapper(runnable);
|
|
|
|
cancelable.swap(runnable);
|
|
|
|
}
|
|
|
|
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(NS_DispatchToCurrentThread(runnable));
|
2013-03-26 15:13:17 +04:00
|
|
|
}
|
|
|
|
|
2010-11-11 02:26:03 +03:00
|
|
|
nsresult
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase::GetQuotaInfo(nsACString& aOrigin,
|
|
|
|
PersistenceType* aPersistenceType)
|
2010-11-11 02:26:03 +03:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
using mozilla::dom::quota::QuotaManager;
|
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread(), "This can't work off the main thread!");
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
if (aPersistenceType) {
|
2014-11-28 11:44:12 +03:00
|
|
|
*aPersistenceType = mSpec->metadata().persistenceType();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(*aPersistenceType != PERSISTENCE_TYPE_INVALID);
|
|
|
|
}
|
|
|
|
|
|
|
|
PrincipalInfo* principalInfo = mFactory->GetPrincipalInfo();
|
|
|
|
MOZ_ASSERT(principalInfo);
|
|
|
|
|
|
|
|
switch (principalInfo->type()) {
|
|
|
|
case PrincipalInfo::TNullPrincipalInfo:
|
|
|
|
MOZ_CRASH("Is this needed?!");
|
|
|
|
|
|
|
|
case PrincipalInfo::TSystemPrincipalInfo:
|
2016-06-05 22:42:25 +03:00
|
|
|
QuotaManager::GetInfoForChrome(nullptr, nullptr, &aOrigin, nullptr);
|
2014-09-27 03:21:57 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case PrincipalInfo::TContentPrincipalInfo: {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIPrincipal> principal =
|
|
|
|
PrincipalInfoToPrincipal(*principalInfo, &rv);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = QuotaManager::GetInfoFromPrincipal(principal,
|
2016-06-05 22:42:25 +03:00
|
|
|
nullptr,
|
2014-09-27 03:21:57 +04:00
|
|
|
nullptr,
|
|
|
|
&aOrigin,
|
|
|
|
nullptr);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unknown PrincipalInfo type!");
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Should never get here!");
|
2010-11-11 02:26:03 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::ExpireFileActors(bool aExpireAll)
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
|
|
|
|
2015-11-25 03:54:27 +03:00
|
|
|
if (mBackgroundActor && mFileActors.Count()) {
|
|
|
|
for (auto iter = mFileActors.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsISupports* key = iter.Key();
|
|
|
|
PBackgroundIDBDatabaseFileChild* actor = iter.Data();
|
|
|
|
MOZ_ASSERT(key);
|
|
|
|
MOZ_ASSERT(actor);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-11-25 03:54:27 +03:00
|
|
|
bool shouldExpire = aExpireAll;
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!shouldExpire) {
|
2015-11-25 03:54:27 +03:00
|
|
|
nsCOMPtr<nsIWeakReference> weakRef = do_QueryInterface(key);
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(weakRef);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> referent = do_QueryReferent(weakRef);
|
|
|
|
shouldExpire = !referent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldExpire) {
|
2015-11-25 03:54:27 +03:00
|
|
|
PBackgroundIDBDatabaseFileChild::Send__delete__(actor);
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-11-25 03:54:27 +03:00
|
|
|
if (!aExpireAll) {
|
|
|
|
iter.Remove();
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (aExpireAll) {
|
|
|
|
mFileActors.Clear();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(!mFileActors.Count());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mReceivedBlobs.Count()) {
|
|
|
|
if (aExpireAll) {
|
|
|
|
mReceivedBlobs.Clear();
|
|
|
|
} else {
|
2015-07-21 04:48:54 +03:00
|
|
|
for (auto iter = mReceivedBlobs.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsISupports* key = iter.Get()->GetKey();
|
|
|
|
MOZ_ASSERT(key);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWeakReference> weakRef = do_QueryInterface(key);
|
|
|
|
MOZ_ASSERT(weakRef);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> referent = do_QueryReferent(weakRef);
|
|
|
|
if (!referent) {
|
|
|
|
iter.Remove();
|
|
|
|
}
|
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::NoteLiveMutableFile(IDBMutableFile* aMutableFile)
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aMutableFile);
|
2015-09-09 14:15:05 +03:00
|
|
|
aMutableFile->AssertIsOnOwningThread();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(!mLiveMutableFiles.Contains(aMutableFile));
|
|
|
|
|
|
|
|
mLiveMutableFiles.AppendElement(aMutableFile);
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::NoteFinishedMutableFile(IDBMutableFile* aMutableFile)
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(aMutableFile);
|
2015-09-09 14:15:05 +03:00
|
|
|
aMutableFile->AssertIsOnOwningThread();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
// It's ok if this is called after we cleared the array, so don't assert that
|
|
|
|
// aMutableFile is in the list.
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
mLiveMutableFiles.RemoveElement(aMutableFile);
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-09-27 03:21:57 +04:00
|
|
|
IDBDatabase::InvalidateMutableFiles()
|
2012-06-01 21:21:12 +04:00
|
|
|
{
|
2015-09-09 14:15:05 +03:00
|
|
|
AssertIsOnOwningThread();
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2015-09-09 14:15:05 +03:00
|
|
|
if (!mLiveMutableFiles.IsEmpty()) {
|
2014-09-27 03:21:57 +04:00
|
|
|
for (uint32_t count = mLiveMutableFiles.Length(), index = 0;
|
|
|
|
index < count;
|
|
|
|
index++) {
|
|
|
|
mLiveMutableFiles[index]->Invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
mLiveMutableFiles.Clear();
|
|
|
|
}
|
2012-06-01 21:21:12 +04:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::Invalidate()
|
2010-06-23 23:46:08 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
AssertIsOnOwningThread();
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!mInvalidated) {
|
|
|
|
mInvalidated = true;
|
2013-03-16 10:58:50 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
InvalidateInternal();
|
2013-05-11 01:22:01 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
|
|
|
|
2014-11-14 05:20:38 +03:00
|
|
|
void
|
|
|
|
IDBDatabase::LogWarning(const char* aMessageName,
|
|
|
|
const nsAString& aFilename,
|
2015-09-02 04:01:02 +03:00
|
|
|
uint32_t aLineNumber,
|
|
|
|
uint32_t aColumnNumber)
|
2014-11-14 05:20:38 +03:00
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
|
|
|
MOZ_ASSERT(aMessageName);
|
|
|
|
|
2016-03-16 10:12:17 +03:00
|
|
|
ScriptErrorHelper::DumpLocalizedMessage(nsDependentCString(aMessageName),
|
|
|
|
aFilename,
|
|
|
|
aLineNumber,
|
|
|
|
aColumnNumber,
|
|
|
|
nsIScriptError::warningFlag,
|
|
|
|
mFactory->IsChrome(),
|
|
|
|
mFactory->InnerWindowID());
|
2014-11-14 05:20:38 +03:00
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(IDBDatabase, IDBWrapperCache)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(IDBDatabase, IDBWrapperCache)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(IDBDatabase)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(IDBWrapperCache)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(IDBDatabase)
|
2013-05-11 01:22:01 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
|
|
|
|
tmp->AssertIsOnOwningThread();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFactory)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(IDBDatabase, IDBWrapperCache)
|
|
|
|
tmp->AssertIsOnOwningThread();
|
2010-10-19 21:58:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// Don't unlink mFactory!
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
// We've been unlinked, at the very least we should be able to prevent further
|
|
|
|
// transactions from starting and unblock any other SetVersion callers.
|
|
|
|
tmp->CloseInternal();
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
void
|
|
|
|
IDBDatabase::LastRelease()
|
|
|
|
{
|
|
|
|
AssertIsOnOwningThread();
|
2014-09-13 20:12:19 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
CloseInternal();
|
|
|
|
|
|
|
|
if (mBackgroundActor) {
|
|
|
|
mBackgroundActor->SendDeleteMeInternal();
|
|
|
|
MOZ_ASSERT(!mBackgroundActor, "SendDeleteMeInternal should have cleared!");
|
2011-12-20 14:59:07 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2011-12-20 14:59:07 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
nsresult
|
|
|
|
IDBDatabase::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
|
|
|
{
|
2014-12-17 09:26:15 +03:00
|
|
|
nsresult rv =
|
2015-03-20 07:42:37 +03:00
|
|
|
IndexedDatabaseManager::CommonPostHandleEvent(aVisitor, mFactory);
|
2014-12-17 09:26:15 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2014-09-27 03:21:57 +04:00
|
|
|
}
|
2010-06-23 23:46:08 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
IDBDatabase::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2014-09-27 03:21:57 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return IDBDatabaseBinding::Wrap(aCx, this, aGivenProto);
|
2010-06-23 23:46:08 +04:00
|
|
|
}
|
|
|
|
|
2014-12-17 09:26:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CancelableRunnableWrapper::Run()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRunnable> runnable;
|
|
|
|
mRunnable.swap(runnable);
|
|
|
|
|
|
|
|
if (runnable) {
|
|
|
|
return runnable->Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-11 21:40:06 +03:00
|
|
|
nsresult
|
2014-12-17 09:26:15 +03:00
|
|
|
CancelableRunnableWrapper::Cancel()
|
|
|
|
{
|
|
|
|
if (mRunnable) {
|
|
|
|
mRunnable = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
NS_IMPL_ISUPPORTS(IDBDatabase::Observer, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
IDBDatabase::
|
|
|
|
Observer::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const char16_t* aData)
|
2012-06-03 20:33:52 +04:00
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aTopic);
|
2012-06-03 20:33:52 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
if (!strcmp(aTopic, kWindowObserverTopic)) {
|
|
|
|
if (mWeakDatabase) {
|
|
|
|
nsCOMPtr<nsISupportsPRUint64> supportsInt = do_QueryInterface(aSubject);
|
|
|
|
MOZ_ASSERT(supportsInt);
|
|
|
|
|
|
|
|
uint64_t windowId;
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(supportsInt->GetData(&windowId));
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
if (windowId == mWindowId) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBDatabase> database = mWeakDatabase;
|
2014-09-27 03:21:57 +04:00
|
|
|
mWeakDatabase = nullptr;
|
|
|
|
|
|
|
|
database->InvalidateInternal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, kCycleCollectionObserverTopic) ||
|
|
|
|
!strcmp(aTopic, kMemoryPressureObserverTopic)) {
|
|
|
|
if (mWeakDatabase) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IDBDatabase> database = mWeakDatabase;
|
2014-09-27 03:21:57 +04:00
|
|
|
|
|
|
|
database->ExpireFileActors(/* aExpireAll */ false);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_WARNING("Unknown observer topic!");
|
|
|
|
return NS_OK;
|
2012-06-03 20:33:52 +04:00
|
|
|
}
|
2014-09-27 03:21:57 +04:00
|
|
|
|
2016-03-30 06:04:56 +03:00
|
|
|
nsresult
|
|
|
|
IDBDatabase::RenameObjectStore(int64_t aObjectStoreId, const nsAString& aName)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mSpec);
|
|
|
|
|
|
|
|
nsTArray<ObjectStoreSpec>& objectStores = mSpec->objectStores();
|
|
|
|
|
|
|
|
ObjectStoreSpec* foundObjectStoreSpec = nullptr;
|
|
|
|
// Find the matched object store spec and check if 'aName' is already used by
|
|
|
|
// another object store.
|
|
|
|
for (uint32_t objCount = objectStores.Length(), objIndex = 0;
|
|
|
|
objIndex < objCount;
|
|
|
|
objIndex++) {
|
|
|
|
const ObjectStoreSpec& objSpec = objectStores[objIndex];
|
|
|
|
if (objSpec.metadata().id() == aObjectStoreId) {
|
|
|
|
MOZ_ASSERT(!foundObjectStoreSpec);
|
|
|
|
foundObjectStoreSpec = &objectStores[objIndex];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (aName == objSpec.metadata().name()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(foundObjectStoreSpec);
|
|
|
|
|
|
|
|
// Update the name of the matched object store.
|
|
|
|
foundObjectStoreSpec->metadata().name() = nsString(aName);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
IDBDatabase::RenameIndex(int64_t aObjectStoreId,
|
|
|
|
int64_t aIndexId,
|
|
|
|
const nsAString& aName)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mSpec);
|
|
|
|
|
|
|
|
nsTArray<ObjectStoreSpec>& objectStores = mSpec->objectStores();
|
|
|
|
|
|
|
|
ObjectStoreSpec* foundObjectStoreSpec = nullptr;
|
|
|
|
// Find the matched index metadata and check if 'aName' is already used by
|
|
|
|
// another index.
|
|
|
|
for (uint32_t objCount = objectStores.Length(), objIndex = 0;
|
|
|
|
objIndex < objCount;
|
|
|
|
objIndex++) {
|
|
|
|
const ObjectStoreSpec& objSpec = objectStores[objIndex];
|
|
|
|
if (objSpec.metadata().id() == aObjectStoreId) {
|
|
|
|
foundObjectStoreSpec = &objectStores[objIndex];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(foundObjectStoreSpec);
|
|
|
|
|
|
|
|
nsTArray<IndexMetadata>& indexes = foundObjectStoreSpec->indexes();
|
|
|
|
IndexMetadata* foundIndexMetadata = nullptr;
|
|
|
|
for (uint32_t idxCount = indexes.Length(), idxIndex = 0;
|
|
|
|
idxIndex < idxCount;
|
|
|
|
idxIndex++) {
|
|
|
|
const IndexMetadata& metadata = indexes[idxIndex];
|
|
|
|
if (metadata.id() == aIndexId) {
|
|
|
|
MOZ_ASSERT(!foundIndexMetadata);
|
|
|
|
foundIndexMetadata = &indexes[idxIndex];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (aName == metadata.name()) {
|
|
|
|
return NS_ERROR_DOM_INDEXEDDB_CONSTRAINT_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(foundIndexMetadata);
|
|
|
|
|
|
|
|
// Update the name of the matched object store.
|
|
|
|
foundIndexMetadata->name() = nsString(aName);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|