no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / ipc / glue / BackgroundParentImpl.cpp
blob6fcd344ddbe6ae93ade641ea46456aa209b46732
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::RecordAnnotationCString(
152 CrashReporter::Annotation::ipc_channel_error, aReason);
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, const nsACString& aSystemLocale)
195 -> already_AddRefed<PBackgroundIDBFactoryParent> {
196 using mozilla::dom::indexedDB::AllocPBackgroundIDBFactoryParent;
198 AssertIsInMainProcess();
199 AssertIsOnBackgroundThread();
201 return AllocPBackgroundIDBFactoryParent(aLoggingInfo, aSystemLocale);
204 mozilla::ipc::IPCResult
205 BackgroundParentImpl::RecvPBackgroundIDBFactoryConstructor(
206 PBackgroundIDBFactoryParent* aActor, const LoggingInfo& aLoggingInfo,
207 const nsACString& aSystemLocale) {
208 using mozilla::dom::indexedDB::RecvPBackgroundIDBFactoryConstructor;
210 AssertIsInMainProcess();
211 AssertIsOnBackgroundThread();
212 MOZ_ASSERT(aActor);
214 if (!RecvPBackgroundIDBFactoryConstructor(aActor, aLoggingInfo,
215 aSystemLocale)) {
216 return IPC_FAIL_NO_REASON(this);
218 return IPC_OK();
221 auto BackgroundParentImpl::AllocPBackgroundIndexedDBUtilsParent()
222 -> PBackgroundIndexedDBUtilsParent* {
223 AssertIsInMainProcess();
224 AssertIsOnBackgroundThread();
226 return mozilla::dom::indexedDB::AllocPBackgroundIndexedDBUtilsParent();
229 bool BackgroundParentImpl::DeallocPBackgroundIndexedDBUtilsParent(
230 PBackgroundIndexedDBUtilsParent* aActor) {
231 AssertIsInMainProcess();
232 AssertIsOnBackgroundThread();
233 MOZ_ASSERT(aActor);
235 return mozilla::dom::indexedDB::DeallocPBackgroundIndexedDBUtilsParent(
236 aActor);
239 mozilla::ipc::IPCResult BackgroundParentImpl::RecvFlushPendingFileDeletions() {
240 AssertIsInMainProcess();
241 AssertIsOnBackgroundThread();
243 if (!mozilla::dom::indexedDB::RecvFlushPendingFileDeletions()) {
244 return IPC_FAIL_NO_REASON(this);
246 return IPC_OK();
249 already_AddRefed<BackgroundParentImpl::PBackgroundSDBConnectionParent>
250 BackgroundParentImpl::AllocPBackgroundSDBConnectionParent(
251 const PersistenceType& aPersistenceType,
252 const PrincipalInfo& aPrincipalInfo) {
253 AssertIsInMainProcess();
254 AssertIsOnBackgroundThread();
256 return mozilla::dom::AllocPBackgroundSDBConnectionParent(aPersistenceType,
257 aPrincipalInfo);
260 mozilla::ipc::IPCResult
261 BackgroundParentImpl::RecvPBackgroundSDBConnectionConstructor(
262 PBackgroundSDBConnectionParent* aActor,
263 const PersistenceType& aPersistenceType,
264 const PrincipalInfo& aPrincipalInfo) {
265 AssertIsInMainProcess();
266 AssertIsOnBackgroundThread();
267 MOZ_ASSERT(aActor);
269 if (!mozilla::dom::RecvPBackgroundSDBConnectionConstructor(
270 aActor, aPersistenceType, aPrincipalInfo)) {
271 return IPC_FAIL_NO_REASON(this);
273 return IPC_OK();
276 already_AddRefed<BackgroundParentImpl::PBackgroundLSDatabaseParent>
277 BackgroundParentImpl::AllocPBackgroundLSDatabaseParent(
278 const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
279 const uint64_t& aDatastoreId) {
280 AssertIsInMainProcess();
281 AssertIsOnBackgroundThread();
283 return mozilla::dom::AllocPBackgroundLSDatabaseParent(
284 aPrincipalInfo, aPrivateBrowsingId, aDatastoreId);
287 mozilla::ipc::IPCResult
288 BackgroundParentImpl::RecvPBackgroundLSDatabaseConstructor(
289 PBackgroundLSDatabaseParent* aActor, const PrincipalInfo& aPrincipalInfo,
290 const uint32_t& aPrivateBrowsingId, const uint64_t& aDatastoreId) {
291 AssertIsInMainProcess();
292 AssertIsOnBackgroundThread();
293 MOZ_ASSERT(aActor);
295 if (!mozilla::dom::RecvPBackgroundLSDatabaseConstructor(
296 aActor, aPrincipalInfo, aPrivateBrowsingId, aDatastoreId)) {
297 return IPC_FAIL_NO_REASON(this);
299 return IPC_OK();
302 BackgroundParentImpl::PBackgroundLSObserverParent*
303 BackgroundParentImpl::AllocPBackgroundLSObserverParent(
304 const uint64_t& aObserverId) {
305 AssertIsInMainProcess();
306 AssertIsOnBackgroundThread();
308 return mozilla::dom::AllocPBackgroundLSObserverParent(aObserverId);
311 mozilla::ipc::IPCResult
312 BackgroundParentImpl::RecvPBackgroundLSObserverConstructor(
313 PBackgroundLSObserverParent* aActor, const uint64_t& aObserverId) {
314 AssertIsInMainProcess();
315 AssertIsOnBackgroundThread();
316 MOZ_ASSERT(aActor);
318 if (!mozilla::dom::RecvPBackgroundLSObserverConstructor(aActor,
319 aObserverId)) {
320 return IPC_FAIL_NO_REASON(this);
322 return IPC_OK();
325 bool BackgroundParentImpl::DeallocPBackgroundLSObserverParent(
326 PBackgroundLSObserverParent* aActor) {
327 AssertIsInMainProcess();
328 AssertIsOnBackgroundThread();
329 MOZ_ASSERT(aActor);
331 return mozilla::dom::DeallocPBackgroundLSObserverParent(aActor);
334 BackgroundParentImpl::PBackgroundLSRequestParent*
335 BackgroundParentImpl::AllocPBackgroundLSRequestParent(
336 const LSRequestParams& aParams) {
337 AssertIsInMainProcess();
338 AssertIsOnBackgroundThread();
340 return mozilla::dom::AllocPBackgroundLSRequestParent(this, aParams);
343 mozilla::ipc::IPCResult
344 BackgroundParentImpl::RecvPBackgroundLSRequestConstructor(
345 PBackgroundLSRequestParent* aActor, const LSRequestParams& aParams) {
346 AssertIsInMainProcess();
347 AssertIsOnBackgroundThread();
348 MOZ_ASSERT(aActor);
350 if (!mozilla::dom::RecvPBackgroundLSRequestConstructor(aActor, aParams)) {
351 return IPC_FAIL_NO_REASON(this);
353 return IPC_OK();
356 bool BackgroundParentImpl::DeallocPBackgroundLSRequestParent(
357 PBackgroundLSRequestParent* aActor) {
358 AssertIsInMainProcess();
359 AssertIsOnBackgroundThread();
360 MOZ_ASSERT(aActor);
362 return mozilla::dom::DeallocPBackgroundLSRequestParent(aActor);
365 BackgroundParentImpl::PBackgroundLSSimpleRequestParent*
366 BackgroundParentImpl::AllocPBackgroundLSSimpleRequestParent(
367 const LSSimpleRequestParams& aParams) {
368 AssertIsInMainProcess();
369 AssertIsOnBackgroundThread();
371 return mozilla::dom::AllocPBackgroundLSSimpleRequestParent(this, aParams);
374 mozilla::ipc::IPCResult
375 BackgroundParentImpl::RecvPBackgroundLSSimpleRequestConstructor(
376 PBackgroundLSSimpleRequestParent* aActor,
377 const LSSimpleRequestParams& aParams) {
378 AssertIsInMainProcess();
379 AssertIsOnBackgroundThread();
380 MOZ_ASSERT(aActor);
382 if (!mozilla::dom::RecvPBackgroundLSSimpleRequestConstructor(aActor,
383 aParams)) {
384 return IPC_FAIL_NO_REASON(this);
386 return IPC_OK();
389 bool BackgroundParentImpl::DeallocPBackgroundLSSimpleRequestParent(
390 PBackgroundLSSimpleRequestParent* aActor) {
391 AssertIsInMainProcess();
392 AssertIsOnBackgroundThread();
393 MOZ_ASSERT(aActor);
395 return mozilla::dom::DeallocPBackgroundLSSimpleRequestParent(aActor);
398 BackgroundParentImpl::PBackgroundLocalStorageCacheParent*
399 BackgroundParentImpl::AllocPBackgroundLocalStorageCacheParent(
400 const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
401 const uint32_t& aPrivateBrowsingId) {
402 AssertIsInMainProcess();
403 AssertIsOnBackgroundThread();
405 return mozilla::dom::AllocPBackgroundLocalStorageCacheParent(
406 aPrincipalInfo, aOriginKey, aPrivateBrowsingId);
409 mozilla::ipc::IPCResult
410 BackgroundParentImpl::RecvPBackgroundLocalStorageCacheConstructor(
411 PBackgroundLocalStorageCacheParent* aActor,
412 const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
413 const uint32_t& aPrivateBrowsingId) {
414 AssertIsInMainProcess();
415 AssertIsOnBackgroundThread();
416 MOZ_ASSERT(aActor);
418 return mozilla::dom::RecvPBackgroundLocalStorageCacheConstructor(
419 this, aActor, aPrincipalInfo, aOriginKey, aPrivateBrowsingId);
422 bool BackgroundParentImpl::DeallocPBackgroundLocalStorageCacheParent(
423 PBackgroundLocalStorageCacheParent* aActor) {
424 AssertIsInMainProcess();
425 AssertIsOnBackgroundThread();
426 MOZ_ASSERT(aActor);
428 return mozilla::dom::DeallocPBackgroundLocalStorageCacheParent(aActor);
431 auto BackgroundParentImpl::AllocPBackgroundStorageParent(
432 const nsAString& aProfilePath, const uint32_t& aPrivateBrowsingId)
433 -> PBackgroundStorageParent* {
434 AssertIsInMainProcess();
435 AssertIsOnBackgroundThread();
437 return mozilla::dom::AllocPBackgroundStorageParent(aProfilePath,
438 aPrivateBrowsingId);
441 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundStorageConstructor(
442 PBackgroundStorageParent* aActor, const nsAString& aProfilePath,
443 const uint32_t& aPrivateBrowsingId) {
444 AssertIsInMainProcess();
445 AssertIsOnBackgroundThread();
446 MOZ_ASSERT(aActor);
448 return mozilla::dom::RecvPBackgroundStorageConstructor(aActor, aProfilePath,
449 aPrivateBrowsingId);
452 bool BackgroundParentImpl::DeallocPBackgroundStorageParent(
453 PBackgroundStorageParent* aActor) {
454 AssertIsInMainProcess();
455 AssertIsOnBackgroundThread();
456 MOZ_ASSERT(aActor);
458 return mozilla::dom::DeallocPBackgroundStorageParent(aActor);
461 already_AddRefed<BackgroundParentImpl::PBackgroundSessionStorageManagerParent>
462 BackgroundParentImpl::AllocPBackgroundSessionStorageManagerParent(
463 const uint64_t& aTopContextId) {
464 AssertIsInMainProcess();
465 AssertIsOnBackgroundThread();
467 return dom::AllocPBackgroundSessionStorageManagerParent(aTopContextId);
470 already_AddRefed<mozilla::dom::PBackgroundSessionStorageServiceParent>
471 BackgroundParentImpl::AllocPBackgroundSessionStorageServiceParent() {
472 AssertIsInMainProcess();
473 AssertIsOnBackgroundThread();
475 return MakeAndAddRef<mozilla::dom::BackgroundSessionStorageServiceParent>();
478 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateFileSystemManagerParent(
479 const PrincipalInfo& aPrincipalInfo,
480 Endpoint<PFileSystemManagerParent>&& aParentEndpoint,
481 CreateFileSystemManagerParentResolver&& aResolver) {
482 AssertIsInMainProcess();
483 AssertIsOnBackgroundThread();
485 return mozilla::dom::CreateFileSystemManagerParent(
486 aPrincipalInfo, std::move(aParentEndpoint), std::move(aResolver));
489 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateWebTransportParent(
490 const nsAString& aURL, nsIPrincipal* aPrincipal,
491 const mozilla::Maybe<IPCClientInfo>& aClientInfo, const bool& aDedicated,
492 const bool& aRequireUnreliable, const uint32_t& aCongestionControl,
493 nsTArray<WebTransportHash>&& aServerCertHashes,
494 Endpoint<PWebTransportParent>&& aParentEndpoint,
495 CreateWebTransportParentResolver&& aResolver) {
496 AssertIsInMainProcess();
497 AssertIsOnBackgroundThread();
499 RefPtr<mozilla::dom::WebTransportParent> webt =
500 new mozilla::dom::WebTransportParent();
501 webt->Create(aURL, aPrincipal, aClientInfo, aDedicated, aRequireUnreliable,
502 aCongestionControl, std::move(aServerCertHashes),
503 std::move(aParentEndpoint), std::move(aResolver));
504 return IPC_OK();
507 already_AddRefed<PIdleSchedulerParent>
508 BackgroundParentImpl::AllocPIdleSchedulerParent() {
509 AssertIsOnBackgroundThread();
510 RefPtr<IdleSchedulerParent> actor = new IdleSchedulerParent();
511 return actor.forget();
514 already_AddRefed<dom::PRemoteWorkerControllerParent>
515 BackgroundParentImpl::AllocPRemoteWorkerControllerParent(
516 const dom::RemoteWorkerData& aRemoteWorkerData) {
517 RefPtr<dom::RemoteWorkerControllerParent> actor =
518 new dom::RemoteWorkerControllerParent(aRemoteWorkerData);
519 return actor.forget();
522 IPCResult BackgroundParentImpl::RecvPRemoteWorkerControllerConstructor(
523 dom::PRemoteWorkerControllerParent* aActor,
524 const dom::RemoteWorkerData& aRemoteWorkerData) {
525 MOZ_ASSERT(aActor);
527 return IPC_OK();
530 already_AddRefed<dom::PRemoteWorkerServiceParent>
531 BackgroundParentImpl::AllocPRemoteWorkerServiceParent() {
532 return MakeAndAddRef<dom::RemoteWorkerServiceParent>();
535 IPCResult BackgroundParentImpl::RecvPRemoteWorkerServiceConstructor(
536 PRemoteWorkerServiceParent* aActor) {
537 mozilla::dom::RemoteWorkerServiceParent* actor =
538 static_cast<mozilla::dom::RemoteWorkerServiceParent*>(aActor);
540 RefPtr<ThreadsafeContentParentHandle> parent =
541 BackgroundParent::GetContentParentHandle(this);
542 // If the ContentParent is null we are dealing with a same-process actor.
543 if (!parent) {
544 actor->Initialize(NOT_REMOTE_TYPE);
545 } else {
546 actor->Initialize(parent->GetRemoteType());
548 return IPC_OK();
551 mozilla::dom::PSharedWorkerParent*
552 BackgroundParentImpl::AllocPSharedWorkerParent(
553 const mozilla::dom::RemoteWorkerData& aData, const uint64_t& aWindowID,
554 const mozilla::dom::MessagePortIdentifier& aPortIdentifier) {
555 RefPtr<dom::SharedWorkerParent> agent =
556 new mozilla::dom::SharedWorkerParent();
557 return agent.forget().take();
560 IPCResult BackgroundParentImpl::RecvPSharedWorkerConstructor(
561 PSharedWorkerParent* aActor, const mozilla::dom::RemoteWorkerData& aData,
562 const uint64_t& aWindowID,
563 const mozilla::dom::MessagePortIdentifier& aPortIdentifier) {
564 mozilla::dom::SharedWorkerParent* actor =
565 static_cast<mozilla::dom::SharedWorkerParent*>(aActor);
566 actor->Initialize(aData, aWindowID, aPortIdentifier);
567 return IPC_OK();
570 bool BackgroundParentImpl::DeallocPSharedWorkerParent(
571 mozilla::dom::PSharedWorkerParent* aActor) {
572 RefPtr<mozilla::dom::SharedWorkerParent> actor =
573 dont_AddRef(static_cast<mozilla::dom::SharedWorkerParent*>(aActor));
574 return true;
577 dom::PFileCreatorParent* BackgroundParentImpl::AllocPFileCreatorParent(
578 const nsAString& aFullPath, const nsAString& aType, const nsAString& aName,
579 const Maybe<int64_t>& aLastModified, const bool& aExistenceCheck,
580 const bool& aIsFromNsIFile) {
581 RefPtr<dom::FileCreatorParent> actor = new dom::FileCreatorParent();
582 return actor.forget().take();
585 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPFileCreatorConstructor(
586 dom::PFileCreatorParent* aActor, const nsAString& aFullPath,
587 const nsAString& aType, const nsAString& aName,
588 const Maybe<int64_t>& aLastModified, const bool& aExistenceCheck,
589 const bool& aIsFromNsIFile) {
590 bool isFileRemoteType = false;
592 // If the ContentParentHandle is null we are dealing with a same-process
593 // actor.
594 RefPtr<ThreadsafeContentParentHandle> parent =
595 BackgroundParent::GetContentParentHandle(this);
596 if (!parent) {
597 isFileRemoteType = true;
598 } else {
599 isFileRemoteType = parent->GetRemoteType() == FILE_REMOTE_TYPE;
602 dom::FileCreatorParent* actor = static_cast<dom::FileCreatorParent*>(aActor);
604 // We allow the creation of File via this IPC call only for the 'file' process
605 // or for testing.
606 if (!isFileRemoteType && !StaticPrefs::dom_file_createInChild()) {
607 Unused << dom::FileCreatorParent::Send__delete__(
608 actor, dom::FileCreationErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
609 return IPC_OK();
612 return actor->CreateAndShareFile(aFullPath, aType, aName, aLastModified,
613 aExistenceCheck, aIsFromNsIFile);
616 bool BackgroundParentImpl::DeallocPFileCreatorParent(
617 dom::PFileCreatorParent* aActor) {
618 RefPtr<dom::FileCreatorParent> actor =
619 dont_AddRef(static_cast<dom::FileCreatorParent*>(aActor));
620 return true;
623 dom::PTemporaryIPCBlobParent*
624 BackgroundParentImpl::AllocPTemporaryIPCBlobParent() {
625 return new dom::TemporaryIPCBlobParent();
628 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPTemporaryIPCBlobConstructor(
629 dom::PTemporaryIPCBlobParent* aActor) {
630 dom::TemporaryIPCBlobParent* actor =
631 static_cast<dom::TemporaryIPCBlobParent*>(aActor);
632 return actor->CreateAndShareFile();
635 bool BackgroundParentImpl::DeallocPTemporaryIPCBlobParent(
636 dom::PTemporaryIPCBlobParent* aActor) {
637 delete aActor;
638 return true;
641 already_AddRefed<BackgroundParentImpl::PVsyncParent>
642 BackgroundParentImpl::AllocPVsyncParent() {
643 AssertIsInMainProcess();
644 AssertIsOnBackgroundThread();
646 RefPtr<mozilla::dom::VsyncParent> actor = new mozilla::dom::VsyncParent();
648 RefPtr<mozilla::VsyncDispatcher> vsyncDispatcher =
649 gfxPlatform::GetPlatform()->GetGlobalVsyncDispatcher();
650 actor->UpdateVsyncDispatcher(vsyncDispatcher);
651 return actor.forget();
654 camera::PCamerasParent* BackgroundParentImpl::AllocPCamerasParent() {
655 AssertIsInMainProcess();
656 AssertIsOnBackgroundThread();
658 #ifdef MOZ_WEBRTC
659 RefPtr<mozilla::camera::CamerasParent> actor =
660 mozilla::camera::CamerasParent::Create();
661 return actor.forget().take();
662 #else
663 return nullptr;
664 #endif
667 #ifdef MOZ_WEBRTC
668 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPCamerasConstructor(
669 camera::PCamerasParent* aActor) {
670 AssertIsInMainProcess();
671 AssertIsOnBackgroundThread();
672 MOZ_ASSERT(aActor);
673 return static_cast<camera::CamerasParent*>(aActor)->RecvPCamerasConstructor();
675 #endif
677 bool BackgroundParentImpl::DeallocPCamerasParent(
678 camera::PCamerasParent* aActor) {
679 AssertIsInMainProcess();
680 AssertIsOnBackgroundThread();
681 MOZ_ASSERT(aActor);
683 #ifdef MOZ_WEBRTC
684 RefPtr<mozilla::camera::CamerasParent> actor =
685 dont_AddRef(static_cast<mozilla::camera::CamerasParent*>(aActor));
686 #endif
687 return true;
690 auto BackgroundParentImpl::AllocPUDPSocketParent(
691 const Maybe<PrincipalInfo>& /* unused */, const nsACString& /* unused */)
692 -> PUDPSocketParent* {
693 RefPtr<UDPSocketParent> p = new UDPSocketParent(this);
695 return p.forget().take();
698 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPUDPSocketConstructor(
699 PUDPSocketParent* aActor, const Maybe<PrincipalInfo>& aOptionalPrincipal,
700 const nsACString& aFilter) {
701 AssertIsInMainProcess();
702 AssertIsOnBackgroundThread();
704 if (aOptionalPrincipal.isSome()) {
705 // Support for checking principals (for non-mtransport use) will be handled
706 // in bug 1167039
707 return IPC_FAIL_NO_REASON(this);
709 // No principal - This must be from mtransport (WebRTC/ICE) - We'd want
710 // to DispatchToMainThread() here, but if we do we must block RecvBind()
711 // until Init() gets run. Since we don't have a principal, and we verify
712 // we have a filter, we can safely skip the Dispatch and just invoke Init()
713 // to install the filter.
715 // For mtransport, this will always be "stun", which doesn't allow outbound
716 // packets if they aren't STUN packets until a STUN response is seen.
717 if (!aFilter.EqualsASCII(NS_NETWORK_SOCKET_FILTER_HANDLER_STUN_SUFFIX)) {
718 return IPC_FAIL_NO_REASON(this);
721 if (!static_cast<UDPSocketParent*>(aActor)->Init(nullptr, aFilter)) {
722 MOZ_CRASH("UDPSocketCallback - failed init");
725 return IPC_OK();
728 bool BackgroundParentImpl::DeallocPUDPSocketParent(PUDPSocketParent* actor) {
729 UDPSocketParent* p = static_cast<UDPSocketParent*>(actor);
730 p->Release();
731 return true;
734 mozilla::dom::PBroadcastChannelParent*
735 BackgroundParentImpl::AllocPBroadcastChannelParent(
736 const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin,
737 const nsAString& aChannel) {
738 AssertIsInMainProcess();
739 AssertIsOnBackgroundThread();
741 nsString originChannelKey;
743 // The format of originChannelKey is:
744 // <channelName>|<origin+OriginAttributes>
746 originChannelKey.Assign(aChannel);
748 originChannelKey.AppendLiteral("|");
750 originChannelKey.Append(NS_ConvertUTF8toUTF16(aOrigin));
752 return new BroadcastChannelParent(originChannelKey);
755 namespace {
757 class CheckPrincipalRunnable final : public Runnable {
758 public:
759 CheckPrincipalRunnable(
760 already_AddRefed<ThreadsafeContentParentHandle> aParent,
761 const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin)
762 : Runnable("ipc::CheckPrincipalRunnable"),
763 mContentParent(aParent),
764 mPrincipalInfo(aPrincipalInfo),
765 mOrigin(aOrigin) {
766 AssertIsInMainProcess();
767 AssertIsOnBackgroundThread();
769 MOZ_ASSERT(mContentParent);
772 NS_IMETHOD Run() override {
773 AssertIsOnMainThread();
774 RefPtr<ContentParent> contentParent = mContentParent->GetContentParent();
775 if (!contentParent) {
776 return NS_OK;
779 auto principalOrErr = PrincipalInfoToPrincipal(mPrincipalInfo);
780 if (NS_WARN_IF(principalOrErr.isErr())) {
781 contentParent->KillHard(
782 "BroadcastChannel killed: PrincipalInfoToPrincipal failed.");
783 return NS_OK;
786 nsAutoCString origin;
787 nsresult rv = principalOrErr.unwrap()->GetOrigin(origin);
788 if (NS_FAILED(rv)) {
789 contentParent->KillHard(
790 "BroadcastChannel killed: principal::GetOrigin failed.");
791 return NS_OK;
794 if (NS_WARN_IF(!mOrigin.Equals(origin))) {
795 contentParent->KillHard("BroadcastChannel killed: origins do not match.");
796 return NS_OK;
799 return NS_OK;
802 private:
803 RefPtr<ThreadsafeContentParentHandle> mContentParent;
804 PrincipalInfo mPrincipalInfo;
805 nsCString mOrigin;
808 } // namespace
810 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBroadcastChannelConstructor(
811 PBroadcastChannelParent* actor, const PrincipalInfo& aPrincipalInfo,
812 const nsACString& aOrigin, const nsAString& aChannel) {
813 AssertIsInMainProcess();
814 AssertIsOnBackgroundThread();
816 RefPtr<ThreadsafeContentParentHandle> parent =
817 BackgroundParent::GetContentParentHandle(this);
819 // If the ContentParent is null we are dealing with a same-process actor.
820 if (!parent) {
821 return IPC_OK();
824 // XXX The principal can be checked right here on the PBackground thread
825 // since BackgroundParentImpl now overrides the ProcessingError method and
826 // kills invalid child processes (IPC_FAIL triggers a processing error).
828 RefPtr<CheckPrincipalRunnable> runnable =
829 new CheckPrincipalRunnable(parent.forget(), aPrincipalInfo, aOrigin);
830 MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
832 return IPC_OK();
835 bool BackgroundParentImpl::DeallocPBroadcastChannelParent(
836 PBroadcastChannelParent* aActor) {
837 AssertIsInMainProcess();
838 AssertIsOnBackgroundThread();
839 MOZ_ASSERT(aActor);
841 delete static_cast<BroadcastChannelParent*>(aActor);
842 return true;
845 mozilla::dom::PServiceWorkerManagerParent*
846 BackgroundParentImpl::AllocPServiceWorkerManagerParent() {
847 AssertIsInMainProcess();
848 AssertIsOnBackgroundThread();
850 RefPtr<dom::ServiceWorkerManagerParent> agent =
851 new dom::ServiceWorkerManagerParent();
852 return agent.forget().take();
855 bool BackgroundParentImpl::DeallocPServiceWorkerManagerParent(
856 PServiceWorkerManagerParent* aActor) {
857 AssertIsInMainProcess();
858 AssertIsOnBackgroundThread();
859 MOZ_ASSERT(aActor);
861 RefPtr<dom::ServiceWorkerManagerParent> parent =
862 dont_AddRef(static_cast<dom::ServiceWorkerManagerParent*>(aActor));
863 MOZ_ASSERT(parent);
864 return true;
867 mozilla::ipc::IPCResult
868 BackgroundParentImpl::RecvShutdownServiceWorkerRegistrar() {
869 AssertIsInMainProcess();
870 AssertIsOnBackgroundThread();
872 if (BackgroundParent::IsOtherProcessActor(this)) {
873 return IPC_FAIL_NO_REASON(this);
876 RefPtr<dom::ServiceWorkerRegistrar> service =
877 dom::ServiceWorkerRegistrar::Get();
878 MOZ_ASSERT(service);
880 service->Shutdown();
881 return IPC_OK();
884 already_AddRefed<PCacheStorageParent>
885 BackgroundParentImpl::AllocPCacheStorageParent(
886 const Namespace& aNamespace, const PrincipalInfo& aPrincipalInfo) {
887 return dom::cache::AllocPCacheStorageParent(this, aNamespace, aPrincipalInfo);
890 PMessagePortParent* BackgroundParentImpl::AllocPMessagePortParent(
891 const nsID& aUUID, const nsID& aDestinationUUID,
892 const uint32_t& aSequenceID) {
893 AssertIsInMainProcess();
894 AssertIsOnBackgroundThread();
896 return new MessagePortParent(aUUID);
899 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPMessagePortConstructor(
900 PMessagePortParent* aActor, const nsID& aUUID, const nsID& aDestinationUUID,
901 const uint32_t& aSequenceID) {
902 AssertIsInMainProcess();
903 AssertIsOnBackgroundThread();
905 MessagePortParent* mp = static_cast<MessagePortParent*>(aActor);
906 if (!mp->Entangle(aDestinationUUID, aSequenceID)) {
907 return IPC_FAIL_NO_REASON(this);
909 return IPC_OK();
912 bool BackgroundParentImpl::DeallocPMessagePortParent(
913 PMessagePortParent* aActor) {
914 AssertIsInMainProcess();
915 AssertIsOnBackgroundThread();
916 MOZ_ASSERT(aActor);
918 delete static_cast<MessagePortParent*>(aActor);
919 return true;
922 mozilla::ipc::IPCResult BackgroundParentImpl::RecvMessagePortForceClose(
923 const nsID& aUUID, const nsID& aDestinationUUID,
924 const uint32_t& aSequenceID) {
925 AssertIsInMainProcess();
926 AssertIsOnBackgroundThread();
928 if (!MessagePortParent::ForceClose(aUUID, aDestinationUUID, aSequenceID)) {
929 return IPC_FAIL(this, "MessagePortParent::ForceClose failed.");
932 return IPC_OK();
935 already_AddRefed<BackgroundParentImpl::PQuotaParent>
936 BackgroundParentImpl::AllocPQuotaParent() {
937 AssertIsInMainProcess();
938 AssertIsOnBackgroundThread();
940 return mozilla::dom::quota::AllocPQuotaParent();
943 mozilla::ipc::IPCResult BackgroundParentImpl::RecvShutdownQuotaManager() {
944 AssertIsInMainProcess();
945 AssertIsOnBackgroundThread();
947 if (BackgroundParent::IsOtherProcessActor(this)) {
948 return IPC_FAIL_NO_REASON(this);
951 if (!mozilla::dom::quota::RecvShutdownQuotaManager()) {
952 return IPC_FAIL_NO_REASON(this);
954 return IPC_OK();
957 mozilla::ipc::IPCResult
958 BackgroundParentImpl::RecvShutdownBackgroundSessionStorageManagers() {
959 AssertIsInMainProcess();
960 AssertIsOnBackgroundThread();
962 if (BackgroundParent::IsOtherProcessActor(this)) {
963 return IPC_FAIL_NO_REASON(this);
966 if (!mozilla::dom::RecvShutdownBackgroundSessionStorageManagers()) {
967 return IPC_FAIL_NO_REASON(this);
969 return IPC_OK();
972 mozilla::ipc::IPCResult
973 BackgroundParentImpl::RecvPropagateBackgroundSessionStorageManager(
974 const uint64_t& aCurrentTopContextId, const uint64_t& aTargetTopContextId) {
975 AssertIsInMainProcess();
976 AssertIsOnBackgroundThread();
978 if (BackgroundParent::IsOtherProcessActor(this)) {
979 return IPC_FAIL(this, "Wrong actor");
982 mozilla::dom::RecvPropagateBackgroundSessionStorageManager(
983 aCurrentTopContextId, aTargetTopContextId);
985 return IPC_OK();
988 mozilla::ipc::IPCResult
989 BackgroundParentImpl::RecvRemoveBackgroundSessionStorageManager(
990 const uint64_t& aTopContextId) {
991 AssertIsInMainProcess();
992 AssertIsOnBackgroundThread();
994 if (BackgroundParent::IsOtherProcessActor(this)) {
995 return IPC_FAIL_NO_REASON(this);
998 if (!mozilla::dom::RecvRemoveBackgroundSessionStorageManager(aTopContextId)) {
999 return IPC_FAIL_NO_REASON(this);
1001 return IPC_OK();
1004 mozilla::ipc::IPCResult BackgroundParentImpl::RecvGetSessionStorageManagerData(
1005 const uint64_t& aTopContextId, const uint32_t& aSizeLimit,
1006 const bool& aCancelSessionStoreTimer,
1007 GetSessionStorageManagerDataResolver&& aResolver) {
1008 AssertIsInMainProcess();
1009 AssertIsOnBackgroundThread();
1011 if (BackgroundParent::IsOtherProcessActor(this)) {
1012 return IPC_FAIL(this, "Wrong actor");
1015 if (!mozilla::dom::RecvGetSessionStorageData(aTopContextId, aSizeLimit,
1016 aCancelSessionStoreTimer,
1017 std::move(aResolver))) {
1018 return IPC_FAIL(this, "Couldn't get session storage data");
1021 return IPC_OK();
1024 mozilla::ipc::IPCResult BackgroundParentImpl::RecvLoadSessionStorageManagerData(
1025 const uint64_t& aTopContextId,
1026 nsTArray<mozilla::dom::SSCacheCopy>&& aOriginCacheCopy) {
1027 AssertIsInMainProcess();
1028 AssertIsOnBackgroundThread();
1030 if (BackgroundParent::IsOtherProcessActor(this)) {
1031 return IPC_FAIL(this, "Wrong actor");
1034 if (!mozilla::dom::RecvLoadSessionStorageData(aTopContextId,
1035 std::move(aOriginCacheCopy))) {
1036 return IPC_FAIL_NO_REASON(this);
1039 return IPC_OK();
1042 already_AddRefed<dom::PFileSystemRequestParent>
1043 BackgroundParentImpl::AllocPFileSystemRequestParent(
1044 const FileSystemParams& aParams) {
1045 AssertIsInMainProcess();
1046 AssertIsOnBackgroundThread();
1048 RefPtr<FileSystemRequestParent> result = new FileSystemRequestParent();
1050 if (NS_WARN_IF(!result->Initialize(aParams))) {
1051 return nullptr;
1054 return result.forget();
1057 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPFileSystemRequestConstructor(
1058 PFileSystemRequestParent* aActor, const FileSystemParams& params) {
1059 static_cast<FileSystemRequestParent*>(aActor)->Start();
1060 return IPC_OK();
1063 // Gamepad API Background IPC
1064 already_AddRefed<dom::PGamepadEventChannelParent>
1065 BackgroundParentImpl::AllocPGamepadEventChannelParent() {
1066 return dom::GamepadEventChannelParent::Create();
1069 already_AddRefed<dom::PGamepadTestChannelParent>
1070 BackgroundParentImpl::AllocPGamepadTestChannelParent() {
1071 return dom::GamepadTestChannelParent::Create();
1074 dom::PWebAuthnTransactionParent*
1075 BackgroundParentImpl::AllocPWebAuthnTransactionParent() {
1076 return new dom::WebAuthnTransactionParent();
1079 bool BackgroundParentImpl::DeallocPWebAuthnTransactionParent(
1080 dom::PWebAuthnTransactionParent* aActor) {
1081 MOZ_ASSERT(aActor);
1082 delete aActor;
1083 return true;
1086 already_AddRefed<net::PHttpBackgroundChannelParent>
1087 BackgroundParentImpl::AllocPHttpBackgroundChannelParent(
1088 const uint64_t& aChannelId) {
1089 AssertIsInMainProcess();
1090 AssertIsOnBackgroundThread();
1092 RefPtr<net::HttpBackgroundChannelParent> actor =
1093 new net::HttpBackgroundChannelParent();
1094 return actor.forget();
1097 mozilla::ipc::IPCResult
1098 BackgroundParentImpl::RecvPHttpBackgroundChannelConstructor(
1099 net::PHttpBackgroundChannelParent* aActor, const uint64_t& aChannelId) {
1100 MOZ_ASSERT(aActor);
1101 AssertIsInMainProcess();
1102 AssertIsOnBackgroundThread();
1104 net::HttpBackgroundChannelParent* aParent =
1105 static_cast<net::HttpBackgroundChannelParent*>(aActor);
1107 if (NS_WARN_IF(NS_FAILED(aParent->Init(aChannelId)))) {
1108 return IPC_FAIL_NO_REASON(this);
1111 return IPC_OK();
1114 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIPort(
1115 Endpoint<PMIDIPortParent>&& aEndpoint, const MIDIPortInfo& aPortInfo,
1116 const bool& aSysexEnabled) {
1117 AssertIsInMainProcess();
1118 AssertIsOnBackgroundThread();
1120 if (!aEndpoint.IsValid()) {
1121 return IPC_FAIL(this, "invalid endpoint for MIDIPort");
1124 MIDIPlatformService::OwnerThread()->Dispatch(NS_NewRunnableFunction(
1125 "CreateMIDIPortRunnable", [=, endpoint = std::move(aEndpoint)]() mutable {
1126 RefPtr<MIDIPortParent> result =
1127 new MIDIPortParent(aPortInfo, aSysexEnabled);
1128 endpoint.Bind(result);
1129 }));
1131 return IPC_OK();
1134 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIManager(
1135 Endpoint<PMIDIManagerParent>&& aEndpoint) {
1136 AssertIsInMainProcess();
1137 AssertIsOnBackgroundThread();
1139 if (!aEndpoint.IsValid()) {
1140 return IPC_FAIL(this, "invalid endpoint for MIDIManager");
1143 MIDIPlatformService::OwnerThread()->Dispatch(NS_NewRunnableFunction(
1144 "CreateMIDIManagerRunnable",
1145 [=, endpoint = std::move(aEndpoint)]() mutable {
1146 RefPtr<MIDIManagerParent> result = new MIDIManagerParent();
1147 endpoint.Bind(result);
1148 MIDIPlatformService::Get()->AddManager(result);
1149 }));
1151 return IPC_OK();
1154 mozilla::ipc::IPCResult BackgroundParentImpl::RecvHasMIDIDevice(
1155 HasMIDIDeviceResolver&& aResolver) {
1156 AssertIsInMainProcess();
1157 AssertIsOnBackgroundThread();
1159 InvokeAsync(MIDIPlatformService::OwnerThread(), __func__,
1160 []() {
1161 bool hasDevice = MIDIPlatformService::Get()->HasDevice();
1162 return BoolPromise::CreateAndResolve(hasDevice, __func__);
1164 ->Then(GetCurrentSerialEventTarget(), __func__,
1165 [resolver = std::move(aResolver)](
1166 const BoolPromise::ResolveOrRejectValue& r) {
1167 resolver(r.IsResolve() && r.ResolveValue());
1170 return IPC_OK();
1173 already_AddRefed<mozilla::dom::PClientManagerParent>
1174 BackgroundParentImpl::AllocPClientManagerParent() {
1175 return mozilla::dom::AllocClientManagerParent();
1178 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPClientManagerConstructor(
1179 mozilla::dom::PClientManagerParent* aActor) {
1180 mozilla::dom::InitClientManagerParent(aActor);
1181 return IPC_OK();
1184 IPCResult BackgroundParentImpl::RecvStorageActivity(
1185 const PrincipalInfo& aPrincipalInfo) {
1186 dom::StorageActivityService::SendActivity(aPrincipalInfo);
1187 return IPC_OK();
1190 IPCResult BackgroundParentImpl::RecvPServiceWorkerManagerConstructor(
1191 PServiceWorkerManagerParent* const aActor) {
1192 // Only the parent process is allowed to construct this actor.
1193 if (BackgroundParent::IsOtherProcessActor(this)) {
1194 return IPC_FAIL_NO_REASON(aActor);
1196 return IPC_OK();
1199 already_AddRefed<PServiceWorkerParent>
1200 BackgroundParentImpl::AllocPServiceWorkerParent(
1201 const IPCServiceWorkerDescriptor&) {
1202 return MakeAndAddRef<ServiceWorkerParent>();
1205 IPCResult BackgroundParentImpl::RecvPServiceWorkerConstructor(
1206 PServiceWorkerParent* aActor,
1207 const IPCServiceWorkerDescriptor& aDescriptor) {
1208 dom::InitServiceWorkerParent(aActor, aDescriptor);
1209 return IPC_OK();
1212 already_AddRefed<PServiceWorkerContainerParent>
1213 BackgroundParentImpl::AllocPServiceWorkerContainerParent() {
1214 return MakeAndAddRef<mozilla::dom::ServiceWorkerContainerParent>();
1217 mozilla::ipc::IPCResult
1218 BackgroundParentImpl::RecvPServiceWorkerContainerConstructor(
1219 PServiceWorkerContainerParent* aActor) {
1220 dom::InitServiceWorkerContainerParent(aActor);
1221 return IPC_OK();
1224 already_AddRefed<PServiceWorkerRegistrationParent>
1225 BackgroundParentImpl::AllocPServiceWorkerRegistrationParent(
1226 const IPCServiceWorkerRegistrationDescriptor&) {
1227 return MakeAndAddRef<mozilla::dom::ServiceWorkerRegistrationParent>();
1230 mozilla::ipc::IPCResult
1231 BackgroundParentImpl::RecvPServiceWorkerRegistrationConstructor(
1232 PServiceWorkerRegistrationParent* aActor,
1233 const IPCServiceWorkerRegistrationDescriptor& aDescriptor) {
1234 dom::InitServiceWorkerRegistrationParent(aActor, aDescriptor);
1235 return IPC_OK();
1238 dom::PEndpointForReportParent*
1239 BackgroundParentImpl::AllocPEndpointForReportParent(
1240 const nsAString& aGroupName, const PrincipalInfo& aPrincipalInfo) {
1241 RefPtr<dom::EndpointForReportParent> actor =
1242 new dom::EndpointForReportParent();
1243 return actor.forget().take();
1246 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPEndpointForReportConstructor(
1247 PEndpointForReportParent* aActor, const nsAString& aGroupName,
1248 const PrincipalInfo& aPrincipalInfo) {
1249 static_cast<dom::EndpointForReportParent*>(aActor)->Run(aGroupName,
1250 aPrincipalInfo);
1251 return IPC_OK();
1254 mozilla::ipc::IPCResult
1255 BackgroundParentImpl::RecvEnsureRDDProcessAndCreateBridge(
1256 EnsureRDDProcessAndCreateBridgeResolver&& aResolver) {
1257 using Type = std::tuple<const nsresult&,
1258 Endpoint<mozilla::PRemoteDecoderManagerChild>&&>;
1260 RefPtr<ThreadsafeContentParentHandle> parent =
1261 BackgroundParent::GetContentParentHandle(this);
1262 if (NS_WARN_IF(!parent)) {
1263 aResolver(
1264 Type(NS_ERROR_NOT_AVAILABLE, Endpoint<PRemoteDecoderManagerChild>()));
1265 return IPC_OK();
1268 RDDProcessManager* rdd = RDDProcessManager::Get();
1269 if (!rdd) {
1270 aResolver(
1271 Type(NS_ERROR_NOT_AVAILABLE, Endpoint<PRemoteDecoderManagerChild>()));
1272 return IPC_OK();
1275 rdd->EnsureRDDProcessAndCreateBridge(OtherPid(), parent->ChildID())
1276 ->Then(GetCurrentSerialEventTarget(), __func__,
1277 [resolver = std::move(aResolver)](
1278 mozilla::RDDProcessManager::EnsureRDDPromise::
1279 ResolveOrRejectValue&& aValue) mutable {
1280 if (aValue.IsReject()) {
1281 resolver(Type(aValue.RejectValue(),
1282 Endpoint<PRemoteDecoderManagerChild>()));
1283 return;
1285 resolver(Type(NS_OK, std::move(aValue.ResolveValue())));
1287 return IPC_OK();
1290 mozilla::ipc::IPCResult
1291 BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge(
1292 const RemoteDecodeIn& aLocation,
1293 EnsureUtilityProcessAndCreateBridgeResolver&& aResolver) {
1294 base::ProcessId otherPid = OtherPid();
1295 RefPtr<ThreadsafeContentParentHandle> parent =
1296 BackgroundParent::GetContentParentHandle(this);
1297 if (NS_WARN_IF(!parent)) {
1298 return IPC_FAIL_NO_REASON(this);
1300 dom::ContentParentId childId = parent->ChildID();
1301 nsCOMPtr<nsISerialEventTarget> managerThread = GetCurrentSerialEventTarget();
1302 if (!managerThread) {
1303 return IPC_FAIL_NO_REASON(this);
1305 NS_DispatchToMainThread(NS_NewRunnableFunction(
1306 "BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge()",
1307 [aResolver, managerThread, otherPid, childId, aLocation]() {
1308 RefPtr<UtilityProcessManager> upm =
1309 UtilityProcessManager::GetSingleton();
1310 using Type =
1311 std::tuple<const nsresult&,
1312 Endpoint<mozilla::PRemoteDecoderManagerChild>&&>;
1313 if (!upm) {
1314 managerThread->Dispatch(NS_NewRunnableFunction(
1315 "BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge::"
1316 "Failure",
1317 [aResolver]() {
1318 aResolver(Type(NS_ERROR_NOT_AVAILABLE,
1319 Endpoint<PRemoteDecoderManagerChild>()));
1320 }));
1321 } else {
1322 SandboxingKind sbKind = GetSandboxingKindFromLocation(aLocation);
1323 upm->StartProcessForRemoteMediaDecoding(otherPid, childId, sbKind)
1324 ->Then(managerThread, __func__,
1325 [resolver = aResolver](
1326 mozilla::ipc::UtilityProcessManager::
1327 StartRemoteDecodingUtilityPromise::
1328 ResolveOrRejectValue&& aValue) mutable {
1329 if (aValue.IsReject()) {
1330 resolver(Type(aValue.RejectValue(),
1331 Endpoint<PRemoteDecoderManagerChild>()));
1332 return;
1334 resolver(Type(NS_OK, std::move(aValue.ResolveValue())));
1337 }));
1338 return IPC_OK();
1341 mozilla::ipc::IPCResult BackgroundParentImpl::RecvRequestCameraAccess(
1342 const bool& aAllowPermissionRequest,
1343 RequestCameraAccessResolver&& aResolver) {
1344 #ifdef MOZ_WEBRTC
1345 mozilla::camera::CamerasParent::RequestCameraAccess(aAllowPermissionRequest)
1346 ->Then(GetCurrentSerialEventTarget(), __func__,
1347 [resolver = std::move(aResolver)](
1348 const mozilla::camera::CamerasParent::
1349 CameraAccessRequestPromise::ResolveOrRejectValue& aValue) {
1350 if (aValue.IsResolve()) {
1351 resolver(aValue.ResolveValue());
1352 } else {
1353 resolver(CamerasAccessStatus::Error);
1356 #else
1357 aResolver(CamerasAccessStatus::Error);
1358 #endif
1359 return IPC_OK();
1362 bool BackgroundParentImpl::DeallocPEndpointForReportParent(
1363 PEndpointForReportParent* aActor) {
1364 RefPtr<dom::EndpointForReportParent> actor =
1365 dont_AddRef(static_cast<dom::EndpointForReportParent*>(aActor));
1366 return true;
1369 mozilla::ipc::IPCResult BackgroundParentImpl::RecvRemoveEndpoint(
1370 const nsAString& aGroupName, const nsACString& aEndpointURL,
1371 const PrincipalInfo& aPrincipalInfo) {
1372 NS_DispatchToMainThread(NS_NewRunnableFunction(
1373 "BackgroundParentImpl::RecvRemoveEndpoint(",
1374 [aGroupName = nsString(aGroupName),
1375 aEndpointURL = nsCString(aEndpointURL), aPrincipalInfo]() {
1376 dom::ReportingHeader::RemoveEndpoint(aGroupName, aEndpointURL,
1377 aPrincipalInfo);
1378 }));
1380 return IPC_OK();
1383 already_AddRefed<dom::locks::PLockManagerParent>
1384 BackgroundParentImpl::AllocPLockManagerParent(NotNull<nsIPrincipal*> aPrincipal,
1385 const nsID& aClientId) {
1386 return MakeAndAddRef<mozilla::dom::locks::LockManagerParent>(aPrincipal,
1387 aClientId);
1390 already_AddRefed<dom::PFetchParent> BackgroundParentImpl::AllocPFetchParent() {
1391 return MakeAndAddRef<dom::FetchParent>();
1394 } // namespace mozilla::ipc
1396 void TestParent::ActorDestroy(ActorDestroyReason aWhy) {
1397 mozilla::ipc::AssertIsInMainProcess();
1398 AssertIsOnBackgroundThread();