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"
|
2014-06-11 09:44:06 +04:00
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
|
|
|
|
|
|
|
#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()
|
|
|
|
{
|
2015-06-27 04:44:14 +03:00
|
|
|
return NewJavaScriptChild(xpc::GetJSRuntime());
|
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& aIsForApp,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
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
|
|
|
{
|
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-01-27 00:32:31 +03:00
|
|
|
CrossProcessCpowHolder cpows(this, aCpows);
|
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
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|