15af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke/*
22daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * Copyright (C) 2011 Google Inc. All rights reserved.
35af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke *
45af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * Redistribution and use in source and binary forms, with or without
55af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * modification, are permitted provided that the following conditions
65af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * are met:
75af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke *
85af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * 1.  Redistributions of source code must retain the above copyright
95af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke *     notice, this list of conditions and the following disclaimer.
105af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * 2.  Redistributions in binary form must reproduce the above copyright
115af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke *     notice, this list of conditions and the following disclaimer in the
125af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke *     documentation and/or other materials provided with the distribution.
135af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke *
145af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
155af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
165af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
175af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
185af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
195af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
205af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
215af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
235af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke */
255af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
265af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke#include "config.h"
272daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch#include "IDBObjectStoreBackendProxy.h"
282daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch
292daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch#if ENABLE(INDEXED_DATABASE)
305af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
315af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke#include "DOMStringList.h"
325af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke#include "IDBCallbacks.h"
33db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block#include "IDBIndexBackendProxy.h"
34dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch#include "IDBKeyRange.h"
35bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include "IDBTransactionBackendProxy.h"
36545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "WebIDBCallbacksImpl.h"
37dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch#include "WebIDBKeyRange.h"
38545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "WebIDBIndex.h"
39e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "WebIDBKey.h"
40545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "WebIDBObjectStore.h"
41bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include "WebIDBTransactionImpl.h"
42e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "WebSerializedScriptValue.h"
435af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
442daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochusing namespace WebCore;
455af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
462daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochnamespace WebKit {
475af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
482daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochPassRefPtr<IDBObjectStoreBackendInterface> IDBObjectStoreBackendProxy::create(PassOwnPtr<WebIDBObjectStore> objectStore)
495af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
502daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    return adoptRef(new IDBObjectStoreBackendProxy(objectStore));
515af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
525af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
532daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochIDBObjectStoreBackendProxy::IDBObjectStoreBackendProxy(PassOwnPtr<WebIDBObjectStore> objectStore)
54545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    : m_webIDBObjectStore(objectStore)
555af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
565af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
575af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
582daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochIDBObjectStoreBackendProxy::~IDBObjectStoreBackendProxy()
595af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
605af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
615af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
622daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochString IDBObjectStoreBackendProxy::name() const
635af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
64545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    return m_webIDBObjectStore->name();
65545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch}
66545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
672daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochString IDBObjectStoreBackendProxy::keyPath() const
68545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{
69545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    return m_webIDBObjectStore->keyPath();
70545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch}
715af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
722daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochPassRefPtr<DOMStringList> IDBObjectStoreBackendProxy::indexNames() const
73545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{
74545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    return m_webIDBObjectStore->indexNames();
755af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
765af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
772daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid IDBObjectStoreBackendProxy::get(PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
78e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke{
79bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
80bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    // all implementations of IDB interfaces are proxy objects.
81bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
82a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    m_webIDBObjectStore->get(key, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
83e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke}
84e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
852daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid IDBObjectStoreBackendProxy::put(PassRefPtr<SerializedScriptValue> value, PassRefPtr<IDBKey> key, PutMode putMode, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
86e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke{
87a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
88a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
89a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
902daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    m_webIDBObjectStore->put(value, key, static_cast<WebIDBObjectStore::PutMode>(putMode), new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
91e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke}
92e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
932daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid IDBObjectStoreBackendProxy::deleteFunction(PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
94e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke{
95a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
96a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
97a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
984576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wang    m_webIDBObjectStore->deleteFunction(key, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
99e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke}
100e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke
1012daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid IDBObjectStoreBackendProxy::clear(PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
1022fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{
1032fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
1042fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    // all implementations of IDB interfaces are proxy objects.
1052fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
1062fc2651226baac27029e38c9d6ef883fa32084dbSteve Block    m_webIDBObjectStore->clear(new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
1072fc2651226baac27029e38c9d6ef883fa32084dbSteve Block}
1082fc2651226baac27029e38c9d6ef883fa32084dbSteve Block
1092daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochPassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendProxy::createIndex(const String& name, const String& keyPath, bool unique, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
1105af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
111a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
112a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
113a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
1142daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    WebIDBIndex* index = m_webIDBObjectStore->createIndex(name, keyPath, unique, *transactionProxy->getWebIDBTransaction(), ec);
115a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    if (!index)
116a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch        return 0;
117a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    return IDBIndexBackendProxy::create(index);
1185af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
1195af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
1202daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochPassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendProxy::index(const String& name, ExceptionCode& ec)
1215af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
1222daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    WebIDBIndex* index = m_webIDBObjectStore->index(name, ec);
123545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    if (!index)
124545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch        return 0;
125db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block    return IDBIndexBackendProxy::create(index);
126545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch}
1275af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
1282daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid IDBObjectStoreBackendProxy::deleteIndex(const String& name, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
129545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{
130a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
131a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
132a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
1334576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wang    m_webIDBObjectStore->deleteIndex(name, *transactionProxy->getWebIDBTransaction(), ec);
1345af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
1355af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
1362daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochvoid IDBObjectStoreBackendProxy::openCursor(PassRefPtr<IDBKeyRange> range, unsigned short direction, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
137dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch{
138a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
139a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
140a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
141a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    m_webIDBObjectStore->openCursor(range, direction, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
142dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch}
143dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch
1442daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch} // namespace WebKit
1455af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
1465af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke#endif // ENABLE(INDEXED_DATABASE)
147