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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
|
// Copyright (c) 2010 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 "chrome/browser/in_process_webkit/indexed_db_dispatcher_host.h"
#include "base/command_line.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/in_process_webkit/indexed_db_callbacks.h"
#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/browser/renderer_host/resource_message_filter.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/serialized_script_value.h"
#include "third_party/WebKit/WebKit/chromium/public/WebDOMStringList.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBCursor.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabase.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBDatabaseError.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBKeyRange.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBIndex.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBFactory.h"
#include "third_party/WebKit/WebKit/chromium/public/WebIDBObjectStore.h"
#include "third_party/WebKit/WebKit/chromium/public/WebSecurityOrigin.h"
using WebKit::WebDOMStringList;
using WebKit::WebIDBCursor;
using WebKit::WebIDBDatabase;
using WebKit::WebIDBDatabaseError;
using WebKit::WebIDBIndex;
using WebKit::WebIDBKey;
using WebKit::WebIDBKeyRange;
using WebKit::WebIDBObjectStore;
using WebKit::WebSecurityOrigin;
using WebKit::WebSerializedScriptValue;
IndexedDBDispatcherHost::IndexedDBDispatcherHost(
IPC::Message::Sender* sender, WebKitContext* webkit_context)
: sender_(sender),
webkit_context_(webkit_context),
ALLOW_THIS_IN_INITIALIZER_LIST(database_dispatcher_host_(
new DatabaseDispatcherHost(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(index_dispatcher_host_(
new IndexDispatcherHost(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(object_store_dispatcher_host_(
new ObjectStoreDispatcherHost(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(cursor_dispatcher_host_(
new CursorDispatcherHost(this))),
process_handle_(0) {
DCHECK(sender_);
DCHECK(webkit_context_.get());
}
IndexedDBDispatcherHost::~IndexedDBDispatcherHost() {
}
void IndexedDBDispatcherHost::Init(int process_id,
base::ProcessHandle process_handle) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(sender_); // Ensure Shutdown() has not been called.
DCHECK(!process_handle_); // Make sure Init() has not yet been called.
DCHECK(process_handle);
process_id_ = process_id;
process_handle_ = process_handle;
}
void IndexedDBDispatcherHost::Shutdown() {
if (ChromeThread::CurrentlyOn(ChromeThread::IO)) {
sender_ = NULL;
bool success = ChromeThread::PostTask(
ChromeThread::WEBKIT, FROM_HERE,
NewRunnableMethod(this, &IndexedDBDispatcherHost::Shutdown));
if (success)
return;
}
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT) ||
CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess));
DCHECK(!sender_);
database_dispatcher_host_.reset();
index_dispatcher_host_.reset();
}
bool IndexedDBDispatcherHost::OnMessageReceived(const IPC::Message& message) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(process_handle_);
switch (message.type()) {
case ViewHostMsg_IDBCursorDestroyed::ID:
case ViewHostMsg_IDBCursorDirection::ID:
case ViewHostMsg_IDBCursorKey::ID:
case ViewHostMsg_IDBCursorValue::ID:
case ViewHostMsg_IDBFactoryOpen::ID:
case ViewHostMsg_IDBDatabaseName::ID:
case ViewHostMsg_IDBDatabaseDescription::ID:
case ViewHostMsg_IDBDatabaseVersion::ID:
case ViewHostMsg_IDBDatabaseObjectStores::ID:
case ViewHostMsg_IDBDatabaseCreateObjectStore::ID:
case ViewHostMsg_IDBDatabaseObjectStore::ID:
case ViewHostMsg_IDBDatabaseRemoveObjectStore::ID:
case ViewHostMsg_IDBDatabaseDestroyed::ID:
case ViewHostMsg_IDBIndexName::ID:
case ViewHostMsg_IDBIndexKeyPath::ID:
case ViewHostMsg_IDBIndexUnique::ID:
case ViewHostMsg_IDBIndexDestroyed::ID:
case ViewHostMsg_IDBObjectStoreName::ID:
case ViewHostMsg_IDBObjectStoreKeyPath::ID:
case ViewHostMsg_IDBObjectStoreIndexNames::ID:
case ViewHostMsg_IDBObjectStoreGet::ID:
case ViewHostMsg_IDBObjectStoreOpenCursor::ID:
case ViewHostMsg_IDBObjectStorePut::ID:
case ViewHostMsg_IDBObjectStoreRemove::ID:
case ViewHostMsg_IDBObjectStoreCreateIndex::ID:
case ViewHostMsg_IDBObjectStoreIndex::ID:
case ViewHostMsg_IDBObjectStoreRemoveIndex::ID:
case ViewHostMsg_IDBObjectStoreDestroyed::ID:
break;
default:
return false;
}
bool success = ChromeThread::PostTask(
ChromeThread::WEBKIT, FROM_HERE, NewRunnableMethod(
this, &IndexedDBDispatcherHost::OnMessageReceivedWebKit, message));
DCHECK(success);
return true;
}
void IndexedDBDispatcherHost::Send(IPC::Message* message) {
if (!ChromeThread::CurrentlyOn(ChromeThread::IO)) {
// TODO(jorlow): Even if we successfully post, I believe it's possible for
// the task to never run (if the IO thread is already shutting
// down). We may want to handle this case, though
// realistically it probably doesn't matter.
if (!ChromeThread::PostTask(
ChromeThread::IO, FROM_HERE, NewRunnableMethod(
this, &IndexedDBDispatcherHost::Send, message))) {
// The IO thread is dead.
delete message;
}
return;
}
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (!sender_)
delete message;
else
sender_->Send(message);
}
void IndexedDBDispatcherHost::OnMessageReceivedWebKit(
const IPC::Message& message) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
DCHECK(process_handle_);
bool msg_is_ok = true;
bool handled =
database_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
index_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
object_store_dispatcher_host_->OnMessageReceived(message, &msg_is_ok) ||
cursor_dispatcher_host_->OnMessageReceived(message, &msg_is_ok);
if (!handled) {
handled = true;
DCHECK(msg_is_ok);
IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost, message, msg_is_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBFactoryOpen,
OnIDBFactoryOpen)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
}
DCHECK(handled);
if (!msg_is_ok) {
BrowserRenderProcessHost::BadMessageTerminateProcess(message.type(),
process_handle_);
}
}
int32 IndexedDBDispatcherHost::Add(WebIDBCursor* idb_cursor) {
return cursor_dispatcher_host_->map_.Add(idb_cursor);
}
int32 IndexedDBDispatcherHost::Add(WebIDBDatabase* idb_database) {
return database_dispatcher_host_->map_.Add(idb_database);
}
int32 IndexedDBDispatcherHost::Add(WebIDBIndex* idb_index) {
return index_dispatcher_host_->map_.Add(idb_index);
}
int32 IndexedDBDispatcherHost::Add(WebIDBObjectStore* idb_object_store) {
return object_store_dispatcher_host_->map_.Add(idb_object_store);
}
void IndexedDBDispatcherHost::OnIDBFactoryOpen(
const ViewHostMsg_IDBFactoryOpen_Params& params) {
// TODO(jorlow): Check the content settings map and use params.routing_id_
// if it's necessary to ask the user for permission.
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
Context()->GetIDBFactory()->open(
params.name_, params.description_,
new IndexedDBCallbacks<WebIDBDatabase>(this, params.response_id_),
WebSecurityOrigin::createFromDatabaseIdentifier(params.origin_), NULL);
}
//////////////////////////////////////////////////////////////////////
// Helper templates.
//
template <typename ObjectType>
ObjectType* IndexedDBDispatcherHost::GetOrTerminateProcess(
IDMap<ObjectType, IDMapOwnPointer>* map, int32 return_object_id,
IPC::Message* reply_msg, uint32 message_type) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
ObjectType* return_object = map->Lookup(return_object_id);
if (!return_object) {
BrowserRenderProcessHost::BadMessageTerminateProcess(message_type,
process_handle_);
delete reply_msg;
}
return return_object;
}
template <typename ReplyType, typename MessageType,
typename MapObjectType, typename Method>
void IndexedDBDispatcherHost::SyncGetter(
IDMap<MapObjectType, IDMapOwnPointer>* map, int32 object_id,
IPC::Message* reply_msg, Method method) {
MapObjectType* object = GetOrTerminateProcess(map, object_id, reply_msg,
MessageType::ID);
if (!object)
return;
ReplyType reply = (object->*method)();
MessageType::WriteReplyParams(reply_msg, reply);
Send(reply_msg);
}
template <typename ObjectType>
void IndexedDBDispatcherHost::DestroyObject(
IDMap<ObjectType, IDMapOwnPointer>* map, int32 object_id,
uint32 message_type) {
GetOrTerminateProcess(map, object_id, NULL, message_type);
map->Remove(object_id);
}
//////////////////////////////////////////////////////////////////////
// IndexedDBDispatcherHost::DatabaseDispatcherHost
//
IndexedDBDispatcherHost::DatabaseDispatcherHost::DatabaseDispatcherHost(
IndexedDBDispatcherHost* parent)
: parent_(parent) {
}
IndexedDBDispatcherHost::DatabaseDispatcherHost::~DatabaseDispatcherHost() {
}
bool IndexedDBDispatcherHost::DatabaseDispatcherHost::OnMessageReceived(
const IPC::Message& message, bool* msg_is_ok) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::DatabaseDispatcherHost,
message, *msg_is_ok)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseName, OnName)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseDescription,
OnDescription)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseVersion, OnVersion)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseObjectStores,
OnObjectStores)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseCreateObjectStore,
OnCreateObjectStore)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBDatabaseObjectStore,
OnObjectStore)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseRemoveObjectStore,
OnRemoveObjectStore)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBDatabaseDestroyed, OnDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::Send(
IPC::Message* message) {
// The macro magic in OnMessageReceived requires this to link, but it should
// never actually be called.
NOTREACHED();
parent_->Send(message);
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnName(
int32 object_id, IPC::Message* reply_msg) {
parent_->SyncGetter<string16, ViewHostMsg_IDBDatabaseName>(
&map_, object_id, reply_msg, &WebIDBDatabase::name);
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDescription(
int32 object_id, IPC::Message* reply_msg) {
parent_->SyncGetter<string16, ViewHostMsg_IDBDatabaseDescription>(
&map_, object_id, reply_msg, &WebIDBDatabase::description);
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnVersion(
int32 object_id, IPC::Message* reply_msg) {
parent_->SyncGetter<string16, ViewHostMsg_IDBDatabaseVersion>(
&map_, object_id, reply_msg, &WebIDBDatabase::version);
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObjectStores(
int32 idb_database_id, IPC::Message* reply_msg) {
WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
&map_, idb_database_id, reply_msg,
ViewHostMsg_IDBDatabaseObjectStores::ID);
if (!idb_database)
return;
WebDOMStringList web_object_stores = idb_database->objectStores();
std::vector<string16> object_stores;
object_stores.reserve(web_object_stores.length());
for (unsigned i = 0; i < web_object_stores.length(); ++i)
object_stores.push_back(web_object_stores.item(i));
ViewHostMsg_IDBDatabaseObjectStores::WriteReplyParams(reply_msg,
object_stores);
parent_->Send(reply_msg);
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnCreateObjectStore(
const ViewHostMsg_IDBDatabaseCreateObjectStore_Params& params) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
&map_, params.idb_database_id_, NULL,
ViewHostMsg_IDBDatabaseCreateObjectStore::ID);
if (!idb_database)
return;
idb_database->createObjectStore(
params.name_, params.key_path_, params.auto_increment_,
new IndexedDBCallbacks<WebIDBObjectStore>(parent_, params.response_id_));
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnObjectStore(
int32 idb_database_id, const string16& name, int32 mode,
IPC::Message* reply_msg) {
WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
&map_, idb_database_id, reply_msg,
ViewHostMsg_IDBDatabaseObjectStore::ID);
if (!idb_database)
return;
WebIDBObjectStore* object_store = idb_database->objectStore(name, mode);
int32 object_id = object_store ? parent_->Add(object_store) : 0;
ViewHostMsg_IDBDatabaseObjectStore::WriteReplyParams(
reply_msg, !!object_store, object_id);
parent_->Send(reply_msg);
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnRemoveObjectStore(
int32 idb_database_id, int32 response_id, const string16& name) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBDatabase* idb_database = parent_->GetOrTerminateProcess(
&map_, idb_database_id, NULL,
ViewHostMsg_IDBDatabaseRemoveObjectStore::ID);
if (!idb_database)
return;
idb_database->removeObjectStore(
name, new IndexedDBCallbacks<WebIDBObjectStore>(parent_, response_id));
}
void IndexedDBDispatcherHost::DatabaseDispatcherHost::OnDestroyed(
int32 object_id) {
parent_->DestroyObject(&map_, object_id,
ViewHostMsg_IDBDatabaseDestroyed::ID);
}
//////////////////////////////////////////////////////////////////////
// IndexedDBDispatcherHost::IndexDispatcherHost
//
IndexedDBDispatcherHost::IndexDispatcherHost::IndexDispatcherHost(
IndexedDBDispatcherHost* parent)
: parent_(parent) {
}
IndexedDBDispatcherHost::IndexDispatcherHost::~IndexDispatcherHost() {
}
bool IndexedDBDispatcherHost::IndexDispatcherHost::OnMessageReceived(
const IPC::Message& message, bool* msg_is_ok) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::IndexDispatcherHost,
message, *msg_is_ok)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBIndexName, OnName)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBIndexKeyPath, OnKeyPath)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBIndexUnique, OnUnique)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBIndexDestroyed, OnDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void IndexedDBDispatcherHost::IndexDispatcherHost::Send(
IPC::Message* message) {
// The macro magic in OnMessageReceived requires this to link, but it should
// never actually be called.
NOTREACHED();
parent_->Send(message);
}
void IndexedDBDispatcherHost::IndexDispatcherHost::OnName(
int32 object_id, IPC::Message* reply_msg) {
parent_->SyncGetter<string16, ViewHostMsg_IDBIndexName>(
&map_, object_id, reply_msg, &WebIDBIndex::name);
}
void IndexedDBDispatcherHost::IndexDispatcherHost::OnKeyPath(
int32 object_id, IPC::Message* reply_msg) {
parent_->SyncGetter<NullableString16, ViewHostMsg_IDBIndexKeyPath>(
&map_, object_id, reply_msg, &WebIDBIndex::keyPath);
}
void IndexedDBDispatcherHost::IndexDispatcherHost::OnUnique(
int32 object_id, IPC::Message* reply_msg) {
parent_->SyncGetter<bool, ViewHostMsg_IDBIndexUnique>(
&map_, object_id, reply_msg, &WebIDBIndex::unique);
}
void IndexedDBDispatcherHost::IndexDispatcherHost::OnDestroyed(
int32 object_id) {
parent_->DestroyObject(&map_, object_id, ViewHostMsg_IDBIndexDestroyed::ID);
}
//////////////////////////////////////////////////////////////////////
// IndexedDBDispatcherHost::ObjectStoreDispatcherHost
//
IndexedDBDispatcherHost::ObjectStoreDispatcherHost::ObjectStoreDispatcherHost(
IndexedDBDispatcherHost* parent)
: parent_(parent) {
}
IndexedDBDispatcherHost::
ObjectStoreDispatcherHost::~ObjectStoreDispatcherHost() {
}
bool IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnMessageReceived(
const IPC::Message& message, bool* msg_is_ok) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::ObjectStoreDispatcherHost,
message, *msg_is_ok)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreName, OnName)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreKeyPath,
OnKeyPath)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreIndexNames,
OnIndexNames)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreGet, OnGet);
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStorePut, OnPut);
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreRemove, OnRemove);
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreCreateIndex, OnCreateIndex);
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBObjectStoreIndex, OnIndex);
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreRemoveIndex, OnRemoveIndex);
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreDestroyed, OnDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::Send(
IPC::Message* message) {
// The macro magic in OnMessageReceived requires this to link, but it should
// never actually be called.
NOTREACHED();
parent_->Send(message);
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnName(
int32 object_id, IPC::Message* reply_msg) {
parent_->SyncGetter<string16, ViewHostMsg_IDBObjectStoreName>(
&map_, object_id, reply_msg, &WebIDBObjectStore::name);
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnKeyPath(
int32 object_id, IPC::Message* reply_msg) {
parent_->SyncGetter<NullableString16, ViewHostMsg_IDBObjectStoreKeyPath>(
&map_, object_id, reply_msg, &WebIDBObjectStore::keyPath);
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnIndexNames(
int32 idb_object_store_id, IPC::Message* reply_msg) {
WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
&map_, idb_object_store_id, reply_msg,
ViewHostMsg_IDBObjectStoreIndexNames::ID);
if (!idb_object_store)
return;
WebDOMStringList web_index_names = idb_object_store->indexNames();
std::vector<string16> index_names;
index_names.reserve(web_index_names.length());
for (unsigned i = 0; i < web_index_names.length(); ++i)
index_names[i] = web_index_names.item(i);
ViewHostMsg_IDBObjectStoreIndexNames::WriteReplyParams(reply_msg,
index_names);
parent_->Send(reply_msg);
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnGet(
int idb_object_store_id, int32 response_id, const IndexedDBKey& key) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
&map_, idb_object_store_id, NULL, ViewHostMsg_IDBObjectStoreGet::ID);
if (!idb_object_store)
return;
idb_object_store->get(key, new IndexedDBCallbacks<WebSerializedScriptValue>(
parent_, response_id));
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnPut(
int idb_object_store_id, int32 response_id,
const SerializedScriptValue& value, const IndexedDBKey& key,
bool add_only) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
&map_, idb_object_store_id, NULL, ViewHostMsg_IDBObjectStorePut::ID);
if (!idb_object_store)
return;
idb_object_store->put(
value, key, add_only, new IndexedDBCallbacks<WebIDBKey>(
parent_, response_id));
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnRemove(
int idb_object_store_id, int32 response_id, const IndexedDBKey& key) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
&map_, idb_object_store_id, NULL, ViewHostMsg_IDBObjectStoreRemove::ID);
if (!idb_object_store)
return;
idb_object_store->remove(key, new IndexedDBCallbacks<void>(parent_,
response_id));
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnCreateIndex(
const ViewHostMsg_IDBObjectStoreCreateIndex_Params& params) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
&map_, params.idb_object_store_id_, NULL,
ViewHostMsg_IDBObjectStoreCreateIndex::ID);
if (!idb_object_store)
return;
idb_object_store->createIndex(
params.name_, params.key_path_, params.unique_,
new IndexedDBCallbacks<WebIDBIndex>(parent_, params.response_id_));
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnIndex(
int32 idb_object_store_id, const string16& name, IPC::Message* reply_msg) {
WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
&map_, idb_object_store_id, reply_msg,
ViewHostMsg_IDBObjectStoreIndex::ID);
if (!idb_object_store)
return;
WebIDBIndex* index = idb_object_store->index(name);
int32 object_id = index ? parent_->Add(index) : 0;
ViewHostMsg_IDBObjectStoreIndex::WriteReplyParams(reply_msg, !!index,
object_id);
parent_->Send(reply_msg);
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnRemoveIndex(
int32 idb_object_store_id, int32 response_id, const string16& name) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
&map_, idb_object_store_id, NULL,
ViewHostMsg_IDBObjectStoreRemoveIndex::ID);
if (!idb_object_store)
return;
idb_object_store->removeIndex(
name, new IndexedDBCallbacks<void>(parent_, response_id));
}
void IndexedDBDispatcherHost::ObjectStoreDispatcherHost::OnDestroyed(
int32 object_id) {
parent_->DestroyObject(
&map_, object_id, ViewHostMsg_IDBObjectStoreDestroyed::ID);
}
//////////////////////////////////////////////////////////////////////
// IndexedDBDispatcherHost::CursorDispatcherHost
//
IndexedDBDispatcherHost::CursorDispatcherHost::CursorDispatcherHost(
IndexedDBDispatcherHost* parent)
: parent_(parent) {
}
IndexedDBDispatcherHost::CursorDispatcherHost::~CursorDispatcherHost() {
}
bool IndexedDBDispatcherHost::CursorDispatcherHost::OnMessageReceived(
const IPC::Message& message, bool* msg_is_ok) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP_EX(IndexedDBDispatcherHost::CursorDispatcherHost,
message, *msg_is_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBObjectStoreOpenCursor, OnOpenCursor)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBCursorDirection,
OnDirection)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBCursorKey, OnKey)
IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_IDBCursorValue, OnValue)
IPC_MESSAGE_HANDLER(ViewHostMsg_IDBCursorDestroyed, OnDestroyed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void IndexedDBDispatcherHost::CursorDispatcherHost::Send(
IPC::Message* message) {
// The macro magic in OnMessageReceived requires this to link, but it should
// never actually be called.
NOTREACHED();
parent_->Send(message);
}
void IndexedDBDispatcherHost::CursorDispatcherHost::OnOpenCursor(
const ViewHostMsg_IDBObjectStoreOpenCursor_Params& params) {
DCHECK(ChromeThread::CurrentlyOn(ChromeThread::WEBKIT));
WebIDBObjectStore* idb_object_store = parent_->GetOrTerminateProcess(
&parent_->object_store_dispatcher_host_->map_,
params.idb_object_store_id_, NULL,
ViewHostMsg_IDBObjectStoreOpenCursor::ID);
if (!idb_object_store)
return;
idb_object_store->openCursor(
WebIDBKeyRange(params.left_key_, params.right_key_, params.flags_),
params.direction_,
new IndexedDBCallbacks<WebIDBCursor>(parent_, params.response_id_));
}
void IndexedDBDispatcherHost::CursorDispatcherHost::OnDirection(
int32 object_id, IPC::Message* reply_msg) {
WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(
&map_, object_id, reply_msg,
ViewHostMsg_IDBCursorDirection::ID);
if (!idb_cursor)
return;
int direction = idb_cursor->direction();
ViewHostMsg_IDBCursorDirection::WriteReplyParams(reply_msg, direction);
parent_->Send(reply_msg);
}
void IndexedDBDispatcherHost::CursorDispatcherHost::OnKey(
int32 object_id, IPC::Message* reply_msg) {
WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(
&map_, object_id, reply_msg,
ViewHostMsg_IDBCursorKey::ID);
if (!idb_cursor)
return;
IndexedDBKey key(idb_cursor->key());
ViewHostMsg_IDBCursorKey::WriteReplyParams(reply_msg, key);
parent_->Send(reply_msg);
}
void IndexedDBDispatcherHost::CursorDispatcherHost::OnValue(
int32 object_id, IPC::Message* reply_msg) {
WebIDBCursor* idb_cursor = parent_->GetOrTerminateProcess(
&map_, object_id, reply_msg,
ViewHostMsg_IDBCursorValue::ID);
if (!idb_cursor)
return;
SerializedScriptValue value(idb_cursor->value());
ViewHostMsg_IDBCursorValue::WriteReplyParams(reply_msg, value);
parent_->Send(reply_msg);
}
void IndexedDBDispatcherHost::CursorDispatcherHost::OnDestroyed(
int32 object_id) {
parent_->DestroyObject(
&map_, object_id, ViewHostMsg_IDBCursorDestroyed::ID);
}
|