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"
11 # include "CamerasParent.h"
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
;
96 class TestParent final
: public mozilla::ipc::PBackgroundTestParent
{
97 friend class mozilla::ipc::BackgroundParentImpl
;
99 MOZ_COUNTED_DEFAULT_CTOR(TestParent
)
102 ~TestParent() override
{ MOZ_COUNT_DTOR(TestParent
); }
105 void ActorDestroy(ActorDestroyReason aWhy
) override
;
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
) {
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
) {
141 // Other errors are big deals.
142 nsDependentCString
reason(aReason
);
143 if (BackgroundParent::IsOtherProcessActor(this)) {
145 BackgroundParent::KillHardAsync(this, reason
);
148 GetIPCChannel()->InduceConnectionError();
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();
177 if (!PBackgroundTestParent::Send__delete__(aActor
, aTestArg
)) {
178 return IPC_FAIL_NO_REASON(this);
183 bool BackgroundParentImpl::DeallocPBackgroundTestParent(
184 PBackgroundTestParent
* aActor
) {
185 AssertIsInMainProcess();
186 AssertIsOnBackgroundThread();
189 delete static_cast<TestParent
*>(aActor
);
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();
213 if (!RecvPBackgroundIDBFactoryConstructor(aActor
, aLoggingInfo
)) {
214 return IPC_FAIL_NO_REASON(this);
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();
233 return mozilla::dom::indexedDB::DeallocPBackgroundIndexedDBUtilsParent(
237 mozilla::ipc::IPCResult
BackgroundParentImpl::RecvFlushPendingFileDeletions() {
238 AssertIsInMainProcess();
239 AssertIsOnBackgroundThread();
241 if (!mozilla::dom::indexedDB::RecvFlushPendingFileDeletions()) {
242 return IPC_FAIL_NO_REASON(this);
247 BackgroundParentImpl::PBackgroundSDBConnectionParent
*
248 BackgroundParentImpl::AllocPBackgroundSDBConnectionParent(
249 const PersistenceType
& aPersistenceType
,
250 const PrincipalInfo
& aPrincipalInfo
) {
251 AssertIsInMainProcess();
252 AssertIsOnBackgroundThread();
254 return mozilla::dom::AllocPBackgroundSDBConnectionParent(aPersistenceType
,
258 mozilla::ipc::IPCResult
259 BackgroundParentImpl::RecvPBackgroundSDBConnectionConstructor(
260 PBackgroundSDBConnectionParent
* aActor
,
261 const PersistenceType
& aPersistenceType
,
262 const PrincipalInfo
& aPrincipalInfo
) {
263 AssertIsInMainProcess();
264 AssertIsOnBackgroundThread();
267 if (!mozilla::dom::RecvPBackgroundSDBConnectionConstructor(
268 aActor
, aPersistenceType
, aPrincipalInfo
)) {
269 return IPC_FAIL_NO_REASON(this);
274 bool BackgroundParentImpl::DeallocPBackgroundSDBConnectionParent(
275 PBackgroundSDBConnectionParent
* aActor
) {
276 AssertIsInMainProcess();
277 AssertIsOnBackgroundThread();
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();
302 if (!mozilla::dom::RecvPBackgroundLSDatabaseConstructor(
303 aActor
, aPrincipalInfo
, aPrivateBrowsingId
, aDatastoreId
)) {
304 return IPC_FAIL_NO_REASON(this);
309 bool BackgroundParentImpl::DeallocPBackgroundLSDatabaseParent(
310 PBackgroundLSDatabaseParent
* aActor
) {
311 AssertIsInMainProcess();
312 AssertIsOnBackgroundThread();
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();
334 if (!mozilla::dom::RecvPBackgroundLSObserverConstructor(aActor
,
336 return IPC_FAIL_NO_REASON(this);
341 bool BackgroundParentImpl::DeallocPBackgroundLSObserverParent(
342 PBackgroundLSObserverParent
* aActor
) {
343 AssertIsInMainProcess();
344 AssertIsOnBackgroundThread();
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();
366 if (!mozilla::dom::RecvPBackgroundLSRequestConstructor(aActor
, aParams
)) {
367 return IPC_FAIL_NO_REASON(this);
372 bool BackgroundParentImpl::DeallocPBackgroundLSRequestParent(
373 PBackgroundLSRequestParent
* aActor
) {
374 AssertIsInMainProcess();
375 AssertIsOnBackgroundThread();
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();
398 if (!mozilla::dom::RecvPBackgroundLSSimpleRequestConstructor(aActor
,
400 return IPC_FAIL_NO_REASON(this);
405 bool BackgroundParentImpl::DeallocPBackgroundLSSimpleRequestParent(
406 PBackgroundLSSimpleRequestParent
* aActor
) {
407 AssertIsInMainProcess();
408 AssertIsOnBackgroundThread();
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();
434 return mozilla::dom::RecvPBackgroundLocalStorageCacheConstructor(
435 this, aActor
, aPrincipalInfo
, aOriginKey
, aPrivateBrowsingId
);
438 bool BackgroundParentImpl::DeallocPBackgroundLocalStorageCacheParent(
439 PBackgroundLocalStorageCacheParent
* aActor
) {
440 AssertIsInMainProcess();
441 AssertIsOnBackgroundThread();
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
,
457 mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPBackgroundStorageConstructor(
458 PBackgroundStorageParent
* aActor
, const nsAString
& aProfilePath
,
459 const uint32_t& aPrivateBrowsingId
) {
460 AssertIsInMainProcess();
461 AssertIsOnBackgroundThread();
464 return mozilla::dom::RecvPBackgroundStorageConstructor(aActor
, aProfilePath
,
468 bool BackgroundParentImpl::DeallocPBackgroundStorageParent(
469 PBackgroundStorageParent
* aActor
) {
470 AssertIsInMainProcess();
471 AssertIsOnBackgroundThread();
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
,
519 /*aServerCertHashes, */ std::move(aParentEndpoint
),
520 std::move(aResolver
));
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
) {
547 bool BackgroundParentImpl::DeallocPRemoteWorkerControllerParent(
548 dom::PRemoteWorkerControllerParent
* aActor
) {
549 RefPtr
<dom::RemoteWorkerControllerParent
> actor
=
550 dont_AddRef(static_cast<dom::RemoteWorkerControllerParent
*>(aActor
));
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.
568 actor
->Initialize(NOT_REMOTE_TYPE
);
570 actor
->Initialize(parent
->GetRemoteType());
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
);
594 bool BackgroundParentImpl::DeallocPSharedWorkerParent(
595 mozilla::dom::PSharedWorkerParent
* aActor
) {
596 RefPtr
<mozilla::dom::SharedWorkerParent
> actor
=
597 dont_AddRef(static_cast<mozilla::dom::SharedWorkerParent
*>(aActor
));
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
618 RefPtr
<ThreadsafeContentParentHandle
> parent
=
619 BackgroundParent::GetContentParentHandle(this);
621 isFileRemoteType
= true;
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
630 if (!isFileRemoteType
&& !StaticPrefs::dom_file_createInChild()) {
631 Unused
<< dom::FileCreatorParent::Send__delete__(
632 actor
, dom::FileCreationErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR
));
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
));
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
) {
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();
683 RefPtr
<mozilla::camera::CamerasParent
> actor
=
684 mozilla::camera::CamerasParent::Create();
685 return actor
.forget().take();
692 mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPCamerasConstructor(
693 camera::PCamerasParent
* aActor
) {
694 AssertIsInMainProcess();
695 AssertIsOnBackgroundThread();
697 return static_cast<camera::CamerasParent
*>(aActor
)->RecvPCamerasConstructor();
701 bool BackgroundParentImpl::DeallocPCamerasParent(
702 camera::PCamerasParent
* aActor
) {
703 AssertIsInMainProcess();
704 AssertIsOnBackgroundThread();
708 RefPtr
<mozilla::camera::CamerasParent
> actor
=
709 dont_AddRef(static_cast<mozilla::camera::CamerasParent
*>(aActor
));
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
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");
752 bool BackgroundParentImpl::DeallocPUDPSocketParent(PUDPSocketParent
* actor
) {
753 UDPSocketParent
* p
= static_cast<UDPSocketParent
*>(actor
);
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
);
781 class CheckPrincipalRunnable final
: public Runnable
{
783 CheckPrincipalRunnable(
784 already_AddRefed
<ThreadsafeContentParentHandle
> aParent
,
785 const PrincipalInfo
& aPrincipalInfo
, const nsACString
& aOrigin
)
786 : Runnable("ipc::CheckPrincipalRunnable"),
787 mContentParent(aParent
),
788 mPrincipalInfo(aPrincipalInfo
),
790 AssertIsInMainProcess();
791 AssertIsOnBackgroundThread();
793 MOZ_ASSERT(mContentParent
);
796 NS_IMETHOD
Run() override
{
797 AssertIsOnMainThread();
798 RefPtr
<ContentParent
> contentParent
= mContentParent
->GetContentParent();
799 if (!contentParent
) {
803 auto principalOrErr
= PrincipalInfoToPrincipal(mPrincipalInfo
);
804 if (NS_WARN_IF(principalOrErr
.isErr())) {
805 contentParent
->KillHard(
806 "BroadcastChannel killed: PrincipalInfoToPrincipal failed.");
810 nsAutoCString origin
;
811 nsresult rv
= principalOrErr
.unwrap()->GetOrigin(origin
);
813 contentParent
->KillHard(
814 "BroadcastChannel killed: principal::GetOrigin failed.");
818 if (NS_WARN_IF(!mOrigin
.Equals(origin
))) {
819 contentParent
->KillHard("BroadcastChannel killed: origins do not match.");
827 RefPtr
<ThreadsafeContentParentHandle
> mContentParent
;
828 PrincipalInfo mPrincipalInfo
;
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.
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
));
859 bool BackgroundParentImpl::DeallocPBroadcastChannelParent(
860 PBroadcastChannelParent
* aActor
) {
861 AssertIsInMainProcess();
862 AssertIsOnBackgroundThread();
865 delete static_cast<BroadcastChannelParent
*>(aActor
);
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();
885 RefPtr
<dom::ServiceWorkerManagerParent
> parent
=
886 dont_AddRef(static_cast<dom::ServiceWorkerManagerParent
*>(aActor
));
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();
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);
936 bool BackgroundParentImpl::DeallocPMessagePortParent(
937 PMessagePortParent
* aActor
) {
938 AssertIsInMainProcess();
939 AssertIsOnBackgroundThread();
942 delete static_cast<MessagePortParent
*>(aActor
);
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.");
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();
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);
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);
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
);
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);
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");
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);
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
))) {
1085 return result
.forget();
1088 mozilla::ipc::IPCResult
BackgroundParentImpl::RecvPFileSystemRequestConstructor(
1089 PFileSystemRequestParent
* aActor
, const FileSystemParams
& params
) {
1090 static_cast<FileSystemRequestParent
*>(aActor
)->Start();
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
) {
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
) {
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);
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
);
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
);
1185 mozilla::ipc::IPCResult
BackgroundParentImpl::RecvHasMIDIDevice(
1186 HasMIDIDeviceResolver
&& aResolver
) {
1187 AssertIsInMainProcess();
1188 AssertIsOnBackgroundThread();
1190 InvokeAsync(MIDIPlatformService::OwnerThread(), __func__
,
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());
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
);
1220 IPCResult
BackgroundParentImpl::RecvStorageActivity(
1221 const PrincipalInfo
& aPrincipalInfo
) {
1222 dom::StorageActivityService::SendActivity(aPrincipalInfo
);
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
);
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
);
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
);
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
);
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
,
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
>&&>;
1298 Type(NS_ERROR_NOT_AVAILABLE
, Endpoint
<PRemoteDecoderManagerChild
>()));
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
>()));
1310 resolver(Type(NS_OK
, std::move(aValue
.ResolveValue())));
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();
1331 std::tuple
<const nsresult
&,
1332 Endpoint
<mozilla::PRemoteDecoderManagerChild
>&&>;
1334 managerThread
->Dispatch(NS_NewRunnableFunction(
1335 "BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge::"
1338 aResolver(Type(NS_ERROR_NOT_AVAILABLE
,
1339 Endpoint
<PRemoteDecoderManagerChild
>()));
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
>()));
1354 resolver(Type(NS_OK
, std::move(aValue
.ResolveValue())));
1361 mozilla::ipc::IPCResult
BackgroundParentImpl::RecvRequestCameraAccess(
1362 RequestCameraAccessResolver
&& aResolver
) {
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());
1372 resolver(aValue
.RejectValue());
1376 aResolver(NS_ERROR_NOT_IMPLEMENTED
);
1381 bool BackgroundParentImpl::DeallocPEndpointForReportParent(
1382 PEndpointForReportParent
* aActor
) {
1383 RefPtr
<dom::EndpointForReportParent
> actor
=
1384 dont_AddRef(static_cast<dom::EndpointForReportParent
*>(aActor
));
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
,
1402 already_AddRefed
<dom::locks::PLockManagerParent
>
1403 BackgroundParentImpl::AllocPLockManagerParent(NotNull
<nsIPrincipal
*> aPrincipal
,
1404 const nsID
& aClientId
) {
1405 return MakeAndAddRef
<mozilla::dom::locks::LockManagerParent
>(aPrincipal
,
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();