Bug 1858509 add thread-safety annotations around MediaSourceDemuxer::mMonitor r=alwu
[gecko.git] / ipc / glue / BackgroundParentImpl.cpp
blob77f498a01e45875af1e801235afdbc0db28d3d72
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "BackgroundParentImpl.h"
9 #include "BroadcastChannelParent.h"
10 #ifdef MOZ_WEBRTC
11 # include "CamerasParent.h"
12 #endif
13 #include "mozilla/Assertions.h"
14 #include "mozilla/RDDProcessManager.h"
15 #include "mozilla/ipc/UtilityProcessManager.h"
16 #include "mozilla/RemoteDecodeUtils.h"
17 #include "mozilla/RefPtr.h"
18 #include "mozilla/dom/BackgroundSessionStorageServiceParent.h"
19 #include "mozilla/dom/ClientManagerActors.h"
20 #include "mozilla/dom/ContentParent.h"
21 #include "mozilla/dom/DOMTypes.h"
22 #include "mozilla/dom/EndpointForReportParent.h"
23 #include "mozilla/dom/FetchParent.h"
24 #include "mozilla/dom/FileCreatorParent.h"
25 #include "mozilla/dom/FileSystemManagerParentFactory.h"
26 #include "mozilla/dom/FileSystemRequestParent.h"
27 #include "mozilla/dom/GamepadEventChannelParent.h"
28 #include "mozilla/dom/GamepadTestChannelParent.h"
29 #include "mozilla/dom/MIDIManagerParent.h"
30 #include "mozilla/dom/MIDIPlatformService.h"
31 #include "mozilla/dom/MIDIPortParent.h"
32 #include "mozilla/dom/MessagePortParent.h"
33 #include "mozilla/dom/PGamepadEventChannelParent.h"
34 #include "mozilla/dom/PGamepadTestChannelParent.h"
35 #include "mozilla/dom/RemoteWorkerControllerParent.h"
36 #include "mozilla/dom/RemoteWorkerServiceParent.h"
37 #include "mozilla/dom/ReportingHeader.h"
38 #include "mozilla/dom/ServiceWorkerActors.h"
39 #include "mozilla/dom/ServiceWorkerContainerParent.h"
40 #include "mozilla/dom/ServiceWorkerManagerParent.h"
41 #include "mozilla/dom/ServiceWorkerParent.h"
42 #include "mozilla/dom/ServiceWorkerRegistrar.h"
43 #include "mozilla/dom/ServiceWorkerRegistrationParent.h"
44 #include "mozilla/dom/SessionStorageManager.h"
45 #include "mozilla/dom/SharedWorkerParent.h"
46 #include "mozilla/dom/StorageActivityService.h"
47 #include "mozilla/dom/StorageIPC.h"
48 #include "mozilla/dom/TemporaryIPCBlobParent.h"
49 #include "mozilla/dom/WebAuthnTransactionParent.h"
50 #include "mozilla/dom/WebTransportParent.h"
51 #include "mozilla/dom/cache/ActorUtils.h"
52 #include "mozilla/dom/indexedDB/ActorsParent.h"
53 #include "mozilla/dom/locks/LockManagerParent.h"
54 #include "mozilla/dom/localstorage/ActorsParent.h"
55 #include "mozilla/dom/network/UDPSocketParent.h"
56 #include "mozilla/dom/quota/ActorsParent.h"
57 #include "mozilla/dom/quota/QuotaParent.h"
58 #include "mozilla/dom/simpledb/ActorsParent.h"
59 #include "mozilla/dom/VsyncParent.h"
60 #include "mozilla/ipc/BackgroundParent.h"
61 #include "mozilla/ipc/BackgroundUtils.h"
62 #include "mozilla/ipc/Endpoint.h"
63 #include "mozilla/ipc/IdleSchedulerParent.h"
64 #include "mozilla/ipc/PBackgroundSharedTypes.h"
65 #include "mozilla/ipc/PBackgroundTestParent.h"
66 #include "mozilla/net/BackgroundDataBridgeParent.h"
67 #include "mozilla/net/HttpBackgroundChannelParent.h"
68 #include "nsIHttpChannelInternal.h"
69 #include "nsIPrincipal.h"
70 #include "nsProxyRelease.h"
71 #include "nsThreadUtils.h"
72 #include "nsXULAppAPI.h"
74 using mozilla::AssertIsOnMainThread;
75 using mozilla::dom::FileSystemRequestParent;
76 using mozilla::dom::MessagePortParent;
77 using mozilla::dom::MIDIManagerParent;
78 using mozilla::dom::MIDIPlatformService;
79 using mozilla::dom::MIDIPortParent;
80 using mozilla::dom::PMessagePortParent;
81 using mozilla::dom::PMIDIManagerParent;
82 using mozilla::dom::PMIDIPortParent;
83 using mozilla::dom::PServiceWorkerContainerParent;
84 using mozilla::dom::PServiceWorkerParent;
85 using mozilla::dom::PServiceWorkerRegistrationParent;
86 using mozilla::dom::ServiceWorkerParent;
87 using mozilla::dom::UDPSocketParent;
88 using mozilla::dom::WebAuthnTransactionParent;
89 using mozilla::dom::cache::PCacheParent;
90 using mozilla::dom::cache::PCacheStorageParent;
91 using mozilla::dom::cache::PCacheStreamControlParent;
92 using mozilla::ipc::AssertIsOnBackgroundThread;
94 namespace {
96 class TestParent final : public mozilla::ipc::PBackgroundTestParent {
97 friend class mozilla::ipc::BackgroundParentImpl;
99 MOZ_COUNTED_DEFAULT_CTOR(TestParent)
101 protected:
102 ~TestParent() override { MOZ_COUNT_DTOR(TestParent); }
104 public:
105 void ActorDestroy(ActorDestroyReason aWhy) override;
108 } // namespace
110 namespace mozilla::ipc {
112 using mozilla::dom::BroadcastChannelParent;
113 using mozilla::dom::ContentParent;
114 using mozilla::dom::ThreadsafeContentParentHandle;
116 BackgroundParentImpl::BackgroundParentImpl() {
117 AssertIsInMainProcess();
119 MOZ_COUNT_CTOR(mozilla::ipc::BackgroundParentImpl);
122 BackgroundParentImpl::~BackgroundParentImpl() {
123 AssertIsInMainProcess();
124 AssertIsOnMainThread();
126 MOZ_COUNT_DTOR(mozilla::ipc::BackgroundParentImpl);
129 void BackgroundParentImpl::ProcessingError(Result aCode, const char* aReason) {
130 if (MsgDropped == aCode) {
131 return;
134 // XXX Remove this cut-out once bug 1858621 is fixed. Some parent actors
135 // currently return nullptr in actor allocation methods for non fatal errors.
136 // We don't want to crash the parent process or child processes in that case.
137 if (MsgValueError == aCode) {
138 return;
141 // Other errors are big deals.
142 nsDependentCString reason(aReason);
143 if (BackgroundParent::IsOtherProcessActor(this)) {
144 #ifndef FUZZING
145 BackgroundParent::KillHardAsync(this, reason);
146 #endif
147 if (CanSend()) {
148 GetIPCChannel()->InduceConnectionError();
150 } else {
151 CrashReporter::AnnotateCrashReport(
152 CrashReporter::Annotation::ipc_channel_error, reason);
154 MOZ_CRASH("in-process BackgroundParent abort due to IPC error");
158 void BackgroundParentImpl::ActorDestroy(ActorDestroyReason aWhy) {
159 AssertIsInMainProcess();
160 AssertIsOnBackgroundThread();
163 BackgroundParentImpl::PBackgroundTestParent*
164 BackgroundParentImpl::AllocPBackgroundTestParent(const nsACString& aTestArg) {
165 AssertIsInMainProcess();
166 AssertIsOnBackgroundThread();
168 return new TestParent();
171 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundTestConstructor(
172 PBackgroundTestParent* aActor, const nsACString& aTestArg) {
173 AssertIsInMainProcess();
174 AssertIsOnBackgroundThread();
175 MOZ_ASSERT(aActor);
177 if (!PBackgroundTestParent::Send__delete__(aActor, aTestArg)) {
178 return IPC_FAIL_NO_REASON(this);
180 return IPC_OK();
183 bool BackgroundParentImpl::DeallocPBackgroundTestParent(
184 PBackgroundTestParent* aActor) {
185 AssertIsInMainProcess();
186 AssertIsOnBackgroundThread();
187 MOZ_ASSERT(aActor);
189 delete static_cast<TestParent*>(aActor);
190 return true;
193 auto BackgroundParentImpl::AllocPBackgroundIDBFactoryParent(
194 const LoggingInfo& aLoggingInfo)
195 -> already_AddRefed<PBackgroundIDBFactoryParent> {
196 using mozilla::dom::indexedDB::AllocPBackgroundIDBFactoryParent;
198 AssertIsInMainProcess();
199 AssertIsOnBackgroundThread();
201 return AllocPBackgroundIDBFactoryParent(aLoggingInfo);
204 mozilla::ipc::IPCResult
205 BackgroundParentImpl::RecvPBackgroundIDBFactoryConstructor(
206 PBackgroundIDBFactoryParent* aActor, const LoggingInfo& aLoggingInfo) {
207 using mozilla::dom::indexedDB::RecvPBackgroundIDBFactoryConstructor;
209 AssertIsInMainProcess();
210 AssertIsOnBackgroundThread();
211 MOZ_ASSERT(aActor);
213 if (!RecvPBackgroundIDBFactoryConstructor(aActor, aLoggingInfo)) {
214 return IPC_FAIL_NO_REASON(this);
216 return IPC_OK();
219 auto BackgroundParentImpl::AllocPBackgroundIndexedDBUtilsParent()
220 -> PBackgroundIndexedDBUtilsParent* {
221 AssertIsInMainProcess();
222 AssertIsOnBackgroundThread();
224 return mozilla::dom::indexedDB::AllocPBackgroundIndexedDBUtilsParent();
227 bool BackgroundParentImpl::DeallocPBackgroundIndexedDBUtilsParent(
228 PBackgroundIndexedDBUtilsParent* aActor) {
229 AssertIsInMainProcess();
230 AssertIsOnBackgroundThread();
231 MOZ_ASSERT(aActor);
233 return mozilla::dom::indexedDB::DeallocPBackgroundIndexedDBUtilsParent(
234 aActor);
237 mozilla::ipc::IPCResult BackgroundParentImpl::RecvFlushPendingFileDeletions() {
238 AssertIsInMainProcess();
239 AssertIsOnBackgroundThread();
241 if (!mozilla::dom::indexedDB::RecvFlushPendingFileDeletions()) {
242 return IPC_FAIL_NO_REASON(this);
244 return IPC_OK();
247 BackgroundParentImpl::PBackgroundSDBConnectionParent*
248 BackgroundParentImpl::AllocPBackgroundSDBConnectionParent(
249 const PersistenceType& aPersistenceType,
250 const PrincipalInfo& aPrincipalInfo) {
251 AssertIsInMainProcess();
252 AssertIsOnBackgroundThread();
254 return mozilla::dom::AllocPBackgroundSDBConnectionParent(aPersistenceType,
255 aPrincipalInfo);
258 mozilla::ipc::IPCResult
259 BackgroundParentImpl::RecvPBackgroundSDBConnectionConstructor(
260 PBackgroundSDBConnectionParent* aActor,
261 const PersistenceType& aPersistenceType,
262 const PrincipalInfo& aPrincipalInfo) {
263 AssertIsInMainProcess();
264 AssertIsOnBackgroundThread();
265 MOZ_ASSERT(aActor);
267 if (!mozilla::dom::RecvPBackgroundSDBConnectionConstructor(
268 aActor, aPersistenceType, aPrincipalInfo)) {
269 return IPC_FAIL_NO_REASON(this);
271 return IPC_OK();
274 bool BackgroundParentImpl::DeallocPBackgroundSDBConnectionParent(
275 PBackgroundSDBConnectionParent* aActor) {
276 AssertIsInMainProcess();
277 AssertIsOnBackgroundThread();
278 MOZ_ASSERT(aActor);
280 return mozilla::dom::DeallocPBackgroundSDBConnectionParent(aActor);
283 BackgroundParentImpl::PBackgroundLSDatabaseParent*
284 BackgroundParentImpl::AllocPBackgroundLSDatabaseParent(
285 const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
286 const uint64_t& aDatastoreId) {
287 AssertIsInMainProcess();
288 AssertIsOnBackgroundThread();
290 return mozilla::dom::AllocPBackgroundLSDatabaseParent(
291 aPrincipalInfo, aPrivateBrowsingId, aDatastoreId);
294 mozilla::ipc::IPCResult
295 BackgroundParentImpl::RecvPBackgroundLSDatabaseConstructor(
296 PBackgroundLSDatabaseParent* aActor, const PrincipalInfo& aPrincipalInfo,
297 const uint32_t& aPrivateBrowsingId, const uint64_t& aDatastoreId) {
298 AssertIsInMainProcess();
299 AssertIsOnBackgroundThread();
300 MOZ_ASSERT(aActor);
302 if (!mozilla::dom::RecvPBackgroundLSDatabaseConstructor(
303 aActor, aPrincipalInfo, aPrivateBrowsingId, aDatastoreId)) {
304 return IPC_FAIL_NO_REASON(this);
306 return IPC_OK();
309 bool BackgroundParentImpl::DeallocPBackgroundLSDatabaseParent(
310 PBackgroundLSDatabaseParent* aActor) {
311 AssertIsInMainProcess();
312 AssertIsOnBackgroundThread();
313 MOZ_ASSERT(aActor);
315 return mozilla::dom::DeallocPBackgroundLSDatabaseParent(aActor);
318 BackgroundParentImpl::PBackgroundLSObserverParent*
319 BackgroundParentImpl::AllocPBackgroundLSObserverParent(
320 const uint64_t& aObserverId) {
321 AssertIsInMainProcess();
322 AssertIsOnBackgroundThread();
324 return mozilla::dom::AllocPBackgroundLSObserverParent(aObserverId);
327 mozilla::ipc::IPCResult
328 BackgroundParentImpl::RecvPBackgroundLSObserverConstructor(
329 PBackgroundLSObserverParent* aActor, const uint64_t& aObserverId) {
330 AssertIsInMainProcess();
331 AssertIsOnBackgroundThread();
332 MOZ_ASSERT(aActor);
334 if (!mozilla::dom::RecvPBackgroundLSObserverConstructor(aActor,
335 aObserverId)) {
336 return IPC_FAIL_NO_REASON(this);
338 return IPC_OK();
341 bool BackgroundParentImpl::DeallocPBackgroundLSObserverParent(
342 PBackgroundLSObserverParent* aActor) {
343 AssertIsInMainProcess();
344 AssertIsOnBackgroundThread();
345 MOZ_ASSERT(aActor);
347 return mozilla::dom::DeallocPBackgroundLSObserverParent(aActor);
350 BackgroundParentImpl::PBackgroundLSRequestParent*
351 BackgroundParentImpl::AllocPBackgroundLSRequestParent(
352 const LSRequestParams& aParams) {
353 AssertIsInMainProcess();
354 AssertIsOnBackgroundThread();
356 return mozilla::dom::AllocPBackgroundLSRequestParent(this, aParams);
359 mozilla::ipc::IPCResult
360 BackgroundParentImpl::RecvPBackgroundLSRequestConstructor(
361 PBackgroundLSRequestParent* aActor, const LSRequestParams& aParams) {
362 AssertIsInMainProcess();
363 AssertIsOnBackgroundThread();
364 MOZ_ASSERT(aActor);
366 if (!mozilla::dom::RecvPBackgroundLSRequestConstructor(aActor, aParams)) {
367 return IPC_FAIL_NO_REASON(this);
369 return IPC_OK();
372 bool BackgroundParentImpl::DeallocPBackgroundLSRequestParent(
373 PBackgroundLSRequestParent* aActor) {
374 AssertIsInMainProcess();
375 AssertIsOnBackgroundThread();
376 MOZ_ASSERT(aActor);
378 return mozilla::dom::DeallocPBackgroundLSRequestParent(aActor);
381 BackgroundParentImpl::PBackgroundLSSimpleRequestParent*
382 BackgroundParentImpl::AllocPBackgroundLSSimpleRequestParent(
383 const LSSimpleRequestParams& aParams) {
384 AssertIsInMainProcess();
385 AssertIsOnBackgroundThread();
387 return mozilla::dom::AllocPBackgroundLSSimpleRequestParent(this, aParams);
390 mozilla::ipc::IPCResult
391 BackgroundParentImpl::RecvPBackgroundLSSimpleRequestConstructor(
392 PBackgroundLSSimpleRequestParent* aActor,
393 const LSSimpleRequestParams& aParams) {
394 AssertIsInMainProcess();
395 AssertIsOnBackgroundThread();
396 MOZ_ASSERT(aActor);
398 if (!mozilla::dom::RecvPBackgroundLSSimpleRequestConstructor(aActor,
399 aParams)) {
400 return IPC_FAIL_NO_REASON(this);
402 return IPC_OK();
405 bool BackgroundParentImpl::DeallocPBackgroundLSSimpleRequestParent(
406 PBackgroundLSSimpleRequestParent* aActor) {
407 AssertIsInMainProcess();
408 AssertIsOnBackgroundThread();
409 MOZ_ASSERT(aActor);
411 return mozilla::dom::DeallocPBackgroundLSSimpleRequestParent(aActor);
414 BackgroundParentImpl::PBackgroundLocalStorageCacheParent*
415 BackgroundParentImpl::AllocPBackgroundLocalStorageCacheParent(
416 const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
417 const uint32_t& aPrivateBrowsingId) {
418 AssertIsInMainProcess();
419 AssertIsOnBackgroundThread();
421 return mozilla::dom::AllocPBackgroundLocalStorageCacheParent(
422 aPrincipalInfo, aOriginKey, aPrivateBrowsingId);
425 mozilla::ipc::IPCResult
426 BackgroundParentImpl::RecvPBackgroundLocalStorageCacheConstructor(
427 PBackgroundLocalStorageCacheParent* aActor,
428 const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
429 const uint32_t& aPrivateBrowsingId) {
430 AssertIsInMainProcess();
431 AssertIsOnBackgroundThread();
432 MOZ_ASSERT(aActor);
434 return mozilla::dom::RecvPBackgroundLocalStorageCacheConstructor(
435 this, aActor, aPrincipalInfo, aOriginKey, aPrivateBrowsingId);
438 bool BackgroundParentImpl::DeallocPBackgroundLocalStorageCacheParent(
439 PBackgroundLocalStorageCacheParent* aActor) {
440 AssertIsInMainProcess();
441 AssertIsOnBackgroundThread();
442 MOZ_ASSERT(aActor);
444 return mozilla::dom::DeallocPBackgroundLocalStorageCacheParent(aActor);
447 auto BackgroundParentImpl::AllocPBackgroundStorageParent(
448 const nsAString& aProfilePath, const uint32_t& aPrivateBrowsingId)
449 -> PBackgroundStorageParent* {
450 AssertIsInMainProcess();
451 AssertIsOnBackgroundThread();
453 return mozilla::dom::AllocPBackgroundStorageParent(aProfilePath,
454 aPrivateBrowsingId);
457 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundStorageConstructor(
458 PBackgroundStorageParent* aActor, const nsAString& aProfilePath,
459 const uint32_t& aPrivateBrowsingId) {
460 AssertIsInMainProcess();
461 AssertIsOnBackgroundThread();
462 MOZ_ASSERT(aActor);
464 return mozilla::dom::RecvPBackgroundStorageConstructor(aActor, aProfilePath,
465 aPrivateBrowsingId);
468 bool BackgroundParentImpl::DeallocPBackgroundStorageParent(
469 PBackgroundStorageParent* aActor) {
470 AssertIsInMainProcess();
471 AssertIsOnBackgroundThread();
472 MOZ_ASSERT(aActor);
474 return mozilla::dom::DeallocPBackgroundStorageParent(aActor);
477 already_AddRefed<BackgroundParentImpl::PBackgroundSessionStorageManagerParent>
478 BackgroundParentImpl::AllocPBackgroundSessionStorageManagerParent(
479 const uint64_t& aTopContextId) {
480 AssertIsInMainProcess();
481 AssertIsOnBackgroundThread();
483 return dom::AllocPBackgroundSessionStorageManagerParent(aTopContextId);
486 already_AddRefed<mozilla::dom::PBackgroundSessionStorageServiceParent>
487 BackgroundParentImpl::AllocPBackgroundSessionStorageServiceParent() {
488 AssertIsInMainProcess();
489 AssertIsOnBackgroundThread();
491 return MakeAndAddRef<mozilla::dom::BackgroundSessionStorageServiceParent>();
494 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateFileSystemManagerParent(
495 const PrincipalInfo& aPrincipalInfo,
496 Endpoint<PFileSystemManagerParent>&& aParentEndpoint,
497 CreateFileSystemManagerParentResolver&& aResolver) {
498 AssertIsInMainProcess();
499 AssertIsOnBackgroundThread();
501 return mozilla::dom::CreateFileSystemManagerParent(
502 aPrincipalInfo, std::move(aParentEndpoint), std::move(aResolver));
505 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateWebTransportParent(
506 const nsAString& aURL, nsIPrincipal* aPrincipal,
507 const mozilla::Maybe<IPCClientInfo>& aClientInfo, const bool& aDedicated,
508 const bool& aRequireUnreliable, const uint32_t& aCongestionControl,
509 // Sequence<WebTransportHash>* aServerCertHashes,
510 Endpoint<PWebTransportParent>&& aParentEndpoint,
511 CreateWebTransportParentResolver&& aResolver) {
512 AssertIsInMainProcess();
513 AssertIsOnBackgroundThread();
515 RefPtr<mozilla::dom::WebTransportParent> webt =
516 new mozilla::dom::WebTransportParent();
517 webt->Create(aURL, aPrincipal, aClientInfo, aDedicated, aRequireUnreliable,
518 aCongestionControl,
519 /*aServerCertHashes, */ std::move(aParentEndpoint),
520 std::move(aResolver));
521 return IPC_OK();
524 already_AddRefed<PIdleSchedulerParent>
525 BackgroundParentImpl::AllocPIdleSchedulerParent() {
526 AssertIsOnBackgroundThread();
527 RefPtr<IdleSchedulerParent> actor = new IdleSchedulerParent();
528 return actor.forget();
531 dom::PRemoteWorkerControllerParent*
532 BackgroundParentImpl::AllocPRemoteWorkerControllerParent(
533 const dom::RemoteWorkerData& aRemoteWorkerData) {
534 RefPtr<dom::RemoteWorkerControllerParent> actor =
535 new dom::RemoteWorkerControllerParent(aRemoteWorkerData);
536 return actor.forget().take();
539 IPCResult BackgroundParentImpl::RecvPRemoteWorkerControllerConstructor(
540 dom::PRemoteWorkerControllerParent* aActor,
541 const dom::RemoteWorkerData& aRemoteWorkerData) {
542 MOZ_ASSERT(aActor);
544 return IPC_OK();
547 bool BackgroundParentImpl::DeallocPRemoteWorkerControllerParent(
548 dom::PRemoteWorkerControllerParent* aActor) {
549 RefPtr<dom::RemoteWorkerControllerParent> actor =
550 dont_AddRef(static_cast<dom::RemoteWorkerControllerParent*>(aActor));
551 return true;
554 already_AddRefed<dom::PRemoteWorkerServiceParent>
555 BackgroundParentImpl::AllocPRemoteWorkerServiceParent() {
556 return MakeAndAddRef<dom::RemoteWorkerServiceParent>();
559 IPCResult BackgroundParentImpl::RecvPRemoteWorkerServiceConstructor(
560 PRemoteWorkerServiceParent* aActor) {
561 mozilla::dom::RemoteWorkerServiceParent* actor =
562 static_cast<mozilla::dom::RemoteWorkerServiceParent*>(aActor);
564 RefPtr<ThreadsafeContentParentHandle> parent =
565 BackgroundParent::GetContentParentHandle(this);
566 // If the ContentParent is null we are dealing with a same-process actor.
567 if (!parent) {
568 actor->Initialize(NOT_REMOTE_TYPE);
569 } else {
570 actor->Initialize(parent->GetRemoteType());
572 return IPC_OK();
575 mozilla::dom::PSharedWorkerParent*
576 BackgroundParentImpl::AllocPSharedWorkerParent(
577 const mozilla::dom::RemoteWorkerData& aData, const uint64_t& aWindowID,
578 const mozilla::dom::MessagePortIdentifier& aPortIdentifier) {
579 RefPtr<dom::SharedWorkerParent> agent =
580 new mozilla::dom::SharedWorkerParent();
581 return agent.forget().take();
584 IPCResult BackgroundParentImpl::RecvPSharedWorkerConstructor(
585 PSharedWorkerParent* aActor, const mozilla::dom::RemoteWorkerData& aData,
586 const uint64_t& aWindowID,
587 const mozilla::dom::MessagePortIdentifier& aPortIdentifier) {
588 mozilla::dom::SharedWorkerParent* actor =
589 static_cast<mozilla::dom::SharedWorkerParent*>(aActor);
590 actor->Initialize(aData, aWindowID, aPortIdentifier);
591 return IPC_OK();
594 bool BackgroundParentImpl::DeallocPSharedWorkerParent(
595 mozilla::dom::PSharedWorkerParent* aActor) {
596 RefPtr<mozilla::dom::SharedWorkerParent> actor =
597 dont_AddRef(static_cast<mozilla::dom::SharedWorkerParent*>(aActor));
598 return true;
601 dom::PFileCreatorParent* BackgroundParentImpl::AllocPFileCreatorParent(
602 const nsAString& aFullPath, const nsAString& aType, const nsAString& aName,
603 const Maybe<int64_t>& aLastModified, const bool& aExistenceCheck,
604 const bool& aIsFromNsIFile) {
605 RefPtr<dom::FileCreatorParent> actor = new dom::FileCreatorParent();
606 return actor.forget().take();
609 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPFileCreatorConstructor(
610 dom::PFileCreatorParent* aActor, const nsAString& aFullPath,
611 const nsAString& aType, const nsAString& aName,
612 const Maybe<int64_t>& aLastModified, const bool& aExistenceCheck,
613 const bool& aIsFromNsIFile) {
614 bool isFileRemoteType = false;
616 // If the ContentParentHandle is null we are dealing with a same-process
617 // actor.
618 RefPtr<ThreadsafeContentParentHandle> parent =
619 BackgroundParent::GetContentParentHandle(this);
620 if (!parent) {
621 isFileRemoteType = true;
622 } else {
623 isFileRemoteType = parent->GetRemoteType() == FILE_REMOTE_TYPE;
626 dom::FileCreatorParent* actor = static_cast<dom::FileCreatorParent*>(aActor);
628 // We allow the creation of File via this IPC call only for the 'file' process
629 // or for testing.
630 if (!isFileRemoteType && !StaticPrefs::dom_file_createInChild()) {
631 Unused << dom::FileCreatorParent::Send__delete__(
632 actor, dom::FileCreationErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
633 return IPC_OK();
636 return actor->CreateAndShareFile(aFullPath, aType, aName, aLastModified,
637 aExistenceCheck, aIsFromNsIFile);
640 bool BackgroundParentImpl::DeallocPFileCreatorParent(
641 dom::PFileCreatorParent* aActor) {
642 RefPtr<dom::FileCreatorParent> actor =
643 dont_AddRef(static_cast<dom::FileCreatorParent*>(aActor));
644 return true;
647 dom::PTemporaryIPCBlobParent*
648 BackgroundParentImpl::AllocPTemporaryIPCBlobParent() {
649 return new dom::TemporaryIPCBlobParent();
652 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPTemporaryIPCBlobConstructor(
653 dom::PTemporaryIPCBlobParent* aActor) {
654 dom::TemporaryIPCBlobParent* actor =
655 static_cast<dom::TemporaryIPCBlobParent*>(aActor);
656 return actor->CreateAndShareFile();
659 bool BackgroundParentImpl::DeallocPTemporaryIPCBlobParent(
660 dom::PTemporaryIPCBlobParent* aActor) {
661 delete aActor;
662 return true;
665 already_AddRefed<BackgroundParentImpl::PVsyncParent>
666 BackgroundParentImpl::AllocPVsyncParent() {
667 AssertIsInMainProcess();
668 AssertIsOnBackgroundThread();
670 RefPtr<mozilla::dom::VsyncParent> actor = new mozilla::dom::VsyncParent();
672 RefPtr<mozilla::VsyncDispatcher> vsyncDispatcher =
673 gfxPlatform::GetPlatform()->GetGlobalVsyncDispatcher();
674 actor->UpdateVsyncDispatcher(vsyncDispatcher);
675 return actor.forget();
678 camera::PCamerasParent* BackgroundParentImpl::AllocPCamerasParent() {
679 AssertIsInMainProcess();
680 AssertIsOnBackgroundThread();
682 #ifdef MOZ_WEBRTC
683 RefPtr<mozilla::camera::CamerasParent> actor =
684 mozilla::camera::CamerasParent::Create();
685 return actor.forget().take();
686 #else
687 return nullptr;
688 #endif
691 #ifdef MOZ_WEBRTC
692 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPCamerasConstructor(
693 camera::PCamerasParent* aActor) {
694 AssertIsInMainProcess();
695 AssertIsOnBackgroundThread();
696 MOZ_ASSERT(aActor);
697 return static_cast<camera::CamerasParent*>(aActor)->RecvPCamerasConstructor();
699 #endif
701 bool BackgroundParentImpl::DeallocPCamerasParent(
702 camera::PCamerasParent* aActor) {
703 AssertIsInMainProcess();
704 AssertIsOnBackgroundThread();
705 MOZ_ASSERT(aActor);
707 #ifdef MOZ_WEBRTC
708 RefPtr<mozilla::camera::CamerasParent> actor =
709 dont_AddRef(static_cast<mozilla::camera::CamerasParent*>(aActor));
710 #endif
711 return true;
714 auto BackgroundParentImpl::AllocPUDPSocketParent(
715 const Maybe<PrincipalInfo>& /* unused */, const nsACString& /* unused */)
716 -> PUDPSocketParent* {
717 RefPtr<UDPSocketParent> p = new UDPSocketParent(this);
719 return p.forget().take();
722 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPUDPSocketConstructor(
723 PUDPSocketParent* aActor, const Maybe<PrincipalInfo>& aOptionalPrincipal,
724 const nsACString& aFilter) {
725 AssertIsInMainProcess();
726 AssertIsOnBackgroundThread();
728 if (aOptionalPrincipal.isSome()) {
729 // Support for checking principals (for non-mtransport use) will be handled
730 // in bug 1167039
731 return IPC_FAIL_NO_REASON(this);
733 // No principal - This must be from mtransport (WebRTC/ICE) - We'd want
734 // to DispatchToMainThread() here, but if we do we must block RecvBind()
735 // until Init() gets run. Since we don't have a principal, and we verify
736 // we have a filter, we can safely skip the Dispatch and just invoke Init()
737 // to install the filter.
739 // For mtransport, this will always be "stun", which doesn't allow outbound
740 // packets if they aren't STUN packets until a STUN response is seen.
741 if (!aFilter.EqualsASCII(NS_NETWORK_SOCKET_FILTER_HANDLER_STUN_SUFFIX)) {
742 return IPC_FAIL_NO_REASON(this);
745 if (!static_cast<UDPSocketParent*>(aActor)->Init(nullptr, aFilter)) {
746 MOZ_CRASH("UDPSocketCallback - failed init");
749 return IPC_OK();
752 bool BackgroundParentImpl::DeallocPUDPSocketParent(PUDPSocketParent* actor) {
753 UDPSocketParent* p = static_cast<UDPSocketParent*>(actor);
754 p->Release();
755 return true;
758 mozilla::dom::PBroadcastChannelParent*
759 BackgroundParentImpl::AllocPBroadcastChannelParent(
760 const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin,
761 const nsAString& aChannel) {
762 AssertIsInMainProcess();
763 AssertIsOnBackgroundThread();
765 nsString originChannelKey;
767 // The format of originChannelKey is:
768 // <channelName>|<origin+OriginAttributes>
770 originChannelKey.Assign(aChannel);
772 originChannelKey.AppendLiteral("|");
774 originChannelKey.Append(NS_ConvertUTF8toUTF16(aOrigin));
776 return new BroadcastChannelParent(originChannelKey);
779 namespace {
781 class CheckPrincipalRunnable final : public Runnable {
782 public:
783 CheckPrincipalRunnable(
784 already_AddRefed<ThreadsafeContentParentHandle> aParent,
785 const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin)
786 : Runnable("ipc::CheckPrincipalRunnable"),
787 mContentParent(aParent),
788 mPrincipalInfo(aPrincipalInfo),
789 mOrigin(aOrigin) {
790 AssertIsInMainProcess();
791 AssertIsOnBackgroundThread();
793 MOZ_ASSERT(mContentParent);
796 NS_IMETHOD Run() override {
797 AssertIsOnMainThread();
798 RefPtr<ContentParent> contentParent = mContentParent->GetContentParent();
799 if (!contentParent) {
800 return NS_OK;
803 auto principalOrErr = PrincipalInfoToPrincipal(mPrincipalInfo);
804 if (NS_WARN_IF(principalOrErr.isErr())) {
805 contentParent->KillHard(
806 "BroadcastChannel killed: PrincipalInfoToPrincipal failed.");
807 return NS_OK;
810 nsAutoCString origin;
811 nsresult rv = principalOrErr.unwrap()->GetOrigin(origin);
812 if (NS_FAILED(rv)) {
813 contentParent->KillHard(
814 "BroadcastChannel killed: principal::GetOrigin failed.");
815 return NS_OK;
818 if (NS_WARN_IF(!mOrigin.Equals(origin))) {
819 contentParent->KillHard("BroadcastChannel killed: origins do not match.");
820 return NS_OK;
823 return NS_OK;
826 private:
827 RefPtr<ThreadsafeContentParentHandle> mContentParent;
828 PrincipalInfo mPrincipalInfo;
829 nsCString mOrigin;
832 } // namespace
834 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBroadcastChannelConstructor(
835 PBroadcastChannelParent* actor, const PrincipalInfo& aPrincipalInfo,
836 const nsACString& aOrigin, const nsAString& aChannel) {
837 AssertIsInMainProcess();
838 AssertIsOnBackgroundThread();
840 RefPtr<ThreadsafeContentParentHandle> parent =
841 BackgroundParent::GetContentParentHandle(this);
843 // If the ContentParent is null we are dealing with a same-process actor.
844 if (!parent) {
845 return IPC_OK();
848 // XXX The principal can be checked right here on the PBackground thread
849 // since BackgroundParentImpl now overrides the ProcessingError method and
850 // kills invalid child processes (IPC_FAIL triggers a processing error).
852 RefPtr<CheckPrincipalRunnable> runnable =
853 new CheckPrincipalRunnable(parent.forget(), aPrincipalInfo, aOrigin);
854 MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
856 return IPC_OK();
859 bool BackgroundParentImpl::DeallocPBroadcastChannelParent(
860 PBroadcastChannelParent* aActor) {
861 AssertIsInMainProcess();
862 AssertIsOnBackgroundThread();
863 MOZ_ASSERT(aActor);
865 delete static_cast<BroadcastChannelParent*>(aActor);
866 return true;
869 mozilla::dom::PServiceWorkerManagerParent*
870 BackgroundParentImpl::AllocPServiceWorkerManagerParent() {
871 AssertIsInMainProcess();
872 AssertIsOnBackgroundThread();
874 RefPtr<dom::ServiceWorkerManagerParent> agent =
875 new dom::ServiceWorkerManagerParent();
876 return agent.forget().take();
879 bool BackgroundParentImpl::DeallocPServiceWorkerManagerParent(
880 PServiceWorkerManagerParent* aActor) {
881 AssertIsInMainProcess();
882 AssertIsOnBackgroundThread();
883 MOZ_ASSERT(aActor);
885 RefPtr<dom::ServiceWorkerManagerParent> parent =
886 dont_AddRef(static_cast<dom::ServiceWorkerManagerParent*>(aActor));
887 MOZ_ASSERT(parent);
888 return true;
891 mozilla::ipc::IPCResult
892 BackgroundParentImpl::RecvShutdownServiceWorkerRegistrar() {
893 AssertIsInMainProcess();
894 AssertIsOnBackgroundThread();
896 if (BackgroundParent::IsOtherProcessActor(this)) {
897 return IPC_FAIL_NO_REASON(this);
900 RefPtr<dom::ServiceWorkerRegistrar> service =
901 dom::ServiceWorkerRegistrar::Get();
902 MOZ_ASSERT(service);
904 service->Shutdown();
905 return IPC_OK();
908 already_AddRefed<PCacheStorageParent>
909 BackgroundParentImpl::AllocPCacheStorageParent(
910 const Namespace& aNamespace, const PrincipalInfo& aPrincipalInfo) {
911 return dom::cache::AllocPCacheStorageParent(this, aNamespace, aPrincipalInfo);
914 PMessagePortParent* BackgroundParentImpl::AllocPMessagePortParent(
915 const nsID& aUUID, const nsID& aDestinationUUID,
916 const uint32_t& aSequenceID) {
917 AssertIsInMainProcess();
918 AssertIsOnBackgroundThread();
920 return new MessagePortParent(aUUID);
923 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPMessagePortConstructor(
924 PMessagePortParent* aActor, const nsID& aUUID, const nsID& aDestinationUUID,
925 const uint32_t& aSequenceID) {
926 AssertIsInMainProcess();
927 AssertIsOnBackgroundThread();
929 MessagePortParent* mp = static_cast<MessagePortParent*>(aActor);
930 if (!mp->Entangle(aDestinationUUID, aSequenceID)) {
931 return IPC_FAIL_NO_REASON(this);
933 return IPC_OK();
936 bool BackgroundParentImpl::DeallocPMessagePortParent(
937 PMessagePortParent* aActor) {
938 AssertIsInMainProcess();
939 AssertIsOnBackgroundThread();
940 MOZ_ASSERT(aActor);
942 delete static_cast<MessagePortParent*>(aActor);
943 return true;
946 mozilla::ipc::IPCResult BackgroundParentImpl::RecvMessagePortForceClose(
947 const nsID& aUUID, const nsID& aDestinationUUID,
948 const uint32_t& aSequenceID) {
949 AssertIsInMainProcess();
950 AssertIsOnBackgroundThread();
952 if (!MessagePortParent::ForceClose(aUUID, aDestinationUUID, aSequenceID)) {
953 return IPC_FAIL(this, "MessagePortParent::ForceClose failed.");
956 return IPC_OK();
959 BackgroundParentImpl::PQuotaParent* BackgroundParentImpl::AllocPQuotaParent() {
960 AssertIsInMainProcess();
961 AssertIsOnBackgroundThread();
963 return mozilla::dom::quota::AllocPQuotaParent();
966 bool BackgroundParentImpl::DeallocPQuotaParent(PQuotaParent* aActor) {
967 AssertIsInMainProcess();
968 AssertIsOnBackgroundThread();
969 MOZ_ASSERT(aActor);
971 return mozilla::dom::quota::DeallocPQuotaParent(aActor);
974 mozilla::ipc::IPCResult BackgroundParentImpl::RecvShutdownQuotaManager() {
975 AssertIsInMainProcess();
976 AssertIsOnBackgroundThread();
978 if (BackgroundParent::IsOtherProcessActor(this)) {
979 return IPC_FAIL_NO_REASON(this);
982 if (!mozilla::dom::quota::RecvShutdownQuotaManager()) {
983 return IPC_FAIL_NO_REASON(this);
985 return IPC_OK();
988 mozilla::ipc::IPCResult
989 BackgroundParentImpl::RecvShutdownBackgroundSessionStorageManagers() {
990 AssertIsInMainProcess();
991 AssertIsOnBackgroundThread();
993 if (BackgroundParent::IsOtherProcessActor(this)) {
994 return IPC_FAIL_NO_REASON(this);
997 if (!mozilla::dom::RecvShutdownBackgroundSessionStorageManagers()) {
998 return IPC_FAIL_NO_REASON(this);
1000 return IPC_OK();
1003 mozilla::ipc::IPCResult
1004 BackgroundParentImpl::RecvPropagateBackgroundSessionStorageManager(
1005 const uint64_t& aCurrentTopContextId, const uint64_t& aTargetTopContextId) {
1006 AssertIsInMainProcess();
1007 AssertIsOnBackgroundThread();
1009 if (BackgroundParent::IsOtherProcessActor(this)) {
1010 return IPC_FAIL(this, "Wrong actor");
1013 mozilla::dom::RecvPropagateBackgroundSessionStorageManager(
1014 aCurrentTopContextId, aTargetTopContextId);
1016 return IPC_OK();
1019 mozilla::ipc::IPCResult
1020 BackgroundParentImpl::RecvRemoveBackgroundSessionStorageManager(
1021 const uint64_t& aTopContextId) {
1022 AssertIsInMainProcess();
1023 AssertIsOnBackgroundThread();
1025 if (BackgroundParent::IsOtherProcessActor(this)) {
1026 return IPC_FAIL_NO_REASON(this);
1029 if (!mozilla::dom::RecvRemoveBackgroundSessionStorageManager(aTopContextId)) {
1030 return IPC_FAIL_NO_REASON(this);
1032 return IPC_OK();
1035 mozilla::ipc::IPCResult BackgroundParentImpl::RecvGetSessionStorageManagerData(
1036 const uint64_t& aTopContextId, const uint32_t& aSizeLimit,
1037 const bool& aCancelSessionStoreTimer,
1038 GetSessionStorageManagerDataResolver&& aResolver) {
1039 AssertIsInMainProcess();
1040 AssertIsOnBackgroundThread();
1042 if (BackgroundParent::IsOtherProcessActor(this)) {
1043 return IPC_FAIL(this, "Wrong actor");
1046 if (!mozilla::dom::RecvGetSessionStorageData(aTopContextId, aSizeLimit,
1047 aCancelSessionStoreTimer,
1048 std::move(aResolver))) {
1049 return IPC_FAIL(this, "Couldn't get session storage data");
1052 return IPC_OK();
1055 mozilla::ipc::IPCResult BackgroundParentImpl::RecvLoadSessionStorageManagerData(
1056 const uint64_t& aTopContextId,
1057 nsTArray<mozilla::dom::SSCacheCopy>&& aOriginCacheCopy) {
1058 AssertIsInMainProcess();
1059 AssertIsOnBackgroundThread();
1061 if (BackgroundParent::IsOtherProcessActor(this)) {
1062 return IPC_FAIL(this, "Wrong actor");
1065 if (!mozilla::dom::RecvLoadSessionStorageData(aTopContextId,
1066 std::move(aOriginCacheCopy))) {
1067 return IPC_FAIL_NO_REASON(this);
1070 return IPC_OK();
1073 already_AddRefed<dom::PFileSystemRequestParent>
1074 BackgroundParentImpl::AllocPFileSystemRequestParent(
1075 const FileSystemParams& aParams) {
1076 AssertIsInMainProcess();
1077 AssertIsOnBackgroundThread();
1079 RefPtr<FileSystemRequestParent> result = new FileSystemRequestParent();
1081 if (NS_WARN_IF(!result->Initialize(aParams))) {
1082 return nullptr;
1085 return result.forget();
1088 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPFileSystemRequestConstructor(
1089 PFileSystemRequestParent* aActor, const FileSystemParams& params) {
1090 static_cast<FileSystemRequestParent*>(aActor)->Start();
1091 return IPC_OK();
1094 // Gamepad API Background IPC
1095 already_AddRefed<dom::PGamepadEventChannelParent>
1096 BackgroundParentImpl::AllocPGamepadEventChannelParent() {
1097 return dom::GamepadEventChannelParent::Create();
1100 already_AddRefed<dom::PGamepadTestChannelParent>
1101 BackgroundParentImpl::AllocPGamepadTestChannelParent() {
1102 return dom::GamepadTestChannelParent::Create();
1105 dom::PWebAuthnTransactionParent*
1106 BackgroundParentImpl::AllocPWebAuthnTransactionParent() {
1107 return new dom::WebAuthnTransactionParent();
1110 bool BackgroundParentImpl::DeallocPWebAuthnTransactionParent(
1111 dom::PWebAuthnTransactionParent* aActor) {
1112 MOZ_ASSERT(aActor);
1113 delete aActor;
1114 return true;
1117 already_AddRefed<net::PHttpBackgroundChannelParent>
1118 BackgroundParentImpl::AllocPHttpBackgroundChannelParent(
1119 const uint64_t& aChannelId) {
1120 AssertIsInMainProcess();
1121 AssertIsOnBackgroundThread();
1123 RefPtr<net::HttpBackgroundChannelParent> actor =
1124 new net::HttpBackgroundChannelParent();
1125 return actor.forget();
1128 mozilla::ipc::IPCResult
1129 BackgroundParentImpl::RecvPHttpBackgroundChannelConstructor(
1130 net::PHttpBackgroundChannelParent* aActor, const uint64_t& aChannelId) {
1131 MOZ_ASSERT(aActor);
1132 AssertIsInMainProcess();
1133 AssertIsOnBackgroundThread();
1135 net::HttpBackgroundChannelParent* aParent =
1136 static_cast<net::HttpBackgroundChannelParent*>(aActor);
1138 if (NS_WARN_IF(NS_FAILED(aParent->Init(aChannelId)))) {
1139 return IPC_FAIL_NO_REASON(this);
1142 return IPC_OK();
1145 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIPort(
1146 Endpoint<PMIDIPortParent>&& aEndpoint, const MIDIPortInfo& aPortInfo,
1147 const bool& aSysexEnabled) {
1148 AssertIsInMainProcess();
1149 AssertIsOnBackgroundThread();
1151 if (!aEndpoint.IsValid()) {
1152 return IPC_FAIL(this, "invalid endpoint for MIDIPort");
1155 MIDIPlatformService::OwnerThread()->Dispatch(NS_NewRunnableFunction(
1156 "CreateMIDIPortRunnable", [=, endpoint = std::move(aEndpoint)]() mutable {
1157 RefPtr<MIDIPortParent> result =
1158 new MIDIPortParent(aPortInfo, aSysexEnabled);
1159 endpoint.Bind(result);
1160 }));
1162 return IPC_OK();
1165 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIManager(
1166 Endpoint<PMIDIManagerParent>&& aEndpoint) {
1167 AssertIsInMainProcess();
1168 AssertIsOnBackgroundThread();
1170 if (!aEndpoint.IsValid()) {
1171 return IPC_FAIL(this, "invalid endpoint for MIDIManager");
1174 MIDIPlatformService::OwnerThread()->Dispatch(NS_NewRunnableFunction(
1175 "CreateMIDIManagerRunnable",
1176 [=, endpoint = std::move(aEndpoint)]() mutable {
1177 RefPtr<MIDIManagerParent> result = new MIDIManagerParent();
1178 endpoint.Bind(result);
1179 MIDIPlatformService::Get()->AddManager(result);
1180 }));
1182 return IPC_OK();
1185 mozilla::ipc::IPCResult BackgroundParentImpl::RecvHasMIDIDevice(
1186 HasMIDIDeviceResolver&& aResolver) {
1187 AssertIsInMainProcess();
1188 AssertIsOnBackgroundThread();
1190 InvokeAsync(MIDIPlatformService::OwnerThread(), __func__,
1191 []() {
1192 bool hasDevice = MIDIPlatformService::Get()->HasDevice();
1193 return BoolPromise::CreateAndResolve(hasDevice, __func__);
1195 ->Then(GetCurrentSerialEventTarget(), __func__,
1196 [resolver = std::move(aResolver)](
1197 const BoolPromise::ResolveOrRejectValue& r) {
1198 resolver(r.IsResolve() && r.ResolveValue());
1201 return IPC_OK();
1204 mozilla::dom::PClientManagerParent*
1205 BackgroundParentImpl::AllocPClientManagerParent() {
1206 return mozilla::dom::AllocClientManagerParent();
1209 bool BackgroundParentImpl::DeallocPClientManagerParent(
1210 mozilla::dom::PClientManagerParent* aActor) {
1211 return mozilla::dom::DeallocClientManagerParent(aActor);
1214 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPClientManagerConstructor(
1215 mozilla::dom::PClientManagerParent* aActor) {
1216 mozilla::dom::InitClientManagerParent(aActor);
1217 return IPC_OK();
1220 IPCResult BackgroundParentImpl::RecvStorageActivity(
1221 const PrincipalInfo& aPrincipalInfo) {
1222 dom::StorageActivityService::SendActivity(aPrincipalInfo);
1223 return IPC_OK();
1226 IPCResult BackgroundParentImpl::RecvPServiceWorkerManagerConstructor(
1227 PServiceWorkerManagerParent* const aActor) {
1228 // Only the parent process is allowed to construct this actor.
1229 if (BackgroundParent::IsOtherProcessActor(this)) {
1230 return IPC_FAIL_NO_REASON(aActor);
1232 return IPC_OK();
1235 already_AddRefed<PServiceWorkerParent>
1236 BackgroundParentImpl::AllocPServiceWorkerParent(
1237 const IPCServiceWorkerDescriptor&) {
1238 return MakeAndAddRef<ServiceWorkerParent>();
1241 IPCResult BackgroundParentImpl::RecvPServiceWorkerConstructor(
1242 PServiceWorkerParent* aActor,
1243 const IPCServiceWorkerDescriptor& aDescriptor) {
1244 dom::InitServiceWorkerParent(aActor, aDescriptor);
1245 return IPC_OK();
1248 already_AddRefed<PServiceWorkerContainerParent>
1249 BackgroundParentImpl::AllocPServiceWorkerContainerParent() {
1250 return MakeAndAddRef<mozilla::dom::ServiceWorkerContainerParent>();
1253 mozilla::ipc::IPCResult
1254 BackgroundParentImpl::RecvPServiceWorkerContainerConstructor(
1255 PServiceWorkerContainerParent* aActor) {
1256 dom::InitServiceWorkerContainerParent(aActor);
1257 return IPC_OK();
1260 already_AddRefed<PServiceWorkerRegistrationParent>
1261 BackgroundParentImpl::AllocPServiceWorkerRegistrationParent(
1262 const IPCServiceWorkerRegistrationDescriptor&) {
1263 return MakeAndAddRef<mozilla::dom::ServiceWorkerRegistrationParent>();
1266 mozilla::ipc::IPCResult
1267 BackgroundParentImpl::RecvPServiceWorkerRegistrationConstructor(
1268 PServiceWorkerRegistrationParent* aActor,
1269 const IPCServiceWorkerRegistrationDescriptor& aDescriptor) {
1270 dom::InitServiceWorkerRegistrationParent(aActor, aDescriptor);
1271 return IPC_OK();
1274 dom::PEndpointForReportParent*
1275 BackgroundParentImpl::AllocPEndpointForReportParent(
1276 const nsAString& aGroupName, const PrincipalInfo& aPrincipalInfo) {
1277 RefPtr<dom::EndpointForReportParent> actor =
1278 new dom::EndpointForReportParent();
1279 return actor.forget().take();
1282 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPEndpointForReportConstructor(
1283 PEndpointForReportParent* aActor, const nsAString& aGroupName,
1284 const PrincipalInfo& aPrincipalInfo) {
1285 static_cast<dom::EndpointForReportParent*>(aActor)->Run(aGroupName,
1286 aPrincipalInfo);
1287 return IPC_OK();
1290 mozilla::ipc::IPCResult
1291 BackgroundParentImpl::RecvEnsureRDDProcessAndCreateBridge(
1292 EnsureRDDProcessAndCreateBridgeResolver&& aResolver) {
1293 RDDProcessManager* rdd = RDDProcessManager::Get();
1294 using Type = std::tuple<const nsresult&,
1295 Endpoint<mozilla::PRemoteDecoderManagerChild>&&>;
1296 if (!rdd) {
1297 aResolver(
1298 Type(NS_ERROR_NOT_AVAILABLE, Endpoint<PRemoteDecoderManagerChild>()));
1299 } else {
1300 rdd->EnsureRDDProcessAndCreateBridge(OtherPid())
1301 ->Then(GetCurrentSerialEventTarget(), __func__,
1302 [resolver = std::move(aResolver)](
1303 mozilla::RDDProcessManager::EnsureRDDPromise::
1304 ResolveOrRejectValue&& aValue) mutable {
1305 if (aValue.IsReject()) {
1306 resolver(Type(aValue.RejectValue(),
1307 Endpoint<PRemoteDecoderManagerChild>()));
1308 return;
1310 resolver(Type(NS_OK, std::move(aValue.ResolveValue())));
1313 return IPC_OK();
1316 mozilla::ipc::IPCResult
1317 BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge(
1318 const RemoteDecodeIn& aLocation,
1319 EnsureUtilityProcessAndCreateBridgeResolver&& aResolver) {
1320 base::ProcessId otherPid = OtherPid();
1321 nsCOMPtr<nsISerialEventTarget> managerThread = GetCurrentSerialEventTarget();
1322 if (!managerThread) {
1323 return IPC_FAIL_NO_REASON(this);
1325 NS_DispatchToMainThread(NS_NewRunnableFunction(
1326 "BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge()",
1327 [aResolver, managerThread, otherPid, aLocation]() {
1328 RefPtr<UtilityProcessManager> upm =
1329 UtilityProcessManager::GetSingleton();
1330 using Type =
1331 std::tuple<const nsresult&,
1332 Endpoint<mozilla::PRemoteDecoderManagerChild>&&>;
1333 if (!upm) {
1334 managerThread->Dispatch(NS_NewRunnableFunction(
1335 "BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge::"
1336 "Failure",
1337 [aResolver]() {
1338 aResolver(Type(NS_ERROR_NOT_AVAILABLE,
1339 Endpoint<PRemoteDecoderManagerChild>()));
1340 }));
1341 } else {
1342 SandboxingKind sbKind = GetSandboxingKindFromLocation(aLocation);
1343 upm->StartProcessForRemoteMediaDecoding(otherPid, sbKind)
1344 ->Then(managerThread, __func__,
1345 [resolver = aResolver](
1346 mozilla::ipc::UtilityProcessManager::
1347 StartRemoteDecodingUtilityPromise::
1348 ResolveOrRejectValue&& aValue) mutable {
1349 if (aValue.IsReject()) {
1350 resolver(Type(aValue.RejectValue(),
1351 Endpoint<PRemoteDecoderManagerChild>()));
1352 return;
1354 resolver(Type(NS_OK, std::move(aValue.ResolveValue())));
1357 }));
1358 return IPC_OK();
1361 mozilla::ipc::IPCResult BackgroundParentImpl::RecvRequestCameraAccess(
1362 RequestCameraAccessResolver&& aResolver) {
1363 #ifdef MOZ_WEBRTC
1364 mozilla::camera::CamerasParent::RequestCameraAccess()->Then(
1365 GetCurrentSerialEventTarget(), __func__,
1366 [resolver = std::move(aResolver)](
1367 const mozilla::camera::CamerasParent::CameraAccessRequestPromise::
1368 ResolveOrRejectValue& aValue) {
1369 if (aValue.IsResolve()) {
1370 resolver(aValue.ResolveValue());
1371 } else {
1372 resolver(aValue.RejectValue());
1375 #else
1376 aResolver(NS_ERROR_NOT_IMPLEMENTED);
1377 #endif
1378 return IPC_OK();
1381 bool BackgroundParentImpl::DeallocPEndpointForReportParent(
1382 PEndpointForReportParent* aActor) {
1383 RefPtr<dom::EndpointForReportParent> actor =
1384 dont_AddRef(static_cast<dom::EndpointForReportParent*>(aActor));
1385 return true;
1388 mozilla::ipc::IPCResult BackgroundParentImpl::RecvRemoveEndpoint(
1389 const nsAString& aGroupName, const nsACString& aEndpointURL,
1390 const PrincipalInfo& aPrincipalInfo) {
1391 NS_DispatchToMainThread(NS_NewRunnableFunction(
1392 "BackgroundParentImpl::RecvRemoveEndpoint(",
1393 [aGroupName = nsString(aGroupName),
1394 aEndpointURL = nsCString(aEndpointURL), aPrincipalInfo]() {
1395 dom::ReportingHeader::RemoveEndpoint(aGroupName, aEndpointURL,
1396 aPrincipalInfo);
1397 }));
1399 return IPC_OK();
1402 already_AddRefed<dom::locks::PLockManagerParent>
1403 BackgroundParentImpl::AllocPLockManagerParent(NotNull<nsIPrincipal*> aPrincipal,
1404 const nsID& aClientId) {
1405 return MakeAndAddRef<mozilla::dom::locks::LockManagerParent>(aPrincipal,
1406 aClientId);
1409 already_AddRefed<dom::PFetchParent> BackgroundParentImpl::AllocPFetchParent() {
1410 return MakeAndAddRef<dom::FetchParent>();
1413 } // namespace mozilla::ipc
1415 void TestParent::ActorDestroy(ActorDestroyReason aWhy) {
1416 mozilla::ipc::AssertIsInMainProcess();
1417 AssertIsOnBackgroundThread();