2014-06-11 09:44:06 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-06-11 09:44:06 +04: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 "nsIContentChild.h"
|
|
|
|
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/DOMTypes.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-06-11 09:44:06 +04:00
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
2015-09-10 23:50:58 +03:00
|
|
|
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
2016-09-21 13:27:26 +03:00
|
|
|
#include "mozilla/ipc/FileDescriptorSetChild.h"
|
2014-06-11 09:44:06 +04:00
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
2017-03-14 14:29:43 +03:00
|
|
|
#include "mozilla/ipc/IPCStreamAlloc.h"
|
|
|
|
#include "mozilla/ipc/IPCStreamDestination.h"
|
|
|
|
#include "mozilla/ipc/IPCStreamSource.h"
|
|
|
|
#include "mozilla/ipc/PChildToParentStreamChild.h"
|
|
|
|
#include "mozilla/ipc/PParentToChildStreamChild.h"
|
2017-03-29 11:40:38 +03:00
|
|
|
#include "mozilla/dom/ipc/MemoryStreamChild.h"
|
2014-06-11 09:44:06 +04:00
|
|
|
|
|
|
|
#include "nsPrintfCString.h"
|
2015-06-27 04:44:14 +03:00
|
|
|
#include "xpcpublic.h"
|
2014-06-11 09:44:06 +04:00
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
PJavaScriptChild*
|
|
|
|
nsIContentChild::AllocPJavaScriptChild()
|
|
|
|
{
|
2016-08-11 15:39:23 +03:00
|
|
|
return NewJavaScriptChild();
|
2014-06-11 09:44:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::DeallocPJavaScriptChild(PJavaScriptChild* aChild)
|
|
|
|
{
|
2015-01-27 00:32:18 +03:00
|
|
|
ReleaseJavaScriptChild(aChild);
|
2014-06-11 09:44:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBrowserChild*
|
2014-10-29 21:11:00 +03:00
|
|
|
nsIContentChild::AllocPBrowserChild(const TabId& aTabId,
|
|
|
|
const IPCTabContext& aContext,
|
2014-06-11 09:44:06 +04:00
|
|
|
const uint32_t& aChromeFlags,
|
2014-10-24 04:28:00 +04:00
|
|
|
const ContentParentId& aCpID,
|
2014-06-11 09:44:06 +04:00
|
|
|
const bool& aIsForBrowser)
|
|
|
|
{
|
|
|
|
// We'll happily accept any kind of IPCTabContext here; we don't need to
|
|
|
|
// check that it's of a certain type for security purposes, because we
|
|
|
|
// believe whatever the parent process tells us.
|
|
|
|
|
|
|
|
MaybeInvalidTabContext tc(aContext);
|
|
|
|
if (!tc.IsValid()) {
|
|
|
|
NS_ERROR(nsPrintfCString("Received an invalid TabContext from "
|
|
|
|
"the parent process. (%s) Crashing...",
|
|
|
|
tc.GetInvalidReason()).get());
|
|
|
|
MOZ_CRASH("Invalid TabContext received from the parent process.");
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<TabChild> child =
|
2014-10-29 21:11:00 +03:00
|
|
|
TabChild::Create(this, aTabId, tc.GetTabContext(), aChromeFlags);
|
2014-06-11 09:44:06 +04:00
|
|
|
|
|
|
|
// The ref here is released in DeallocPBrowserChild.
|
|
|
|
return child.forget().take();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::DeallocPBrowserChild(PBrowserChild* aIframe)
|
|
|
|
{
|
|
|
|
TabChild* child = static_cast<TabChild*>(aIframe);
|
|
|
|
NS_RELEASE(child);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-01 06:16:28 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
nsIContentChild::RecvPBrowserConstructor(PBrowserChild* aActor,
|
|
|
|
const TabId& aTabId,
|
|
|
|
const IPCTabContext& aContext,
|
|
|
|
const uint32_t& aChromeFlags,
|
|
|
|
const ContentParentId& aCpID,
|
|
|
|
const bool& aIsForBrowser)
|
|
|
|
{
|
|
|
|
// This runs after AllocPBrowserChild() returns and the IPC machinery for this
|
|
|
|
// PBrowserChild has been set up.
|
|
|
|
|
|
|
|
auto tabChild = static_cast<TabChild*>(static_cast<TabChild*>(aActor));
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(tabChild->Init()))) {
|
|
|
|
return IPC_FAIL(tabChild, "TabChild::Init failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->NotifyObservers(static_cast<nsITabChild*>(tabChild), "tab-child-created", nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-03-29 11:40:38 +03:00
|
|
|
PMemoryStreamChild*
|
|
|
|
nsIContentChild::AllocPMemoryStreamChild(const uint64_t& aSize)
|
|
|
|
{
|
|
|
|
return new MemoryStreamChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::DeallocPMemoryStreamChild(PMemoryStreamChild* aActor)
|
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:06 +04:00
|
|
|
PBlobChild*
|
|
|
|
nsIContentChild::AllocPBlobChild(const BlobConstructorParams& aParams)
|
|
|
|
{
|
|
|
|
return BlobChild::Create(this, aParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::DeallocPBlobChild(PBlobChild* aActor)
|
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
BlobChild::Destroy(aActor);
|
2014-06-11 09:44:06 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlobChild*
|
2015-05-12 15:09:51 +03:00
|
|
|
nsIContentChild::GetOrCreateActorForBlob(Blob* aBlob)
|
2014-06-11 09:44:06 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aBlob);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BlobImpl> blobImpl = aBlob->Impl();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(blobImpl);
|
2014-06-11 09:44:06 +04:00
|
|
|
|
2015-05-12 15:11:03 +03:00
|
|
|
return GetOrCreateActorForBlobImpl(blobImpl);
|
2015-05-12 15:09:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BlobChild*
|
2015-05-12 15:11:03 +03:00
|
|
|
nsIContentChild::GetOrCreateActorForBlobImpl(BlobImpl* aImpl)
|
2015-05-12 15:09:51 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aImpl);
|
|
|
|
|
|
|
|
BlobChild* actor = BlobChild::GetOrCreate(this, aImpl);
|
2014-06-11 09:44:06 +04:00
|
|
|
NS_ENSURE_TRUE(actor, nullptr);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return actor;
|
2014-06-11 09:44:06 +04:00
|
|
|
}
|
|
|
|
|
2017-03-14 14:28:58 +03:00
|
|
|
PChildToParentStreamChild*
|
|
|
|
nsIContentChild::AllocPChildToParentStreamChild()
|
2016-09-21 13:27:26 +03:00
|
|
|
{
|
2017-03-14 14:28:58 +03:00
|
|
|
MOZ_CRASH("PChildToParentStreamChild actors should be manually constructed!");
|
2016-09-21 13:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-03-14 14:28:58 +03:00
|
|
|
nsIContentChild::DeallocPChildToParentStreamChild(PChildToParentStreamChild* aActor)
|
2016-09-21 13:27:26 +03:00
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-14 14:29:43 +03:00
|
|
|
PParentToChildStreamChild*
|
|
|
|
nsIContentChild::AllocPParentToChildStreamChild()
|
|
|
|
{
|
|
|
|
return mozilla::ipc::AllocPParentToChildStreamChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::DeallocPParentToChildStreamChild(PParentToChildStreamChild* aActor)
|
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-09-21 13:27:26 +03:00
|
|
|
PFileDescriptorSetChild*
|
|
|
|
nsIContentChild::AllocPFileDescriptorSetChild(const FileDescriptor& aFD)
|
|
|
|
{
|
|
|
|
return new FileDescriptorSetChild(aFD);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::DeallocPFileDescriptorSetChild(PFileDescriptorSetChild* aActor)
|
|
|
|
{
|
|
|
|
delete static_cast<FileDescriptorSetChild*>(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-06-11 09:44:06 +04:00
|
|
|
nsIContentChild::RecvAsyncMessage(const nsString& aMsg,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<CpowEntry>&& aCpows,
|
2016-04-09 16:50:59 +03:00
|
|
|
const IPC::Principal& aPrincipal,
|
|
|
|
const ClonedMessageData& aData)
|
2014-06-11 09:44:06 +04:00
|
|
|
{
|
2017-01-17 22:00:38 +03:00
|
|
|
CrossProcessCpowHolder cpows(this, aCpows);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> cpm = nsFrameMessageManager::GetChildProcessManager();
|
2014-06-11 09:44:06 +04:00
|
|
|
if (cpm) {
|
2015-09-10 23:50:58 +03:00
|
|
|
ipc::StructuredCloneData data;
|
|
|
|
ipc::UnpackClonedMessageDataForChild(aData, data);
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2015-04-16 18:17:54 +03:00
|
|
|
cpm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(cpm.get()), nullptr,
|
2015-09-10 23:50:58 +03:00
|
|
|
aMsg, false, &data, &cpows, aPrincipal, nullptr);
|
2014-06-11 09:44:06 +04:00
|
|
|
}
|
2016-11-15 06:26:00 +03:00
|
|
|
return IPC_OK();
|
2014-06-11 09:44:06 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|