Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / ipc / glue / BackgroundParentImpl.cpp
blob5cb45b0a2cce1aed6816960b3bfed44ccdfa0f3f
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/MediaTransportParent.h"
33 #include "mozilla/dom/MessagePortParent.h"
34 #include "mozilla/dom/PGamepadEventChannelParent.h"
35 #include "mozilla/dom/PGamepadTestChannelParent.h"
36 #include "mozilla/dom/RemoteWorkerControllerParent.h"
37 #include "mozilla/dom/RemoteWorkerServiceParent.h"
38 #include "mozilla/dom/ReportingHeader.h"
39 #include "mozilla/dom/ServiceWorkerActors.h"
40 #include "mozilla/dom/ServiceWorkerContainerParent.h"
41 #include "mozilla/dom/ServiceWorkerManagerParent.h"
42 #include "mozilla/dom/ServiceWorkerParent.h"
43 #include "mozilla/dom/ServiceWorkerRegistrar.h"
44 #include "mozilla/dom/ServiceWorkerRegistrationParent.h"
45 #include "mozilla/dom/SessionStorageManager.h"
46 #include "mozilla/dom/SharedWorkerParent.h"
47 #include "mozilla/dom/StorageActivityService.h"
48 #include "mozilla/dom/StorageIPC.h"
49 #include "mozilla/dom/TemporaryIPCBlobParent.h"
50 #include "mozilla/dom/WebAuthnTransactionParent.h"
51 #include "mozilla/dom/WebTransportParent.h"
52 #include "mozilla/dom/cache/ActorUtils.h"
53 #include "mozilla/dom/indexedDB/ActorsParent.h"
54 #include "mozilla/dom/locks/LockManagerParent.h"
55 #include "mozilla/dom/localstorage/ActorsParent.h"
56 #include "mozilla/dom/network/UDPSocketParent.h"
57 #include "mozilla/dom/quota/ActorsParent.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 "mozilla/net/HttpConnectionMgrParent.h"
69 #include "mozilla/net/WebSocketConnectionParent.h"
70 #include "mozilla/psm/IPCClientCertsParent.h"
71 #include "mozilla/psm/SelectTLSClientAuthCertParent.h"
72 #include "mozilla/psm/VerifySSLServerCertParent.h"
73 #include "nsIHttpChannelInternal.h"
74 #include "nsIPrincipal.h"
75 #include "nsProxyRelease.h"
76 #include "nsThreadUtils.h"
77 #include "nsXULAppAPI.h"
79 using mozilla::AssertIsOnMainThread;
80 using mozilla::dom::FileSystemRequestParent;
81 using mozilla::dom::MessagePortParent;
82 using mozilla::dom::MIDIManagerParent;
83 using mozilla::dom::MIDIPlatformService;
84 using mozilla::dom::MIDIPortParent;
85 using mozilla::dom::PMessagePortParent;
86 using mozilla::dom::PMIDIManagerParent;
87 using mozilla::dom::PMIDIPortParent;
88 using mozilla::dom::PServiceWorkerContainerParent;
89 using mozilla::dom::PServiceWorkerParent;
90 using mozilla::dom::PServiceWorkerRegistrationParent;
91 using mozilla::dom::ServiceWorkerParent;
92 using mozilla::dom::UDPSocketParent;
93 using mozilla::dom::WebAuthnTransactionParent;
94 using mozilla::dom::cache::PCacheParent;
95 using mozilla::dom::cache::PCacheStorageParent;
96 using mozilla::dom::cache::PCacheStreamControlParent;
97 using mozilla::ipc::AssertIsOnBackgroundThread;
99 namespace {
101 class TestParent final : public mozilla::ipc::PBackgroundTestParent {
102 friend class mozilla::ipc::BackgroundParentImpl;
104 MOZ_COUNTED_DEFAULT_CTOR(TestParent)
106 protected:
107 ~TestParent() override { MOZ_COUNT_DTOR(TestParent); }
109 public:
110 void ActorDestroy(ActorDestroyReason aWhy) override;
113 } // namespace
115 namespace mozilla::ipc {
117 using mozilla::dom::BroadcastChannelParent;
118 using mozilla::dom::ContentParent;
119 using mozilla::dom::ThreadsafeContentParentHandle;
121 BackgroundParentImpl::BackgroundParentImpl() {
122 AssertIsInMainOrSocketProcess();
124 MOZ_COUNT_CTOR(mozilla::ipc::BackgroundParentImpl);
127 BackgroundParentImpl::~BackgroundParentImpl() {
128 AssertIsInMainOrSocketProcess();
129 AssertIsOnMainThread();
131 MOZ_COUNT_DTOR(mozilla::ipc::BackgroundParentImpl);
134 void BackgroundParentImpl::ActorDestroy(ActorDestroyReason aWhy) {
135 AssertIsInMainOrSocketProcess();
136 AssertIsOnBackgroundThread();
139 already_AddRefed<net::PBackgroundDataBridgeParent>
140 BackgroundParentImpl::AllocPBackgroundDataBridgeParent(
141 const uint64_t& aChannelID) {
142 MOZ_ASSERT(XRE_IsSocketProcess(), "Should be in socket process");
143 AssertIsOnBackgroundThread();
145 RefPtr<net::BackgroundDataBridgeParent> actor =
146 new net::BackgroundDataBridgeParent(aChannelID);
147 return actor.forget();
150 BackgroundParentImpl::PBackgroundTestParent*
151 BackgroundParentImpl::AllocPBackgroundTestParent(const nsACString& aTestArg) {
152 AssertIsInMainOrSocketProcess();
153 AssertIsOnBackgroundThread();
155 return new TestParent();
158 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundTestConstructor(
159 PBackgroundTestParent* aActor, const nsACString& aTestArg) {
160 AssertIsInMainOrSocketProcess();
161 AssertIsOnBackgroundThread();
162 MOZ_ASSERT(aActor);
164 if (!PBackgroundTestParent::Send__delete__(aActor, aTestArg)) {
165 return IPC_FAIL_NO_REASON(this);
167 return IPC_OK();
170 bool BackgroundParentImpl::DeallocPBackgroundTestParent(
171 PBackgroundTestParent* aActor) {
172 AssertIsInMainOrSocketProcess();
173 AssertIsOnBackgroundThread();
174 MOZ_ASSERT(aActor);
176 delete static_cast<TestParent*>(aActor);
177 return true;
180 auto BackgroundParentImpl::AllocPBackgroundIDBFactoryParent(
181 const LoggingInfo& aLoggingInfo)
182 -> already_AddRefed<PBackgroundIDBFactoryParent> {
183 using mozilla::dom::indexedDB::AllocPBackgroundIDBFactoryParent;
185 AssertIsInMainOrSocketProcess();
186 AssertIsOnBackgroundThread();
188 return AllocPBackgroundIDBFactoryParent(aLoggingInfo);
191 mozilla::ipc::IPCResult
192 BackgroundParentImpl::RecvPBackgroundIDBFactoryConstructor(
193 PBackgroundIDBFactoryParent* aActor, const LoggingInfo& aLoggingInfo) {
194 using mozilla::dom::indexedDB::RecvPBackgroundIDBFactoryConstructor;
196 AssertIsInMainOrSocketProcess();
197 AssertIsOnBackgroundThread();
198 MOZ_ASSERT(aActor);
200 if (!RecvPBackgroundIDBFactoryConstructor(aActor, aLoggingInfo)) {
201 return IPC_FAIL_NO_REASON(this);
203 return IPC_OK();
206 auto BackgroundParentImpl::AllocPBackgroundIndexedDBUtilsParent()
207 -> PBackgroundIndexedDBUtilsParent* {
208 AssertIsInMainOrSocketProcess();
209 AssertIsOnBackgroundThread();
211 return mozilla::dom::indexedDB::AllocPBackgroundIndexedDBUtilsParent();
214 bool BackgroundParentImpl::DeallocPBackgroundIndexedDBUtilsParent(
215 PBackgroundIndexedDBUtilsParent* aActor) {
216 AssertIsInMainOrSocketProcess();
217 AssertIsOnBackgroundThread();
218 MOZ_ASSERT(aActor);
220 return mozilla::dom::indexedDB::DeallocPBackgroundIndexedDBUtilsParent(
221 aActor);
224 mozilla::ipc::IPCResult BackgroundParentImpl::RecvFlushPendingFileDeletions() {
225 AssertIsInMainOrSocketProcess();
226 AssertIsOnBackgroundThread();
228 if (!mozilla::dom::indexedDB::RecvFlushPendingFileDeletions()) {
229 return IPC_FAIL_NO_REASON(this);
231 return IPC_OK();
234 BackgroundParentImpl::PBackgroundSDBConnectionParent*
235 BackgroundParentImpl::AllocPBackgroundSDBConnectionParent(
236 const PersistenceType& aPersistenceType,
237 const PrincipalInfo& aPrincipalInfo) {
238 AssertIsInMainOrSocketProcess();
239 AssertIsOnBackgroundThread();
241 return mozilla::dom::AllocPBackgroundSDBConnectionParent(aPersistenceType,
242 aPrincipalInfo);
245 mozilla::ipc::IPCResult
246 BackgroundParentImpl::RecvPBackgroundSDBConnectionConstructor(
247 PBackgroundSDBConnectionParent* aActor,
248 const PersistenceType& aPersistenceType,
249 const PrincipalInfo& aPrincipalInfo) {
250 AssertIsInMainOrSocketProcess();
251 AssertIsOnBackgroundThread();
252 MOZ_ASSERT(aActor);
254 if (!mozilla::dom::RecvPBackgroundSDBConnectionConstructor(
255 aActor, aPersistenceType, aPrincipalInfo)) {
256 return IPC_FAIL_NO_REASON(this);
258 return IPC_OK();
261 bool BackgroundParentImpl::DeallocPBackgroundSDBConnectionParent(
262 PBackgroundSDBConnectionParent* aActor) {
263 AssertIsInMainOrSocketProcess();
264 AssertIsOnBackgroundThread();
265 MOZ_ASSERT(aActor);
267 return mozilla::dom::DeallocPBackgroundSDBConnectionParent(aActor);
270 BackgroundParentImpl::PBackgroundLSDatabaseParent*
271 BackgroundParentImpl::AllocPBackgroundLSDatabaseParent(
272 const PrincipalInfo& aPrincipalInfo, const uint32_t& aPrivateBrowsingId,
273 const uint64_t& aDatastoreId) {
274 AssertIsInMainOrSocketProcess();
275 AssertIsOnBackgroundThread();
277 return mozilla::dom::AllocPBackgroundLSDatabaseParent(
278 aPrincipalInfo, aPrivateBrowsingId, aDatastoreId);
281 mozilla::ipc::IPCResult
282 BackgroundParentImpl::RecvPBackgroundLSDatabaseConstructor(
283 PBackgroundLSDatabaseParent* aActor, const PrincipalInfo& aPrincipalInfo,
284 const uint32_t& aPrivateBrowsingId, const uint64_t& aDatastoreId) {
285 AssertIsInMainOrSocketProcess();
286 AssertIsOnBackgroundThread();
287 MOZ_ASSERT(aActor);
289 if (!mozilla::dom::RecvPBackgroundLSDatabaseConstructor(
290 aActor, aPrincipalInfo, aPrivateBrowsingId, aDatastoreId)) {
291 return IPC_FAIL_NO_REASON(this);
293 return IPC_OK();
296 bool BackgroundParentImpl::DeallocPBackgroundLSDatabaseParent(
297 PBackgroundLSDatabaseParent* aActor) {
298 AssertIsInMainOrSocketProcess();
299 AssertIsOnBackgroundThread();
300 MOZ_ASSERT(aActor);
302 return mozilla::dom::DeallocPBackgroundLSDatabaseParent(aActor);
305 BackgroundParentImpl::PBackgroundLSObserverParent*
306 BackgroundParentImpl::AllocPBackgroundLSObserverParent(
307 const uint64_t& aObserverId) {
308 AssertIsInMainOrSocketProcess();
309 AssertIsOnBackgroundThread();
311 return mozilla::dom::AllocPBackgroundLSObserverParent(aObserverId);
314 mozilla::ipc::IPCResult
315 BackgroundParentImpl::RecvPBackgroundLSObserverConstructor(
316 PBackgroundLSObserverParent* aActor, const uint64_t& aObserverId) {
317 AssertIsInMainOrSocketProcess();
318 AssertIsOnBackgroundThread();
319 MOZ_ASSERT(aActor);
321 if (!mozilla::dom::RecvPBackgroundLSObserverConstructor(aActor,
322 aObserverId)) {
323 return IPC_FAIL_NO_REASON(this);
325 return IPC_OK();
328 bool BackgroundParentImpl::DeallocPBackgroundLSObserverParent(
329 PBackgroundLSObserverParent* aActor) {
330 AssertIsInMainOrSocketProcess();
331 AssertIsOnBackgroundThread();
332 MOZ_ASSERT(aActor);
334 return mozilla::dom::DeallocPBackgroundLSObserverParent(aActor);
337 BackgroundParentImpl::PBackgroundLSRequestParent*
338 BackgroundParentImpl::AllocPBackgroundLSRequestParent(
339 const LSRequestParams& aParams) {
340 AssertIsInMainOrSocketProcess();
341 AssertIsOnBackgroundThread();
343 return mozilla::dom::AllocPBackgroundLSRequestParent(this, aParams);
346 mozilla::ipc::IPCResult
347 BackgroundParentImpl::RecvPBackgroundLSRequestConstructor(
348 PBackgroundLSRequestParent* aActor, const LSRequestParams& aParams) {
349 AssertIsInMainOrSocketProcess();
350 AssertIsOnBackgroundThread();
351 MOZ_ASSERT(aActor);
353 if (!mozilla::dom::RecvPBackgroundLSRequestConstructor(aActor, aParams)) {
354 return IPC_FAIL_NO_REASON(this);
356 return IPC_OK();
359 bool BackgroundParentImpl::DeallocPBackgroundLSRequestParent(
360 PBackgroundLSRequestParent* aActor) {
361 AssertIsInMainOrSocketProcess();
362 AssertIsOnBackgroundThread();
363 MOZ_ASSERT(aActor);
365 return mozilla::dom::DeallocPBackgroundLSRequestParent(aActor);
368 BackgroundParentImpl::PBackgroundLSSimpleRequestParent*
369 BackgroundParentImpl::AllocPBackgroundLSSimpleRequestParent(
370 const LSSimpleRequestParams& aParams) {
371 AssertIsInMainOrSocketProcess();
372 AssertIsOnBackgroundThread();
374 return mozilla::dom::AllocPBackgroundLSSimpleRequestParent(this, aParams);
377 mozilla::ipc::IPCResult
378 BackgroundParentImpl::RecvPBackgroundLSSimpleRequestConstructor(
379 PBackgroundLSSimpleRequestParent* aActor,
380 const LSSimpleRequestParams& aParams) {
381 AssertIsInMainOrSocketProcess();
382 AssertIsOnBackgroundThread();
383 MOZ_ASSERT(aActor);
385 if (!mozilla::dom::RecvPBackgroundLSSimpleRequestConstructor(aActor,
386 aParams)) {
387 return IPC_FAIL_NO_REASON(this);
389 return IPC_OK();
392 bool BackgroundParentImpl::DeallocPBackgroundLSSimpleRequestParent(
393 PBackgroundLSSimpleRequestParent* aActor) {
394 AssertIsInMainOrSocketProcess();
395 AssertIsOnBackgroundThread();
396 MOZ_ASSERT(aActor);
398 return mozilla::dom::DeallocPBackgroundLSSimpleRequestParent(aActor);
401 BackgroundParentImpl::PBackgroundLocalStorageCacheParent*
402 BackgroundParentImpl::AllocPBackgroundLocalStorageCacheParent(
403 const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
404 const uint32_t& aPrivateBrowsingId) {
405 AssertIsInMainOrSocketProcess();
406 AssertIsOnBackgroundThread();
408 return mozilla::dom::AllocPBackgroundLocalStorageCacheParent(
409 aPrincipalInfo, aOriginKey, aPrivateBrowsingId);
412 mozilla::ipc::IPCResult
413 BackgroundParentImpl::RecvPBackgroundLocalStorageCacheConstructor(
414 PBackgroundLocalStorageCacheParent* aActor,
415 const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
416 const uint32_t& aPrivateBrowsingId) {
417 AssertIsInMainOrSocketProcess();
418 AssertIsOnBackgroundThread();
419 MOZ_ASSERT(aActor);
421 return mozilla::dom::RecvPBackgroundLocalStorageCacheConstructor(
422 this, aActor, aPrincipalInfo, aOriginKey, aPrivateBrowsingId);
425 bool BackgroundParentImpl::DeallocPBackgroundLocalStorageCacheParent(
426 PBackgroundLocalStorageCacheParent* aActor) {
427 AssertIsInMainOrSocketProcess();
428 AssertIsOnBackgroundThread();
429 MOZ_ASSERT(aActor);
431 return mozilla::dom::DeallocPBackgroundLocalStorageCacheParent(aActor);
434 auto BackgroundParentImpl::AllocPBackgroundStorageParent(
435 const nsAString& aProfilePath, const uint32_t& aPrivateBrowsingId)
436 -> PBackgroundStorageParent* {
437 AssertIsInMainOrSocketProcess();
438 AssertIsOnBackgroundThread();
440 return mozilla::dom::AllocPBackgroundStorageParent(aProfilePath,
441 aPrivateBrowsingId);
444 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBackgroundStorageConstructor(
445 PBackgroundStorageParent* aActor, const nsAString& aProfilePath,
446 const uint32_t& aPrivateBrowsingId) {
447 AssertIsInMainOrSocketProcess();
448 AssertIsOnBackgroundThread();
449 MOZ_ASSERT(aActor);
451 return mozilla::dom::RecvPBackgroundStorageConstructor(aActor, aProfilePath,
452 aPrivateBrowsingId);
455 bool BackgroundParentImpl::DeallocPBackgroundStorageParent(
456 PBackgroundStorageParent* aActor) {
457 AssertIsInMainOrSocketProcess();
458 AssertIsOnBackgroundThread();
459 MOZ_ASSERT(aActor);
461 return mozilla::dom::DeallocPBackgroundStorageParent(aActor);
464 already_AddRefed<BackgroundParentImpl::PBackgroundSessionStorageManagerParent>
465 BackgroundParentImpl::AllocPBackgroundSessionStorageManagerParent(
466 const uint64_t& aTopContextId) {
467 AssertIsInMainOrSocketProcess();
468 AssertIsOnBackgroundThread();
470 return dom::AllocPBackgroundSessionStorageManagerParent(aTopContextId);
473 already_AddRefed<mozilla::dom::PBackgroundSessionStorageServiceParent>
474 BackgroundParentImpl::AllocPBackgroundSessionStorageServiceParent() {
475 AssertIsInMainOrSocketProcess();
476 AssertIsOnBackgroundThread();
478 return MakeAndAddRef<mozilla::dom::BackgroundSessionStorageServiceParent>();
481 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateFileSystemManagerParent(
482 const PrincipalInfo& aPrincipalInfo,
483 Endpoint<PFileSystemManagerParent>&& aParentEndpoint,
484 CreateFileSystemManagerParentResolver&& aResolver) {
485 AssertIsInMainProcess();
486 AssertIsOnBackgroundThread();
488 return mozilla::dom::CreateFileSystemManagerParent(
489 aPrincipalInfo, std::move(aParentEndpoint), std::move(aResolver));
492 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateWebTransportParent(
493 const nsAString& aURL, nsIPrincipal* aPrincipal,
494 const mozilla::Maybe<IPCClientInfo>& aClientInfo, const bool& aDedicated,
495 const bool& aRequireUnreliable, const uint32_t& aCongestionControl,
496 // Sequence<WebTransportHash>* aServerCertHashes,
497 Endpoint<PWebTransportParent>&& aParentEndpoint,
498 CreateWebTransportParentResolver&& aResolver) {
499 AssertIsInMainProcess();
500 AssertIsOnBackgroundThread();
502 RefPtr<mozilla::dom::WebTransportParent> webt =
503 new mozilla::dom::WebTransportParent();
504 webt->Create(aURL, aPrincipal, aClientInfo, aDedicated, aRequireUnreliable,
505 aCongestionControl,
506 /*aServerCertHashes, */ std::move(aParentEndpoint),
507 std::move(aResolver));
508 return IPC_OK();
511 already_AddRefed<PIdleSchedulerParent>
512 BackgroundParentImpl::AllocPIdleSchedulerParent() {
513 AssertIsOnBackgroundThread();
514 RefPtr<IdleSchedulerParent> actor = new IdleSchedulerParent();
515 return actor.forget();
518 dom::PRemoteWorkerControllerParent*
519 BackgroundParentImpl::AllocPRemoteWorkerControllerParent(
520 const dom::RemoteWorkerData& aRemoteWorkerData) {
521 RefPtr<dom::RemoteWorkerControllerParent> actor =
522 new dom::RemoteWorkerControllerParent(aRemoteWorkerData);
523 return actor.forget().take();
526 IPCResult BackgroundParentImpl::RecvPRemoteWorkerControllerConstructor(
527 dom::PRemoteWorkerControllerParent* aActor,
528 const dom::RemoteWorkerData& aRemoteWorkerData) {
529 MOZ_ASSERT(aActor);
531 return IPC_OK();
534 bool BackgroundParentImpl::DeallocPRemoteWorkerControllerParent(
535 dom::PRemoteWorkerControllerParent* aActor) {
536 RefPtr<dom::RemoteWorkerControllerParent> actor =
537 dont_AddRef(static_cast<dom::RemoteWorkerControllerParent*>(aActor));
538 return true;
541 already_AddRefed<dom::PRemoteWorkerServiceParent>
542 BackgroundParentImpl::AllocPRemoteWorkerServiceParent() {
543 return MakeAndAddRef<dom::RemoteWorkerServiceParent>();
546 IPCResult BackgroundParentImpl::RecvPRemoteWorkerServiceConstructor(
547 PRemoteWorkerServiceParent* aActor) {
548 mozilla::dom::RemoteWorkerServiceParent* actor =
549 static_cast<mozilla::dom::RemoteWorkerServiceParent*>(aActor);
551 RefPtr<ThreadsafeContentParentHandle> parent =
552 BackgroundParent::GetContentParentHandle(this);
553 // If the ContentParent is null we are dealing with a same-process actor.
554 if (!parent) {
555 actor->Initialize(NOT_REMOTE_TYPE);
556 } else {
557 actor->Initialize(parent->GetRemoteType());
559 return IPC_OK();
562 mozilla::dom::PSharedWorkerParent*
563 BackgroundParentImpl::AllocPSharedWorkerParent(
564 const mozilla::dom::RemoteWorkerData& aData, const uint64_t& aWindowID,
565 const mozilla::dom::MessagePortIdentifier& aPortIdentifier) {
566 RefPtr<dom::SharedWorkerParent> agent =
567 new mozilla::dom::SharedWorkerParent();
568 return agent.forget().take();
571 IPCResult BackgroundParentImpl::RecvPSharedWorkerConstructor(
572 PSharedWorkerParent* aActor, const mozilla::dom::RemoteWorkerData& aData,
573 const uint64_t& aWindowID,
574 const mozilla::dom::MessagePortIdentifier& aPortIdentifier) {
575 mozilla::dom::SharedWorkerParent* actor =
576 static_cast<mozilla::dom::SharedWorkerParent*>(aActor);
577 actor->Initialize(aData, aWindowID, aPortIdentifier);
578 return IPC_OK();
581 bool BackgroundParentImpl::DeallocPSharedWorkerParent(
582 mozilla::dom::PSharedWorkerParent* aActor) {
583 RefPtr<mozilla::dom::SharedWorkerParent> actor =
584 dont_AddRef(static_cast<mozilla::dom::SharedWorkerParent*>(aActor));
585 return true;
588 dom::PFileCreatorParent* BackgroundParentImpl::AllocPFileCreatorParent(
589 const nsAString& aFullPath, const nsAString& aType, const nsAString& aName,
590 const Maybe<int64_t>& aLastModified, const bool& aExistenceCheck,
591 const bool& aIsFromNsIFile) {
592 RefPtr<dom::FileCreatorParent> actor = new dom::FileCreatorParent();
593 return actor.forget().take();
596 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPFileCreatorConstructor(
597 dom::PFileCreatorParent* aActor, const nsAString& aFullPath,
598 const nsAString& aType, const nsAString& aName,
599 const Maybe<int64_t>& aLastModified, const bool& aExistenceCheck,
600 const bool& aIsFromNsIFile) {
601 bool isFileRemoteType = false;
603 // If the ContentParentHandle is null we are dealing with a same-process
604 // actor.
605 RefPtr<ThreadsafeContentParentHandle> parent =
606 BackgroundParent::GetContentParentHandle(this);
607 if (!parent) {
608 isFileRemoteType = true;
609 } else {
610 isFileRemoteType = parent->GetRemoteType() == FILE_REMOTE_TYPE;
613 dom::FileCreatorParent* actor = static_cast<dom::FileCreatorParent*>(aActor);
615 // We allow the creation of File via this IPC call only for the 'file' process
616 // or for testing.
617 if (!isFileRemoteType && !StaticPrefs::dom_file_createInChild()) {
618 Unused << dom::FileCreatorParent::Send__delete__(
619 actor, dom::FileCreationErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
620 return IPC_OK();
623 return actor->CreateAndShareFile(aFullPath, aType, aName, aLastModified,
624 aExistenceCheck, aIsFromNsIFile);
627 bool BackgroundParentImpl::DeallocPFileCreatorParent(
628 dom::PFileCreatorParent* aActor) {
629 RefPtr<dom::FileCreatorParent> actor =
630 dont_AddRef(static_cast<dom::FileCreatorParent*>(aActor));
631 return true;
634 dom::PTemporaryIPCBlobParent*
635 BackgroundParentImpl::AllocPTemporaryIPCBlobParent() {
636 return new dom::TemporaryIPCBlobParent();
639 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPTemporaryIPCBlobConstructor(
640 dom::PTemporaryIPCBlobParent* aActor) {
641 dom::TemporaryIPCBlobParent* actor =
642 static_cast<dom::TemporaryIPCBlobParent*>(aActor);
643 return actor->CreateAndShareFile();
646 bool BackgroundParentImpl::DeallocPTemporaryIPCBlobParent(
647 dom::PTemporaryIPCBlobParent* aActor) {
648 delete aActor;
649 return true;
652 already_AddRefed<BackgroundParentImpl::PVsyncParent>
653 BackgroundParentImpl::AllocPVsyncParent() {
654 AssertIsInMainOrSocketProcess();
655 AssertIsOnBackgroundThread();
657 RefPtr<mozilla::dom::VsyncParent> actor = new mozilla::dom::VsyncParent();
659 RefPtr<mozilla::VsyncDispatcher> vsyncDispatcher =
660 gfxPlatform::GetPlatform()->GetGlobalVsyncDispatcher();
661 actor->UpdateVsyncDispatcher(vsyncDispatcher);
662 return actor.forget();
665 camera::PCamerasParent* BackgroundParentImpl::AllocPCamerasParent() {
666 AssertIsInMainOrSocketProcess();
667 AssertIsOnBackgroundThread();
669 #ifdef MOZ_WEBRTC
670 RefPtr<mozilla::camera::CamerasParent> actor =
671 mozilla::camera::CamerasParent::Create();
672 return actor.forget().take();
673 #else
674 return nullptr;
675 #endif
678 #ifdef MOZ_WEBRTC
679 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPCamerasConstructor(
680 camera::PCamerasParent* aActor) {
681 AssertIsInMainOrSocketProcess();
682 AssertIsOnBackgroundThread();
683 MOZ_ASSERT(aActor);
684 return static_cast<camera::CamerasParent*>(aActor)->RecvPCamerasConstructor();
686 #endif
688 bool BackgroundParentImpl::DeallocPCamerasParent(
689 camera::PCamerasParent* aActor) {
690 AssertIsInMainOrSocketProcess();
691 AssertIsOnBackgroundThread();
692 MOZ_ASSERT(aActor);
694 #ifdef MOZ_WEBRTC
695 RefPtr<mozilla::camera::CamerasParent> actor =
696 dont_AddRef(static_cast<mozilla::camera::CamerasParent*>(aActor));
697 #endif
698 return true;
701 auto BackgroundParentImpl::AllocPUDPSocketParent(
702 const Maybe<PrincipalInfo>& /* unused */, const nsACString& /* unused */)
703 -> PUDPSocketParent* {
704 RefPtr<UDPSocketParent> p = new UDPSocketParent(this);
706 return p.forget().take();
709 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPUDPSocketConstructor(
710 PUDPSocketParent* aActor, const Maybe<PrincipalInfo>& aOptionalPrincipal,
711 const nsACString& aFilter) {
712 AssertIsInMainOrSocketProcess();
713 AssertIsOnBackgroundThread();
715 if (aOptionalPrincipal.isSome()) {
716 // Support for checking principals (for non-mtransport use) will be handled
717 // in bug 1167039
718 return IPC_FAIL_NO_REASON(this);
720 // No principal - This must be from mtransport (WebRTC/ICE) - We'd want
721 // to DispatchToMainThread() here, but if we do we must block RecvBind()
722 // until Init() gets run. Since we don't have a principal, and we verify
723 // we have a filter, we can safely skip the Dispatch and just invoke Init()
724 // to install the filter.
726 // For mtransport, this will always be "stun", which doesn't allow outbound
727 // packets if they aren't STUN packets until a STUN response is seen.
728 if (!aFilter.EqualsASCII(NS_NETWORK_SOCKET_FILTER_HANDLER_STUN_SUFFIX)) {
729 return IPC_FAIL_NO_REASON(this);
732 if (!static_cast<UDPSocketParent*>(aActor)->Init(nullptr, aFilter)) {
733 MOZ_CRASH("UDPSocketCallback - failed init");
736 return IPC_OK();
739 bool BackgroundParentImpl::DeallocPUDPSocketParent(PUDPSocketParent* actor) {
740 UDPSocketParent* p = static_cast<UDPSocketParent*>(actor);
741 p->Release();
742 return true;
745 already_AddRefed<mozilla::psm::PVerifySSLServerCertParent>
746 BackgroundParentImpl::AllocPVerifySSLServerCertParent(
747 const nsTArray<ByteArray>& aPeerCertChain, const nsACString& aHostName,
748 const int32_t& aPort, const OriginAttributes& aOriginAttributes,
749 const Maybe<ByteArray>& aStapledOCSPResponse,
750 const Maybe<ByteArray>& aSctsFromTLSExtension,
751 const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
752 const uint32_t& aProviderFlags, const uint32_t& aCertVerifierFlags) {
753 RefPtr<mozilla::psm::VerifySSLServerCertParent> parent =
754 new mozilla::psm::VerifySSLServerCertParent();
755 return parent.forget();
758 mozilla::ipc::IPCResult
759 BackgroundParentImpl::RecvPVerifySSLServerCertConstructor(
760 PVerifySSLServerCertParent* aActor, nsTArray<ByteArray>&& aPeerCertChain,
761 const nsACString& aHostName, const int32_t& aPort,
762 const OriginAttributes& aOriginAttributes,
763 const Maybe<ByteArray>& aStapledOCSPResponse,
764 const Maybe<ByteArray>& aSctsFromTLSExtension,
765 const Maybe<DelegatedCredentialInfoArg>& aDcInfo,
766 const uint32_t& aProviderFlags, const uint32_t& aCertVerifierFlags) {
767 mozilla::psm::VerifySSLServerCertParent* authCert =
768 static_cast<mozilla::psm::VerifySSLServerCertParent*>(aActor);
769 if (!authCert->Dispatch(std::move(aPeerCertChain), aHostName, aPort,
770 aOriginAttributes, aStapledOCSPResponse,
771 aSctsFromTLSExtension, aDcInfo, aProviderFlags,
772 aCertVerifierFlags)) {
773 return IPC_FAIL_NO_REASON(this);
775 return IPC_OK();
778 already_AddRefed<mozilla::psm::PSelectTLSClientAuthCertParent>
779 BackgroundParentImpl::AllocPSelectTLSClientAuthCertParent(
780 const nsACString& aHostName, const OriginAttributes& aOriginAttributes,
781 const int32_t& aPort, const uint32_t& aProviderFlags,
782 const uint32_t& aProviderTlsFlags, const ByteArray& aServerCertBytes,
783 const nsTArray<ByteArray>& aCANames) {
784 RefPtr<mozilla::psm::SelectTLSClientAuthCertParent> parent =
785 new mozilla::psm::SelectTLSClientAuthCertParent();
786 return parent.forget();
789 mozilla::ipc::IPCResult
790 BackgroundParentImpl::RecvPSelectTLSClientAuthCertConstructor(
791 PSelectTLSClientAuthCertParent* actor, const nsACString& aHostName,
792 const OriginAttributes& aOriginAttributes, const int32_t& aPort,
793 const uint32_t& aProviderFlags, const uint32_t& aProviderTlsFlags,
794 const ByteArray& aServerCertBytes, nsTArray<ByteArray>&& aCANames) {
795 mozilla::psm::SelectTLSClientAuthCertParent* selectTLSClientAuthCertParent =
796 static_cast<mozilla::psm::SelectTLSClientAuthCertParent*>(actor);
797 if (!selectTLSClientAuthCertParent->Dispatch(
798 aHostName, aOriginAttributes, aPort, aProviderFlags,
799 aProviderTlsFlags, aServerCertBytes, std::move(aCANames))) {
800 return IPC_FAIL_NO_REASON(this);
802 return IPC_OK();
805 mozilla::dom::PBroadcastChannelParent*
806 BackgroundParentImpl::AllocPBroadcastChannelParent(
807 const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin,
808 const nsAString& aChannel) {
809 AssertIsInMainOrSocketProcess();
810 AssertIsOnBackgroundThread();
812 nsString originChannelKey;
814 // The format of originChannelKey is:
815 // <channelName>|<origin+OriginAttributes>
817 originChannelKey.Assign(aChannel);
819 originChannelKey.AppendLiteral("|");
821 originChannelKey.Append(NS_ConvertUTF8toUTF16(aOrigin));
823 return new BroadcastChannelParent(originChannelKey);
826 namespace {
828 class CheckPrincipalRunnable final : public Runnable {
829 public:
830 CheckPrincipalRunnable(
831 already_AddRefed<ThreadsafeContentParentHandle> aParent,
832 const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin)
833 : Runnable("ipc::CheckPrincipalRunnable"),
834 mContentParent(aParent),
835 mPrincipalInfo(aPrincipalInfo),
836 mOrigin(aOrigin) {
837 AssertIsInMainOrSocketProcess();
838 AssertIsOnBackgroundThread();
840 MOZ_ASSERT(mContentParent);
843 NS_IMETHOD Run() override {
844 AssertIsOnMainThread();
845 RefPtr<ContentParent> contentParent = mContentParent->GetContentParent();
846 if (!contentParent) {
847 return NS_OK;
850 auto principalOrErr = PrincipalInfoToPrincipal(mPrincipalInfo);
851 if (NS_WARN_IF(principalOrErr.isErr())) {
852 contentParent->KillHard(
853 "BroadcastChannel killed: PrincipalInfoToPrincipal failed.");
854 return NS_OK;
857 nsAutoCString origin;
858 nsresult rv = principalOrErr.unwrap()->GetOrigin(origin);
859 if (NS_FAILED(rv)) {
860 contentParent->KillHard(
861 "BroadcastChannel killed: principal::GetOrigin failed.");
862 return NS_OK;
865 if (NS_WARN_IF(!mOrigin.Equals(origin))) {
866 contentParent->KillHard("BroadcastChannel killed: origins do not match.");
867 return NS_OK;
870 return NS_OK;
873 private:
874 RefPtr<ThreadsafeContentParentHandle> mContentParent;
875 PrincipalInfo mPrincipalInfo;
876 nsCString mOrigin;
879 } // namespace
881 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPBroadcastChannelConstructor(
882 PBroadcastChannelParent* actor, const PrincipalInfo& aPrincipalInfo,
883 const nsACString& aOrigin, const nsAString& aChannel) {
884 AssertIsInMainOrSocketProcess();
885 AssertIsOnBackgroundThread();
887 RefPtr<ThreadsafeContentParentHandle> parent =
888 BackgroundParent::GetContentParentHandle(this);
890 // If the ContentParent is null we are dealing with a same-process actor.
891 if (!parent) {
892 return IPC_OK();
895 RefPtr<CheckPrincipalRunnable> runnable =
896 new CheckPrincipalRunnable(parent.forget(), aPrincipalInfo, aOrigin);
897 MOZ_ALWAYS_SUCCEEDS(NS_DispatchToMainThread(runnable));
899 return IPC_OK();
902 bool BackgroundParentImpl::DeallocPBroadcastChannelParent(
903 PBroadcastChannelParent* aActor) {
904 AssertIsInMainOrSocketProcess();
905 AssertIsOnBackgroundThread();
906 MOZ_ASSERT(aActor);
908 delete static_cast<BroadcastChannelParent*>(aActor);
909 return true;
912 mozilla::dom::PServiceWorkerManagerParent*
913 BackgroundParentImpl::AllocPServiceWorkerManagerParent() {
914 AssertIsInMainOrSocketProcess();
915 AssertIsOnBackgroundThread();
917 RefPtr<dom::ServiceWorkerManagerParent> agent =
918 new dom::ServiceWorkerManagerParent();
919 return agent.forget().take();
922 bool BackgroundParentImpl::DeallocPServiceWorkerManagerParent(
923 PServiceWorkerManagerParent* aActor) {
924 AssertIsInMainOrSocketProcess();
925 AssertIsOnBackgroundThread();
926 MOZ_ASSERT(aActor);
928 RefPtr<dom::ServiceWorkerManagerParent> parent =
929 dont_AddRef(static_cast<dom::ServiceWorkerManagerParent*>(aActor));
930 MOZ_ASSERT(parent);
931 return true;
934 mozilla::ipc::IPCResult
935 BackgroundParentImpl::RecvShutdownServiceWorkerRegistrar() {
936 AssertIsInMainOrSocketProcess();
937 AssertIsOnBackgroundThread();
939 if (BackgroundParent::IsOtherProcessActor(this)) {
940 return IPC_FAIL_NO_REASON(this);
943 RefPtr<dom::ServiceWorkerRegistrar> service =
944 dom::ServiceWorkerRegistrar::Get();
945 MOZ_ASSERT(service);
947 service->Shutdown();
948 return IPC_OK();
951 already_AddRefed<PCacheStorageParent>
952 BackgroundParentImpl::AllocPCacheStorageParent(
953 const Namespace& aNamespace, const PrincipalInfo& aPrincipalInfo) {
954 return dom::cache::AllocPCacheStorageParent(this, aNamespace, aPrincipalInfo);
957 PMessagePortParent* BackgroundParentImpl::AllocPMessagePortParent(
958 const nsID& aUUID, const nsID& aDestinationUUID,
959 const uint32_t& aSequenceID) {
960 AssertIsInMainOrSocketProcess();
961 AssertIsOnBackgroundThread();
963 return new MessagePortParent(aUUID);
966 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPMessagePortConstructor(
967 PMessagePortParent* aActor, const nsID& aUUID, const nsID& aDestinationUUID,
968 const uint32_t& aSequenceID) {
969 AssertIsInMainOrSocketProcess();
970 AssertIsOnBackgroundThread();
972 MessagePortParent* mp = static_cast<MessagePortParent*>(aActor);
973 if (!mp->Entangle(aDestinationUUID, aSequenceID)) {
974 return IPC_FAIL_NO_REASON(this);
976 return IPC_OK();
979 already_AddRefed<psm::PIPCClientCertsParent>
980 BackgroundParentImpl::AllocPIPCClientCertsParent() {
981 // This should only be called in the parent process with the socket process
982 // as the child process, not any content processes, hence the check that the
983 // child ID be 0.
984 MOZ_ASSERT(XRE_IsParentProcess());
985 MOZ_ASSERT(mozilla::ipc::BackgroundParent::GetChildID(this) == 0);
986 if (!XRE_IsParentProcess() ||
987 mozilla::ipc::BackgroundParent::GetChildID(this) != 0) {
988 return nullptr;
990 RefPtr<psm::IPCClientCertsParent> result = new psm::IPCClientCertsParent();
991 return result.forget();
994 bool BackgroundParentImpl::DeallocPMessagePortParent(
995 PMessagePortParent* aActor) {
996 AssertIsInMainOrSocketProcess();
997 AssertIsOnBackgroundThread();
998 MOZ_ASSERT(aActor);
1000 delete static_cast<MessagePortParent*>(aActor);
1001 return true;
1004 mozilla::ipc::IPCResult BackgroundParentImpl::RecvMessagePortForceClose(
1005 const nsID& aUUID, const nsID& aDestinationUUID,
1006 const uint32_t& aSequenceID) {
1007 AssertIsInMainOrSocketProcess();
1008 AssertIsOnBackgroundThread();
1010 if (!MessagePortParent::ForceClose(aUUID, aDestinationUUID, aSequenceID)) {
1011 return IPC_FAIL(this, "MessagePortParent::ForceClose failed.");
1014 return IPC_OK();
1017 BackgroundParentImpl::PQuotaParent* BackgroundParentImpl::AllocPQuotaParent() {
1018 AssertIsInMainOrSocketProcess();
1019 AssertIsOnBackgroundThread();
1021 return mozilla::dom::quota::AllocPQuotaParent();
1024 bool BackgroundParentImpl::DeallocPQuotaParent(PQuotaParent* aActor) {
1025 AssertIsInMainOrSocketProcess();
1026 AssertIsOnBackgroundThread();
1027 MOZ_ASSERT(aActor);
1029 return mozilla::dom::quota::DeallocPQuotaParent(aActor);
1032 mozilla::ipc::IPCResult BackgroundParentImpl::RecvShutdownQuotaManager() {
1033 AssertIsInMainOrSocketProcess();
1034 AssertIsOnBackgroundThread();
1036 if (BackgroundParent::IsOtherProcessActor(this)) {
1037 return IPC_FAIL_NO_REASON(this);
1040 if (!mozilla::dom::quota::RecvShutdownQuotaManager()) {
1041 return IPC_FAIL_NO_REASON(this);
1043 return IPC_OK();
1046 mozilla::ipc::IPCResult
1047 BackgroundParentImpl::RecvShutdownBackgroundSessionStorageManagers() {
1048 AssertIsInMainOrSocketProcess();
1049 AssertIsOnBackgroundThread();
1051 if (BackgroundParent::IsOtherProcessActor(this)) {
1052 return IPC_FAIL_NO_REASON(this);
1055 if (!mozilla::dom::RecvShutdownBackgroundSessionStorageManagers()) {
1056 return IPC_FAIL_NO_REASON(this);
1058 return IPC_OK();
1061 mozilla::ipc::IPCResult
1062 BackgroundParentImpl::RecvPropagateBackgroundSessionStorageManager(
1063 const uint64_t& aCurrentTopContextId, const uint64_t& aTargetTopContextId) {
1064 AssertIsInMainOrSocketProcess();
1065 AssertIsOnBackgroundThread();
1067 if (BackgroundParent::IsOtherProcessActor(this)) {
1068 return IPC_FAIL(this, "Wrong actor");
1071 mozilla::dom::RecvPropagateBackgroundSessionStorageManager(
1072 aCurrentTopContextId, aTargetTopContextId);
1074 return IPC_OK();
1077 mozilla::ipc::IPCResult
1078 BackgroundParentImpl::RecvRemoveBackgroundSessionStorageManager(
1079 const uint64_t& aTopContextId) {
1080 AssertIsInMainOrSocketProcess();
1081 AssertIsOnBackgroundThread();
1083 if (BackgroundParent::IsOtherProcessActor(this)) {
1084 return IPC_FAIL_NO_REASON(this);
1087 if (!mozilla::dom::RecvRemoveBackgroundSessionStorageManager(aTopContextId)) {
1088 return IPC_FAIL_NO_REASON(this);
1090 return IPC_OK();
1093 mozilla::ipc::IPCResult BackgroundParentImpl::RecvGetSessionStorageManagerData(
1094 const uint64_t& aTopContextId, const uint32_t& aSizeLimit,
1095 const bool& aCancelSessionStoreTimer,
1096 GetSessionStorageManagerDataResolver&& aResolver) {
1097 AssertIsInMainProcess();
1098 AssertIsOnBackgroundThread();
1100 if (BackgroundParent::IsOtherProcessActor(this)) {
1101 return IPC_FAIL(this, "Wrong actor");
1104 if (!mozilla::dom::RecvGetSessionStorageData(aTopContextId, aSizeLimit,
1105 aCancelSessionStoreTimer,
1106 std::move(aResolver))) {
1107 return IPC_FAIL(this, "Couldn't get session storage data");
1110 return IPC_OK();
1113 mozilla::ipc::IPCResult BackgroundParentImpl::RecvLoadSessionStorageManagerData(
1114 const uint64_t& aTopContextId,
1115 nsTArray<mozilla::dom::SSCacheCopy>&& aOriginCacheCopy) {
1116 AssertIsInMainProcess();
1117 AssertIsOnBackgroundThread();
1119 if (BackgroundParent::IsOtherProcessActor(this)) {
1120 return IPC_FAIL(this, "Wrong actor");
1123 if (!mozilla::dom::RecvLoadSessionStorageData(aTopContextId,
1124 std::move(aOriginCacheCopy))) {
1125 return IPC_FAIL_NO_REASON(this);
1128 return IPC_OK();
1131 already_AddRefed<dom::PFileSystemRequestParent>
1132 BackgroundParentImpl::AllocPFileSystemRequestParent(
1133 const FileSystemParams& aParams) {
1134 AssertIsInMainOrSocketProcess();
1135 AssertIsOnBackgroundThread();
1137 RefPtr<FileSystemRequestParent> result = new FileSystemRequestParent();
1139 if (NS_WARN_IF(!result->Initialize(aParams))) {
1140 return nullptr;
1143 return result.forget();
1146 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPFileSystemRequestConstructor(
1147 PFileSystemRequestParent* aActor, const FileSystemParams& params) {
1148 static_cast<FileSystemRequestParent*>(aActor)->Start();
1149 return IPC_OK();
1152 // Gamepad API Background IPC
1153 already_AddRefed<dom::PGamepadEventChannelParent>
1154 BackgroundParentImpl::AllocPGamepadEventChannelParent() {
1155 return dom::GamepadEventChannelParent::Create();
1158 already_AddRefed<dom::PGamepadTestChannelParent>
1159 BackgroundParentImpl::AllocPGamepadTestChannelParent() {
1160 return dom::GamepadTestChannelParent::Create();
1163 dom::PWebAuthnTransactionParent*
1164 BackgroundParentImpl::AllocPWebAuthnTransactionParent() {
1165 return new dom::WebAuthnTransactionParent();
1168 bool BackgroundParentImpl::DeallocPWebAuthnTransactionParent(
1169 dom::PWebAuthnTransactionParent* aActor) {
1170 MOZ_ASSERT(aActor);
1171 delete aActor;
1172 return true;
1175 already_AddRefed<net::PHttpBackgroundChannelParent>
1176 BackgroundParentImpl::AllocPHttpBackgroundChannelParent(
1177 const uint64_t& aChannelId) {
1178 AssertIsInMainOrSocketProcess();
1179 AssertIsOnBackgroundThread();
1181 RefPtr<net::HttpBackgroundChannelParent> actor =
1182 new net::HttpBackgroundChannelParent();
1183 return actor.forget();
1186 mozilla::ipc::IPCResult
1187 BackgroundParentImpl::RecvPHttpBackgroundChannelConstructor(
1188 net::PHttpBackgroundChannelParent* aActor, const uint64_t& aChannelId) {
1189 MOZ_ASSERT(aActor);
1190 AssertIsInMainOrSocketProcess();
1191 AssertIsOnBackgroundThread();
1193 net::HttpBackgroundChannelParent* aParent =
1194 static_cast<net::HttpBackgroundChannelParent*>(aActor);
1196 if (NS_WARN_IF(NS_FAILED(aParent->Init(aChannelId)))) {
1197 return IPC_FAIL_NO_REASON(this);
1200 return IPC_OK();
1203 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIPort(
1204 Endpoint<PMIDIPortParent>&& aEndpoint, const MIDIPortInfo& aPortInfo,
1205 const bool& aSysexEnabled) {
1206 AssertIsInMainOrSocketProcess();
1207 AssertIsOnBackgroundThread();
1209 if (!aEndpoint.IsValid()) {
1210 return IPC_FAIL(this, "invalid endpoint for MIDIPort");
1213 MIDIPlatformService::OwnerThread()->Dispatch(NS_NewRunnableFunction(
1214 "CreateMIDIPortRunnable", [=, endpoint = std::move(aEndpoint)]() mutable {
1215 RefPtr<MIDIPortParent> result =
1216 new MIDIPortParent(aPortInfo, aSysexEnabled);
1217 endpoint.Bind(result);
1218 }));
1220 return IPC_OK();
1223 mozilla::ipc::IPCResult BackgroundParentImpl::RecvCreateMIDIManager(
1224 Endpoint<PMIDIManagerParent>&& aEndpoint) {
1225 AssertIsInMainOrSocketProcess();
1226 AssertIsOnBackgroundThread();
1228 if (!aEndpoint.IsValid()) {
1229 return IPC_FAIL(this, "invalid endpoint for MIDIManager");
1232 MIDIPlatformService::OwnerThread()->Dispatch(NS_NewRunnableFunction(
1233 "CreateMIDIManagerRunnable",
1234 [=, endpoint = std::move(aEndpoint)]() mutable {
1235 RefPtr<MIDIManagerParent> result = new MIDIManagerParent();
1236 endpoint.Bind(result);
1237 MIDIPlatformService::Get()->AddManager(result);
1238 }));
1240 return IPC_OK();
1243 mozilla::ipc::IPCResult BackgroundParentImpl::RecvHasMIDIDevice(
1244 HasMIDIDeviceResolver&& aResolver) {
1245 AssertIsInMainOrSocketProcess();
1246 AssertIsOnBackgroundThread();
1248 InvokeAsync(MIDIPlatformService::OwnerThread(), __func__,
1249 []() {
1250 bool hasDevice = MIDIPlatformService::Get()->HasDevice();
1251 return BoolPromise::CreateAndResolve(hasDevice, __func__);
1253 ->Then(GetCurrentSerialEventTarget(), __func__,
1254 [resolver = std::move(aResolver)](
1255 const BoolPromise::ResolveOrRejectValue& r) {
1256 resolver(r.IsResolve() && r.ResolveValue());
1259 return IPC_OK();
1262 mozilla::dom::PClientManagerParent*
1263 BackgroundParentImpl::AllocPClientManagerParent() {
1264 return mozilla::dom::AllocClientManagerParent();
1267 bool BackgroundParentImpl::DeallocPClientManagerParent(
1268 mozilla::dom::PClientManagerParent* aActor) {
1269 return mozilla::dom::DeallocClientManagerParent(aActor);
1272 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPClientManagerConstructor(
1273 mozilla::dom::PClientManagerParent* aActor) {
1274 mozilla::dom::InitClientManagerParent(aActor);
1275 return IPC_OK();
1278 IPCResult BackgroundParentImpl::RecvStorageActivity(
1279 const PrincipalInfo& aPrincipalInfo) {
1280 dom::StorageActivityService::SendActivity(aPrincipalInfo);
1281 return IPC_OK();
1284 IPCResult BackgroundParentImpl::RecvPServiceWorkerManagerConstructor(
1285 PServiceWorkerManagerParent* const aActor) {
1286 // Only the parent process is allowed to construct this actor.
1287 if (BackgroundParent::IsOtherProcessActor(this)) {
1288 return IPC_FAIL_NO_REASON(aActor);
1290 return IPC_OK();
1293 already_AddRefed<PServiceWorkerParent>
1294 BackgroundParentImpl::AllocPServiceWorkerParent(
1295 const IPCServiceWorkerDescriptor&) {
1296 return MakeAndAddRef<ServiceWorkerParent>();
1299 IPCResult BackgroundParentImpl::RecvPServiceWorkerConstructor(
1300 PServiceWorkerParent* aActor,
1301 const IPCServiceWorkerDescriptor& aDescriptor) {
1302 dom::InitServiceWorkerParent(aActor, aDescriptor);
1303 return IPC_OK();
1306 already_AddRefed<PServiceWorkerContainerParent>
1307 BackgroundParentImpl::AllocPServiceWorkerContainerParent() {
1308 return MakeAndAddRef<mozilla::dom::ServiceWorkerContainerParent>();
1311 mozilla::ipc::IPCResult
1312 BackgroundParentImpl::RecvPServiceWorkerContainerConstructor(
1313 PServiceWorkerContainerParent* aActor) {
1314 dom::InitServiceWorkerContainerParent(aActor);
1315 return IPC_OK();
1318 already_AddRefed<PServiceWorkerRegistrationParent>
1319 BackgroundParentImpl::AllocPServiceWorkerRegistrationParent(
1320 const IPCServiceWorkerRegistrationDescriptor&) {
1321 return MakeAndAddRef<mozilla::dom::ServiceWorkerRegistrationParent>();
1324 mozilla::ipc::IPCResult
1325 BackgroundParentImpl::RecvPServiceWorkerRegistrationConstructor(
1326 PServiceWorkerRegistrationParent* aActor,
1327 const IPCServiceWorkerRegistrationDescriptor& aDescriptor) {
1328 dom::InitServiceWorkerRegistrationParent(aActor, aDescriptor);
1329 return IPC_OK();
1332 dom::PEndpointForReportParent*
1333 BackgroundParentImpl::AllocPEndpointForReportParent(
1334 const nsAString& aGroupName, const PrincipalInfo& aPrincipalInfo) {
1335 RefPtr<dom::EndpointForReportParent> actor =
1336 new dom::EndpointForReportParent();
1337 return actor.forget().take();
1340 mozilla::ipc::IPCResult BackgroundParentImpl::RecvPEndpointForReportConstructor(
1341 PEndpointForReportParent* aActor, const nsAString& aGroupName,
1342 const PrincipalInfo& aPrincipalInfo) {
1343 static_cast<dom::EndpointForReportParent*>(aActor)->Run(aGroupName,
1344 aPrincipalInfo);
1345 return IPC_OK();
1348 mozilla::ipc::IPCResult
1349 BackgroundParentImpl::RecvEnsureRDDProcessAndCreateBridge(
1350 EnsureRDDProcessAndCreateBridgeResolver&& aResolver) {
1351 RDDProcessManager* rdd = RDDProcessManager::Get();
1352 using Type = std::tuple<const nsresult&,
1353 Endpoint<mozilla::PRemoteDecoderManagerChild>&&>;
1354 if (!rdd) {
1355 aResolver(
1356 Type(NS_ERROR_NOT_AVAILABLE, Endpoint<PRemoteDecoderManagerChild>()));
1357 } else {
1358 rdd->EnsureRDDProcessAndCreateBridge(OtherPid())
1359 ->Then(GetCurrentSerialEventTarget(), __func__,
1360 [resolver = std::move(aResolver)](
1361 mozilla::RDDProcessManager::EnsureRDDPromise::
1362 ResolveOrRejectValue&& aValue) mutable {
1363 if (aValue.IsReject()) {
1364 resolver(Type(aValue.RejectValue(),
1365 Endpoint<PRemoteDecoderManagerChild>()));
1366 return;
1368 resolver(Type(NS_OK, std::move(aValue.ResolveValue())));
1371 return IPC_OK();
1374 mozilla::ipc::IPCResult
1375 BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge(
1376 const RemoteDecodeIn& aLocation,
1377 EnsureUtilityProcessAndCreateBridgeResolver&& aResolver) {
1378 base::ProcessId otherPid = OtherPid();
1379 nsCOMPtr<nsISerialEventTarget> managerThread = GetCurrentSerialEventTarget();
1380 if (!managerThread) {
1381 return IPC_FAIL_NO_REASON(this);
1383 NS_DispatchToMainThread(NS_NewRunnableFunction(
1384 "BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge()",
1385 [aResolver, managerThread, otherPid, aLocation]() {
1386 RefPtr<UtilityProcessManager> upm =
1387 UtilityProcessManager::GetSingleton();
1388 using Type =
1389 std::tuple<const nsresult&,
1390 Endpoint<mozilla::PRemoteDecoderManagerChild>&&>;
1391 if (!upm) {
1392 managerThread->Dispatch(NS_NewRunnableFunction(
1393 "BackgroundParentImpl::RecvEnsureUtilityProcessAndCreateBridge::"
1394 "Failure",
1395 [aResolver]() {
1396 aResolver(Type(NS_ERROR_NOT_AVAILABLE,
1397 Endpoint<PRemoteDecoderManagerChild>()));
1398 }));
1399 } else {
1400 SandboxingKind sbKind = GetSandboxingKindFromLocation(aLocation);
1401 upm->StartProcessForRemoteMediaDecoding(otherPid, sbKind)
1402 ->Then(managerThread, __func__,
1403 [resolver = aResolver](
1404 mozilla::ipc::UtilityProcessManager::
1405 StartRemoteDecodingUtilityPromise::
1406 ResolveOrRejectValue&& aValue) mutable {
1407 if (aValue.IsReject()) {
1408 resolver(Type(aValue.RejectValue(),
1409 Endpoint<PRemoteDecoderManagerChild>()));
1410 return;
1412 resolver(Type(NS_OK, std::move(aValue.ResolveValue())));
1415 }));
1416 return IPC_OK();
1419 mozilla::ipc::IPCResult BackgroundParentImpl::RecvRequestCameraAccess(
1420 RequestCameraAccessResolver&& aResolver) {
1421 #ifdef MOZ_WEBRTC
1422 mozilla::camera::CamerasParent::RequestCameraAccess()->Then(
1423 GetCurrentSerialEventTarget(), __func__,
1424 [resolver = std::move(aResolver)](
1425 const mozilla::camera::CamerasParent::CameraAccessRequestPromise::
1426 ResolveOrRejectValue& aValue) {
1427 if (aValue.IsResolve()) {
1428 resolver(aValue.ResolveValue());
1429 } else {
1430 resolver(aValue.RejectValue());
1433 #else
1434 aResolver(NS_ERROR_NOT_IMPLEMENTED);
1435 #endif
1436 return IPC_OK();
1439 bool BackgroundParentImpl::DeallocPEndpointForReportParent(
1440 PEndpointForReportParent* aActor) {
1441 RefPtr<dom::EndpointForReportParent> actor =
1442 dont_AddRef(static_cast<dom::EndpointForReportParent*>(aActor));
1443 return true;
1446 mozilla::ipc::IPCResult BackgroundParentImpl::RecvRemoveEndpoint(
1447 const nsAString& aGroupName, const nsACString& aEndpointURL,
1448 const PrincipalInfo& aPrincipalInfo) {
1449 NS_DispatchToMainThread(NS_NewRunnableFunction(
1450 "BackgroundParentImpl::RecvRemoveEndpoint(",
1451 [aGroupName = nsString(aGroupName),
1452 aEndpointURL = nsCString(aEndpointURL), aPrincipalInfo]() {
1453 dom::ReportingHeader::RemoveEndpoint(aGroupName, aEndpointURL,
1454 aPrincipalInfo);
1455 }));
1457 return IPC_OK();
1460 dom::PMediaTransportParent* BackgroundParentImpl::AllocPMediaTransportParent() {
1461 #ifdef MOZ_WEBRTC
1462 return new MediaTransportParent;
1463 #else
1464 return nullptr;
1465 #endif
1468 bool BackgroundParentImpl::DeallocPMediaTransportParent(
1469 dom::PMediaTransportParent* aActor) {
1470 #ifdef MOZ_WEBRTC
1471 delete aActor;
1472 #endif
1473 return true;
1476 already_AddRefed<dom::locks::PLockManagerParent>
1477 BackgroundParentImpl::AllocPLockManagerParent(
1478 const ContentPrincipalInfo& aPrincipalInfo, const nsID& aClientId) {
1479 return MakeAndAddRef<mozilla::dom::locks::LockManagerParent>(aPrincipalInfo,
1480 aClientId);
1483 already_AddRefed<dom::PFetchParent> BackgroundParentImpl::AllocPFetchParent() {
1484 return MakeAndAddRef<dom::FetchParent>();
1487 already_AddRefed<mozilla::net::PWebSocketConnectionParent>
1488 BackgroundParentImpl::AllocPWebSocketConnectionParent(
1489 const uint32_t& aListenerId) {
1490 Maybe<nsCOMPtr<nsIHttpUpgradeListener>> listener =
1491 net::HttpConnectionMgrParent::GetAndRemoveHttpUpgradeListener(
1492 aListenerId);
1493 if (!listener) {
1494 return nullptr;
1497 RefPtr<mozilla::net::WebSocketConnectionParent> actor =
1498 new mozilla::net::WebSocketConnectionParent(*listener);
1499 return actor.forget();
1502 mozilla::ipc::IPCResult
1503 BackgroundParentImpl::RecvPWebSocketConnectionConstructor(
1504 PWebSocketConnectionParent* actor, const uint32_t& aListenerId) {
1505 return IPC_OK();
1508 } // namespace mozilla::ipc
1510 void TestParent::ActorDestroy(ActorDestroyReason aWhy) {
1511 mozilla::ipc::AssertIsInMainOrSocketProcess();
1512 AssertIsOnBackgroundThread();