Commit 77a081cf authored by beidson@apple.com's avatar beidson@apple.com
Browse files

IndexedDB IDL Refactoring.

https://bugs.webkit.org/show_bug.cgi?id=121996

Reviewed by Alexey Proskuryakov.

This includes:
1 - Leveraging EventTarget.idl inheritance
2 - Removing comments
3 - Reordering to match the spec's IDLs
4 - Removing nonstandard, WebKit-specific methods
5 - Updating interfaces to match the spec (versions are only uint64_t's now...)
6 - Updating implementation code as needed (versions are only uint64_t's now...)

IDL changes:
* Modules/indexeddb/IDBCursor.idl:
* Modules/indexeddb/IDBDatabase.idl:
* Modules/indexeddb/IDBFactory.idl:
* Modules/indexeddb/IDBIndex.idl:
* Modules/indexeddb/IDBKeyRange.idl:
* Modules/indexeddb/IDBObjectStore.idl:
* Modules/indexeddb/IDBRequest.idl:
* Modules/indexeddb/IDBTransaction.idl:
* Modules/indexeddb/IDBVersionChangeEvent.idl:

* Modules/indexeddb/IndexedDB.h: Add new enum to represent version nullness.

Adapt to new IDLs, and also refactor representation of initial, null versioning:
* Modules/indexeddb/IDBCallbacks.h:
(WebCore::IDBCallbacks::onBlocked):
(WebCore::IDBCallbacks::onUpgradeNeeded):

* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::version):
(WebCore::IDBDatabase::onVersionChange):
* Modules/indexeddb/IDBDatabase.h:

* Modules/indexeddb/IDBDatabaseCallbacks.h:
* Modules/indexeddb/IDBDatabaseCallbacksImpl.cpp:
(WebCore::IDBDatabaseCallbacksImpl::onVersionChange):
* Modules/indexeddb/IDBDatabaseCallbacksImpl.h:

* Modules/indexeddb/IDBFactory.cpp:
(WebCore::IDBFactory::open):
(WebCore::IDBFactory::openInternal):
(WebCore::IDBFactory::deleteDatabase):
* Modules/indexeddb/IDBFactory.h:

* Modules/indexeddb/IDBMetadata.h:
(WebCore::IDBDatabaseMetadata::IDBDatabaseMetadata):

* Modules/indexeddb/IDBOpenDBRequest.cpp:
(WebCore::IDBOpenDBRequest::create):
(WebCore::IDBOpenDBRequest::IDBOpenDBRequest):
(WebCore::IDBOpenDBRequest::onBlocked):
(WebCore::IDBOpenDBRequest::onUpgradeNeeded):
* Modules/indexeddb/IDBOpenDBRequest.h:

* Modules/indexeddb/IDBRequest.cpp:
* Modules/indexeddb/IDBRequest.h:

* Modules/indexeddb/IDBTransaction.cpp:
* Modules/indexeddb/IDBTransaction.h:

* Modules/indexeddb/IDBVersionChangeEvent.cpp:
(WebCore::IDBVersionChangeEvent::IDBVersionChangeEvent):
* Modules/indexeddb/IDBVersionChangeEvent.h:
(WebCore::IDBVersionChangeEvent::create):
(WebCore::IDBVersionChangeEvent::oldVersion):
(WebCore::IDBVersionChangeEvent::newVersion):

Keep leveldb building with minimal adaptations to the new IDLs,
but note that the LevelDB implementation is now incompatible with the spec:
* Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.cpp:
(WebCore::IDBBackingStore::getIDBDatabaseMetaData):
(WebCore::objectStoreCursorOptions):
(WebCore::indexCursorOptions):

* Modules/indexeddb/leveldb/IDBDatabaseBackendLevelDB.cpp:
(WebCore::IDBDatabaseBackendLevelDB::IDBDatabaseBackendLevelDB):
(WebCore::IDBDatabaseBackendLevelDB::openInternal):
(WebCore::IDBDatabaseBackendLevelDB::VersionChangeOperation::perform):
(WebCore::IDBDatabaseBackendLevelDB::processPendingCalls):
(WebCore::IDBDatabaseBackendLevelDB::openConnection):
(WebCore::IDBDatabaseBackendLevelDB::runIntVersionChangeTransaction):
(WebCore::IDBDatabaseBackendLevelDB::deleteDatabase):
(WebCore::IDBDatabaseBackendLevelDB::deleteDatabaseFinal):
(WebCore::IDBDatabaseBackendLevelDB::VersionChangeAbortOperation::perform):

* Modules/indexeddb/leveldb/IDBLevelDBCoding.cpp:
(WebCore::IDBLevelDBCoding::compareEncodedIDBKeys):

* inspector/InspectorIndexedDBAgent.cpp: Update for metadata change.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@156590 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4e3438e4
2013-09-27 Brady Eidson <beidson@apple.com>
IndexedDB IDL Refactoring.
https://bugs.webkit.org/show_bug.cgi?id=121996
Reviewed by Alexey Proskuryakov.
This includes:
1 - Leveraging EventTarget.idl inheritance
2 - Removing comments
3 - Reordering to match the spec's IDLs
4 - Removing nonstandard, WebKit-specific methods
5 - Updating interfaces to match the spec (versions are only uint64_t's now...)
6 - Updating implementation code as needed (versions are only uint64_t's now...)
IDL changes:
* Modules/indexeddb/IDBCursor.idl:
* Modules/indexeddb/IDBDatabase.idl:
* Modules/indexeddb/IDBFactory.idl:
* Modules/indexeddb/IDBIndex.idl:
* Modules/indexeddb/IDBKeyRange.idl:
* Modules/indexeddb/IDBObjectStore.idl:
* Modules/indexeddb/IDBRequest.idl:
* Modules/indexeddb/IDBTransaction.idl:
* Modules/indexeddb/IDBVersionChangeEvent.idl:
* Modules/indexeddb/IndexedDB.h: Add new enum to represent version nullness.
Adapt to new IDLs, and also refactor representation of initial, null versioning:
* Modules/indexeddb/IDBCallbacks.h:
(WebCore::IDBCallbacks::onBlocked):
(WebCore::IDBCallbacks::onUpgradeNeeded):
* Modules/indexeddb/IDBDatabase.cpp:
(WebCore::IDBDatabase::version):
(WebCore::IDBDatabase::onVersionChange):
* Modules/indexeddb/IDBDatabase.h:
* Modules/indexeddb/IDBDatabaseCallbacks.h:
* Modules/indexeddb/IDBDatabaseCallbacksImpl.cpp:
(WebCore::IDBDatabaseCallbacksImpl::onVersionChange):
* Modules/indexeddb/IDBDatabaseCallbacksImpl.h:
* Modules/indexeddb/IDBFactory.cpp:
(WebCore::IDBFactory::open):
(WebCore::IDBFactory::openInternal):
(WebCore::IDBFactory::deleteDatabase):
* Modules/indexeddb/IDBFactory.h:
* Modules/indexeddb/IDBMetadata.h:
(WebCore::IDBDatabaseMetadata::IDBDatabaseMetadata):
* Modules/indexeddb/IDBOpenDBRequest.cpp:
(WebCore::IDBOpenDBRequest::create):
(WebCore::IDBOpenDBRequest::IDBOpenDBRequest):
(WebCore::IDBOpenDBRequest::onBlocked):
(WebCore::IDBOpenDBRequest::onUpgradeNeeded):
* Modules/indexeddb/IDBOpenDBRequest.h:
* Modules/indexeddb/IDBRequest.cpp:
* Modules/indexeddb/IDBRequest.h:
* Modules/indexeddb/IDBTransaction.cpp:
* Modules/indexeddb/IDBTransaction.h:
* Modules/indexeddb/IDBVersionChangeEvent.cpp:
(WebCore::IDBVersionChangeEvent::IDBVersionChangeEvent):
* Modules/indexeddb/IDBVersionChangeEvent.h:
(WebCore::IDBVersionChangeEvent::create):
(WebCore::IDBVersionChangeEvent::oldVersion):
(WebCore::IDBVersionChangeEvent::newVersion):
Keep leveldb building with minimal adaptations to the new IDLs,
but note that the LevelDB implementation is now incompatible with the spec:
* Modules/indexeddb/leveldb/IDBBackingStoreLevelDB.cpp:
(WebCore::IDBBackingStore::getIDBDatabaseMetaData):
(WebCore::objectStoreCursorOptions):
(WebCore::indexCursorOptions):
* Modules/indexeddb/leveldb/IDBDatabaseBackendLevelDB.cpp:
(WebCore::IDBDatabaseBackendLevelDB::IDBDatabaseBackendLevelDB):
(WebCore::IDBDatabaseBackendLevelDB::openInternal):
(WebCore::IDBDatabaseBackendLevelDB::VersionChangeOperation::perform):
(WebCore::IDBDatabaseBackendLevelDB::processPendingCalls):
(WebCore::IDBDatabaseBackendLevelDB::openConnection):
(WebCore::IDBDatabaseBackendLevelDB::runIntVersionChangeTransaction):
(WebCore::IDBDatabaseBackendLevelDB::deleteDatabase):
(WebCore::IDBDatabaseBackendLevelDB::deleteDatabaseFinal):
(WebCore::IDBDatabaseBackendLevelDB::VersionChangeAbortOperation::perform):
* Modules/indexeddb/leveldb/IDBLevelDBCoding.cpp:
(WebCore::IDBLevelDBCoding::compareEncodedIDBKeys):
* inspector/InspectorIndexedDBAgent.cpp: Update for metadata change.
2013-09-27 Enrica Casucci <enrica@apple.com>
 
Upstream changes to Pasteboard implementation for iOS.
......@@ -68,9 +68,9 @@ public:
// From IDBCursor.advance()/continue()
virtual void onSuccessWithPrefetch(const Vector<RefPtr<IDBKey> >& keys, const Vector<RefPtr<IDBKey> >& primaryKeys, const Vector<RefPtr<SharedBuffer> >& values) = 0;
// From IDBFactory.open()/deleteDatabase()
virtual void onBlocked(int64_t /* existingVersion */) { ASSERT_NOT_REACHED(); }
virtual void onBlocked(uint64_t /* existingVersion */) { ASSERT_NOT_REACHED(); }
// From IDBFactory.open()
virtual void onUpgradeNeeded(int64_t /* oldVersion */, PassRefPtr<IDBDatabaseBackendInterface>, const IDBDatabaseMetadata&) { ASSERT_NOT_REACHED(); }
virtual void onUpgradeNeeded(uint64_t /* oldVersion */, PassRefPtr<IDBDatabaseBackendInterface>, const IDBDatabaseMetadata&) { ASSERT_NOT_REACHED(); }
virtual void onSuccess(PassRefPtr<IDBDatabaseBackendInterface>, const IDBDatabaseMetadata&) { ASSERT_NOT_REACHED(); }
};
......
......@@ -27,11 +27,10 @@
Conditional=INDEXED_DATABASE,
JSNoStaticTables
] interface IDBCursor {
readonly attribute IDBAny source;
readonly attribute DOMString direction;
readonly attribute any key;
readonly attribute any primaryKey;
readonly attribute IDBAny source;
[CallWith=ScriptState, RaisesException] IDBRequest update(any value);
[RaisesException] void advance([EnforceRange] unsigned long count);
......
......@@ -131,12 +131,9 @@ PassRefPtr<DOMStringList> IDBDatabase::objectStoreNames() const
return objectStoreNames.release();
}
PassRefPtr<IDBAny> IDBDatabase::version() const
uint64_t IDBDatabase::version() const
{
int64_t intVersion = m_metadata.intVersion;
if (intVersion == IDBDatabaseMetadata::NoIntVersion)
return IDBAny::createString(m_metadata.version);
return IDBAny::create(intVersion);
return m_metadata.version;
}
PassRefPtr<IDBObjectStore> IDBDatabase::createObjectStore(const String& name, const Dictionary& options, ExceptionCode& ec)
......@@ -303,7 +300,7 @@ void IDBDatabase::closeConnection()
}
}
void IDBDatabase::onVersionChange(int64_t oldVersion, int64_t newVersion)
void IDBDatabase::onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness)
{
IDB_TRACE("IDBDatabase::onVersionChange");
if (m_contextStopped || !scriptExecutionContext())
......@@ -312,8 +309,7 @@ void IDBDatabase::onVersionChange(int64_t oldVersion, int64_t newVersion)
if (m_closePending)
return;
RefPtr<IDBAny> newVersionAny = newVersion == IDBDatabaseMetadata::NoIntVersion ? IDBAny::createNull() : IDBAny::create(newVersion);
enqueueEvent(IDBVersionChangeEvent::create(IDBAny::create(oldVersion), newVersionAny.release(), eventNames().versionchangeEvent));
enqueueEvent(IDBVersionChangeEvent::create(oldVersion, newVersion, newVersionNullness));
}
void IDBDatabase::enqueueEvent(PassRefPtr<Event> event)
......
......@@ -60,7 +60,7 @@ public:
// Implement the IDL
const String name() const { return m_metadata.name; }
PassRefPtr<IDBAny> version() const;
uint64_t version() const;
PassRefPtr<DOMStringList> objectStoreNames() const;
PassRefPtr<IDBObjectStore> createObjectStore(const String& name, const Dictionary&, ExceptionCode&);
......@@ -76,7 +76,7 @@ public:
DEFINE_ATTRIBUTE_EVENT_LISTENER(versionchange);
// IDBDatabaseCallbacks
virtual void onVersionChange(int64_t oldVersion, int64_t newVersion);
virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness);
virtual void onAbort(int64_t, PassRefPtr<IDBDatabaseError>);
virtual void onComplete(int64_t);
......
......@@ -29,30 +29,20 @@
ActiveDOMObject,
EventTarget,
JSNoStaticTables
] interface IDBDatabase {
] interface IDBDatabase : EventTarget {
readonly attribute DOMString name;
readonly attribute IDBAny version;
readonly attribute unsigned long long version;
readonly attribute DOMStringList objectStoreNames;
attribute EventListener onabort;
attribute EventListener onerror;
attribute EventListener onversionchange;
[Custom, RaisesException] IDBObjectStore createObjectStore(DOMString name, optional Dictionary options);
[RaisesException] void deleteObjectStore(DOMString name);
[CallWith=ScriptExecutionContext, RaisesException] IDBTransaction transaction(DOMStringList storeNames, [Default=NullString] optional DOMString mode);
[CallWith=ScriptExecutionContext, RaisesException] IDBTransaction transaction(sequence<DOMString> storeNames, [Default=NullString] optional DOMString mode);
[CallWith=ScriptExecutionContext, RaisesException] IDBTransaction transaction(DOMString storeName, [Default=NullString] optional DOMString mode);
[CallWith=ScriptExecutionContext, RaisesException] IDBTransaction transaction(sequence<DOMString> storeNames, [Default=NullString] optional DOMString mode);
void close();
// EventTarget interface
void addEventListener(DOMString type,
EventListener listener,
optional boolean useCapture);
void removeEventListener(DOMString type,
EventListener listener,
optional boolean useCapture);
[RaisesException] boolean dispatchEvent(Event evt);
attribute EventListener onabort;
attribute EventListener onerror;
attribute EventListener onversionchange;
};
......@@ -29,20 +29,25 @@
#if ENABLE(INDEXED_DATABASE)
#include "IDBDatabaseError.h"
#include "IndexedDB.h"
#include <wtf/RefCounted.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class IDBDatabase;
class IDBDatabaseCallbacks : public RefCounted<IDBDatabaseCallbacks> {
public:
virtual ~IDBDatabaseCallbacks() { }
virtual void onForcedClose() = 0;
virtual void onVersionChange(int64_t oldVersion, int64_t newVersion) = 0;
virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness) = 0;
virtual void onAbort(int64_t transactionId, PassRefPtr<IDBDatabaseError>) = 0;
virtual void onComplete(int64_t transactionId) = 0;
virtual void connect(IDBDatabase*) = 0;
};
} // namespace WebCore
......
......@@ -52,10 +52,10 @@ void IDBDatabaseCallbacksImpl::onForcedClose()
m_database->forceClose();
}
void IDBDatabaseCallbacksImpl::onVersionChange(int64_t oldVersion, int64_t newVersion)
void IDBDatabaseCallbacksImpl::onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness)
{
if (m_database)
m_database->onVersionChange(oldVersion, newVersion);
m_database->onVersionChange(oldVersion, newVersion, newVersionNullness);
}
void IDBDatabaseCallbacksImpl::connect(IDBDatabase* database)
......
......@@ -36,19 +36,19 @@ namespace WebCore {
class IDBDatabase;
class IDBDatabaseCallbacksImpl : public IDBDatabaseCallbacks {
class IDBDatabaseCallbacksImpl FINAL : public IDBDatabaseCallbacks {
public:
static PassRefPtr<IDBDatabaseCallbacksImpl> create();
virtual ~IDBDatabaseCallbacksImpl();
virtual ~IDBDatabaseCallbacksImpl() OVERRIDE;
// IDBDatabaseCallbacks
virtual void onForcedClose();
virtual void onVersionChange(int64_t oldVersion, int64_t newVersion);
virtual void onForcedClose() OVERRIDE;
virtual void onVersionChange(uint64_t oldVersion, uint64_t newVersion, IndexedDB::VersionNullness newVersionNullness) OVERRIDE;
virtual void onAbort(int64_t transactionId, PassRefPtr<IDBDatabaseError>);
virtual void onComplete(int64_t transactionId);
virtual void onAbort(int64_t transactionId, PassRefPtr<IDBDatabaseError>) OVERRIDE;
virtual void onComplete(int64_t transactionId) OVERRIDE;
void connect(IDBDatabase*);
virtual void connect(IDBDatabase*) OVERRIDE;
private:
IDBDatabaseCallbacksImpl();
......
......@@ -113,6 +113,12 @@ PassRefPtr<IDBRequest> IDBFactory::getDatabaseNames(ScriptExecutionContext* cont
return request;
}
PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, const String& name, ExceptionCode& ec)
{
IDB_TRACE("IDBFactory::open");
return openInternal(context, name, 0, IndexedDB::NullVersion, ec);
}
PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, const String& name, unsigned long long version, ExceptionCode& ec)
{
IDB_TRACE("IDBFactory::open");
......@@ -120,13 +126,13 @@ PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, c
ec = TypeError;
return 0;
}
return openInternal(context, name, version, ec);
return openInternal(context, name, version, IndexedDB::NonNullVersion, ec);
}
PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptExecutionContext* context, const String& name, int64_t version, ExceptionCode& ec)
PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptExecutionContext* context, const String& name, uint64_t version, IndexedDB::VersionNullness versionNullness, ExceptionCode& ec)
{
HistogramSupport::histogramEnumeration("WebCore.IndexedDB.FrontEndAPICalls", IDBOpenCall, IDBMethodsMax);
ASSERT(version >= 1 || version == IDBDatabaseMetadata::NoIntVersion);
ASSERT(version >= 1 || versionNullness == IndexedDB::NullVersion);
if (name.isNull()) {
ec = TypeError;
return 0;
......@@ -138,19 +144,13 @@ PassRefPtr<IDBOpenDBRequest> IDBFactory::openInternal(ScriptExecutionContext* co
return 0;
}
RefPtr<IDBDatabaseCallbacksImpl> databaseCallbacks = IDBDatabaseCallbacksImpl::create();
RefPtr<IDBDatabaseCallbacks> databaseCallbacks = IDBDatabaseCallbacksImpl::create();
int64_t transactionId = IDBDatabase::nextTransactionId();
RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databaseCallbacks, transactionId, version);
RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, databaseCallbacks, transactionId, version, versionNullness);
m_backend->open(name, version, transactionId, request, databaseCallbacks, context->securityOrigin(), context, getIndexedDBDatabasePath(context));
return request;
}
PassRefPtr<IDBOpenDBRequest> IDBFactory::open(ScriptExecutionContext* context, const String& name, ExceptionCode& ec)
{
IDB_TRACE("IDBFactory::open");
return openInternal(context, name, IDBDatabaseMetadata::NoIntVersion, ec);
}
PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ScriptExecutionContext* context, const String& name, ExceptionCode& ec)
{
IDB_TRACE("IDBFactory::deleteDatabase");
......@@ -166,7 +166,7 @@ PassRefPtr<IDBOpenDBRequest> IDBFactory::deleteDatabase(ScriptExecutionContext*
return 0;
}
RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, IDBDatabaseMetadata::DefaultIntVersion);
RefPtr<IDBOpenDBRequest> request = IDBOpenDBRequest::create(context, 0, 0, 0, IndexedDB::NullVersion);
m_backend->deleteDatabase(name, request, context->securityOrigin(), context, getIndexedDBDatabasePath(context));
return request;
}
......
......@@ -68,7 +68,7 @@ public:
private:
IDBFactory(IDBFactoryBackendInterface*);
PassRefPtr<IDBOpenDBRequest> openInternal(ScriptExecutionContext*, const String& name, int64_t version, ExceptionCode&);
PassRefPtr<IDBOpenDBRequest> openInternal(ScriptExecutionContext*, const String& name, uint64_t version, IndexedDB::VersionNullness, ExceptionCode&);
RefPtr<IDBFactoryBackendInterface> m_backend;
};
......
......@@ -28,11 +28,8 @@
JSNoStaticTables,
ImplementationLacksVTable
] interface IDBFactory {
[CallWith=ScriptExecutionContext, ImplementedAs=getDatabaseNames, RaisesException] IDBRequest webkitGetDatabaseNames();
[CallWith=ScriptExecutionContext, RaisesException] IDBOpenDBRequest open(DOMString name, [EnforceRange] optional unsigned long long version);
[CallWith=ScriptExecutionContext, RaisesException] IDBOpenDBRequest deleteDatabase(DOMString name);
[CallWith=ScriptExecutionContext, RaisesException] short cmp(any first, any second);
};
......@@ -31,8 +31,8 @@
readonly attribute DOMString name;
readonly attribute IDBObjectStore objectStore;
[ImplementedAs=keyPathAny] readonly attribute IDBAny keyPath;
readonly attribute boolean unique;
readonly attribute boolean multiEntry;
readonly attribute boolean unique;
[CallWith=ScriptExecutionContext, RaisesException] IDBRequest openCursor(optional IDBKeyRange? range, optional DOMString direction);
[CallWith=ScriptExecutionContext, RaisesException] IDBRequest openCursor(any key, optional DOMString direction);
......
......@@ -34,8 +34,8 @@
readonly attribute boolean upperOpen;
[CallWith=ScriptExecutionContext, RaisesException] static IDBKeyRange only(any value);
[CallWith=ScriptExecutionContext, RaisesException] static IDBKeyRange lowerBound(any bound, optional boolean open);
[CallWith=ScriptExecutionContext, RaisesException] static IDBKeyRange upperBound(any bound, optional boolean open);
[CallWith=ScriptExecutionContext, RaisesException] static IDBKeyRange lowerBound(any lower, optional boolean open);
[CallWith=ScriptExecutionContext, RaisesException] static IDBKeyRange upperBound(any upper, optional boolean open);
[CallWith=ScriptExecutionContext, RaisesException] static IDBKeyRange bound(any lower, any upper, optional boolean lowerOpen, optional boolean upperOpen);
};
......@@ -30,6 +30,7 @@
#define IDBMetadata_h
#include "IDBKeyPath.h"
#include <stdint.h>
#include <wtf/HashMap.h>
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>
......@@ -79,31 +80,45 @@ struct IDBObjectStoreMetadata {
};
struct IDBDatabaseMetadata {
// FIXME: These can probably be collapsed into 0.
#if USE(LEVELDB)
// FIXME: These are only here to support the LevelDB backend which incorrectly handles versioning.
// Once LevelDB supports a single, uint64_t version and throws out the old string version, these
// should be gotten rid of.
// Also, "NoIntVersion" used to be a magic number of -1, which doesn't work with the new unsigned type.
// Changing the value to INT64_MAX here seems like a reasonable temporary fix as the current LevelDB
// already cannot represent valid version numbers between INT64_MAX and UINT64_MAX.
#ifndef INT64_MAX
#define INT64_MAX 9223372036854775807LL
#endif
enum {
NoIntVersion = -1,
NoIntVersion = INT64_MAX,
DefaultIntVersion = 0
};
#endif // USE(LEVELDB)
typedef HashMap<int64_t, IDBObjectStoreMetadata> ObjectStoreMap;
IDBDatabaseMetadata()
: intVersion(NoIntVersion)
: id(0)
, version(0)
, maxObjectStoreId(0)
{
}
IDBDatabaseMetadata(const String& name, int64_t id, const String& version, int64_t intVersion, int64_t maxObjectStoreId)
IDBDatabaseMetadata(const String& name, int64_t id, uint64_t version, int64_t maxObjectStoreId)
: name(name)
, id(id)
, version(version)
, intVersion(intVersion)
, maxObjectStoreId(maxObjectStoreId)
{
}
String name;
int64_t id;
String version;
int64_t intVersion;
uint64_t version;
int64_t maxObjectStoreId;
ObjectStoreMap objectStores;
......
......@@ -38,12 +38,11 @@
[CallWith=ScriptState, RaisesException] IDBRequest add(any value, optional any key);
[CallWith=ScriptExecutionContext, ImplementedAs=deleteFunction, RaisesException] IDBRequest delete(IDBKeyRange? keyRange);
[CallWith=ScriptExecutionContext, ImplementedAs=deleteFunction, RaisesException] IDBRequest delete(any key);
[CallWith=ScriptExecutionContext, RaisesException] IDBRequest clear();
[CallWith=ScriptExecutionContext, RaisesException] IDBRequest get(IDBKeyRange? key);
[CallWith=ScriptExecutionContext, RaisesException] IDBRequest get(any key);
[CallWith=ScriptExecutionContext, RaisesException] IDBRequest clear();
[CallWith=ScriptExecutionContext, RaisesException] IDBRequest openCursor(optional IDBKeyRange? range, optional DOMString direction);
[CallWith=ScriptExecutionContext, RaisesException] IDBRequest openCursor(any key, optional DOMString direction);
[CallWith=ScriptExecutionContext, Custom, RaisesException] IDBIndex createIndex(DOMString name, sequence<DOMString> keyPath, optional Dictionary options);
[CallWith=ScriptExecutionContext, Custom, RaisesException] IDBIndex createIndex(DOMString name, DOMString keyPath, optional Dictionary options);
[RaisesException] IDBIndex index(DOMString name);
......
......@@ -37,18 +37,19 @@
namespace WebCore {
PassRefPtr<IDBOpenDBRequest> IDBOpenDBRequest::create(ScriptExecutionContext* context, PassRefPtr<IDBDatabaseCallbacksImpl> callbacks, int64_t transactionId, int64_t version)
PassRefPtr<IDBOpenDBRequest> IDBOpenDBRequest::create(ScriptExecutionContext* context, PassRefPtr<IDBDatabaseCallbacks> callbacks, int64_t transactionId, uint64_t version, IndexedDB::VersionNullness versionNullness)
{
RefPtr<IDBOpenDBRequest> request(adoptRef(new IDBOpenDBRequest(context, callbacks, transactionId, version)));
RefPtr<IDBOpenDBRequest> request(adoptRef(new IDBOpenDBRequest(context, callbacks, transactionId, version, versionNullness)));
request->suspendIfNeeded();
return request.release();
}
IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext* context, PassRefPtr<IDBDatabaseCallbacksImpl> callbacks, int64_t transactionId, int64_t version)
IDBOpenDBRequest::IDBOpenDBRequest(ScriptExecutionContext* context, PassRefPtr<IDBDatabaseCallbacks> callbacks, int64_t transactionId, uint64_t version, IndexedDB::VersionNullness versionNullness)
: IDBRequest(context, IDBAny::createNull(), IDBDatabaseBackendInterface::NormalTask, 0)
, m_databaseCallbacks(callbacks)
, m_transactionId(transactionId)
, m_version(version)
, m_versionNullness(versionNullness)
{
ASSERT(!m_result);
}
......@@ -62,16 +63,16 @@ EventTargetInterface IDBOpenDBRequest::eventTargetInterface() const
return IDBOpenDBRequestEventTargetInterfaceType;
}
void IDBOpenDBRequest::onBlocked(int64_t oldVersion)
void IDBOpenDBRequest::onBlocked(uint64_t oldVersion)
{
IDB_TRACE("IDBOpenDBRequest::onBlocked()");
if (!shouldEnqueueEvent())
return;
RefPtr<IDBAny> newVersionAny = (m_version == IDBDatabaseMetadata::DefaultIntVersion) ? IDBAny::createNull() : IDBAny::create(m_version);
enqueueEvent(IDBVersionChangeEvent::create(IDBAny::create(oldVersion), newVersionAny.release(), eventNames().blockedEvent));
enqueueEvent(IDBVersionChangeEvent::create(oldVersion, m_version, m_versionNullness, eventNames().blockedEvent));
}
void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, PassRefPtr<IDBDatabaseBackendInterface> prpDatabaseBackend, const IDBDatabaseMetadata& metadata)
void IDBOpenDBRequest::onUpgradeNeeded(uint64_t oldVersion, PassRefPtr<IDBDatabaseBackendInterface> prpDatabaseBackend, const IDBDatabaseMetadata& metadata)
{
IDB_TRACE("IDBOpenDBRequest::onUpgradeNeeded()");
if (m_contextStopped || !scriptExecutionContext()) {
......@@ -92,19 +93,15 @@ void IDBOpenDBRequest::onUpgradeNeeded(int64_t oldVersion, PassRefPtr<IDBDatabas
m_databaseCallbacks->connect(idbDatabase.get());
m_databaseCallbacks = 0;
if (oldVersion == IDBDatabaseMetadata::NoIntVersion) {
// This database hasn't had an integer version before.
oldVersion = IDBDatabaseMetadata::DefaultIntVersion;
}
IDBDatabaseMetadata oldMetadata(metadata);
oldMetadata.intVersion = oldVersion;
oldMetadata.version = oldVersion;
m_transaction = IDBTransaction::create(scriptExecutionContext(), m_transactionId, idbDatabase.get(), this, oldMetadata);
m_result = IDBAny::create(idbDatabase.release());
if (m_version == IDBDatabaseMetadata::NoIntVersion)
if (m_versionNullness == IndexedDB::NullVersion)
m_version = 1;
enqueueEvent(IDBVersionChangeEvent::create(IDBAny::create(oldVersion), IDBAny::create(m_version), eventNames().upgradeneededEvent));
enqueueEvent(IDBVersionChangeEvent::create(oldVersion, m_version, m_versionNullness, eventNames().upgradeneededEvent));
}
void IDBOpenDBRequest::onSuccess(PassRefPtr<IDBDatabaseBackendInterface> prpBackend, const IDBDatabaseMetadata& metadata)
......
......@@ -29,20 +29,21 @@
#if ENABLE(INDEXED_DATABASE)
#include "IDBRequest.h"
#include "IndexedDB.h"
namespace WebCore {
class IDBDatabaseCallbacksImpl;
class IDBDatabaseCallbacks;
class IDBOpenDBRequest : public IDBRequest {
public:
static PassRefPtr<IDBOpenDBRequest> create(ScriptExecutionContext*, PassRefPtr<IDBDatabaseCallbacksImpl>, int64_t transactionId, int64_t version);
static PassRefPtr<IDBOpenDBRequest> create(ScriptExecutionContext*, PassRefPtr<IDBDatabaseCallbacks>, int64_t transactionId, uint64_t version, IndexedDB::VersionNullness);
virtual ~IDBOpenDBRequest();
using IDBRequest::onSuccess;
virtual void onBlocked(int64_t existingVersion) OVERRIDE;
virtual void onUpgradeNeeded(int64_t oldVersion, PassRefPtr<IDBDatabaseBackendInterface>, const IDBDatabaseMetadata&) OVERRIDE;
virtual void onBlocked(uint64_t existingVersion) OVERRIDE;
virtual void onUpgradeNeeded(uint64_t oldVersion, PassRefPtr<IDBDatabaseBackendInterface>, const IDBDatabaseMetadata&) OVERRIDE;
virtual void onSuccess(PassRefPtr<IDBDatabaseBackendInterface>, const IDBDatabaseMetadata&) OVERRIDE;
// EventTarget
......@@ -56,11 +57,12 @@ protected:
virtual bool shouldEnqueueEvent() const OVERRIDE;
private:
IDBOpenDBRequest(ScriptExecutionContext*, PassRefPtr<IDBDatabaseCallbacksImpl>, int64_t transactionId, int64_t version);
IDBOpenDBRequest(ScriptExecutionContext*, PassRefPtr<IDBDatabaseCallbacks>, int64_t transactionId, uint64_t version, IndexedDB::VersionNullness);
RefPtr<IDBDatabaseCallbacksImpl> m_databaseCallbacks;
RefPtr<IDBDatabaseCallbacks> m_databaseCallbacks;
const int64_t m_transactionId;
int64_t m_version;
uint64_t m_version;