no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / ipc / glue / BackgroundChildImpl.cpp
blobf21f393e2c61b608fa1752a46ea12c70306d4ad3
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 "BackgroundChildImpl.h"
9 #include "BroadcastChannelChild.h"
10 #ifdef MOZ_WEBRTC
11 # include "CamerasChild.h"
12 #endif
13 #include "mozilla/Assertions.h"
14 #include "mozilla/SchedulerGroup.h"
15 #include "mozilla/dom/ClientManagerActors.h"
16 #include "mozilla/dom/FileCreatorChild.h"
17 #include "mozilla/dom/PBackgroundLSDatabaseChild.h"
18 #include "mozilla/dom/PBackgroundLSObserverChild.h"
19 #include "mozilla/dom/PBackgroundLSRequestChild.h"
20 #include "mozilla/dom/PBackgroundLSSimpleRequestChild.h"
21 #include "mozilla/dom/PBackgroundSDBConnectionChild.h"
22 #include "mozilla/dom/PFileSystemRequestChild.h"
23 #include "mozilla/dom/EndpointForReportChild.h"
24 #include "mozilla/dom/PVsync.h"
25 #include "mozilla/dom/TemporaryIPCBlobChild.h"
26 #include "mozilla/dom/cache/ActorUtils.h"
27 #include "mozilla/dom/indexedDB/PBackgroundIndexedDBUtilsChild.h"
28 #include "mozilla/dom/indexedDB/ThreadLocal.h"
29 #include "mozilla/dom/quota/PQuotaChild.h"
30 #include "mozilla/dom/RemoteWorkerChild.h"
31 #include "mozilla/dom/RemoteWorkerControllerChild.h"
32 #include "mozilla/dom/RemoteWorkerServiceChild.h"
33 #include "mozilla/dom/ServiceWorkerChild.h"
34 #include "mozilla/dom/SharedWorkerChild.h"
35 #include "mozilla/dom/StorageIPC.h"
36 #include "mozilla/dom/MessagePortChild.h"
37 #include "mozilla/dom/ServiceWorkerContainerChild.h"
38 #include "mozilla/dom/ServiceWorkerManagerChild.h"
39 #include "mozilla/ipc/PBackgroundTestChild.h"
40 #include "mozilla/net/PUDPSocketChild.h"
41 #include "mozilla/dom/network/UDPSocketChild.h"
42 #include "mozilla/dom/WebAuthnTransactionChild.h"
43 #include "mozilla/dom/MIDIPortChild.h"
44 #include "mozilla/dom/MIDIManagerChild.h"
45 #include "nsID.h"
47 namespace {
49 class TestChild final : public mozilla::ipc::PBackgroundTestChild {
50 friend class mozilla::ipc::BackgroundChildImpl;
52 nsCString mTestArg;
54 explicit TestChild(const nsACString& aTestArg) : mTestArg(aTestArg) {
55 MOZ_COUNT_CTOR(TestChild);
58 protected:
59 ~TestChild() override { MOZ_COUNT_DTOR(TestChild); }
61 public:
62 mozilla::ipc::IPCResult Recv__delete__(const nsACString& aTestArg) override;
65 } // namespace
67 namespace mozilla::ipc {
69 using mozilla::dom::UDPSocketChild;
70 using mozilla::net::PUDPSocketChild;
72 using mozilla::dom::PRemoteWorkerChild;
73 using mozilla::dom::PServiceWorkerChild;
74 using mozilla::dom::PServiceWorkerContainerChild;
75 using mozilla::dom::PServiceWorkerRegistrationChild;
76 using mozilla::dom::RemoteWorkerChild;
77 using mozilla::dom::StorageDBChild;
78 using mozilla::dom::cache::PCacheChild;
79 using mozilla::dom::cache::PCacheStreamControlChild;
81 using mozilla::dom::WebAuthnTransactionChild;
83 using mozilla::dom::PMIDIManagerChild;
84 using mozilla::dom::PMIDIPortChild;
86 // -----------------------------------------------------------------------------
87 // BackgroundChildImpl::ThreadLocal
88 // -----------------------------------------------------------------------------
90 BackgroundChildImpl::ThreadLocal::ThreadLocal() : mCurrentFileHandle(nullptr) {
91 // May happen on any thread!
92 MOZ_COUNT_CTOR(mozilla::ipc::BackgroundChildImpl::ThreadLocal);
95 BackgroundChildImpl::ThreadLocal::~ThreadLocal() {
96 // May happen on any thread!
97 MOZ_COUNT_DTOR(mozilla::ipc::BackgroundChildImpl::ThreadLocal);
100 // -----------------------------------------------------------------------------
101 // BackgroundChildImpl
102 // -----------------------------------------------------------------------------
104 BackgroundChildImpl::BackgroundChildImpl() {
105 // May happen on any thread!
106 MOZ_COUNT_CTOR(mozilla::ipc::BackgroundChildImpl);
109 BackgroundChildImpl::~BackgroundChildImpl() {
110 // May happen on any thread!
111 MOZ_COUNT_DTOR(mozilla::ipc::BackgroundChildImpl);
114 void BackgroundChildImpl::ProcessingError(Result aCode, const char* aReason) {
115 // May happen on any thread!
117 nsAutoCString abortMessage;
119 switch (aCode) {
120 case MsgDropped:
121 return;
123 #define HANDLE_CASE(_result) \
124 case _result: \
125 abortMessage.AssignLiteral(#_result); \
126 break
128 HANDLE_CASE(MsgNotKnown);
129 HANDLE_CASE(MsgNotAllowed);
130 HANDLE_CASE(MsgPayloadError);
131 HANDLE_CASE(MsgProcessingError);
132 HANDLE_CASE(MsgRouteError);
133 HANDLE_CASE(MsgValueError);
135 #undef HANDLE_CASE
137 default:
138 MOZ_CRASH("Unknown error code!");
141 CrashReporter::RecordAnnotationCString(
142 CrashReporter::Annotation::ipc_channel_error, aReason);
144 MOZ_CRASH_UNSAFE_PRINTF("%s: %s", abortMessage.get(), aReason);
147 void BackgroundChildImpl::ActorDestroy(ActorDestroyReason aWhy) {
148 // May happen on any thread!
151 PBackgroundTestChild* BackgroundChildImpl::AllocPBackgroundTestChild(
152 const nsACString& aTestArg) {
153 return new TestChild(aTestArg);
156 bool BackgroundChildImpl::DeallocPBackgroundTestChild(
157 PBackgroundTestChild* aActor) {
158 MOZ_ASSERT(aActor);
160 delete static_cast<TestChild*>(aActor);
161 return true;
164 BackgroundChildImpl::PBackgroundIndexedDBUtilsChild*
165 BackgroundChildImpl::AllocPBackgroundIndexedDBUtilsChild() {
166 MOZ_CRASH(
167 "PBackgroundIndexedDBUtilsChild actors should be manually "
168 "constructed!");
171 bool BackgroundChildImpl::DeallocPBackgroundIndexedDBUtilsChild(
172 PBackgroundIndexedDBUtilsChild* aActor) {
173 MOZ_ASSERT(aActor);
175 delete aActor;
176 return true;
179 BackgroundChildImpl::PBackgroundLSObserverChild*
180 BackgroundChildImpl::AllocPBackgroundLSObserverChild(
181 const uint64_t& aObserverId) {
182 MOZ_CRASH("PBackgroundLSObserverChild actor should be manually constructed!");
185 bool BackgroundChildImpl::DeallocPBackgroundLSObserverChild(
186 PBackgroundLSObserverChild* aActor) {
187 MOZ_ASSERT(aActor);
189 delete aActor;
190 return true;
193 BackgroundChildImpl::PBackgroundLSRequestChild*
194 BackgroundChildImpl::AllocPBackgroundLSRequestChild(
195 const LSRequestParams& aParams) {
196 MOZ_CRASH("PBackgroundLSRequestChild actor should be manually constructed!");
199 bool BackgroundChildImpl::DeallocPBackgroundLSRequestChild(
200 PBackgroundLSRequestChild* aActor) {
201 MOZ_ASSERT(aActor);
203 delete aActor;
204 return true;
207 BackgroundChildImpl::PBackgroundLocalStorageCacheChild*
208 BackgroundChildImpl::AllocPBackgroundLocalStorageCacheChild(
209 const PrincipalInfo& aPrincipalInfo, const nsACString& aOriginKey,
210 const uint32_t& aPrivateBrowsingId) {
211 MOZ_CRASH(
212 "PBackgroundLocalStorageChild actors should be manually "
213 "constructed!");
216 bool BackgroundChildImpl::DeallocPBackgroundLocalStorageCacheChild(
217 PBackgroundLocalStorageCacheChild* aActor) {
218 MOZ_ASSERT(aActor);
220 delete aActor;
221 return true;
224 BackgroundChildImpl::PBackgroundLSSimpleRequestChild*
225 BackgroundChildImpl::AllocPBackgroundLSSimpleRequestChild(
226 const LSSimpleRequestParams& aParams) {
227 MOZ_CRASH(
228 "PBackgroundLSSimpleRequestChild actor should be manually "
229 "constructed!");
232 bool BackgroundChildImpl::DeallocPBackgroundLSSimpleRequestChild(
233 PBackgroundLSSimpleRequestChild* aActor) {
234 MOZ_ASSERT(aActor);
236 delete aActor;
237 return true;
240 BackgroundChildImpl::PBackgroundStorageChild*
241 BackgroundChildImpl::AllocPBackgroundStorageChild(
242 const nsAString& aProfilePath, const uint32_t& aPrivateBrowsingId) {
243 MOZ_CRASH("PBackgroundStorageChild actors should be manually constructed!");
246 bool BackgroundChildImpl::DeallocPBackgroundStorageChild(
247 PBackgroundStorageChild* aActor) {
248 MOZ_ASSERT(aActor);
250 StorageDBChild* child = static_cast<StorageDBChild*>(aActor);
251 child->ReleaseIPDLReference();
252 return true;
255 already_AddRefed<PRemoteWorkerChild>
256 BackgroundChildImpl::AllocPRemoteWorkerChild(const RemoteWorkerData& aData) {
257 return MakeAndAddRef<RemoteWorkerChild>(aData);
260 IPCResult BackgroundChildImpl::RecvPRemoteWorkerConstructor(
261 PRemoteWorkerChild* aActor, const RemoteWorkerData& aData) {
262 dom::RemoteWorkerChild* actor = static_cast<dom::RemoteWorkerChild*>(aActor);
263 actor->ExecWorker(aData);
264 return IPC_OK();
267 dom::PSharedWorkerChild* BackgroundChildImpl::AllocPSharedWorkerChild(
268 const dom::RemoteWorkerData& aData, const uint64_t& aWindowID,
269 const dom::MessagePortIdentifier& aPortIdentifier) {
270 RefPtr<dom::SharedWorkerChild> agent = new dom::SharedWorkerChild();
271 return agent.forget().take();
274 bool BackgroundChildImpl::DeallocPSharedWorkerChild(
275 dom::PSharedWorkerChild* aActor) {
276 RefPtr<dom::SharedWorkerChild> actor =
277 dont_AddRef(static_cast<dom::SharedWorkerChild*>(aActor));
278 return true;
281 dom::PTemporaryIPCBlobChild*
282 BackgroundChildImpl::AllocPTemporaryIPCBlobChild() {
283 MOZ_CRASH("This is not supposed to be called.");
284 return nullptr;
287 bool BackgroundChildImpl::DeallocPTemporaryIPCBlobChild(
288 dom::PTemporaryIPCBlobChild* aActor) {
289 RefPtr<dom::TemporaryIPCBlobChild> actor =
290 dont_AddRef(static_cast<dom::TemporaryIPCBlobChild*>(aActor));
291 return true;
294 dom::PFileCreatorChild* BackgroundChildImpl::AllocPFileCreatorChild(
295 const nsAString& aFullPath, const nsAString& aType, const nsAString& aName,
296 const Maybe<int64_t>& aLastModified, const bool& aExistenceCheck,
297 const bool& aIsFromNsIFile) {
298 return new dom::FileCreatorChild();
301 bool BackgroundChildImpl::DeallocPFileCreatorChild(PFileCreatorChild* aActor) {
302 delete static_cast<dom::FileCreatorChild*>(aActor);
303 return true;
306 PUDPSocketChild* BackgroundChildImpl::AllocPUDPSocketChild(
307 const Maybe<PrincipalInfo>& aPrincipalInfo, const nsACString& aFilter) {
308 MOZ_CRASH("AllocPUDPSocket should not be called");
309 return nullptr;
312 bool BackgroundChildImpl::DeallocPUDPSocketChild(PUDPSocketChild* child) {
313 UDPSocketChild* p = static_cast<UDPSocketChild*>(child);
314 p->ReleaseIPDLReference();
315 return true;
318 // -----------------------------------------------------------------------------
319 // BroadcastChannel API
320 // -----------------------------------------------------------------------------
322 dom::PBroadcastChannelChild* BackgroundChildImpl::AllocPBroadcastChannelChild(
323 const PrincipalInfo& aPrincipalInfo, const nsACString& aOrigin,
324 const nsAString& aChannel) {
325 RefPtr<dom::BroadcastChannelChild> agent = new dom::BroadcastChannelChild();
326 return agent.forget().take();
329 bool BackgroundChildImpl::DeallocPBroadcastChannelChild(
330 PBroadcastChannelChild* aActor) {
331 RefPtr<dom::BroadcastChannelChild> child =
332 dont_AddRef(static_cast<dom::BroadcastChannelChild*>(aActor));
333 MOZ_ASSERT(child);
334 return true;
337 camera::PCamerasChild* BackgroundChildImpl::AllocPCamerasChild() {
338 #ifdef MOZ_WEBRTC
339 RefPtr<camera::CamerasChild> agent = new camera::CamerasChild();
340 return agent.forget().take();
341 #else
342 return nullptr;
343 #endif
346 bool BackgroundChildImpl::DeallocPCamerasChild(camera::PCamerasChild* aActor) {
347 #ifdef MOZ_WEBRTC
348 RefPtr<camera::CamerasChild> child =
349 dont_AddRef(static_cast<camera::CamerasChild*>(aActor));
350 MOZ_ASSERT(aActor);
351 camera::Shutdown();
352 #endif
353 return true;
356 // -----------------------------------------------------------------------------
357 // ServiceWorkerManager
358 // -----------------------------------------------------------------------------
360 dom::PServiceWorkerManagerChild*
361 BackgroundChildImpl::AllocPServiceWorkerManagerChild() {
362 RefPtr<dom::ServiceWorkerManagerChild> agent =
363 new dom::ServiceWorkerManagerChild();
364 return agent.forget().take();
367 bool BackgroundChildImpl::DeallocPServiceWorkerManagerChild(
368 PServiceWorkerManagerChild* aActor) {
369 RefPtr<dom::ServiceWorkerManagerChild> child =
370 dont_AddRef(static_cast<dom::ServiceWorkerManagerChild*>(aActor));
371 MOZ_ASSERT(child);
372 return true;
375 // -----------------------------------------------------------------------------
376 // Cache API
377 // -----------------------------------------------------------------------------
379 already_AddRefed<PCacheChild> BackgroundChildImpl::AllocPCacheChild() {
380 return dom::cache::AllocPCacheChild();
383 already_AddRefed<PCacheStreamControlChild>
384 BackgroundChildImpl::AllocPCacheStreamControlChild() {
385 return dom::cache::AllocPCacheStreamControlChild();
388 // -----------------------------------------------------------------------------
389 // MessageChannel/MessagePort API
390 // -----------------------------------------------------------------------------
392 dom::PMessagePortChild* BackgroundChildImpl::AllocPMessagePortChild(
393 const nsID& aUUID, const nsID& aDestinationUUID,
394 const uint32_t& aSequenceID) {
395 RefPtr<dom::MessagePortChild> agent = new dom::MessagePortChild();
396 return agent.forget().take();
399 bool BackgroundChildImpl::DeallocPMessagePortChild(PMessagePortChild* aActor) {
400 RefPtr<dom::MessagePortChild> child =
401 dont_AddRef(static_cast<dom::MessagePortChild*>(aActor));
402 MOZ_ASSERT(child);
403 return true;
406 dom::PWebAuthnTransactionChild*
407 BackgroundChildImpl::AllocPWebAuthnTransactionChild() {
408 MOZ_CRASH("PWebAuthnTransaction actor should be manually constructed!");
409 return nullptr;
412 bool BackgroundChildImpl::DeallocPWebAuthnTransactionChild(
413 PWebAuthnTransactionChild* aActor) {
414 MOZ_ASSERT(aActor);
415 RefPtr<dom::WebAuthnTransactionChild> child =
416 dont_AddRef(static_cast<dom::WebAuthnTransactionChild*>(aActor));
417 return true;
420 already_AddRefed<PServiceWorkerChild>
421 BackgroundChildImpl::AllocPServiceWorkerChild(
422 const IPCServiceWorkerDescriptor&) {
423 MOZ_CRASH("Shouldn't be called.");
424 return {};
427 already_AddRefed<PServiceWorkerContainerChild>
428 BackgroundChildImpl::AllocPServiceWorkerContainerChild() {
429 return mozilla::dom::ServiceWorkerContainerChild::Create();
432 already_AddRefed<PServiceWorkerRegistrationChild>
433 BackgroundChildImpl::AllocPServiceWorkerRegistrationChild(
434 const IPCServiceWorkerRegistrationDescriptor&) {
435 MOZ_CRASH("Shouldn't be called.");
436 return {};
439 dom::PEndpointForReportChild* BackgroundChildImpl::AllocPEndpointForReportChild(
440 const nsAString& aGroupName, const PrincipalInfo& aPrincipalInfo) {
441 return new dom::EndpointForReportChild();
444 bool BackgroundChildImpl::DeallocPEndpointForReportChild(
445 PEndpointForReportChild* aActor) {
446 MOZ_ASSERT(aActor);
447 delete static_cast<dom::EndpointForReportChild*>(aActor);
448 return true;
451 } // namespace mozilla::ipc
453 mozilla::ipc::IPCResult TestChild::Recv__delete__(const nsACString& aTestArg) {
454 MOZ_RELEASE_ASSERT(aTestArg == mTestArg,
455 "BackgroundTest message was corrupted!");
457 return IPC_OK();