2013-11-27 07:59:41 +00:00
|
|
|
/* 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"
|
|
|
|
|
2014-10-16 04:56:52 +00:00
|
|
|
#include "ActorsChild.h" // IndexedDB
|
2015-01-15 16:58:40 +00:00
|
|
|
#include "BroadcastChannelChild.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "FileDescriptorSetChild.h"
|
2014-11-20 19:48:18 +00:00
|
|
|
#include "mozilla/Assertions.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/dom/PBlobChild.h"
|
2015-03-02 13:20:00 +00:00
|
|
|
#include "mozilla/dom/cache/ActorUtils.h"
|
2014-09-26 23:21:57 +00:00
|
|
|
#include "mozilla/dom/indexedDB/PBackgroundIDBFactoryChild.h"
|
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
2013-11-27 07:59:41 +00:00
|
|
|
#include "mozilla/ipc/PBackgroundTestChild.h"
|
2015-01-13 23:37:00 +00:00
|
|
|
#include "mozilla/layout/VsyncChild.h"
|
2014-10-16 04:56:52 +00:00
|
|
|
#include "nsID.h"
|
2013-11-27 07:59:41 +00:00
|
|
|
#include "nsTraceRefcnt.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class TestChild final : public mozilla::ipc::PBackgroundTestChild
|
2013-11-27 07:59:41 +00:00
|
|
|
{
|
|
|
|
friend class mozilla::ipc::BackgroundChildImpl;
|
|
|
|
|
|
|
|
nsCString mTestArg;
|
|
|
|
|
2014-09-01 01:12:55 +00:00
|
|
|
explicit TestChild(const nsCString& aTestArg)
|
2014-09-26 23:21:57 +00:00
|
|
|
: mTestArg(aTestArg)
|
2013-11-27 07:59:41 +00:00
|
|
|
{
|
2014-07-15 15:37:45 +00:00
|
|
|
MOZ_COUNT_CTOR(TestChild);
|
2013-11-27 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:37:45 +00:00
|
|
|
protected:
|
2013-11-27 07:59:41 +00:00
|
|
|
~TestChild()
|
|
|
|
{
|
2014-07-15 15:37:45 +00:00
|
|
|
MOZ_COUNT_DTOR(TestChild);
|
2013-11-27 07:59:41 +00:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:37:45 +00:00
|
|
|
public:
|
2013-11-27 07:59:41 +00:00
|
|
|
virtual bool
|
2015-03-21 16:28:04 +00:00
|
|
|
Recv__delete__(const nsCString& aTestArg) override;
|
2013-11-27 07:59:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
2015-03-02 13:20:00 +00:00
|
|
|
using mozilla::dom::cache::PCacheChild;
|
|
|
|
using mozilla::dom::cache::PCacheStorageChild;
|
|
|
|
using mozilla::dom::cache::PCacheStreamControlChild;
|
|
|
|
|
2014-04-01 02:55:36 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 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
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
2013-11-27 07:59:41 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-11-20 19:48:18 +00:00
|
|
|
void
|
2015-02-03 17:09:27 +00:00
|
|
|
BackgroundChildImpl::ProcessingError(Result aCode, const char* aReason)
|
2014-11-20 19:48:18 +00:00
|
|
|
{
|
|
|
|
// May happen on any thread!
|
|
|
|
|
|
|
|
nsAutoCString abortMessage;
|
|
|
|
|
2015-02-03 17:09:27 +00:00
|
|
|
switch (aCode) {
|
2014-11-20 19:48:18 +00:00
|
|
|
|
|
|
|
#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();
|
|
|
|
}
|
|
|
|
|
2013-11-27 07:59:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-09-26 23:21:57 +00:00
|
|
|
BackgroundChildImpl::PBackgroundIDBFactoryChild*
|
2014-10-16 04:56:52 +00:00
|
|
|
BackgroundChildImpl::AllocPBackgroundIDBFactoryChild(
|
|
|
|
const LoggingInfo& aLoggingInfo)
|
2014-09-26 23:21:57 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-13 23:37:00 +00:00
|
|
|
BackgroundChildImpl::PVsyncChild*
|
|
|
|
BackgroundChildImpl::AllocPVsyncChild()
|
|
|
|
{
|
2015-01-29 21:19:00 +00:00
|
|
|
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();
|
2015-01-13 23:37:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
BackgroundChildImpl::DeallocPVsyncChild(PVsyncChild* aActor)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
|
2015-01-29 21:19:00 +00:00
|
|
|
// This actor already has one ref-count. Please check AllocPVsyncChild().
|
|
|
|
nsRefPtr<mozilla::layout::VsyncChild> actor =
|
|
|
|
dont_AddRef(static_cast<mozilla::layout::VsyncChild*>(aActor));
|
2015-01-13 23:37:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-15 16:58:40 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// BroadcastChannel API
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
dom::PBroadcastChannelChild*
|
|
|
|
BackgroundChildImpl::AllocPBroadcastChannelChild(const PrincipalInfo& aPrincipalInfo,
|
|
|
|
const nsString& aOrigin,
|
|
|
|
const nsString& aChannel)
|
|
|
|
{
|
|
|
|
nsRefPtr<dom::BroadcastChannelChild> agent =
|
|
|
|
new dom::BroadcastChannelChild(aOrigin, aChannel);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-03-02 13:20:00 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2013-11-27 07:59:41 +00:00
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
bool
|
|
|
|
TestChild::Recv__delete__(const nsCString& aTestArg)
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aTestArg == mTestArg,
|
|
|
|
"BackgroundTest message was corrupted!");
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|