2009-08-18 12:05:15 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
2012-05-21 04:12:37 -07: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/. */
|
2009-08-12 09:18:08 -07:00
|
|
|
|
2012-06-21 17:56:10 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
2010-08-20 16:24:40 -07:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#endif
|
|
|
|
|
2010-10-08 14:48:37 -07:00
|
|
|
#ifdef MOZ_WIDGET_QT
|
2010-10-08 23:05:50 -07:00
|
|
|
#include "nsQAppInstance.h"
|
2010-10-08 14:48:37 -07:00
|
|
|
#endif
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
#include "ContentChild.h"
|
2010-11-24 06:15:03 -08:00
|
|
|
#include "CrashReporterChild.h"
|
2009-08-12 09:18:08 -07:00
|
|
|
#include "TabChild.h"
|
2011-03-23 20:23:33 -07:00
|
|
|
#if defined(MOZ_SYDNEYAUDIO)
|
2010-11-16 20:14:19 -08:00
|
|
|
#include "AudioChild.h"
|
2011-03-23 20:23:33 -07:00
|
|
|
#endif
|
2009-08-12 09:18:08 -07:00
|
|
|
|
2011-10-05 15:15:45 -07:00
|
|
|
#include "mozilla/dom/ExternalHelperAppChild.h"
|
|
|
|
#include "mozilla/dom/PCrashReporterChild.h"
|
|
|
|
#include "mozilla/dom/StorageChild.h"
|
|
|
|
#include "mozilla/hal_sandbox/PHalChild.h"
|
2009-08-12 11:31:48 -07:00
|
|
|
#include "mozilla/ipc/TestShellChild.h"
|
2009-11-06 12:43:39 -08:00
|
|
|
#include "mozilla/ipc/XPCShellEnvironment.h"
|
|
|
|
#include "mozilla/jsipc/PContextWrapperChild.h"
|
2011-10-05 15:15:45 -07:00
|
|
|
#include "mozilla/net/NeckoChild.h"
|
2011-11-02 07:51:39 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-06-14 19:31:55 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2009-08-12 11:31:48 -07:00
|
|
|
|
2011-03-23 20:23:33 -07:00
|
|
|
#if defined(MOZ_SYDNEYAUDIO)
|
2010-11-16 20:14:19 -08:00
|
|
|
#include "nsAudioStream.h"
|
2011-03-23 20:23:33 -07:00
|
|
|
#endif
|
2011-02-16 10:43:23 -08:00
|
|
|
#include "nsIMemoryReporter.h"
|
2010-07-21 11:42:32 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsTObserverArray.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2009-08-25 16:39:30 -07:00
|
|
|
#include "nsXULAppAPI.h"
|
2010-07-21 11:42:32 -07:00
|
|
|
#include "nsWeakReference.h"
|
2010-09-23 18:39:32 -07:00
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIConsoleService.h"
|
2011-09-13 10:53:51 -07:00
|
|
|
#include "nsJSEnvironment.h"
|
2011-10-05 15:15:45 -07:00
|
|
|
#include "SandboxHal.h"
|
2012-04-10 12:57:20 -07:00
|
|
|
#include "nsDebugImpl.h"
|
2009-08-25 16:07:22 -07:00
|
|
|
|
2010-07-02 08:50:41 -07:00
|
|
|
#include "History.h"
|
|
|
|
#include "nsDocShellCID.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
|
2009-09-02 17:18:27 -07:00
|
|
|
#include "base/message_loop.h"
|
|
|
|
#include "base/task.h"
|
|
|
|
|
2010-03-10 21:33:00 -08:00
|
|
|
#include "nsChromeRegistryContent.h"
|
|
|
|
#include "mozilla/chrome/RegistryMessageUtils.h"
|
2010-08-31 11:58:35 -07:00
|
|
|
#include "nsFrameMessageManager.h"
|
2010-03-10 21:33:00 -08:00
|
|
|
|
2010-09-20 21:16:37 -07:00
|
|
|
#include "nsIGeolocationProvider.h"
|
2011-02-16 10:43:23 -08:00
|
|
|
#include "mozilla/dom/PMemoryReportRequestChild.h"
|
2010-09-20 21:16:37 -07:00
|
|
|
|
2010-10-09 11:07:38 -07:00
|
|
|
#ifdef MOZ_PERMISSIONS
|
|
|
|
#include "nsPermission.h"
|
|
|
|
#include "nsPermissionManager.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2010-11-24 06:15:03 -08:00
|
|
|
#include "APKOpen.h"
|
|
|
|
#endif
|
|
|
|
|
2011-02-16 10:43:23 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <process.h>
|
|
|
|
#define getpid _getpid
|
|
|
|
#endif
|
|
|
|
|
2011-07-20 21:37:32 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-20 14:40:53 -08:00
|
|
|
#include "mozilla/dom/sms/SmsChild.h"
|
|
|
|
|
2011-10-05 15:15:45 -07:00
|
|
|
using namespace mozilla::hal_sandbox;
|
2009-08-12 11:31:48 -07:00
|
|
|
using namespace mozilla::ipc;
|
2009-08-18 12:05:15 -07:00
|
|
|
using namespace mozilla::net;
|
2010-07-02 08:50:41 -07:00
|
|
|
using namespace mozilla::places;
|
2010-10-20 10:12:32 -07:00
|
|
|
using namespace mozilla::docshell;
|
2011-11-20 14:40:53 -08:00
|
|
|
using namespace mozilla::dom::sms;
|
2009-08-12 11:31:48 -07:00
|
|
|
|
2009-08-12 09:18:08 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-02-16 10:43:23 -08:00
|
|
|
|
|
|
|
class MemoryReportRequestChild : public PMemoryReportRequestChild
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MemoryReportRequestChild();
|
|
|
|
virtual ~MemoryReportRequestChild();
|
|
|
|
};
|
|
|
|
|
|
|
|
MemoryReportRequestChild::MemoryReportRequestChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(MemoryReportRequestChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryReportRequestChild::~MemoryReportRequestChild()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(MemoryReportRequestChild);
|
|
|
|
}
|
|
|
|
|
2010-09-15 09:44:57 -07:00
|
|
|
class AlertObserver
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
AlertObserver(nsIObserver *aObserver, const nsString& aData)
|
2010-12-05 05:15:36 -08:00
|
|
|
: mObserver(aObserver)
|
|
|
|
, mData(aData)
|
2010-09-15 09:44:57 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~AlertObserver() {}
|
|
|
|
|
|
|
|
bool ShouldRemoveFrom(nsIObserver* aObserver,
|
|
|
|
const nsString& aData) const
|
|
|
|
{
|
|
|
|
return (mObserver == aObserver &&
|
|
|
|
mData == aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Observes(const nsString& aData) const
|
|
|
|
{
|
|
|
|
return mData.Equals(aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notify(const nsCString& aType) const
|
|
|
|
{
|
|
|
|
mObserver->Observe(nsnull, aType.get(), mData.get());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIObserver> mObserver;
|
|
|
|
nsString mData;
|
|
|
|
};
|
|
|
|
|
2012-06-14 19:31:55 -07:00
|
|
|
class ConsoleListener MOZ_FINAL : public nsIConsoleListener
|
2010-09-23 18:39:32 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ConsoleListener(ContentChild* aChild)
|
|
|
|
: mChild(aChild) {}
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSICONSOLELISTENER
|
|
|
|
|
|
|
|
private:
|
|
|
|
ContentChild* mChild;
|
|
|
|
friend class ContentChild;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(ConsoleListener, nsIConsoleListener)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ConsoleListener::Observe(nsIConsoleMessage* aMessage)
|
|
|
|
{
|
|
|
|
if (!mChild)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptError> scriptError = do_QueryInterface(aMessage);
|
|
|
|
if (scriptError) {
|
|
|
|
nsString msg, sourceName, sourceLine;
|
|
|
|
nsXPIDLCString category;
|
|
|
|
PRUint32 lineNum, colNum, flags;
|
|
|
|
|
|
|
|
nsresult rv = scriptError->GetErrorMessage(msg);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = scriptError->GetSourceName(sourceName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = scriptError->GetSourceLine(sourceLine);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = scriptError->GetCategory(getter_Copies(category));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = scriptError->GetLineNumber(&lineNum);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = scriptError->GetColumnNumber(&colNum);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = scriptError->GetFlags(&flags);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mChild->SendScriptError(msg, sourceName, sourceLine,
|
|
|
|
lineNum, colNum, flags, category);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXPIDLString msg;
|
|
|
|
nsresult rv = aMessage->GetMessageMoz(getter_Copies(msg));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mChild->SendConsoleMessage(msg);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-07-21 11:42:32 -07:00
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild* ContentChild::sSingleton;
|
2009-08-12 17:32:50 -07:00
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::ContentChild()
|
2012-04-25 09:35:58 -07:00
|
|
|
: mID(PRUint64(-1))
|
2010-11-24 10:22:40 -08:00
|
|
|
#ifdef ANDROID
|
2012-04-25 09:35:58 -07:00
|
|
|
, mScreenSize(0, 0)
|
2010-11-24 10:22:40 -08:00
|
|
|
#endif
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2012-04-10 12:57:20 -07:00
|
|
|
// This process is a content process, so it's clearly running in
|
|
|
|
// multiprocess mode!
|
|
|
|
nsDebugImpl::SetMultiprocessMode("Child");
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::~ContentChild()
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::Init(MessageLoop* aIOLoop,
|
|
|
|
base::ProcessHandle aParentHandle,
|
|
|
|
IPC::Channel* aChannel)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2012-06-21 17:56:10 -07:00
|
|
|
#ifdef MOZ_WIDGET_GTK2
|
2010-08-20 16:24:40 -07:00
|
|
|
// sigh
|
|
|
|
gtk_init(NULL, NULL);
|
|
|
|
#endif
|
2010-10-08 14:48:37 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_QT
|
|
|
|
// sigh, seriously
|
2010-10-08 23:05:50 -07:00
|
|
|
nsQAppInstance::AddRef();
|
2010-10-08 14:48:37 -07:00
|
|
|
#endif
|
2010-08-20 16:24:40 -07:00
|
|
|
|
2010-09-09 18:25:26 -07:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
// Do this after initializing GDK, or GDK will install its own handler.
|
|
|
|
XRE_InstallX11ErrorHandler();
|
|
|
|
#endif
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
NS_ASSERTION(!sSingleton, "only one ContentChild per child");
|
2010-11-05 09:38:17 -07:00
|
|
|
|
2009-10-27 14:52:37 -07:00
|
|
|
Open(aChannel, aParentHandle, aIOLoop);
|
2009-08-12 17:32:50 -07:00
|
|
|
sSingleton = this;
|
|
|
|
|
2011-06-08 12:56:31 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
SendPCrashReporterConstructor(CrashReporter::CurrentThreadId(),
|
|
|
|
XRE_GetProcessType());
|
2011-11-10 16:17:46 -08:00
|
|
|
#if defined(MOZ_WIDGET_ANDROID)
|
2011-06-08 13:21:03 -07:00
|
|
|
PCrashReporterChild* crashreporter = ManagedPCrashReporterChild()[0];
|
2011-06-08 12:56:31 -07:00
|
|
|
|
2010-11-24 06:15:03 -08:00
|
|
|
InfallibleTArray<Mapping> mappings;
|
|
|
|
const struct mapping_info *info = getLibraryMapping();
|
2011-05-25 13:54:30 -07:00
|
|
|
while (info && info->name) {
|
2010-11-24 06:15:03 -08:00
|
|
|
mappings.AppendElement(Mapping(nsDependentCString(info->name),
|
|
|
|
nsDependentCString(info->file_id),
|
|
|
|
info->base,
|
|
|
|
info->len,
|
|
|
|
info->offset));
|
|
|
|
info++;
|
|
|
|
}
|
|
|
|
crashreporter->SendAddLibraryMappings(mappings);
|
2011-06-08 12:56:31 -07:00
|
|
|
#endif
|
2010-11-24 06:15:03 -08:00
|
|
|
#endif
|
|
|
|
|
2009-08-12 17:32:50 -07:00
|
|
|
return true;
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2010-09-23 18:39:32 -07:00
|
|
|
void
|
|
|
|
ContentChild::InitXPCOM()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIConsoleService> svc(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (!svc) {
|
|
|
|
NS_WARNING("Couldn't acquire console service");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mConsoleListener = new ConsoleListener(this);
|
|
|
|
if (NS_FAILED(svc->RegisterListener(mConsoleListener)))
|
|
|
|
NS_WARNING("Couldn't register console listener for child process");
|
|
|
|
}
|
|
|
|
|
2011-02-16 10:43:23 -08:00
|
|
|
PMemoryReportRequestChild*
|
|
|
|
ContentChild::AllocPMemoryReportRequest()
|
|
|
|
{
|
|
|
|
return new MemoryReportRequestChild();
|
|
|
|
}
|
|
|
|
|
2011-06-29 16:39:32 -07:00
|
|
|
// This is just a wrapper for InfallibleTArray<MemoryReport> that implements
|
|
|
|
// nsISupports, so it can be passed to nsIMemoryMultiReporter::CollectReports.
|
2012-06-14 19:31:55 -07:00
|
|
|
class MemoryReportsWrapper MOZ_FINAL : public nsISupports {
|
2011-06-29 16:39:32 -07:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
MemoryReportsWrapper(InfallibleTArray<MemoryReport> *r) : mReports(r) { }
|
|
|
|
InfallibleTArray<MemoryReport> *mReports;
|
|
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS0(MemoryReportsWrapper)
|
|
|
|
|
2012-06-14 19:31:55 -07:00
|
|
|
class MemoryReportCallback MOZ_FINAL : public nsIMemoryMultiReporterCallback
|
2011-06-29 16:39:32 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
MemoryReportCallback(const nsACString &aProcess)
|
|
|
|
: mProcess(aProcess)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Callback(const nsACString &aProcess, const nsACString &aPath,
|
|
|
|
PRInt32 aKind, PRInt32 aUnits, PRInt64 aAmount,
|
|
|
|
const nsACString &aDescription,
|
|
|
|
nsISupports *aiWrappedReports)
|
|
|
|
{
|
|
|
|
MemoryReportsWrapper *wrappedReports =
|
|
|
|
static_cast<MemoryReportsWrapper *>(aiWrappedReports);
|
|
|
|
|
|
|
|
MemoryReport memreport(mProcess, nsCString(aPath), aKind, aUnits,
|
|
|
|
aAmount, nsCString(aDescription));
|
|
|
|
wrappedReports->mReports->AppendElement(memreport);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
const nsCString mProcess;
|
|
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS1(
|
|
|
|
MemoryReportCallback
|
|
|
|
, nsIMemoryMultiReporterCallback
|
|
|
|
)
|
|
|
|
|
2011-02-16 10:43:23 -08:00
|
|
|
bool
|
|
|
|
ContentChild::RecvPMemoryReportRequestConstructor(PMemoryReportRequestChild* child)
|
|
|
|
{
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMemoryReporterManager> mgr = do_GetService("@mozilla.org/memory-reporter-manager;1");
|
|
|
|
|
2011-06-29 16:39:32 -07:00
|
|
|
InfallibleTArray<MemoryReport> reports;
|
|
|
|
|
2012-04-24 11:43:00 -07:00
|
|
|
nsPrintfCString process("Content (%d)", getpid());
|
2011-06-29 16:39:32 -07:00
|
|
|
|
|
|
|
// First do the vanilla memory reporters.
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> e;
|
|
|
|
mgr->EnumerateReporters(getter_AddRefs(e));
|
2011-09-28 23:19:26 -07:00
|
|
|
bool more;
|
2011-06-29 16:39:32 -07:00
|
|
|
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
|
|
|
|
nsCOMPtr<nsIMemoryReporter> r;
|
|
|
|
e->GetNext(getter_AddRefs(r));
|
2011-02-16 10:43:23 -08:00
|
|
|
|
|
|
|
nsCString path;
|
2011-05-22 19:49:56 -07:00
|
|
|
PRInt32 kind;
|
2011-06-16 11:34:09 -07:00
|
|
|
PRInt32 units;
|
|
|
|
PRInt64 amount;
|
2011-06-29 16:39:32 -07:00
|
|
|
nsCString desc;
|
2012-04-09 22:52:33 -07:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(r->GetPath(path)) &&
|
|
|
|
NS_SUCCEEDED(r->GetKind(&kind)) &&
|
|
|
|
NS_SUCCEEDED(r->GetUnits(&units)) &&
|
|
|
|
NS_SUCCEEDED(r->GetAmount(&amount)) &&
|
|
|
|
NS_SUCCEEDED(r->GetDescription(desc)))
|
|
|
|
{
|
|
|
|
MemoryReport memreport(process, path, kind, units, amount, desc);
|
|
|
|
reports.AppendElement(memreport);
|
|
|
|
}
|
2011-06-29 16:39:32 -07:00
|
|
|
}
|
2011-02-16 10:43:23 -08:00
|
|
|
|
2011-06-29 16:39:32 -07:00
|
|
|
// Then do the memory multi-reporters, by calling CollectReports on each
|
|
|
|
// one, whereupon the callback will turn each measurement into a
|
|
|
|
// MemoryReport.
|
|
|
|
mgr->EnumerateMultiReporters(getter_AddRefs(e));
|
2011-07-06 22:54:34 -07:00
|
|
|
nsRefPtr<MemoryReportsWrapper> wrappedReports =
|
|
|
|
new MemoryReportsWrapper(&reports);
|
|
|
|
nsRefPtr<MemoryReportCallback> cb = new MemoryReportCallback(process);
|
2011-06-29 16:39:32 -07:00
|
|
|
while (NS_SUCCEEDED(e->HasMoreElements(&more)) && more) {
|
|
|
|
nsCOMPtr<nsIMemoryMultiReporter> r;
|
|
|
|
e->GetNext(getter_AddRefs(r));
|
2011-07-06 22:54:34 -07:00
|
|
|
r->CollectReports(cb, wrappedReports);
|
2011-02-16 10:43:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
child->Send__delete__(child, reports);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::DeallocPMemoryReportRequest(PMemoryReportRequestChild* actor)
|
|
|
|
{
|
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
PBrowserChild*
|
2012-06-21 18:17:52 -07:00
|
|
|
ContentChild::AllocPBrowser(const PRUint32& aChromeFlags, const bool& aIsBrowserFrame)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2012-06-21 18:17:52 -07:00
|
|
|
nsRefPtr<TabChild> iframe = new TabChild(aChromeFlags, aIsBrowserFrame);
|
2010-08-20 16:24:40 -07:00
|
|
|
return NS_SUCCEEDED(iframe->Init()) ? iframe.forget().get() : NULL;
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::DeallocPBrowser(PBrowserChild* iframe)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2010-05-14 22:27:52 -07:00
|
|
|
TabChild* child = static_cast<TabChild*>(iframe);
|
|
|
|
NS_RELEASE(child);
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 06:15:03 -08:00
|
|
|
PCrashReporterChild*
|
2011-06-08 12:56:31 -07:00
|
|
|
ContentChild::AllocPCrashReporter(const mozilla::dom::NativeThreadId& id,
|
|
|
|
const PRUint32& processType)
|
2010-11-24 06:15:03 -08:00
|
|
|
{
|
2011-06-08 12:56:31 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2010-11-24 06:15:03 -08:00
|
|
|
return new CrashReporterChild();
|
2011-06-08 12:56:31 -07:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
2010-11-24 06:15:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::DeallocPCrashReporter(PCrashReporterChild* crashreporter)
|
|
|
|
{
|
|
|
|
delete crashreporter;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-05 15:15:45 -07:00
|
|
|
PHalChild*
|
|
|
|
ContentChild::AllocPHal()
|
|
|
|
{
|
|
|
|
return CreateHalChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::DeallocPHal(PHalChild* aHal)
|
|
|
|
{
|
|
|
|
delete aHal;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-09 15:59:06 -07:00
|
|
|
PTestShellChild*
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::AllocPTestShell()
|
2009-08-12 11:31:48 -07:00
|
|
|
{
|
2010-05-14 22:27:52 -07:00
|
|
|
return new TestShellChild();
|
2009-08-12 11:31:48 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::DeallocPTestShell(PTestShellChild* shell)
|
2009-08-12 11:31:48 -07:00
|
|
|
{
|
2010-05-14 22:27:52 -07:00
|
|
|
delete shell;
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-08-25 16:07:22 -07:00
|
|
|
}
|
|
|
|
|
2009-11-06 12:43:39 -08:00
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::RecvPTestShellConstructor(PTestShellChild* actor)
|
2009-11-06 12:43:39 -08:00
|
|
|
{
|
|
|
|
actor->SendPContextWrapperConstructor()->SendPObjectWrapperConstructor(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-16 20:14:19 -08:00
|
|
|
PAudioChild*
|
|
|
|
ContentChild::AllocPAudio(const PRInt32& numChannels,
|
|
|
|
const PRInt32& rate,
|
|
|
|
const PRInt32& format)
|
|
|
|
{
|
2011-03-23 20:23:33 -07:00
|
|
|
#if defined(MOZ_SYDNEYAUDIO)
|
2010-11-25 20:13:54 -08:00
|
|
|
AudioChild *child = new AudioChild();
|
|
|
|
NS_ADDREF(child);
|
2010-11-16 20:14:19 -08:00
|
|
|
return child;
|
2011-03-23 20:23:33 -07:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
2010-11-16 20:14:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::DeallocPAudio(PAudioChild* doomed)
|
|
|
|
{
|
2011-03-23 20:23:33 -07:00
|
|
|
#if defined(MOZ_SYDNEYAUDIO)
|
2010-11-25 20:13:54 -08:00
|
|
|
AudioChild *child = static_cast<AudioChild*>(doomed);
|
|
|
|
NS_RELEASE(child);
|
2011-03-23 20:23:33 -07:00
|
|
|
#endif
|
2010-11-16 20:14:19 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-18 12:05:15 -07:00
|
|
|
PNeckoChild*
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::AllocPNecko()
|
2009-08-18 12:05:15 -07:00
|
|
|
{
|
|
|
|
return new NeckoChild();
|
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::DeallocPNecko(PNeckoChild* necko)
|
2009-08-18 12:05:15 -07:00
|
|
|
{
|
|
|
|
delete necko;
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-08-18 12:05:15 -07:00
|
|
|
}
|
|
|
|
|
2010-09-15 15:55:08 -07:00
|
|
|
PExternalHelperAppChild*
|
|
|
|
ContentChild::AllocPExternalHelperApp(const IPC::URI& uri,
|
|
|
|
const nsCString& aMimeContentType,
|
|
|
|
const nsCString& aContentDisposition,
|
|
|
|
const bool& aForceSave,
|
2010-11-21 11:21:59 -08:00
|
|
|
const PRInt64& aContentLength,
|
|
|
|
const IPC::URI& aReferrer)
|
2010-09-15 15:55:08 -07:00
|
|
|
{
|
|
|
|
ExternalHelperAppChild *child = new ExternalHelperAppChild();
|
|
|
|
child->AddRef();
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::DeallocPExternalHelperApp(PExternalHelperAppChild* aService)
|
|
|
|
{
|
|
|
|
ExternalHelperAppChild *child = static_cast<ExternalHelperAppChild*>(aService);
|
|
|
|
child->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-20 14:40:53 -08:00
|
|
|
PSmsChild*
|
|
|
|
ContentChild::AllocPSms()
|
|
|
|
{
|
|
|
|
return new SmsChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::DeallocPSms(PSmsChild* aSms)
|
|
|
|
{
|
|
|
|
delete aSms;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-18 17:15:23 -08:00
|
|
|
PStorageChild*
|
|
|
|
ContentChild::AllocPStorage(const StorageConstructData& aData)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("We should never be manually allocating PStorageChild actors");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::DeallocPStorage(PStorageChild* aActor)
|
|
|
|
{
|
|
|
|
StorageChild* child = static_cast<StorageChild*>(aActor);
|
|
|
|
child->ReleaseIPDLReference();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-10 21:33:00 -08:00
|
|
|
bool
|
2010-11-08 18:49:00 -08:00
|
|
|
ContentChild::RecvRegisterChrome(const InfallibleTArray<ChromePackage>& packages,
|
|
|
|
const InfallibleTArray<ResourceMapping>& resources,
|
2011-01-11 13:34:31 -08:00
|
|
|
const InfallibleTArray<OverrideMapping>& overrides,
|
|
|
|
const nsCString& locale)
|
2010-03-10 21:33:00 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
|
|
|
|
nsChromeRegistryContent* chromeRegistry =
|
|
|
|
static_cast<nsChromeRegistryContent*>(registrySvc.get());
|
2011-01-11 13:34:31 -08:00
|
|
|
chromeRegistry->RegisterRemoteChrome(packages, resources, overrides, locale);
|
2010-03-10 21:33:00 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-11 05:44:12 -07:00
|
|
|
bool
|
2011-09-28 23:19:26 -07:00
|
|
|
ContentChild::RecvSetOffline(const bool& offline)
|
2010-05-11 05:44:12 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIIOService> io (do_GetIOService());
|
|
|
|
NS_ASSERTION(io, "IO Service can not be null");
|
|
|
|
|
|
|
|
io->SetOffline(offline);
|
2011-02-14 14:34:46 -08:00
|
|
|
|
2010-05-11 05:44:12 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-12-06 22:03:49 -08:00
|
|
|
void
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentChild::ActorDestroy(ActorDestroyReason why)
|
2009-09-02 17:18:27 -07:00
|
|
|
{
|
2010-08-20 16:24:40 -07:00
|
|
|
if (AbnormalShutdown == why) {
|
|
|
|
NS_WARNING("shutting down early because of crash!");
|
|
|
|
QuickExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef DEBUG
|
|
|
|
// In release builds, there's no point in the content process
|
|
|
|
// going through the full XPCOM shutdown path, because it doesn't
|
|
|
|
// keep persistent state.
|
|
|
|
QuickExit();
|
|
|
|
#endif
|
2009-09-02 17:18:27 -07:00
|
|
|
|
2010-09-15 09:44:57 -07:00
|
|
|
mAlertObservers.Clear();
|
2011-02-14 14:34:46 -08:00
|
|
|
|
2010-09-23 18:39:32 -07:00
|
|
|
nsCOMPtr<nsIConsoleService> svc(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (svc) {
|
|
|
|
svc->UnregisterListener(mConsoleListener);
|
|
|
|
mConsoleListener->mChild = nsnull;
|
|
|
|
}
|
|
|
|
|
2009-12-06 22:03:49 -08:00
|
|
|
XRE_ShutdownChildProcess();
|
2009-09-02 17:18:27 -07:00
|
|
|
}
|
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
void
|
|
|
|
ContentChild::ProcessingError(Result what)
|
|
|
|
{
|
|
|
|
switch (what) {
|
|
|
|
case MsgDropped:
|
|
|
|
QuickExit();
|
|
|
|
|
|
|
|
case MsgNotKnown:
|
|
|
|
case MsgNotAllowed:
|
|
|
|
case MsgPayloadError:
|
|
|
|
case MsgProcessingError:
|
|
|
|
case MsgRouteError:
|
|
|
|
case MsgValueError:
|
|
|
|
NS_RUNTIMEABORT("aborting because of fatal error");
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_RUNTIMEABORT("not reached");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentChild::QuickExit()
|
|
|
|
{
|
|
|
|
NS_WARNING("content process _exit()ing");
|
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
|
2010-09-15 09:44:57 -07:00
|
|
|
nsresult
|
|
|
|
ContentChild::AddRemoteAlertObserver(const nsString& aData,
|
|
|
|
nsIObserver* aObserver)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aObserver, "Adding a null observer?");
|
|
|
|
mAlertObservers.AppendElement(new AlertObserver(aObserver, aData));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-25 17:13:47 -07:00
|
|
|
bool
|
2010-10-19 13:35:08 -07:00
|
|
|
ContentChild::RecvPreferenceUpdate(const PrefTuple& aPref)
|
2010-07-21 11:42:32 -07:00
|
|
|
{
|
2011-11-02 07:51:39 -07:00
|
|
|
Preferences::SetPreference(&aPref);
|
2011-01-05 20:54:47 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::RecvClearUserPreference(const nsCString& aPrefName)
|
|
|
|
{
|
2011-11-02 07:51:39 -07:00
|
|
|
Preferences::ClearContentPref(aPrefName.get());
|
2010-05-25 17:13:47 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-15 09:44:57 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvNotifyAlertsObserver(const nsCString& aType, const nsString& aData)
|
|
|
|
{
|
|
|
|
for (PRUint32 i = 0; i < mAlertObservers.Length();
|
|
|
|
/*we mutate the array during the loop; ++i iff no mutation*/) {
|
|
|
|
AlertObserver* observer = mAlertObservers[i];
|
|
|
|
if (observer->Observes(aData) && observer->Notify(aType)) {
|
|
|
|
// if aType == alertfinished, this alert is done. we can
|
|
|
|
// remove the observer.
|
|
|
|
if (aType.Equals(nsDependentCString("alertfinished"))) {
|
|
|
|
mAlertObservers.RemoveElementAt(i);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:50:41 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvNotifyVisited(const IPC::URI& aURI)
|
|
|
|
{
|
2010-07-26 12:59:34 -07:00
|
|
|
nsCOMPtr<nsIURI> newURI(aURI);
|
2010-07-02 08:50:41 -07:00
|
|
|
History::GetService()->NotifyVisited(newURI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-31 11:58:35 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::RecvAsyncMessage(const nsString& aMsg, const nsString& aJSON)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsFrameMessageManager> cpm = nsFrameMessageManager::sChildProcessManager;
|
|
|
|
if (cpm) {
|
|
|
|
cpm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(cpm.get()),
|
2011-10-17 07:59:28 -07:00
|
|
|
aMsg, false, aJSON, nsnull, nsnull);
|
2010-08-31 11:58:35 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-20 21:16:37 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvGeolocationUpdate(const GeoPosition& somewhere)
|
|
|
|
{
|
2010-09-20 21:16:37 -07:00
|
|
|
nsCOMPtr<nsIGeolocationUpdate> gs = do_GetService("@mozilla.org/geolocation/service;1");
|
2010-09-21 19:36:58 -07:00
|
|
|
if (!gs) {
|
2010-09-20 21:16:37 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMGeoPosition> position = somewhere;
|
|
|
|
gs->Update(position);
|
2010-09-20 21:16:37 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-09 11:07:38 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvAddPermission(const IPC::Permission& permission)
|
|
|
|
{
|
|
|
|
#if MOZ_PERMISSIONS
|
2011-08-30 10:45:09 -07:00
|
|
|
nsCOMPtr<nsIPermissionManager> permissionManagerIface =
|
|
|
|
do_GetService(NS_PERMISSIONMANAGER_CONTRACTID);
|
|
|
|
nsPermissionManager* permissionManager =
|
|
|
|
static_cast<nsPermissionManager*>(permissionManagerIface.get());
|
2010-10-09 11:07:38 -07:00
|
|
|
NS_ABORT_IF_FALSE(permissionManager,
|
|
|
|
"We have no permissionManager in the Content process !");
|
|
|
|
|
|
|
|
permissionManager->AddInternal(nsCString(permission.host),
|
|
|
|
nsCString(permission.type),
|
|
|
|
permission.capability,
|
|
|
|
0,
|
|
|
|
permission.expireType,
|
|
|
|
permission.expireTime,
|
|
|
|
nsPermissionManager::eNotify,
|
|
|
|
nsPermissionManager::eNoDBOperation);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-19 22:36:17 -07:00
|
|
|
|
2010-11-24 10:22:40 -08:00
|
|
|
bool
|
|
|
|
ContentChild::RecvScreenSizeChanged(const gfxIntSize& size)
|
|
|
|
{
|
|
|
|
#ifdef ANDROID
|
|
|
|
mScreenSize = size;
|
|
|
|
#else
|
|
|
|
NS_RUNTIMEABORT("Message currently only expected on android");
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-12-11 14:36:08 -08:00
|
|
|
bool
|
|
|
|
ContentChild::RecvFlushMemory(const nsString& reason)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> os =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (os)
|
2010-12-12 08:48:04 -08:00
|
|
|
os->NotifyObservers(nsnull, "memory-pressure", reason.get());
|
2010-12-11 14:36:08 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-20 21:37:32 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvActivateA11y()
|
|
|
|
{
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
// Start accessibility in content process if it's running in chrome
|
|
|
|
// process.
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService =
|
|
|
|
do_GetService("@mozilla.org/accessibilityService;1");
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-13 10:53:51 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvGarbageCollect()
|
|
|
|
{
|
2012-05-09 11:53:23 -07:00
|
|
|
nsJSContext::GarbageCollectNow(js::gcreason::DOM_IPC, nsGCNormal, true);
|
2011-09-13 10:53:51 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentChild::RecvCycleCollect()
|
|
|
|
{
|
2012-05-09 11:53:23 -07:00
|
|
|
nsJSContext::GarbageCollectNow(js::gcreason::DOM_IPC, nsGCNormal, true);
|
2011-09-13 10:53:51 -07:00
|
|
|
nsJSContext::CycleCollectNow();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-04 13:31:00 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvAppInfo(const nsCString& version, const nsCString& buildID)
|
|
|
|
{
|
|
|
|
mAppInfo.version.Assign(version);
|
|
|
|
mAppInfo.buildID.Assign(buildID);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-30 00:00:48 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvSetID(const PRUint64 &id)
|
|
|
|
{
|
|
|
|
if (mID != PRUint64(-1)) {
|
|
|
|
NS_WARNING("Setting content child's ID twice?");
|
|
|
|
}
|
|
|
|
mID = id;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-19 17:13:20 -07:00
|
|
|
bool
|
|
|
|
ContentChild::RecvLastPrivateDocShellDestroyed()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
obs->NotifyObservers(nsnull, "last-pb-context-exited", nsnull);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:18:08 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|