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/StructuredCloneUtils.h"
|
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
2014-06-11 09:44:06 +04:00
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
|
|
|
|
|
|
|
#include "nsIJSRuntimeService.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
PJavaScriptChild*
|
|
|
|
nsIContentChild::AllocPJavaScriptChild()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIJSRuntimeService> svc = do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
|
|
|
|
NS_ENSURE_TRUE(svc, nullptr);
|
|
|
|
|
|
|
|
JSRuntime *rt;
|
|
|
|
svc->GetRuntime(&rt);
|
|
|
|
NS_ENSURE_TRUE(svc, nullptr);
|
|
|
|
|
2015-01-27 00:32:18 +03:00
|
|
|
return NewJavaScriptChild(rt);
|
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.");
|
|
|
|
}
|
|
|
|
|
2014-09-09 12:57:54 +04:00
|
|
|
nsRefPtr<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-05-12 15:11:03 +03:00
|
|
|
nsRefPtr<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,
|
|
|
|
const ClonedMessageData& aData,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<CpowEntry>&& aCpows,
|
2014-06-11 09:44:06 +04:00
|
|
|
const IPC::Principal& aPrincipal)
|
|
|
|
{
|
2015-02-20 04:12:38 +03:00
|
|
|
nsRefPtr<nsFrameMessageManager> cpm = nsFrameMessageManager::GetChildProcessManager();
|
2014-06-11 09:44:06 +04:00
|
|
|
if (cpm) {
|
|
|
|
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForChild(aData);
|
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,
|
2014-06-11 09:44:06 +04:00
|
|
|
aMsg, false, &cloneData, &cpows, aPrincipal, nullptr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // dom
|
|
|
|
} // mozilla
|