tizen beta release
[framework/web/webkit-efl.git] / Source / WebKit / chromium / src / IDBDatabaseBackendProxy.cpp
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 #if ENABLE(INDEXED_DATABASE)
30
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"
44
45 using namespace WebCore;
46
47 namespace WebKit {
48
49 PassRefPtr<IDBDatabaseBackendInterface> IDBDatabaseBackendProxy::create(PassOwnPtr<WebIDBDatabase> database)
50 {
51     return adoptRef(new IDBDatabaseBackendProxy(database));
52 }
53
54 IDBDatabaseBackendProxy::IDBDatabaseBackendProxy(PassOwnPtr<WebIDBDatabase> database)
55     : m_webIDBDatabase(database)
56 {
57 }
58
59 IDBDatabaseBackendProxy::~IDBDatabaseBackendProxy()
60 {
61 }
62
63 String IDBDatabaseBackendProxy::name() const
64 {
65     return m_webIDBDatabase->name();
66 }
67
68 String IDBDatabaseBackendProxy::version() const
69 {
70     return m_webIDBDatabase->version();
71 }
72
73 PassRefPtr<DOMStringList> IDBDatabaseBackendProxy::objectStoreNames() const
74 {
75     return m_webIDBDatabase->objectStoreNames();
76 }
77
78 PassRefPtr<IDBObjectStoreBackendInterface> IDBDatabaseBackendProxy::createObjectStore(const String& name, const String& keyPath, bool autoIncrement, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
79 {
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));
84     if (!objectStore)
85         return 0;
86     return IDBObjectStoreBackendProxy::create(objectStore.release());
87 }
88
89 void IDBDatabaseBackendProxy::deleteObjectStore(const String& name, IDBTransactionBackendInterface* transaction, ExceptionCode& ec)
90 {
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);
95 }
96
97 void IDBDatabaseBackendProxy::setVersion(const String& version, PassRefPtr<IDBCallbacks> callbacks, PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks, ExceptionCode& ec)
98 {
99     m_webIDBDatabase->setVersion(version, new WebIDBCallbacksImpl(callbacks), ec);
100 }
101
102 PassRefPtr<IDBTransactionBackendInterface> IDBDatabaseBackendProxy::transaction(DOMStringList* storeNames, unsigned short mode, ExceptionCode& ec)
103 {
104     WebDOMStringList names(storeNames);
105     OwnPtr<WebIDBTransaction> transaction = adoptPtr(m_webIDBDatabase->transaction(names, mode, ec));
106     if (!transaction) {
107         ASSERT(ec);
108         return 0;
109     }
110     return IDBTransactionBackendProxy::create(transaction.release());
111 }
112
113 void IDBDatabaseBackendProxy::close(PassRefPtr<IDBDatabaseCallbacks>)
114 {
115     m_webIDBDatabase->close();
116 }
117
118 void IDBDatabaseBackendProxy::open(PassRefPtr<IDBDatabaseCallbacks> databaseCallbacks)
119 {
120     m_webIDBDatabase->open(new WebIDBDatabaseCallbacksImpl(databaseCallbacks));
121 }
122
123 } // namespace WebKit
124
125 #endif // ENABLE(INDEXED_DATABASE)