OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/renderer_webidbobjectstore_impl.h" | |
6 | |
7 #include "chrome/renderer/render_thread.h" | |
8 #include "chrome/renderer/renderer_webidbindex_impl.h" | |
9 #include "chrome/renderer/renderer_webidbtransaction_impl.h" | |
10 #include "content/common/indexed_db_messages.h" | |
11 #include "content/common/serialized_script_value.h" | |
12 #include "content/renderer/indexed_db_dispatcher.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMStringList.h" | |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKey.h" | |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyRange.h" | |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h" | |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSerializedScriptVa
lue.h" | |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | |
19 | |
20 using WebKit::WebDOMStringList; | |
21 using WebKit::WebExceptionCode; | |
22 using WebKit::WebFrame; | |
23 using WebKit::WebIDBCallbacks; | |
24 using WebKit::WebIDBKeyRange; | |
25 using WebKit::WebIDBIndex; | |
26 using WebKit::WebIDBKey; | |
27 using WebKit::WebIDBTransaction; | |
28 using WebKit::WebSerializedScriptValue; | |
29 using WebKit::WebString; | |
30 | |
31 RendererWebIDBObjectStoreImpl::RendererWebIDBObjectStoreImpl( | |
32 int32 idb_object_store_id) | |
33 : idb_object_store_id_(idb_object_store_id) { | |
34 } | |
35 | |
36 RendererWebIDBObjectStoreImpl::~RendererWebIDBObjectStoreImpl() { | |
37 // It's not possible for there to be pending callbacks that address this | |
38 // object since inside WebKit, they hold a reference to the object wich owns | |
39 // this object. But, if that ever changed, then we'd need to invalidate | |
40 // any such pointers. | |
41 RenderThread::current()->Send( | |
42 new IndexedDBHostMsg_ObjectStoreDestroyed(idb_object_store_id_)); | |
43 } | |
44 | |
45 WebString RendererWebIDBObjectStoreImpl::name() const { | |
46 string16 result; | |
47 RenderThread::current()->Send( | |
48 new IndexedDBHostMsg_ObjectStoreName(idb_object_store_id_, &result)); | |
49 return result; | |
50 } | |
51 | |
52 WebString RendererWebIDBObjectStoreImpl::keyPath() const { | |
53 NullableString16 result; | |
54 RenderThread::current()->Send( | |
55 new IndexedDBHostMsg_ObjectStoreKeyPath(idb_object_store_id_, &result)); | |
56 return result; | |
57 } | |
58 | |
59 WebDOMStringList RendererWebIDBObjectStoreImpl::indexNames() const { | |
60 std::vector<string16> result; | |
61 RenderThread::current()->Send( | |
62 new IndexedDBHostMsg_ObjectStoreIndexNames( | |
63 idb_object_store_id_, &result)); | |
64 WebDOMStringList web_result; | |
65 for (std::vector<string16>::const_iterator it = result.begin(); | |
66 it != result.end(); ++it) { | |
67 web_result.append(*it); | |
68 } | |
69 return web_result; | |
70 } | |
71 | |
72 void RendererWebIDBObjectStoreImpl::get( | |
73 const WebIDBKey& key, | |
74 WebIDBCallbacks* callbacks, | |
75 const WebIDBTransaction& transaction, | |
76 WebExceptionCode& ec) { | |
77 IndexedDBDispatcher* dispatcher = | |
78 RenderThread::current()->indexed_db_dispatcher(); | |
79 dispatcher->RequestIDBObjectStoreGet( | |
80 IndexedDBKey(key), callbacks, idb_object_store_id_, transaction, &ec); | |
81 } | |
82 | |
83 void RendererWebIDBObjectStoreImpl::put( | |
84 const WebSerializedScriptValue& value, | |
85 const WebIDBKey& key, | |
86 PutMode put_mode, | |
87 WebIDBCallbacks* callbacks, | |
88 const WebIDBTransaction& transaction, | |
89 WebExceptionCode& ec) { | |
90 IndexedDBDispatcher* dispatcher = | |
91 RenderThread::current()->indexed_db_dispatcher(); | |
92 dispatcher->RequestIDBObjectStorePut( | |
93 SerializedScriptValue(value), IndexedDBKey(key), put_mode, callbacks, | |
94 idb_object_store_id_, transaction, &ec); | |
95 } | |
96 | |
97 void RendererWebIDBObjectStoreImpl::deleteFunction( | |
98 const WebIDBKey& key, | |
99 WebIDBCallbacks* callbacks, | |
100 const WebIDBTransaction& transaction, | |
101 WebExceptionCode& ec) { | |
102 IndexedDBDispatcher* dispatcher = | |
103 RenderThread::current()->indexed_db_dispatcher(); | |
104 dispatcher->RequestIDBObjectStoreDelete( | |
105 IndexedDBKey(key), callbacks, idb_object_store_id_, transaction, &ec); | |
106 } | |
107 | |
108 void RendererWebIDBObjectStoreImpl::clear( | |
109 WebIDBCallbacks* callbacks, | |
110 const WebIDBTransaction& transaction, | |
111 WebExceptionCode& ec) { | |
112 IndexedDBDispatcher* dispatcher = | |
113 RenderThread::current()->indexed_db_dispatcher(); | |
114 dispatcher->RequestIDBObjectStoreClear( | |
115 callbacks, idb_object_store_id_, transaction, &ec); | |
116 } | |
117 | |
118 WebIDBIndex* RendererWebIDBObjectStoreImpl::createIndex( | |
119 const WebString& name, | |
120 const WebString& key_path, | |
121 bool unique, | |
122 const WebIDBTransaction& transaction, | |
123 WebExceptionCode& ec) { | |
124 IndexedDBHostMsg_ObjectStoreCreateIndex_Params params; | |
125 params.name = name; | |
126 params.key_path = key_path; | |
127 params.unique = unique; | |
128 params.transaction_id = IndexedDBDispatcher::TransactionId(transaction); | |
129 params.idb_object_store_id = idb_object_store_id_; | |
130 | |
131 int32 index_id; | |
132 RenderThread::current()->Send( | |
133 new IndexedDBHostMsg_ObjectStoreCreateIndex(params, &index_id, &ec)); | |
134 if (!index_id) | |
135 return NULL; | |
136 return new RendererWebIDBIndexImpl(index_id); | |
137 } | |
138 | |
139 WebIDBIndex* RendererWebIDBObjectStoreImpl::index( | |
140 const WebString& name, | |
141 WebExceptionCode& ec) { | |
142 int32 idb_index_id; | |
143 RenderThread::current()->Send( | |
144 new IndexedDBHostMsg_ObjectStoreIndex(idb_object_store_id_, name, | |
145 &idb_index_id, &ec)); | |
146 if (!idb_index_id) | |
147 return NULL; | |
148 return new RendererWebIDBIndexImpl(idb_index_id); | |
149 } | |
150 | |
151 void RendererWebIDBObjectStoreImpl::deleteIndex( | |
152 const WebString& name, | |
153 const WebIDBTransaction& transaction, | |
154 WebExceptionCode& ec) { | |
155 RenderThread::current()->Send( | |
156 new IndexedDBHostMsg_ObjectStoreDeleteIndex( | |
157 idb_object_store_id_, name, | |
158 IndexedDBDispatcher::TransactionId(transaction), &ec)); | |
159 } | |
160 | |
161 void RendererWebIDBObjectStoreImpl::openCursor( | |
162 const WebIDBKeyRange& idb_key_range, | |
163 unsigned short direction, WebIDBCallbacks* callbacks, | |
164 const WebIDBTransaction& transaction, | |
165 WebExceptionCode& ec) { | |
166 IndexedDBDispatcher* dispatcher = | |
167 RenderThread::current()->indexed_db_dispatcher(); | |
168 dispatcher->RequestIDBObjectStoreOpenCursor( | |
169 idb_key_range, direction, callbacks, idb_object_store_id_, | |
170 transaction, &ec); | |
171 } | |
OLD | NEW |