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 "IDBDatabaseBackendProxy.h" 28 29 #include "WebFrameImpl.h" 30 #include "WebIDBCallbacksImpl.h" 31 #include "WebIDBDatabaseCallbacksImpl.h" 32 #include "core/dom/DOMError.h" 33 #include "modules/indexeddb/IDBCallbacks.h" 34 #include "modules/indexeddb/IDBDatabaseCallbacks.h" 35 #include "modules/indexeddb/IDBKeyRange.h" 36 #include "modules/indexeddb/IDBMetadata.h" 37 #include "public/platform/WebData.h" 38 #include "public/platform/WebIDBCursor.h" 39 #include "public/platform/WebIDBDatabase.h" 40 #include "public/platform/WebIDBDatabaseError.h" 41 #include "public/platform/WebIDBKeyRange.h" 42 43 using namespace WebCore; 44 45 namespace WebKit { 46 47 PassRefPtr<IDBDatabaseBackendInterface> IDBDatabaseBackendProxy::create(PassOwnPtr<WebIDBDatabase> database) 48 { 49 return adoptRef(new IDBDatabaseBackendProxy(database)); 50 } 51 52 IDBDatabaseBackendProxy::IDBDatabaseBackendProxy(PassOwnPtr<WebIDBDatabase> database) 53 : m_webIDBDatabase(database) 54 { 55 } 56 57 IDBDatabaseBackendProxy::~IDBDatabaseBackendProxy() 58 { 59 } 60 61 void IDBDatabaseBackendProxy::createObjectStore(int64_t transactionId, int64_t objectStoreId, const String& name, const IDBKeyPath& keyPath, bool autoIncrement) 62 { 63 if (m_webIDBDatabase) 64 m_webIDBDatabase->createObjectStore(transactionId, objectStoreId, name, keyPath, autoIncrement); 65 } 66 67 void IDBDatabaseBackendProxy::deleteObjectStore(int64_t transactionId, int64_t objectStoreId) 68 { 69 if (m_webIDBDatabase) 70 m_webIDBDatabase->deleteObjectStore(transactionId, objectStoreId); 71 } 72 73 void IDBDatabaseBackendProxy::createTransaction(int64_t id, PassRefPtr<IDBDatabaseCallbacks>, const Vector<int64_t>& objectStoreIds, unsigned short mode) 74 { 75 // WebIDBDatabaseImpl holds on to the specific callbacks object for this connection. 76 m_webIDBDatabase->createTransaction(id, 0, objectStoreIds, mode); 77 } 78 79 void IDBDatabaseBackendProxy::commit(int64_t transactionId) 80 { 81 m_webIDBDatabase->commit(transactionId); 82 } 83 84 void IDBDatabaseBackendProxy::abort(int64_t transactionId) 85 { 86 m_webIDBDatabase->abort(transactionId); 87 } 88 89 void IDBDatabaseBackendProxy::openCursor(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, IndexedDB::CursorDirection direction, bool keyOnly, TaskType taskType, PassRefPtr<IDBCallbacks> callbacks) 90 { 91 m_webIDBDatabase->openCursor(transactionId, objectStoreId, indexId, keyRange, static_cast<WebIDBCursor::Direction>(direction), keyOnly, static_cast<WebIDBDatabase::TaskType>(taskType), new WebIDBCallbacksImpl(callbacks)); 92 } 93 94 void IDBDatabaseBackendProxy::count(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks) 95 { 96 if (m_webIDBDatabase) 97 m_webIDBDatabase->count(transactionId, objectStoreId, indexId, keyRange, new WebIDBCallbacksImpl(callbacks)); 98 } 99 100 void IDBDatabaseBackendProxy::get(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange> keyRange, bool keyOnly, PassRefPtr<IDBCallbacks> callbacks) 101 { 102 if (m_webIDBDatabase) 103 m_webIDBDatabase->get(transactionId, objectStoreId, indexId, keyRange, keyOnly, new WebIDBCallbacksImpl(callbacks)); 104 } 105 106 void IDBDatabaseBackendProxy::put(int64_t transactionId, int64_t objectStoreId, PassRefPtr<SharedBuffer> value, PassRefPtr<IDBKey> key, PutMode putMode, PassRefPtr<IDBCallbacks> callbacks, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys) 107 { 108 if (m_webIDBDatabase) { 109 m_webIDBDatabase->put(transactionId, objectStoreId, WebData(value), key, static_cast<WebIDBDatabase::PutMode>(putMode), new WebIDBCallbacksImpl(callbacks), indexIds, indexKeys); 110 } 111 } 112 113 void IDBDatabaseBackendProxy::setIndexKeys(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKey> primaryKey, const Vector<int64_t>& indexIds, const Vector<IndexKeys>& indexKeys) 114 { 115 if (m_webIDBDatabase) 116 m_webIDBDatabase->setIndexKeys(transactionId, objectStoreId, primaryKey, indexIds, indexKeys); 117 } 118 119 void IDBDatabaseBackendProxy::setIndexesReady(int64_t transactionId, int64_t objectStoreId, const Vector<int64_t>& indexIds) 120 { 121 if (m_webIDBDatabase) 122 m_webIDBDatabase->setIndexesReady(transactionId, objectStoreId, indexIds); 123 } 124 125 void IDBDatabaseBackendProxy::deleteRange(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKeyRange> keyRange, PassRefPtr<IDBCallbacks> callbacks) 126 { 127 if (m_webIDBDatabase) 128 m_webIDBDatabase->deleteRange(transactionId, objectStoreId, keyRange, new WebIDBCallbacksImpl(callbacks)); 129 } 130 131 void IDBDatabaseBackendProxy::clear(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBCallbacks> callbacks) 132 { 133 if (m_webIDBDatabase) 134 m_webIDBDatabase->clear(transactionId, objectStoreId, new WebIDBCallbacksImpl(callbacks)); 135 } 136 137 void IDBDatabaseBackendProxy::createIndex(int64_t transactionId, int64_t objectStoreId, int64_t indexId, const String& name, const WebCore::IDBKeyPath& keyPath, bool unique, bool multiEntry) 138 { 139 if (m_webIDBDatabase) 140 m_webIDBDatabase->createIndex(transactionId, objectStoreId, indexId, name, keyPath, unique, multiEntry); 141 } 142 143 void IDBDatabaseBackendProxy::deleteIndex(int64_t transactionId, int64_t objectStoreId, int64_t indexId) 144 { 145 if (m_webIDBDatabase) 146 m_webIDBDatabase->deleteIndex(transactionId, objectStoreId, indexId); 147 } 148 149 void IDBDatabaseBackendProxy::close(PassRefPtr<IDBDatabaseCallbacks>) 150 { 151 m_webIDBDatabase->close(); 152 } 153 154 } // namespace WebKit 155