Home | History | Annotate | Download | only in src
      1 /*
      2  * Copyright (C) 2011 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *
      8  * 1.  Redistributions of source code must retain the above copyright
      9  *     notice, this list of conditions and the following disclaimer.
     10  * 2.  Redistributions in binary form must reproduce the above copyright
     11  *     notice, this list of conditions and the following disclaimer in the
     12  *     documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
     15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
     18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "IDBObjectStoreBackendProxy.h"
     28 
     29 #if ENABLE(INDEXED_DATABASE)
     30 
     31 #include "DOMStringList.h"
     32 #include "IDBCallbacks.h"
     33 #include "IDBIndexBackendProxy.h"
     34 #include "IDBKeyRange.h"
     35 #include "IDBTransactionBackendProxy.h"
     36 #include "WebIDBCallbacksImpl.h"
     37 #include "WebIDBKeyRange.h"
     38 #include "WebIDBIndex.h"
     39 #include "WebIDBKey.h"
     40 #include "WebIDBObjectStore.h"
     41 #include "WebIDBTransactionImpl.h"
     42 #include "WebSerializedScriptValue.h"
     43 
     44 using namespace WebCore;
     45 
     46 namespace WebKit {
     47 
     48 PassRefPtr<IDBObjectStoreBackendInterface> IDBObjectStoreBackendProxy::create(PassOwnPtr<WebIDBObjectStore> objectStore)
     49 {
     50     return adoptRef(new IDBObjectStoreBackendProxy(objectStore));
     51 }
     52 
     53 IDBObjectStoreBackendProxy::IDBObjectStoreBackendProxy(PassOwnPtr<WebIDBObjectStore> objectStore)
     54     : m_webIDBObjectStore(objectStore)
     55 {
     56 }
     57 
     58 IDBObjectStoreBackendProxy::~IDBObjectStoreBackendProxy()
     59 {
     60 }
     61 
     62 String IDBObjectStoreBackendProxy::name() const
     63 {
     64     return m_webIDBObjectStore->name();
     65 }
     66 
     67 String IDBObjectStoreBackendProxy::keyPath() const
     68 {
     69     return m_webIDBObjectStore->keyPath();
     70 }
     71 
     72 PassRefPtr<DOMStringList> IDBObjectStoreBackendProxy::indexNames() const
     73 {
     74     return m_webIDBObjectStore->indexNames();
     75 }
     76 
     77 void IDBObjectStoreBackendProxy::get(PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
     78 {
     79     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
     80     // all implementations of IDB interfaces are proxy objects.
     81     IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
     82     m_webIDBObjectStore->get(key, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
     83 }
     84 
     85 void IDBObjectStoreBackendProxy::put(PassRefPtr<SerializedScriptValue> value, PassRefPtr<IDBKey> key, PutMode putMode, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
     86 {
     87     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
     88     // all implementations of IDB interfaces are proxy objects.
     89     IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
     90     m_webIDBObjectStore->put(value, key, static_cast<WebIDBObjectStore::PutMode>(putMode), new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
     91 }
     92 
     93 void IDBObjectStoreBackendProxy::deleteFunction(PassRefPtr<IDBKey> key, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
     94 {
     95     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
     96     // all implementations of IDB interfaces are proxy objects.
     97     IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
     98     m_webIDBObjectStore->deleteFunction(key, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
     99 }
    100 
    101 void IDBObjectStoreBackendProxy::clear(PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
    102 {
    103     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
    104     // all implementations of IDB interfaces are proxy objects.
    105     IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
    106     m_webIDBObjectStore->clear(new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
    107 }
    108 
    109 PassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendProxy::createIndex(const String& name, const String& keyPath, bool unique, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
    110 {
    111     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
    112     // all implementations of IDB interfaces are proxy objects.
    113     IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
    114     WebIDBIndex* index = m_webIDBObjectStore->createIndex(name, keyPath, unique, *transactionProxy->getWebIDBTransaction(), ec);
    115     if (!index)
    116         return 0;
    117     return IDBIndexBackendProxy::create(index);
    118 }
    119 
    120 PassRefPtr<IDBIndexBackendInterface> IDBObjectStoreBackendProxy::index(const String& name, ExceptionCode& ec)
    121 {
    122     WebIDBIndex* index = m_webIDBObjectStore->index(name, ec);
    123     if (!index)
    124         return 0;
    125     return IDBIndexBackendProxy::create(index);
    126 }
    127 
    128 void IDBObjectStoreBackendProxy::deleteIndex(const String& name, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
    129 {
    130     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
    131     // all implementations of IDB interfaces are proxy objects.
    132     IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
    133     m_webIDBObjectStore->deleteIndex(name, *transactionProxy->getWebIDBTransaction(), ec);
    134 }
    135 
    136 void IDBObjectStoreBackendProxy::openCursor(PassRefPtr<IDBKeyRange> range, unsigned short direction, PassRefPtr<IDBCallbacks> callbacks, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
    137 {
    138     // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
    139     // all implementations of IDB interfaces are proxy objects.
    140     IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
    141     m_webIDBObjectStore->openCursor(range, direction, new WebIDBCallbacksImpl(callbacks), *transactionProxy->getWebIDBTransaction(), ec);
    142 }
    143 
    144 } // namespace WebKit
    145 
    146 #endif // ENABLE(INDEXED_DATABASE)
    147