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-09-09 15:00:14 -07:00
|
|
|
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "base/basictypes.h"
|
2009-08-12 09:18:08 -07:00
|
|
|
|
2012-07-17 16:59:44 -07:00
|
|
|
#if defined(ANDROID) || defined(LINUX)
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ContentParent.h"
|
2010-11-24 06:15:03 -08:00
|
|
|
#include "CrashReporterParent.h"
|
2010-07-02 08:50:41 -07:00
|
|
|
#include "History.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "IDBFactory.h"
|
|
|
|
#include "IndexedDBParent.h"
|
|
|
|
#include "IndexedDatabaseManager.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/Util.h"
|
|
|
|
#include "mozilla/dom/ExternalHelperAppParent.h"
|
|
|
|
#include "mozilla/dom/PMemoryReportRequestParent.h"
|
|
|
|
#include "mozilla/dom/StorageParent.h"
|
|
|
|
#include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h"
|
|
|
|
#include "mozilla/dom/sms/SmsParent.h"
|
|
|
|
#include "mozilla/hal_sandbox/PHalParent.h"
|
2009-08-12 11:31:48 -07:00
|
|
|
#include "mozilla/ipc/TestShellParent.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2009-08-18 12:05:15 -07:00
|
|
|
#include "mozilla/net/NeckoParent.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "nsAppRunner.h"
|
2009-09-02 17:18:27 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsCExternalHandlerService.h"
|
2009-09-02 17:18:27 -07:00
|
|
|
#include "nsCOMPtr.h"
|
2010-03-10 21:33:00 -08:00
|
|
|
#include "nsChromeRegistryChrome.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsConsoleMessage.h"
|
|
|
|
#include "nsDebugImpl.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2010-08-10 10:14:45 -07:00
|
|
|
#include "nsExternalHelperAppService.h"
|
2010-08-31 11:58:35 -07:00
|
|
|
#include "nsFrameMessageManager.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsHashPropertyBag.h"
|
2010-09-15 09:44:57 -07:00
|
|
|
#include "nsIAlertsService.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsIClipboard.h"
|
2010-09-23 18:39:32 -07:00
|
|
|
#include "nsIConsoleService.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsIDOMGeoGeolocation.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIFilePicker.h"
|
|
|
|
#include "nsIMemoryReporter.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIPresShell.h"
|
2010-09-23 18:39:32 -07:00
|
|
|
#include "nsIScriptError.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsISupportsPrimitives.h"
|
|
|
|
#include "nsIWindowWatcher.h"
|
|
|
|
#include "nsMemoryReporterManager.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
2011-06-16 19:59:00 -07:00
|
|
|
#include "nsSystemInfo.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsToolkitCompsCID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "SandboxHal.h"
|
|
|
|
#include "TabParent.h"
|
2011-02-14 14:34:46 -08:00
|
|
|
|
2012-07-17 16:59:44 -07:00
|
|
|
#ifdef ANDROID
|
|
|
|
# include "gfxAndroidPlatform.h"
|
2010-10-09 11:07:38 -07:00
|
|
|
#endif
|
|
|
|
|
2010-11-24 05:58:21 -08:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2012-07-17 16:59:44 -07:00
|
|
|
# include "nsExceptionHandler.h"
|
|
|
|
# include "nsICrashReporter.h"
|
2010-11-24 05:58:21 -08:00
|
|
|
#endif
|
|
|
|
|
2012-07-17 16:59:44 -07:00
|
|
|
#ifdef MOZ_PERMISSIONS
|
|
|
|
# include "nsPermissionManager.h"
|
|
|
|
#endif
|
2011-02-16 10:43:23 -08:00
|
|
|
|
2012-07-17 16:59:44 -07:00
|
|
|
#ifdef MOZ_SYDNEYAUDIO
|
|
|
|
# include "AudioParent.h"
|
2011-11-10 16:17:46 -08:00
|
|
|
#endif
|
2012-07-17 16:59:44 -07:00
|
|
|
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2012-07-17 16:59:44 -07:00
|
|
|
# include "AndroidBridge.h"
|
2011-01-12 20:04:42 -08:00
|
|
|
#endif
|
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
|
|
|
static const char* sClipboardTextFlavors[] = { kUnicodeMime };
|
|
|
|
|
2011-01-19 22:14:12 -08:00
|
|
|
using base::KillProcess;
|
2012-06-19 16:14:39 -07:00
|
|
|
using namespace mozilla::dom::devicestorage;
|
2011-11-20 14:40:53 -08:00
|
|
|
using namespace mozilla::dom::sms;
|
2012-07-14 04:24:20 -07:00
|
|
|
using namespace mozilla::dom::indexedDB;
|
2012-07-17 16:59:44 -07:00
|
|
|
using namespace mozilla::hal_sandbox;
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::net;
|
|
|
|
using namespace mozilla::places;
|
2009-09-02 17:18:27 -07:00
|
|
|
|
2009-08-12 09:18:08 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2010-05-11 10:22:34 -07:00
|
|
|
#define NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC "ipc:network:set-offline"
|
2010-05-11 05:44:12 -07:00
|
|
|
|
2011-02-16 10:43:23 -08:00
|
|
|
class MemoryReportRequestParent : public PMemoryReportRequestParent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MemoryReportRequestParent();
|
|
|
|
virtual ~MemoryReportRequestParent();
|
|
|
|
|
|
|
|
virtual bool Recv__delete__(const InfallibleTArray<MemoryReport>& report);
|
|
|
|
private:
|
|
|
|
ContentParent* Owner()
|
|
|
|
{
|
|
|
|
return static_cast<ContentParent*>(Manager());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
MemoryReportRequestParent::MemoryReportRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(MemoryReportRequestParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MemoryReportRequestParent::Recv__delete__(const InfallibleTArray<MemoryReport>& report)
|
|
|
|
{
|
|
|
|
Owner()->SetChildMemoryReporters(report);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryReportRequestParent::~MemoryReportRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(MemoryReportRequestParent);
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:10:20 -07:00
|
|
|
nsDataHashtable<nsStringHashKey, ContentParent*>* ContentParent::gAppContentParents;
|
|
|
|
nsTArray<ContentParent*>* ContentParent::gNonAppContentParents;
|
2012-04-19 17:13:20 -07:00
|
|
|
nsTArray<ContentParent*>* ContentParent::gPrivateContent;
|
2009-08-12 09:18:08 -07:00
|
|
|
|
2011-09-30 00:00:48 -07:00
|
|
|
// The first content child has ID 1, so the chrome process can have ID 0.
|
|
|
|
static PRUint64 gContentChildID = 1;
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent*
|
2011-08-02 12:35:42 -07:00
|
|
|
ContentParent::GetNewOrUsed()
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2012-07-13 14:10:20 -07:00
|
|
|
if (!gNonAppContentParents)
|
|
|
|
gNonAppContentParents = new nsTArray<ContentParent*>();
|
2011-08-02 12:35:42 -07:00
|
|
|
|
|
|
|
PRInt32 maxContentProcesses = Preferences::GetInt("dom.ipc.processCount", 1);
|
|
|
|
if (maxContentProcesses < 1)
|
|
|
|
maxContentProcesses = 1;
|
|
|
|
|
2012-07-13 14:10:20 -07:00
|
|
|
if (gNonAppContentParents->Length() >= PRUint32(maxContentProcesses)) {
|
|
|
|
PRUint32 idx = rand() % gNonAppContentParents->Length();
|
|
|
|
ContentParent* p = (*gNonAppContentParents)[idx];
|
|
|
|
NS_ASSERTION(p->IsAlive(), "Non-alive contentparent in gNonAppContentParents?");
|
2011-08-02 12:35:42 -07:00
|
|
|
return p;
|
2011-03-26 13:16:45 -07:00
|
|
|
}
|
2011-08-02 12:35:42 -07:00
|
|
|
|
2012-07-13 14:10:20 -07:00
|
|
|
nsRefPtr<ContentParent> p =
|
|
|
|
new ContentParent(/* appManifestURL = */ EmptyString());
|
2011-08-02 12:35:42 -07:00
|
|
|
p->Init();
|
2012-07-13 14:10:20 -07:00
|
|
|
gNonAppContentParents->AppendElement(p);
|
2011-08-02 12:35:42 -07:00
|
|
|
return p;
|
|
|
|
}
|
2010-12-26 12:03:52 -08:00
|
|
|
|
2012-07-13 14:10:20 -07:00
|
|
|
ContentParent*
|
|
|
|
ContentParent::GetForApp(const nsAString& aAppManifestURL)
|
|
|
|
{
|
|
|
|
if (aAppManifestURL.IsEmpty()) {
|
|
|
|
return GetNewOrUsed();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gAppContentParents) {
|
|
|
|
gAppContentParents =
|
|
|
|
new nsDataHashtable<nsStringHashKey, ContentParent*>();
|
|
|
|
gAppContentParents->Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Each app gets its own ContentParent instance.
|
|
|
|
ContentParent* p = gAppContentParents->Get(aAppManifestURL);
|
|
|
|
if (!p) {
|
|
|
|
p = new ContentParent(aAppManifestURL);
|
|
|
|
p->Init();
|
|
|
|
gAppContentParents->Put(aAppManifestURL, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
AppendToTArray(const nsAString& aKey, ContentParent* aValue, void* aArray)
|
|
|
|
{
|
|
|
|
nsTArray<ContentParent*> *array =
|
|
|
|
static_cast<nsTArray<ContentParent*>*>(aArray);
|
|
|
|
array->AppendElement(aValue);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2011-08-02 12:35:42 -07:00
|
|
|
void
|
|
|
|
ContentParent::GetAll(nsTArray<ContentParent*>& aArray)
|
|
|
|
{
|
2012-07-13 14:10:20 -07:00
|
|
|
aArray.Clear();
|
|
|
|
|
|
|
|
if (gNonAppContentParents) {
|
|
|
|
aArray.AppendElements(*gNonAppContentParents);
|
2011-08-02 12:35:42 -07:00
|
|
|
}
|
|
|
|
|
2012-07-13 14:10:20 -07:00
|
|
|
if (gAppContentParents) {
|
|
|
|
gAppContentParents->EnumerateRead(&AppendToTArray, &aArray);
|
|
|
|
}
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-26 12:03:52 -08:00
|
|
|
void
|
|
|
|
ContentParent::Init()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
2011-10-17 07:59:28 -07:00
|
|
|
obs->AddObserver(this, "xpcom-shutdown", false);
|
|
|
|
obs->AddObserver(this, NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC, false);
|
|
|
|
obs->AddObserver(this, "child-memory-reporter-request", false);
|
|
|
|
obs->AddObserver(this, "memory-pressure", false);
|
|
|
|
obs->AddObserver(this, "child-gc-request", false);
|
|
|
|
obs->AddObserver(this, "child-cc-request", false);
|
2012-04-19 17:13:20 -07:00
|
|
|
obs->AddObserver(this, "last-pb-context-exited", false);
|
2011-07-20 21:37:32 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
2011-10-17 07:59:28 -07:00
|
|
|
obs->AddObserver(this, "a11y-init-or-shutdown", false);
|
2011-07-20 21:37:32 -07:00
|
|
|
#endif
|
2010-12-26 12:03:52 -08:00
|
|
|
}
|
2012-04-03 21:09:20 -07:00
|
|
|
Preferences::AddStrongObserver(this, "");
|
2010-12-26 12:03:52 -08:00
|
|
|
nsCOMPtr<nsIThreadInternal>
|
|
|
|
threadInt(do_QueryInterface(NS_GetCurrentThread()));
|
|
|
|
if (threadInt) {
|
2011-12-02 04:33:05 -08:00
|
|
|
threadInt->AddObserver(this);
|
2010-12-26 12:03:52 -08:00
|
|
|
}
|
|
|
|
if (obs) {
|
2011-08-02 12:35:42 -07:00
|
|
|
obs->NotifyObservers(static_cast<nsIObserver*>(this), "ipc:content-created", nsnull);
|
2010-12-26 12:03:52 -08:00
|
|
|
}
|
2011-07-20 21:37:32 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
// If accessibility is running in chrome process then start it in content
|
|
|
|
// process.
|
|
|
|
if (nsIPresShell::IsAccessibilityActive()) {
|
2011-09-18 12:02:27 -07:00
|
|
|
unused << SendActivateA11y();
|
2011-07-20 21:37:32 -07:00
|
|
|
}
|
|
|
|
#endif
|
2010-12-26 12:03:52 -08:00
|
|
|
}
|
|
|
|
|
2012-07-17 11:27:27 -07:00
|
|
|
void
|
|
|
|
ContentParent::ShutDown()
|
|
|
|
{
|
|
|
|
if (mIsAlive) {
|
|
|
|
// Close() can only be called once. It kicks off the
|
|
|
|
// destruction sequence.
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
// NB: must MarkAsDead() here so that this isn't accidentally
|
|
|
|
// returned from Get*() while in the midst of shutdown.
|
|
|
|
MarkAsDead();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentParent::MarkAsDead()
|
|
|
|
{
|
|
|
|
if (!mAppManifestURL.IsEmpty()) {
|
|
|
|
if (gAppContentParents) {
|
|
|
|
gAppContentParents->Remove(mAppManifestURL);
|
|
|
|
if (!gAppContentParents->Count()) {
|
|
|
|
delete gAppContentParents;
|
|
|
|
gAppContentParents = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (gNonAppContentParents) {
|
|
|
|
gNonAppContentParents->RemoveElement(this);
|
|
|
|
if (!gNonAppContentParents->Length()) {
|
|
|
|
delete gNonAppContentParents;
|
|
|
|
gNonAppContentParents = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gPrivateContent) {
|
|
|
|
gPrivateContent->RemoveElement(this);
|
|
|
|
if (!gPrivateContent->Length()) {
|
|
|
|
delete gPrivateContent;
|
|
|
|
gPrivateContent = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsAlive = false;
|
|
|
|
}
|
|
|
|
|
2010-11-24 05:58:21 -08:00
|
|
|
void
|
|
|
|
ContentParent::OnChannelConnected(int32 pid)
|
|
|
|
{
|
|
|
|
ProcessHandle handle;
|
|
|
|
if (!base::OpenPrivilegedProcessHandle(pid, &handle)) {
|
|
|
|
NS_WARNING("Can't open handle to child process.");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SetOtherProcess(handle);
|
2011-02-14 14:34:46 -08:00
|
|
|
|
|
|
|
#if defined(ANDROID) || defined(LINUX)
|
|
|
|
// Check nice preference
|
2012-04-03 21:09:20 -07:00
|
|
|
PRInt32 nice = Preferences::GetInt("dom.ipc.content.nice", 0);
|
2011-02-14 14:34:46 -08:00
|
|
|
|
|
|
|
// Environment variable overrides preference
|
|
|
|
char* relativeNicenessStr = getenv("MOZ_CHILD_PROCESS_RELATIVE_NICENESS");
|
|
|
|
if (relativeNicenessStr) {
|
|
|
|
nice = atoi(relativeNicenessStr);
|
|
|
|
}
|
|
|
|
|
2011-06-17 06:26:17 -07:00
|
|
|
/* make the GUI thread have higher priority on single-cpu devices */
|
2011-06-16 19:59:00 -07:00
|
|
|
nsCOMPtr<nsIPropertyBag2> infoService = do_GetService(NS_SYSTEMINFO_CONTRACTID);
|
|
|
|
if (infoService) {
|
|
|
|
PRInt32 cpus;
|
|
|
|
nsresult rv = infoService->GetPropertyAsInt32(NS_LITERAL_STRING("cpucount"), &cpus);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
cpus = 1;
|
|
|
|
}
|
|
|
|
if (nice != 0 && cpus == 1) {
|
|
|
|
setpriority(PRIO_PROCESS, pid, getpriority(PRIO_PROCESS, pid) + nice);
|
|
|
|
}
|
2011-02-14 14:34:46 -08:00
|
|
|
}
|
|
|
|
#endif
|
2010-11-24 05:58:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
2011-08-30 21:11:25 -07:00
|
|
|
|
2010-11-24 05:58:21 -08:00
|
|
|
void
|
|
|
|
DelayedDeleteSubprocess(GeckoChildProcessHost* aSubprocess)
|
|
|
|
{
|
|
|
|
XRE_GetIOMessageLoop()
|
|
|
|
->PostTask(FROM_HERE,
|
|
|
|
new DeleteTask<GeckoChildProcessHost>(aSubprocess));
|
|
|
|
}
|
2011-08-30 21:11:25 -07:00
|
|
|
|
|
|
|
// This runnable only exists to delegate ownership of the
|
|
|
|
// ContentParent to this runnable, until it's deleted by the event
|
|
|
|
// system.
|
|
|
|
struct DelayedDeleteContentParentTask : public nsRunnable
|
|
|
|
{
|
|
|
|
DelayedDeleteContentParentTask(ContentParent* aObj) : mObj(aObj) { }
|
|
|
|
|
|
|
|
// No-op
|
|
|
|
NS_IMETHODIMP Run() { return NS_OK; }
|
|
|
|
|
|
|
|
nsRefPtr<ContentParent> mObj;
|
|
|
|
};
|
|
|
|
|
2010-11-24 05:58:21 -08:00
|
|
|
}
|
|
|
|
|
2010-02-01 17:53:52 -08:00
|
|
|
void
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::ActorDestroy(ActorDestroyReason why)
|
2010-02-01 17:53:52 -08:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIThreadObserver>
|
|
|
|
kungFuDeathGrip(static_cast<nsIThreadObserver*>(this));
|
2010-12-26 12:03:52 -08:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2010-12-26 11:27:50 -08:00
|
|
|
if (obs) {
|
2010-02-01 17:53:52 -08:00
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this), "xpcom-shutdown");
|
2010-12-26 11:27:50 -08:00
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this), "memory-pressure");
|
2011-02-16 10:43:23 -08:00
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this), "child-memory-reporter-request");
|
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this), NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC);
|
2011-09-13 10:53:51 -07:00
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this), "child-gc-request");
|
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this), "child-cc-request");
|
2012-04-19 17:13:20 -07:00
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this), "last-pb-context-exited");
|
2011-07-20 21:37:32 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this), "a11y-init-or-shutdown");
|
|
|
|
#endif
|
2010-12-26 11:27:50 -08:00
|
|
|
}
|
|
|
|
|
2011-08-02 12:57:48 -07:00
|
|
|
mMessageManager->Disconnect();
|
|
|
|
|
2011-02-16 10:43:23 -08:00
|
|
|
// clear the child memory reporters
|
|
|
|
InfallibleTArray<MemoryReport> empty;
|
|
|
|
SetChildMemoryReporters(empty);
|
|
|
|
|
2010-12-26 11:27:50 -08:00
|
|
|
// remove the global remote preferences observers
|
2012-04-03 21:09:20 -07:00
|
|
|
Preferences::RemoveObserver(this, "");
|
2010-12-26 11:27:50 -08:00
|
|
|
|
|
|
|
RecvRemoveGeolocationListener();
|
|
|
|
|
2010-02-01 17:53:52 -08:00
|
|
|
nsCOMPtr<nsIThreadInternal>
|
|
|
|
threadInt(do_QueryInterface(NS_GetCurrentThread()));
|
|
|
|
if (threadInt)
|
2011-12-02 04:33:05 -08:00
|
|
|
threadInt->RemoveObserver(this);
|
2010-02-01 17:53:52 -08:00
|
|
|
if (mRunToCompletionDepth)
|
|
|
|
mRunToCompletionDepth = 0;
|
2010-04-11 17:24:45 -07:00
|
|
|
|
2012-07-17 11:27:27 -07:00
|
|
|
MarkAsDead();
|
2010-10-08 12:12:40 -07:00
|
|
|
|
|
|
|
if (obs) {
|
2010-11-24 05:58:21 -08:00
|
|
|
nsRefPtr<nsHashPropertyBag> props = new nsHashPropertyBag();
|
|
|
|
props->Init();
|
|
|
|
|
|
|
|
if (AbnormalShutdown == why) {
|
2011-10-17 07:59:28 -07:00
|
|
|
props->SetPropertyAsBool(NS_LITERAL_STRING("abnormal"), true);
|
2010-11-24 05:58:21 -08:00
|
|
|
|
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2011-06-08 12:56:31 -07:00
|
|
|
MOZ_ASSERT(ManagedPCrashReporterParent().Length() > 0);
|
|
|
|
CrashReporterParent* crashReporter =
|
|
|
|
static_cast<CrashReporterParent*>(ManagedPCrashReporterParent()[0]);
|
2010-11-24 05:58:21 -08:00
|
|
|
|
2011-06-08 12:56:31 -07:00
|
|
|
crashReporter->GenerateCrashReport(this, NULL);
|
|
|
|
|
|
|
|
nsAutoString dumpID(crashReporter->ChildDumpID());
|
2011-04-28 15:03:40 -07:00
|
|
|
props->SetPropertyAsAString(NS_LITERAL_STRING("dumpID"), dumpID);
|
2010-11-24 05:58:21 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
obs->NotifyObservers((nsIPropertyBag2*) props, "ipc:content-shutdown", nsnull);
|
|
|
|
}
|
2010-10-08 12:12:40 -07:00
|
|
|
}
|
2010-11-24 05:58:21 -08:00
|
|
|
|
|
|
|
MessageLoop::current()->
|
|
|
|
PostTask(FROM_HERE,
|
|
|
|
NewRunnableFunction(DelayedDeleteSubprocess, mSubprocess));
|
|
|
|
mSubprocess = NULL;
|
2011-08-30 21:11:25 -07:00
|
|
|
|
|
|
|
// IPDL rules require actors to live on past ActorDestroy, but it
|
|
|
|
// may be that the kungFuDeathGrip above is the last reference to
|
|
|
|
// |this|. If so, when we go out of scope here, we're deleted and
|
|
|
|
// all hell breaks loose.
|
|
|
|
//
|
|
|
|
// This runnable ensures that a reference to |this| lives on at
|
|
|
|
// least until after the current task finishes running.
|
|
|
|
NS_DispatchToCurrentThread(new DelayedDeleteContentParentTask(this));
|
2010-02-01 17:53:52 -08:00
|
|
|
}
|
|
|
|
|
2009-08-12 09:18:08 -07:00
|
|
|
TabParent*
|
2012-06-21 18:17:52 -07:00
|
|
|
ContentParent::CreateTab(PRUint32 aChromeFlags, bool aIsBrowserFrame)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2012-06-21 18:17:52 -07:00
|
|
|
return static_cast<TabParent*>(SendPBrowserConstructor(aChromeFlags, aIsBrowserFrame));
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 11:27:27 -07:00
|
|
|
void
|
|
|
|
ContentParent::NotifyTabDestroyed(PBrowserParent* aTab)
|
|
|
|
{
|
|
|
|
// There can be more than one PBrowser for a given app process
|
|
|
|
// because of popup windows. When the last one closes, shut
|
|
|
|
// us down.
|
|
|
|
if (IsForApp() && ManagedPBrowserParent().Length() == 1) {
|
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableMethod(this, &ContentParent::ShutDown));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-12 11:31:48 -07:00
|
|
|
TestShellParent*
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::CreateTestShell()
|
2009-08-12 11:31:48 -07:00
|
|
|
{
|
2009-09-09 15:00:14 -07:00
|
|
|
return static_cast<TestShellParent*>(SendPTestShellConstructor());
|
2009-08-12 11:31:48 -07:00
|
|
|
}
|
|
|
|
|
2009-11-11 00:34:08 -08:00
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::DestroyTestShell(TestShellParent* aTestShell)
|
2009-11-11 00:34:08 -08:00
|
|
|
{
|
2009-12-03 00:16:14 -08:00
|
|
|
return PTestShellParent::Send__delete__(aTestShell);
|
2009-11-11 00:34:08 -08:00
|
|
|
}
|
|
|
|
|
2011-06-23 16:31:58 -07:00
|
|
|
TestShellParent*
|
|
|
|
ContentParent::GetTestShellSingleton()
|
|
|
|
{
|
|
|
|
if (!ManagedPTestShellParent().Length())
|
|
|
|
return nsnull;
|
|
|
|
return static_cast<TestShellParent*>(ManagedPTestShellParent()[0]);
|
|
|
|
}
|
|
|
|
|
2012-07-13 14:10:20 -07:00
|
|
|
ContentParent::ContentParent(const nsAString& aAppManifestURL)
|
2011-04-29 12:21:57 -07:00
|
|
|
: mGeolocationWatchID(-1)
|
2010-02-01 17:53:52 -08:00
|
|
|
, mRunToCompletionDepth(0)
|
2010-03-29 13:29:45 -07:00
|
|
|
, mShouldCallUnblockChild(false)
|
2010-04-11 17:24:45 -07:00
|
|
|
, mIsAlive(true)
|
2011-08-02 12:35:42 -07:00
|
|
|
, mSendPermissionUpdates(false)
|
2012-07-13 14:10:20 -07:00
|
|
|
, mAppManifestURL(aAppManifestURL)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2012-04-10 12:57:20 -07:00
|
|
|
// From this point on, NS_WARNING, NS_ASSERTION, etc. should print out the
|
|
|
|
// PID along with the warning.
|
|
|
|
nsDebugImpl::SetMultiprocessMode("Parent");
|
|
|
|
|
2009-09-02 17:18:27 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2009-12-06 22:03:49 -08:00
|
|
|
mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content);
|
2012-07-17 16:59:44 -07:00
|
|
|
|
|
|
|
bool useOffMainThreadCompositing = !!CompositorParent::CompositorLoop();
|
|
|
|
if (useOffMainThreadCompositing) {
|
|
|
|
// FIXME. Oh please fixme. Somehow.
|
|
|
|
//
|
|
|
|
// We need the child process's ProcessHandle to do
|
|
|
|
// PCompositor::Open() below (on win32 ... sigh). We don't
|
|
|
|
// get that until onconnect, but that's too late to open the
|
|
|
|
// compositor channel below.
|
|
|
|
mSubprocess->SyncLaunch();
|
|
|
|
} else {
|
|
|
|
mSubprocess->AsyncLaunch();
|
|
|
|
}
|
2009-10-27 14:52:37 -07:00
|
|
|
Open(mSubprocess->GetChannel(), mSubprocess->GetChildProcessHandle());
|
2011-09-30 00:00:48 -07:00
|
|
|
unused << SendSetID(gContentChildID++);
|
2010-03-10 21:33:00 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
|
|
|
|
nsChromeRegistryChrome* chromeRegistry =
|
|
|
|
static_cast<nsChromeRegistryChrome*>(registrySvc.get());
|
|
|
|
chromeRegistry->SendRegisteredChrome(this);
|
2011-08-02 12:57:48 -07:00
|
|
|
mMessageManager = nsFrameMessageManager::NewProcessMessageManager(this);
|
2011-10-04 13:31:00 -07:00
|
|
|
|
|
|
|
if (gAppData) {
|
|
|
|
nsCString version(gAppData->version);
|
|
|
|
nsCString buildID(gAppData->buildID);
|
|
|
|
|
|
|
|
//Sending all information to content process
|
2012-07-17 16:59:44 -07:00
|
|
|
unused << SendAppInfo(version, buildID);
|
2011-10-04 13:31:00 -07:00
|
|
|
}
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::~ContentParent()
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2010-11-24 05:58:21 -08:00
|
|
|
if (OtherProcess())
|
|
|
|
base::CloseProcessHandle(OtherProcess());
|
|
|
|
|
2009-09-02 17:18:27 -07:00
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
2012-07-13 14:10:20 -07:00
|
|
|
|
|
|
|
// We should be removed from all these lists in ActorDestroy.
|
|
|
|
MOZ_ASSERT(!gPrivateContent || !gPrivateContent->Contains(this));
|
|
|
|
if (mAppManifestURL.IsEmpty()) {
|
|
|
|
MOZ_ASSERT(!gNonAppContentParents ||
|
|
|
|
!gNonAppContentParents->Contains(this));
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(!gAppContentParents ||
|
|
|
|
!gAppContentParents->Get(mAppManifestURL));
|
|
|
|
}
|
2010-04-11 17:24:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::IsAlive()
|
2010-04-11 17:24:45 -07:00
|
|
|
{
|
|
|
|
return mIsAlive;
|
2009-09-02 17:18:27 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 11:27:27 -07:00
|
|
|
bool
|
|
|
|
ContentParent::IsForApp()
|
|
|
|
{
|
|
|
|
return !mAppManifestURL.IsEmpty();
|
|
|
|
}
|
|
|
|
|
2010-05-25 17:13:47 -07:00
|
|
|
bool
|
2010-11-08 18:49:00 -08:00
|
|
|
ContentParent::RecvReadPrefsArray(InfallibleTArray<PrefTuple> *prefs)
|
2010-05-25 17:13:47 -07:00
|
|
|
{
|
2011-11-02 07:51:39 -07:00
|
|
|
Preferences::MirrorPreferences(prefs);
|
2010-05-28 11:09:15 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-12 20:04:42 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvReadFontList(InfallibleTArray<FontListEntry>* retValue)
|
|
|
|
{
|
|
|
|
#ifdef ANDROID
|
|
|
|
gfxAndroidPlatform::GetPlatform()->GetFontList(retValue);
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-09 11:07:38 -07:00
|
|
|
bool
|
2010-11-08 18:49:00 -08:00
|
|
|
ContentParent::RecvReadPermissions(InfallibleTArray<IPC::Permission>* aPermissions)
|
2010-07-15 07:04:25 -07:00
|
|
|
{
|
2010-10-09 11:07:38 -07:00
|
|
|
#ifdef 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 Chrome process !");
|
|
|
|
|
2010-10-21 11:36:39 -07:00
|
|
|
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
2011-09-18 12:02:27 -07:00
|
|
|
DebugOnly<nsresult> rv = permissionManager->GetEnumerator(getter_AddRefs(enumerator));
|
2010-10-09 11:07:38 -07:00
|
|
|
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "Could not get enumerator!");
|
|
|
|
while(1) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasMore;
|
2010-10-09 11:07:38 -07:00
|
|
|
enumerator->HasMoreElements(&hasMore);
|
|
|
|
if (!hasMore)
|
|
|
|
break;
|
2010-10-21 11:36:39 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> supp;
|
|
|
|
enumerator->GetNext(getter_AddRefs(supp));
|
2010-10-09 11:07:38 -07:00
|
|
|
nsCOMPtr<nsIPermission> perm = do_QueryInterface(supp);
|
|
|
|
|
|
|
|
nsCString host;
|
|
|
|
perm->GetHost(host);
|
|
|
|
nsCString type;
|
|
|
|
perm->GetType(type);
|
|
|
|
PRUint32 capability;
|
|
|
|
perm->GetCapability(&capability);
|
|
|
|
PRUint32 expireType;
|
|
|
|
perm->GetExpireType(&expireType);
|
|
|
|
PRInt64 expireTime;
|
|
|
|
perm->GetExpireTime(&expireTime);
|
|
|
|
|
|
|
|
aPermissions->AppendElement(IPC::Permission(host, type, capability,
|
|
|
|
expireType, expireTime));
|
2010-07-15 07:04:25 -07:00
|
|
|
}
|
2010-10-09 11:07:38 -07:00
|
|
|
|
|
|
|
// Ask for future changes
|
2011-08-02 12:35:42 -07:00
|
|
|
mSendPermissionUpdates = true;
|
2010-10-09 11:07:38 -07:00
|
|
|
#endif
|
|
|
|
|
2011-04-29 16:46:20 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvSetClipboardText(const nsString& text, const PRInt32& whichClipboard)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsString> dataWrapper =
|
|
|
|
do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
rv = dataWrapper->SetData(text);
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
2012-04-16 19:14:01 -07:00
|
|
|
trans->Init(nsnull);
|
2011-02-28 21:36:43 -08:00
|
|
|
|
|
|
|
// If our data flavor has already been added, this will fail. But we don't care
|
|
|
|
trans->AddDataFlavor(kUnicodeMime);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> nsisupportsDataWrapper =
|
|
|
|
do_QueryInterface(dataWrapper);
|
|
|
|
|
|
|
|
rv = trans->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
|
|
|
|
text.Length() * sizeof(PRUnichar));
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
clipboard->SetData(trans, NULL, whichClipboard);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvGetClipboardText(const PRInt32& whichClipboard, nsString* text)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
2012-04-16 19:14:01 -07:00
|
|
|
trans->Init(nsnull);
|
2011-02-28 21:36:43 -08:00
|
|
|
|
|
|
|
clipboard->GetData(trans, whichClipboard);
|
|
|
|
nsCOMPtr<nsISupports> tmp;
|
|
|
|
PRUint32 len;
|
2011-08-09 12:38:26 -07:00
|
|
|
rv = trans->GetTransferData(kUnicodeMime, getter_AddRefs(tmp), &len);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return false;
|
2011-02-28 21:36:43 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupportsString> supportsString = do_QueryInterface(tmp);
|
|
|
|
// No support for non-text data
|
2011-08-09 12:38:26 -07:00
|
|
|
if (!supportsString)
|
|
|
|
return false;
|
2011-02-28 21:36:43 -08:00
|
|
|
supportsString->GetData(*text);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvEmptyClipboard()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
clipboard->EmptyClipboard(nsIClipboard::kGlobalClipboard);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-28 23:19:26 -07:00
|
|
|
ContentParent::RecvClipboardHasText(bool* hasText)
|
2011-02-28 21:36:43 -08:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
|
|
|
clipboard->HasDataMatchingFlavors(sClipboardTextFlavors, 1,
|
|
|
|
nsIClipboard::kGlobalClipboard, hasText);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-30 11:04:41 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvGetSystemColors(const PRUint32& colorsCount, InfallibleTArray<PRUint32>* colors)
|
|
|
|
{
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2011-07-27 17:34:47 -07:00
|
|
|
NS_ASSERTION(AndroidBridge::Bridge() != nsnull, "AndroidBridge is not available");
|
|
|
|
if (AndroidBridge::Bridge() == nsnull) {
|
|
|
|
// Do not fail - the colors won't be right, but it's not critical
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-30 11:04:41 -07:00
|
|
|
|
|
|
|
colors->AppendElements(colorsCount);
|
|
|
|
|
|
|
|
// The array elements correspond to the members of AndroidSystemColors structure,
|
|
|
|
// so just pass the pointer to the elements buffer
|
|
|
|
AndroidBridge::Bridge()->GetSystemColors((AndroidSystemColors*)colors->Elements());
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-06-13 14:02:13 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvGetIconForExtension(const nsCString& aFileExt, const PRUint32& aIconSize, InfallibleTArray<PRUint8>* bits)
|
|
|
|
{
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2011-07-27 17:34:47 -07:00
|
|
|
NS_ASSERTION(AndroidBridge::Bridge() != nsnull, "AndroidBridge is not available");
|
|
|
|
if (AndroidBridge::Bridge() == nsnull) {
|
|
|
|
// Do not fail - just no icon will be shown
|
|
|
|
return true;
|
|
|
|
}
|
2011-06-13 14:02:13 -07:00
|
|
|
|
|
|
|
bits->AppendElements(aIconSize * aIconSize * 4);
|
|
|
|
|
|
|
|
AndroidBridge::Bridge()->GetIconForExtension(aFileExt, aIconSize, bits->Elements());
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-07-26 18:14:52 -07:00
|
|
|
bool
|
2011-09-28 23:19:26 -07:00
|
|
|
ContentParent::RecvGetShowPasswordSetting(bool* showPassword)
|
2011-07-26 18:14:52 -07:00
|
|
|
{
|
|
|
|
// default behavior is to show the last password character
|
2011-10-17 07:59:28 -07:00
|
|
|
*showPassword = true;
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2011-07-26 18:14:52 -07:00
|
|
|
NS_ASSERTION(AndroidBridge::Bridge() != nsnull, "AndroidBridge is not available");
|
|
|
|
if (AndroidBridge::Bridge() != nsnull)
|
|
|
|
*showPassword = AndroidBridge::Bridge()->GetShowPasswordSetting();
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-20 23:36:17 -07:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS3(ContentParent,
|
2010-02-01 17:53:52 -08:00
|
|
|
nsIObserver,
|
2010-09-20 21:16:37 -07:00
|
|
|
nsIThreadObserver,
|
2012-03-20 23:36:17 -07:00
|
|
|
nsIDOMGeoPositionCallback)
|
2009-09-02 17:18:27 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const PRUnichar* aData)
|
2009-09-02 17:18:27 -07:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown") && mSubprocess) {
|
2009-12-06 22:03:49 -08:00
|
|
|
Close();
|
2010-11-24 05:58:21 -08:00
|
|
|
NS_ASSERTION(!mSubprocess, "Close should have nulled mSubprocess");
|
2009-09-02 17:18:27 -07:00
|
|
|
}
|
2010-05-11 05:44:12 -07:00
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
if (!mIsAlive || !mSubprocess)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-12-11 14:36:08 -08:00
|
|
|
// listening for memory pressure event
|
|
|
|
if (!strcmp(aTopic, "memory-pressure")) {
|
2010-12-26 12:03:52 -08:00
|
|
|
unused << SendFlushMemory(nsDependentString(aData));
|
2010-12-11 14:36:08 -08:00
|
|
|
}
|
2010-05-25 17:13:47 -07:00
|
|
|
// listening for remotePrefs...
|
2010-12-11 14:36:08 -08:00
|
|
|
else if (!strcmp(aTopic, "nsPref:changed")) {
|
2010-05-25 17:13:47 -07:00
|
|
|
// We know prefs are ASCII here.
|
|
|
|
NS_LossyConvertUTF16toASCII strData(aData);
|
2010-10-19 13:35:08 -07:00
|
|
|
|
2011-11-02 07:51:39 -07:00
|
|
|
PrefTuple pref;
|
|
|
|
bool prefNeedUpdate = Preferences::MirrorPreference(strData.get(), &pref);
|
2011-02-11 13:50:11 -08:00
|
|
|
if (prefNeedUpdate) {
|
2011-03-30 10:40:48 -07:00
|
|
|
if (!SendPreferenceUpdate(pref)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2011-01-05 20:54:47 -08:00
|
|
|
} else {
|
2011-03-30 10:40:48 -07:00
|
|
|
// Pref wasn't found. It was probably removed.
|
|
|
|
if (!SendClearUserPreference(strData)) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2011-01-05 20:54:47 -08:00
|
|
|
}
|
2010-05-25 17:13:47 -07:00
|
|
|
}
|
2010-07-19 11:33:33 -07:00
|
|
|
else if (!strcmp(aTopic, NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC)) {
|
2010-05-11 05:44:12 -07:00
|
|
|
NS_ConvertUTF16toUTF8 dataStr(aData);
|
|
|
|
const char *offline = dataStr.get();
|
2010-07-19 11:33:33 -07:00
|
|
|
if (!SendSetOffline(!strcmp(offline, "true") ? true : false))
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2010-05-11 05:44:12 -07:00
|
|
|
}
|
2010-09-15 09:44:57 -07:00
|
|
|
// listening for alert notifications
|
|
|
|
else if (!strcmp(aTopic, "alertfinished") ||
|
|
|
|
!strcmp(aTopic, "alertclickcallback") ) {
|
|
|
|
if (!SendNotifyAlertsObserver(nsDependentCString(aTopic),
|
|
|
|
nsDependentString(aData)))
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2011-02-16 10:43:23 -08:00
|
|
|
else if (!strcmp(aTopic, "child-memory-reporter-request")) {
|
2011-09-18 12:02:27 -07:00
|
|
|
unused << SendPMemoryReportRequestConstructor();
|
2011-09-13 10:53:51 -07:00
|
|
|
}
|
|
|
|
else if (!strcmp(aTopic, "child-gc-request")){
|
2012-07-17 16:59:44 -07:00
|
|
|
unused << SendGarbageCollect();
|
2011-09-13 10:53:51 -07:00
|
|
|
}
|
|
|
|
else if (!strcmp(aTopic, "child-cc-request")){
|
2012-07-17 16:59:44 -07:00
|
|
|
unused << SendCycleCollect();
|
2011-02-16 10:43:23 -08:00
|
|
|
}
|
2012-04-19 17:13:20 -07:00
|
|
|
else if (!strcmp(aTopic, "last-pb-context-exited")) {
|
|
|
|
unused << SendLastPrivateDocShellDestroyed();
|
|
|
|
}
|
2011-07-20 21:37:32 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
// Make sure accessibility is running in content process when accessibility
|
|
|
|
// gets initiated in chrome process.
|
|
|
|
else if (aData && (*aData == '1') &&
|
|
|
|
!strcmp(aTopic, "a11y-init-or-shutdown")) {
|
2011-09-18 12:02:27 -07:00
|
|
|
unused << SendActivateA11y();
|
2011-07-20 21:37:32 -07:00
|
|
|
}
|
|
|
|
#endif
|
2011-02-16 10:43:23 -08:00
|
|
|
|
2009-09-02 17:18:27 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
PBrowserParent*
|
2012-06-21 18:17:52 -07:00
|
|
|
ContentParent::AllocPBrowser(const PRUint32& aChromeFlags, const bool& aIsBrowserFrame)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2010-03-26 11:39:39 -07:00
|
|
|
TabParent* parent = new TabParent();
|
|
|
|
if (parent){
|
|
|
|
NS_ADDREF(parent);
|
|
|
|
}
|
|
|
|
return parent;
|
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
|
|
|
ContentParent::DeallocPBrowser(PBrowserParent* frame)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2010-03-26 11:39:39 -07:00
|
|
|
TabParent* parent = static_cast<TabParent*>(frame);
|
|
|
|
NS_RELEASE(parent);
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
PDeviceStorageRequestParent*
|
|
|
|
ContentParent::AllocPDeviceStorageRequest(const DeviceStorageParams& aParams)
|
|
|
|
{
|
|
|
|
return new DeviceStorageRequestParent(aParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPDeviceStorageRequest(PDeviceStorageRequestParent* doomed)
|
|
|
|
{
|
|
|
|
delete doomed;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-24 06:15:03 -08:00
|
|
|
PCrashReporterParent*
|
2011-06-08 12:56:31 -07:00
|
|
|
ContentParent::AllocPCrashReporter(const NativeThreadId& tid,
|
|
|
|
const PRUint32& processType)
|
2010-11-24 06:15:03 -08:00
|
|
|
{
|
2011-06-08 12:56:31 -07:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
2011-06-29 20:44:28 -07:00
|
|
|
return new CrashReporterParent();
|
2011-06-08 12:56:31 -07:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvPCrashReporterConstructor(PCrashReporterParent* actor,
|
|
|
|
const NativeThreadId& tid,
|
|
|
|
const PRUint32& processType)
|
|
|
|
{
|
|
|
|
static_cast<CrashReporterParent*>(actor)->SetChildData(tid, processType);
|
|
|
|
return true;
|
2010-11-24 06:15:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPCrashReporter(PCrashReporterParent* crashreporter)
|
|
|
|
{
|
|
|
|
delete crashreporter;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-10-05 15:15:45 -07:00
|
|
|
PHalParent*
|
|
|
|
ContentParent::AllocPHal()
|
|
|
|
{
|
|
|
|
return CreateHalParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPHal(PHalParent* aHal)
|
|
|
|
{
|
|
|
|
delete aHal;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-14 04:24:20 -07:00
|
|
|
PIndexedDBParent*
|
|
|
|
ContentParent::AllocPIndexedDB()
|
|
|
|
{
|
|
|
|
return new IndexedDBParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPIndexedDB(PIndexedDBParent* aActor)
|
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvPIndexedDBConstructor(PIndexedDBParent* aActor)
|
|
|
|
{
|
|
|
|
nsRefPtr<IndexedDatabaseManager> mgr = IndexedDatabaseManager::GetOrCreate();
|
|
|
|
NS_ENSURE_TRUE(mgr, false);
|
|
|
|
|
|
|
|
if (!IndexedDatabaseManager::IsMainProcess()) {
|
|
|
|
NS_RUNTIMEABORT("Not supported yet!");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<IDBFactory> factory;
|
|
|
|
nsresult rv = IDBFactory::Create(getter_AddRefs(factory));
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
NS_ASSERTION(factory, "This should never be null!");
|
|
|
|
|
|
|
|
IndexedDBParent* actor = static_cast<IndexedDBParent*>(aActor);
|
|
|
|
actor->mFactory = factory;
|
|
|
|
actor->mASCIIOrigin = factory->GetASCIIOrigin();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-16 10:43:23 -08:00
|
|
|
PMemoryReportRequestParent*
|
|
|
|
ContentParent::AllocPMemoryReportRequest()
|
|
|
|
{
|
|
|
|
MemoryReportRequestParent* parent = new MemoryReportRequestParent();
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPMemoryReportRequest(PMemoryReportRequestParent* actor)
|
|
|
|
{
|
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentParent::SetChildMemoryReporters(const InfallibleTArray<MemoryReport>& report)
|
|
|
|
{
|
2011-06-16 11:34:09 -07:00
|
|
|
nsCOMPtr<nsIMemoryReporterManager> mgr =
|
|
|
|
do_GetService("@mozilla.org/memory-reporter-manager;1");
|
2011-04-29 16:55:04 -07:00
|
|
|
for (PRInt32 i = 0; i < mMemoryReporters.Count(); i++)
|
2011-02-16 10:43:23 -08:00
|
|
|
mgr->UnregisterReporter(mMemoryReporters[i]);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < report.Length(); i++) {
|
2011-06-05 18:22:45 -07:00
|
|
|
nsCString process = report[i].process();
|
|
|
|
nsCString path = report[i].path();
|
|
|
|
PRInt32 kind = report[i].kind();
|
2011-06-16 11:34:09 -07:00
|
|
|
PRInt32 units = report[i].units();
|
|
|
|
PRInt64 amount = report[i].amount();
|
2011-06-05 18:22:45 -07:00
|
|
|
nsCString desc = report[i].desc();
|
2011-02-16 10:43:23 -08:00
|
|
|
|
2011-06-16 11:34:09 -07:00
|
|
|
nsRefPtr<nsMemoryReporter> r =
|
|
|
|
new nsMemoryReporter(process, path, kind, units, amount, desc);
|
|
|
|
|
|
|
|
mMemoryReporters.AppendObject(r);
|
|
|
|
mgr->RegisterReporter(r);
|
2011-02-16 10:43:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs =
|
|
|
|
do_GetService("@mozilla.org/observer-service;1");
|
|
|
|
if (obs)
|
|
|
|
obs->NotifyObservers(nsnull, "child-memory-reporter-update", nsnull);
|
|
|
|
}
|
|
|
|
|
2009-09-09 15:59:06 -07:00
|
|
|
PTestShellParent*
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::AllocPTestShell()
|
2009-08-12 11:31:48 -07:00
|
|
|
{
|
|
|
|
return new TestShellParent();
|
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::DeallocPTestShell(PTestShellParent* shell)
|
2009-08-12 11:31:48 -07:00
|
|
|
{
|
|
|
|
delete shell;
|
2009-09-17 16:09:20 -07:00
|
|
|
return true;
|
2009-08-12 11:31:48 -07:00
|
|
|
}
|
2010-11-16 20:14:19 -08:00
|
|
|
|
|
|
|
PAudioParent*
|
|
|
|
ContentParent::AllocPAudio(const PRInt32& numChannels,
|
|
|
|
const PRInt32& rate,
|
|
|
|
const PRInt32& format)
|
|
|
|
{
|
2011-03-23 20:23:33 -07:00
|
|
|
#if defined(MOZ_SYDNEYAUDIO)
|
2010-11-16 20:14:19 -08:00
|
|
|
AudioParent *parent = new AudioParent(numChannels, rate, format);
|
2010-11-25 20:13:54 -08:00
|
|
|
NS_ADDREF(parent);
|
2010-11-16 20:14:19 -08:00
|
|
|
return parent;
|
2011-03-23 20:23:33 -07:00
|
|
|
#else
|
|
|
|
return nsnull;
|
|
|
|
#endif
|
2010-11-16 20:14:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPAudio(PAudioParent* doomed)
|
|
|
|
{
|
2011-03-23 20:23:33 -07:00
|
|
|
#if defined(MOZ_SYDNEYAUDIO)
|
2010-11-16 20:14:19 -08:00
|
|
|
AudioParent *parent = static_cast<AudioParent*>(doomed);
|
|
|
|
NS_RELEASE(parent);
|
2011-03-23 20:23:33 -07:00
|
|
|
#endif
|
2010-11-16 20:14:19 -08:00
|
|
|
return true;
|
|
|
|
}
|
2009-08-12 11:31:48 -07:00
|
|
|
|
2009-08-18 12:05:15 -07:00
|
|
|
PNeckoParent*
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::AllocPNecko()
|
2009-08-18 12:05:15 -07:00
|
|
|
{
|
|
|
|
return new NeckoParent();
|
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::DeallocPNecko(PNeckoParent* 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
|
|
|
PExternalHelperAppParent*
|
|
|
|
ContentParent::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
|
|
|
{
|
|
|
|
ExternalHelperAppParent *parent = new ExternalHelperAppParent(uri, aContentLength);
|
|
|
|
parent->AddRef();
|
2010-11-21 11:21:59 -08:00
|
|
|
parent->Init(this, aMimeContentType, aContentDisposition, aForceSave, aReferrer);
|
2010-09-15 15:55:08 -07:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPExternalHelperApp(PExternalHelperAppParent* aService)
|
|
|
|
{
|
|
|
|
ExternalHelperAppParent *parent = static_cast<ExternalHelperAppParent *>(aService);
|
|
|
|
parent->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-20 14:40:53 -08:00
|
|
|
PSmsParent*
|
|
|
|
ContentParent::AllocPSms()
|
|
|
|
{
|
|
|
|
return new SmsParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPSms(PSmsParent* aSms)
|
|
|
|
{
|
|
|
|
delete aSms;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-18 17:15:23 -08:00
|
|
|
PStorageParent*
|
|
|
|
ContentParent::AllocPStorage(const StorageConstructData& aData)
|
|
|
|
{
|
|
|
|
return new StorageParent(aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPStorage(PStorageParent* aActor)
|
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-03-29 13:29:45 -07:00
|
|
|
void
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::ReportChildAlreadyBlocked()
|
2010-03-29 13:29:45 -07:00
|
|
|
{
|
|
|
|
if (!mRunToCompletionDepth) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Running to completion...\n");
|
|
|
|
#endif
|
|
|
|
mRunToCompletionDepth = 1;
|
|
|
|
mShouldCallUnblockChild = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-01 17:53:52 -08:00
|
|
|
bool
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::RequestRunToCompletion()
|
2010-02-01 17:53:52 -08:00
|
|
|
{
|
|
|
|
if (!mRunToCompletionDepth &&
|
|
|
|
BlockChild()) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Running to completion...\n");
|
|
|
|
#endif
|
|
|
|
mRunToCompletionDepth = 1;
|
2010-03-29 13:29:45 -07:00
|
|
|
mShouldCallUnblockChild = true;
|
2010-02-01 17:53:52 -08:00
|
|
|
}
|
|
|
|
return !!mRunToCompletionDepth;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:50:41 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvStartVisitedQuery(const IPC::URI& aURI)
|
|
|
|
{
|
2010-07-26 12:59:34 -07:00
|
|
|
nsCOMPtr<nsIURI> newURI(aURI);
|
2010-08-05 10:07:46 -07:00
|
|
|
nsCOMPtr<IHistory> history = services::GetHistoryService();
|
|
|
|
NS_ABORT_IF_FALSE(history, "History must exist at this point.");
|
|
|
|
if (history) {
|
|
|
|
history->RegisterVisitedCallback(newURI, nsnull);
|
|
|
|
}
|
2010-07-02 08:50:41 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:50:24 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvVisitURI(const IPC::URI& uri,
|
2010-08-02 08:29:10 -07:00
|
|
|
const IPC::URI& referrer,
|
|
|
|
const PRUint32& flags)
|
2010-07-02 08:50:24 -07:00
|
|
|
{
|
2010-07-26 12:59:34 -07:00
|
|
|
nsCOMPtr<nsIURI> ourURI(uri);
|
|
|
|
nsCOMPtr<nsIURI> ourReferrer(referrer);
|
2010-08-05 10:07:46 -07:00
|
|
|
nsCOMPtr<IHistory> history = services::GetHistoryService();
|
|
|
|
NS_ABORT_IF_FALSE(history, "History must exist at this point");
|
|
|
|
if (history) {
|
|
|
|
history->VisitURI(ourURI, ourReferrer, flags);
|
|
|
|
}
|
2010-07-02 08:50:24 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:53:42 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvSetURITitle(const IPC::URI& uri,
|
|
|
|
const nsString& title)
|
|
|
|
{
|
2010-07-26 12:59:34 -07:00
|
|
|
nsCOMPtr<nsIURI> ourURI(uri);
|
2010-08-05 10:07:46 -07:00
|
|
|
nsCOMPtr<IHistory> history = services::GetHistoryService();
|
|
|
|
NS_ABORT_IF_FALSE(history, "History must exist at this point");
|
|
|
|
if (history) {
|
|
|
|
history->SetURITitle(ourURI, title);
|
|
|
|
}
|
2010-07-02 08:53:42 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-10-20 08:19:24 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvShowFilePicker(const PRInt16& mode,
|
|
|
|
const PRInt16& selectedType,
|
2011-09-28 23:19:26 -07:00
|
|
|
const bool& addToRecentDocs,
|
2010-10-20 08:19:24 -07:00
|
|
|
const nsString& title,
|
|
|
|
const nsString& defaultFile,
|
|
|
|
const nsString& defaultExtension,
|
2010-11-08 18:49:00 -08:00
|
|
|
const InfallibleTArray<nsString>& filters,
|
|
|
|
const InfallibleTArray<nsString>& filterNames,
|
|
|
|
InfallibleTArray<nsString>* files,
|
2010-10-20 08:19:24 -07:00
|
|
|
PRInt16* retValue,
|
|
|
|
nsresult* result)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFilePicker> filePicker = do_CreateInstance("@mozilla.org/filepicker;1");
|
|
|
|
if (!filePicker) {
|
|
|
|
*result = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// as the parent given to the content process would be meaningless in this
|
|
|
|
// process, always use active window as the parent
|
|
|
|
nsCOMPtr<nsIWindowWatcher> ww = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
|
|
|
|
nsCOMPtr<nsIDOMWindow> window;
|
|
|
|
ww->GetActiveWindow(getter_AddRefs(window));
|
|
|
|
|
|
|
|
// initialize the "real" picker with all data given
|
|
|
|
*result = filePicker->Init(window, title, mode);
|
|
|
|
if (NS_FAILED(*result))
|
|
|
|
return true;
|
2011-05-24 05:28:19 -07:00
|
|
|
|
|
|
|
filePicker->SetAddToRecentDocs(addToRecentDocs);
|
|
|
|
|
2010-10-20 08:19:24 -07:00
|
|
|
PRUint32 count = filters.Length();
|
|
|
|
for (PRUint32 i = 0; i < count; ++i) {
|
|
|
|
filePicker->AppendFilter(filterNames[i], filters[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
filePicker->SetDefaultString(defaultFile);
|
|
|
|
filePicker->SetDefaultExtension(defaultExtension);
|
|
|
|
filePicker->SetFilterIndex(selectedType);
|
|
|
|
|
|
|
|
// and finally open the dialog
|
|
|
|
*result = filePicker->Show(retValue);
|
|
|
|
if (NS_FAILED(*result))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (mode == nsIFilePicker::modeOpenMultiple) {
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> fileIter;
|
|
|
|
*result = filePicker->GetFiles(getter_AddRefs(fileIter));
|
|
|
|
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> singleFile;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool loop = true;
|
2010-10-20 08:19:24 -07:00
|
|
|
while (NS_SUCCEEDED(fileIter->HasMoreElements(&loop)) && loop) {
|
|
|
|
fileIter->GetNext(getter_AddRefs(singleFile));
|
|
|
|
if (singleFile) {
|
|
|
|
nsAutoString filePath;
|
|
|
|
singleFile->GetPath(filePath);
|
|
|
|
files->AppendElement(filePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-05 19:08:30 -07:00
|
|
|
nsCOMPtr<nsIFile> file;
|
2010-10-20 08:19:24 -07:00
|
|
|
filePicker->GetFile(getter_AddRefs(file));
|
|
|
|
|
|
|
|
// even with NS_OK file can be null if nothing was selected
|
|
|
|
if (file) {
|
|
|
|
nsAutoString filePath;
|
|
|
|
file->GetPath(filePath);
|
|
|
|
files->AppendElement(filePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-10 10:14:45 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvLoadURIExternal(const IPC::URI& uri)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtService(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
|
|
|
if (!extProtService)
|
|
|
|
return true;
|
|
|
|
nsCOMPtr<nsIURI> ourURI(uri);
|
|
|
|
extProtService->LoadURI(ourURI, nsnull);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-02-01 17:53:52 -08:00
|
|
|
/* void onDispatchedEvent (in nsIThreadInternal thread); */
|
|
|
|
NS_IMETHODIMP
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::OnDispatchedEvent(nsIThreadInternal *thread)
|
2012-01-18 02:23:28 -08:00
|
|
|
{
|
2011-12-02 04:33:05 -08:00
|
|
|
NS_NOTREACHED("OnDispatchedEvent unimplemented");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2010-02-01 17:53:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* void onProcessNextEvent (in nsIThreadInternal thread, in boolean mayWait, in unsigned long recursionDepth); */
|
|
|
|
NS_IMETHODIMP
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::OnProcessNextEvent(nsIThreadInternal *thread,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mayWait,
|
2010-07-19 11:33:33 -07:00
|
|
|
PRUint32 recursionDepth)
|
2010-02-01 17:53:52 -08:00
|
|
|
{
|
|
|
|
if (mRunToCompletionDepth)
|
|
|
|
++mRunToCompletionDepth;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* void afterProcessNextEvent (in nsIThreadInternal thread, in unsigned long recursionDepth); */
|
|
|
|
NS_IMETHODIMP
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::AfterProcessNextEvent(nsIThreadInternal *thread,
|
|
|
|
PRUint32 recursionDepth)
|
2010-02-01 17:53:52 -08:00
|
|
|
{
|
|
|
|
if (mRunToCompletionDepth &&
|
|
|
|
!--mRunToCompletionDepth) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("... ran to completion.\n");
|
|
|
|
#endif
|
2010-03-29 13:29:45 -07:00
|
|
|
if (mShouldCallUnblockChild) {
|
|
|
|
mShouldCallUnblockChild = false;
|
|
|
|
UnblockChild();
|
|
|
|
}
|
2010-02-01 17:53:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-05 11:11:32 -07:00
|
|
|
|
2010-09-15 09:44:57 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvShowAlertNotification(const nsString& aImageUrl, const nsString& aTitle,
|
2011-09-28 23:19:26 -07:00
|
|
|
const nsString& aText, const bool& aTextClickable,
|
2010-09-15 09:44:57 -07:00
|
|
|
const nsString& aCookie, const nsString& aName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
|
|
|
|
if (sysAlerts) {
|
|
|
|
sysAlerts->ShowAlertNotification(aImageUrl, aTitle, aText, aTextClickable,
|
|
|
|
aCookie, this, aName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-31 11:58:35 -07:00
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvSyncMessage(const nsString& aMsg, const nsString& aJSON,
|
2010-11-08 18:49:00 -08:00
|
|
|
InfallibleTArray<nsString>* aRetvals)
|
2010-08-31 11:58:35 -07:00
|
|
|
{
|
2011-08-02 12:57:48 -07:00
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
2010-08-31 11:58:35 -07:00
|
|
|
if (ppm) {
|
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
|
2011-10-17 07:59:28 -07:00
|
|
|
aMsg,true, aJSON, nsnull, aRetvals);
|
2010-08-31 11:58:35 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvAsyncMessage(const nsString& aMsg, const nsString& aJSON)
|
|
|
|
{
|
2011-08-02 12:57:48 -07:00
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
2010-08-31 11:58:35 -07:00
|
|
|
if (ppm) {
|
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.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
|
2010-11-05 10:43:13 -07:00
|
|
|
ContentParent::RecvAddGeolocationListener()
|
2010-09-20 21:16:37 -07:00
|
|
|
{
|
2010-09-27 14:23:35 -07:00
|
|
|
if (mGeolocationWatchID == -1) {
|
|
|
|
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
|
|
|
|
if (!geo) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-04-16 12:08:48 -07:00
|
|
|
jsval dummy = JSVAL_VOID;
|
|
|
|
geo->WatchPosition(this, nsnull, dummy, nsnull, &mGeolocationWatchID);
|
2010-09-20 21:16:37 -07:00
|
|
|
}
|
2010-09-20 21:16:37 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2010-11-05 10:43:13 -07:00
|
|
|
ContentParent::RecvRemoveGeolocationListener()
|
2010-09-20 21:16:37 -07:00
|
|
|
{
|
2010-09-27 14:23:35 -07:00
|
|
|
if (mGeolocationWatchID != -1) {
|
|
|
|
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
|
|
|
|
if (!geo) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
geo->ClearWatch(mGeolocationWatchID);
|
|
|
|
mGeolocationWatchID = -1;
|
2010-09-20 21:16:37 -07:00
|
|
|
}
|
2010-09-20 21:16:37 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-09-20 21:16:37 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ContentParent::HandleEvent(nsIDOMGeoPosition* postion)
|
|
|
|
{
|
2010-12-26 12:03:52 -08:00
|
|
|
unused << SendGeolocationUpdate(GeoPosition(postion));
|
2010-09-20 21:16:37 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-23 18:39:32 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvConsoleMessage(const nsString& aMessage)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIConsoleService> svc(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (!svc)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
nsRefPtr<nsConsoleMessage> msg(new nsConsoleMessage(aMessage.get()));
|
|
|
|
svc->LogMessage(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvScriptError(const nsString& aMessage,
|
|
|
|
const nsString& aSourceName,
|
|
|
|
const nsString& aSourceLine,
|
|
|
|
const PRUint32& aLineNumber,
|
|
|
|
const PRUint32& aColNumber,
|
|
|
|
const PRUint32& aFlags,
|
|
|
|
const nsCString& aCategory)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIConsoleService> svc(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (!svc)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptError> msg(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
|
|
|
nsresult rv = msg->Init(aMessage.get(), aSourceName.get(), aSourceLine.get(),
|
|
|
|
aLineNumber, aColNumber, aFlags, aCategory.get());
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
svc->LogMessage(msg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-19 17:13:20 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvPrivateDocShellsExist(const bool& aExist)
|
|
|
|
{
|
|
|
|
if (!gPrivateContent)
|
2012-07-13 14:10:20 -07:00
|
|
|
gPrivateContent = new nsTArray<ContentParent*>();
|
2012-04-19 17:13:20 -07:00
|
|
|
if (aExist) {
|
|
|
|
gPrivateContent->AppendElement(this);
|
|
|
|
} else {
|
|
|
|
gPrivateContent->RemoveElement(this);
|
|
|
|
if (!gPrivateContent->Length()) {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
obs->NotifyObservers(nsnull, "last-pb-context-exited", nsnull);
|
|
|
|
delete gPrivateContent;
|
|
|
|
gPrivateContent = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:18:08 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|