2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "IDBDatabaseBackendProxy.h"
29 #if ENABLE(INDEXED_DATABASE)
31 #include "DOMStringList.h"
32 #include "IDBCallbacks.h"
33 #include "IDBDatabaseCallbacks.h"
34 #include "IDBObjectStoreBackendProxy.h"
35 #include "IDBTransactionBackendProxy.h"
36 #include "WebDOMStringList.h"
37 #include "WebFrameImpl.h"
38 #include "WebIDBCallbacksImpl.h"
39 #include "WebIDBDatabase.h"
40 #include "WebIDBDatabaseCallbacksImpl.h"
41 #include "WebIDBDatabaseError.h"
42 #include "WebIDBObjectStore.h"
43 #include "WebIDBTransaction.h"
45 using namespace WebCore;
49 PassRefPtr<IDBDatabaseBackendInterface> IDBDatabaseBackendProxy::create(PassOwnPtr<WebIDBDatabase> database)
51 return adoptRef(new IDBDatabaseBackendProxy(database));
54 IDBDatabaseBackendProxy::IDBDatabaseBackendProxy(PassOwnPtr<WebIDBDatabase> database)
55 : m_webIDBDatabase(database)
59 IDBDatabaseBackendProxy::~IDBDatabaseBackendProxy()
63 String IDBDatabaseBackendProxy::name() const
65 return m_webIDBDatabase->name();
68 String IDBDatabaseBackendProxy::version() const
70 return m_webIDBDatabase->version();
73 PassRefPtr<DOMStringList> IDBDatabaseBackendProxy::objectStoreNames() const
75 return m_webIDBDatabase->objectStoreNames();
78 PassRefPtr<IDBObjectStoreBackendInterface> IDBDatabaseBackendProxy::createObjectStore(const String& name, const String& keyPath, bool autoIncrement, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
80 // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
81 // all implementations of IDB interfaces are proxy objects.
82 IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
83 OwnPtr<WebIDBObjectStore> objectStore = adoptPtr(m_webIDBDatabase->createObjectStore(name, keyPath, autoIncrement, *transactionProxy->getWebIDBTransaction(), ec));
86 return IDBObjectStoreBackendProxy::create(objectStore.release());
89 void IDBDatabaseBackendProxy::deleteObjectStore(const String& name, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
91 // The transaction pointer is guaranteed to be a pointer to a proxy object as, in the renderer,
92 // all implementations of IDB interfaces are proxy objects.
93 IDBTransactionBackendProxy* transactionProxy = static_cast<IDBTransactionBackendProxy*>(transaction);
94 m_webIDBDatabase->deleteObjectStore(name, *transactionProxy->getWebIDBTransaction(), ec);
97 void IDBDatabaseBackendProxy::setVersion(const String& version, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, ExceptionCode& ec)
99 m_webIDBDatabase->setVersion(version, new WebIDBCallbacksImpl(callbacks), ec);
102 PassRefPtr<IDBTransactionBackendInterface> IDBDatabaseBackendProxy::transaction(DOMStringList* storeNames, unsigned short mode, ExceptionCode& ec)
104 WebDOMStringList names(storeNames);
105 OwnPtr<WebIDBTransaction> transaction = adoptPtr(m_webIDBDatabase->transaction(names, mode, ec));
110 return IDBTransactionBackendProxy::create(transaction.release());
113 void IDBDatabaseBackendProxy::close(PassRefPtr<IDBDatabaseCallbacks>)
115 m_webIDBDatabase->close();
118 void IDBDatabaseBackendProxy::open(PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
120 m_webIDBDatabase->open(new WebIDBDatabaseCallbacksImpl(databaseCallbacks));
123 } // namespace WebKit
125 #endif // ENABLE(INDEXED_DATABASE)