18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
22daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch * Copyright (C) 2011 Google Inc. All rights reserved.
38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Redistribution and use in source and binary forms, with or without
58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modification, are permitted provided that the following conditions
68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * are met:
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 1.  Redistributions of source code must retain the above copyright
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *     notice, this list of conditions and the following disclaimer.
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 2.  Redistributions in binary form must reproduce the above copyright
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *     notice, this list of conditions and the following disclaimer in the
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *     documentation and/or other materials provided with the distribution.
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
255af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
26dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#include "config.h"
27db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block#include "IDBIndexBackendProxy.h"
285af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
2968513a70bcd92384395513322f1b801e7bf9c729Steve Block#if ENABLE(INDEXED_DATABASE)
3068513a70bcd92384395513322f1b801e7bf9c729Steve Block
3168513a70bcd92384395513322f1b801e7bf9c729Steve Block#include "IDBCallbacks.h"
3268513a70bcd92384395513322f1b801e7bf9c729Steve Block#include "IDBKeyRange.h"
33a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch#include "IDBTransactionBackendProxy.h"
3468513a70bcd92384395513322f1b801e7bf9c729Steve Block#include "WebIDBCallbacksImpl.h"
355af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke#include "WebIDBDatabaseError.h"
365af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke#include "WebIDBIndex.h"
3768513a70bcd92384395513322f1b801e7bf9c729Steve Block#include "WebIDBKey.h"
3868513a70bcd92384395513322f1b801e7bf9c729Steve Block#include "WebIDBKeyRange.h"
398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
402daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochusing namespace WebCore;
418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
422daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdochnamespace WebKit {
432daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch
442daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochPassRefPtr<IDBIndexBackendInterface> IDBIndexBackendProxy::create(PassOwnPtr<WebIDBIndex> index)
455af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
46db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block    return adoptRef(new IDBIndexBackendProxy(index));
475af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
485af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
492daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben MurdochIDBIndexBackendProxy::IDBIndexBackendProxy(PassOwnPtr<WebIDBIndex> index)
50db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Block    : m_webIDBIndex(index)
515af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
525af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
535af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
54db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve BlockIDBIndexBackendProxy::~IDBIndexBackendProxy()
555af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
565af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
575af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
58db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve BlockString IDBIndexBackendProxy::name()
595af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
605af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke    return m_webIDBIndex->name();
615af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
625af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
6368513a70bcd92384395513322f1b801e7bf9c729Steve BlockString IDBIndexBackendProxy::storeName()
6468513a70bcd92384395513322f1b801e7bf9c729Steve Block{
6568513a70bcd92384395513322f1b801e7bf9c729Steve Block    return m_webIDBIndex->storeName();
6668513a70bcd92384395513322f1b801e7bf9c729Steve Block}
6768513a70bcd92384395513322f1b801e7bf9c729Steve Block
68db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve BlockString IDBIndexBackendProxy::keyPath()
695af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
705af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke    return m_webIDBIndex->keyPath();
715af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
725af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke
73db14019a23d96bc8a444b6576a5da8bd1cfbc8b0Steve Blockbool IDBIndexBackendProxy::unique()
745af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{
755af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke    return m_webIDBIndex->unique();
765af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke}
778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
78a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvoid IDBIndexBackendProxy::openCursor(PassRefPtr<IDBKeyRange> keyRange, unsigned short direction, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
7968513a70bcd92384395513322f1b801e7bf9c729Steve Block{
80a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
81a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
82a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
83a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    m_webIDBIndex->openObjectCursor(keyRange, direction, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
8468513a70bcd92384395513322f1b801e7bf9c729Steve Block}
8568513a70bcd92384395513322f1b801e7bf9c729Steve Block
86a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvoid IDBIndexBackendProxy::openKeyCursor(PassRefPtr<IDBKeyRange> keyRange, unsigned short direction, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
8768513a70bcd92384395513322f1b801e7bf9c729Steve Block{
88a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
89a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
90a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
91a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    m_webIDBIndex->openKeyCursor(keyRange, direction, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
9268513a70bcd92384395513322f1b801e7bf9c729Steve Block}
9368513a70bcd92384395513322f1b801e7bf9c729Steve Block
94a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvoid IDBIndexBackendProxy::get(PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
9568513a70bcd92384395513322f1b801e7bf9c729Steve Block{
96a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
97a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
98a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
99a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    m_webIDBIndex->getObject(key, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
10068513a70bcd92384395513322f1b801e7bf9c729Steve Block}
10168513a70bcd92384395513322f1b801e7bf9c729Steve Block
102a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvoid IDBIndexBackendProxy::getKey(PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
10368513a70bcd92384395513322f1b801e7bf9c729Steve Block{
104a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
105a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    // all implementations of IDB interfaces are proxy objects.
106a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
107a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch    m_webIDBIndex->getKey(key, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
10868513a70bcd92384395513322f1b801e7bf9c729Steve Block}
10968513a70bcd92384395513322f1b801e7bf9c729Steve Block
1102daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch} // namespace WebKit
1118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
112dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block#endif // ENABLE(INDEXED_DATABASE)
113