|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 |
|
6 #include "IndexedDBParent.h" |
|
7 |
|
8 #include "nsIDOMEvent.h" |
|
9 #include "nsIDOMFile.h" |
|
10 #include "nsIXPConnect.h" |
|
11 |
|
12 #include "mozilla/AppProcessChecker.h" |
|
13 #include "mozilla/Assertions.h" |
|
14 #include "mozilla/Attributes.h" |
|
15 #include "mozilla/dom/ContentParent.h" |
|
16 #include "mozilla/dom/IDBDatabaseBinding.h" |
|
17 #include "mozilla/dom/ipc/Blob.h" |
|
18 #include "mozilla/dom/TabParent.h" |
|
19 #include "mozilla/unused.h" |
|
20 #include "nsCxPusher.h" |
|
21 |
|
22 #include "AsyncConnectionHelper.h" |
|
23 #include "DatabaseInfo.h" |
|
24 #include "IDBDatabase.h" |
|
25 #include "IDBEvents.h" |
|
26 #include "IDBFactory.h" |
|
27 #include "IDBIndex.h" |
|
28 #include "IDBKeyRange.h" |
|
29 #include "IDBObjectStore.h" |
|
30 #include "IDBTransaction.h" |
|
31 |
|
32 #define CHROME_ORIGIN "chrome" |
|
33 #define PERMISSION_PREFIX "indexedDB-chrome-" |
|
34 #define PERMISSION_SUFFIX_READ "-read" |
|
35 #define PERMISSION_SUFFIX_WRITE "-write" |
|
36 |
|
37 USING_INDEXEDDB_NAMESPACE |
|
38 |
|
39 using namespace mozilla; |
|
40 using namespace mozilla::dom; |
|
41 |
|
42 /******************************************************************************* |
|
43 * AutoSetCurrentTransaction |
|
44 ******************************************************************************/ |
|
45 |
|
46 AutoSetCurrentTransaction::AutoSetCurrentTransaction( |
|
47 IDBTransaction* aTransaction) |
|
48 { |
|
49 MOZ_ASSERT(aTransaction); |
|
50 AsyncConnectionHelper::SetCurrentTransaction(aTransaction); |
|
51 } |
|
52 |
|
53 AutoSetCurrentTransaction::~AutoSetCurrentTransaction() |
|
54 { |
|
55 AsyncConnectionHelper::SetCurrentTransaction(nullptr); |
|
56 } |
|
57 |
|
58 /******************************************************************************* |
|
59 * IndexedDBParent |
|
60 ******************************************************************************/ |
|
61 |
|
62 IndexedDBParent::IndexedDBParent(ContentParent* aContentParent) |
|
63 : mManagerContent(aContentParent), mManagerTab(nullptr), mDisconnected(false) |
|
64 { |
|
65 MOZ_COUNT_CTOR(IndexedDBParent); |
|
66 MOZ_ASSERT(aContentParent); |
|
67 } |
|
68 |
|
69 IndexedDBParent::IndexedDBParent(TabParent* aTabParent) |
|
70 : mManagerContent(nullptr), mManagerTab(aTabParent), mDisconnected(false) |
|
71 { |
|
72 MOZ_COUNT_CTOR(IndexedDBParent); |
|
73 MOZ_ASSERT(aTabParent); |
|
74 } |
|
75 |
|
76 IndexedDBParent::~IndexedDBParent() |
|
77 { |
|
78 MOZ_COUNT_DTOR(IndexedDBParent); |
|
79 } |
|
80 |
|
81 void |
|
82 IndexedDBParent::Disconnect() |
|
83 { |
|
84 if (mDisconnected) { |
|
85 return; |
|
86 } |
|
87 |
|
88 mDisconnected = true; |
|
89 |
|
90 const InfallibleTArray<PIndexedDBDatabaseParent*>& databases = |
|
91 ManagedPIndexedDBDatabaseParent(); |
|
92 for (uint32_t i = 0; i < databases.Length(); ++i) { |
|
93 static_cast<IndexedDBDatabaseParent*>(databases[i])->Disconnect(); |
|
94 } |
|
95 } |
|
96 |
|
97 bool |
|
98 IndexedDBParent::CheckReadPermission(const nsAString& aDatabaseName) |
|
99 { |
|
100 NS_NAMED_LITERAL_CSTRING(permission, PERMISSION_SUFFIX_READ); |
|
101 return CheckPermissionInternal(aDatabaseName, permission); |
|
102 } |
|
103 |
|
104 bool |
|
105 IndexedDBParent::CheckWritePermission(const nsAString& aDatabaseName) |
|
106 { |
|
107 // Write permission assumes read permission is granted as well. |
|
108 MOZ_ASSERT(CheckReadPermission(aDatabaseName)); |
|
109 |
|
110 NS_NAMED_LITERAL_CSTRING(permission, PERMISSION_SUFFIX_WRITE); |
|
111 return CheckPermissionInternal(aDatabaseName, permission); |
|
112 } |
|
113 |
|
114 mozilla::ipc::IProtocol* |
|
115 IndexedDBParent::CloneProtocol(Channel* aChannel, |
|
116 mozilla::ipc::ProtocolCloneContext* aCtx) |
|
117 { |
|
118 MOZ_ASSERT(mManagerContent != nullptr); |
|
119 MOZ_ASSERT(mManagerTab == nullptr); |
|
120 MOZ_ASSERT(!mDisconnected); |
|
121 MOZ_ASSERT(IndexedDatabaseManager::Get()); |
|
122 MOZ_ASSERT(IndexedDatabaseManager::IsMainProcess()); |
|
123 |
|
124 ContentParent* contentParent = aCtx->GetContentParent(); |
|
125 nsAutoPtr<PIndexedDBParent> actor(contentParent->AllocPIndexedDBParent()); |
|
126 if (!actor || !contentParent->RecvPIndexedDBConstructor(actor)) { |
|
127 return nullptr; |
|
128 } |
|
129 return actor.forget(); |
|
130 } |
|
131 |
|
132 bool |
|
133 IndexedDBParent::CheckPermissionInternal(const nsAString& aDatabaseName, |
|
134 const nsACString& aPermission) |
|
135 { |
|
136 MOZ_ASSERT(!mASCIIOrigin.IsEmpty()); |
|
137 MOZ_ASSERT(mManagerContent || mManagerTab); |
|
138 |
|
139 if (mASCIIOrigin.EqualsLiteral(CHROME_ORIGIN)) { |
|
140 nsAutoCString fullPermission = |
|
141 NS_LITERAL_CSTRING(PERMISSION_PREFIX) + |
|
142 NS_ConvertUTF16toUTF8(aDatabaseName) + |
|
143 aPermission; |
|
144 |
|
145 if ((mManagerContent && |
|
146 !AssertAppProcessPermission(mManagerContent, fullPermission.get())) || |
|
147 (mManagerTab && |
|
148 !AssertAppProcessPermission(mManagerTab, fullPermission.get()))) { |
|
149 return false; |
|
150 } |
|
151 } |
|
152 |
|
153 return true; |
|
154 } |
|
155 |
|
156 void |
|
157 IndexedDBParent::ActorDestroy(ActorDestroyReason aWhy) |
|
158 { |
|
159 // Nothing really needs to be done here... |
|
160 } |
|
161 |
|
162 bool |
|
163 IndexedDBParent::RecvPIndexedDBDatabaseConstructor( |
|
164 PIndexedDBDatabaseParent* aActor, |
|
165 const nsString& aName, |
|
166 const uint64_t& aVersion, |
|
167 const PersistenceType& aPersistenceType) |
|
168 { |
|
169 if (!CheckReadPermission(aName)) { |
|
170 return false; |
|
171 } |
|
172 |
|
173 if (IsDisconnected()) { |
|
174 // We're shutting down, ignore this request. |
|
175 return true; |
|
176 } |
|
177 |
|
178 if (!mFactory) { |
|
179 return true; |
|
180 } |
|
181 |
|
182 nsRefPtr<IDBOpenDBRequest> request; |
|
183 nsresult rv = mFactory->OpenInternal(aName, aVersion, aPersistenceType, false, |
|
184 getter_AddRefs(request)); |
|
185 NS_ENSURE_SUCCESS(rv, false); |
|
186 |
|
187 IndexedDBDatabaseParent* actor = |
|
188 static_cast<IndexedDBDatabaseParent*>(aActor); |
|
189 |
|
190 rv = actor->SetOpenRequest(request); |
|
191 NS_ENSURE_SUCCESS(rv, false); |
|
192 |
|
193 return true; |
|
194 } |
|
195 |
|
196 bool |
|
197 IndexedDBParent::RecvPIndexedDBDeleteDatabaseRequestConstructor( |
|
198 PIndexedDBDeleteDatabaseRequestParent* aActor, |
|
199 const nsString& aName, |
|
200 const PersistenceType& aPersistenceType) |
|
201 { |
|
202 if (!CheckWritePermission(aName)) { |
|
203 return false; |
|
204 } |
|
205 |
|
206 if (IsDisconnected()) { |
|
207 // We're shutting down, ignore this request. |
|
208 return true; |
|
209 } |
|
210 |
|
211 if (!mFactory) { |
|
212 return true; |
|
213 } |
|
214 |
|
215 IndexedDBDeleteDatabaseRequestParent* actor = |
|
216 static_cast<IndexedDBDeleteDatabaseRequestParent*>(aActor); |
|
217 |
|
218 nsRefPtr<IDBOpenDBRequest> request; |
|
219 |
|
220 nsresult rv = mFactory->OpenInternal(aName, 0, aPersistenceType, true, |
|
221 getter_AddRefs(request)); |
|
222 NS_ENSURE_SUCCESS(rv, false); |
|
223 |
|
224 rv = actor->SetOpenRequest(request); |
|
225 NS_ENSURE_SUCCESS(rv, false); |
|
226 |
|
227 return true; |
|
228 } |
|
229 |
|
230 PIndexedDBDatabaseParent* |
|
231 IndexedDBParent::AllocPIndexedDBDatabaseParent( |
|
232 const nsString& aName, |
|
233 const uint64_t& aVersion, |
|
234 const PersistenceType& aPersistenceType) |
|
235 { |
|
236 return new IndexedDBDatabaseParent(); |
|
237 } |
|
238 |
|
239 bool |
|
240 IndexedDBParent::DeallocPIndexedDBDatabaseParent(PIndexedDBDatabaseParent* aActor) |
|
241 { |
|
242 delete aActor; |
|
243 return true; |
|
244 } |
|
245 |
|
246 PIndexedDBDeleteDatabaseRequestParent* |
|
247 IndexedDBParent::AllocPIndexedDBDeleteDatabaseRequestParent( |
|
248 const nsString& aName, |
|
249 const PersistenceType& aPersistenceType) |
|
250 { |
|
251 return new IndexedDBDeleteDatabaseRequestParent(mFactory); |
|
252 } |
|
253 |
|
254 bool |
|
255 IndexedDBParent::DeallocPIndexedDBDeleteDatabaseRequestParent( |
|
256 PIndexedDBDeleteDatabaseRequestParent* aActor) |
|
257 { |
|
258 delete aActor; |
|
259 return true; |
|
260 } |
|
261 |
|
262 /******************************************************************************* |
|
263 * IndexedDBDatabaseParent |
|
264 ******************************************************************************/ |
|
265 |
|
266 IndexedDBDatabaseParent::IndexedDBDatabaseParent() |
|
267 : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()) |
|
268 { |
|
269 MOZ_COUNT_CTOR(IndexedDBDatabaseParent); |
|
270 } |
|
271 |
|
272 IndexedDBDatabaseParent::~IndexedDBDatabaseParent() |
|
273 { |
|
274 MOZ_COUNT_DTOR(IndexedDBDatabaseParent); |
|
275 } |
|
276 |
|
277 nsresult |
|
278 IndexedDBDatabaseParent::SetOpenRequest(IDBOpenDBRequest* aRequest) |
|
279 { |
|
280 MOZ_ASSERT(aRequest); |
|
281 MOZ_ASSERT(!mOpenRequest); |
|
282 |
|
283 nsresult rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR), |
|
284 mEventListener, false); |
|
285 NS_ENSURE_SUCCESS(rv, rv); |
|
286 |
|
287 rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), |
|
288 mEventListener, false); |
|
289 NS_ENSURE_SUCCESS(rv, rv); |
|
290 |
|
291 rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(BLOCKED_EVT_STR), |
|
292 mEventListener, false); |
|
293 NS_ENSURE_SUCCESS(rv, rv); |
|
294 |
|
295 rv = aRequest->EventTarget::AddEventListener(NS_LITERAL_STRING(UPGRADENEEDED_EVT_STR), |
|
296 mEventListener, false); |
|
297 NS_ENSURE_SUCCESS(rv, rv); |
|
298 |
|
299 mOpenRequest = aRequest; |
|
300 return NS_OK; |
|
301 } |
|
302 |
|
303 nsresult |
|
304 IndexedDBDatabaseParent::HandleEvent(nsIDOMEvent* aEvent) |
|
305 { |
|
306 MOZ_ASSERT(aEvent); |
|
307 |
|
308 if (IsDisconnected()) { |
|
309 // We're shutting down, ignore this event. |
|
310 return NS_OK; |
|
311 } |
|
312 |
|
313 nsString type; |
|
314 nsresult rv = aEvent->GetType(type); |
|
315 NS_ENSURE_SUCCESS(rv, rv); |
|
316 |
|
317 nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetTarget(); |
|
318 |
|
319 if (mDatabase && |
|
320 SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, |
|
321 mDatabase))) { |
|
322 rv = HandleDatabaseEvent(aEvent, type); |
|
323 NS_ENSURE_SUCCESS(rv, rv); |
|
324 |
|
325 return NS_OK; |
|
326 } |
|
327 |
|
328 if (mOpenRequest && |
|
329 SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, |
|
330 mOpenRequest))) { |
|
331 rv = HandleRequestEvent(aEvent, type); |
|
332 NS_ENSURE_SUCCESS(rv, rv); |
|
333 |
|
334 return NS_OK; |
|
335 } |
|
336 |
|
337 MOZ_CRASH("Unexpected message!"); |
|
338 } |
|
339 |
|
340 void |
|
341 IndexedDBDatabaseParent::Disconnect() |
|
342 { |
|
343 if (mDatabase) { |
|
344 mDatabase->DisconnectFromActorParent(); |
|
345 } |
|
346 } |
|
347 |
|
348 bool |
|
349 IndexedDBDatabaseParent::CheckWritePermission(const nsAString& aDatabaseName) |
|
350 { |
|
351 IndexedDBParent* manager = static_cast<IndexedDBParent*>(Manager()); |
|
352 MOZ_ASSERT(manager); |
|
353 |
|
354 return manager->CheckWritePermission(aDatabaseName); |
|
355 } |
|
356 |
|
357 void |
|
358 IndexedDBDatabaseParent::Invalidate() |
|
359 { |
|
360 MOZ_ASSERT(mDatabase); |
|
361 |
|
362 if (!IsDisconnected()) { |
|
363 mozilla::unused << SendInvalidate(); |
|
364 } |
|
365 } |
|
366 |
|
367 nsresult |
|
368 IndexedDBDatabaseParent::HandleRequestEvent(nsIDOMEvent* aEvent, |
|
369 const nsAString& aType) |
|
370 { |
|
371 MOZ_ASSERT(mOpenRequest); |
|
372 MOZ_ASSERT(!IsDisconnected()); |
|
373 |
|
374 nsresult rv; |
|
375 |
|
376 if (aType.EqualsLiteral(ERROR_EVT_STR)) { |
|
377 nsRefPtr<IDBOpenDBRequest> request; |
|
378 mOpenRequest.swap(request); |
|
379 |
|
380 rv = request->GetErrorCode(); |
|
381 MOZ_ASSERT(NS_FAILED(rv)); |
|
382 |
|
383 if (!SendError(rv)) { |
|
384 return NS_ERROR_FAILURE; |
|
385 } |
|
386 |
|
387 rv = aEvent->PreventDefault(); |
|
388 NS_ENSURE_SUCCESS(rv, rv); |
|
389 |
|
390 return NS_OK; |
|
391 } |
|
392 |
|
393 if (aType.EqualsLiteral(BLOCKED_EVT_STR)) { |
|
394 MOZ_ASSERT(!mDatabase); |
|
395 |
|
396 nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); |
|
397 NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); |
|
398 |
|
399 uint64_t oldVersion = changeEvent->OldVersion(); |
|
400 |
|
401 if (!SendBlocked(oldVersion)) { |
|
402 return NS_ERROR_FAILURE; |
|
403 } |
|
404 |
|
405 return NS_OK; |
|
406 } |
|
407 |
|
408 AutoSafeJSContext cx; |
|
409 |
|
410 ErrorResult error; |
|
411 JS::Rooted<JS::Value> result(cx); |
|
412 mOpenRequest->GetResult(cx, &result, error); |
|
413 ENSURE_SUCCESS(error, error.ErrorCode()); |
|
414 |
|
415 MOZ_ASSERT(!JSVAL_IS_PRIMITIVE(result)); |
|
416 |
|
417 IDBDatabase *database; |
|
418 rv = UNWRAP_OBJECT(IDBDatabase, &result.toObject(), database); |
|
419 if (NS_FAILED(rv)) { |
|
420 NS_WARNING("Didn't get the object we expected!"); |
|
421 return rv; |
|
422 } |
|
423 |
|
424 DatabaseInfo* dbInfo = database->Info(); |
|
425 MOZ_ASSERT(dbInfo); |
|
426 |
|
427 nsAutoTArray<nsString, 20> objectStoreNames; |
|
428 if (!dbInfo->GetObjectStoreNames(objectStoreNames)) { |
|
429 MOZ_CRASH("This should never fail!"); |
|
430 } |
|
431 |
|
432 InfallibleTArray<ObjectStoreInfoGuts> objectStoreInfos; |
|
433 if (!objectStoreNames.IsEmpty()) { |
|
434 uint32_t length = objectStoreNames.Length(); |
|
435 |
|
436 objectStoreInfos.SetCapacity(length); |
|
437 |
|
438 for (uint32_t i = 0; i < length; i++) { |
|
439 ObjectStoreInfo* osInfo = dbInfo->GetObjectStore(objectStoreNames[i]); |
|
440 MOZ_ASSERT(osInfo); |
|
441 |
|
442 objectStoreInfos.AppendElement(*osInfo); |
|
443 } |
|
444 } |
|
445 |
|
446 if (aType.EqualsLiteral(SUCCESS_EVT_STR)) { |
|
447 nsRefPtr<IDBOpenDBRequest> request; |
|
448 mOpenRequest.swap(request); |
|
449 |
|
450 EventTarget* target = static_cast<EventTarget*>(database); |
|
451 |
|
452 #ifdef DEBUG |
|
453 { |
|
454 nsresult rvDEBUG = |
|
455 target->AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), |
|
456 mEventListener, false); |
|
457 NS_WARN_IF_FALSE(NS_SUCCEEDED(rvDEBUG), "Failed to add error listener!"); |
|
458 } |
|
459 #endif |
|
460 |
|
461 NS_NAMED_LITERAL_STRING(versionChange, VERSIONCHANGE_EVT_STR); |
|
462 rv = target->AddEventListener(versionChange, mEventListener, false); |
|
463 NS_ENSURE_SUCCESS(rv, rv); |
|
464 |
|
465 if (!SendSuccess(*dbInfo, objectStoreInfos)) { |
|
466 return NS_ERROR_FAILURE; |
|
467 } |
|
468 |
|
469 MOZ_ASSERT(!mDatabase || mDatabase == database); |
|
470 |
|
471 if (!mDatabase) { |
|
472 database->SetActor(this); |
|
473 mDatabase = database; |
|
474 } |
|
475 |
|
476 return NS_OK; |
|
477 } |
|
478 |
|
479 if (aType.EqualsLiteral(UPGRADENEEDED_EVT_STR)) { |
|
480 MOZ_ASSERT(!mDatabase); |
|
481 |
|
482 IDBTransaction* transaction = |
|
483 AsyncConnectionHelper::GetCurrentTransaction(); |
|
484 MOZ_ASSERT(transaction); |
|
485 |
|
486 if (!CheckWritePermission(database->Name())) { |
|
487 // If we get here then the child process is either dead or in the process |
|
488 // of being killed. Abort the transaction now to prevent any changes to |
|
489 // the database. |
|
490 ErrorResult rv; |
|
491 transaction->Abort(rv); |
|
492 if (rv.Failed()) { |
|
493 NS_WARNING("Failed to abort transaction!"); |
|
494 } |
|
495 return NS_ERROR_FAILURE; |
|
496 } |
|
497 |
|
498 nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); |
|
499 NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); |
|
500 |
|
501 uint64_t oldVersion = changeEvent->OldVersion(); |
|
502 |
|
503 nsAutoPtr<IndexedDBVersionChangeTransactionParent> actor( |
|
504 new IndexedDBVersionChangeTransactionParent()); |
|
505 |
|
506 rv = actor->SetTransaction(transaction); |
|
507 NS_ENSURE_SUCCESS(rv, rv); |
|
508 |
|
509 VersionChangeTransactionParams versionChangeParams; |
|
510 versionChangeParams.dbInfo() = *dbInfo; |
|
511 versionChangeParams.osInfo() = objectStoreInfos; |
|
512 versionChangeParams.oldVersion() = oldVersion; |
|
513 |
|
514 if (!SendPIndexedDBTransactionConstructor(actor.forget(), |
|
515 versionChangeParams)) { |
|
516 return NS_ERROR_FAILURE; |
|
517 } |
|
518 |
|
519 database->SetActor(this); |
|
520 mDatabase = database; |
|
521 |
|
522 return NS_OK; |
|
523 } |
|
524 |
|
525 MOZ_CRASH("Unexpected message type!"); |
|
526 } |
|
527 |
|
528 nsresult |
|
529 IndexedDBDatabaseParent::HandleDatabaseEvent(nsIDOMEvent* aEvent, |
|
530 const nsAString& aType) |
|
531 { |
|
532 MOZ_ASSERT(mDatabase); |
|
533 MOZ_ASSERT(!aType.EqualsLiteral(ERROR_EVT_STR), |
|
534 "Should never get error events in the parent process!"); |
|
535 MOZ_ASSERT(!IsDisconnected()); |
|
536 |
|
537 if (aType.EqualsLiteral(VERSIONCHANGE_EVT_STR)) { |
|
538 AutoSafeJSContext cx; |
|
539 NS_ENSURE_TRUE(cx, NS_ERROR_FAILURE); |
|
540 |
|
541 nsCOMPtr<IDBVersionChangeEvent> changeEvent = do_QueryInterface(aEvent); |
|
542 NS_ENSURE_TRUE(changeEvent, NS_ERROR_FAILURE); |
|
543 |
|
544 uint64_t oldVersion = changeEvent->OldVersion(); |
|
545 |
|
546 Nullable<uint64_t> newVersionVal = changeEvent->GetNewVersion(); |
|
547 |
|
548 uint64_t newVersion; |
|
549 if (newVersionVal.IsNull()) { |
|
550 newVersion = 0; |
|
551 } |
|
552 else { |
|
553 newVersion = newVersionVal.Value(); |
|
554 } |
|
555 |
|
556 if (!SendVersionChange(oldVersion, newVersion)) { |
|
557 return NS_ERROR_FAILURE; |
|
558 } |
|
559 |
|
560 return NS_OK; |
|
561 } |
|
562 |
|
563 MOZ_CRASH("Unexpected message type!"); |
|
564 } |
|
565 |
|
566 void |
|
567 IndexedDBDatabaseParent::ActorDestroy(ActorDestroyReason aWhy) |
|
568 { |
|
569 if (mDatabase) { |
|
570 mDatabase->SetActor(static_cast<IndexedDBDatabaseParent*>(nullptr)); |
|
571 mDatabase->InvalidateInternal(/* aIsDead */ true); |
|
572 } |
|
573 } |
|
574 |
|
575 bool |
|
576 IndexedDBDatabaseParent::RecvClose(const bool& aUnlinked) |
|
577 { |
|
578 MOZ_ASSERT(mDatabase); |
|
579 |
|
580 if (IsDisconnected()) { |
|
581 // We're shutting down, ignore this request. |
|
582 return true; |
|
583 } |
|
584 |
|
585 mDatabase->CloseInternal(aUnlinked); |
|
586 return true; |
|
587 } |
|
588 |
|
589 bool |
|
590 IndexedDBDatabaseParent::RecvPIndexedDBTransactionConstructor( |
|
591 PIndexedDBTransactionParent* aActor, |
|
592 const TransactionParams& aParams) |
|
593 { |
|
594 MOZ_ASSERT(aParams.type() == |
|
595 TransactionParams::TNormalTransactionParams); |
|
596 MOZ_ASSERT(!mOpenRequest); |
|
597 |
|
598 if (IsDisconnected()) { |
|
599 // We're shutting down, ignore this request. |
|
600 return true; |
|
601 } |
|
602 |
|
603 if (!mDatabase) { |
|
604 return true; |
|
605 } |
|
606 |
|
607 IndexedDBTransactionParent* actor = |
|
608 static_cast<IndexedDBTransactionParent*>(aActor); |
|
609 |
|
610 const NormalTransactionParams& params = aParams.get_NormalTransactionParams(); |
|
611 |
|
612 if (params.mode() != IDBTransaction::READ_ONLY && |
|
613 !CheckWritePermission(mDatabase->Name())) { |
|
614 return false; |
|
615 } |
|
616 |
|
617 if (mDatabase->IsClosed()) { |
|
618 // If the window was navigated then we won't be able to do anything here. |
|
619 return true; |
|
620 } |
|
621 |
|
622 Sequence<nsString> storesToOpen; |
|
623 storesToOpen.AppendElements(params.names()); |
|
624 |
|
625 nsRefPtr<IDBTransaction> transaction = |
|
626 IDBTransaction::Create(mDatabase, storesToOpen, params.mode(), false); |
|
627 NS_ENSURE_TRUE(transaction, false); |
|
628 |
|
629 nsresult rv = actor->SetTransaction(transaction); |
|
630 NS_ENSURE_SUCCESS(rv, false); |
|
631 |
|
632 return true; |
|
633 } |
|
634 |
|
635 PIndexedDBTransactionParent* |
|
636 IndexedDBDatabaseParent::AllocPIndexedDBTransactionParent( |
|
637 const TransactionParams& aParams) |
|
638 { |
|
639 MOZ_ASSERT(aParams.type() == |
|
640 TransactionParams::TNormalTransactionParams); |
|
641 return new IndexedDBTransactionParent(); |
|
642 } |
|
643 |
|
644 bool |
|
645 IndexedDBDatabaseParent::DeallocPIndexedDBTransactionParent( |
|
646 PIndexedDBTransactionParent* aActor) |
|
647 { |
|
648 delete aActor; |
|
649 return true; |
|
650 } |
|
651 |
|
652 /******************************************************************************* |
|
653 * IndexedDBTransactionParent |
|
654 ******************************************************************************/ |
|
655 |
|
656 IndexedDBTransactionParent::IndexedDBTransactionParent() |
|
657 : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()), |
|
658 mArtificialRequestCount(false) |
|
659 { |
|
660 MOZ_COUNT_CTOR(IndexedDBTransactionParent); |
|
661 } |
|
662 |
|
663 IndexedDBTransactionParent::~IndexedDBTransactionParent() |
|
664 { |
|
665 MOZ_COUNT_DTOR(IndexedDBTransactionParent); |
|
666 } |
|
667 |
|
668 nsresult |
|
669 IndexedDBTransactionParent::SetTransaction(IDBTransaction* aTransaction) |
|
670 { |
|
671 MOZ_ASSERT(aTransaction); |
|
672 MOZ_ASSERT(!mTransaction); |
|
673 |
|
674 EventTarget* target = static_cast<EventTarget*>(aTransaction); |
|
675 |
|
676 NS_NAMED_LITERAL_STRING(complete, COMPLETE_EVT_STR); |
|
677 nsresult rv = target->AddEventListener(complete, mEventListener, false); |
|
678 NS_ENSURE_SUCCESS(rv, rv); |
|
679 |
|
680 rv = target->AddEventListener(NS_LITERAL_STRING(ABORT_EVT_STR), |
|
681 mEventListener, false); |
|
682 NS_ENSURE_SUCCESS(rv, rv); |
|
683 |
|
684 aTransaction->OnNewRequest(); |
|
685 mArtificialRequestCount = true; |
|
686 |
|
687 aTransaction->SetActor(this); |
|
688 |
|
689 mTransaction = aTransaction; |
|
690 return NS_OK; |
|
691 } |
|
692 |
|
693 nsresult |
|
694 IndexedDBTransactionParent::HandleEvent(nsIDOMEvent* aEvent) |
|
695 { |
|
696 MOZ_ASSERT(aEvent); |
|
697 |
|
698 if (IsDisconnected()) { |
|
699 // We're shutting down, ignore this event. |
|
700 return NS_OK; |
|
701 } |
|
702 |
|
703 nsString type; |
|
704 nsresult rv = aEvent->GetType(type); |
|
705 NS_ENSURE_SUCCESS(rv, rv); |
|
706 |
|
707 CompleteParams params; |
|
708 |
|
709 if (type.EqualsLiteral(COMPLETE_EVT_STR)) { |
|
710 params = CompleteResult(); |
|
711 } |
|
712 else if (type.EqualsLiteral(ABORT_EVT_STR)) { |
|
713 #ifdef DEBUG |
|
714 { |
|
715 nsCOMPtr<EventTarget> target = aEvent->InternalDOMEvent()->GetTarget(); |
|
716 MOZ_ASSERT(SameCOMIdentity(target, NS_ISUPPORTS_CAST(EventTarget*, |
|
717 mTransaction))); |
|
718 } |
|
719 #endif |
|
720 params = AbortResult(mTransaction->GetAbortCode()); |
|
721 } |
|
722 else { |
|
723 NS_WARNING("Unknown message type!"); |
|
724 return NS_ERROR_UNEXPECTED; |
|
725 } |
|
726 |
|
727 if (!SendComplete(params)) { |
|
728 return NS_ERROR_FAILURE; |
|
729 } |
|
730 |
|
731 return NS_OK; |
|
732 } |
|
733 |
|
734 void |
|
735 IndexedDBTransactionParent::ActorDestroy(ActorDestroyReason aWhy) |
|
736 { |
|
737 if (mTransaction) { |
|
738 if (mArtificialRequestCount) { |
|
739 // The transaction never completed and now the child side is dead. Abort |
|
740 // here to be safe. |
|
741 ErrorResult rv; |
|
742 mTransaction->Abort(rv); |
|
743 |
|
744 mTransaction->OnRequestFinished(); |
|
745 #ifdef DEBUG |
|
746 mArtificialRequestCount = false; |
|
747 #endif |
|
748 } |
|
749 mTransaction->SetActor(static_cast<IndexedDBTransactionParent*>(nullptr)); |
|
750 } |
|
751 } |
|
752 |
|
753 bool |
|
754 IndexedDBTransactionParent::RecvAbort(const nsresult& aAbortCode) |
|
755 { |
|
756 MOZ_ASSERT(mTransaction); |
|
757 |
|
758 if (IsDisconnected()) { |
|
759 // We're shutting down, ignore this request. |
|
760 return true; |
|
761 } |
|
762 |
|
763 mTransaction->Abort(aAbortCode); |
|
764 return true; |
|
765 } |
|
766 |
|
767 bool |
|
768 IndexedDBTransactionParent::RecvAllRequestsFinished() |
|
769 { |
|
770 MOZ_ASSERT(mTransaction); |
|
771 MOZ_ASSERT(mArtificialRequestCount); |
|
772 |
|
773 if (IsDisconnected()) { |
|
774 // We're shutting down, ignore this request. |
|
775 return true; |
|
776 } |
|
777 |
|
778 mTransaction->OnRequestFinished(); |
|
779 mArtificialRequestCount = false; |
|
780 |
|
781 return true; |
|
782 } |
|
783 |
|
784 bool |
|
785 IndexedDBTransactionParent::RecvDeleteObjectStore(const nsString& aName) |
|
786 { |
|
787 MOZ_CRASH("Should be overridden, don't call me!"); |
|
788 } |
|
789 |
|
790 bool |
|
791 IndexedDBTransactionParent::RecvPIndexedDBObjectStoreConstructor( |
|
792 PIndexedDBObjectStoreParent* aActor, |
|
793 const ObjectStoreConstructorParams& aParams) |
|
794 { |
|
795 if (IsDisconnected()) { |
|
796 // We're shutting down, ignore this request. |
|
797 return true; |
|
798 } |
|
799 |
|
800 if (!mTransaction) { |
|
801 return true; |
|
802 } |
|
803 |
|
804 IndexedDBObjectStoreParent* actor = |
|
805 static_cast<IndexedDBObjectStoreParent*>(aActor); |
|
806 |
|
807 if (aParams.type() == |
|
808 ObjectStoreConstructorParams::TGetObjectStoreParams) { |
|
809 const GetObjectStoreParams& params = aParams.get_GetObjectStoreParams(); |
|
810 const nsString& name = params.name(); |
|
811 |
|
812 nsRefPtr<IDBObjectStore> objectStore; |
|
813 |
|
814 { |
|
815 AutoSetCurrentTransaction asct(mTransaction); |
|
816 |
|
817 ErrorResult rv; |
|
818 objectStore = mTransaction->ObjectStore(name, rv); |
|
819 ENSURE_SUCCESS(rv, false); |
|
820 |
|
821 actor->SetObjectStore(objectStore); |
|
822 } |
|
823 |
|
824 objectStore->SetActor(actor); |
|
825 return true; |
|
826 } |
|
827 |
|
828 if (aParams.type() == |
|
829 ObjectStoreConstructorParams::TCreateObjectStoreParams) { |
|
830 MOZ_CRASH("Should be overridden, don't call me!"); |
|
831 } |
|
832 |
|
833 MOZ_CRASH("Unknown param type!"); |
|
834 } |
|
835 |
|
836 PIndexedDBObjectStoreParent* |
|
837 IndexedDBTransactionParent::AllocPIndexedDBObjectStoreParent( |
|
838 const ObjectStoreConstructorParams& aParams) |
|
839 { |
|
840 return new IndexedDBObjectStoreParent(); |
|
841 } |
|
842 |
|
843 bool |
|
844 IndexedDBTransactionParent::DeallocPIndexedDBObjectStoreParent( |
|
845 PIndexedDBObjectStoreParent* aActor) |
|
846 { |
|
847 delete aActor; |
|
848 return true; |
|
849 } |
|
850 |
|
851 /******************************************************************************* |
|
852 * IndexedDBVersionChangeTransactionParent |
|
853 ******************************************************************************/ |
|
854 |
|
855 IndexedDBVersionChangeTransactionParent:: |
|
856 IndexedDBVersionChangeTransactionParent() |
|
857 { |
|
858 MOZ_COUNT_CTOR(IndexedDBVersionChangeTransactionParent); |
|
859 } |
|
860 |
|
861 IndexedDBVersionChangeTransactionParent:: |
|
862 ~IndexedDBVersionChangeTransactionParent() |
|
863 { |
|
864 MOZ_COUNT_DTOR(IndexedDBVersionChangeTransactionParent); |
|
865 } |
|
866 |
|
867 bool |
|
868 IndexedDBVersionChangeTransactionParent::RecvDeleteObjectStore( |
|
869 const nsString& aName) |
|
870 { |
|
871 MOZ_ASSERT(!mTransaction || |
|
872 mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE); |
|
873 |
|
874 if (IsDisconnected()) { |
|
875 // We're shutting down, ignore this request. |
|
876 return true; |
|
877 } |
|
878 |
|
879 if (!mTransaction) { |
|
880 return true; |
|
881 } |
|
882 |
|
883 if (mTransaction->Database()->IsInvalidated()) { |
|
884 // If we've invalidated this database in the parent then we should bail out |
|
885 // now to avoid logic problems that could force-kill the child. |
|
886 return true; |
|
887 } |
|
888 |
|
889 IDBDatabase* db = mTransaction->Database(); |
|
890 MOZ_ASSERT(db); |
|
891 |
|
892 ErrorResult rv; |
|
893 |
|
894 { |
|
895 AutoSetCurrentTransaction asct(mTransaction); |
|
896 db->DeleteObjectStore(aName, rv); |
|
897 } |
|
898 |
|
899 ENSURE_SUCCESS(rv, false); |
|
900 return true; |
|
901 } |
|
902 |
|
903 bool |
|
904 IndexedDBVersionChangeTransactionParent::RecvPIndexedDBObjectStoreConstructor( |
|
905 PIndexedDBObjectStoreParent* aActor, |
|
906 const ObjectStoreConstructorParams& aParams) |
|
907 { |
|
908 if (IsDisconnected()) { |
|
909 // We're shutting down, ignore this request. |
|
910 return true; |
|
911 } |
|
912 |
|
913 if (!mTransaction) { |
|
914 return true; |
|
915 } |
|
916 |
|
917 if (mTransaction->Database()->IsInvalidated()) { |
|
918 // If we've invalidated this database in the parent then we should bail out |
|
919 // now to avoid logic problems that could force-kill the child. |
|
920 return true; |
|
921 } |
|
922 |
|
923 IndexedDBObjectStoreParent* actor = |
|
924 static_cast<IndexedDBObjectStoreParent*>(aActor); |
|
925 |
|
926 if (aParams.type() == |
|
927 ObjectStoreConstructorParams::TCreateObjectStoreParams) { |
|
928 MOZ_ASSERT(mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE); |
|
929 |
|
930 const CreateObjectStoreParams& params = |
|
931 aParams.get_CreateObjectStoreParams(); |
|
932 |
|
933 const ObjectStoreInfoGuts& info = params.info(); |
|
934 |
|
935 IDBDatabase* db = mTransaction->Database(); |
|
936 MOZ_ASSERT(db); |
|
937 |
|
938 nsRefPtr<IDBObjectStore> objectStore; |
|
939 |
|
940 ErrorResult rv; |
|
941 |
|
942 { |
|
943 AutoSetCurrentTransaction asct(mTransaction); |
|
944 |
|
945 objectStore = db->CreateObjectStoreInternal(mTransaction, info, rv); |
|
946 } |
|
947 |
|
948 ENSURE_SUCCESS(rv, false); |
|
949 |
|
950 actor->SetObjectStore(objectStore); |
|
951 objectStore->SetActor(actor); |
|
952 return true; |
|
953 } |
|
954 |
|
955 return |
|
956 IndexedDBTransactionParent::RecvPIndexedDBObjectStoreConstructor(aActor, |
|
957 aParams); |
|
958 } |
|
959 |
|
960 PIndexedDBObjectStoreParent* |
|
961 IndexedDBVersionChangeTransactionParent::AllocPIndexedDBObjectStoreParent( |
|
962 const ObjectStoreConstructorParams& aParams) |
|
963 { |
|
964 if (aParams.type() == |
|
965 ObjectStoreConstructorParams::TCreateObjectStoreParams || |
|
966 mTransaction->GetMode() == IDBTransaction::VERSION_CHANGE) { |
|
967 return new IndexedDBVersionChangeObjectStoreParent(); |
|
968 } |
|
969 |
|
970 return IndexedDBTransactionParent::AllocPIndexedDBObjectStoreParent(aParams); |
|
971 } |
|
972 |
|
973 /******************************************************************************* |
|
974 * IndexedDBCursorParent |
|
975 ******************************************************************************/ |
|
976 |
|
977 IndexedDBCursorParent::IndexedDBCursorParent(IDBCursor* aCursor) |
|
978 : mCursor(aCursor) |
|
979 { |
|
980 MOZ_COUNT_CTOR(IndexedDBCursorParent); |
|
981 MOZ_ASSERT(aCursor); |
|
982 aCursor->SetActor(this); |
|
983 } |
|
984 |
|
985 IndexedDBCursorParent::~IndexedDBCursorParent() |
|
986 { |
|
987 MOZ_COUNT_DTOR(IndexedDBCursorParent); |
|
988 } |
|
989 |
|
990 bool |
|
991 IndexedDBCursorParent::IsDisconnected() const |
|
992 { |
|
993 MOZ_ASSERT(mCursor); |
|
994 return mCursor->Transaction()->GetActorParent()->IsDisconnected(); |
|
995 } |
|
996 |
|
997 void |
|
998 IndexedDBCursorParent::ActorDestroy(ActorDestroyReason aWhy) |
|
999 { |
|
1000 MOZ_ASSERT(mCursor); |
|
1001 mCursor->SetActor(static_cast<IndexedDBCursorParent*>(nullptr)); |
|
1002 } |
|
1003 |
|
1004 bool |
|
1005 IndexedDBCursorParent::RecvPIndexedDBRequestConstructor( |
|
1006 PIndexedDBRequestParent* aActor, |
|
1007 const CursorRequestParams& aParams) |
|
1008 { |
|
1009 MOZ_ASSERT(mCursor); |
|
1010 |
|
1011 if (IsDisconnected()) { |
|
1012 // We're shutting down, ignore this request. |
|
1013 return true; |
|
1014 } |
|
1015 |
|
1016 IndexedDBCursorRequestParent* actor = |
|
1017 static_cast<IndexedDBCursorRequestParent*>(aActor); |
|
1018 |
|
1019 if (mCursor->Transaction()->Database()->IsInvalidated()) { |
|
1020 // If we've invalidated this database in the parent then we should bail out |
|
1021 // now to avoid logic problems that could force-kill the child. |
|
1022 return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); |
|
1023 } |
|
1024 |
|
1025 switch (aParams.type()) { |
|
1026 case CursorRequestParams::TContinueParams: |
|
1027 return actor->Continue(aParams.get_ContinueParams()); |
|
1028 |
|
1029 default: |
|
1030 MOZ_CRASH("Unknown type!"); |
|
1031 } |
|
1032 |
|
1033 MOZ_CRASH("Should never get here!"); |
|
1034 } |
|
1035 |
|
1036 PIndexedDBRequestParent* |
|
1037 IndexedDBCursorParent::AllocPIndexedDBRequestParent( |
|
1038 const CursorRequestParams& aParams) |
|
1039 { |
|
1040 MOZ_ASSERT(mCursor); |
|
1041 return new IndexedDBCursorRequestParent(mCursor, aParams.type()); |
|
1042 } |
|
1043 |
|
1044 bool |
|
1045 IndexedDBCursorParent::DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) |
|
1046 { |
|
1047 delete aActor; |
|
1048 return true; |
|
1049 } |
|
1050 |
|
1051 /******************************************************************************* |
|
1052 * IndexedDBObjectStoreParent |
|
1053 ******************************************************************************/ |
|
1054 |
|
1055 IndexedDBObjectStoreParent::IndexedDBObjectStoreParent() |
|
1056 { |
|
1057 MOZ_COUNT_CTOR(IndexedDBObjectStoreParent); |
|
1058 } |
|
1059 |
|
1060 IndexedDBObjectStoreParent::~IndexedDBObjectStoreParent() |
|
1061 { |
|
1062 MOZ_COUNT_DTOR(IndexedDBObjectStoreParent); |
|
1063 } |
|
1064 |
|
1065 void |
|
1066 IndexedDBObjectStoreParent::SetObjectStore(IDBObjectStore* aObjectStore) |
|
1067 { |
|
1068 // Sadly can't assert aObjectStore here... |
|
1069 MOZ_ASSERT(!mObjectStore); |
|
1070 |
|
1071 mObjectStore = aObjectStore; |
|
1072 } |
|
1073 |
|
1074 void |
|
1075 IndexedDBObjectStoreParent::ActorDestroy(ActorDestroyReason aWhy) |
|
1076 { |
|
1077 if (mObjectStore) { |
|
1078 mObjectStore->SetActor(static_cast<IndexedDBObjectStoreParent*>(nullptr)); |
|
1079 } |
|
1080 } |
|
1081 |
|
1082 bool |
|
1083 IndexedDBObjectStoreParent::RecvDeleteIndex(const nsString& aName) |
|
1084 { |
|
1085 MOZ_CRASH("Should be overridden, don't call me!"); |
|
1086 } |
|
1087 |
|
1088 bool |
|
1089 IndexedDBObjectStoreParent::RecvPIndexedDBRequestConstructor( |
|
1090 PIndexedDBRequestParent* aActor, |
|
1091 const ObjectStoreRequestParams& aParams) |
|
1092 { |
|
1093 if (IsDisconnected()) { |
|
1094 // We're shutting down, ignore this request. |
|
1095 return true; |
|
1096 } |
|
1097 |
|
1098 if (!mObjectStore) { |
|
1099 return true; |
|
1100 } |
|
1101 |
|
1102 IndexedDBObjectStoreRequestParent* actor = |
|
1103 static_cast<IndexedDBObjectStoreRequestParent*>(aActor); |
|
1104 |
|
1105 if (mObjectStore->Transaction()->Database()->IsInvalidated()) { |
|
1106 // If we've invalidated this database in the parent then we should bail out |
|
1107 // now to avoid logic problems that could force-kill the child. |
|
1108 return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); |
|
1109 } |
|
1110 |
|
1111 switch (aParams.type()) { |
|
1112 case ObjectStoreRequestParams::TGetParams: |
|
1113 return actor->Get(aParams.get_GetParams()); |
|
1114 |
|
1115 case ObjectStoreRequestParams::TGetAllParams: |
|
1116 return actor->GetAll(aParams.get_GetAllParams()); |
|
1117 |
|
1118 case ObjectStoreRequestParams::TGetAllKeysParams: |
|
1119 return actor->GetAllKeys(aParams.get_GetAllKeysParams()); |
|
1120 |
|
1121 case ObjectStoreRequestParams::TAddParams: |
|
1122 return actor->Add(aParams.get_AddParams()); |
|
1123 |
|
1124 case ObjectStoreRequestParams::TPutParams: |
|
1125 return actor->Put(aParams.get_PutParams()); |
|
1126 |
|
1127 case ObjectStoreRequestParams::TDeleteParams: |
|
1128 return actor->Delete(aParams.get_DeleteParams()); |
|
1129 |
|
1130 case ObjectStoreRequestParams::TClearParams: |
|
1131 return actor->Clear(aParams.get_ClearParams()); |
|
1132 |
|
1133 case ObjectStoreRequestParams::TCountParams: |
|
1134 return actor->Count(aParams.get_CountParams()); |
|
1135 |
|
1136 case ObjectStoreRequestParams::TOpenCursorParams: |
|
1137 return actor->OpenCursor(aParams.get_OpenCursorParams()); |
|
1138 |
|
1139 case ObjectStoreRequestParams::TOpenKeyCursorParams: |
|
1140 return actor->OpenKeyCursor(aParams.get_OpenKeyCursorParams()); |
|
1141 |
|
1142 default: |
|
1143 MOZ_CRASH("Unknown type!"); |
|
1144 } |
|
1145 |
|
1146 MOZ_CRASH("Should never get here!"); |
|
1147 } |
|
1148 |
|
1149 bool |
|
1150 IndexedDBObjectStoreParent::RecvPIndexedDBIndexConstructor( |
|
1151 PIndexedDBIndexParent* aActor, |
|
1152 const IndexConstructorParams& aParams) |
|
1153 { |
|
1154 if (IsDisconnected()) { |
|
1155 // We're shutting down, ignore this request. |
|
1156 return true; |
|
1157 } |
|
1158 |
|
1159 if (!mObjectStore) { |
|
1160 return true; |
|
1161 } |
|
1162 |
|
1163 IndexedDBIndexParent* actor = static_cast<IndexedDBIndexParent*>(aActor); |
|
1164 |
|
1165 if (aParams.type() == IndexConstructorParams::TGetIndexParams) { |
|
1166 const GetIndexParams& params = aParams.get_GetIndexParams(); |
|
1167 const nsString& name = params.name(); |
|
1168 |
|
1169 nsRefPtr<IDBIndex> index; |
|
1170 |
|
1171 { |
|
1172 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1173 |
|
1174 ErrorResult rv; |
|
1175 index = mObjectStore->Index(name, rv); |
|
1176 ENSURE_SUCCESS(rv, false); |
|
1177 |
|
1178 actor->SetIndex(index); |
|
1179 } |
|
1180 |
|
1181 index->SetActor(actor); |
|
1182 return true; |
|
1183 } |
|
1184 |
|
1185 if (aParams.type() == IndexConstructorParams::TCreateIndexParams) { |
|
1186 MOZ_CRASH("Should be overridden, don't call me!"); |
|
1187 } |
|
1188 |
|
1189 MOZ_CRASH("Unknown param type!"); |
|
1190 } |
|
1191 |
|
1192 PIndexedDBRequestParent* |
|
1193 IndexedDBObjectStoreParent::AllocPIndexedDBRequestParent( |
|
1194 const ObjectStoreRequestParams& aParams) |
|
1195 { |
|
1196 return new IndexedDBObjectStoreRequestParent(mObjectStore, aParams.type()); |
|
1197 } |
|
1198 |
|
1199 bool |
|
1200 IndexedDBObjectStoreParent::DeallocPIndexedDBRequestParent( |
|
1201 PIndexedDBRequestParent* aActor) |
|
1202 { |
|
1203 delete aActor; |
|
1204 return true; |
|
1205 } |
|
1206 |
|
1207 PIndexedDBIndexParent* |
|
1208 IndexedDBObjectStoreParent::AllocPIndexedDBIndexParent( |
|
1209 const IndexConstructorParams& aParams) |
|
1210 { |
|
1211 return new IndexedDBIndexParent(); |
|
1212 } |
|
1213 |
|
1214 bool |
|
1215 IndexedDBObjectStoreParent::DeallocPIndexedDBIndexParent( |
|
1216 PIndexedDBIndexParent* aActor) |
|
1217 { |
|
1218 delete aActor; |
|
1219 return true; |
|
1220 } |
|
1221 |
|
1222 PIndexedDBCursorParent* |
|
1223 IndexedDBObjectStoreParent::AllocPIndexedDBCursorParent( |
|
1224 const ObjectStoreCursorConstructorParams& aParams) |
|
1225 { |
|
1226 MOZ_CRASH("Caller is supposed to manually construct a cursor!"); |
|
1227 } |
|
1228 |
|
1229 bool |
|
1230 IndexedDBObjectStoreParent::DeallocPIndexedDBCursorParent( |
|
1231 PIndexedDBCursorParent* aActor) |
|
1232 { |
|
1233 delete aActor; |
|
1234 return true; |
|
1235 } |
|
1236 |
|
1237 /******************************************************************************* |
|
1238 * IndexedDBVersionChangeObjectStoreParent |
|
1239 ******************************************************************************/ |
|
1240 |
|
1241 IndexedDBVersionChangeObjectStoreParent:: |
|
1242 IndexedDBVersionChangeObjectStoreParent() |
|
1243 { |
|
1244 MOZ_COUNT_CTOR(IndexedDBVersionChangeObjectStoreParent); |
|
1245 } |
|
1246 |
|
1247 IndexedDBVersionChangeObjectStoreParent:: |
|
1248 ~IndexedDBVersionChangeObjectStoreParent() |
|
1249 { |
|
1250 MOZ_COUNT_DTOR(IndexedDBVersionChangeObjectStoreParent); |
|
1251 } |
|
1252 |
|
1253 bool |
|
1254 IndexedDBVersionChangeObjectStoreParent::RecvDeleteIndex(const nsString& aName) |
|
1255 { |
|
1256 MOZ_ASSERT(!mObjectStore || |
|
1257 mObjectStore->Transaction()->GetMode() == |
|
1258 IDBTransaction::VERSION_CHANGE); |
|
1259 |
|
1260 if (IsDisconnected()) { |
|
1261 // We're shutting down, ignore this request. |
|
1262 return true; |
|
1263 } |
|
1264 |
|
1265 if (!mObjectStore) { |
|
1266 return true; |
|
1267 } |
|
1268 |
|
1269 if (mObjectStore->Transaction()->Database()->IsInvalidated()) { |
|
1270 // If we've invalidated this database in the parent then we should bail out |
|
1271 // now to avoid logic problems that could force-kill the child. |
|
1272 return true; |
|
1273 } |
|
1274 |
|
1275 ErrorResult rv; |
|
1276 |
|
1277 { |
|
1278 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1279 |
|
1280 mObjectStore->DeleteIndex(aName, rv); |
|
1281 } |
|
1282 |
|
1283 ENSURE_SUCCESS(rv, false); |
|
1284 return true; |
|
1285 } |
|
1286 |
|
1287 bool |
|
1288 IndexedDBVersionChangeObjectStoreParent::RecvPIndexedDBIndexConstructor( |
|
1289 PIndexedDBIndexParent* aActor, |
|
1290 const IndexConstructorParams& aParams) |
|
1291 { |
|
1292 if (IsDisconnected()) { |
|
1293 // We're shutting down, ignore this request. |
|
1294 return true; |
|
1295 } |
|
1296 |
|
1297 if (!mObjectStore) { |
|
1298 return true; |
|
1299 } |
|
1300 |
|
1301 if (mObjectStore->Transaction()->Database()->IsInvalidated()) { |
|
1302 // If we've invalidated this database in the parent then we should bail out |
|
1303 // now to avoid logic problems that could force-kill the child. |
|
1304 return true; |
|
1305 } |
|
1306 |
|
1307 IndexedDBIndexParent* actor = static_cast<IndexedDBIndexParent*>(aActor); |
|
1308 |
|
1309 if (aParams.type() == IndexConstructorParams::TCreateIndexParams) { |
|
1310 MOZ_ASSERT(mObjectStore->Transaction()->GetMode() == |
|
1311 IDBTransaction::VERSION_CHANGE); |
|
1312 |
|
1313 const CreateIndexParams& params = aParams.get_CreateIndexParams(); |
|
1314 const IndexInfo& info = params.info(); |
|
1315 |
|
1316 nsRefPtr<IDBIndex> index; |
|
1317 |
|
1318 { |
|
1319 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1320 |
|
1321 ErrorResult rv; |
|
1322 index = mObjectStore->CreateIndexInternal(info, rv); |
|
1323 ENSURE_SUCCESS(rv, false); |
|
1324 } |
|
1325 |
|
1326 actor->SetIndex(index); |
|
1327 index->SetActor(actor); |
|
1328 return true; |
|
1329 } |
|
1330 |
|
1331 return IndexedDBObjectStoreParent::RecvPIndexedDBIndexConstructor(aActor, |
|
1332 aParams); |
|
1333 } |
|
1334 |
|
1335 /******************************************************************************* |
|
1336 * IndexedDBIndexParent |
|
1337 ******************************************************************************/ |
|
1338 |
|
1339 IndexedDBIndexParent::IndexedDBIndexParent() |
|
1340 { |
|
1341 MOZ_COUNT_CTOR(IndexedDBIndexParent); |
|
1342 } |
|
1343 |
|
1344 IndexedDBIndexParent::~IndexedDBIndexParent() |
|
1345 { |
|
1346 MOZ_COUNT_DTOR(IndexedDBIndexParent); |
|
1347 } |
|
1348 |
|
1349 void |
|
1350 IndexedDBIndexParent::SetIndex(IDBIndex* aIndex) |
|
1351 { |
|
1352 MOZ_ASSERT(aIndex); |
|
1353 MOZ_ASSERT(!mIndex); |
|
1354 |
|
1355 mIndex = aIndex; |
|
1356 } |
|
1357 |
|
1358 void |
|
1359 IndexedDBIndexParent::ActorDestroy(ActorDestroyReason aWhy) |
|
1360 { |
|
1361 if (mIndex) { |
|
1362 mIndex->SetActor(static_cast<IndexedDBIndexParent*>(nullptr)); |
|
1363 } |
|
1364 } |
|
1365 |
|
1366 bool |
|
1367 IndexedDBIndexParent::RecvPIndexedDBRequestConstructor( |
|
1368 PIndexedDBRequestParent* aActor, |
|
1369 const IndexRequestParams& aParams) |
|
1370 { |
|
1371 if (IsDisconnected()) { |
|
1372 // We're shutting down, ignore this request. |
|
1373 return true; |
|
1374 } |
|
1375 |
|
1376 if (!mIndex) { |
|
1377 return true; |
|
1378 } |
|
1379 |
|
1380 IndexedDBIndexRequestParent* actor = |
|
1381 static_cast<IndexedDBIndexRequestParent*>(aActor); |
|
1382 |
|
1383 if (mIndex->ObjectStore()->Transaction()->Database()->IsInvalidated()) { |
|
1384 // If we've invalidated this database in the parent then we should bail out |
|
1385 // now to avoid logic problems that could force-kill the child. |
|
1386 return actor->Send__delete__(actor, NS_ERROR_DOM_INDEXEDDB_UNKNOWN_ERR); |
|
1387 } |
|
1388 |
|
1389 switch (aParams.type()) { |
|
1390 case IndexRequestParams::TGetParams: |
|
1391 return actor->Get(aParams.get_GetParams()); |
|
1392 |
|
1393 case IndexRequestParams::TGetKeyParams: |
|
1394 return actor->GetKey(aParams.get_GetKeyParams()); |
|
1395 |
|
1396 case IndexRequestParams::TGetAllParams: |
|
1397 return actor->GetAll(aParams.get_GetAllParams()); |
|
1398 |
|
1399 case IndexRequestParams::TGetAllKeysParams: |
|
1400 return actor->GetAllKeys(aParams.get_GetAllKeysParams()); |
|
1401 |
|
1402 case IndexRequestParams::TCountParams: |
|
1403 return actor->Count(aParams.get_CountParams()); |
|
1404 |
|
1405 case IndexRequestParams::TOpenCursorParams: |
|
1406 return actor->OpenCursor(aParams.get_OpenCursorParams()); |
|
1407 |
|
1408 case IndexRequestParams::TOpenKeyCursorParams: |
|
1409 return actor->OpenKeyCursor(aParams.get_OpenKeyCursorParams()); |
|
1410 |
|
1411 default: |
|
1412 MOZ_CRASH("Unknown type!"); |
|
1413 } |
|
1414 |
|
1415 MOZ_CRASH("Should never get here!"); |
|
1416 } |
|
1417 |
|
1418 PIndexedDBRequestParent* |
|
1419 IndexedDBIndexParent::AllocPIndexedDBRequestParent(const IndexRequestParams& aParams) |
|
1420 { |
|
1421 return new IndexedDBIndexRequestParent(mIndex, aParams.type()); |
|
1422 } |
|
1423 |
|
1424 bool |
|
1425 IndexedDBIndexParent::DeallocPIndexedDBRequestParent(PIndexedDBRequestParent* aActor) |
|
1426 { |
|
1427 delete aActor; |
|
1428 return true; |
|
1429 } |
|
1430 |
|
1431 PIndexedDBCursorParent* |
|
1432 IndexedDBIndexParent::AllocPIndexedDBCursorParent( |
|
1433 const IndexCursorConstructorParams& aParams) |
|
1434 { |
|
1435 MOZ_CRASH("Caller is supposed to manually construct a cursor!"); |
|
1436 } |
|
1437 |
|
1438 bool |
|
1439 IndexedDBIndexParent::DeallocPIndexedDBCursorParent(PIndexedDBCursorParent* aActor) |
|
1440 { |
|
1441 delete aActor; |
|
1442 return true; |
|
1443 } |
|
1444 |
|
1445 /******************************************************************************* |
|
1446 * IndexedDBRequestParentBase |
|
1447 ******************************************************************************/ |
|
1448 |
|
1449 IndexedDBRequestParentBase::IndexedDBRequestParentBase() |
|
1450 { |
|
1451 MOZ_COUNT_CTOR(IndexedDBRequestParentBase); |
|
1452 } |
|
1453 |
|
1454 IndexedDBRequestParentBase::~IndexedDBRequestParentBase() |
|
1455 { |
|
1456 MOZ_COUNT_DTOR(IndexedDBRequestParentBase); |
|
1457 } |
|
1458 |
|
1459 void |
|
1460 IndexedDBRequestParentBase::ActorDestroy(ActorDestroyReason aWhy) |
|
1461 { |
|
1462 if (mRequest) { |
|
1463 mRequest->SetActor(nullptr); |
|
1464 } |
|
1465 } |
|
1466 |
|
1467 /******************************************************************************* |
|
1468 * IndexedDBObjectStoreRequestParent |
|
1469 ******************************************************************************/ |
|
1470 |
|
1471 IndexedDBObjectStoreRequestParent::IndexedDBObjectStoreRequestParent( |
|
1472 IDBObjectStore* aObjectStore, |
|
1473 RequestType aRequestType) |
|
1474 : mObjectStore(aObjectStore), mRequestType(aRequestType) |
|
1475 { |
|
1476 MOZ_COUNT_CTOR(IndexedDBObjectStoreRequestParent); |
|
1477 // Sadly can't assert aObjectStore here... |
|
1478 MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && |
|
1479 aRequestType <= ParamsUnionType::T__Last); |
|
1480 } |
|
1481 |
|
1482 IndexedDBObjectStoreRequestParent::~IndexedDBObjectStoreRequestParent() |
|
1483 { |
|
1484 MOZ_COUNT_DTOR(IndexedDBObjectStoreRequestParent); |
|
1485 } |
|
1486 |
|
1487 void |
|
1488 IndexedDBObjectStoreRequestParent::ConvertBlobActors( |
|
1489 const InfallibleTArray<PBlobParent*>& aActors, |
|
1490 nsTArray<nsCOMPtr<nsIDOMBlob> >& aBlobs) |
|
1491 { |
|
1492 MOZ_ASSERT(aBlobs.IsEmpty()); |
|
1493 MOZ_ASSERT(mObjectStore); |
|
1494 |
|
1495 if (!aActors.IsEmpty()) { |
|
1496 // Walk the chain to get to ContentParent. |
|
1497 MOZ_ASSERT(mObjectStore->Transaction()->Database()->GetContentParent()); |
|
1498 |
|
1499 uint32_t length = aActors.Length(); |
|
1500 aBlobs.SetCapacity(length); |
|
1501 |
|
1502 for (uint32_t index = 0; index < length; index++) { |
|
1503 BlobParent* actor = static_cast<BlobParent*>(aActors[index]); |
|
1504 nsCOMPtr<nsIDOMBlob> blob = actor->GetBlob(); |
|
1505 aBlobs.AppendElement(blob); |
|
1506 } |
|
1507 } |
|
1508 } |
|
1509 |
|
1510 bool |
|
1511 IndexedDBObjectStoreRequestParent::IsDisconnected() |
|
1512 { |
|
1513 MOZ_ASSERT(mObjectStore); |
|
1514 MOZ_ASSERT(mObjectStore->GetActorParent()); |
|
1515 return mObjectStore->GetActorParent()->IsDisconnected(); |
|
1516 } |
|
1517 |
|
1518 bool |
|
1519 IndexedDBObjectStoreRequestParent::Get(const GetParams& aParams) |
|
1520 { |
|
1521 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams); |
|
1522 MOZ_ASSERT(mObjectStore); |
|
1523 |
|
1524 nsRefPtr<IDBRequest> request; |
|
1525 |
|
1526 nsRefPtr<IDBKeyRange> keyRange = |
|
1527 IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); |
|
1528 MOZ_ASSERT(keyRange); |
|
1529 |
|
1530 { |
|
1531 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1532 |
|
1533 ErrorResult rv; |
|
1534 request = mObjectStore->GetInternal(keyRange, rv); |
|
1535 ENSURE_SUCCESS(rv, false); |
|
1536 } |
|
1537 |
|
1538 request->SetActor(this); |
|
1539 mRequest.swap(request); |
|
1540 |
|
1541 return true; |
|
1542 } |
|
1543 |
|
1544 bool |
|
1545 IndexedDBObjectStoreRequestParent::GetAll(const GetAllParams& aParams) |
|
1546 { |
|
1547 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams); |
|
1548 MOZ_ASSERT(mObjectStore); |
|
1549 |
|
1550 nsRefPtr<IDBRequest> request; |
|
1551 |
|
1552 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
1553 |
|
1554 nsRefPtr<IDBKeyRange> keyRange; |
|
1555 |
|
1556 switch (keyRangeUnion.type()) { |
|
1557 case ipc::OptionalKeyRange::TKeyRange: |
|
1558 keyRange = |
|
1559 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
1560 break; |
|
1561 |
|
1562 case ipc::OptionalKeyRange::Tvoid_t: |
|
1563 break; |
|
1564 |
|
1565 default: |
|
1566 MOZ_CRASH("Unknown param type!"); |
|
1567 } |
|
1568 |
|
1569 { |
|
1570 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1571 |
|
1572 ErrorResult rv; |
|
1573 request = mObjectStore->GetAllInternal(keyRange, aParams.limit(), rv); |
|
1574 ENSURE_SUCCESS(rv, false); |
|
1575 } |
|
1576 |
|
1577 request->SetActor(this); |
|
1578 mRequest.swap(request); |
|
1579 return true; |
|
1580 } |
|
1581 |
|
1582 bool |
|
1583 IndexedDBObjectStoreRequestParent::GetAllKeys(const GetAllKeysParams& aParams) |
|
1584 { |
|
1585 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams); |
|
1586 MOZ_ASSERT(mObjectStore); |
|
1587 |
|
1588 nsRefPtr<IDBRequest> request; |
|
1589 |
|
1590 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
1591 |
|
1592 nsRefPtr<IDBKeyRange> keyRange; |
|
1593 |
|
1594 switch (keyRangeUnion.type()) { |
|
1595 case ipc::OptionalKeyRange::TKeyRange: |
|
1596 keyRange = |
|
1597 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
1598 break; |
|
1599 |
|
1600 case ipc::OptionalKeyRange::Tvoid_t: |
|
1601 break; |
|
1602 |
|
1603 default: |
|
1604 MOZ_CRASH("Unknown param type!"); |
|
1605 } |
|
1606 |
|
1607 { |
|
1608 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1609 |
|
1610 ErrorResult rv; |
|
1611 request = mObjectStore->GetAllKeysInternal(keyRange, aParams.limit(), rv); |
|
1612 ENSURE_SUCCESS(rv, false); |
|
1613 } |
|
1614 |
|
1615 request->SetActor(this); |
|
1616 mRequest.swap(request); |
|
1617 return true; |
|
1618 } |
|
1619 |
|
1620 bool |
|
1621 IndexedDBObjectStoreRequestParent::Add(const AddParams& aParams) |
|
1622 { |
|
1623 MOZ_ASSERT(mRequestType == ParamsUnionType::TAddParams); |
|
1624 MOZ_ASSERT(mObjectStore); |
|
1625 |
|
1626 ipc::AddPutParams params = aParams.commonParams(); |
|
1627 |
|
1628 nsTArray<nsCOMPtr<nsIDOMBlob> > blobs; |
|
1629 ConvertBlobActors(params.blobsParent(), blobs); |
|
1630 |
|
1631 nsRefPtr<IDBRequest> request; |
|
1632 |
|
1633 { |
|
1634 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1635 |
|
1636 nsresult rv = |
|
1637 mObjectStore->AddOrPutInternal(params.cloneInfo(), params.key(), |
|
1638 params.indexUpdateInfos(), blobs, false, |
|
1639 getter_AddRefs(request)); |
|
1640 NS_ENSURE_SUCCESS(rv, false); |
|
1641 } |
|
1642 |
|
1643 request->SetActor(this); |
|
1644 mRequest.swap(request); |
|
1645 return true; |
|
1646 } |
|
1647 |
|
1648 bool |
|
1649 IndexedDBObjectStoreRequestParent::Put(const PutParams& aParams) |
|
1650 { |
|
1651 MOZ_ASSERT(mRequestType == ParamsUnionType::TPutParams); |
|
1652 MOZ_ASSERT(mObjectStore); |
|
1653 |
|
1654 ipc::AddPutParams params = aParams.commonParams(); |
|
1655 |
|
1656 nsTArray<nsCOMPtr<nsIDOMBlob> > blobs; |
|
1657 ConvertBlobActors(params.blobsParent(), blobs); |
|
1658 |
|
1659 nsRefPtr<IDBRequest> request; |
|
1660 |
|
1661 { |
|
1662 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1663 |
|
1664 nsresult rv = |
|
1665 mObjectStore->AddOrPutInternal(params.cloneInfo(), params.key(), |
|
1666 params.indexUpdateInfos(), blobs, true, |
|
1667 getter_AddRefs(request)); |
|
1668 NS_ENSURE_SUCCESS(rv, false); |
|
1669 } |
|
1670 |
|
1671 request->SetActor(this); |
|
1672 mRequest.swap(request); |
|
1673 return true; |
|
1674 } |
|
1675 |
|
1676 bool |
|
1677 IndexedDBObjectStoreRequestParent::Delete(const DeleteParams& aParams) |
|
1678 { |
|
1679 MOZ_ASSERT(mRequestType == ParamsUnionType::TDeleteParams); |
|
1680 MOZ_ASSERT(mObjectStore); |
|
1681 |
|
1682 nsRefPtr<IDBRequest> request; |
|
1683 |
|
1684 nsRefPtr<IDBKeyRange> keyRange = |
|
1685 IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); |
|
1686 MOZ_ASSERT(keyRange); |
|
1687 |
|
1688 { |
|
1689 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1690 |
|
1691 ErrorResult rv; |
|
1692 request = mObjectStore->DeleteInternal(keyRange, rv); |
|
1693 ENSURE_SUCCESS(rv, false); |
|
1694 } |
|
1695 |
|
1696 request->SetActor(this); |
|
1697 mRequest.swap(request); |
|
1698 return true; |
|
1699 } |
|
1700 |
|
1701 bool |
|
1702 IndexedDBObjectStoreRequestParent::Clear(const ClearParams& aParams) |
|
1703 { |
|
1704 MOZ_ASSERT(mRequestType == ParamsUnionType::TClearParams); |
|
1705 MOZ_ASSERT(mObjectStore); |
|
1706 |
|
1707 nsRefPtr<IDBRequest> request; |
|
1708 |
|
1709 { |
|
1710 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1711 |
|
1712 ErrorResult rv; |
|
1713 request = mObjectStore->Clear(rv); |
|
1714 ENSURE_SUCCESS(rv, false); |
|
1715 } |
|
1716 |
|
1717 request->SetActor(this); |
|
1718 mRequest.swap(request); |
|
1719 return true; |
|
1720 } |
|
1721 |
|
1722 bool |
|
1723 IndexedDBObjectStoreRequestParent::Count(const CountParams& aParams) |
|
1724 { |
|
1725 MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams); |
|
1726 MOZ_ASSERT(mObjectStore); |
|
1727 |
|
1728 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
1729 |
|
1730 nsRefPtr<IDBKeyRange> keyRange; |
|
1731 |
|
1732 switch (keyRangeUnion.type()) { |
|
1733 case ipc::OptionalKeyRange::TKeyRange: |
|
1734 keyRange = |
|
1735 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
1736 break; |
|
1737 |
|
1738 case ipc::OptionalKeyRange::Tvoid_t: |
|
1739 break; |
|
1740 |
|
1741 default: |
|
1742 MOZ_CRASH("Unknown param type!"); |
|
1743 } |
|
1744 |
|
1745 nsRefPtr<IDBRequest> request; |
|
1746 |
|
1747 { |
|
1748 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1749 |
|
1750 ErrorResult rv; |
|
1751 request = mObjectStore->CountInternal(keyRange, rv); |
|
1752 ENSURE_SUCCESS(rv, false); |
|
1753 } |
|
1754 |
|
1755 request->SetActor(this); |
|
1756 mRequest.swap(request); |
|
1757 return true; |
|
1758 } |
|
1759 |
|
1760 bool |
|
1761 IndexedDBObjectStoreRequestParent::OpenCursor(const OpenCursorParams& aParams) |
|
1762 { |
|
1763 MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams); |
|
1764 MOZ_ASSERT(mObjectStore); |
|
1765 |
|
1766 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
1767 |
|
1768 nsRefPtr<IDBKeyRange> keyRange; |
|
1769 |
|
1770 switch (keyRangeUnion.type()) { |
|
1771 case ipc::OptionalKeyRange::TKeyRange: |
|
1772 keyRange = |
|
1773 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
1774 break; |
|
1775 |
|
1776 case ipc::OptionalKeyRange::Tvoid_t: |
|
1777 break; |
|
1778 |
|
1779 default: |
|
1780 MOZ_CRASH("Unknown param type!"); |
|
1781 } |
|
1782 |
|
1783 size_t direction = static_cast<size_t>(aParams.direction()); |
|
1784 |
|
1785 nsRefPtr<IDBRequest> request; |
|
1786 |
|
1787 { |
|
1788 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1789 |
|
1790 ErrorResult rv; |
|
1791 request = mObjectStore->OpenCursorInternal(keyRange, direction, rv); |
|
1792 ENSURE_SUCCESS(rv, false); |
|
1793 } |
|
1794 |
|
1795 request->SetActor(this); |
|
1796 mRequest.swap(request); |
|
1797 return true; |
|
1798 } |
|
1799 |
|
1800 bool |
|
1801 IndexedDBObjectStoreRequestParent::OpenKeyCursor( |
|
1802 const OpenKeyCursorParams& aParams) |
|
1803 { |
|
1804 MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenKeyCursorParams); |
|
1805 MOZ_ASSERT(mObjectStore); |
|
1806 |
|
1807 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
1808 |
|
1809 nsRefPtr<IDBKeyRange> keyRange; |
|
1810 |
|
1811 switch (keyRangeUnion.type()) { |
|
1812 case ipc::OptionalKeyRange::TKeyRange: |
|
1813 keyRange = |
|
1814 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
1815 break; |
|
1816 |
|
1817 case ipc::OptionalKeyRange::Tvoid_t: |
|
1818 break; |
|
1819 |
|
1820 default: |
|
1821 MOZ_CRASH("Unknown param type!"); |
|
1822 } |
|
1823 |
|
1824 size_t direction = static_cast<size_t>(aParams.direction()); |
|
1825 |
|
1826 nsRefPtr<IDBRequest> request; |
|
1827 |
|
1828 { |
|
1829 AutoSetCurrentTransaction asct(mObjectStore->Transaction()); |
|
1830 |
|
1831 ErrorResult rv; |
|
1832 request = mObjectStore->OpenKeyCursorInternal(keyRange, direction, rv); |
|
1833 ENSURE_SUCCESS(rv, false); |
|
1834 } |
|
1835 |
|
1836 request->SetActor(this); |
|
1837 mRequest.swap(request); |
|
1838 return true; |
|
1839 } |
|
1840 |
|
1841 /******************************************************************************* |
|
1842 * IndexedDBIndexRequestParent |
|
1843 ******************************************************************************/ |
|
1844 |
|
1845 IndexedDBIndexRequestParent::IndexedDBIndexRequestParent( |
|
1846 IDBIndex* aIndex, |
|
1847 RequestType aRequestType) |
|
1848 : mIndex(aIndex), mRequestType(aRequestType) |
|
1849 { |
|
1850 MOZ_COUNT_CTOR(IndexedDBIndexRequestParent); |
|
1851 // Sadly can't assert aIndex here... |
|
1852 MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && |
|
1853 aRequestType <= ParamsUnionType::T__Last); |
|
1854 } |
|
1855 |
|
1856 IndexedDBIndexRequestParent::~IndexedDBIndexRequestParent() |
|
1857 { |
|
1858 MOZ_COUNT_DTOR(IndexedDBIndexRequestParent); |
|
1859 } |
|
1860 |
|
1861 bool |
|
1862 IndexedDBIndexRequestParent::IsDisconnected() |
|
1863 { |
|
1864 MOZ_ASSERT(mIndex); |
|
1865 MOZ_ASSERT(mIndex->GetActorParent()); |
|
1866 return mIndex->GetActorParent()->IsDisconnected(); |
|
1867 } |
|
1868 |
|
1869 bool |
|
1870 IndexedDBIndexRequestParent::Get(const GetParams& aParams) |
|
1871 { |
|
1872 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetParams); |
|
1873 MOZ_ASSERT(mIndex); |
|
1874 |
|
1875 nsRefPtr<IDBRequest> request; |
|
1876 |
|
1877 nsRefPtr<IDBKeyRange> keyRange = |
|
1878 IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); |
|
1879 MOZ_ASSERT(keyRange); |
|
1880 |
|
1881 { |
|
1882 AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
|
1883 |
|
1884 ErrorResult rv; |
|
1885 request = mIndex->GetInternal(keyRange, rv); |
|
1886 ENSURE_SUCCESS(rv, false); |
|
1887 } |
|
1888 |
|
1889 request->SetActor(this); |
|
1890 mRequest.swap(request); |
|
1891 return true; |
|
1892 } |
|
1893 |
|
1894 bool |
|
1895 IndexedDBIndexRequestParent::GetKey(const GetKeyParams& aParams) |
|
1896 { |
|
1897 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetKeyParams); |
|
1898 MOZ_ASSERT(mIndex); |
|
1899 |
|
1900 nsRefPtr<IDBRequest> request; |
|
1901 |
|
1902 nsRefPtr<IDBKeyRange> keyRange = |
|
1903 IDBKeyRange::FromSerializedKeyRange(aParams.keyRange()); |
|
1904 MOZ_ASSERT(keyRange); |
|
1905 |
|
1906 { |
|
1907 AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
|
1908 |
|
1909 ErrorResult rv; |
|
1910 request = mIndex->GetKeyInternal(keyRange, rv); |
|
1911 ENSURE_SUCCESS(rv, false); |
|
1912 } |
|
1913 |
|
1914 request->SetActor(this); |
|
1915 mRequest.swap(request); |
|
1916 return true; |
|
1917 } |
|
1918 |
|
1919 bool |
|
1920 IndexedDBIndexRequestParent::GetAll(const GetAllParams& aParams) |
|
1921 { |
|
1922 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllParams); |
|
1923 MOZ_ASSERT(mIndex); |
|
1924 |
|
1925 nsRefPtr<IDBRequest> request; |
|
1926 |
|
1927 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
1928 |
|
1929 nsRefPtr<IDBKeyRange> keyRange; |
|
1930 |
|
1931 switch (keyRangeUnion.type()) { |
|
1932 case ipc::OptionalKeyRange::TKeyRange: |
|
1933 keyRange = |
|
1934 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
1935 break; |
|
1936 |
|
1937 case ipc::OptionalKeyRange::Tvoid_t: |
|
1938 break; |
|
1939 |
|
1940 default: |
|
1941 MOZ_CRASH("Unknown param type!"); |
|
1942 } |
|
1943 |
|
1944 { |
|
1945 AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
|
1946 |
|
1947 ErrorResult rv; |
|
1948 request = mIndex->GetAllInternal(keyRange, aParams.limit(), rv); |
|
1949 ENSURE_SUCCESS(rv, false); |
|
1950 } |
|
1951 |
|
1952 request->SetActor(this); |
|
1953 mRequest.swap(request); |
|
1954 return true; |
|
1955 } |
|
1956 |
|
1957 bool |
|
1958 IndexedDBIndexRequestParent::GetAllKeys(const GetAllKeysParams& aParams) |
|
1959 { |
|
1960 MOZ_ASSERT(mRequestType == ParamsUnionType::TGetAllKeysParams); |
|
1961 MOZ_ASSERT(mIndex); |
|
1962 |
|
1963 nsRefPtr<IDBRequest> request; |
|
1964 |
|
1965 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
1966 |
|
1967 nsRefPtr<IDBKeyRange> keyRange; |
|
1968 |
|
1969 switch (keyRangeUnion.type()) { |
|
1970 case ipc::OptionalKeyRange::TKeyRange: |
|
1971 keyRange = |
|
1972 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
1973 break; |
|
1974 |
|
1975 case ipc::OptionalKeyRange::Tvoid_t: |
|
1976 break; |
|
1977 |
|
1978 default: |
|
1979 MOZ_CRASH("Unknown param type!"); |
|
1980 } |
|
1981 |
|
1982 { |
|
1983 AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
|
1984 |
|
1985 ErrorResult rv; |
|
1986 request = mIndex->GetAllKeysInternal(keyRange, aParams.limit(), rv); |
|
1987 ENSURE_SUCCESS(rv, false); |
|
1988 } |
|
1989 |
|
1990 request->SetActor(this); |
|
1991 mRequest.swap(request); |
|
1992 return true; |
|
1993 } |
|
1994 |
|
1995 bool |
|
1996 IndexedDBIndexRequestParent::Count(const CountParams& aParams) |
|
1997 { |
|
1998 MOZ_ASSERT(mRequestType == ParamsUnionType::TCountParams); |
|
1999 MOZ_ASSERT(mIndex); |
|
2000 |
|
2001 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
2002 |
|
2003 nsRefPtr<IDBKeyRange> keyRange; |
|
2004 |
|
2005 switch (keyRangeUnion.type()) { |
|
2006 case ipc::OptionalKeyRange::TKeyRange: |
|
2007 keyRange = |
|
2008 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
2009 break; |
|
2010 |
|
2011 case ipc::OptionalKeyRange::Tvoid_t: |
|
2012 break; |
|
2013 |
|
2014 default: |
|
2015 MOZ_CRASH("Unknown param type!"); |
|
2016 } |
|
2017 |
|
2018 nsRefPtr<IDBRequest> request; |
|
2019 |
|
2020 { |
|
2021 AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
|
2022 |
|
2023 ErrorResult rv; |
|
2024 request = mIndex->CountInternal(keyRange, rv); |
|
2025 ENSURE_SUCCESS(rv, false); |
|
2026 } |
|
2027 |
|
2028 request->SetActor(this); |
|
2029 mRequest.swap(request); |
|
2030 return true; |
|
2031 } |
|
2032 |
|
2033 bool |
|
2034 IndexedDBIndexRequestParent::OpenCursor(const OpenCursorParams& aParams) |
|
2035 { |
|
2036 MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenCursorParams); |
|
2037 MOZ_ASSERT(mIndex); |
|
2038 |
|
2039 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
2040 |
|
2041 nsRefPtr<IDBKeyRange> keyRange; |
|
2042 |
|
2043 switch (keyRangeUnion.type()) { |
|
2044 case ipc::OptionalKeyRange::TKeyRange: |
|
2045 keyRange = |
|
2046 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
2047 break; |
|
2048 |
|
2049 case ipc::OptionalKeyRange::Tvoid_t: |
|
2050 break; |
|
2051 |
|
2052 default: |
|
2053 MOZ_CRASH("Unknown param type!"); |
|
2054 } |
|
2055 |
|
2056 size_t direction = static_cast<size_t>(aParams.direction()); |
|
2057 |
|
2058 nsRefPtr<IDBRequest> request; |
|
2059 |
|
2060 { |
|
2061 AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
|
2062 |
|
2063 nsresult rv = |
|
2064 mIndex->OpenCursorInternal(keyRange, direction, getter_AddRefs(request)); |
|
2065 NS_ENSURE_SUCCESS(rv, false); |
|
2066 } |
|
2067 |
|
2068 request->SetActor(this); |
|
2069 mRequest.swap(request); |
|
2070 return true; |
|
2071 } |
|
2072 |
|
2073 bool |
|
2074 IndexedDBIndexRequestParent::OpenKeyCursor(const OpenKeyCursorParams& aParams) |
|
2075 { |
|
2076 MOZ_ASSERT(mRequestType == ParamsUnionType::TOpenKeyCursorParams); |
|
2077 MOZ_ASSERT(mIndex); |
|
2078 |
|
2079 const ipc::OptionalKeyRange keyRangeUnion = aParams.optionalKeyRange(); |
|
2080 |
|
2081 nsRefPtr<IDBKeyRange> keyRange; |
|
2082 |
|
2083 switch (keyRangeUnion.type()) { |
|
2084 case ipc::OptionalKeyRange::TKeyRange: |
|
2085 keyRange = |
|
2086 IDBKeyRange::FromSerializedKeyRange(keyRangeUnion.get_KeyRange()); |
|
2087 break; |
|
2088 |
|
2089 case ipc::OptionalKeyRange::Tvoid_t: |
|
2090 break; |
|
2091 |
|
2092 default: |
|
2093 MOZ_CRASH("Unknown param type!"); |
|
2094 } |
|
2095 |
|
2096 size_t direction = static_cast<size_t>(aParams.direction()); |
|
2097 |
|
2098 nsRefPtr<IDBRequest> request; |
|
2099 |
|
2100 { |
|
2101 AutoSetCurrentTransaction asct(mIndex->ObjectStore()->Transaction()); |
|
2102 |
|
2103 ErrorResult rv; |
|
2104 request = mIndex->OpenKeyCursorInternal(keyRange, direction, rv); |
|
2105 ENSURE_SUCCESS(rv, false); |
|
2106 } |
|
2107 |
|
2108 request->SetActor(this); |
|
2109 mRequest.swap(request); |
|
2110 return true; |
|
2111 } |
|
2112 |
|
2113 /******************************************************************************* |
|
2114 * IndexedDBCursorRequestParent |
|
2115 ******************************************************************************/ |
|
2116 |
|
2117 IndexedDBCursorRequestParent::IndexedDBCursorRequestParent( |
|
2118 IDBCursor* aCursor, |
|
2119 RequestType aRequestType) |
|
2120 : mCursor(aCursor), mRequestType(aRequestType) |
|
2121 { |
|
2122 MOZ_COUNT_CTOR(IndexedDBCursorRequestParent); |
|
2123 MOZ_ASSERT(aCursor); |
|
2124 MOZ_ASSERT(aRequestType > ParamsUnionType::T__None && |
|
2125 aRequestType <= ParamsUnionType::T__Last); |
|
2126 } |
|
2127 |
|
2128 IndexedDBCursorRequestParent::~IndexedDBCursorRequestParent() |
|
2129 { |
|
2130 MOZ_COUNT_DTOR(IndexedDBCursorRequestParent); |
|
2131 } |
|
2132 |
|
2133 bool |
|
2134 IndexedDBCursorRequestParent::IsDisconnected() |
|
2135 { |
|
2136 MOZ_ASSERT(mCursor); |
|
2137 MOZ_ASSERT(mCursor->GetActorParent()); |
|
2138 return mCursor->GetActorParent()->IsDisconnected(); |
|
2139 } |
|
2140 |
|
2141 bool |
|
2142 IndexedDBCursorRequestParent::Continue(const ContinueParams& aParams) |
|
2143 { |
|
2144 MOZ_ASSERT(mCursor); |
|
2145 MOZ_ASSERT(mRequestType == ParamsUnionType::TContinueParams); |
|
2146 |
|
2147 { |
|
2148 AutoSetCurrentTransaction asct(mCursor->Transaction()); |
|
2149 |
|
2150 ErrorResult rv; |
|
2151 mCursor->ContinueInternal(aParams.key(), aParams.count(), rv); |
|
2152 ENSURE_SUCCESS(rv, false); |
|
2153 } |
|
2154 |
|
2155 mRequest = mCursor->Request(); |
|
2156 MOZ_ASSERT(mRequest); |
|
2157 |
|
2158 mRequest->SetActor(this); |
|
2159 return true; |
|
2160 } |
|
2161 |
|
2162 /******************************************************************************* |
|
2163 * IndexedDBDeleteDatabaseRequestParent |
|
2164 ******************************************************************************/ |
|
2165 |
|
2166 IndexedDBDeleteDatabaseRequestParent::IndexedDBDeleteDatabaseRequestParent( |
|
2167 IDBFactory* aFactory) |
|
2168 : mEventListener(MOZ_THIS_IN_INITIALIZER_LIST()), mFactory(aFactory) |
|
2169 { |
|
2170 MOZ_COUNT_CTOR(IndexedDBDeleteDatabaseRequestParent); |
|
2171 MOZ_ASSERT(aFactory); |
|
2172 } |
|
2173 |
|
2174 IndexedDBDeleteDatabaseRequestParent::~IndexedDBDeleteDatabaseRequestParent() |
|
2175 { |
|
2176 MOZ_COUNT_DTOR(IndexedDBDeleteDatabaseRequestParent); |
|
2177 } |
|
2178 |
|
2179 nsresult |
|
2180 IndexedDBDeleteDatabaseRequestParent::HandleEvent(nsIDOMEvent* aEvent) |
|
2181 { |
|
2182 MOZ_ASSERT(aEvent); |
|
2183 |
|
2184 if (IsDisconnected()) { |
|
2185 // We're shutting down, ignore this event. |
|
2186 return NS_OK; |
|
2187 } |
|
2188 |
|
2189 nsString type; |
|
2190 nsresult rv = aEvent->GetType(type); |
|
2191 NS_ENSURE_SUCCESS(rv, rv); |
|
2192 |
|
2193 if (type.EqualsASCII(BLOCKED_EVT_STR)) { |
|
2194 nsCOMPtr<IDBVersionChangeEvent> event = do_QueryInterface(aEvent); |
|
2195 MOZ_ASSERT(event); |
|
2196 |
|
2197 uint64_t currentVersion = event->OldVersion(); |
|
2198 |
|
2199 if (!SendBlocked(currentVersion)) { |
|
2200 return NS_ERROR_FAILURE; |
|
2201 } |
|
2202 |
|
2203 return NS_OK; |
|
2204 } |
|
2205 |
|
2206 #ifdef DEBUG |
|
2207 if (type.EqualsASCII(SUCCESS_EVT_STR)) { |
|
2208 MOZ_ASSERT(NS_SUCCEEDED(mOpenRequest->GetErrorCode())); |
|
2209 } |
|
2210 else { |
|
2211 MOZ_ASSERT(type.EqualsASCII(ERROR_EVT_STR)); |
|
2212 MOZ_ASSERT(NS_FAILED(mOpenRequest->GetErrorCode())); |
|
2213 } |
|
2214 #endif |
|
2215 |
|
2216 if (!Send__delete__(this, mOpenRequest->GetErrorCode())) { |
|
2217 return NS_ERROR_FAILURE; |
|
2218 } |
|
2219 |
|
2220 return NS_OK; |
|
2221 } |
|
2222 |
|
2223 nsresult |
|
2224 IndexedDBDeleteDatabaseRequestParent::SetOpenRequest( |
|
2225 IDBOpenDBRequest* aOpenRequest) |
|
2226 { |
|
2227 MOZ_ASSERT(aOpenRequest); |
|
2228 MOZ_ASSERT(!mOpenRequest); |
|
2229 |
|
2230 EventTarget* target = static_cast<EventTarget*>(aOpenRequest); |
|
2231 |
|
2232 nsresult rv = target->AddEventListener(NS_LITERAL_STRING(SUCCESS_EVT_STR), |
|
2233 mEventListener, false); |
|
2234 NS_ENSURE_SUCCESS(rv, rv); |
|
2235 |
|
2236 rv = target->AddEventListener(NS_LITERAL_STRING(ERROR_EVT_STR), |
|
2237 mEventListener, false); |
|
2238 NS_ENSURE_SUCCESS(rv, rv); |
|
2239 |
|
2240 rv = target->AddEventListener(NS_LITERAL_STRING(BLOCKED_EVT_STR), |
|
2241 mEventListener, false); |
|
2242 NS_ENSURE_SUCCESS(rv, rv); |
|
2243 |
|
2244 mOpenRequest = aOpenRequest; |
|
2245 return NS_OK; |
|
2246 } |
|
2247 |
|
2248 /******************************************************************************* |
|
2249 * WeakEventListener |
|
2250 ******************************************************************************/ |
|
2251 |
|
2252 NS_IMPL_ISUPPORTS(WeakEventListenerBase, nsIDOMEventListener) |
|
2253 |
|
2254 NS_IMETHODIMP |
|
2255 WeakEventListenerBase::HandleEvent(nsIDOMEvent* aEvent) |
|
2256 { |
|
2257 MOZ_CRASH("This must be overridden!"); |
|
2258 } |