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" 27545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "WebIDBObjectStoreImpl.h" 285af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 292daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch#if ENABLE(INDEXED_DATABASE) 302daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch 315af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke#include "DOMStringList.h" 32545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "IDBCallbacksProxy.h" 332bde8e466a4451c7319e3a072d118917957d6554Steve Block#include "IDBIndexBackendInterface.h" 34dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch#include "IDBKeyRange.h" 35dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch#include "IDBObjectStoreBackendInterface.h" 36545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include "WebIDBIndexImpl.h" 37e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "WebIDBKey.h" 38dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch#include "WebIDBKeyRange.h" 39bec39347bb3bb5bf1187ccaf471d26247f28b585Kristian Monsen#include "WebIDBTransaction.h" 40e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke#include "WebSerializedScriptValue.h" 415af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 42545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochusing namespace WebCore; 435af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 44545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochnamespace WebKit { 45545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch 46dd8bb3de4f353a81954234999f1fea748aee2ea9Ben MurdochWebIDBObjectStoreImpl::WebIDBObjectStoreImpl(PassRefPtr<IDBObjectStoreBackendInterface> objectStore) 47545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch : m_objectStore(objectStore) 485af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{ 495af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke} 505af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 51545e470e52f0ac6a3a072bf559c796b42c6066b6Ben MurdochWebIDBObjectStoreImpl::~WebIDBObjectStoreImpl() 525af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{ 535af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke} 545af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 55545e470e52f0ac6a3a072bf559c796b42c6066b6Ben MurdochWebString WebIDBObjectStoreImpl::name() const 565af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{ 57545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch return m_objectStore->name(); 585af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke} 595af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 60545e470e52f0ac6a3a072bf559c796b42c6066b6Ben MurdochWebString WebIDBObjectStoreImpl::keyPath() const 615af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{ 62545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch return m_objectStore->keyPath(); 63545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch} 645af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 65545e470e52f0ac6a3a072bf559c796b42c6066b6Ben MurdochWebDOMStringList WebIDBObjectStoreImpl::indexNames() const 66545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{ 67545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch return m_objectStore->indexNames(); 685af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke} 695af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 70a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvoid WebIDBObjectStoreImpl::get(const WebIDBKey& key, WebIDBCallbacks* callbacks, const WebIDBTransaction& transaction, WebExceptionCode& ec) 71e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke{ 72a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch m_objectStore->get(key, IDBCallbacksProxy::create(callbacks), transaction.getIDBTransactionBackendInterface(), ec); 73e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke} 74e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke 752fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockvoid WebIDBObjectStoreImpl::put(const WebSerializedScriptValue& value, const WebIDBKey& key, PutMode putMode, WebIDBCallbacks* callbacks, const WebIDBTransaction& transaction, WebExceptionCode& ec) 76e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke{ 772fc2651226baac27029e38c9d6ef883fa32084dbSteve Block m_objectStore->put(value, key, static_cast<IDBObjectStoreBackendInterface::PutMode>(putMode), IDBCallbacksProxy::create(callbacks), transaction.getIDBTransactionBackendInterface(), ec); 78e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke} 79e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke 804576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wangvoid WebIDBObjectStoreImpl::deleteFunction(const WebIDBKey& key, WebIDBCallbacks* callbacks, const WebIDBTransaction& transaction, WebExceptionCode& ec) 81e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke{ 824576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wang m_objectStore->deleteFunction(key, IDBCallbacksProxy::create(callbacks), transaction.getIDBTransactionBackendInterface(), ec); 83e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke} 84e458d70a0d18538346f41b503114c9ebe6b2ce12Leon Clarke 852fc2651226baac27029e38c9d6ef883fa32084dbSteve Blockvoid WebIDBObjectStoreImpl::clear(WebIDBCallbacks* callbacks, const WebIDBTransaction& transaction, WebExceptionCode& ec) 862fc2651226baac27029e38c9d6ef883fa32084dbSteve Block{ 872fc2651226baac27029e38c9d6ef883fa32084dbSteve Block m_objectStore->clear(IDBCallbacksProxy::create(callbacks), transaction.getIDBTransactionBackendInterface(), ec); 882fc2651226baac27029e38c9d6ef883fa32084dbSteve Block} 892fc2651226baac27029e38c9d6ef883fa32084dbSteve Block 90a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochWebIDBIndex* WebIDBObjectStoreImpl::createIndex(const WebString& name, const WebString& keyPath, bool unique, const WebIDBTransaction& transaction, WebExceptionCode& ec) 915af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{ 92a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch RefPtr<IDBIndexBackendInterface> index = m_objectStore->createIndex(name, keyPath, unique, transaction.getIDBTransactionBackendInterface(), ec); 93a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch if (!index) 94a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return 0; 95a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch return new WebIDBIndexImpl(index); 965af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke} 975af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 98a94275402997c11dd2e778633dacf4b7e630a35dBen MurdochWebIDBIndex* WebIDBObjectStoreImpl::index(const WebString& name, WebExceptionCode& ec) 995af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke{ 100a94275402997c11dd2e778633dacf4b7e630a35dBen Murdoch RefPtr<IDBIndexBackendInterface> index = m_objectStore->index(name, ec); 101545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch if (!index) 102545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch return 0; 103545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch return new WebIDBIndexImpl(index); 104545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch} 1055af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 1064576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wangvoid WebIDBObjectStoreImpl::deleteIndex(const WebString& name, const WebIDBTransaction& transaction, WebExceptionCode& ec) 107545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch{ 1084576aa36e9a9671459299c7963ac95aa94beaea9Shimeng (Simon) Wang m_objectStore->deleteIndex(name, transaction.getIDBTransactionBackendInterface(), ec); 1095af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke} 1105af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 111a94275402997c11dd2e778633dacf4b7e630a35dBen Murdochvoid WebIDBObjectStoreImpl::openCursor(const WebIDBKeyRange& keyRange, unsigned short direction, WebIDBCallbacks* callbacks, const WebIDBTransaction& transaction, WebExceptionCode& ec) 112dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch{ 113e14391e94c850b8bd03680c23b38978db68687a8John Reck m_objectStore->openCursor(keyRange, direction, IDBCallbacksProxy::create(callbacks), transaction.getIDBTransactionBackendInterface(), ec); 114dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch} 115dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch 1162daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch} // namespace WebKit 1175af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke 1185af96e2c7b73ebc627c6894727826a7576d31758Leon Clarke#endif // ENABLE(INDEXED_DATABASE) 119