Files
palemoon27/ipc/glue/BackgroundChildImpl.cpp
T
roytam1 0c01ffebb4 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1197669 - Part1 - 1.Enable the testcase on B2G. 2. fix the mimetype check in testcase. r=jwwang (9bbae092f)
- Bug 1197669 - Part2 - 1. Ensure the EOS is sent to MediaCodec. 2. mEndOfStream should be protected by monitor. r=sotaro (62b8e66b7)
- bug 1193922 skip SetIsOnlyNodeForContext after shutdown r=padenot (df991d0af)
- Minor (1d695f7c4)
- Bug 1197051 - Don't try to decode ahead while seeking - r=jya (7d8d877ad)
- Bug 1197075: P1. Revert "Bug 1197051 - Don't try to decode ahead while seeking - r=jya". r=edwin (e837b12e3)
- Bug 1143575. Push all available frames to the compositor. r=cpearce (109e54ae8)
- partial of  Bug 1197075: P2. Revert "Bug 1171257 - Add force decode ahead to MediaFormatReader r=jya,bholley". r=edwin (5f4859e47)
- Minor (a841ca407)
- Bug 1199155. Part 2 - fix includes and forward declarations. r=roc. (ca523595a)
- Bug 1199155. Part 1 - move dom/media/DecodedStream.* to dom/media/mediasink/ and implement the interface of MediaSink. r=roc. (90b376a24)
- Bug 1199155. Part 3 - rename mDecodedStream to mStreamSink. r=roc. (1aae54328)
- Bug 1203374. Part 1 - extract the code of computing canplaythrough so it is reusable. r=jya. (acc5fc8c6)
- Bug 1203374. Part 2 - duplicate the implementation of MediaDecoder::CanPlayThrough so MDSM can call its own CanPlayThrough() on its own thread. r=jya. (a042541a8)
- Bug 1182928 - Disable dormant mode for EME videos in Firefox Beta and Release. r=sotaro (ea5964ae9)
- Bug 1197022 - [EME] Disable dormant mode for EME videos on all channels. r=kentuckyfriedtakahe (742d00672)
- Bug 1179110 - Fix ComputePlaybackRate. r=jww (a43272af5)
- Bug 1178622 - Fix enum-to-string mismatch in MediaDecoder.cpp. r=jya. (b9da7ebf3)
- Bug 1203418. Part 1 - cache the results of ComputePlaybackRate() so they can be mirrored by MDSM. r=cpearce. (95f7ac068)
- Bug 1203418. Part 2 - duplicate the implementation of MediaDecoder::GetStatistics so MDSM can call it on its own thread. r=cpearce. (2755b85a7)
- Bug 1203418. Part 3 - ensure MDSM::mPlaybackOffset and MediaDecoder::mPlaybackPosition are mono-increasing to avoid "jitter" in calculating playback statistics. r=cpearce. (54dcb6219)
- Bug 1104616 - Proxy video capture access to the main process. r=jesup,glandium,mrbkap (cfdd08459)
- Bug 1200614 - Protect the capture engines array from concurrent access (during shutdown). r=jesup (c4dbd6e10)
- Bug 1200614 - Check whether engines are still alive when webrtc ops run. r=jesup (d42d3474f)
- Bug 1194640 - add NSPR logging of camera capabilities, r=jesup (c7365b916)
- Bug 1204413 - Make MediaDecoder::IsTransportSeekable run on the main thread. r=kinetik. (098868b0d)
- Bug 1198202 - Increase hardware video decoding fallback threshold. r=ajones (1059f9b0f)
- Bug 1201197 - add dedicated listener to enumerateDevices. r=jesup (a51477957)
- Bug 1199562. Part 1 - rename mAudioSink to mMediaSink as well as related member names. r=roc. (c2db1b4d4)
- Bug 1199562. Part 2 - replace usage of mStreamSink with mMediaSink in most cases. r=roc. (7aa0754c4)
- Bug 1199562. Part 3 - remove unused code. r=roc. (343c5be2f)
- Bug 1203877 - Remove MediaDecoder::UpdatePlaybackOffset. r=kinetik. (4476dd1f8)
- Bug 1204430. Part 2 - mirror MediaDecoder::mMediaSeekable. r=kinetik. (51ca1197d)
- Bug 1206576 - Dispatch some MDSM functions to hide its internal thread model. r=jya. (74b9a169c)
- Bug 1206574 - Remove AbstractMediaDecoder::IsShutdown(). r=cpearce. (4ed17a27f)
- Bug 1207017. Part 1 - fix coding styles. r=kinetik. (cc10a28c3)
- Bug 1207017. Part 2 - remove duplicated GetStateMachine(). r=kinetik. (19b663098)
- Bug 1200477 - Allow building with WebRTC disabled. r=glandium,mrbkap (56055c3c7)
2021-10-14 09:25:28 +08:00

428 lines
11 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "BackgroundChildImpl.h"
#include "ActorsChild.h" // IndexedDB
#include "BroadcastChannelChild.h"
#include "ServiceWorkerManagerChild.h"
#include "FileDescriptorSetChild.h"
#ifdef MOZ_WEBRTC
#include "CamerasChild.h"
#endif
#include "mozilla/media/MediaChild.h"
#include "mozilla/Assertions.h"
#include "mozilla/dom/PBlobChild.h"
#include "mozilla/dom/asmjscache/AsmJSCache.h"
#include "mozilla/dom/cache/ActorUtils.h"
#include "mozilla/dom/indexedDB/PBackgroundIDBFactoryChild.h"
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/dom/MessagePortChild.h"
#include "mozilla/dom/NuwaChild.h"
#include "mozilla/ipc/PBackgroundTestChild.h"
#include "mozilla/layout/VsyncChild.h"
#include "mozilla/net/PUDPSocketChild.h"
#include "mozilla/dom/network/UDPSocketChild.h"
#include "nsID.h"
#include "nsTraceRefcnt.h"
namespace {
class TestChild final : public mozilla::ipc::PBackgroundTestChild
{
friend class mozilla::ipc::BackgroundChildImpl;
nsCString mTestArg;
explicit TestChild(const nsCString& aTestArg)
: mTestArg(aTestArg)
{
MOZ_COUNT_CTOR(TestChild);
}
protected:
~TestChild()
{
MOZ_COUNT_DTOR(TestChild);
}
public:
virtual bool
Recv__delete__(const nsCString& aTestArg) override;
};
} // namespace
namespace mozilla {
namespace ipc {
using mozilla::dom::UDPSocketChild;
using mozilla::net::PUDPSocketChild;
using mozilla::dom::asmjscache::PAsmJSCacheEntryChild;
using mozilla::dom::cache::PCacheChild;
using mozilla::dom::cache::PCacheStorageChild;
using mozilla::dom::cache::PCacheStreamControlChild;
using mozilla::dom::PNuwaChild;
// -----------------------------------------------------------------------------
// BackgroundChildImpl::ThreadLocal
// -----------------------------------------------------------------------------
BackgroundChildImpl::
ThreadLocal::ThreadLocal()
{
// May happen on any thread!
MOZ_COUNT_CTOR(mozilla::ipc::BackgroundChildImpl::ThreadLocal);
}
BackgroundChildImpl::
ThreadLocal::~ThreadLocal()
{
// May happen on any thread!
MOZ_COUNT_DTOR(mozilla::ipc::BackgroundChildImpl::ThreadLocal);
}
// -----------------------------------------------------------------------------
// BackgroundChildImpl
// -----------------------------------------------------------------------------
BackgroundChildImpl::BackgroundChildImpl()
{
// May happen on any thread!
MOZ_COUNT_CTOR(mozilla::ipc::BackgroundChildImpl);
}
BackgroundChildImpl::~BackgroundChildImpl()
{
// May happen on any thread!
MOZ_COUNT_DTOR(mozilla::ipc::BackgroundChildImpl);
}
void
BackgroundChildImpl::ProcessingError(Result aCode, const char* aReason)
{
// May happen on any thread!
nsAutoCString abortMessage;
switch (aCode) {
#define HANDLE_CASE(_result) \
case _result: \
abortMessage.AssignLiteral(#_result); \
break
HANDLE_CASE(MsgDropped);
HANDLE_CASE(MsgNotKnown);
HANDLE_CASE(MsgNotAllowed);
HANDLE_CASE(MsgPayloadError);
HANDLE_CASE(MsgProcessingError);
HANDLE_CASE(MsgRouteError);
HANDLE_CASE(MsgValueError);
#undef HANDLE_CASE
default:
MOZ_CRASH("Unknown error code!");
}
// This is just MOZ_CRASH() un-inlined so that we can pass the result code as
// a string. MOZ_CRASH() only supports string literals at the moment.
MOZ_ReportCrash(abortMessage.get(), __FILE__, __LINE__); MOZ_REALLY_CRASH();
}
void
BackgroundChildImpl::ActorDestroy(ActorDestroyReason aWhy)
{
// May happen on any thread!
}
PBackgroundTestChild*
BackgroundChildImpl::AllocPBackgroundTestChild(const nsCString& aTestArg)
{
return new TestChild(aTestArg);
}
bool
BackgroundChildImpl::DeallocPBackgroundTestChild(PBackgroundTestChild* aActor)
{
MOZ_ASSERT(aActor);
delete static_cast<TestChild*>(aActor);
return true;
}
BackgroundChildImpl::PBackgroundIDBFactoryChild*
BackgroundChildImpl::AllocPBackgroundIDBFactoryChild(
const LoggingInfo& aLoggingInfo)
{
MOZ_CRASH("PBackgroundIDBFactoryChild actors should be manually "
"constructed!");
}
bool
BackgroundChildImpl::DeallocPBackgroundIDBFactoryChild(
PBackgroundIDBFactoryChild* aActor)
{
MOZ_ASSERT(aActor);
delete aActor;
return true;
}
auto
BackgroundChildImpl::AllocPBlobChild(const BlobConstructorParams& aParams)
-> PBlobChild*
{
MOZ_ASSERT(aParams.type() != BlobConstructorParams::T__None);
return mozilla::dom::BlobChild::Create(this, aParams);
}
bool
BackgroundChildImpl::DeallocPBlobChild(PBlobChild* aActor)
{
MOZ_ASSERT(aActor);
mozilla::dom::BlobChild::Destroy(aActor);
return true;
}
PFileDescriptorSetChild*
BackgroundChildImpl::AllocPFileDescriptorSetChild(
const FileDescriptor& aFileDescriptor)
{
return new FileDescriptorSetChild(aFileDescriptor);
}
bool
BackgroundChildImpl::DeallocPFileDescriptorSetChild(
PFileDescriptorSetChild* aActor)
{
MOZ_ASSERT(aActor);
delete static_cast<FileDescriptorSetChild*>(aActor);
return true;
}
BackgroundChildImpl::PVsyncChild*
BackgroundChildImpl::AllocPVsyncChild()
{
nsRefPtr<mozilla::layout::VsyncChild> actor = new mozilla::layout::VsyncChild();
// There still has one ref-count after return, and it will be released in
// DeallocPVsyncChild().
return actor.forget().take();
}
bool
BackgroundChildImpl::DeallocPVsyncChild(PVsyncChild* aActor)
{
MOZ_ASSERT(aActor);
// This actor already has one ref-count. Please check AllocPVsyncChild().
nsRefPtr<mozilla::layout::VsyncChild> actor =
dont_AddRef(static_cast<mozilla::layout::VsyncChild*>(aActor));
return true;
}
PUDPSocketChild*
BackgroundChildImpl::AllocPUDPSocketChild(const OptionalPrincipalInfo& aPrincipalInfo,
const nsCString& aFilter)
{
MOZ_CRASH("AllocPUDPSocket should not be called");
return nullptr;
}
bool
BackgroundChildImpl::DeallocPUDPSocketChild(PUDPSocketChild* child)
{
UDPSocketChild* p = static_cast<UDPSocketChild*>(child);
p->ReleaseIPDLReference();
return true;
}
// -----------------------------------------------------------------------------
// BroadcastChannel API
// -----------------------------------------------------------------------------
dom::PBroadcastChannelChild*
BackgroundChildImpl::AllocPBroadcastChannelChild(const PrincipalInfo& aPrincipalInfo,
const nsCString& aOrigin,
const nsString& aChannel,
const bool& aPrivateBrowsing)
{
nsRefPtr<dom::BroadcastChannelChild> agent =
new dom::BroadcastChannelChild(aOrigin);
return agent.forget().take();
}
bool
BackgroundChildImpl::DeallocPBroadcastChannelChild(
PBroadcastChannelChild* aActor)
{
nsRefPtr<dom::BroadcastChannelChild> child =
dont_AddRef(static_cast<dom::BroadcastChannelChild*>(aActor));
MOZ_ASSERT(child);
return true;
}
camera::PCamerasChild*
BackgroundChildImpl::AllocPCamerasChild()
{
#ifdef MOZ_WEBRTC
nsRefPtr<camera::CamerasChild> agent =
new camera::CamerasChild();
return agent.forget().take();
#else
return nullptr;
#endif
}
bool
BackgroundChildImpl::DeallocPCamerasChild(camera::PCamerasChild *aActor)
{
#ifdef MOZ_WEBRTC
nsRefPtr<camera::CamerasChild> child =
dont_AddRef(static_cast<camera::CamerasChild*>(aActor));
MOZ_ASSERT(aActor);
#endif
return true;
}
// -----------------------------------------------------------------------------
// ServiceWorkerManager
// -----------------------------------------------------------------------------
dom::PServiceWorkerManagerChild*
BackgroundChildImpl::AllocPServiceWorkerManagerChild()
{
nsRefPtr<dom::workers::ServiceWorkerManagerChild> agent =
new dom::workers::ServiceWorkerManagerChild();
return agent.forget().take();
}
bool
BackgroundChildImpl::DeallocPServiceWorkerManagerChild(
PServiceWorkerManagerChild* aActor)
{
nsRefPtr<dom::workers::ServiceWorkerManagerChild> child =
dont_AddRef(static_cast<dom::workers::ServiceWorkerManagerChild*>(aActor));
MOZ_ASSERT(child);
return true;
}
// -----------------------------------------------------------------------------
// Cache API
// -----------------------------------------------------------------------------
PCacheStorageChild*
BackgroundChildImpl::AllocPCacheStorageChild(const Namespace& aNamespace,
const PrincipalInfo& aPrincipalInfo)
{
MOZ_CRASH("CacheStorageChild actor must be provided to PBackground manager");
return nullptr;
}
bool
BackgroundChildImpl::DeallocPCacheStorageChild(PCacheStorageChild* aActor)
{
dom::cache::DeallocPCacheStorageChild(aActor);
return true;
}
PCacheChild*
BackgroundChildImpl::AllocPCacheChild()
{
return dom::cache::AllocPCacheChild();
}
bool
BackgroundChildImpl::DeallocPCacheChild(PCacheChild* aActor)
{
dom::cache::DeallocPCacheChild(aActor);
return true;
}
PCacheStreamControlChild*
BackgroundChildImpl::AllocPCacheStreamControlChild()
{
return dom::cache::AllocPCacheStreamControlChild();
}
bool
BackgroundChildImpl::DeallocPCacheStreamControlChild(PCacheStreamControlChild* aActor)
{
dom::cache::DeallocPCacheStreamControlChild(aActor);
return true;
}
// -----------------------------------------------------------------------------
// MessageChannel/MessagePort API
// -----------------------------------------------------------------------------
dom::PMessagePortChild*
BackgroundChildImpl::AllocPMessagePortChild(const nsID& aUUID,
const nsID& aDestinationUUID,
const uint32_t& aSequenceID)
{
nsRefPtr<dom::MessagePortChild> agent = new dom::MessagePortChild();
return agent.forget().take();
}
bool
BackgroundChildImpl::DeallocPMessagePortChild(PMessagePortChild* aActor)
{
nsRefPtr<dom::MessagePortChild> child =
dont_AddRef(static_cast<dom::MessagePortChild*>(aActor));
MOZ_ASSERT(child);
return true;
}
PNuwaChild*
BackgroundChildImpl::AllocPNuwaChild()
{
return new mozilla::dom::NuwaChild();
}
bool
BackgroundChildImpl::DeallocPNuwaChild(PNuwaChild* aActor)
{
MOZ_ASSERT(aActor);
delete aActor;
return true;
}
PAsmJSCacheEntryChild*
BackgroundChildImpl::AllocPAsmJSCacheEntryChild(
const dom::asmjscache::OpenMode& aOpenMode,
const dom::asmjscache::WriteParams& aWriteParams,
const PrincipalInfo& aPrincipalInfo)
{
MOZ_CRASH("PAsmJSCacheEntryChild actors should be manually constructed!");
}
bool
BackgroundChildImpl::DeallocPAsmJSCacheEntryChild(PAsmJSCacheEntryChild* aActor)
{
MOZ_ASSERT(aActor);
dom::asmjscache::DeallocEntryChild(aActor);
return true;
}
} // namespace ipc
} // namespace mozilla
bool
TestChild::Recv__delete__(const nsCString& aTestArg)
{
MOZ_RELEASE_ASSERT(aTestArg == mTestArg,
"BackgroundTest message was corrupted!");
return true;
}