2014-06-11 09:44:03 +04: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 "nsIContentParent.h"
|
|
|
|
|
|
|
|
#include "mozilla/AppProcessChecker.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-06-11 09:44:03 +04:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
|
|
|
#include "mozilla/dom/PTabContext.h"
|
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
|
|
|
#include "mozilla/dom/StructuredCloneUtils.h"
|
|
|
|
#include "mozilla/dom/TabParent.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/ipc/BlobParent.h"
|
2015-01-27 00:32:18 +03:00
|
|
|
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
|
2014-06-11 09:44:03 +04:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
|
|
|
|
#include "nsFrameMessageManager.h"
|
|
|
|
#include "nsIJSRuntimeService.h"
|
|
|
|
#include "nsPrintfCString.h"
|
|
|
|
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
2014-10-29 21:11:00 +03:00
|
|
|
// XXX need another bug to move this to a common header.
|
|
|
|
#ifdef DISABLE_ASSERTS_FOR_FUZZING
|
2015-02-07 02:05:08 +03:00
|
|
|
#define ASSERT_UNLESS_FUZZING(...) do { } while (0)
|
2014-10-29 21:11:00 +03:00
|
|
|
#else
|
2015-02-07 02:05:08 +03:00
|
|
|
#define ASSERT_UNLESS_FUZZING(...) MOZ_ASSERT(false, __VA_ARGS__)
|
2014-10-29 21:11:00 +03:00
|
|
|
#endif
|
|
|
|
|
2014-06-11 09:44:03 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
nsIContentParent::nsIContentParent()
|
|
|
|
{
|
|
|
|
mMessageManager = nsFrameMessageManager::NewProcessMessageManager(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ContentParent*
|
|
|
|
nsIContentParent::AsContentParent()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsContentParent());
|
|
|
|
return static_cast<ContentParent*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
PJavaScriptParent*
|
|
|
|
nsIContentParent::AllocPJavaScriptParent()
|
|
|
|
{
|
|
|
|
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 NewJavaScriptParent(rt);
|
2014-06-11 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentParent::DeallocPJavaScriptParent(PJavaScriptParent* aParent)
|
|
|
|
{
|
2015-01-27 00:32:18 +03:00
|
|
|
ReleaseJavaScriptParent(aParent);
|
2014-06-11 09:44:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
bool
|
|
|
|
nsIContentParent::CanOpenBrowser(const IPCTabContext& aContext)
|
2014-06-11 09:44:03 +04:00
|
|
|
{
|
|
|
|
const IPCTabAppBrowserContext& appBrowser = aContext.appBrowserContext();
|
|
|
|
|
|
|
|
// We don't trust the IPCTabContext we receive from the child, so we'll bail
|
|
|
|
// if we receive an IPCTabContext that's not a PopupIPCTabContext.
|
|
|
|
// (PopupIPCTabContext lets the child process prove that it has access to
|
|
|
|
// the app it's trying to open.)
|
|
|
|
if (appBrowser.type() != IPCTabAppBrowserContext::TPopupIPCTabContext) {
|
2015-02-07 02:05:08 +03:00
|
|
|
ASSERT_UNLESS_FUZZING("Unexpected IPCTabContext type. Aborting AllocPBrowserParent.");
|
2014-06-11 09:44:13 +04:00
|
|
|
return false;
|
2014-06-11 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const PopupIPCTabContext& popupContext = appBrowser.get_PopupIPCTabContext();
|
2014-10-29 21:11:00 +03:00
|
|
|
if (popupContext.opener().type() != PBrowserOrId::TPBrowserParent) {
|
2015-02-07 02:05:08 +03:00
|
|
|
ASSERT_UNLESS_FUZZING("Unexpected PopupIPCTabContext type. Aborting AllocPBrowserParent.");
|
2014-10-29 21:11:00 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-06 00:47:32 +03:00
|
|
|
auto opener = TabParent::GetFrom(popupContext.opener().get_PBrowserParent());
|
2014-06-11 09:44:03 +04:00
|
|
|
if (!opener) {
|
2015-02-07 02:05:08 +03:00
|
|
|
ASSERT_UNLESS_FUZZING("Got null opener from child; aborting AllocPBrowserParent.");
|
2014-06-11 09:44:13 +04:00
|
|
|
return false;
|
2014-06-11 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Popup windows of isBrowser frames must be isBrowser if the parent
|
|
|
|
// isBrowser. Allocating a !isBrowser frame with same app ID would allow
|
|
|
|
// the content to access data it's not supposed to.
|
|
|
|
if (!popupContext.isBrowserElement() && opener->IsBrowserElement()) {
|
2015-02-07 02:05:08 +03:00
|
|
|
ASSERT_UNLESS_FUZZING("Child trying to escalate privileges! Aborting AllocPBrowserParent.");
|
2014-06-11 09:44:13 +04:00
|
|
|
return false;
|
2014-06-11 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
MaybeInvalidTabContext tc(aContext);
|
|
|
|
if (!tc.IsValid()) {
|
|
|
|
NS_ERROR(nsPrintfCString("Child passed us an invalid TabContext. (%s) "
|
|
|
|
"Aborting AllocPBrowserParent.",
|
|
|
|
tc.GetInvalidReason()).get());
|
2014-06-11 09:44:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBrowserParent*
|
2014-10-29 21:11:00 +03:00
|
|
|
nsIContentParent::AllocPBrowserParent(const TabId& aTabId,
|
|
|
|
const IPCTabContext& aContext,
|
2014-06-11 09:44:13 +04:00
|
|
|
const uint32_t& aChromeFlags,
|
2014-10-24 04:28:00 +04:00
|
|
|
const ContentParentId& aCpId,
|
2014-06-11 09:44:13 +04:00
|
|
|
const bool& aIsForApp,
|
|
|
|
const bool& aIsForBrowser)
|
|
|
|
{
|
2014-10-24 04:28:00 +04:00
|
|
|
unused << aCpId;
|
2014-06-11 09:44:13 +04:00
|
|
|
unused << aIsForApp;
|
|
|
|
unused << aIsForBrowser;
|
|
|
|
|
|
|
|
if (!CanOpenBrowser(aContext)) {
|
2014-06-11 09:44:03 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
MaybeInvalidTabContext tc(aContext);
|
|
|
|
MOZ_ASSERT(tc.IsValid());
|
2014-10-29 21:11:00 +03:00
|
|
|
TabParent* parent = new TabParent(this, aTabId, tc.GetTabContext(), aChromeFlags);
|
2014-06-11 09:44:03 +04:00
|
|
|
|
|
|
|
// We release this ref in DeallocPBrowserParent()
|
|
|
|
NS_ADDREF(parent);
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentParent::DeallocPBrowserParent(PBrowserParent* aFrame)
|
|
|
|
{
|
2015-02-06 00:47:32 +03:00
|
|
|
TabParent* parent = TabParent::GetFrom(aFrame);
|
2014-06-11 09:44:03 +04:00
|
|
|
NS_RELEASE(parent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
PBlobParent*
|
|
|
|
nsIContentParent::AllocPBlobParent(const BlobConstructorParams& aParams)
|
|
|
|
{
|
|
|
|
return BlobParent::Create(this, aParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentParent::DeallocPBlobParent(PBlobParent* aActor)
|
|
|
|
{
|
2014-09-27 03:21:57 +04:00
|
|
|
BlobParent::Destroy(aActor);
|
2014-06-11 09:44:03 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlobParent*
|
2014-10-08 20:15:23 +04:00
|
|
|
nsIContentParent::GetOrCreateActorForBlob(File* aBlob)
|
2014-06-11 09:44:03 +04:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aBlob);
|
|
|
|
|
2014-10-08 20:15:23 +04:00
|
|
|
nsRefPtr<FileImpl> blobImpl = aBlob->Impl();
|
2014-09-27 03:21:57 +04:00
|
|
|
MOZ_ASSERT(blobImpl);
|
2014-06-11 09:44:03 +04:00
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
BlobParent* actor = BlobParent::GetOrCreate(this, blobImpl);
|
2014-06-11 09:44:03 +04:00
|
|
|
NS_ENSURE_TRUE(actor, nullptr);
|
|
|
|
|
2014-09-27 03:21:57 +04:00
|
|
|
return actor;
|
2014-06-11 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentParent::RecvSyncMessage(const nsString& aMsg,
|
|
|
|
const ClonedMessageData& aData,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<CpowEntry>&& aCpows,
|
2014-06-11 09:44:03 +04:00
|
|
|
const IPC::Principal& aPrincipal,
|
|
|
|
InfallibleTArray<nsString>* aRetvals)
|
|
|
|
{
|
|
|
|
// FIXME Permission check in Content process
|
|
|
|
nsIPrincipal* principal = aPrincipal;
|
2014-06-14 11:32:24 +04:00
|
|
|
if (IsContentParent()) {
|
|
|
|
ContentParent* parent = AsContentParent();
|
|
|
|
if (!ContentParent::IgnoreIPCPrincipal() &&
|
|
|
|
parent && principal && !AssertAppPrincipal(parent, principal)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-11 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
|
|
|
if (ppm) {
|
|
|
|
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
|
2015-01-27 00:32:31 +03:00
|
|
|
CrossProcessCpowHolder cpows(this, aCpows);
|
2014-06-11 09:44:03 +04:00
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
|
|
|
|
aMsg, true, &cloneData, &cpows, aPrincipal, aRetvals);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-10-08 08:32:45 +04:00
|
|
|
nsIContentParent::RecvRpcMessage(const nsString& aMsg,
|
|
|
|
const ClonedMessageData& aData,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<CpowEntry>&& aCpows,
|
2014-10-08 08:32:45 +04:00
|
|
|
const IPC::Principal& aPrincipal,
|
|
|
|
InfallibleTArray<nsString>* aRetvals)
|
2014-06-11 09:44:03 +04:00
|
|
|
{
|
|
|
|
// FIXME Permission check in Content process
|
|
|
|
nsIPrincipal* principal = aPrincipal;
|
2014-06-14 11:32:24 +04:00
|
|
|
if (IsContentParent()) {
|
|
|
|
ContentParent* parent = AsContentParent();
|
|
|
|
if (!ContentParent::IgnoreIPCPrincipal() &&
|
|
|
|
parent && principal && !AssertAppPrincipal(parent, principal)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-11 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
|
|
|
if (ppm) {
|
|
|
|
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
|
2015-01-27 00:32:31 +03:00
|
|
|
CrossProcessCpowHolder cpows(this, aCpows);
|
2014-06-11 09:44:03 +04:00
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
|
|
|
|
aMsg, true, &cloneData, &cpows, aPrincipal, aRetvals);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentParent::RecvAsyncMessage(const nsString& aMsg,
|
|
|
|
const ClonedMessageData& aData,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<CpowEntry>&& aCpows,
|
2014-06-11 09:44:03 +04:00
|
|
|
const IPC::Principal& aPrincipal)
|
|
|
|
{
|
|
|
|
// FIXME Permission check in Content process
|
|
|
|
nsIPrincipal* principal = aPrincipal;
|
2014-06-14 11:32:24 +04:00
|
|
|
if (IsContentParent()) {
|
|
|
|
ContentParent* parent = AsContentParent();
|
|
|
|
if (!ContentParent::IgnoreIPCPrincipal() &&
|
|
|
|
parent && principal && !AssertAppPrincipal(parent, principal)) {
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-11 09:44:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
|
|
|
if (ppm) {
|
|
|
|
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
|
2015-01-27 00:32:31 +03:00
|
|
|
CrossProcessCpowHolder cpows(this, aCpows);
|
2014-06-11 09:44:03 +04:00
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
|
|
|
|
aMsg, false, &cloneData, &cpows, aPrincipal, nullptr);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|