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"
|
2017-05-02 12:57:51 +03:00
|
|
|
#include "mozilla/dom/TabGroup.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"
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
#include "mozilla/dom/ipc/IPCBlobInputStreamChild.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,
|
2017-04-07 02:46:18 +03:00
|
|
|
const TabId& aSameTabGroupAs,
|
2014-10-29 21:11:00 +03:00
|
|
|
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 =
|
2017-04-07 02:46:18 +03:00
|
|
|
TabChild::Create(this, aTabId, aSameTabGroupAs,
|
|
|
|
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,
|
2017-04-07 02:46:18 +03:00
|
|
|
const TabId& aSameTabGroupAs,
|
2016-12-01 06:16:28 +03:00
|
|
|
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);
|
|
|
|
}
|
2017-03-21 10:44:12 +03:00
|
|
|
// Notify parent that we are ready to handle input events.
|
|
|
|
tabChild->SendRemoteIsReadyToHandleInputEvents();
|
2016-12-01 06:16:28 +03:00
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
PIPCBlobInputStreamChild*
|
|
|
|
nsIContentChild::AllocPIPCBlobInputStreamChild(const nsID& aID,
|
|
|
|
const uint64_t& aSize)
|
|
|
|
{
|
|
|
|
// IPCBlobInputStreamChild is refcounted. Here it's created and in
|
|
|
|
// DeallocPIPCBlobInputStreamChild is released.
|
|
|
|
|
|
|
|
RefPtr<IPCBlobInputStreamChild> actor =
|
|
|
|
new IPCBlobInputStreamChild(aID, aSize);
|
|
|
|
return actor.forget().take();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsIContentChild::DeallocPIPCBlobInputStreamChild(PIPCBlobInputStreamChild* aActor)
|
|
|
|
{
|
|
|
|
RefPtr<IPCBlobInputStreamChild> actor =
|
|
|
|
dont_AddRef(static_cast<IPCBlobInputStreamChild*>(aActor));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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-03-30 00:43:21 +03:00
|
|
|
NS_LossyConvertUTF16toASCII messageNameCStr(aMsg);
|
Bug 1375392 - Tweak the PROFILER_LABEL* macros. r=mstange.
This patch makes the following changes to the macros.
- Removes PROFILER_LABEL_FUNC. It's only suitable for use in functions outside
classes, due to PROFILER_FUNCTION_NAME not getting class names, and it was
mostly misused.
- Removes PROFILER_FUNCTION_NAME. It's no longer used, and __func__ is
universally available now anyway.
- Combines the first two string literal arguments of PROFILER_LABEL and
PROFILER_LABEL_DYNAMIC into a single argument. There was no good reason for
them to be separate, and it forced a '::' in the label, which isn't always
appropriate. Also, the meaning of the "name_space" argument was interpreted
in an interesting variety of ways.
- Adds an "AUTO_" prefix to PROFILER_LABEL and PROFILER_LABEL_DYNAMIC, to make
it clearer they construct RAII objects rather than just being function calls.
(I myself have screwed up the scoping because of this in the past.)
- Fills in the 'js::ProfileEntry::Category::' qualifier within the macro, so
the caller doesn't need to. This makes a *lot* more of the uses fit onto a
single line.
The patch also makes the following changes to the macro uses (beyond those
required by the changes described above).
- Fixes a bunch of labels that had gotten out of sync with the name of the
class and/or function that encloses them.
- Removes a useless PROFILER_LABEL use within a trivial scope in
EventStateManager::DispatchMouseOrPointerEvent(). It clearly wasn't serving
any useful purpose. It also serves as extra evidence that the AUTO_ prefix is
a good idea.
- Tweaks DecodePool::SyncRunIf{Preferred,Possible} so that the labelling is
done within them, instead of at their callsites, because that's a more
standard way of doing things.
--HG--
extra : rebase_source : 318d1bc6fc1425a94aacbf489dd46e4f83211de4
2017-06-22 10:08:53 +03:00
|
|
|
AUTO_PROFILER_LABEL_DYNAMIC("nsIContentChild::RecvAsyncMessage", EVENTS,
|
|
|
|
messageNameCStr.get());
|
2017-03-30 00:43:21 +03: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
|
|
|
}
|
|
|
|
|
2017-05-02 12:57:51 +03:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsIEventTarget>
|
|
|
|
nsIContentChild::GetConstructedEventTarget(const IPC::Message& aMsg)
|
|
|
|
{
|
|
|
|
ActorHandle handle;
|
|
|
|
TabId tabId, sameTabGroupAs;
|
|
|
|
PickleIterator iter(aMsg);
|
|
|
|
if (!IPC::ReadParam(&aMsg, &iter, &handle)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
aMsg.IgnoreSentinel(&iter);
|
|
|
|
if (!IPC::ReadParam(&aMsg, &iter, &tabId)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
aMsg.IgnoreSentinel(&iter);
|
|
|
|
if (!IPC::ReadParam(&aMsg, &iter, &sameTabGroupAs)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If sameTabGroupAs is non-zero, then the new tab will be in the same
|
|
|
|
// TabGroup as a previously created tab. Rather than try to find the
|
|
|
|
// previously created tab (whose constructor message may not even have been
|
|
|
|
// processed yet, in theory) and look up its event target, we just use the
|
|
|
|
// default event target. This means that runnables for this tab will not be
|
|
|
|
// labeled. However, this path is only taken for print preview and view
|
|
|
|
// source, which are not performance-sensitive.
|
|
|
|
if (sameTabGroupAs) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the request for a new TabChild is coming from the parent process, then
|
|
|
|
// there is no opener. Therefore, we create a fresh TabGroup.
|
|
|
|
RefPtr<TabGroup> tabGroup = new TabGroup();
|
|
|
|
nsCOMPtr<nsIEventTarget> target = tabGroup->EventTargetFor(TaskCategory::Other);
|
|
|
|
return target.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|