OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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 "content/renderer/indexed_db/renderer_webidbdatabase_impl.h" | |
6 | |
7 #include "content/common/indexed_db/indexed_db_messages.h" | |
8 #include "content/renderer/indexed_db/indexed_db_dispatcher.h" | |
9 #include "content/renderer/indexed_db/renderer_webidbobjectstore_impl.h" | |
10 #include "content/renderer/indexed_db/renderer_webidbtransaction_impl.h" | |
11 #include "content/renderer/render_thread_impl.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | |
13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" | |
14 #include "webkit/glue/worker_task_runner.h" | |
15 | |
16 using WebKit::WebDOMStringList; | |
17 using WebKit::WebExceptionCode; | |
18 using WebKit::WebFrame; | |
19 using WebKit::WebIDBCallbacks; | |
20 using WebKit::WebIDBDatabaseCallbacks; | |
21 using WebKit::WebIDBTransaction; | |
22 using WebKit::WebString; | |
23 using WebKit::WebVector; | |
24 using webkit_glue::WorkerTaskRunner; | |
25 | |
26 RendererWebIDBDatabaseImpl::RendererWebIDBDatabaseImpl(int32 idb_database_id) | |
27 : idb_database_id_(idb_database_id) { | |
28 } | |
29 | |
30 RendererWebIDBDatabaseImpl::~RendererWebIDBDatabaseImpl() { | |
31 // It's not possible for there to be pending callbacks that address this | |
32 // object since inside WebKit, they hold a reference to the object which owns | |
33 // this object. But, if that ever changed, then we'd need to invalidate | |
34 // any such pointers. | |
35 ChildThread::current()->Send(new IndexedDBHostMsg_DatabaseDestroyed( | |
36 idb_database_id_)); | |
37 } | |
38 | |
39 WebString RendererWebIDBDatabaseImpl::name() const { | |
40 string16 result; | |
41 ChildThread::current()->Send( | |
42 new IndexedDBHostMsg_DatabaseName(idb_database_id_, &result)); | |
43 return result; | |
44 } | |
45 | |
46 WebString RendererWebIDBDatabaseImpl::version() const { | |
47 string16 result; | |
48 ChildThread::current()->Send( | |
49 new IndexedDBHostMsg_DatabaseVersion(idb_database_id_, &result)); | |
50 return result; | |
51 } | |
52 | |
53 WebDOMStringList RendererWebIDBDatabaseImpl::objectStoreNames() const { | |
54 std::vector<string16> result; | |
55 ChildThread::current()->Send( | |
56 new IndexedDBHostMsg_DatabaseObjectStoreNames(idb_database_id_, &result)); | |
57 WebDOMStringList webResult; | |
58 for (std::vector<string16>::const_iterator it = result.begin(); | |
59 it != result.end(); ++it) { | |
60 webResult.append(*it); | |
61 } | |
62 return webResult; | |
63 } | |
64 | |
65 WebKit::WebIDBObjectStore* RendererWebIDBDatabaseImpl::createObjectStore( | |
66 const WebKit::WebString& name, | |
67 const WebKit::WebString& key_path, | |
68 bool auto_increment, | |
69 const WebKit::WebIDBTransaction& transaction, | |
70 WebExceptionCode& ec) { | |
71 IndexedDBHostMsg_DatabaseCreateObjectStore_Params params; | |
72 params.name = name; | |
73 params.key_path = key_path; | |
74 params.auto_increment = auto_increment; | |
75 params.transaction_id = IndexedDBDispatcher::TransactionId(transaction); | |
76 params.idb_database_id = idb_database_id_; | |
77 | |
78 int object_store; | |
79 ChildThread::current()->Send( | |
80 new IndexedDBHostMsg_DatabaseCreateObjectStore( | |
81 params, &object_store, &ec)); | |
82 if (!object_store) | |
83 return NULL; | |
84 return new RendererWebIDBObjectStoreImpl(object_store); | |
85 } | |
86 | |
87 void RendererWebIDBDatabaseImpl::deleteObjectStore( | |
88 const WebString& name, | |
89 const WebIDBTransaction& transaction, | |
90 WebExceptionCode& ec) { | |
91 ChildThread::current()->Send( | |
92 new IndexedDBHostMsg_DatabaseDeleteObjectStore( | |
93 idb_database_id_, name, | |
94 IndexedDBDispatcher::TransactionId(transaction), &ec)); | |
95 } | |
96 | |
97 void RendererWebIDBDatabaseImpl::setVersion( | |
98 const WebString& version, | |
99 WebIDBCallbacks* callbacks, | |
100 WebExceptionCode& ec) { | |
101 IndexedDBDispatcher* dispatcher = | |
102 IndexedDBDispatcher::ThreadSpecificInstance(); | |
103 dispatcher->RequestIDBDatabaseSetVersion( | |
104 version, callbacks, idb_database_id_, &ec); | |
105 } | |
106 | |
107 WebKit::WebIDBTransaction* RendererWebIDBDatabaseImpl::transaction( | |
108 const WebDOMStringList& names, | |
109 unsigned short mode, | |
110 WebExceptionCode& ec) { | |
111 std::vector<string16> object_stores; | |
112 object_stores.reserve(names.length()); | |
113 for (unsigned int i = 0; i < names.length(); ++i) | |
114 object_stores.push_back(names.item(i)); | |
115 | |
116 int transaction_id; | |
117 ChildThread::current()->Send(new IndexedDBHostMsg_DatabaseTransaction( | |
118 WorkerTaskRunner::Instance()->CurrentWorkerId(), | |
119 idb_database_id_, object_stores, mode, &transaction_id, &ec)); | |
120 if (!transaction_id) | |
121 return NULL; | |
122 return new RendererWebIDBTransactionImpl(transaction_id); | |
123 } | |
124 | |
125 void RendererWebIDBDatabaseImpl::close() { | |
126 IndexedDBDispatcher* dispatcher = | |
127 IndexedDBDispatcher::ThreadSpecificInstance(); | |
128 dispatcher->RequestIDBDatabaseClose(idb_database_id_); | |
129 } | |
130 | |
131 void RendererWebIDBDatabaseImpl::open(WebIDBDatabaseCallbacks* callbacks) { | |
132 IndexedDBDispatcher* dispatcher = | |
133 IndexedDBDispatcher::ThreadSpecificInstance(); | |
134 DCHECK(dispatcher); | |
135 dispatcher->RequestIDBDatabaseOpen(callbacks, idb_database_id_); | |
136 } | |
OLD | NEW |