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-12-14 15:58:45 -08:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "base/basictypes.h"
|
2009-08-12 09:18:08 -07:00
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
#include "ContentParent.h"
|
|
|
|
|
2012-07-17 16:59:44 -07:00
|
|
|
#if defined(ANDROID) || defined(LINUX)
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <sys/resource.h>
|
|
|
|
#endif
|
|
|
|
|
2014-03-21 05:50:07 -07:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
2011-07-12 23:52:31 -07:00
|
|
|
#include "chrome/common/process_watcher.h"
|
|
|
|
|
2012-12-22 03:53:38 -08:00
|
|
|
#include "AppProcessChecker.h"
|
2012-12-05 19:01:58 -08:00
|
|
|
#include "AudioChannelService.h"
|
2010-11-24 06:15:03 -08:00
|
|
|
#include "CrashReporterParent.h"
|
2012-11-09 01:55:54 -08:00
|
|
|
#include "IHistory.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "IDBFactory.h"
|
|
|
|
#include "IndexedDBParent.h"
|
|
|
|
#include "IndexedDatabaseManager.h"
|
2012-08-08 19:58:06 -07:00
|
|
|
#include "mozIApplication.h"
|
2012-08-15 18:46:03 -07:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2013-11-18 13:49:53 -08:00
|
|
|
#include "mozilla/dom/asmjscache/AsmJSCache.h"
|
2013-05-17 13:17:53 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "mozilla/dom/ExternalHelperAppParent.h"
|
2014-03-25 11:37:13 -07:00
|
|
|
#include "mozilla/dom/PFileDescriptorSetParent.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "mozilla/dom/PMemoryReportRequestParent.h"
|
2013-02-14 12:41:30 -08:00
|
|
|
#include "mozilla/dom/power/PowerManagerService.h"
|
2013-04-15 05:38:48 -07:00
|
|
|
#include "mozilla/dom/DOMStorageIPC.h"
|
2012-09-13 09:37:14 -07:00
|
|
|
#include "mozilla/dom/bluetooth/PBluetoothParent.h"
|
2013-09-03 15:28:06 -07:00
|
|
|
#include "mozilla/dom/PFMRadioParent.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h"
|
2014-03-04 19:25:40 -08:00
|
|
|
#include "mozilla/dom/FileSystemRequestParent.h"
|
2013-09-06 13:44:26 -07:00
|
|
|
#include "mozilla/dom/GeolocationBinding.h"
|
2014-03-25 11:37:28 -07:00
|
|
|
#include "mozilla/dom/FileDescriptorSetParent.h"
|
2013-09-06 23:19:53 -07:00
|
|
|
#include "mozilla/dom/telephony/TelephonyParent.h"
|
2014-03-10 05:36:12 -07:00
|
|
|
#include "mozilla/dom/time/DateCacheCleaner.h"
|
2012-11-06 13:29:30 -08:00
|
|
|
#include "SmsParent.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "mozilla/hal_sandbox/PHalParent.h"
|
2013-11-26 23:59:41 -08:00
|
|
|
#include "mozilla/ipc/BackgroundChild.h"
|
|
|
|
#include "mozilla/ipc/BackgroundParent.h"
|
2009-08-12 11:31:48 -07:00
|
|
|
#include "mozilla/ipc/TestShellParent.h"
|
2013-08-16 10:59:31 -07:00
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "mozilla/layers/CompositorParent.h"
|
2012-08-29 05:24:48 -07:00
|
|
|
#include "mozilla/layers/ImageBridgeParent.h"
|
2009-08-18 12:05:15 -07:00
|
|
|
#include "mozilla/net/NeckoParent.h"
|
2012-08-15 18:46:03 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/StaticPtr.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "nsAppRunner.h"
|
2009-09-02 17:18:27 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2013-08-16 10:59:31 -07:00
|
|
|
#include "nsCDefaultURIFixup.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"
|
2012-11-09 09:52:09 -08:00
|
|
|
#include "nsConsoleService.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsDebugImpl.h"
|
2012-08-02 23:25:30 -07:00
|
|
|
#include "nsDOMFile.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"
|
2013-04-25 17:53:26 -07:00
|
|
|
#include "nsIAppsService.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsIClipboard.h"
|
|
|
|
#include "nsIDOMGeoGeolocation.h"
|
2014-01-07 04:16:07 -08:00
|
|
|
#include "mozilla/dom/WakeLock.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsIDOMWindow.h"
|
2013-09-23 14:30:40 -07:00
|
|
|
#include "nsIExternalProtocolService.h"
|
2014-01-10 17:09:20 -08:00
|
|
|
#include "nsIGfxInfo.h"
|
2013-12-13 08:28:46 -08:00
|
|
|
#include "nsIIdleService.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsIMemoryReporter.h"
|
2013-02-14 12:41:30 -08:00
|
|
|
#include "nsIMozBrowserFrame.h"
|
2013-01-10 10:16:40 -08:00
|
|
|
#include "nsIMutable.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIPresShell.h"
|
2012-08-01 23:02:29 -07:00
|
|
|
#include "nsIRemoteBlob.h"
|
2010-09-23 18:39:32 -07:00
|
|
|
#include "nsIScriptError.h"
|
2013-08-27 10:10:39 -07:00
|
|
|
#include "nsIStyleSheet.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsISupportsPrimitives.h"
|
2013-08-16 10:59:31 -07:00
|
|
|
#include "nsIURIFixup.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsIWindowWatcher.h"
|
2013-12-12 14:13:20 -08:00
|
|
|
#include "nsIXULRuntime.h"
|
2013-10-22 22:26:24 -07:00
|
|
|
#include "nsMemoryReporterManager.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2013-08-27 10:10:39 -07:00
|
|
|
#include "nsStyleSheetService.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "nsToolkitCompsCID.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
2013-04-25 17:53:26 -07:00
|
|
|
#include "PreallocatedProcessManager.h"
|
|
|
|
#include "ProcessPriorityManager.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "SandboxHal.h"
|
2012-08-01 23:02:29 -07:00
|
|
|
#include "StructuredCloneUtils.h"
|
2012-07-17 16:59:44 -07:00
|
|
|
#include "TabParent.h"
|
2012-08-23 12:33:46 -07:00
|
|
|
#include "URIUtils.h"
|
2013-05-06 21:10:31 -07:00
|
|
|
#include "nsIWebBrowserChrome.h"
|
|
|
|
#include "nsIDocShell.h"
|
2013-10-18 13:57:55 -07:00
|
|
|
#include "mozilla/net/NeckoMessageUtils.h"
|
2014-02-26 18:52:54 -08:00
|
|
|
#include "gfxPrefs.h"
|
2011-02-14 14:34:46 -08:00
|
|
|
|
2013-09-23 14:30:40 -07:00
|
|
|
#if defined(ANDROID) || defined(LINUX)
|
|
|
|
#include "nsSystemInfo.h"
|
2010-10-09 11:07:38 -07:00
|
|
|
#endif
|
|
|
|
|
2013-09-23 14:30:40 -07:00
|
|
|
#ifdef ANDROID
|
|
|
|
# include "gfxAndroidPlatform.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
|
|
|
|
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
|
|
|
|
|
2012-08-03 16:48:58 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "nsIVolume.h"
|
|
|
|
#include "nsIVolumeService.h"
|
2013-11-24 15:50:03 -08:00
|
|
|
#include "SpeakerManagerService.h"
|
2012-12-14 16:01:34 -08:00
|
|
|
using namespace mozilla::system;
|
2012-08-03 16:48:58 -07:00
|
|
|
#endif
|
|
|
|
|
2012-09-13 09:37:14 -07:00
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
#include "BluetoothParent.h"
|
|
|
|
#include "BluetoothService.h"
|
|
|
|
#endif
|
|
|
|
|
2013-07-03 00:24:32 -07:00
|
|
|
#include "JavaScriptParent.h"
|
2013-09-03 15:28:06 -07:00
|
|
|
|
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
#include "mozilla/dom/FMRadioParent.h"
|
|
|
|
#endif
|
|
|
|
|
2013-02-27 12:31:19 -08:00
|
|
|
#include "Crypto.h"
|
|
|
|
|
2013-04-03 15:13:17 -07:00
|
|
|
#ifdef MOZ_WEBSPEECH
|
|
|
|
#include "mozilla/dom/SpeechSynthesisParent.h"
|
|
|
|
#endif
|
|
|
|
|
2013-11-26 23:59:41 -08:00
|
|
|
#ifdef ENABLE_TESTS
|
2014-03-31 19:55:36 -07:00
|
|
|
#include "BackgroundChildImpl.h"
|
2013-11-26 23:59:41 -08:00
|
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
|
|
|
#include "nsIIPCBackgroundChildCreateCallback.h"
|
|
|
|
#endif
|
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
|
|
|
static const char* sClipboardTextFlavors[] = { kUnicodeMime };
|
|
|
|
|
2012-12-19 23:41:08 -08:00
|
|
|
using base::ChildPrivileges;
|
2011-01-19 22:14:12 -08:00
|
|
|
using base::KillProcess;
|
2012-09-13 09:37:14 -07:00
|
|
|
using namespace mozilla::dom::bluetooth;
|
2012-06-19 16:14:39 -07:00
|
|
|
using namespace mozilla::dom::devicestorage;
|
2012-07-14 04:24:20 -07:00
|
|
|
using namespace mozilla::dom::indexedDB;
|
2013-02-14 12:41:30 -08:00
|
|
|
using namespace mozilla::dom::power;
|
2013-03-01 00:38:47 -08:00
|
|
|
using namespace mozilla::dom::mobilemessage;
|
2013-09-06 23:19:53 -07:00
|
|
|
using namespace mozilla::dom::telephony;
|
2013-01-26 13:14:01 -08:00
|
|
|
using namespace mozilla::hal;
|
2012-07-17 16:59:44 -07:00
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::net;
|
2013-07-03 00:24:32 -07:00
|
|
|
using namespace mozilla::jsipc;
|
2009-09-02 17:18:27 -07:00
|
|
|
|
2013-11-26 23:59:41 -08:00
|
|
|
#ifdef ENABLE_TESTS
|
|
|
|
|
|
|
|
class BackgroundTester MOZ_FINAL : public nsIIPCBackgroundChildCreateCallback,
|
|
|
|
public nsIObserver
|
|
|
|
{
|
|
|
|
static uint32_t sCallbackCount;
|
|
|
|
|
|
|
|
private:
|
|
|
|
~BackgroundTester()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
ActorCreated(PBackgroundChild* aActor) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
MOZ_RELEASE_ASSERT(aActor,
|
|
|
|
"Failed to create a PBackgroundChild actor!");
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(testStr, "0123456789");
|
|
|
|
|
|
|
|
PBackgroundTestChild* testActor =
|
|
|
|
aActor->SendPBackgroundTestConstructor(testStr);
|
|
|
|
MOZ_RELEASE_ASSERT(testActor);
|
|
|
|
|
|
|
|
if (!sCallbackCount) {
|
|
|
|
PBackgroundChild* existingBackgroundChild =
|
|
|
|
BackgroundChild::GetForCurrentThread();
|
|
|
|
|
|
|
|
MOZ_RELEASE_ASSERT(existingBackgroundChild);
|
|
|
|
MOZ_RELEASE_ASSERT(existingBackgroundChild == aActor);
|
|
|
|
|
|
|
|
bool ok =
|
|
|
|
existingBackgroundChild->
|
|
|
|
SendPBackgroundTestConstructor(testStr);
|
|
|
|
MOZ_RELEASE_ASSERT(ok);
|
|
|
|
|
|
|
|
// Callback 3.
|
|
|
|
ok = BackgroundChild::GetOrCreateForCurrentThread(this);
|
|
|
|
MOZ_RELEASE_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
sCallbackCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void
|
|
|
|
ActorFailed() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
MOZ_CRASH("Failed to create a PBackgroundChild actor!");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
Observe(nsISupports* aSubject, const char* aTopic, const char16_t* aData)
|
|
|
|
MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
MOZ_RELEASE_ASSERT(observerService);
|
|
|
|
|
|
|
|
nsresult rv = observerService->RemoveObserver(this, aTopic);
|
|
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, "profile-after-change")) {
|
|
|
|
if (mozilla::Preferences::GetBool("pbackground.testing", false)) {
|
|
|
|
rv = observerService->AddObserver(this, "xpcom-shutdown",
|
|
|
|
false);
|
|
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
|
|
|
|
// Callback 1.
|
|
|
|
bool ok = BackgroundChild::GetOrCreateForCurrentThread(this);
|
|
|
|
MOZ_RELEASE_ASSERT(ok);
|
|
|
|
|
2014-03-31 19:55:36 -07:00
|
|
|
BackgroundChildImpl::ThreadLocal* threadLocal =
|
|
|
|
BackgroundChildImpl::GetThreadLocalForCurrentThread();
|
|
|
|
MOZ_RELEASE_ASSERT(threadLocal);
|
|
|
|
|
2013-11-26 23:59:41 -08:00
|
|
|
// Callback 2.
|
|
|
|
ok = BackgroundChild::GetOrCreateForCurrentThread(this);
|
|
|
|
MOZ_RELEASE_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown")) {
|
|
|
|
MOZ_RELEASE_ASSERT(sCallbackCount == 3);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_CRASH("Unknown observer topic!");
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t BackgroundTester::sCallbackCount = 0;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS2(BackgroundTester, nsIIPCBackgroundChildCreateCallback,
|
|
|
|
nsIObserver)
|
|
|
|
|
|
|
|
#endif // ENABLE_TESTS
|
|
|
|
|
|
|
|
void
|
|
|
|
MaybeTestPBackground()
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_TESTS
|
|
|
|
// This test relies on running the event loop and XPCShell does not always
|
|
|
|
// do so. Bail out here if we detect that we're running in XPCShell.
|
|
|
|
if (PR_GetEnv("XPCSHELL_TEST_PROFILE_DIR")) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is called too early at startup to test preferences directly. We have
|
|
|
|
// to install an observer to be notified when preferences are available.
|
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
MOZ_RELEASE_ASSERT(observerService);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIObserver> observer = new BackgroundTester();
|
|
|
|
nsresult rv = observerService->AddObserver(observer, "profile-after-change",
|
|
|
|
false);
|
|
|
|
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2013-10-22 22:26:24 -07:00
|
|
|
virtual bool Recv__delete__(const uint32_t& generation, const InfallibleTArray<MemoryReport>& report);
|
2011-02-16 10:43:23 -08:00
|
|
|
private:
|
|
|
|
ContentParent* Owner()
|
|
|
|
{
|
|
|
|
return static_cast<ContentParent*>(Manager());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MemoryReportRequestParent::MemoryReportRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(MemoryReportRequestParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-10-22 22:26:24 -07:00
|
|
|
MemoryReportRequestParent::Recv__delete__(const uint32_t& generation, const InfallibleTArray<MemoryReport>& childReports)
|
2011-02-16 10:43:23 -08:00
|
|
|
{
|
2013-10-22 22:26:24 -07:00
|
|
|
nsRefPtr<nsMemoryReporterManager> mgr =
|
|
|
|
nsMemoryReporterManager::GetOrCreate();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->HandleChildReports(generation, childReports);
|
|
|
|
}
|
2011-02-16 10:43:23 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MemoryReportRequestParent::~MemoryReportRequestParent()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(MemoryReportRequestParent);
|
|
|
|
}
|
|
|
|
|
2013-11-05 19:58:20 -08:00
|
|
|
// A memory reporter for ContentParent objects themselves.
|
2013-12-07 21:39:47 -08:00
|
|
|
class ContentParentsMemoryReporter MOZ_FINAL : public nsIMemoryReporter
|
2013-07-17 14:31:10 -07:00
|
|
|
{
|
|
|
|
public:
|
2013-12-07 21:39:47 -08:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2013-11-05 19:58:20 -08:00
|
|
|
};
|
2013-12-07 21:39:47 -08:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(ContentParentsMemoryReporter, nsIMemoryReporter)
|
2013-07-17 14:31:10 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-11-05 19:58:20 -08:00
|
|
|
ContentParentsMemoryReporter::CollectReports(nsIMemoryReporterCallback* cb,
|
|
|
|
nsISupports* aClosure)
|
2013-07-17 14:31:10 -07:00
|
|
|
{
|
|
|
|
nsAutoTArray<ContentParent*, 16> cps;
|
|
|
|
ContentParent::GetAllEvenIfDead(cps);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < cps.Length(); i++) {
|
|
|
|
ContentParent* cp = cps[i];
|
2013-09-27 18:42:08 -07:00
|
|
|
MessageChannel* channel = cp->GetIPCChannel();
|
2013-07-17 14:31:10 -07:00
|
|
|
|
|
|
|
nsString friendlyName;
|
|
|
|
cp->FriendlyName(friendlyName);
|
|
|
|
|
|
|
|
cp->AddRef();
|
|
|
|
nsrefcnt refcnt = cp->Release();
|
|
|
|
|
|
|
|
const char* channelStr = "no channel";
|
|
|
|
uint32_t numQueuedMessages = 0;
|
|
|
|
if (channel) {
|
|
|
|
if (channel->Unsound_IsClosed()) {
|
|
|
|
channelStr = "closed channel";
|
|
|
|
} else {
|
|
|
|
channelStr = "open channel";
|
|
|
|
}
|
|
|
|
numQueuedMessages = channel->Unsound_NumQueuedMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPrintfCString path("queued-ipc-messages/content-parent"
|
|
|
|
"(%s, pid=%d, %s, 0x%p, refcnt=%d)",
|
|
|
|
NS_ConvertUTF16toUTF8(friendlyName).get(),
|
|
|
|
cp->Pid(), channelStr, cp, refcnt);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(desc,
|
|
|
|
"The number of unset IPC messages held in this ContentParent's "
|
|
|
|
"channel. A large value here might indicate that we're leaking "
|
|
|
|
"messages. Similarly, a ContentParent object for a process that's no "
|
|
|
|
"longer running could indicate that we're leaking ContentParents.");
|
|
|
|
|
|
|
|
nsresult rv = cb->Callback(/* process */ EmptyCString(),
|
|
|
|
path,
|
2013-12-11 11:59:39 -08:00
|
|
|
KIND_OTHER,
|
|
|
|
UNITS_COUNT,
|
2013-07-17 14:31:10 -07:00
|
|
|
numQueuedMessages,
|
|
|
|
desc,
|
|
|
|
aClosure);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
nsDataHashtable<nsStringHashKey, ContentParent*>* ContentParent::sAppContentParents;
|
|
|
|
nsTArray<ContentParent*>* ContentParent::sNonAppContentParents;
|
|
|
|
nsTArray<ContentParent*>* ContentParent::sPrivateContent;
|
2013-07-17 14:31:10 -07:00
|
|
|
StaticAutoPtr<LinkedList<ContentParent> > ContentParent::sContentParents;
|
2009-08-12 09:18:08 -07:00
|
|
|
|
2012-12-28 01:45:16 -08:00
|
|
|
// This is true when subprocess launching is enabled. This is the
|
|
|
|
// case between StartUp() and ShutDown() or JoinAllSubprocesses().
|
|
|
|
static bool sCanLaunchSubprocesses;
|
|
|
|
|
2011-09-30 00:00:48 -07:00
|
|
|
// The first content child has ID 1, so the chrome process can have ID 0.
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint64_t gContentChildID = 1;
|
2011-09-30 00:00:48 -07:00
|
|
|
|
2012-08-15 18:46:03 -07:00
|
|
|
// We want the prelaunched process to know that it's for apps, but not
|
|
|
|
// actually for any app in particular. Use a magic manifest URL.
|
|
|
|
// Can't be a static constant.
|
|
|
|
#define MAGIC_PREALLOCATED_APP_MANIFEST_URL NS_LITERAL_STRING("{{template}}")
|
|
|
|
|
2014-02-12 22:55:28 -08:00
|
|
|
static const char* sObserverTopics[] = {
|
|
|
|
"xpcom-shutdown",
|
|
|
|
NS_IPC_IOSERVICE_SET_OFFLINE_TOPIC,
|
|
|
|
"child-memory-reporter-request",
|
|
|
|
"memory-pressure",
|
|
|
|
"child-gc-request",
|
|
|
|
"child-cc-request",
|
|
|
|
"child-mmu-request",
|
|
|
|
"last-pb-context-exited",
|
|
|
|
"file-watcher-update",
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
NS_VOLUME_STATE_CHANGED,
|
|
|
|
"phone-state-changed",
|
|
|
|
#endif
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
"a11y-init-or-shutdown",
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2013-11-21 19:25:34 -08:00
|
|
|
/* static */ already_AddRefed<ContentParent>
|
2013-06-03 03:14:40 -07:00
|
|
|
ContentParent::RunNuwaProcess()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-11-21 19:25:34 -08:00
|
|
|
nsRefPtr<ContentParent> nuwaProcess =
|
2013-06-03 03:14:40 -07:00
|
|
|
new ContentParent(/* aApp = */ nullptr,
|
|
|
|
/* aIsForBrowser = */ false,
|
|
|
|
/* aIsForPreallocated = */ true,
|
|
|
|
PROCESS_PRIORITY_BACKGROUND,
|
|
|
|
/* aIsNuwaProcess = */ true);
|
2013-11-21 19:25:34 -08:00
|
|
|
nuwaProcess->Init();
|
|
|
|
return nuwaProcess.forget();
|
2013-06-03 03:14:40 -07:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
// PreallocateAppProcess is called by the PreallocatedProcessManager.
|
|
|
|
// ContentParent then takes this process back within
|
|
|
|
// MaybeTakePreallocatedAppProcess.
|
|
|
|
/*static*/ already_AddRefed<ContentParent>
|
2012-08-15 18:46:03 -07:00
|
|
|
ContentParent::PreallocateAppProcess()
|
|
|
|
{
|
2013-04-25 17:53:26 -07:00
|
|
|
nsRefPtr<ContentParent> process =
|
2013-04-25 17:53:26 -07:00
|
|
|
new ContentParent(/* app = */ nullptr,
|
|
|
|
/* isForBrowserElement = */ false,
|
|
|
|
/* isForPreallocated = */ true,
|
2014-03-13 00:24:42 -07:00
|
|
|
PROCESS_PRIORITY_PREALLOC);
|
2013-04-25 17:53:26 -07:00
|
|
|
process->Init();
|
|
|
|
return process.forget();
|
2012-08-15 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ already_AddRefed<ContentParent>
|
2013-02-08 06:32:23 -08:00
|
|
|
ContentParent::MaybeTakePreallocatedAppProcess(const nsAString& aAppManifestURL,
|
2013-02-14 12:41:30 -08:00
|
|
|
ProcessPriority aInitialPriority)
|
2012-08-15 18:46:03 -07:00
|
|
|
{
|
2013-04-25 17:53:26 -07:00
|
|
|
nsRefPtr<ContentParent> process = PreallocatedProcessManager::Take();
|
2013-02-08 06:32:23 -08:00
|
|
|
if (!process) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-03-12 15:48:15 -07:00
|
|
|
if (!process->SetPriorityAndCheckIsAlive(aInitialPriority)) {
|
2013-02-08 06:32:23 -08:00
|
|
|
// Kill the process just in case it's not actually dead; we don't want
|
|
|
|
// to "leak" this process!
|
|
|
|
process->KillHard();
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-03-12 15:48:15 -07:00
|
|
|
process->TransformPreallocatedIntoApp(aAppManifestURL);
|
2013-02-08 06:32:23 -08:00
|
|
|
|
2012-08-15 18:46:03 -07:00
|
|
|
return process.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ContentParent::StartUp()
|
|
|
|
{
|
|
|
|
if (XRE_GetProcessType() != GeckoProcessType_Default) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-06 21:35:30 -08:00
|
|
|
// Note: This reporter measures all ContentParents.
|
|
|
|
RegisterStrongMemoryReporter(new ContentParentsMemoryReporter());
|
2013-07-17 14:31:10 -07:00
|
|
|
|
2014-03-10 05:36:12 -07:00
|
|
|
mozilla::dom::time::InitializeDateCacheCleaner();
|
|
|
|
|
2013-11-26 23:59:41 -08:00
|
|
|
BackgroundChild::Startup();
|
|
|
|
|
2012-12-28 01:45:16 -08:00
|
|
|
sCanLaunchSubprocesses = true;
|
2013-04-25 17:53:26 -07:00
|
|
|
|
|
|
|
// Try to preallocate a process that we can transform into an app later.
|
|
|
|
PreallocatedProcessManager::AllocateAfterDelay();
|
2013-11-26 23:59:41 -08:00
|
|
|
|
|
|
|
// Test the PBackground infrastructure on ENABLE_TESTS builds when a special
|
|
|
|
// testing preference is set.
|
|
|
|
MaybeTestPBackground();
|
2012-08-15 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ContentParent::ShutDown()
|
|
|
|
{
|
|
|
|
// No-op for now. We rely on normal process shutdown and
|
|
|
|
// ClearOnShutdown() to clean up our state.
|
2012-12-28 01:45:16 -08:00
|
|
|
sCanLaunchSubprocesses = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ContentParent::JoinProcessesIOThread(const nsTArray<ContentParent*>* aProcesses,
|
|
|
|
Monitor* aMonitor, bool* aDone)
|
|
|
|
{
|
|
|
|
const nsTArray<ContentParent*>& processes = *aProcesses;
|
|
|
|
for (uint32_t i = 0; i < processes.Length(); ++i) {
|
|
|
|
if (GeckoChildProcessHost* process = processes[i]->mSubprocess) {
|
|
|
|
process->Join();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(*aMonitor);
|
|
|
|
*aDone = true;
|
|
|
|
lock.Notify();
|
|
|
|
}
|
|
|
|
// Don't touch any arguments to this function from now on.
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
ContentParent::JoinAllSubprocesses()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsAutoTArray<ContentParent*, 8> processes;
|
|
|
|
GetAll(processes);
|
|
|
|
if (processes.IsEmpty()) {
|
|
|
|
printf_stderr("There are no live subprocesses.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf_stderr("Subprocesses are still alive. Doing emergency join.\n");
|
|
|
|
|
|
|
|
bool done = false;
|
|
|
|
Monitor monitor("mozilla.dom.ContentParent.JoinAllSubprocesses");
|
|
|
|
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
|
|
|
|
NewRunnableFunction(
|
|
|
|
&ContentParent::JoinProcessesIOThread,
|
|
|
|
&processes, &monitor, &done));
|
|
|
|
{
|
|
|
|
MonitorAutoLock lock(monitor);
|
|
|
|
while (!done) {
|
|
|
|
lock.Wait();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sCanLaunchSubprocesses = false;
|
2012-08-15 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2013-04-02 16:52:51 -07:00
|
|
|
/*static*/ already_AddRefed<ContentParent>
|
2012-08-23 03:23:43 -07:00
|
|
|
ContentParent::GetNewOrUsed(bool aForBrowserElement)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2013-04-25 17:53:26 -07:00
|
|
|
if (!sNonAppContentParents)
|
|
|
|
sNonAppContentParents = new nsTArray<ContentParent*>();
|
2011-08-02 12:35:42 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t maxContentProcesses = Preferences::GetInt("dom.ipc.processCount", 1);
|
2011-08-02 12:35:42 -07:00
|
|
|
if (maxContentProcesses < 1)
|
|
|
|
maxContentProcesses = 1;
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
if (sNonAppContentParents->Length() >= uint32_t(maxContentProcesses)) {
|
|
|
|
uint32_t idx = rand() % sNonAppContentParents->Length();
|
|
|
|
nsRefPtr<ContentParent> p = (*sNonAppContentParents)[idx];
|
|
|
|
NS_ASSERTION(p->IsAlive(), "Non-alive contentparent in sNonAppContentParents?");
|
2013-04-02 16:52:51 -07:00
|
|
|
return p.forget();
|
2011-03-26 13:16:45 -07:00
|
|
|
}
|
2012-08-08 19:58:06 -07:00
|
|
|
|
2014-02-13 02:42:41 -08:00
|
|
|
// Try to take and transform the preallocated process into browser.
|
|
|
|
nsRefPtr<ContentParent> p = PreallocatedProcessManager::Take();
|
|
|
|
if (p) {
|
|
|
|
p->TransformPreallocatedIntoBrowser();
|
|
|
|
} else {
|
|
|
|
// Failed in using the preallocated process: fork from the chrome process.
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
if (Preferences::GetBool("dom.ipc.processPrelaunch.enabled", false)) {
|
|
|
|
// Wait until the Nuwa process forks a new process.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
p = new ContentParent(/* app = */ nullptr,
|
|
|
|
aForBrowserElement,
|
|
|
|
/* isForPreallocated = */ false,
|
|
|
|
PROCESS_PRIORITY_FOREGROUND);
|
|
|
|
}
|
|
|
|
|
2011-08-02 12:35:42 -07:00
|
|
|
p->Init();
|
2013-04-25 17:53:26 -07:00
|
|
|
sNonAppContentParents->AppendElement(p);
|
2013-04-02 16:52:51 -07:00
|
|
|
return p.forget();
|
2011-08-02 12:35:42 -07:00
|
|
|
}
|
2010-12-26 12:03:52 -08:00
|
|
|
|
2013-02-14 12:41:30 -08:00
|
|
|
/*static*/ ProcessPriority
|
2013-07-23 16:39:17 -07:00
|
|
|
ContentParent::GetInitialProcessPriority(Element* aFrameElement)
|
2013-02-14 12:41:30 -08:00
|
|
|
{
|
|
|
|
// Frames with mozapptype == critical which are expecting a system message
|
2013-09-24 01:10:20 -07:00
|
|
|
// get FOREGROUND_HIGH priority.
|
2013-02-14 12:41:30 -08:00
|
|
|
|
|
|
|
if (!aFrameElement) {
|
|
|
|
return PROCESS_PRIORITY_FOREGROUND;
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:10:20 -07:00
|
|
|
if (aFrameElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozapptype,
|
|
|
|
NS_LITERAL_STRING("keyboard"), eCaseMatters)) {
|
|
|
|
return PROCESS_PRIORITY_FOREGROUND_KEYBOARD;
|
|
|
|
} else if (!aFrameElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozapptype,
|
|
|
|
NS_LITERAL_STRING("critical"), eCaseMatters)) {
|
2013-02-14 12:41:30 -08:00
|
|
|
return PROCESS_PRIORITY_FOREGROUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMozBrowserFrame> browserFrame =
|
|
|
|
do_QueryInterface(aFrameElement);
|
|
|
|
if (!browserFrame) {
|
|
|
|
return PROCESS_PRIORITY_FOREGROUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
return browserFrame->GetIsExpectingSystemMessage() ?
|
|
|
|
PROCESS_PRIORITY_FOREGROUND_HIGH :
|
|
|
|
PROCESS_PRIORITY_FOREGROUND;
|
|
|
|
}
|
|
|
|
|
2013-11-19 03:03:30 -08:00
|
|
|
bool
|
|
|
|
ContentParent::PreallocatedProcessReady()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
return PreallocatedProcessManager::PreallocatedProcessReady();
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentParent::RunAfterPreallocatedProcessReady(nsIRunnable* aRequest)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
PreallocatedProcessManager::RunAfterPreallocatedProcessReady(aRequest);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-08-08 19:58:06 -07:00
|
|
|
/*static*/ TabParent*
|
2013-02-14 12:41:30 -08:00
|
|
|
ContentParent::CreateBrowserOrApp(const TabContext& aContext,
|
2013-07-23 16:39:17 -07:00
|
|
|
Element* aFrameElement)
|
2012-07-13 14:10:20 -07:00
|
|
|
{
|
2012-12-28 01:45:16 -08:00
|
|
|
if (!sCanLaunchSubprocesses) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
if (aContext.IsBrowserElement() || !aContext.HasOwnApp()) {
|
2013-04-02 16:52:51 -07:00
|
|
|
if (nsRefPtr<ContentParent> cp = GetNewOrUsed(aContext.IsBrowserElement())) {
|
2013-05-06 21:10:31 -07:00
|
|
|
uint32_t chromeFlags = 0;
|
|
|
|
|
|
|
|
// Propagate the private-browsing status of the element's parent
|
|
|
|
// docshell to the remote docshell, via the chrome flags.
|
|
|
|
nsCOMPtr<Element> frameElement = do_QueryInterface(aFrameElement);
|
|
|
|
MOZ_ASSERT(frameElement);
|
|
|
|
nsIDocShell* docShell =
|
|
|
|
frameElement->OwnerDoc()->GetWindow()->GetDocShell();
|
|
|
|
MOZ_ASSERT(docShell);
|
|
|
|
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(docShell);
|
|
|
|
if (loadContext && loadContext->UsePrivateBrowsing()) {
|
|
|
|
chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW;
|
|
|
|
}
|
|
|
|
bool affectLifetime;
|
|
|
|
docShell->GetAffectPrivateSessionLifetime(&affectLifetime);
|
|
|
|
if (affectLifetime) {
|
|
|
|
chromeFlags |= nsIWebBrowserChrome::CHROME_PRIVATE_LIFETIME;
|
|
|
|
}
|
|
|
|
|
2014-01-10 17:10:57 -08:00
|
|
|
nsRefPtr<TabParent> tp(new TabParent(cp, aContext, chromeFlags));
|
|
|
|
tp->SetOwnerElement(aFrameElement);
|
|
|
|
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
PBrowserParent* browser = cp->SendPBrowserConstructor(
|
2014-03-15 12:00:15 -07:00
|
|
|
// DeallocPBrowserParent() releases this ref.
|
|
|
|
tp.forget().take(),
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
aContext.AsIPCTabContext(),
|
2013-05-06 21:10:31 -07:00
|
|
|
chromeFlags);
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
return static_cast<TabParent*>(browser);
|
2012-08-08 19:58:06 -07:00
|
|
|
}
|
|
|
|
return nullptr;
|
2012-07-13 14:10:20 -07:00
|
|
|
}
|
|
|
|
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
// If we got here, we have an app and we're not a browser element. ownApp
|
|
|
|
// shouldn't be null, because we otherwise would have gone into the
|
|
|
|
// !HasOwnApp() branch above.
|
|
|
|
nsCOMPtr<mozIApplication> ownApp = aContext.GetOwnApp();
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
if (!sAppContentParents) {
|
|
|
|
sAppContentParents =
|
2012-07-13 14:10:20 -07:00
|
|
|
new nsDataHashtable<nsStringHashKey, ContentParent*>();
|
|
|
|
}
|
|
|
|
|
2014-03-25 21:56:35 -07:00
|
|
|
// Each app gets its own ContentParent instance unless it shares it with
|
|
|
|
// a parent app.
|
2012-08-08 19:58:06 -07:00
|
|
|
nsAutoString manifestURL;
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
if (NS_FAILED(ownApp->GetManifestURL(manifestURL))) {
|
2012-08-08 19:58:06 -07:00
|
|
|
NS_ERROR("Failed to get manifest URL");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-02-14 12:41:30 -08:00
|
|
|
ProcessPriority initialPriority = GetInitialProcessPriority(aFrameElement);
|
2013-04-25 17:53:26 -07:00
|
|
|
nsRefPtr<ContentParent> p = sAppContentParents->Get(manifestURL);
|
2014-03-25 21:56:35 -07:00
|
|
|
|
|
|
|
if (!p && Preferences::GetBool("dom.ipc.reuse_parent_app")) {
|
|
|
|
nsAutoString parentAppURL;
|
|
|
|
aFrameElement->GetAttr(kNameSpaceID_None,
|
|
|
|
nsGkAtoms::parentapp, parentAppURL);
|
|
|
|
nsAdoptingString systemAppURL =
|
|
|
|
Preferences::GetString("browser.homescreenURL");
|
|
|
|
nsCOMPtr<nsIAppsService> appsService =
|
|
|
|
do_GetService(APPS_SERVICE_CONTRACTID);
|
|
|
|
if (!parentAppURL.IsEmpty() &&
|
|
|
|
!parentAppURL.Equals(systemAppURL) &&
|
|
|
|
appsService) {
|
|
|
|
nsCOMPtr<mozIApplication> parentApp;
|
|
|
|
nsCOMPtr<mozIApplication> app;
|
|
|
|
appsService->GetAppByManifestURL(parentAppURL,
|
|
|
|
getter_AddRefs(parentApp));
|
|
|
|
appsService->GetAppByManifestURL(manifestURL,
|
|
|
|
getter_AddRefs(app));
|
|
|
|
|
|
|
|
// Only let certified apps re-use the same process.
|
|
|
|
unsigned short parentAppStatus = 0;
|
|
|
|
unsigned short appStatus = 0;
|
|
|
|
if (app &&
|
|
|
|
NS_SUCCEEDED(app->GetAppStatus(&appStatus)) &&
|
|
|
|
appStatus == nsIPrincipal::APP_STATUS_CERTIFIED &&
|
|
|
|
parentApp &&
|
|
|
|
NS_SUCCEEDED(parentApp->GetAppStatus(&parentAppStatus)) &&
|
|
|
|
parentAppStatus == nsIPrincipal::APP_STATUS_CERTIFIED) {
|
|
|
|
// Check if we can re-use the process of the parent app.
|
|
|
|
p = sAppContentParents->Get(parentAppURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 12:41:30 -08:00
|
|
|
if (p) {
|
|
|
|
// Check that the process is still alive and set its priority.
|
|
|
|
// Hopefully the process won't die after this point, if this call
|
|
|
|
// succeeds.
|
|
|
|
if (!p->SetPriorityAndCheckIsAlive(initialPriority)) {
|
|
|
|
p = nullptr;
|
|
|
|
}
|
|
|
|
}
|
2013-02-14 12:41:30 -08:00
|
|
|
|
2013-02-14 12:41:30 -08:00
|
|
|
if (!p) {
|
2014-03-12 15:48:15 -07:00
|
|
|
p = MaybeTakePreallocatedAppProcess(manifestURL,
|
2013-02-14 12:41:30 -08:00
|
|
|
initialPriority);
|
2013-02-08 06:32:23 -08:00
|
|
|
if (!p) {
|
2013-11-19 03:03:30 -08:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
if (Preferences::GetBool("dom.ipc.processPrelaunch.enabled",
|
|
|
|
false)) {
|
|
|
|
// Returning nullptr from here so the frame loader will retry
|
|
|
|
// later when we have a spare process.
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
#endif
|
2013-01-17 12:06:36 -08:00
|
|
|
NS_WARNING("Unable to use pre-allocated app process");
|
2013-04-25 17:53:26 -07:00
|
|
|
p = new ContentParent(ownApp,
|
|
|
|
/* isForBrowserElement = */ false,
|
|
|
|
/* isForPreallocated = */ false,
|
|
|
|
initialPriority);
|
2012-08-15 18:46:03 -07:00
|
|
|
p->Init();
|
|
|
|
}
|
2013-04-25 17:53:26 -07:00
|
|
|
sAppContentParents->Put(manifestURL, p);
|
2012-07-13 14:10:20 -07:00
|
|
|
}
|
|
|
|
|
2014-01-10 17:10:57 -08:00
|
|
|
uint32_t chromeFlags = 0;
|
|
|
|
|
|
|
|
nsRefPtr<TabParent> tp = new TabParent(p, aContext, chromeFlags);
|
2013-02-14 12:41:30 -08:00
|
|
|
tp->SetOwnerElement(aFrameElement);
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
PBrowserParent* browser = p->SendPBrowserConstructor(
|
2014-03-15 12:00:15 -07:00
|
|
|
// DeallocPBrowserParent() releases this ref.
|
|
|
|
nsRefPtr<TabParent>(tp).forget().take(),
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
aContext.AsIPCTabContext(),
|
2014-01-10 17:10:57 -08:00
|
|
|
chromeFlags);
|
2013-02-14 12:41:30 -08:00
|
|
|
|
|
|
|
p->MaybeTakeCPUWakeLock(aFrameElement);
|
|
|
|
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
return static_cast<TabParent*>(browser);
|
2012-07-13 14:10:20 -07:00
|
|
|
}
|
|
|
|
|
2011-08-02 12:35:42 -07:00
|
|
|
void
|
|
|
|
ContentParent::GetAll(nsTArray<ContentParent*>& aArray)
|
|
|
|
{
|
2012-07-13 14:10:20 -07:00
|
|
|
aArray.Clear();
|
|
|
|
|
2013-07-17 14:31:10 -07:00
|
|
|
if (!sContentParents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-17 14:31:10 -07:00
|
|
|
for (ContentParent* cp = sContentParents->getFirst(); cp;
|
2013-06-03 03:14:40 -07:00
|
|
|
cp = cp->LinkedListElement<ContentParent>::getNext()) {
|
2013-07-17 14:31:10 -07:00
|
|
|
if (cp->mIsAlive) {
|
|
|
|
aArray.AppendElement(cp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentParent::GetAllEvenIfDead(nsTArray<ContentParent*>& aArray)
|
|
|
|
{
|
|
|
|
aArray.Clear();
|
|
|
|
|
|
|
|
if (!sContentParents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-07-17 14:31:10 -07:00
|
|
|
for (ContentParent* cp = sContentParents->getFirst(); cp;
|
2013-06-03 03:14:40 -07:00
|
|
|
cp = cp->LinkedListElement<ContentParent>::getNext()) {
|
2013-04-25 17:53:26 -07:00
|
|
|
aArray.AppendElement(cp);
|
2012-10-02 18:19:11 -07:00
|
|
|
}
|
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) {
|
2014-02-12 22:55:28 -08:00
|
|
|
size_t length = ArrayLength(sObserverTopics);
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
|
|
|
obs->AddObserver(this, sObserverTopics[i], false);
|
|
|
|
}
|
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
|
|
|
if (obs) {
|
2012-07-30 07:20:58 -07:00
|
|
|
obs->NotifyObservers(static_cast<nsIObserver*>(this), "ipc:content-created", nullptr);
|
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
|
2013-01-09 07:03:28 -08:00
|
|
|
|
|
|
|
DebugOnly<FileUpdateDispatcher*> observer = FileUpdateDispatcher::GetSingleton();
|
|
|
|
NS_ASSERTION(observer, "FileUpdateDispatcher is null");
|
2010-12-26 12:03:52 -08:00
|
|
|
}
|
|
|
|
|
2013-02-14 12:41:30 -08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
class SystemMessageHandledListener MOZ_FINAL
|
|
|
|
: public nsITimerCallback
|
|
|
|
, public LinkedListElement<SystemMessageHandledListener>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
SystemMessageHandledListener() {}
|
|
|
|
|
|
|
|
static void OnSystemMessageHandled()
|
|
|
|
{
|
|
|
|
if (!sListeners) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemMessageHandledListener* listener = sListeners->popFirst();
|
|
|
|
if (!listener) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Careful: ShutDown() may delete |this|.
|
|
|
|
listener->ShutDown();
|
|
|
|
}
|
|
|
|
|
2014-01-07 04:16:07 -08:00
|
|
|
void Init(WakeLock* aWakeLock)
|
2013-02-14 12:41:30 -08:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mWakeLock);
|
|
|
|
MOZ_ASSERT(!mTimer);
|
|
|
|
|
|
|
|
// mTimer keeps a strong reference to |this|. When this object's
|
|
|
|
// destructor runs, it will remove itself from the LinkedList.
|
|
|
|
|
|
|
|
if (!sListeners) {
|
|
|
|
sListeners = new LinkedList<SystemMessageHandledListener>();
|
|
|
|
ClearOnShutdown(&sListeners);
|
|
|
|
}
|
|
|
|
sListeners->insertBack(this);
|
|
|
|
|
|
|
|
mWakeLock = aWakeLock;
|
|
|
|
|
|
|
|
mTimer = do_CreateInstance("@mozilla.org/timer;1");
|
|
|
|
|
|
|
|
uint32_t timeoutSec =
|
|
|
|
Preferences::GetInt("dom.ipc.systemMessageCPULockTimeoutSec", 30);
|
|
|
|
mTimer->InitWithCallback(this, timeoutSec * 1000,
|
|
|
|
nsITimer::TYPE_ONE_SHOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Notify(nsITimer* aTimer)
|
|
|
|
{
|
|
|
|
// Careful: ShutDown() may delete |this|.
|
|
|
|
ShutDown();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static StaticAutoPtr<LinkedList<SystemMessageHandledListener> > sListeners;
|
|
|
|
|
|
|
|
void ShutDown()
|
|
|
|
{
|
|
|
|
nsRefPtr<SystemMessageHandledListener> kungFuDeathGrip = this;
|
|
|
|
|
2014-01-07 04:16:07 -08:00
|
|
|
ErrorResult rv;
|
|
|
|
mWakeLock->Unlock(rv);
|
2013-02-14 12:41:30 -08:00
|
|
|
|
|
|
|
if (mTimer) {
|
|
|
|
mTimer->Cancel();
|
|
|
|
mTimer = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-07 04:16:07 -08:00
|
|
|
nsRefPtr<WakeLock> mWakeLock;
|
2013-02-14 12:41:30 -08:00
|
|
|
nsCOMPtr<nsITimer> mTimer;
|
|
|
|
};
|
|
|
|
|
|
|
|
StaticAutoPtr<LinkedList<SystemMessageHandledListener> >
|
|
|
|
SystemMessageHandledListener::sListeners;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(SystemMessageHandledListener,
|
|
|
|
nsITimerCallback)
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
void
|
2013-07-23 16:39:17 -07:00
|
|
|
ContentParent::MaybeTakeCPUWakeLock(Element* aFrameElement)
|
2013-02-14 12:41:30 -08:00
|
|
|
{
|
|
|
|
// Take the CPU wake lock on behalf of this processs if it's expecting a
|
|
|
|
// system message. We'll release the CPU lock once the message is
|
|
|
|
// delivered, or after some period of time, which ever comes first.
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMozBrowserFrame> browserFrame =
|
|
|
|
do_QueryInterface(aFrameElement);
|
|
|
|
if (!browserFrame ||
|
|
|
|
!browserFrame->GetIsExpectingSystemMessage()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<PowerManagerService> pms = PowerManagerService::GetInstance();
|
2014-01-07 04:16:07 -08:00
|
|
|
nsRefPtr<WakeLock> lock =
|
2013-02-14 12:41:30 -08:00
|
|
|
pms->NewWakeLockOnBehalfOfProcess(NS_LITERAL_STRING("cpu"), this);
|
|
|
|
|
|
|
|
// This object's Init() function keeps it alive.
|
|
|
|
nsRefPtr<SystemMessageHandledListener> listener =
|
|
|
|
new SystemMessageHandledListener();
|
|
|
|
listener->Init(lock);
|
|
|
|
}
|
|
|
|
|
2013-02-08 06:32:23 -08:00
|
|
|
bool
|
2013-02-14 12:41:30 -08:00
|
|
|
ContentParent::SetPriorityAndCheckIsAlive(ProcessPriority aPriority)
|
2012-08-15 18:46:03 -07:00
|
|
|
{
|
2013-04-25 17:53:26 -07:00
|
|
|
ProcessPriorityManager::SetProcessPriority(this, aPriority);
|
2013-02-08 06:32:23 -08:00
|
|
|
|
2013-02-14 12:41:30 -08:00
|
|
|
// Now that we've set this process's priority, check whether the process is
|
|
|
|
// still alive. Hopefully we've set the priority to FOREGROUND*, so the
|
|
|
|
// process won't unexpectedly crash after this point!
|
2013-02-14 12:41:29 -08:00
|
|
|
//
|
2014-03-21 05:50:07 -07:00
|
|
|
// Bug 943174: use waitid() with WNOWAIT so that, if the process
|
|
|
|
// did exit, we won't consume its zombie and confuse the
|
|
|
|
// GeckoChildProcessHost dtor. Also, if the process isn't a
|
|
|
|
// direct child because of Nuwa this will fail with ECHILD, and we
|
|
|
|
// need to assume the child is alive in that case rather than
|
|
|
|
// assuming it's dead (as is otherwise a reasonable fallback).
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
siginfo_t info;
|
|
|
|
info.si_pid = 0;
|
|
|
|
if (waitid(P_PID, Pid(), &info, WNOWAIT | WNOHANG | WEXITED) == 0
|
|
|
|
&& info.si_pid != 0) {
|
2013-02-14 12:41:29 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-14 12:41:30 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
// Helper for ContentParent::TransformPreallocatedIntoApp.
|
|
|
|
static void
|
|
|
|
TryGetNameFromManifestURL(const nsAString& aManifestURL,
|
|
|
|
nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
|
|
|
if (aManifestURL.IsEmpty() ||
|
|
|
|
aManifestURL == MAGIC_PREALLOCATED_APP_MANIFEST_URL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE_VOID(appsService);
|
|
|
|
|
2013-10-08 15:52:26 -07:00
|
|
|
nsCOMPtr<mozIApplication> app;
|
|
|
|
appsService->GetAppByManifestURL(aManifestURL, getter_AddRefs(app));
|
2013-04-25 17:53:26 -07:00
|
|
|
|
|
|
|
if (!app) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
app->GetName(aName);
|
|
|
|
}
|
|
|
|
|
2014-03-12 15:48:15 -07:00
|
|
|
void
|
|
|
|
ContentParent::TransformPreallocatedIntoApp(const nsAString& aAppManifestURL)
|
2013-02-14 12:41:30 -08:00
|
|
|
{
|
2013-04-25 17:53:26 -07:00
|
|
|
MOZ_ASSERT(IsPreallocated());
|
|
|
|
mAppManifestURL = aAppManifestURL;
|
|
|
|
TryGetNameFromManifestURL(aAppManifestURL, mAppName);
|
2012-08-15 18:46:03 -07:00
|
|
|
}
|
|
|
|
|
2014-02-13 02:42:41 -08:00
|
|
|
void
|
|
|
|
ContentParent::TransformPreallocatedIntoBrowser()
|
|
|
|
{
|
|
|
|
// Reset mAppManifestURL, mIsForBrowser and mOSPrivileges for browser.
|
|
|
|
mAppManifestURL.Truncate();
|
|
|
|
mIsForBrowser = true;
|
|
|
|
}
|
|
|
|
|
2012-08-15 18:46:03 -07:00
|
|
|
void
|
2013-07-17 12:13:20 -07:00
|
|
|
ContentParent::ShutDownProcess(bool aCloseWithError)
|
2012-07-17 11:27:27 -07:00
|
|
|
{
|
2012-10-05 12:09:33 -07:00
|
|
|
const InfallibleTArray<PIndexedDBParent*>& idbParents =
|
2013-08-07 11:08:52 -07:00
|
|
|
ManagedPIndexedDBParent();
|
2012-10-05 12:09:33 -07:00
|
|
|
for (uint32_t i = 0; i < idbParents.Length(); ++i) {
|
2013-08-07 11:08:52 -07:00
|
|
|
static_cast<IndexedDBParent*>(idbParents[i])->Disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If Close() fails with an error, we'll end up back in this function, but
|
|
|
|
// with aCloseWithError = true. It's important that we call
|
|
|
|
// CloseWithError() in this case; see bug 895204.
|
|
|
|
|
|
|
|
if (!aCloseWithError && !mCalledClose) {
|
|
|
|
// Close() can only be called once: It kicks off the destruction
|
|
|
|
// sequence.
|
|
|
|
mCalledClose = true;
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCloseWithError && !mCalledCloseWithError) {
|
2013-09-27 18:42:08 -07:00
|
|
|
MessageChannel* channel = GetIPCChannel();
|
2013-08-07 11:08:52 -07:00
|
|
|
if (channel) {
|
|
|
|
mCalledCloseWithError = true;
|
|
|
|
channel->CloseWithError();
|
|
|
|
}
|
2012-07-17 11:27:27 -07:00
|
|
|
}
|
2012-10-05 12:09:33 -07:00
|
|
|
|
2013-08-07 11:08:52 -07:00
|
|
|
// NB: must MarkAsDead() here so that this isn't accidentally
|
|
|
|
// returned from Get*() while in the midst of shutdown.
|
|
|
|
MarkAsDead();
|
|
|
|
|
|
|
|
// A ContentParent object might not get freed until after XPCOM shutdown has
|
|
|
|
// shut down the cycle collector. But by then it's too late to release any
|
|
|
|
// CC'ed objects, so we need to null them out here, while we still can. See
|
|
|
|
// bug 899761.
|
|
|
|
if (mMessageManager) {
|
|
|
|
mMessageManager->Disconnect();
|
|
|
|
mMessageManager = nullptr;
|
2013-07-15 05:55:13 -07:00
|
|
|
}
|
2012-07-17 11:27:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentParent::MarkAsDead()
|
|
|
|
{
|
|
|
|
if (!mAppManifestURL.IsEmpty()) {
|
2013-04-25 17:53:26 -07:00
|
|
|
if (sAppContentParents) {
|
|
|
|
sAppContentParents->Remove(mAppManifestURL);
|
|
|
|
if (!sAppContentParents->Count()) {
|
|
|
|
delete sAppContentParents;
|
2013-10-28 07:04:12 -07:00
|
|
|
sAppContentParents = nullptr;
|
2012-07-17 11:27:27 -07:00
|
|
|
}
|
|
|
|
}
|
2013-04-25 17:53:26 -07:00
|
|
|
} else if (sNonAppContentParents) {
|
|
|
|
sNonAppContentParents->RemoveElement(this);
|
|
|
|
if (!sNonAppContentParents->Length()) {
|
|
|
|
delete sNonAppContentParents;
|
2013-10-28 07:04:12 -07:00
|
|
|
sNonAppContentParents = nullptr;
|
2012-07-17 11:27:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
if (sPrivateContent) {
|
|
|
|
sPrivateContent->RemoveElement(this);
|
|
|
|
if (!sPrivateContent->Length()) {
|
|
|
|
delete sPrivateContent;
|
2013-10-28 07:04:12 -07:00
|
|
|
sPrivateContent = nullptr;
|
2012-07-17 11:27:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mIsAlive = false;
|
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:40 -07:00
|
|
|
void
|
|
|
|
ContentParent::OnChannelError()
|
|
|
|
{
|
|
|
|
nsRefPtr<ContentParent> content(this);
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
2013-12-11 01:48:28 -08:00
|
|
|
// Handle app or Nuwa process exit before normal channel error handling.
|
2013-11-21 19:25:34 -08:00
|
|
|
PreallocatedProcessManager::MaybeForgetSpare(this);
|
2013-06-03 03:14:40 -07:00
|
|
|
#endif
|
2013-12-11 01:48:28 -08:00
|
|
|
PContentParent::OnChannelError();
|
2013-06-03 03:14:40 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 05:58:21 -08:00
|
|
|
void
|
2012-09-17 01:37:20 -07:00
|
|
|
ContentParent::OnChannelConnected(int32_t pid)
|
2010-11-24 05:58:21 -08:00
|
|
|
{
|
|
|
|
ProcessHandle handle;
|
|
|
|
if (!base::OpenPrivilegedProcessHandle(pid, &handle)) {
|
|
|
|
NS_WARNING("Can't open handle to child process.");
|
|
|
|
}
|
|
|
|
else {
|
2013-09-30 17:56:16 -07:00
|
|
|
// we need to close the existing handle before setting a new one.
|
|
|
|
base::CloseProcessHandle(OtherProcess());
|
2010-11-24 05:58:21 -08:00
|
|
|
SetOtherProcess(handle);
|
2011-02-14 14:34:46 -08:00
|
|
|
|
|
|
|
#if defined(ANDROID) || defined(LINUX)
|
|
|
|
// Check nice preference
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t 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) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t cpus;
|
2011-06-16 19:59:00 -07:00
|
|
|
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
|
|
|
}
|
2013-08-26 21:56:57 -07:00
|
|
|
|
|
|
|
// Set a reply timeout. The only time the parent process will actually
|
|
|
|
// timeout is through urgent messages (which are used by CPOWs).
|
|
|
|
SetReplyTimeoutMs(Preferences::GetInt("dom.ipc.cpow.timeout", 3000));
|
2010-11-24 05:58:21 -08:00
|
|
|
}
|
|
|
|
|
2011-07-12 23:52:31 -07:00
|
|
|
void
|
|
|
|
ContentParent::ProcessingError(Result what)
|
|
|
|
{
|
|
|
|
if (MsgDropped == what) {
|
|
|
|
// Messages sent after crashes etc. are not a big deal.
|
|
|
|
return;
|
|
|
|
}
|
2012-09-05 15:18:48 -07:00
|
|
|
// Other errors are big deals.
|
|
|
|
KillHard();
|
2011-07-12 23:52:31 -07:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-01-10 05:22:14 -08:00
|
|
|
if (mForceKillTask) {
|
|
|
|
mForceKillTask->Cancel();
|
|
|
|
mForceKillTask = nullptr;
|
|
|
|
}
|
|
|
|
|
2012-09-27 22:43:24 -07:00
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
|
|
|
if (ppm) {
|
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
|
|
|
|
CHILD_PROCESS_SHUTDOWN_MESSAGE, false,
|
2013-11-06 09:21:15 -08:00
|
|
|
nullptr, nullptr, nullptr, nullptr);
|
2012-09-27 22:43:24 -07:00
|
|
|
}
|
2014-03-19 17:22:25 -07:00
|
|
|
nsRefPtr<ContentParent> kungFuDeathGrip(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) {
|
2014-02-12 22:55:28 -08:00
|
|
|
size_t length = ArrayLength(sObserverTopics);
|
|
|
|
for (size_t i = 0; i < length; ++i) {
|
|
|
|
obs->RemoveObserver(static_cast<nsIObserver*>(this),
|
|
|
|
sObserverTopics[i]);
|
|
|
|
}
|
2010-12-26 11:27:50 -08:00
|
|
|
}
|
|
|
|
|
2013-08-05 04:02:38 -07:00
|
|
|
if (ppm) {
|
|
|
|
ppm->Disconnect();
|
|
|
|
}
|
2011-08-02 12:57:48 -07:00
|
|
|
|
2013-10-22 22:26:24 -07:00
|
|
|
// Tell the memory reporter manager that this ContentParent is going away.
|
|
|
|
nsRefPtr<nsMemoryReporterManager> mgr =
|
|
|
|
nsMemoryReporterManager::GetOrCreate();
|
2014-03-03 14:27:03 -08:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
bool isMemoryChild = !IsNuwaProcess();
|
|
|
|
#else
|
|
|
|
bool isMemoryChild = true;
|
|
|
|
#endif
|
|
|
|
if (mgr && isMemoryChild) {
|
2013-10-22 22:26:24 -07:00
|
|
|
mgr->DecrementNumChildProcesses();
|
|
|
|
}
|
2011-02-16 10:43:23 -08:00
|
|
|
|
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();
|
|
|
|
|
2012-11-09 09:52:09 -08:00
|
|
|
mConsoleService = nullptr;
|
|
|
|
|
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();
|
|
|
|
|
2012-11-17 07:05:18 -08:00
|
|
|
props->SetPropertyAsUint64(NS_LITERAL_STRING("childID"), mChildID);
|
|
|
|
|
2010-11-24 05:58:21 -08:00
|
|
|
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
|
2013-01-03 15:39:25 -08:00
|
|
|
// There's a window in which child processes can crash
|
|
|
|
// after IPC is established, but before a crash reporter
|
|
|
|
// is created.
|
|
|
|
if (ManagedPCrashReporterParent().Length() > 0) {
|
|
|
|
CrashReporterParent* crashReporter =
|
2011-06-08 12:56:31 -07:00
|
|
|
static_cast<CrashReporterParent*>(ManagedPCrashReporterParent()[0]);
|
2010-11-24 05:58:21 -08:00
|
|
|
|
2013-01-07 06:42:32 -08:00
|
|
|
// If we're an app process, always stomp the latest URI
|
|
|
|
// loaded in the child process with our manifest URL. We
|
|
|
|
// would rather associate the crashes with apps than
|
|
|
|
// random child windows loaded in them.
|
|
|
|
//
|
|
|
|
// XXX would be nice if we could get both ...
|
|
|
|
if (!mAppManifestURL.IsEmpty()) {
|
|
|
|
crashReporter->AnnotateCrashReport(NS_LITERAL_CSTRING("URL"),
|
|
|
|
NS_ConvertUTF16toUTF8(mAppManifestURL));
|
|
|
|
}
|
|
|
|
|
2013-10-28 07:04:12 -07:00
|
|
|
crashReporter->GenerateCrashReport(this, nullptr);
|
2012-12-25 15:06:27 -08:00
|
|
|
|
2013-01-03 15:39:25 -08:00
|
|
|
nsAutoString dumpID(crashReporter->ChildDumpID());
|
|
|
|
props->SetPropertyAsAString(NS_LITERAL_STRING("dumpID"), dumpID);
|
|
|
|
}
|
2010-11-24 05:58:21 -08:00
|
|
|
#endif
|
|
|
|
}
|
2012-11-17 07:05:18 -08:00
|
|
|
obs->NotifyObservers((nsIPropertyBag2*) props, "ipc:content-shutdown", nullptr);
|
2010-10-08 12:12:40 -07:00
|
|
|
}
|
2010-11-24 05:58:21 -08:00
|
|
|
|
2013-12-13 08:28:46 -08:00
|
|
|
mIdleListeners.Clear();
|
|
|
|
|
2013-07-15 05:55:13 -07:00
|
|
|
// If the child process was terminated due to a SIGKIL, ShutDownProcess
|
|
|
|
// might not have been called yet. We must call it to ensure that our
|
|
|
|
// channel is closed, etc.
|
2013-07-17 12:13:20 -07:00
|
|
|
ShutDownProcess(/* closeWithError */ true);
|
2013-07-15 05:55:13 -07:00
|
|
|
|
2010-11-24 05:58:21 -08:00
|
|
|
MessageLoop::current()->
|
|
|
|
PostTask(FROM_HERE,
|
|
|
|
NewRunnableFunction(DelayedDeleteSubprocess, mSubprocess));
|
2013-10-28 07:04:12 -07:00
|
|
|
mSubprocess = nullptr;
|
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
|
|
|
}
|
|
|
|
|
2012-07-17 11:27:27 -07:00
|
|
|
void
|
2013-01-10 05:22:14 -08:00
|
|
|
ContentParent::NotifyTabDestroying(PBrowserParent* aTab)
|
|
|
|
{
|
|
|
|
// There can be more than one PBrowser for a given app process
|
|
|
|
// because of popup windows. PBrowsers can also destroy
|
|
|
|
// concurrently. When all the PBrowsers are destroying, kick off
|
|
|
|
// another task to ensure the child process *really* shuts down,
|
|
|
|
// even if the PBrowsers themselves never finish destroying.
|
|
|
|
int32_t numLiveTabs = ManagedPBrowserParent().Length();
|
|
|
|
++mNumDestroyingTabs;
|
|
|
|
if (mNumDestroyingTabs != numLiveTabs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're dying now, so prevent this content process from being
|
|
|
|
// recycled during its shutdown procedure.
|
|
|
|
MarkAsDead();
|
|
|
|
|
|
|
|
MOZ_ASSERT(!mForceKillTask);
|
|
|
|
int32_t timeoutSecs =
|
|
|
|
Preferences::GetInt("dom.ipc.tabs.shutdownTimeoutSecs", 5);
|
|
|
|
if (timeoutSecs > 0) {
|
|
|
|
MessageLoop::current()->PostDelayedTask(
|
|
|
|
FROM_HERE,
|
|
|
|
mForceKillTask = NewRunnableMethod(this, &ContentParent::KillHard),
|
|
|
|
timeoutSecs * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentParent::NotifyTabDestroyed(PBrowserParent* aTab,
|
|
|
|
bool aNotifiedDestroying)
|
2012-07-17 11:27:27 -07:00
|
|
|
{
|
2013-01-10 05:22:14 -08:00
|
|
|
if (aNotifiedDestroying) {
|
|
|
|
--mNumDestroyingTabs;
|
|
|
|
}
|
|
|
|
|
2012-07-17 11:27:27 -07:00
|
|
|
// There can be more than one PBrowser for a given app process
|
|
|
|
// because of popup windows. When the last one closes, shut
|
|
|
|
// us down.
|
2012-11-27 12:43:52 -08:00
|
|
|
if (ManagedPBrowserParent().Length() == 1) {
|
2012-07-17 11:27:27 -07:00
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
FROM_HERE,
|
2013-07-15 05:55:13 -07:00
|
|
|
NewRunnableMethod(this, &ContentParent::ShutDownProcess,
|
|
|
|
/* force */ false));
|
2012-07-17 11:27:27 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-03 00:24:32 -07:00
|
|
|
jsipc::JavaScriptParent*
|
|
|
|
ContentParent::GetCPOWManager()
|
|
|
|
{
|
|
|
|
if (ManagedPJavaScriptParent().Length()) {
|
|
|
|
return static_cast<JavaScriptParent*>(ManagedPJavaScriptParent()[0]);
|
|
|
|
}
|
|
|
|
JavaScriptParent* actor = static_cast<JavaScriptParent*>(SendPJavaScriptConstructor());
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
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())
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-06-23 16:31:58 -07:00
|
|
|
return static_cast<TestShellParent*>(ManagedPTestShellParent()[0]);
|
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:40 -07:00
|
|
|
void
|
|
|
|
ContentParent::InitializeMembers()
|
|
|
|
{
|
|
|
|
mSubprocess = nullptr;
|
|
|
|
mChildID = gContentChildID++;
|
|
|
|
mGeolocationWatchID = -1;
|
|
|
|
mForceKillTask = nullptr;
|
|
|
|
mNumDestroyingTabs = 0;
|
|
|
|
mIsAlive = true;
|
|
|
|
mSendPermissionUpdates = false;
|
|
|
|
mCalledClose = false;
|
|
|
|
mCalledCloseWithError = false;
|
|
|
|
mCalledKillHard = false;
|
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
ContentParent::ContentParent(mozIApplication* aApp,
|
2012-08-29 05:24:48 -07:00
|
|
|
bool aIsForBrowser,
|
2013-04-25 17:53:26 -07:00
|
|
|
bool aIsForPreallocated,
|
2013-06-03 03:14:40 -07:00
|
|
|
ProcessPriority aInitialPriority /* = PROCESS_PRIORITY_FOREGROUND */,
|
|
|
|
bool aIsNuwaProcess /* = false */)
|
2014-03-12 15:48:15 -07:00
|
|
|
: mIsForBrowser(aIsForBrowser)
|
2014-01-14 10:35:08 -08:00
|
|
|
, mIsNuwaProcess(aIsNuwaProcess)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2013-06-03 03:14:40 -07:00
|
|
|
InitializeMembers(); // Perform common initialization.
|
|
|
|
|
2014-01-14 21:17:34 -08:00
|
|
|
// No more than one of !!aApp, aIsForBrowser, aIsForPreallocated should be
|
|
|
|
// true.
|
|
|
|
MOZ_ASSERT(!!aApp + aIsForBrowser + aIsForPreallocated <= 1);
|
|
|
|
|
|
|
|
// Only the preallocated process uses Nuwa.
|
|
|
|
MOZ_ASSERT_IF(aIsNuwaProcess, aIsForPreallocated);
|
2013-04-25 17:53:26 -07:00
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
// Insert ourselves into the global linked list of ContentParent objects.
|
2013-07-17 14:31:10 -07:00
|
|
|
if (!sContentParents) {
|
|
|
|
sContentParents = new LinkedList<ContentParent>();
|
|
|
|
}
|
2013-06-03 03:14:40 -07:00
|
|
|
if (!aIsNuwaProcess) {
|
|
|
|
sContentParents->insertBack(this);
|
|
|
|
}
|
2013-04-25 17:53:26 -07:00
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
if (aApp) {
|
|
|
|
aApp->GetManifestURL(mAppManifestURL);
|
|
|
|
aApp->GetName(mAppName);
|
|
|
|
} else if (aIsForPreallocated) {
|
|
|
|
mAppManifestURL = MAGIC_PREALLOCATED_APP_MANIFEST_URL;
|
|
|
|
}
|
|
|
|
|
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!");
|
2014-03-12 15:48:15 -07:00
|
|
|
ChildPrivileges privs = aIsNuwaProcess
|
|
|
|
? base::PRIVILEGES_INHERIT
|
|
|
|
: base::PRIVILEGES_DEFAULT;
|
|
|
|
mSubprocess = new GeckoChildProcessHost(GeckoProcessType_Content, privs);
|
2013-11-01 19:09:45 -07:00
|
|
|
mSubprocess->SetSandboxEnabled(ShouldSandboxContentProcesses());
|
2012-07-17 16:59:44 -07:00
|
|
|
|
2013-06-03 03:14:40 -07:00
|
|
|
IToplevelProtocol::SetTransport(mSubprocess->GetChannel());
|
|
|
|
|
2014-03-03 14:27:03 -08:00
|
|
|
if (!aIsNuwaProcess) {
|
|
|
|
// Tell the memory reporter manager that this ContentParent exists.
|
|
|
|
nsRefPtr<nsMemoryReporterManager> mgr =
|
|
|
|
nsMemoryReporterManager::GetOrCreate();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->IncrementNumChildProcesses();
|
|
|
|
}
|
2013-10-22 22:26:24 -07:00
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:40 -07:00
|
|
|
std::vector<std::string> extraArgs;
|
|
|
|
if (aIsNuwaProcess) {
|
|
|
|
extraArgs.push_back("-nuwa");
|
|
|
|
}
|
|
|
|
mSubprocess->LaunchAndWaitForProcessHandle(extraArgs);
|
2013-01-26 13:14:01 -08:00
|
|
|
|
2013-09-30 17:56:16 -07:00
|
|
|
Open(mSubprocess->GetChannel(), mSubprocess->GetOwnedChildProcessHandle());
|
2010-03-10 21:33:00 -08:00
|
|
|
|
2013-11-29 01:28:54 -08:00
|
|
|
InitInternal(aInitialPriority,
|
|
|
|
true, /* Setup off-main thread compositing */
|
|
|
|
true /* Send registered chrome */);
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:40 -07:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
2013-11-29 01:28:54 -08:00
|
|
|
static const mozilla::ipc::FileDescriptor*
|
2013-06-03 03:14:40 -07:00
|
|
|
FindFdProtocolFdMapping(const nsTArray<ProtocolFdMapping>& aFds,
|
|
|
|
ProtocolId aProtoId)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; i < aFds.Length(); i++) {
|
|
|
|
if (aFds[i].protocolId() == aProtoId) {
|
|
|
|
return &aFds[i].fd();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This constructor is used for new content process cloned from a template.
|
|
|
|
*
|
|
|
|
* For Nuwa.
|
|
|
|
*/
|
|
|
|
ContentParent::ContentParent(ContentParent* aTemplate,
|
|
|
|
const nsAString& aAppManifestURL,
|
|
|
|
base::ProcessHandle aPid,
|
2014-03-12 15:48:15 -07:00
|
|
|
const nsTArray<ProtocolFdMapping>& aFds)
|
|
|
|
: mAppManifestURL(aAppManifestURL)
|
2013-06-03 03:14:40 -07:00
|
|
|
, mIsForBrowser(false)
|
2014-01-14 10:35:08 -08:00
|
|
|
, mIsNuwaProcess(false)
|
2013-06-03 03:14:40 -07:00
|
|
|
{
|
|
|
|
InitializeMembers(); // Perform common initialization.
|
|
|
|
|
|
|
|
sContentParents->insertBack(this);
|
|
|
|
|
|
|
|
// From this point on, NS_WARNING, NS_ASSERTION, etc. should print out the
|
|
|
|
// PID along with the warning.
|
|
|
|
nsDebugImpl::SetMultiprocessMode("Parent");
|
|
|
|
|
|
|
|
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
|
|
|
|
|
|
|
const FileDescriptor* fd = FindFdProtocolFdMapping(aFds, GetProtocolId());
|
|
|
|
|
|
|
|
NS_ASSERTION(fd != nullptr, "IPC Channel for PContent is necessary!");
|
|
|
|
mSubprocess = new GeckoExistingProcessHost(GeckoProcessType_Content,
|
|
|
|
aPid,
|
2014-03-12 15:48:15 -07:00
|
|
|
*fd);
|
2013-06-03 03:14:40 -07:00
|
|
|
|
2014-03-03 14:27:03 -08:00
|
|
|
// Tell the memory reporter manager that this ContentParent exists.
|
|
|
|
nsRefPtr<nsMemoryReporterManager> mgr =
|
|
|
|
nsMemoryReporterManager::GetOrCreate();
|
|
|
|
if (mgr) {
|
|
|
|
mgr->IncrementNumChildProcesses();
|
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:40 -07:00
|
|
|
mSubprocess->LaunchAndWaitForProcessHandle();
|
|
|
|
|
|
|
|
// Clone actors routed by aTemplate for this instance.
|
|
|
|
IToplevelProtocol::SetTransport(mSubprocess->GetChannel());
|
|
|
|
ProtocolCloneContext cloneContext;
|
|
|
|
cloneContext.SetContentParent(this);
|
|
|
|
CloneManagees(aTemplate, &cloneContext);
|
|
|
|
CloneOpenedToplevels(aTemplate, aFds, aPid, &cloneContext);
|
|
|
|
|
|
|
|
Open(mSubprocess->GetChannel(),
|
|
|
|
mSubprocess->GetChildProcessHandle());
|
|
|
|
|
|
|
|
// Set the subprocess's priority (bg if we're a preallocated process, fg
|
|
|
|
// otherwise). We do this first because we're likely /lowering/ its CPU and
|
|
|
|
// memory priority, which it has inherited from this process.
|
|
|
|
ProcessPriority priority;
|
|
|
|
if (IsPreallocated()) {
|
2014-03-13 00:24:42 -07:00
|
|
|
priority = PROCESS_PRIORITY_PREALLOC;
|
2013-06-03 03:14:40 -07:00
|
|
|
} else {
|
|
|
|
priority = PROCESS_PRIORITY_FOREGROUND;
|
|
|
|
}
|
|
|
|
|
2013-11-29 01:28:54 -08:00
|
|
|
InitInternal(priority,
|
|
|
|
false, /* Setup Off-main thread compositing */
|
|
|
|
false /* Send registered chrome */);
|
2013-06-03 03:14:40 -07:00
|
|
|
}
|
|
|
|
#endif // MOZ_NUWA_PROCESS
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
ContentParent::~ContentParent()
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2013-01-10 05:22:14 -08:00
|
|
|
if (mForceKillTask) {
|
|
|
|
mForceKillTask->Cancel();
|
|
|
|
}
|
|
|
|
|
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.
|
2013-04-25 17:53:26 -07:00
|
|
|
MOZ_ASSERT(!sPrivateContent || !sPrivateContent->Contains(this));
|
2012-07-13 14:10:20 -07:00
|
|
|
if (mAppManifestURL.IsEmpty()) {
|
2013-04-25 17:53:26 -07:00
|
|
|
MOZ_ASSERT(!sNonAppContentParents ||
|
|
|
|
!sNonAppContentParents->Contains(this));
|
2012-07-13 14:10:20 -07:00
|
|
|
} else {
|
2013-04-25 17:53:26 -07:00
|
|
|
// In general, we expect sAppContentParents->Get(mAppManifestURL) to be
|
2013-10-28 07:04:12 -07:00
|
|
|
// nullptr. But it could be that we created another ContentParent for
|
|
|
|
// this app after we did this->ActorDestroy(), so the right check is
|
|
|
|
// that sAppContentParents->Get(mAppManifestURL) != this.
|
2013-04-25 17:53:26 -07:00
|
|
|
MOZ_ASSERT(!sAppContentParents ||
|
|
|
|
sAppContentParents->Get(mAppManifestURL) != this);
|
2012-07-13 14:10:20 -07:00
|
|
|
}
|
2010-04-11 17:24:45 -07:00
|
|
|
}
|
|
|
|
|
2013-11-29 01:28:54 -08:00
|
|
|
void
|
|
|
|
ContentParent::InitInternal(ProcessPriority aInitialPriority,
|
|
|
|
bool aSetupOffMainThreadCompositing,
|
|
|
|
bool aSendRegisteredChrome)
|
|
|
|
{
|
|
|
|
// Set the subprocess's priority. We do this early on because we're likely
|
|
|
|
// /lowering/ the process's CPU and memory priority, which it has inherited
|
|
|
|
// from this process.
|
|
|
|
//
|
|
|
|
// This call can cause us to send IPC messages to the child process, so it
|
|
|
|
// must come after the Open() call above.
|
|
|
|
ProcessPriorityManager::SetProcessPriority(this, aInitialPriority);
|
|
|
|
|
|
|
|
if (aSetupOffMainThreadCompositing) {
|
|
|
|
// NB: internally, this will send an IPC message to the child
|
|
|
|
// process to get it to create the CompositorChild. This
|
|
|
|
// message goes through the regular IPC queue for this
|
|
|
|
// channel, so delivery will happen-before any other messages
|
|
|
|
// we send. The CompositorChild must be created before any
|
|
|
|
// PBrowsers are created, because they rely on the Compositor
|
|
|
|
// already being around. (Creation is async, so can't happen
|
|
|
|
// on demand.)
|
|
|
|
bool useOffMainThreadCompositing = !!CompositorParent::CompositorLoop();
|
|
|
|
if (useOffMainThreadCompositing) {
|
|
|
|
DebugOnly<bool> opened = PCompositor::Open(this);
|
|
|
|
MOZ_ASSERT(opened);
|
|
|
|
|
2014-02-26 18:52:54 -08:00
|
|
|
if (gfxPrefs::AsyncVideoEnabled()) {
|
2013-11-29 01:28:54 -08:00
|
|
|
opened = PImageBridge::Open(this);
|
|
|
|
MOZ_ASSERT(opened);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aSendRegisteredChrome) {
|
|
|
|
nsCOMPtr<nsIChromeRegistry> registrySvc = nsChromeRegistry::GetService();
|
|
|
|
nsChromeRegistryChrome* chromeRegistry =
|
|
|
|
static_cast<nsChromeRegistryChrome*>(registrySvc.get());
|
|
|
|
chromeRegistry->SendRegisteredChrome(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
mMessageManager = nsFrameMessageManager::NewProcessMessageManager(this);
|
|
|
|
|
|
|
|
if (gAppData) {
|
|
|
|
nsCString version(gAppData->version);
|
|
|
|
nsCString buildID(gAppData->buildID);
|
|
|
|
nsCString name(gAppData->name);
|
|
|
|
nsCString UAName(gAppData->UAName);
|
|
|
|
|
|
|
|
// Sending all information to content process.
|
|
|
|
unused << SendAppInfo(version, buildID, name, UAName);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsStyleSheetService *sheetService = nsStyleSheetService::GetInstance();
|
|
|
|
if (sheetService) {
|
|
|
|
// This looks like a lot of work, but in a normal browser session we just
|
|
|
|
// send two loads.
|
|
|
|
|
|
|
|
nsCOMArray<nsIStyleSheet>& agentSheets = *sheetService->AgentStyleSheets();
|
|
|
|
for (uint32_t i = 0; i < agentSheets.Length(); i++) {
|
|
|
|
URIParams uri;
|
|
|
|
SerializeURI(agentSheets[i]->GetSheetURI(), uri);
|
|
|
|
unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AGENT_SHEET);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMArray<nsIStyleSheet>& userSheets = *sheetService->UserStyleSheets();
|
|
|
|
for (uint32_t i = 0; i < userSheets.Length(); i++) {
|
|
|
|
URIParams uri;
|
|
|
|
SerializeURI(userSheets[i]->GetSheetURI(), uri);
|
|
|
|
unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::USER_SHEET);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMArray<nsIStyleSheet>& authorSheets = *sheetService->AuthorStyleSheets();
|
|
|
|
for (uint32_t i = 0; i < authorSheets.Length(); i++) {
|
|
|
|
URIParams uri;
|
|
|
|
SerializeURI(authorSheets[i]->GetSheetURI(), uri);
|
|
|
|
unused << SendLoadAndRegisterSheet(uri, nsIStyleSheetService::AUTHOR_SHEET);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_CONTENT_SANDBOX
|
2014-03-12 15:48:15 -07:00
|
|
|
bool shouldSandbox = true;
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
if (IsNuwaProcess()) {
|
|
|
|
shouldSandbox = false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (shouldSandbox && !SendSetProcessSandbox()) {
|
|
|
|
KillHard();
|
2013-11-29 01:28:54 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2014-01-14 10:35:08 -08:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
bool
|
|
|
|
ContentParent::IsNuwaProcess()
|
|
|
|
{
|
|
|
|
return mIsNuwaProcess;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-07-17 14:31:10 -07:00
|
|
|
int32_t
|
|
|
|
ContentParent::Pid()
|
|
|
|
{
|
|
|
|
if (!mSubprocess || !mSubprocess->GetChildProcessHandle()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return base::GetProcId(mSubprocess->GetChildProcessHandle());
|
|
|
|
}
|
|
|
|
|
2010-05-25 17:13:47 -07:00
|
|
|
bool
|
2012-08-22 13:00:21 -07:00
|
|
|
ContentParent::RecvReadPrefsArray(InfallibleTArray<PrefSetting>* aPrefs)
|
2010-05-25 17:13:47 -07:00
|
|
|
{
|
2012-08-22 13:00:21 -07:00
|
|
|
Preferences::GetPreferences(aPrefs);
|
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);
|
2012-08-23 11:38:01 -07:00
|
|
|
uint32_t appId;
|
|
|
|
perm->GetAppId(&appId);
|
|
|
|
bool isInBrowserElement;
|
|
|
|
perm->GetIsInBrowserElement(&isInBrowserElement);
|
2010-10-09 11:07:38 -07:00
|
|
|
nsCString type;
|
|
|
|
perm->GetType(type);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t capability;
|
2010-10-09 11:07:38 -07:00
|
|
|
perm->GetCapability(&capability);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t expireType;
|
2010-10-09 11:07:38 -07:00
|
|
|
perm->GetExpireType(&expireType);
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t expireTime;
|
2010-10-09 11:07:38 -07:00
|
|
|
perm->GetExpireTime(&expireTime);
|
|
|
|
|
2012-08-23 11:38:01 -07:00
|
|
|
aPermissions->AppendElement(IPC::Permission(host, appId,
|
|
|
|
isInBrowserElement, 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
|
2012-08-14 20:37:44 -07:00
|
|
|
ContentParent::RecvSetClipboardText(const nsString& text,
|
|
|
|
const bool& isPrivateData,
|
2012-08-22 08:56:38 -07:00
|
|
|
const int32_t& whichClipboard)
|
2011-02-28 21:36:43 -08:00
|
|
|
{
|
|
|
|
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);
|
2014-02-09 16:13:10 -08:00
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
rv = dataWrapper->SetData(text);
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
2014-02-09 16:13:10 -08:00
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
nsCOMPtr<nsITransferable> trans = do_CreateInstance("@mozilla.org/widget/transferable;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
2012-07-30 07:20:58 -07:00
|
|
|
trans->Init(nullptr);
|
2014-02-09 16:13:10 -08:00
|
|
|
|
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);
|
2012-08-14 20:37:44 -07:00
|
|
|
trans->SetIsPrivateData(isPrivateData);
|
2014-02-09 16:13:10 -08:00
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
nsCOMPtr<nsISupports> nsisupportsDataWrapper =
|
|
|
|
do_QueryInterface(dataWrapper);
|
2014-02-09 16:13:10 -08:00
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
rv = trans->SetTransferData(kUnicodeMime, nsisupportsDataWrapper,
|
2014-01-04 07:02:17 -08:00
|
|
|
text.Length() * sizeof(char16_t));
|
2011-02-28 21:36:43 -08:00
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
2014-02-09 16:13:10 -08:00
|
|
|
|
2013-10-28 07:04:12 -07:00
|
|
|
clipboard->SetData(trans, nullptr, whichClipboard);
|
2011-02-28 21:36:43 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
ContentParent::RecvGetClipboardText(const int32_t& whichClipboard, nsString* text)
|
2011-02-28 21:36:43 -08:00
|
|
|
{
|
|
|
|
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-07-30 07:20:58 -07:00
|
|
|
trans->Init(nullptr);
|
2014-02-09 16:13:10 -08:00
|
|
|
trans->AddDataFlavor(kUnicodeMime);
|
|
|
|
|
2011-02-28 21:36:43 -08:00
|
|
|
clipboard->GetData(trans, whichClipboard);
|
|
|
|
nsCOMPtr<nsISupports> tmp;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len;
|
2011-08-09 12:38:26 -07:00
|
|
|
rv = trans->GetTransferData(kUnicodeMime, getter_AddRefs(tmp), &len);
|
|
|
|
if (NS_FAILED(rv))
|
2014-02-09 16:13:10 -08:00
|
|
|
return true;
|
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)
|
2014-02-09 16:13:10 -08:00
|
|
|
return true;
|
2011-02-28 21:36:43 -08:00
|
|
|
supportsString->GetData(*text);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-09 16:13:10 -08:00
|
|
|
ContentParent::RecvEmptyClipboard(const int32_t& whichClipboard)
|
2011-02-28 21:36:43 -08:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
2014-02-09 16:13:10 -08:00
|
|
|
clipboard->EmptyClipboard(whichClipboard);
|
2011-02-28 21:36:43 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-02-09 16:13:10 -08:00
|
|
|
ContentParent::RecvClipboardHasText(const int32_t& whichClipboard, bool* hasText)
|
2011-02-28 21:36:43 -08:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIClipboard> clipboard(do_GetService(kCClipboardCID, &rv));
|
|
|
|
NS_ENSURE_SUCCESS(rv, true);
|
|
|
|
|
2014-02-09 16:13:10 -08:00
|
|
|
clipboard->HasDataMatchingFlavors(sClipboardTextFlavors, 1,
|
|
|
|
whichClipboard, hasText);
|
2011-02-28 21:36:43 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-30 11:04:41 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
ContentParent::RecvGetSystemColors(const uint32_t& colorsCount, InfallibleTArray<uint32_t>* colors)
|
2011-03-30 11:04:41 -07:00
|
|
|
{
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(AndroidBridge::Bridge() != nullptr, "AndroidBridge is not available");
|
|
|
|
if (AndroidBridge::Bridge() == nullptr) {
|
2011-07-27 17:34:47 -07:00
|
|
|
// 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
|
2012-08-22 08:56:38 -07:00
|
|
|
ContentParent::RecvGetIconForExtension(const nsCString& aFileExt, const uint32_t& aIconSize, InfallibleTArray<uint8_t>* bits)
|
2011-06-13 14:02:13 -07:00
|
|
|
{
|
2011-11-10 16:17:46 -08:00
|
|
|
#ifdef MOZ_WIDGET_ANDROID
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(AndroidBridge::Bridge() != nullptr, "AndroidBridge is not available");
|
|
|
|
if (AndroidBridge::Bridge() == nullptr) {
|
2011-07-27 17:34:47 -07:00
|
|
|
// 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
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(AndroidBridge::Bridge() != nullptr, "AndroidBridge is not available");
|
2013-11-12 10:41:01 -08:00
|
|
|
|
|
|
|
*showPassword = GeckoAppShell::GetShowPasswordSetting();
|
2011-07-26 18:14:52 -07:00
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-10-08 21:46:19 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvFirstIdle()
|
|
|
|
{
|
2013-06-03 03:14:40 -07:00
|
|
|
// When the ContentChild goes idle, it sends us a FirstIdle message
|
|
|
|
// which we use as a good time to prelaunch another process. If we
|
|
|
|
// prelaunch any sooner than this, then we'll be competing with the
|
2012-10-08 21:46:19 -07:00
|
|
|
// child process and slowing it down.
|
2013-05-09 13:27:06 -07:00
|
|
|
PreallocatedProcessManager::AllocateAfterDelay();
|
2012-10-08 21:46:19 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-05 19:01:58 -08:00
|
|
|
bool
|
2013-09-02 02:45:44 -07:00
|
|
|
ContentParent::RecvAudioChannelGetState(const AudioChannelType& aType,
|
2013-01-08 23:18:16 -08:00
|
|
|
const bool& aElementHidden,
|
|
|
|
const bool& aElementWasHidden,
|
2013-09-02 02:45:44 -07:00
|
|
|
AudioChannelState* aState)
|
2012-12-05 19:01:58 -08:00
|
|
|
{
|
|
|
|
nsRefPtr<AudioChannelService> service =
|
|
|
|
AudioChannelService::GetAudioChannelService();
|
2013-09-02 02:45:44 -07:00
|
|
|
*aState = AUDIO_CHANNEL_STATE_NORMAL;
|
2012-12-05 19:01:58 -08:00
|
|
|
if (service) {
|
2013-09-02 02:45:44 -07:00
|
|
|
*aState = service->GetStateInternal(aType, mChildID,
|
2013-01-08 23:18:16 -08:00
|
|
|
aElementHidden, aElementWasHidden);
|
2012-12-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-09-17 20:46:22 -07:00
|
|
|
ContentParent::RecvAudioChannelRegisterType(const AudioChannelType& aType,
|
|
|
|
const bool& aWithVideo)
|
2012-12-05 19:01:58 -08:00
|
|
|
{
|
|
|
|
nsRefPtr<AudioChannelService> service =
|
|
|
|
AudioChannelService::GetAudioChannelService();
|
|
|
|
if (service) {
|
2013-09-17 20:46:22 -07:00
|
|
|
service->RegisterType(aType, mChildID, aWithVideo);
|
2012-12-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-01-08 23:18:16 -08:00
|
|
|
ContentParent::RecvAudioChannelUnregisterType(const AudioChannelType& aType,
|
2013-09-17 20:46:22 -07:00
|
|
|
const bool& aElementHidden,
|
|
|
|
const bool& aWithVideo)
|
2012-12-05 19:01:58 -08:00
|
|
|
{
|
|
|
|
nsRefPtr<AudioChannelService> service =
|
|
|
|
AudioChannelService::GetAudioChannelService();
|
|
|
|
if (service) {
|
2013-09-17 20:46:22 -07:00
|
|
|
service->UnregisterType(aType, aElementHidden, mChildID, aWithVideo);
|
2013-01-08 23:18:16 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvAudioChannelChangedNotification()
|
|
|
|
{
|
|
|
|
nsRefPtr<AudioChannelService> service =
|
|
|
|
AudioChannelService::GetAudioChannelService();
|
|
|
|
if (service) {
|
2013-04-25 17:53:26 -07:00
|
|
|
service->SendAudioChannelChangedNotification(ChildID());
|
2012-12-05 19:01:58 -08:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-12 05:26:03 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvAudioChannelChangeDefVolChannel(
|
|
|
|
const AudioChannelType& aType, const bool& aHidden)
|
|
|
|
{
|
|
|
|
nsRefPtr<AudioChannelService> service =
|
|
|
|
AudioChannelService::GetAudioChannelService();
|
|
|
|
if (service) {
|
|
|
|
service->SetDefaultVolumeControlChannelInternal(aType,
|
|
|
|
aHidden, mChildID);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-14 16:01:34 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvBroadcastVolume(const nsString& aVolumeName)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIVolumeService> vs = do_GetService(NS_VOLUMESERVICE_CONTRACTID, &rv);
|
|
|
|
if (vs) {
|
|
|
|
vs->BroadcastVolume(aVolumeName);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_WARNING("ContentParent::RecvBroadcastVolume shouldn't be called when MOZ_WIDGET_GONK is not defined");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-06-03 03:14:40 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvNuwaReady()
|
|
|
|
{
|
2013-11-21 19:25:34 -08:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
2014-03-06 05:52:52 -08:00
|
|
|
if (!IsNuwaProcess()) {
|
|
|
|
printf_stderr("Terminating child process %d for unauthorized IPC message: "
|
|
|
|
"NuwaReady", Pid());
|
|
|
|
KillHard();
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-21 19:25:34 -08:00
|
|
|
PreallocatedProcessManager::OnNuwaReady();
|
2013-06-03 03:14:40 -07:00
|
|
|
return true;
|
2013-11-21 19:25:34 -08:00
|
|
|
#else
|
|
|
|
NS_ERROR("ContentParent::RecvNuwaReady() not implemented!");
|
|
|
|
return false;
|
|
|
|
#endif
|
2013-06-03 03:14:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvAddNewProcess(const uint32_t& aPid,
|
|
|
|
const InfallibleTArray<ProtocolFdMapping>& aFds)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
2014-03-06 05:52:52 -08:00
|
|
|
if (!IsNuwaProcess()) {
|
|
|
|
printf_stderr("Terminating child process %d for unauthorized IPC message: "
|
|
|
|
"AddNewProcess(%d)", Pid(), aPid);
|
|
|
|
KillHard();
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-03 03:14:40 -07:00
|
|
|
nsRefPtr<ContentParent> content;
|
|
|
|
content = new ContentParent(this,
|
|
|
|
MAGIC_PREALLOCATED_APP_MANIFEST_URL,
|
|
|
|
aPid,
|
2014-03-12 15:48:15 -07:00
|
|
|
aFds);
|
2013-06-03 03:14:40 -07:00
|
|
|
content->Init();
|
2013-11-21 19:25:34 -08:00
|
|
|
PreallocatedProcessManager::PublishSpareProcess(content);
|
2013-06-03 03:14:40 -07:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_ERROR("ContentParent::RecvAddNewProcess() not implemented!");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-03-19 17:22:25 -07:00
|
|
|
// We want ContentParent to show up in CC logs for debugging purposes, but we
|
|
|
|
// don't actually cycle collect it.
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_0(ContentParent)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(ContentParent)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(ContentParent)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ContentParent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMGeoPositionCallback)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_END
|
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,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aData)
|
2009-09-02 17:18:27 -07:00
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "xpcom-shutdown") && mSubprocess) {
|
2013-07-17 12:13:20 -07:00
|
|
|
ShutDownProcess(/* closeWithError */ false);
|
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
|
2012-11-07 17:07:57 -08:00
|
|
|
if (!strcmp(aTopic, "memory-pressure") &&
|
2013-04-25 18:36:53 -07:00
|
|
|
!StringEndsWith(nsDependentString(aData),
|
|
|
|
NS_LITERAL_STRING("-no-forward"))) {
|
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
|
|
|
|
2012-08-22 13:00:21 -07:00
|
|
|
PrefSetting pref(strData, null_t(), null_t());
|
|
|
|
Preferences::GetPreference(&pref);
|
|
|
|
if (!SendPreferenceUpdate(pref)) {
|
|
|
|
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") ||
|
2013-03-18 06:24:53 -07:00
|
|
|
!strcmp(aTopic, "alertclickcallback") ||
|
|
|
|
!strcmp(aTopic, "alertshow") ) {
|
2010-09-15 09:44:57 -07:00
|
|
|
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")) {
|
2014-03-04 18:27:13 -08:00
|
|
|
bool isNuwa = false;
|
2014-01-14 10:35:08 -08:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
2014-03-04 18:27:13 -08:00
|
|
|
isNuwa = IsNuwaProcess();
|
2014-01-14 10:35:08 -08:00
|
|
|
#endif
|
2014-03-04 18:27:13 -08:00
|
|
|
if (!isNuwa) {
|
|
|
|
unsigned generation;
|
|
|
|
int minimize, identOffset = -1;
|
|
|
|
nsDependentString msg(aData);
|
|
|
|
NS_ConvertUTF16toUTF8 cmsg(msg);
|
|
|
|
|
|
|
|
if (sscanf(cmsg.get(),
|
|
|
|
"generation=%x minimize=%d DMDident=%n",
|
|
|
|
&generation, &minimize, &identOffset) < 2
|
|
|
|
|| identOffset < 0) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
// The pre-%n part of the string should be all ASCII, so the byte
|
|
|
|
// offset in identOffset should be correct as a char offset.
|
|
|
|
MOZ_ASSERT(cmsg[identOffset - 1] == '=');
|
|
|
|
unused << SendPMemoryReportRequestConstructor(
|
|
|
|
generation, minimize, nsString(Substring(msg, identOffset)));
|
|
|
|
}
|
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
|
|
|
}
|
2013-12-02 20:07:02 -08:00
|
|
|
else if (!strcmp(aTopic, "child-mmu-request")){
|
|
|
|
unused << SendMinimizeMemoryUsage();
|
|
|
|
}
|
2012-04-19 17:13:20 -07:00
|
|
|
else if (!strcmp(aTopic, "last-pb-context-exited")) {
|
|
|
|
unused << SendLastPrivateDocShellDestroyed();
|
|
|
|
}
|
2012-08-17 19:43:00 -07:00
|
|
|
else if (!strcmp(aTopic, "file-watcher-update")) {
|
|
|
|
nsCString creason;
|
|
|
|
CopyUTF16toUTF8(aData, creason);
|
2012-08-30 15:17:37 -07:00
|
|
|
DeviceStorageFile* file = static_cast<DeviceStorageFile*>(aSubject);
|
2012-08-17 19:43:00 -07:00
|
|
|
|
2013-05-11 02:10:18 -07:00
|
|
|
unused << SendFilePathUpdate(file->mStorageType, file->mStorageName, file->mPath, creason);
|
2012-08-17 19:43:00 -07:00
|
|
|
}
|
2012-08-03 16:48:58 -07:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
else if(!strcmp(aTopic, NS_VOLUME_STATE_CHANGED)) {
|
|
|
|
nsCOMPtr<nsIVolume> vol = do_QueryInterface(aSubject);
|
|
|
|
if (!vol) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString volName;
|
|
|
|
nsString mountPoint;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t state;
|
2012-12-14 16:01:34 -08:00
|
|
|
int32_t mountGeneration;
|
2013-08-22 16:12:25 -07:00
|
|
|
bool isMediaPresent;
|
|
|
|
bool isSharing;
|
2013-12-03 01:32:56 -08:00
|
|
|
bool isFormatting;
|
2012-08-03 16:48:58 -07:00
|
|
|
|
|
|
|
vol->GetName(volName);
|
|
|
|
vol->GetMountPoint(mountPoint);
|
|
|
|
vol->GetState(&state);
|
2012-12-14 16:01:34 -08:00
|
|
|
vol->GetMountGeneration(&mountGeneration);
|
2013-08-22 16:12:25 -07:00
|
|
|
vol->GetIsMediaPresent(&isMediaPresent);
|
|
|
|
vol->GetIsSharing(&isSharing);
|
2013-12-03 01:32:56 -08:00
|
|
|
vol->GetIsFormatting(&isFormatting);
|
2012-08-03 16:48:58 -07:00
|
|
|
|
2012-12-14 16:01:34 -08:00
|
|
|
unused << SendFileSystemUpdate(volName, mountPoint, state,
|
2013-08-22 16:12:25 -07:00
|
|
|
mountGeneration, isMediaPresent,
|
2013-12-03 01:32:56 -08:00
|
|
|
isSharing, isFormatting);
|
2013-09-13 01:51:45 -07:00
|
|
|
} else if (!strcmp(aTopic, "phone-state-changed")) {
|
|
|
|
nsString state(aData);
|
|
|
|
unused << SendNotifyPhoneStateChange(state);
|
2012-08-03 16:48:58 -07:00
|
|
|
}
|
|
|
|
#endif
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-25 21:19:09 -07:00
|
|
|
PCompositorParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPCompositorParent(mozilla::ipc::Transport* aTransport,
|
|
|
|
base::ProcessId aOtherProcess)
|
2012-07-17 16:59:45 -07:00
|
|
|
{
|
|
|
|
return CompositorParent::Create(aTransport, aOtherProcess);
|
|
|
|
}
|
|
|
|
|
2013-09-25 21:19:09 -07:00
|
|
|
PImageBridgeParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPImageBridgeParent(mozilla::ipc::Transport* aTransport,
|
|
|
|
base::ProcessId aOtherProcess)
|
2012-08-29 05:24:48 -07:00
|
|
|
{
|
|
|
|
return ImageBridgeParent::Create(aTransport, aOtherProcess);
|
|
|
|
}
|
|
|
|
|
2013-11-26 23:59:41 -08:00
|
|
|
PBackgroundParent*
|
|
|
|
ContentParent::AllocPBackgroundParent(Transport* aTransport,
|
|
|
|
ProcessId aOtherProcess)
|
|
|
|
{
|
|
|
|
return BackgroundParent::Alloc(this, aTransport, aOtherProcess);
|
|
|
|
}
|
|
|
|
|
2012-09-04 17:36:16 -07:00
|
|
|
bool
|
2013-01-26 13:14:01 -08:00
|
|
|
ContentParent::RecvGetProcessAttributes(uint64_t* aId,
|
2012-09-04 17:36:16 -07:00
|
|
|
bool* aIsForApp, bool* aIsForBrowser)
|
|
|
|
{
|
2013-02-15 05:40:35 -08:00
|
|
|
*aId = mChildID;
|
2012-09-04 17:36:16 -07:00
|
|
|
*aIsForApp = IsForApp();
|
|
|
|
*aIsForBrowser = mIsForBrowser;
|
2012-11-08 13:09:39 -08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvGetXPCOMProcessAttributes(bool* aIsOffline)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIIOService> io(do_GetIOService());
|
|
|
|
NS_ASSERTION(io, "No IO service?");
|
|
|
|
DebugOnly<nsresult> rv = io->GetOffline(aIsOffline);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "Failed getting offline?");
|
|
|
|
|
2012-09-04 17:36:16 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-03 00:24:32 -07:00
|
|
|
mozilla::jsipc::PJavaScriptParent *
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPJavaScriptParent()
|
2013-07-03 00:24:32 -07:00
|
|
|
{
|
|
|
|
mozilla::jsipc::JavaScriptParent *parent = new mozilla::jsipc::JavaScriptParent();
|
|
|
|
if (!parent->init()) {
|
|
|
|
delete parent;
|
2013-10-28 07:04:12 -07:00
|
|
|
return nullptr;
|
2013-07-03 00:24:32 -07:00
|
|
|
}
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPJavaScriptParent(PJavaScriptParent *parent)
|
2013-07-03 00:24:32 -07:00
|
|
|
{
|
2014-02-05 08:39:59 -08:00
|
|
|
static_cast<mozilla::jsipc::JavaScriptParent *>(parent)->decref();
|
2013-07-03 00:24:32 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-19 11:33:33 -07:00
|
|
|
PBrowserParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPBrowserParent(const IPCTabContext& aContext,
|
|
|
|
const uint32_t &aChromeFlags)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
unused << aChromeFlags;
|
|
|
|
|
2012-11-27 12:43:52 -08:00
|
|
|
const IPCTabAppBrowserContext& appBrowser = aContext.appBrowserContext();
|
|
|
|
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
// We don't trust the IPCTabContext we receive from the child, so we'll bail
|
|
|
|
// if we receive an IPCTabContext that's not a PopupIPCTabContext.
|
|
|
|
// (PopupIPCTabContext lets the child process prove that it has access to
|
|
|
|
// the app it's trying to open.)
|
2012-11-27 12:43:52 -08:00
|
|
|
if (appBrowser.type() != IPCTabAppBrowserContext::TPopupIPCTabContext) {
|
2013-07-08 08:48:39 -07:00
|
|
|
NS_ERROR("Unexpected IPCTabContext type. Aborting AllocPBrowserParent.");
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-27 12:43:52 -08:00
|
|
|
const PopupIPCTabContext& popupContext = appBrowser.get_PopupIPCTabContext();
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
TabParent* opener = static_cast<TabParent*>(popupContext.openerParent());
|
|
|
|
if (!opener) {
|
2013-07-08 08:48:39 -07:00
|
|
|
NS_ERROR("Got null opener from child; aborting AllocPBrowserParent.");
|
2012-08-08 19:58:06 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
// Popup windows of isBrowser frames must be isBrowser if the parent
|
|
|
|
// isBrowser. Allocating a !isBrowser frame with same app ID would allow
|
|
|
|
// the content to access data it's not supposed to.
|
|
|
|
if (!popupContext.isBrowserElement() && opener->IsBrowserElement()) {
|
2013-07-08 08:48:39 -07:00
|
|
|
NS_ERROR("Child trying to escalate privileges! Aborting AllocPBrowserParent.");
|
2012-08-08 19:58:06 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-07-30 14:42:34 -07:00
|
|
|
MaybeInvalidTabContext tc(aContext);
|
|
|
|
if (!tc.IsValid()) {
|
|
|
|
NS_ERROR(nsPrintfCString("Child passed us an invalid TabContext. (%s) "
|
|
|
|
"Aborting AllocPBrowserParent.",
|
|
|
|
tc.GetInvalidReason()).get());
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-01-10 17:10:57 -08:00
|
|
|
TabParent* parent = new TabParent(this, tc.GetTabContext(), aChromeFlags);
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 10:32:37 -08:00
|
|
|
|
2013-07-08 08:48:39 -07:00
|
|
|
// We release this ref in DeallocPBrowserParent()
|
2010-03-26 11:39:39 -07:00
|
|
|
NS_ADDREF(parent);
|
2012-08-08 19:58:06 -07:00
|
|
|
return parent;
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPBrowserParent(PBrowserParent* frame)
|
2009-08-12 09:18:08 -07:00
|
|
|
{
|
2012-08-08 19:58:06 -07:00
|
|
|
TabParent* parent = static_cast<TabParent*>(frame);
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
return true;
|
2009-08-12 09:18:08 -07:00
|
|
|
}
|
|
|
|
|
2012-06-19 16:14:39 -07:00
|
|
|
PDeviceStorageRequestParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPDeviceStorageRequestParent(const DeviceStorageParams& aParams)
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
2012-11-29 21:41:40 -08:00
|
|
|
nsRefPtr<DeviceStorageRequestParent> result = new DeviceStorageRequestParent(aParams);
|
|
|
|
if (!result->EnsureRequiredPermissions(this)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
result->Dispatch();
|
2014-03-15 12:00:15 -07:00
|
|
|
return result.forget().take();
|
2012-06-19 16:14:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPDeviceStorageRequestParent(PDeviceStorageRequestParent* doomed)
|
2012-06-19 16:14:39 -07:00
|
|
|
{
|
2012-08-09 15:41:18 -07:00
|
|
|
DeviceStorageRequestParent *parent = static_cast<DeviceStorageRequestParent*>(doomed);
|
|
|
|
NS_RELEASE(parent);
|
2012-06-19 16:14:39 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-04 19:25:40 -08:00
|
|
|
PFileSystemRequestParent*
|
|
|
|
ContentParent::AllocPFileSystemRequestParent(const FileSystemParams& aParams)
|
|
|
|
{
|
|
|
|
nsRefPtr<FileSystemRequestParent> result = new FileSystemRequestParent();
|
|
|
|
if (!result->Dispatch(this, aParams)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-03-15 12:00:15 -07:00
|
|
|
return result.forget().take();
|
2014-03-04 19:25:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPFileSystemRequestParent(PFileSystemRequestParent* doomed)
|
|
|
|
{
|
|
|
|
FileSystemRequestParent* parent = static_cast<FileSystemRequestParent*>(doomed);
|
|
|
|
NS_RELEASE(parent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-08-01 23:02:29 -07:00
|
|
|
PBlobParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPBlobParent(const BlobConstructorParams& aParams)
|
2012-08-01 23:02:29 -07:00
|
|
|
{
|
2013-07-16 13:07:09 -07:00
|
|
|
return BlobParent::Create(this, aParams);
|
2012-08-01 23:02:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPBlobParent(PBlobParent* aActor)
|
2012-08-01 23:02:29 -07:00
|
|
|
{
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-10 05:47:32 -08:00
|
|
|
BlobParent*
|
|
|
|
ContentParent::GetOrCreateActorForBlob(nsIDOMBlob* aBlob)
|
|
|
|
{
|
2013-08-29 10:16:44 -07:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(aBlob);
|
|
|
|
|
|
|
|
// If the blob represents a remote blob for this ContentParent then we can
|
|
|
|
// simply pass its actor back here.
|
|
|
|
if (nsCOMPtr<nsIRemoteBlob> remoteBlob = do_QueryInterface(aBlob)) {
|
2013-09-17 21:04:20 -07:00
|
|
|
if (BlobParent* actor = static_cast<BlobParent*>(
|
|
|
|
static_cast<PBlobParent*>(remoteBlob->GetPBlob()))) {
|
|
|
|
if (static_cast<ContentParent*>(actor->Manager()) == this) {
|
|
|
|
return actor;
|
|
|
|
}
|
2013-08-29 10:16:44 -07:00
|
|
|
}
|
|
|
|
}
|
2013-01-10 05:47:32 -08:00
|
|
|
|
|
|
|
// XXX This is only safe so long as all blob implementations in our tree
|
|
|
|
// inherit nsDOMFileBase. If that ever changes then this will need to grow
|
|
|
|
// a real interface or something.
|
2013-01-17 12:17:33 -08:00
|
|
|
const nsDOMFileBase* blob = static_cast<nsDOMFileBase*>(aBlob);
|
2013-01-10 05:47:32 -08:00
|
|
|
|
2013-08-29 10:16:44 -07:00
|
|
|
// We often pass blobs that are multipart but that only contain one sub-blob
|
|
|
|
// (WebActivities does this a bunch). Unwrap to reduce the number of actors
|
|
|
|
// that we have to maintain.
|
|
|
|
const nsTArray<nsCOMPtr<nsIDOMBlob> >* subBlobs = blob->GetSubBlobs();
|
|
|
|
if (subBlobs && subBlobs->Length() == 1) {
|
|
|
|
const nsCOMPtr<nsIDOMBlob>& subBlob = subBlobs->ElementAt(0);
|
|
|
|
MOZ_ASSERT(subBlob);
|
|
|
|
|
|
|
|
// We can only take this shortcut if the multipart and the sub-blob are both
|
|
|
|
// Blob objects or both File objects.
|
|
|
|
nsCOMPtr<nsIDOMFile> multipartBlobAsFile = do_QueryInterface(aBlob);
|
|
|
|
nsCOMPtr<nsIDOMFile> subBlobAsFile = do_QueryInterface(subBlob);
|
|
|
|
if (!multipartBlobAsFile == !subBlobAsFile) {
|
|
|
|
// The wrapping might have been unnecessary, see if we can simply pass an
|
|
|
|
// existing remote blob for this ContentParent.
|
|
|
|
if (nsCOMPtr<nsIRemoteBlob> remoteSubBlob = do_QueryInterface(subBlob)) {
|
|
|
|
BlobParent* actor =
|
|
|
|
static_cast<BlobParent*>(
|
|
|
|
static_cast<PBlobParent*>(remoteSubBlob->GetPBlob()));
|
|
|
|
MOZ_ASSERT(actor);
|
|
|
|
|
|
|
|
if (static_cast<ContentParent*>(actor->Manager()) == this) {
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No need to add a reference here since the original blob must have a
|
|
|
|
// strong reference in the caller and it must also have a strong reference
|
|
|
|
// to this sub-blob.
|
|
|
|
aBlob = subBlob;
|
|
|
|
blob = static_cast<nsDOMFileBase*>(aBlob);
|
|
|
|
subBlobs = blob->GetSubBlobs();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-10 10:16:40 -08:00
|
|
|
// All blobs shared between processes must be immutable.
|
|
|
|
nsCOMPtr<nsIMutable> mutableBlob = do_QueryInterface(aBlob);
|
|
|
|
if (!mutableBlob || NS_FAILED(mutableBlob->SetMutable(false))) {
|
|
|
|
NS_WARNING("Failed to make blob immutable!");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-01-17 12:17:33 -08:00
|
|
|
ChildBlobConstructorParams params;
|
|
|
|
|
|
|
|
if (blob->IsSizeUnknown() || blob->IsDateUnknown()) {
|
|
|
|
// We don't want to call GetSize or GetLastModifiedDate
|
|
|
|
// yet since that may stat a file on the main thread
|
|
|
|
// here. Instead we'll learn the size lazily from the
|
|
|
|
// other process.
|
|
|
|
params = MysteryBlobConstructorParams();
|
2012-08-01 23:02:29 -07:00
|
|
|
}
|
2013-01-17 12:17:33 -08:00
|
|
|
else {
|
|
|
|
nsString contentType;
|
|
|
|
nsresult rv = aBlob->GetType(contentType);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2012-08-01 23:02:29 -07:00
|
|
|
|
2013-01-17 12:17:33 -08:00
|
|
|
uint64_t length;
|
|
|
|
rv = aBlob->GetSize(&length);
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2012-08-01 23:02:29 -07:00
|
|
|
|
2013-01-17 12:17:33 -08:00
|
|
|
nsCOMPtr<nsIDOMFile> file = do_QueryInterface(aBlob);
|
|
|
|
if (file) {
|
|
|
|
FileBlobConstructorParams fileParams;
|
2012-08-01 23:02:29 -07:00
|
|
|
|
2013-01-17 12:17:33 -08:00
|
|
|
rv = file->GetMozLastModifiedDate(&fileParams.modDate());
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2013-01-10 05:47:32 -08:00
|
|
|
|
2013-01-17 12:17:33 -08:00
|
|
|
rv = file->GetName(fileParams.name());
|
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
2013-01-10 05:47:32 -08:00
|
|
|
|
2013-01-17 12:17:33 -08:00
|
|
|
fileParams.contentType() = contentType;
|
|
|
|
fileParams.length() = length;
|
2013-01-10 05:47:32 -08:00
|
|
|
|
2013-01-17 12:17:33 -08:00
|
|
|
params = fileParams;
|
|
|
|
} else {
|
|
|
|
NormalBlobConstructorParams blobParams;
|
|
|
|
blobParams.contentType() = contentType;
|
|
|
|
blobParams.length() = length;
|
|
|
|
params = blobParams;
|
2013-01-10 05:47:32 -08:00
|
|
|
}
|
2013-08-29 10:16:44 -07:00
|
|
|
}
|
2013-01-17 12:17:33 -08:00
|
|
|
|
2013-07-16 13:07:09 -07:00
|
|
|
BlobParent* actor = BlobParent::Create(this, aBlob);
|
2013-01-17 12:17:33 -08:00
|
|
|
NS_ENSURE_TRUE(actor, nullptr);
|
|
|
|
|
2013-08-29 10:16:44 -07:00
|
|
|
return SendPBlobConstructor(actor, params) ? actor : nullptr;
|
2012-08-01 23:02:29 -07:00
|
|
|
}
|
|
|
|
|
2012-09-05 15:18:48 -07:00
|
|
|
void
|
|
|
|
ContentParent::KillHard()
|
|
|
|
{
|
2013-08-16 17:44:17 -07:00
|
|
|
// On Windows, calling KillHard multiple times causes problems - the
|
|
|
|
// process handle becomes invalid on the first call, causing a second call
|
|
|
|
// to crash our process - more details in bug 890840.
|
|
|
|
if (mCalledKillHard) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mCalledKillHard = true;
|
2013-01-10 05:22:14 -08:00
|
|
|
mForceKillTask = nullptr;
|
2012-09-05 15:18:48 -07:00
|
|
|
// This ensures the process is eventually killed, but doesn't
|
|
|
|
// immediately KILLITWITHFIRE because we want to get a minidump if
|
|
|
|
// possible. After a timeout though, the process is forceably
|
|
|
|
// killed.
|
|
|
|
if (!KillProcess(OtherProcess(), 1, false)) {
|
|
|
|
NS_WARNING("failed to kill subprocess!");
|
|
|
|
}
|
2014-03-21 05:50:07 -07:00
|
|
|
mSubprocess->SetAlreadyDead();
|
2012-09-05 15:18:48 -07:00
|
|
|
XRE_GetIOMessageLoop()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableFunction(&ProcessWatcher::EnsureProcessTerminated,
|
|
|
|
OtherProcess(), /*force=*/true));
|
2013-07-17 12:13:20 -07:00
|
|
|
//We do clean-up here
|
|
|
|
MessageLoop::current()->PostDelayedTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableMethod(this, &ContentParent::ShutDownProcess,
|
|
|
|
/* closeWithError */ true),
|
|
|
|
3000);
|
2013-09-30 17:56:16 -07:00
|
|
|
// We've now closed the OtherProcess() handle, so must set it to null to
|
|
|
|
// prevent our dtor closing it twice.
|
|
|
|
SetOtherProcess(0);
|
2012-09-05 15:18:48 -07:00
|
|
|
}
|
|
|
|
|
2013-04-25 17:53:26 -07:00
|
|
|
bool
|
|
|
|
ContentParent::IsPreallocated()
|
|
|
|
{
|
|
|
|
return mAppManifestURL == MAGIC_PREALLOCATED_APP_MANIFEST_URL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentParent::FriendlyName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.Truncate();
|
2014-02-03 10:58:11 -08:00
|
|
|
#ifdef MOZ_NUWA_PROCESS
|
|
|
|
if (IsNuwaProcess()) {
|
|
|
|
aName.AssignLiteral("(Nuwa)");
|
|
|
|
} else
|
|
|
|
#endif
|
2013-04-25 17:53:26 -07:00
|
|
|
if (IsPreallocated()) {
|
|
|
|
aName.AssignLiteral("(Preallocated)");
|
|
|
|
} else if (mIsForBrowser) {
|
|
|
|
aName.AssignLiteral("Browser");
|
|
|
|
} else if (!mAppName.IsEmpty()) {
|
|
|
|
aName = mAppName;
|
|
|
|
} else if (!mAppManifestURL.IsEmpty()) {
|
|
|
|
aName.AssignLiteral("Unknown app: ");
|
|
|
|
aName.Append(mAppManifestURL);
|
|
|
|
} else {
|
|
|
|
aName.AssignLiteral("???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-24 06:15:03 -08:00
|
|
|
PCrashReporterParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPCrashReporterParent(const NativeThreadId& tid,
|
|
|
|
const uint32_t& 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
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-06-08 12:56:31 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvPCrashReporterConstructor(PCrashReporterParent* actor,
|
|
|
|
const NativeThreadId& tid,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t& processType)
|
2011-06-08 12:56:31 -07:00
|
|
|
{
|
|
|
|
static_cast<CrashReporterParent*>(actor)->SetChildData(tid, processType);
|
|
|
|
return true;
|
2010-11-24 06:15:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPCrashReporterParent(PCrashReporterParent* crashreporter)
|
2010-11-24 06:15:03 -08:00
|
|
|
{
|
|
|
|
delete crashreporter;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-26 13:14:01 -08:00
|
|
|
hal_sandbox::PHalParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPHalParent()
|
2011-10-05 15:15:45 -07:00
|
|
|
{
|
2013-01-26 13:14:01 -08:00
|
|
|
return hal_sandbox::CreateHalParent();
|
2011-10-05 15:15:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPHalParent(hal_sandbox::PHalParent* aHal)
|
2011-10-05 15:15:45 -07:00
|
|
|
{
|
|
|
|
delete aHal;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-07-14 04:24:20 -07:00
|
|
|
PIndexedDBParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPIndexedDBParent()
|
2012-07-14 04:24:20 -07:00
|
|
|
{
|
2012-10-25 10:12:14 -07:00
|
|
|
return new IndexedDBParent(this);
|
2012-07-14 04:24:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPIndexedDBParent(PIndexedDBParent* aActor)
|
2012-07-14 04:24:20 -07:00
|
|
|
{
|
|
|
|
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;
|
2012-08-01 23:02:29 -07:00
|
|
|
nsresult rv = IDBFactory::Create(this, getter_AddRefs(factory));
|
2012-07-14 04:24:20 -07:00
|
|
|
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*
|
2014-03-04 18:27:13 -08:00
|
|
|
ContentParent::AllocPMemoryReportRequestParent(const uint32_t& generation,
|
|
|
|
const bool &minimizeMemoryUsage,
|
|
|
|
const nsString &aDMDDumpIdent)
|
2011-02-16 10:43:23 -08:00
|
|
|
{
|
|
|
|
MemoryReportRequestParent* parent = new MemoryReportRequestParent();
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPMemoryReportRequestParent(PMemoryReportRequestParent* actor)
|
2011-02-16 10:43:23 -08:00
|
|
|
{
|
|
|
|
delete actor;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-09-09 15:59:06 -07:00
|
|
|
PTestShellParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPTestShellParent()
|
2009-08-12 11:31:48 -07:00
|
|
|
{
|
|
|
|
return new TestShellParent();
|
|
|
|
}
|
|
|
|
|
2009-09-17 16:09:20 -07:00
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPTestShellParent(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
|
|
|
}
|
2013-07-08 08:48:39 -07:00
|
|
|
|
|
|
|
PNeckoParent*
|
|
|
|
ContentParent::AllocPNeckoParent()
|
2009-08-18 12:05:15 -07:00
|
|
|
{
|
|
|
|
return new NeckoParent();
|
|
|
|
}
|
|
|
|
|
2013-07-08 08:48:39 -07:00
|
|
|
bool
|
|
|
|
ContentParent::DeallocPNeckoParent(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*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPExternalHelperAppParent(const OptionalURIParams& uri,
|
|
|
|
const nsCString& aMimeContentType,
|
|
|
|
const nsCString& aContentDisposition,
|
2014-02-13 14:43:58 -08:00
|
|
|
const uint32_t& aContentDispositionHint,
|
|
|
|
const nsString& aContentDispositionFilename,
|
2013-07-08 08:48:39 -07:00
|
|
|
const bool& aForceSave,
|
|
|
|
const int64_t& aContentLength,
|
2013-09-12 12:24:10 -07:00
|
|
|
const OptionalURIParams& aReferrer,
|
|
|
|
PBrowserParent* aBrowser)
|
2010-09-15 15:55:08 -07:00
|
|
|
{
|
|
|
|
ExternalHelperAppParent *parent = new ExternalHelperAppParent(uri, aContentLength);
|
|
|
|
parent->AddRef();
|
2014-02-13 14:43:58 -08:00
|
|
|
parent->Init(this,
|
|
|
|
aMimeContentType,
|
|
|
|
aContentDisposition,
|
|
|
|
aContentDispositionHint,
|
|
|
|
aContentDispositionFilename,
|
|
|
|
aForceSave,
|
|
|
|
aReferrer,
|
|
|
|
aBrowser);
|
2010-09-15 15:55:08 -07:00
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPExternalHelperAppParent(PExternalHelperAppParent* aService)
|
2010-09-15 15:55:08 -07:00
|
|
|
{
|
|
|
|
ExternalHelperAppParent *parent = static_cast<ExternalHelperAppParent *>(aService);
|
|
|
|
parent->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-11-20 14:40:53 -08:00
|
|
|
PSmsParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPSmsParent()
|
2011-11-20 14:40:53 -08:00
|
|
|
{
|
2012-09-25 11:52:30 -07:00
|
|
|
if (!AssertAppProcessPermission(this, "sms")) {
|
2012-08-16 12:34:53 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
2012-11-06 13:29:30 -08:00
|
|
|
|
|
|
|
SmsParent* parent = new SmsParent();
|
|
|
|
parent->AddRef();
|
|
|
|
return parent;
|
2011-11-20 14:40:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPSmsParent(PSmsParent* aSms)
|
2011-11-20 14:40:53 -08:00
|
|
|
{
|
2012-11-06 13:29:30 -08:00
|
|
|
static_cast<SmsParent*>(aSms)->Release();
|
2011-11-20 14:40:53 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-06 23:19:53 -07:00
|
|
|
PTelephonyParent*
|
|
|
|
ContentParent::AllocPTelephonyParent()
|
|
|
|
{
|
|
|
|
if (!AssertAppProcessPermission(this, "telephony")) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TelephonyParent* actor = new TelephonyParent();
|
|
|
|
NS_ADDREF(actor);
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPTelephonyParent(PTelephonyParent* aActor)
|
|
|
|
{
|
|
|
|
static_cast<TelephonyParent*>(aActor)->Release();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-18 17:15:23 -08:00
|
|
|
PStorageParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPStorageParent()
|
2010-11-18 17:15:23 -08:00
|
|
|
{
|
2013-04-15 05:38:48 -07:00
|
|
|
return new DOMStorageDBParent();
|
2010-11-18 17:15:23 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPStorageParent(PStorageParent* aActor)
|
2010-11-18 17:15:23 -08:00
|
|
|
{
|
2013-04-15 05:38:48 -07:00
|
|
|
DOMStorageDBParent* child = static_cast<DOMStorageDBParent*>(aActor);
|
|
|
|
child->ReleaseIPDLReference();
|
2010-11-18 17:15:23 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-13 09:37:14 -07:00
|
|
|
PBluetoothParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPBluetoothParent()
|
2012-09-13 09:37:14 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZ_B2G_BT
|
2012-09-25 11:52:30 -07:00
|
|
|
if (!AssertAppProcessPermission(this, "bluetooth")) {
|
2012-09-13 09:37:14 -07:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return new mozilla::dom::bluetooth::BluetoothParent();
|
|
|
|
#else
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("No support for bluetooth on this platform!");
|
2012-09-13 09:37:14 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPBluetoothParent(PBluetoothParent* aActor)
|
2012-09-13 09:37:14 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
#else
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("No support for bluetooth on this platform!");
|
2012-09-13 09:37:14 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvPBluetoothConstructor(PBluetoothParent* aActor)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_B2G_BT
|
|
|
|
nsRefPtr<BluetoothService> btService = BluetoothService::Get();
|
|
|
|
NS_ENSURE_TRUE(btService, false);
|
|
|
|
|
|
|
|
return static_cast<BluetoothParent*>(aActor)->InitWithService(btService);
|
|
|
|
#else
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("No support for bluetooth on this platform!");
|
2012-09-13 09:37:14 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-09-03 15:28:06 -07:00
|
|
|
PFMRadioParent*
|
|
|
|
ContentParent::AllocPFMRadioParent()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
if (!AssertAppProcessPermission(this, "fmradio")) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return new FMRadioParent();
|
|
|
|
#else
|
|
|
|
NS_WARNING("No support for FMRadio on this platform!");
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPFMRadioParent(PFMRadioParent* aActor)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_B2G_FM
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_WARNING("No support for FMRadio on this platform!");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-11-18 13:49:53 -08:00
|
|
|
asmjscache::PAsmJSCacheEntryParent*
|
|
|
|
ContentParent::AllocPAsmJSCacheEntryParent(
|
2013-12-04 20:32:52 -08:00
|
|
|
const asmjscache::OpenMode& aOpenMode,
|
|
|
|
const asmjscache::WriteParams& aWriteParams,
|
|
|
|
const IPC::Principal& aPrincipal)
|
2013-11-18 13:49:53 -08:00
|
|
|
{
|
2013-12-04 20:32:52 -08:00
|
|
|
return asmjscache::AllocEntryParent(aOpenMode, aWriteParams, aPrincipal);
|
2013-11-18 13:49:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPAsmJSCacheEntryParent(PAsmJSCacheEntryParent* aActor)
|
|
|
|
{
|
|
|
|
asmjscache::DeallocEntryParent(aActor);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-03 15:13:17 -07:00
|
|
|
PSpeechSynthesisParent*
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::AllocPSpeechSynthesisParent()
|
2013-04-03 15:13:17 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZ_WEBSPEECH
|
|
|
|
return new mozilla::dom::SpeechSynthesisParent();
|
|
|
|
#else
|
|
|
|
return nullptr;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-07-08 08:48:39 -07:00
|
|
|
ContentParent::DeallocPSpeechSynthesisParent(PSpeechSynthesisParent* aActor)
|
2013-04-03 15:13:17 -07:00
|
|
|
{
|
|
|
|
#ifdef MOZ_WEBSPEECH
|
|
|
|
delete aActor;
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvPSpeechSynthesisConstructor(PSpeechSynthesisParent* aActor)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WEBSPEECH
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-11-24 15:50:03 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvSpeakerManagerGetSpeakerStatus(bool* aValue)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
*aValue = false;
|
|
|
|
nsRefPtr<SpeakerManagerService> service =
|
|
|
|
SpeakerManagerService::GetSpeakerManagerService();
|
|
|
|
if (service) {
|
|
|
|
*aValue = service->GetSpeakerStatus();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvSpeakerManagerForceSpeaker(const bool& aEnable)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsRefPtr<SpeakerManagerService> service =
|
|
|
|
SpeakerManagerService::GetSpeakerManagerService();
|
|
|
|
if (service) {
|
|
|
|
service->ForceSpeaker(aEnable, mChildID);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:50:41 -07:00
|
|
|
bool
|
2012-08-23 12:33:46 -07:00
|
|
|
ContentParent::RecvStartVisitedQuery(const URIParams& aURI)
|
2010-07-02 08:50:41 -07:00
|
|
|
{
|
2012-08-23 12:33:46 -07:00
|
|
|
nsCOMPtr<nsIURI> newURI = DeserializeURI(aURI);
|
|
|
|
if (!newURI) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-05 10:07:46 -07:00
|
|
|
nsCOMPtr<IHistory> history = services::GetHistoryService();
|
|
|
|
if (history) {
|
2012-08-23 12:33:46 -07:00
|
|
|
history->RegisterVisitedCallback(newURI, nullptr);
|
2010-08-05 10:07:46 -07:00
|
|
|
}
|
2010-07-02 08:50:41 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:50:24 -07:00
|
|
|
|
|
|
|
bool
|
2012-08-23 12:33:46 -07:00
|
|
|
ContentParent::RecvVisitURI(const URIParams& uri,
|
|
|
|
const OptionalURIParams& referrer,
|
|
|
|
const uint32_t& flags)
|
2010-07-02 08:50:24 -07:00
|
|
|
{
|
2012-08-23 12:33:46 -07:00
|
|
|
nsCOMPtr<nsIURI> ourURI = DeserializeURI(uri);
|
|
|
|
if (!ourURI) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> ourReferrer = DeserializeURI(referrer);
|
2010-08-05 10:07:46 -07:00
|
|
|
nsCOMPtr<IHistory> history = services::GetHistoryService();
|
|
|
|
if (history) {
|
2012-08-23 12:33:46 -07:00
|
|
|
history->VisitURI(ourURI, ourReferrer, flags);
|
2010-08-05 10:07:46 -07:00
|
|
|
}
|
2010-07-02 08:50:24 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-07-02 08:53:42 -07:00
|
|
|
|
|
|
|
bool
|
2012-08-23 12:33:46 -07:00
|
|
|
ContentParent::RecvSetURITitle(const URIParams& uri,
|
|
|
|
const nsString& title)
|
2010-07-02 08:53:42 -07:00
|
|
|
{
|
2012-08-23 12:33:46 -07:00
|
|
|
nsCOMPtr<nsIURI> ourURI = DeserializeURI(uri);
|
|
|
|
if (!ourURI) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-05 10:07:46 -07:00
|
|
|
nsCOMPtr<IHistory> history = services::GetHistoryService();
|
|
|
|
if (history) {
|
2012-08-23 12:33:46 -07:00
|
|
|
history->SetURITitle(ourURI, title);
|
2010-08-05 10:07:46 -07:00
|
|
|
}
|
2010-07-02 08:53:42 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-27 12:31:19 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvGetRandomValues(const uint32_t& length,
|
|
|
|
InfallibleTArray<uint8_t>* randomValues)
|
|
|
|
{
|
|
|
|
uint8_t* buf = Crypto::GetRandomValues(length);
|
2013-09-17 09:54:34 -07:00
|
|
|
if (!buf) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-02-27 12:31:19 -08:00
|
|
|
|
|
|
|
randomValues->SetCapacity(length);
|
|
|
|
randomValues->SetLength(length);
|
|
|
|
|
|
|
|
memcpy(randomValues->Elements(), buf, length);
|
|
|
|
|
|
|
|
NS_Free(buf);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-10 10:14:45 -07:00
|
|
|
bool
|
2012-08-23 12:33:46 -07:00
|
|
|
ContentParent::RecvLoadURIExternal(const URIParams& uri)
|
2010-08-10 10:14:45 -07:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIExternalProtocolService> extProtService(do_GetService(NS_EXTERNALPROTOCOLSERVICE_CONTRACTID));
|
2012-08-23 12:33:46 -07:00
|
|
|
if (!extProtService) {
|
2010-08-10 10:14:45 -07:00
|
|
|
return true;
|
2012-08-23 12:33:46 -07:00
|
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> ourURI = DeserializeURI(uri);
|
|
|
|
if (!ourURI) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
extProtService->LoadURI(ourURI, nullptr);
|
2010-08-10 10:14:45 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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,
|
2013-03-18 06:24:53 -07:00
|
|
|
const nsString& aCookie, const nsString& aName,
|
2013-11-11 15:56:21 -08:00
|
|
|
const nsString& aBidi, const nsString& aLang,
|
|
|
|
const IPC::Principal& aPrincipal)
|
2010-09-15 09:44:57 -07:00
|
|
|
{
|
2013-11-11 15:56:21 -08:00
|
|
|
#ifdef MOZ_CHILD_PERMISSIONS
|
|
|
|
uint32_t permission = mozilla::CheckPermission(this, aPrincipal,
|
|
|
|
"desktop-notification");
|
|
|
|
if (permission != nsIPermissionManager::ALLOW_ACTION) {
|
|
|
|
return true;
|
2012-12-20 11:06:42 -08:00
|
|
|
}
|
2013-11-11 15:56:21 -08:00
|
|
|
#endif /* MOZ_CHILD_PERMISSIONS */
|
|
|
|
|
2010-09-15 09:44:57 -07:00
|
|
|
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
|
|
|
|
if (sysAlerts) {
|
|
|
|
sysAlerts->ShowAlertNotification(aImageUrl, aTitle, aText, aTextClickable,
|
2013-11-11 15:56:21 -08:00
|
|
|
aCookie, this, aName, aBidi, aLang, aPrincipal);
|
2013-03-18 06:24:53 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-11-11 15:56:21 -08:00
|
|
|
ContentParent::RecvCloseAlert(const nsString& aName,
|
|
|
|
const IPC::Principal& aPrincipal)
|
2013-03-18 06:24:53 -07:00
|
|
|
{
|
2013-11-11 15:56:21 -08:00
|
|
|
#ifdef MOZ_CHILD_PERMISSIONS
|
|
|
|
uint32_t permission = mozilla::CheckPermission(this, aPrincipal,
|
|
|
|
"desktop-notification");
|
|
|
|
if (permission != nsIPermissionManager::ALLOW_ACTION) {
|
|
|
|
return true;
|
2013-03-18 06:24:53 -07:00
|
|
|
}
|
2013-11-11 15:56:21 -08:00
|
|
|
#endif
|
|
|
|
|
2013-03-18 06:24:53 -07:00
|
|
|
nsCOMPtr<nsIAlertsService> sysAlerts(do_GetService(NS_ALERTSERVICE_CONTRACTID));
|
|
|
|
if (sysAlerts) {
|
2013-11-11 15:56:21 -08:00
|
|
|
sysAlerts->CloseAlert(aName, aPrincipal);
|
2010-09-15 09:44:57 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-08-31 11:58:35 -07:00
|
|
|
|
|
|
|
bool
|
2012-08-01 23:02:29 -07:00
|
|
|
ContentParent::RecvSyncMessage(const nsString& aMsg,
|
|
|
|
const ClonedMessageData& aData,
|
2013-07-10 15:05:39 -07:00
|
|
|
const InfallibleTArray<CpowEntry>& aCpows,
|
2013-11-06 09:21:15 -08:00
|
|
|
const IPC::Principal& aPrincipal,
|
2010-11-08 18:49:00 -08:00
|
|
|
InfallibleTArray<nsString>* aRetvals)
|
2010-08-31 11:58:35 -07:00
|
|
|
{
|
2013-11-06 09:21:17 -08:00
|
|
|
nsIPrincipal* principal = aPrincipal;
|
2013-12-02 07:27:57 -08:00
|
|
|
if (!Preferences::GetBool("dom.testing.ignore_ipc_principal", false) &&
|
2013-11-26 08:31:07 -08:00
|
|
|
principal && !AssertAppPrincipal(this, principal)) {
|
2013-11-06 09:21:17 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-02 12:57:48 -07:00
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
2010-08-31 11:58:35 -07:00
|
|
|
if (ppm) {
|
2013-01-24 08:24:19 -08:00
|
|
|
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
|
2013-07-10 15:05:39 -07:00
|
|
|
CpowIdHolder cpows(GetCPOWManager(), aCpows);
|
2013-11-06 09:21:15 -08:00
|
|
|
|
2010-08-31 11:58:35 -07:00
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
|
2013-11-06 09:21:15 -08:00
|
|
|
aMsg, true, &cloneData, &cpows, aPrincipal, aRetvals);
|
2010-08-31 11:58:35 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-01 09:15:06 -07:00
|
|
|
bool
|
|
|
|
ContentParent::AnswerRpcMessage(const nsString& aMsg,
|
|
|
|
const ClonedMessageData& aData,
|
|
|
|
const InfallibleTArray<CpowEntry>& aCpows,
|
2013-11-06 09:21:15 -08:00
|
|
|
const IPC::Principal& aPrincipal,
|
2013-10-01 09:15:06 -07:00
|
|
|
InfallibleTArray<nsString>* aRetvals)
|
|
|
|
{
|
2013-11-06 09:21:17 -08:00
|
|
|
nsIPrincipal* principal = aPrincipal;
|
2013-12-02 07:27:57 -08:00
|
|
|
if (!Preferences::GetBool("dom.testing.ignore_ipc_principal", false) &&
|
2013-11-26 08:31:07 -08:00
|
|
|
principal && !AssertAppPrincipal(this, principal)) {
|
2013-11-06 09:21:17 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-10-01 09:15:06 -07:00
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
|
|
|
if (ppm) {
|
|
|
|
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
|
|
|
|
CpowIdHolder cpows(GetCPOWManager(), aCpows);
|
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
|
2013-11-06 09:21:15 -08:00
|
|
|
aMsg, true, &cloneData, &cpows, aPrincipal, aRetvals);
|
2013-10-01 09:15:06 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-08-31 11:58:35 -07:00
|
|
|
bool
|
2012-08-01 23:02:29 -07:00
|
|
|
ContentParent::RecvAsyncMessage(const nsString& aMsg,
|
2013-07-10 15:05:39 -07:00
|
|
|
const ClonedMessageData& aData,
|
2013-11-06 09:21:15 -08:00
|
|
|
const InfallibleTArray<CpowEntry>& aCpows,
|
|
|
|
const IPC::Principal& aPrincipal)
|
2010-08-31 11:58:35 -07:00
|
|
|
{
|
2013-11-06 09:21:17 -08:00
|
|
|
nsIPrincipal* principal = aPrincipal;
|
2013-12-02 07:27:57 -08:00
|
|
|
if (!Preferences::GetBool("dom.testing.ignore_ipc_principal", false) &&
|
2013-11-26 08:31:07 -08:00
|
|
|
principal && !AssertAppPrincipal(this, principal)) {
|
2013-11-06 09:21:17 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-02 12:57:48 -07:00
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = mMessageManager;
|
2010-08-31 11:58:35 -07:00
|
|
|
if (ppm) {
|
2013-01-24 08:24:19 -08:00
|
|
|
StructuredCloneData cloneData = ipc::UnpackClonedMessageDataForParent(aData);
|
2013-07-10 15:05:39 -07:00
|
|
|
CpowIdHolder cpows(GetCPOWManager(), aCpows);
|
2010-08-31 11:58:35 -07:00
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
|
2013-11-06 09:21:15 -08:00
|
|
|
aMsg, false, &cloneData, &cpows, aPrincipal, nullptr);
|
2010-08-31 11:58:35 -07:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-20 21:16:37 -07:00
|
|
|
|
2013-01-09 07:03:28 -08:00
|
|
|
bool
|
2013-04-18 07:13:23 -07:00
|
|
|
ContentParent::RecvFilePathUpdateNotify(const nsString& aType,
|
2013-05-11 02:10:18 -07:00
|
|
|
const nsString& aStorageName,
|
2013-04-18 07:13:23 -07:00
|
|
|
const nsString& aFilePath,
|
|
|
|
const nsCString& aReason)
|
2013-01-09 07:03:28 -08:00
|
|
|
{
|
2013-05-11 02:10:18 -07:00
|
|
|
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(aType,
|
|
|
|
aStorageName,
|
|
|
|
aFilePath);
|
2013-01-09 07:03:28 -08:00
|
|
|
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (!obs) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-11 02:10:18 -07:00
|
|
|
obs->NotifyObservers(dsf, "file-watcher-update",
|
|
|
|
NS_ConvertASCIItoUTF16(aReason).get());
|
2013-01-09 07:03:28 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-02-26 09:27:31 -08:00
|
|
|
static int32_t
|
|
|
|
AddGeolocationListener(nsIDOMGeoPositionCallback* watcher, bool highAccuracy)
|
|
|
|
{
|
2013-04-12 11:46:36 -07:00
|
|
|
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
|
2013-02-26 09:27:31 -08:00
|
|
|
if (!geo) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-09-06 13:44:26 -07:00
|
|
|
PositionOptions* options = new PositionOptions();
|
2013-11-26 15:25:43 -08:00
|
|
|
options->mTimeout = 0;
|
|
|
|
options->mMaximumAge = 0;
|
2013-09-06 13:44:26 -07:00
|
|
|
options->mEnableHighAccuracy = highAccuracy;
|
2013-02-26 09:27:31 -08:00
|
|
|
int32_t retval = 1;
|
|
|
|
geo->WatchPosition(watcher, nullptr, options, &retval);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2010-09-20 21:16:37 -07:00
|
|
|
bool
|
2013-02-26 09:27:31 -08:00
|
|
|
ContentParent::RecvAddGeolocationListener(const IPC::Principal& aPrincipal,
|
|
|
|
const bool& aHighAccuracy)
|
2010-09-20 21:16:37 -07:00
|
|
|
{
|
2013-08-22 12:52:07 -07:00
|
|
|
#ifdef MOZ_CHILD_PERMISSIONS
|
2013-12-02 07:27:57 -08:00
|
|
|
if (!Preferences::GetBool("dom.testing.ignore_ipc_principal", false)) {
|
2013-11-26 20:28:16 -08:00
|
|
|
uint32_t permission = mozilla::CheckPermission(this, aPrincipal,
|
|
|
|
"geolocation");
|
|
|
|
if (permission != nsIPermissionManager::ALLOW_ACTION) {
|
2013-01-02 13:21:37 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2013-11-26 20:28:16 -08:00
|
|
|
#endif /* MOZ_CHILD_PERMISSIONS */
|
2013-01-02 13:21:37 -08:00
|
|
|
|
2013-01-06 21:57:00 -08:00
|
|
|
// To ensure no geolocation updates are skipped, we always force the
|
|
|
|
// creation of a new listener.
|
|
|
|
RecvRemoveGeolocationListener();
|
2013-02-26 09:27:31 -08:00
|
|
|
mGeolocationWatchID = AddGeolocationListener(this, aHighAccuracy);
|
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
|
|
|
{
|
2012-12-03 16:03:16 -08:00
|
|
|
if (mGeolocationWatchID != -1) {
|
|
|
|
nsCOMPtr<nsIDOMGeoGeolocation> geo = do_GetService("@mozilla.org/geolocation;1");
|
|
|
|
if (!geo) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
geo->ClearWatch(mGeolocationWatchID);
|
|
|
|
mGeolocationWatchID = -1;
|
2012-12-01 18:21:56 -08:00
|
|
|
}
|
2010-09-20 21:16:37 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-31 08:36:46 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvSetGeolocationHigherAccuracy(const bool& aEnable)
|
|
|
|
{
|
2013-02-26 09:27:31 -08:00
|
|
|
// This should never be called without a listener already present,
|
|
|
|
// so this check allows us to forgo securing privileges.
|
|
|
|
if (mGeolocationWatchID != -1) {
|
|
|
|
RecvRemoveGeolocationListener();
|
|
|
|
mGeolocationWatchID = AddGeolocationListener(this, aEnable);
|
|
|
|
}
|
|
|
|
return true;
|
2012-12-31 08:36:46 -08:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-11-09 09:52:09 -08:00
|
|
|
nsConsoleService *
|
|
|
|
ContentParent::GetConsoleService()
|
|
|
|
{
|
|
|
|
if (mConsoleService) {
|
|
|
|
return mConsoleService.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the ConsoleService by CID rather than ContractID, so that we
|
|
|
|
// can cast the returned pointer to an nsConsoleService (rather than
|
|
|
|
// just an nsIConsoleService). This allows us to call the non-idl function
|
|
|
|
// nsConsoleService::LogMessageWithMode.
|
|
|
|
NS_DEFINE_CID(consoleServiceCID, NS_CONSOLESERVICE_CID);
|
|
|
|
nsCOMPtr<nsConsoleService> consoleService(do_GetService(consoleServiceCID));
|
|
|
|
mConsoleService = consoleService;
|
|
|
|
return mConsoleService.get();
|
|
|
|
}
|
|
|
|
|
2010-09-23 18:39:32 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvConsoleMessage(const nsString& aMessage)
|
|
|
|
{
|
2012-11-09 09:52:09 -08:00
|
|
|
nsRefPtr<nsConsoleService> consoleService = GetConsoleService();
|
|
|
|
if (!consoleService) {
|
2010-09-23 18:39:32 -07:00
|
|
|
return true;
|
2012-11-09 09:52:09 -08:00
|
|
|
}
|
2010-09-23 18:39:32 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsConsoleMessage> msg(new nsConsoleMessage(aMessage.get()));
|
2012-11-09 09:52:09 -08:00
|
|
|
consoleService->LogMessageWithMode(msg, nsConsoleService::SuppressLog);
|
2010-09-23 18:39:32 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvScriptError(const nsString& aMessage,
|
|
|
|
const nsString& aSourceName,
|
|
|
|
const nsString& aSourceLine,
|
2012-08-22 08:56:38 -07:00
|
|
|
const uint32_t& aLineNumber,
|
|
|
|
const uint32_t& aColNumber,
|
|
|
|
const uint32_t& aFlags,
|
2010-09-23 18:39:32 -07:00
|
|
|
const nsCString& aCategory)
|
|
|
|
{
|
2012-11-09 09:52:09 -08:00
|
|
|
nsRefPtr<nsConsoleService> consoleService = GetConsoleService();
|
|
|
|
if (!consoleService) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-09-23 18:39:32 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScriptError> msg(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
2012-09-09 16:29:12 -07:00
|
|
|
nsresult rv = msg->Init(aMessage, aSourceName, aSourceLine,
|
2010-09-23 18:39:32 -07:00
|
|
|
aLineNumber, aColNumber, aFlags, aCategory.get());
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return true;
|
|
|
|
|
2012-11-09 09:52:09 -08:00
|
|
|
consoleService->LogMessageWithMode(msg, nsConsoleService::SuppressLog);
|
2010-09-23 18:39:32 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-04-19 17:13:20 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvPrivateDocShellsExist(const bool& aExist)
|
|
|
|
{
|
2013-04-25 17:53:26 -07:00
|
|
|
if (!sPrivateContent)
|
|
|
|
sPrivateContent = new nsTArray<ContentParent*>();
|
2012-04-19 17:13:20 -07:00
|
|
|
if (aExist) {
|
2013-04-25 17:53:26 -07:00
|
|
|
sPrivateContent->AppendElement(this);
|
2012-04-19 17:13:20 -07:00
|
|
|
} else {
|
2013-04-25 17:53:26 -07:00
|
|
|
sPrivateContent->RemoveElement(this);
|
|
|
|
if (!sPrivateContent->Length()) {
|
2012-04-19 17:13:20 -07:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
2012-07-30 07:20:58 -07:00
|
|
|
obs->NotifyObservers(nullptr, "last-pb-context-exited", nullptr);
|
2013-04-25 17:53:26 -07:00
|
|
|
delete sPrivateContent;
|
2013-10-28 07:04:12 -07:00
|
|
|
sPrivateContent = nullptr;
|
2012-04-19 17:13:20 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-27 22:43:12 -07:00
|
|
|
bool
|
2013-07-10 15:05:39 -07:00
|
|
|
ContentParent::DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const mozilla::dom::StructuredCloneData& aData,
|
2013-11-06 09:21:15 -08:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal)
|
2012-09-27 22:43:12 -07:00
|
|
|
{
|
|
|
|
ClonedMessageData data;
|
2013-01-23 18:39:27 -08:00
|
|
|
if (!BuildClonedMessageDataForParent(this, aData, data)) {
|
|
|
|
return false;
|
2012-09-27 22:43:12 -07:00
|
|
|
}
|
2013-07-10 15:05:39 -07:00
|
|
|
InfallibleTArray<CpowEntry> cpows;
|
|
|
|
if (!GetCPOWManager()->Wrap(aCx, aCpows, &cpows)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-06 09:21:15 -08:00
|
|
|
return SendAsyncMessage(nsString(aMessage), data, cpows, aPrincipal);
|
2012-09-27 22:43:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::CheckPermission(const nsAString& aPermission)
|
|
|
|
{
|
|
|
|
return AssertAppProcessPermission(this, NS_ConvertUTF16toUTF8(aPermission).get());
|
|
|
|
}
|
|
|
|
|
2012-12-22 04:00:10 -08:00
|
|
|
bool
|
|
|
|
ContentParent::CheckManifestURL(const nsAString& aManifestURL)
|
|
|
|
{
|
|
|
|
return AssertAppProcessManifestURL(this, NS_ConvertUTF16toUTF8(aManifestURL).get());
|
|
|
|
}
|
2012-09-27 22:43:12 -07:00
|
|
|
|
2013-01-14 02:08:55 -08:00
|
|
|
bool
|
|
|
|
ContentParent::CheckAppHasPermission(const nsAString& aPermission)
|
|
|
|
{
|
|
|
|
return AssertAppHasPermission(this, NS_ConvertUTF16toUTF8(aPermission).get());
|
|
|
|
}
|
|
|
|
|
2013-06-29 03:52:16 -07:00
|
|
|
bool
|
|
|
|
ContentParent::CheckAppHasStatus(unsigned short aStatus)
|
|
|
|
{
|
|
|
|
return AssertAppHasStatus(this, aStatus);
|
|
|
|
}
|
|
|
|
|
2013-02-14 12:41:30 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvSystemMessageHandled()
|
|
|
|
{
|
|
|
|
SystemMessageHandledListener::OnSystemMessageHandled();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-08 23:37:47 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvCreateFakeVolume(const nsString& fsName, const nsString& mountPoint)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIVolumeService> vs = do_GetService(NS_VOLUMESERVICE_CONTRACTID, &rv);
|
|
|
|
if (vs) {
|
|
|
|
vs->CreateFakeVolume(fsName, mountPoint);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_WARNING("ContentParent::RecvCreateFakeVolume shouldn't be called when MOZ_WIDGET_GONK is not defined");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvSetFakeVolumeState(const nsString& fsName, const int32_t& fsState)
|
|
|
|
{
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIVolumeService> vs = do_GetService(NS_VOLUMESERVICE_CONTRACTID, &rv);
|
|
|
|
if (vs) {
|
|
|
|
vs->SetFakeVolumeState(fsName, fsState);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
NS_WARNING("ContentParent::RecvSetFakeVolumeState shouldn't be called when MOZ_WIDGET_GONK is not defined");
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-08-16 10:59:31 -07:00
|
|
|
bool
|
|
|
|
ContentParent::RecvKeywordToURI(const nsCString& aKeyword, OptionalInputStreamParams* aPostData,
|
|
|
|
OptionalURIParams* aURI)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURIFixup> fixup = do_GetService(NS_URIFIXUP_CONTRACTID);
|
|
|
|
if (!fixup) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> postData;
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (NS_FAILED(fixup->KeywordToURI(aKeyword, getter_AddRefs(postData),
|
|
|
|
getter_AddRefs(uri)))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-25 11:37:13 -07:00
|
|
|
nsTArray<mozilla::ipc::FileDescriptor> fds;
|
|
|
|
SerializeInputStream(postData, *aPostData, fds);
|
|
|
|
MOZ_ASSERT(fds.IsEmpty());
|
|
|
|
|
2013-08-16 10:59:31 -07:00
|
|
|
SerializeURI(uri, *aURI);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-26 21:56:57 -07:00
|
|
|
bool
|
|
|
|
ContentParent::ShouldContinueFromReplyTimeout()
|
|
|
|
{
|
|
|
|
// The only time ContentParent sends blocking messages is for CPOWs, so
|
|
|
|
// timeouts should only ever occur in electrolysis-enabled sessions.
|
2013-12-12 14:13:20 -08:00
|
|
|
MOZ_ASSERT(BrowserTabsRemote());
|
2013-08-26 21:56:57 -07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-01 19:09:45 -07:00
|
|
|
bool
|
|
|
|
ContentParent::ShouldSandboxContentProcesses()
|
|
|
|
{
|
|
|
|
#ifdef MOZ_CONTENT_SANDBOX
|
|
|
|
return !PR_GetEnv("MOZ_DISABLE_CONTENT_SANDBOX");
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-11-24 01:06:27 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvRecordingDeviceEvents(const nsString& aRecordingStatus,
|
|
|
|
const nsString& aPageURL,
|
|
|
|
const bool& aIsAudio,
|
|
|
|
const bool& aIsVideo)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
// recording-device-ipc-events needs to gather more information from content process
|
|
|
|
nsRefPtr<nsHashPropertyBag> props = new nsHashPropertyBag();
|
|
|
|
props->SetPropertyAsUint64(NS_LITERAL_STRING("childID"), ChildID());
|
|
|
|
props->SetPropertyAsBool(NS_LITERAL_STRING("isApp"), IsForApp());
|
|
|
|
props->SetPropertyAsBool(NS_LITERAL_STRING("isAudio"), aIsAudio);
|
|
|
|
props->SetPropertyAsBool(NS_LITERAL_STRING("isVideo"), aIsVideo);
|
|
|
|
|
|
|
|
nsString requestURL = IsForApp() ? AppManifestURL() : aPageURL;
|
|
|
|
props->SetPropertyAsAString(NS_LITERAL_STRING("requestURL"), requestURL);
|
|
|
|
|
|
|
|
obs->NotifyObservers((nsIPropertyBag2*) props,
|
|
|
|
"recording-device-ipc-events",
|
|
|
|
aRecordingStatus.get());
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Could not get the Observer service for ContentParent::RecvRecordingDeviceEvents.");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-10 17:09:20 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvGetGraphicsFeatureStatus(const int32_t& aFeature,
|
|
|
|
int32_t* aStatus,
|
|
|
|
bool* aSuccess)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1");
|
|
|
|
if (!gfxInfo) {
|
|
|
|
*aSuccess = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aSuccess = NS_SUCCEEDED(gfxInfo->GetFeatureStatus(aFeature, aStatus));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-13 08:28:46 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvAddIdleObserver(const uint64_t& aObserver, const uint32_t& aIdleTimeInS)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIIdleService> idleService =
|
|
|
|
do_GetService("@mozilla.org/widget/idleservice;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<ParentIdleListener> listener = new ParentIdleListener(this, aObserver);
|
2013-12-13 08:28:46 -08:00
|
|
|
mIdleListeners.Put(aObserver, listener);
|
|
|
|
idleService->AddIdleObserver(listener, aIdleTimeInS);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::RecvRemoveIdleObserver(const uint64_t& aObserver, const uint32_t& aIdleTimeInS)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIIdleService> idleService =
|
|
|
|
do_GetService("@mozilla.org/widget/idleservice;1", &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2014-03-17 17:23:03 -07:00
|
|
|
nsRefPtr<ParentIdleListener> listener;
|
2013-12-13 08:28:46 -08:00
|
|
|
bool found = mIdleListeners.Get(aObserver, &listener);
|
|
|
|
if (found) {
|
|
|
|
mIdleListeners.Remove(aObserver);
|
|
|
|
idleService->RemoveIdleObserver(listener, aIdleTimeInS);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-05 08:37:26 -08:00
|
|
|
bool
|
|
|
|
ContentParent::RecvBackUpXResources(const FileDescriptor& aXSocketFd)
|
|
|
|
{
|
|
|
|
#ifndef MOZ_X11
|
|
|
|
NS_RUNTIMEABORT("This message only makes sense on X11 platforms");
|
|
|
|
#else
|
|
|
|
NS_ABORT_IF_FALSE(0 > mChildXSocketFdDup.get(),
|
|
|
|
"Already backed up X resources??");
|
|
|
|
mChildXSocketFdDup.forget();
|
|
|
|
if (aXSocketFd.IsValid()) {
|
|
|
|
mChildXSocketFdDup.reset(aXSocketFd.PlatformHandle());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-25 11:37:13 -07:00
|
|
|
PFileDescriptorSetParent*
|
2014-03-25 11:37:28 -07:00
|
|
|
ContentParent::AllocPFileDescriptorSetParent(const FileDescriptor& aFD)
|
2014-03-25 11:37:13 -07:00
|
|
|
{
|
2014-03-25 11:37:28 -07:00
|
|
|
return new FileDescriptorSetParent(aFD);
|
2014-03-25 11:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentParent::DeallocPFileDescriptorSetParent(PFileDescriptorSetParent* aActor)
|
|
|
|
{
|
2014-03-25 11:37:28 -07:00
|
|
|
delete static_cast<FileDescriptorSetParent*>(aActor);
|
2014-03-25 11:37:13 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-08-12 09:18:08 -07:00
|
|
|
} // namespace dom
|
2013-02-14 12:41:30 -08:00
|
|
|
} // namespace mozilla
|
2013-12-13 08:28:46 -08:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(ParentIdleListener, nsIObserver)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 07:02:17 -08:00
|
|
|
ParentIdleListener::Observe(nsISupports*, const char* aTopic, const char16_t* aData) {
|
2013-12-13 08:28:46 -08:00
|
|
|
mozilla::unused << mParent->SendNotifyIdleObserver(mObserver,
|
|
|
|
nsDependentCString(aTopic),
|
|
|
|
nsDependentString(aData));
|
|
|
|
return NS_OK;
|
|
|
|
}
|