2014-06-10 22:44:06 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* 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-26 16:21:57 -07:00
|
|
|
#include "mozilla/dom/DOMTypes.h"
|
2014-10-08 09:15:23 -07:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-06-10 22:44:06 -07:00
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
|
|
|
#include "mozilla/dom/StructuredCloneUtils.h"
|
|
|
|
#include "mozilla/dom/TabChild.h"
|
2014-09-26 16:21:57 -07:00
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
2014-06-10 22:44:06 -07:00
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
|
|
|
|
|
|
|
#include "JavaScriptChild.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);
|
|
|
|
|
|
|
|
nsAutoPtr<JavaScriptChild> child(new JavaScriptChild(rt));
|
|
|
|
if (!child->init()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return child.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::DeallocPJavaScriptChild(PJavaScriptChild* aChild)
|
|
|
|
{
|
|
|
|
static_cast<JavaScriptChild*>(aChild)->decref();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBrowserChild*
|
2014-10-29 11:11:00 -07:00
|
|
|
nsIContentChild::AllocPBrowserChild(const TabId& aTabId,
|
|
|
|
const IPCTabContext& aContext,
|
2014-06-10 22:44:06 -07:00
|
|
|
const uint32_t& aChromeFlags,
|
2014-10-23 17:28:00 -07:00
|
|
|
const ContentParentId& aCpID,
|
2014-06-10 22:44:06 -07: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 01:57:54 -07:00
|
|
|
nsRefPtr<TabChild> child =
|
2014-10-29 11:11:00 -07:00
|
|
|
TabChild::Create(this, aTabId, tc.GetTabContext(), aChromeFlags);
|
2014-06-10 22:44:06 -07: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-26 16:21:57 -07:00
|
|
|
BlobChild::Destroy(aActor);
|
2014-06-10 22:44:06 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlobChild*
|
2014-10-08 09:15:23 -07:00
|
|
|
nsIContentChild::GetOrCreateActorForBlob(File* aBlob)
|
2014-06-10 22:44:06 -07:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aBlob);
|
|
|
|
|
2014-10-08 09:15:23 -07:00
|
|
|
nsRefPtr<FileImpl> blobImpl = aBlob->Impl();
|
2014-09-26 16:21:57 -07:00
|
|
|
MOZ_ASSERT(blobImpl);
|
2014-06-10 22:44:06 -07:00
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
BlobChild* actor = BlobChild::GetOrCreate(this, blobImpl);
|
2014-06-10 22:44:06 -07:00
|
|
|
NS_ENSURE_TRUE(actor, nullptr);
|
|
|
|
|
2014-09-26 16:21:57 -07:00
|
|
|
return actor;
|
2014-06-10 22:44:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::RecvAsyncMessage(const nsString& aMsg,
|
|
|
|
const ClonedMessageData& aData,
|
|
|
|
const InfallibleTArray<CpowEntry>& aCpows,
|
|
|
|
const IPC::Principal& aPrincipal)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsFrameMessageManager> cpm = nsFrameMessageManager::sChildProcessManager;
|
|
|
|
if (cpm) {
|
|
|
|
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForChild(aData);
|
2014-10-06 15:45:42 -07:00
|
|
|
CpowIdHolder cpows(this, aCpows);
|
2014-06-10 22:44:06 -07:00
|
|
|
cpm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(cpm.get()),
|
|
|
|
aMsg, false, &cloneData, &cpows, aPrincipal, nullptr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // dom
|
|
|
|
} // mozilla
|