summaryrefslogtreecommitdiffstats
path: root/content/common/indexed_db/proxy_webidbdatabase_impl.cc
blob: d9074dc9a27e1e6918b36414aa1f5217ec131019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/common/indexed_db/proxy_webidbdatabase_impl.h"

#include <vector>

#include "content/common/child_thread.h"
#include "content/common/indexed_db/indexed_db_messages.h"
#include "content/common/indexed_db/indexed_db_dispatcher.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebVector.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyPath.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBMetadata.h"
#include "webkit/glue/worker_task_runner.h"

using WebKit::WebDOMStringList;
using WebKit::WebExceptionCode;
using WebKit::WebFrame;
using WebKit::WebIDBCallbacks;
using WebKit::WebIDBDatabaseCallbacks;
using WebKit::WebIDBMetadata;
using WebKit::WebIDBKeyPath;
using WebKit::WebString;
using WebKit::WebVector;
using webkit_glue::WorkerTaskRunner;

namespace content {

RendererWebIDBDatabaseImpl::RendererWebIDBDatabaseImpl(int32 ipc_database_id)
    : ipc_database_id_(ipc_database_id) {
}

RendererWebIDBDatabaseImpl::~RendererWebIDBDatabaseImpl() {
  // It's not possible for there to be pending callbacks that address this
  // object since inside WebKit, they hold a reference to the object which owns
  // this object. But, if that ever changed, then we'd need to invalidate
  // any such pointers.
  IndexedDBDispatcher::Send(new IndexedDBHostMsg_DatabaseDestroyed(
      ipc_database_id_));
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->DatabaseDestroyed(ipc_database_id_);
}

void RendererWebIDBDatabaseImpl::createObjectStore(
    long long transaction_id,
    long long object_store_id,
    const WebKit::WebString& name,
    const WebKit::WebIDBKeyPath& key_path,
    bool auto_increment) {
  IndexedDBHostMsg_DatabaseCreateObjectStore_Params params;
  params.ipc_database_id = ipc_database_id_;
  params.transaction_id = transaction_id;
  params.object_store_id = object_store_id;
  params.name = name;
  params.key_path = IndexedDBKeyPath(key_path);
  params.auto_increment = auto_increment;

  IndexedDBDispatcher::Send(
      new IndexedDBHostMsg_DatabaseCreateObjectStore(params));
}

void RendererWebIDBDatabaseImpl::deleteObjectStore(
    long long transaction_id,
    long long object_store_id) {
  IndexedDBDispatcher::Send(
      new IndexedDBHostMsg_DatabaseDeleteObjectStore(
          ipc_database_id_,
          transaction_id,
          object_store_id));
}

void RendererWebIDBDatabaseImpl::createTransaction(
    long long transaction_id,
    WebKit::WebIDBDatabaseCallbacks* callbacks,
    const WebVector<long long>& object_store_ids,
    unsigned short mode)
{
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabaseCreateTransaction(ipc_database_id_,
                                                  transaction_id,
                                                  callbacks,
                                                  object_store_ids,
                                                  mode);
}

void RendererWebIDBDatabaseImpl::close() {
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabaseClose(ipc_database_id_);
}

void RendererWebIDBDatabaseImpl::get(
    long long transaction_id,
    long long object_store_id,
    long long index_id,
    const WebKit::WebIDBKeyRange& key_range,
    bool key_only,
    WebIDBCallbacks* callbacks) {
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabaseGet(
      ipc_database_id_, transaction_id, object_store_id, index_id,
      IndexedDBKeyRange(key_range), key_only, callbacks);
}

void RendererWebIDBDatabaseImpl::put(
    long long transaction_id,
    long long object_store_id,
    WebVector<unsigned char>* value,
    const WebKit::WebIDBKey& key,
    PutMode put_mode,
    WebIDBCallbacks* callbacks,
    const WebVector<long long>& web_index_ids,
    const WebVector<WebIndexKeys>& web_index_keys) {
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabasePutOld(
      ipc_database_id_, transaction_id, object_store_id,
      value, IndexedDBKey(key), put_mode, callbacks,
      web_index_ids, web_index_keys);
}

void RendererWebIDBDatabaseImpl::put(
    long long transaction_id,
    long long object_store_id,
    const WebKit::WebData& value,
    const WebKit::WebIDBKey& key,
    PutMode put_mode,
    WebIDBCallbacks* callbacks,
    const WebVector<long long>& web_index_ids,
    const WebVector<WebIndexKeys>& web_index_keys) {
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabasePut(
      ipc_database_id_, transaction_id, object_store_id,
      value, IndexedDBKey(key), put_mode, callbacks,
      web_index_ids, web_index_keys);
}

void RendererWebIDBDatabaseImpl::setIndexKeys(
    long long transaction_id,
    long long object_store_id,
    const WebKit::WebIDBKey& primary_key,
    const WebVector<long long>& index_ids,
    const WebVector<WebIndexKeys>& index_keys) {
  IndexedDBHostMsg_DatabaseSetIndexKeys_Params params;
  params.ipc_database_id = ipc_database_id_;
  params.transaction_id = transaction_id;
  params.object_store_id = object_store_id;
  params.primary_key = IndexedDBKey(primary_key);
  COMPILE_ASSERT(sizeof(params.index_ids[0]) ==
                 sizeof(index_ids[0]), Cant_copy);
  params.index_ids.assign(index_ids.data(),
                          index_ids.data() + index_ids.size());

  params.index_keys.resize(index_keys.size());
  for (size_t i = 0; i < index_keys.size(); ++i) {
    params.index_keys[i].resize(index_keys[i].size());
    for (size_t j = 0; j < index_keys[i].size(); ++j) {
      params.index_keys[i][j] = content::IndexedDBKey(index_keys[i][j]);
    }
  }
  IndexedDBDispatcher::Send(new IndexedDBHostMsg_DatabaseSetIndexKeys(
      params));
}

void RendererWebIDBDatabaseImpl::setIndexesReady(
    long long transaction_id,
    long long object_store_id,
    const WebVector<long long>& web_index_ids) {
  std::vector<int64> index_ids(web_index_ids.data(),
                               web_index_ids.data() + web_index_ids.size());
  IndexedDBDispatcher::Send(new IndexedDBHostMsg_DatabaseSetIndexesReady(
      ipc_database_id_, transaction_id, object_store_id, index_ids));
}

void RendererWebIDBDatabaseImpl::openCursor(
    long long transaction_id,
    long long object_store_id,
    long long index_id,
    const WebKit::WebIDBKeyRange& key_range,
    unsigned short direction,
    bool key_only,
    TaskType task_type,
    WebIDBCallbacks* callbacks) {
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabaseOpenCursor(
      ipc_database_id_,
      transaction_id, object_store_id, index_id,
      IndexedDBKeyRange(key_range), direction, key_only, task_type, callbacks);
}

void RendererWebIDBDatabaseImpl::count(
    long long transaction_id,
    long long object_store_id,
    long long index_id,
    const WebKit::WebIDBKeyRange& key_range,
    WebIDBCallbacks* callbacks) {
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabaseCount(
      ipc_database_id_,
      transaction_id, object_store_id, index_id,
      IndexedDBKeyRange(key_range), callbacks);
}

void RendererWebIDBDatabaseImpl::deleteRange(
    long long transaction_id,
    long long object_store_id,
    const WebKit::WebIDBKeyRange& key_range,
    WebIDBCallbacks* callbacks) {
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabaseDeleteRange(
      ipc_database_id_,
      transaction_id, object_store_id,
      IndexedDBKeyRange(key_range), callbacks);
}

void RendererWebIDBDatabaseImpl::clear(
    long long transaction_id,
    long long object_store_id,
    WebIDBCallbacks* callbacks) {
  IndexedDBDispatcher* dispatcher =
      IndexedDBDispatcher::ThreadSpecificInstance();
  dispatcher->RequestIDBDatabaseClear(
      ipc_database_id_,
      transaction_id, object_store_id, callbacks);
}

void RendererWebIDBDatabaseImpl::createIndex(
    long long transaction_id,
    long long object_store_id,
    long long index_id,
    const WebString& name,
    const WebIDBKeyPath& key_path,
    bool unique,
    bool multi_entry)
{
  IndexedDBHostMsg_DatabaseCreateIndex_Params params;
  params.ipc_database_id = ipc_database_id_;
  params.transaction_id = transaction_id;
  params.object_store_id = object_store_id;
  params.index_id = index_id;
  params.name = name;
  params.key_path = IndexedDBKeyPath(key_path);
  params.unique = unique;
  params.multi_entry = multi_entry;

  IndexedDBDispatcher::Send(
      new IndexedDBHostMsg_DatabaseCreateIndex(params));
}

void RendererWebIDBDatabaseImpl::deleteIndex(
    long long transaction_id,
    long long object_store_id,
    long long index_id)
{
  IndexedDBDispatcher::Send(
      new IndexedDBHostMsg_DatabaseDeleteIndex(
          ipc_database_id_,
          transaction_id,
          object_store_id, index_id));
}

void RendererWebIDBDatabaseImpl::abort(long long transaction_id) {
  IndexedDBDispatcher::Send(new IndexedDBHostMsg_DatabaseAbort(
      ipc_database_id_, transaction_id));
}

void RendererWebIDBDatabaseImpl::commit(long long transaction_id) {
  IndexedDBDispatcher::Send(new IndexedDBHostMsg_DatabaseCommit(
      ipc_database_id_, transaction_id));
}

}  // namespace content