diff options
Diffstat (limited to 'dom/ipc/ContentParent.cpp')
-rw-r--r-- | dom/ipc/ContentParent.cpp | 373 |
1 files changed, 25 insertions, 348 deletions
diff --git a/dom/ipc/ContentParent.cpp b/dom/ipc/ContentParent.cpp index 73621df22..0a07147bf 100644 --- a/dom/ipc/ContentParent.cpp +++ b/dom/ipc/ContentParent.cpp @@ -16,18 +16,12 @@ # include <sys/resource.h> #endif -#ifdef MOZ_WIDGET_GONK -#include <sys/types.h> -#include <sys/wait.h> -#endif - #include "chrome/common/process_watcher.h" #include "mozilla/a11y/PDocAccessible.h" #include "AppProcessChecker.h" #include "AudioChannelService.h" #include "BlobParent.h" -#include "CrashReporterParent.h" #include "GMPServiceParent.h" #include "HandlerServiceParent.h" #include "IHistory.h" @@ -87,9 +81,6 @@ #include "mozilla/Preferences.h" #include "mozilla/ProcessHangMonitor.h" #include "mozilla/ProcessHangMonitorIPC.h" -#ifdef MOZ_ENABLE_PROFILER_SPS -#include "mozilla/ProfileGatherer.h" -#endif #include "mozilla/ScopeExit.h" #include "mozilla/Services.h" #include "mozilla/StaticPtr.h" @@ -210,14 +201,6 @@ # include "AndroidBridge.h" #endif -#ifdef MOZ_WIDGET_GONK -#include "nsIVolume.h" -#include "nsVolumeService.h" -#include "nsIVolumeService.h" -#include "SpeakerManagerService.h" -using namespace mozilla::system; -#endif - #ifdef MOZ_WIDGET_GTK #include <gdk/gdk.h> #endif @@ -230,21 +213,10 @@ using namespace mozilla::system; #include "mozilla/dom/SpeechSynthesisParent.h" #endif -#if defined(MOZ_CONTENT_SANDBOX) && defined(XP_LINUX) -#include "mozilla/SandboxInfo.h" -#include "mozilla/SandboxBroker.h" -#include "mozilla/SandboxBrokerPolicyFactory.h" -#endif - #ifdef MOZ_TOOLKIT_SEARCH #include "nsIBrowserSearchService.h" #endif -#ifdef MOZ_ENABLE_PROFILER_SPS -#include "nsIProfiler.h" -#include "nsIProfileSaveEvent.h" -#endif - #ifdef XP_WIN #include "mozilla/widget/AudioSession.h" #endif @@ -265,9 +237,6 @@ extern const char* kForceEnableE10sPref; using base::ChildPrivileges; using base::KillProcess; -#ifdef MOZ_ENABLE_PROFILER_SPS -using mozilla::ProfileGatherer; -#endif using namespace mozilla::dom::power; using namespace mozilla::media; @@ -503,9 +472,6 @@ nsTArray<ContentParent*>* ContentParent::sNonAppContentParents; nsTArray<ContentParent*>* ContentParent::sLargeAllocationContentParents; nsTArray<ContentParent*>* ContentParent::sPrivateContent; StaticAutoPtr<LinkedList<ContentParent> > ContentParent::sContentParents; -#if defined(XP_LINUX) && defined(MOZ_CONTENT_SANDBOX) -UniquePtr<SandboxBrokerPolicyFactory> ContentParent::sSandboxBrokerPolicyFactory; -#endif // This is true when subprocess launching is enabled. This is the // case between StartUp() and ShutDown() or JoinAllSubprocesses(). @@ -535,22 +501,9 @@ static const char* sObserverTopics[] = { "child-mmu-request", "last-pb-context-exited", "file-watcher-update", -#ifdef MOZ_WIDGET_GONK - NS_VOLUME_STATE_CHANGED, - NS_VOLUME_REMOVED, - "phone-state-changed", -#endif #ifdef ACCESSIBILITY "a11y-init-or-shutdown", #endif -#ifdef MOZ_ENABLE_PROFILER_SPS - "profiler-started", - "profiler-stopped", - "profiler-paused", - "profiler-resumed", - "profiler-subprocess-gather", - "profiler-subprocess", -#endif "cacheservice:empty-cache", }; @@ -637,18 +590,6 @@ ContentParent::StartUp() return; } -#if defined(MOZ_CONTENT_SANDBOX) && defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 19 - // Require sandboxing on B2G >= KitKat. This condition must stay - // in sync with ContentChild::RecvSetProcessSandbox. - if (!SandboxInfo::Get().CanSandboxContent()) { - // MOZ_CRASH strings are only for debug builds; make sure the - // message is clear on non-debug builds as well: - printf_stderr("Sandboxing support is required on this platform. " - "Recompile kernel with CONFIG_SECCOMP_FILTER=y\n"); - MOZ_CRASH("Sandboxing support is required on this platform."); - } -#endif - // Note: This reporter measures all ContentParents. RegisterStrongMemoryReporter(new ContentParentsMemoryReporter()); @@ -662,10 +603,6 @@ ContentParent::StartUp() PreallocatedProcessManager::AllocateAfterDelay(); sDisableUnsafeCPOWWarnings = PR_GetEnv("DISABLE_UNSAFE_CPOW_WARNINGS"); - -#if defined(XP_LINUX) && defined(MOZ_CONTENT_SANDBOX) - sSandboxBrokerPolicyFactory = MakeUnique<SandboxBrokerPolicyFactory>(); -#endif } /*static*/ void @@ -674,10 +611,6 @@ ContentParent::ShutDown() // No-op for now. We rely on normal process shutdown and // ClearOnShutdown() to clean up our state. sCanLaunchSubprocesses = false; - -#if defined(XP_LINUX) && defined(MOZ_CONTENT_SANDBOX) - sSandboxBrokerPolicyFactory = nullptr; -#endif } /*static*/ void @@ -1353,26 +1286,6 @@ ContentParent::Init() } #endif -#ifdef MOZ_ENABLE_PROFILER_SPS - nsCOMPtr<nsIProfiler> profiler(do_GetService("@mozilla.org/tools/profiler;1")); - bool profilerActive = false; - DebugOnly<nsresult> rv = profiler->IsActive(&profilerActive); - MOZ_ASSERT(NS_SUCCEEDED(rv)); - - if (profilerActive) { - nsCOMPtr<nsIProfilerStartParams> currentProfilerParams; - rv = profiler->GetStartParams(getter_AddRefs(currentProfilerParams)); - MOZ_ASSERT(NS_SUCCEEDED(rv)); - - nsCOMPtr<nsISupports> gatherer; - rv = profiler->GetProfileGatherer(getter_AddRefs(gatherer)); - MOZ_ASSERT(NS_SUCCEEDED(rv)); - mGatherer = static_cast<ProfileGatherer*>(gatherer.get()); - - StartProfiler(currentProfilerParams); - } -#endif - RefPtr<GeckoMediaPluginServiceParent> gmps(GeckoMediaPluginServiceParent::GetSingleton()); gmps->UpdateContentProcessGMPCapabilities(); } @@ -1384,14 +1297,6 @@ ContentParent::ForwardKnownInfo() if (!mMetamorphosed) { return; } -#ifdef MOZ_WIDGET_GONK - InfallibleTArray<VolumeInfo> volumeInfo; - RefPtr<nsVolumeService> vs = nsVolumeService::GetSingleton(); - if (vs) { - vs->GetVolumesForIPC(&volumeInfo); - Unused << SendVolumes(volumeInfo); - } -#endif /* MOZ_WIDGET_GONK */ } namespace { @@ -1439,23 +1344,6 @@ bool ContentParent::SetPriorityAndCheckIsAlive(ProcessPriority aPriority) { ProcessPriorityManager::SetProcessPriority(this, aPriority); - - // 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! - // - // Bug 943174: use waitid() with WNOWAIT so that, if the process - // did exit, we won't consume its zombie and confuse the - // GeckoChildProcessHost dtor. -#ifdef MOZ_WIDGET_GONK - siginfo_t info; - info.si_pid = 0; - if (waitid(P_PID, Pid(), &info, WNOWAIT | WNOHANG | WEXITED) == 0 - && info.si_pid != 0) { - return false; - } -#endif - return true; } @@ -1824,12 +1712,6 @@ ContentParent::ActorDestroy(ActorDestroyReason why) mConsoleService = nullptr; -#ifdef MOZ_ENABLE_PROFILER_SPS - if (mGatherer && !mProfile.IsEmpty()) { - mGatherer->OOPExitProfile(mProfile); - } -#endif - if (obs) { RefPtr<nsHashPropertyBag> props = new nsHashPropertyBag(); @@ -2106,7 +1988,7 @@ ContentParent::ContentParent(mozIApplication* aApp, // PID along with the warning. nsDebugImpl::SetMultiprocessMode("Parent"); -#if defined(XP_WIN) && !defined(MOZ_B2G) +#if defined(XP_WIN) // Request Windows message deferral behavior on our side of the PContent // channel. Generally only applies to the situation where we get caught in // a deadlock with the plugin process when sending CPOWs. @@ -2244,37 +2126,6 @@ ContentParent::InitInternal(ProcessPriority aInitialPriority, } } -#ifdef MOZ_CONTENT_SANDBOX - bool shouldSandbox = true; - MaybeFileDesc brokerFd = void_t(); -#ifdef XP_LINUX - // XXX: Checking the pref here makes it possible to enable/disable sandboxing - // during an active session. Currently the pref is only used for testing - // purpose. If the decision is made to permanently rely on the pref, this - // should be changed so that it is required to restart firefox for the change - // of value to take effect. - shouldSandbox = (Preferences::GetInt("security.sandbox.content.level") > 0) && - !PR_GetEnv("MOZ_DISABLE_CONTENT_SANDBOX"); - - if (shouldSandbox) { - MOZ_ASSERT(!mSandboxBroker); - UniquePtr<SandboxBroker::Policy> policy = - sSandboxBrokerPolicyFactory->GetContentPolicy(Pid()); - if (policy) { - brokerFd = FileDescriptor(); - mSandboxBroker = SandboxBroker::Create(Move(policy), Pid(), brokerFd); - if (!mSandboxBroker) { - KillHard("SandboxBroker::Create failed"); - return; - } - MOZ_ASSERT(static_cast<const FileDescriptor&>(brokerFd).IsValid()); - } - } -#endif - if (shouldSandbox && !SendSetProcessSandbox(brokerFd)) { - KillHard("SandboxInitFailed"); - } -#endif #if defined(XP_WIN) // Send the info needed to join the browser process's audio session. nsID id; @@ -2660,27 +2511,6 @@ ContentParent::Observe(nsISupports* aSubject, NS_ASSERTION(!mSubprocess, "Close should have nulled mSubprocess"); } -#ifdef MOZ_ENABLE_PROFILER_SPS - // Need to do this before the mIsAlive check to avoid missing profiles. - if (!strcmp(aTopic, "profiler-subprocess-gather")) { - if (mGatherer) { - mGatherer->WillGatherOOPProfile(); - if (mIsAlive && mSubprocess) { - Unused << SendGatherProfile(); - } - } - } - else if (!strcmp(aTopic, "profiler-subprocess")) { - nsCOMPtr<nsIProfileSaveEvent> pse = do_QueryInterface(aSubject); - if (pse) { - if (!mProfile.IsEmpty()) { - pse->AddSubProfile(mProfile.get()); - mProfile.Truncate(); - } - } - } -#endif - if (!mIsAlive || !mSubprocess) return NS_OK; @@ -2746,50 +2576,6 @@ ContentParent::Observe(nsISupports* aSubject, else if (!strcmp(aTopic, "last-pb-context-exited")) { Unused << SendLastPrivateDocShellDestroyed(); } -#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; - int32_t state; - int32_t mountGeneration; - bool isMediaPresent; - bool isSharing; - bool isFormatting; - bool isFake; - bool isUnmounting; - bool isRemovable; - bool isHotSwappable; - - vol->GetName(volName); - vol->GetMountPoint(mountPoint); - vol->GetState(&state); - vol->GetMountGeneration(&mountGeneration); - vol->GetIsMediaPresent(&isMediaPresent); - vol->GetIsSharing(&isSharing); - vol->GetIsFormatting(&isFormatting); - vol->GetIsFake(&isFake); - vol->GetIsUnmounting(&isUnmounting); - vol->GetIsRemovable(&isRemovable); - vol->GetIsHotSwappable(&isHotSwappable); - - Unused << SendFileSystemUpdate(volName, mountPoint, state, - mountGeneration, isMediaPresent, - isSharing, isFormatting, isFake, - isUnmounting, isRemovable, isHotSwappable); - } else if (!strcmp(aTopic, "phone-state-changed")) { - nsString state(aData); - Unused << SendNotifyPhoneStateChange(state); - } - else if(!strcmp(aTopic, NS_VOLUME_REMOVED)) { - nsString volName(aData); - Unused << SendVolumeRemoved(volName); - } -#endif #ifdef ACCESSIBILITY else if (aData && !strcmp(aTopic, "a11y-init-or-shutdown")) { if (*aData == '1') { @@ -2811,22 +2597,6 @@ ContentParent::Observe(nsISupports* aSubject, } } #endif -#ifdef MOZ_ENABLE_PROFILER_SPS - else if (!strcmp(aTopic, "profiler-started")) { - nsCOMPtr<nsIProfilerStartParams> params(do_QueryInterface(aSubject)); - StartProfiler(params); - } - else if (!strcmp(aTopic, "profiler-stopped")) { - mGatherer = nullptr; - Unused << SendStopProfiler(); - } - else if (!strcmp(aTopic, "profiler-paused")) { - Unused << SendPauseProfiler(true); - } - else if (!strcmp(aTopic, "profiler-resumed")) { - Unused << SendPauseProfiler(false); - } -#endif else if (!strcmp(aTopic, "cacheservice:empty-cache")) { Unused << SendNotifyEmptyHTTPCache(); } @@ -3100,29 +2870,6 @@ ContentParent::FriendlyName(nsAString& aName, bool aAnonymize) } } -PCrashReporterParent* -ContentParent::AllocPCrashReporterParent(const NativeThreadId& tid, - const uint32_t& processType) -{ - return nullptr; -} - -bool -ContentParent::RecvPCrashReporterConstructor(PCrashReporterParent* actor, - const NativeThreadId& tid, - const uint32_t& processType) -{ - static_cast<CrashReporterParent*>(actor)->SetChildData(tid, processType); - return true; -} - -bool -ContentParent::DeallocPCrashReporterParent(PCrashReporterParent* crashreporter) -{ - delete crashreporter; - return true; -} - hal_sandbox::PHalParent* ContentParent::AllocPHalParent() { @@ -3224,11 +2971,15 @@ PPrintingParent* ContentParent::AllocPPrintingParent() { #ifdef NS_PRINTING - MOZ_ASSERT(!mPrintingParent, - "Only one PrintingParent should be created per process."); + MOZ_RELEASE_ASSERT(!mPrintingParent, + "Only one PrintingParent should be created per process."); // Create the printing singleton for this process. mPrintingParent = new PrintingParent(); + + // Take another reference for IPDL code. + mPrintingParent.get()->AddRef(); + return mPrintingParent.get(); #else MOZ_ASSERT_UNREACHABLE("Should never be created if no printing."); @@ -3240,8 +2991,11 @@ bool ContentParent::DeallocPPrintingParent(PPrintingParent* printing) { #ifdef NS_PRINTING - MOZ_ASSERT(mPrintingParent == printing, - "Only one PrintingParent should have been created per process."); + MOZ_RELEASE_ASSERT(mPrintingParent == printing, + "Only one PrintingParent should have been created per process."); + + // Release reference taken for IPDL code. + static_cast<PrintingParent*>(printing)->Release(); mPrintingParent = nullptr; #else @@ -3451,29 +3205,12 @@ ContentParent::RecvPSpeechSynthesisConstructor(PSpeechSynthesisParent* aActor) bool ContentParent::RecvSpeakerManagerGetSpeakerStatus(bool* aValue) { -#ifdef MOZ_WIDGET_GONK - *aValue = false; - RefPtr<SpeakerManagerService> service = - SpeakerManagerService::GetOrCreateSpeakerManagerService(); - MOZ_ASSERT(service); - - *aValue = service->GetSpeakerStatus(); - return true; -#endif return false; } bool ContentParent::RecvSpeakerManagerForceSpeaker(const bool& aEnable) { -#ifdef MOZ_WIDGET_GONK - RefPtr<SpeakerManagerService> service = - SpeakerManagerService::GetOrCreateSpeakerManagerService(); - MOZ_ASSERT(service); - service->ForceSpeaker(aEnable, mChildID); - - return true; -#endif return false; } @@ -3636,13 +3373,13 @@ ContentParent::RecvIsSecureURI(const uint32_t& type, } bool -ContentParent::RecvAccumulateMixedContentHSTS(const URIParams& aURI, const bool& aActive, const bool& aHSTSPriming) +ContentParent::RecvAccumulateMixedContentHSTS(const URIParams& aURI, const bool& aActive) { nsCOMPtr<nsIURI> ourURI = DeserializeURI(aURI); if (!ourURI) { return false; } - nsMixedContentBlocker::AccumulateMixedContentHSTS(ourURI, aActive, aHSTSPriming); + nsMixedContentBlocker::AccumulateMixedContentHSTS(ourURI, aActive); return true; } @@ -4029,49 +3766,22 @@ 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"); + NS_WARNING("ContentParent::RecvCreateFakeVolume shouldn't be called"); 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"); + NS_WARNING("ContentParent::RecvSetFakeVolumeState shouldn't be called"); return false; -#endif } bool ContentParent::RecvRemoveFakeVolume(const nsString& fsName) { -#ifdef MOZ_WIDGET_GONK - nsresult rv; - nsCOMPtr<nsIVolumeService> vs = do_GetService(NS_VOLUMESERVICE_CONTRACTID, &rv); - if (vs) { - vs->RemoveFakeVolume(fsName); - } - return true; -#else - NS_WARNING("ContentParent::RecvRemoveFakeVolume shouldn't be called when MOZ_WIDGET_GONK is not defined"); + NS_WARNING("ContentParent::RecvRemoveFakeVolume shouldn't be called"); return false; -#endif } bool @@ -4765,19 +4475,6 @@ ContentParent::RecvCreateWindow(PBrowserParent* aThisTab, } bool -ContentParent::RecvProfile(const nsCString& aProfile) -{ -#ifdef MOZ_ENABLE_PROFILER_SPS - if (NS_WARN_IF(!mGatherer)) { - return true; - } - mProfile = aProfile; - mGatherer->GatheredOOPProfile(); -#endif - return true; -} - -bool ContentParent::RecvGetGraphicsDeviceInitData(ContentDeviceData* aOut) { gfxPlatform::GetPlatform()->BuildContentDeviceData(aOut); @@ -4863,34 +4560,6 @@ ContentParent::RecvNotifyBenchmarkResult(const nsString& aCodecName, return true; } -void -ContentParent::StartProfiler(nsIProfilerStartParams* aParams) -{ -#ifdef MOZ_ENABLE_PROFILER_SPS - if (NS_WARN_IF(!aParams)) { - return; - } - - ProfilerInitParams ipcParams; - - ipcParams.enabled() = true; - aParams->GetEntries(&ipcParams.entries()); - aParams->GetInterval(&ipcParams.interval()); - ipcParams.features() = aParams->GetFeatures(); - ipcParams.threadFilters() = aParams->GetThreadFilterNames(); - - Unused << SendStartProfiler(ipcParams); - - nsCOMPtr<nsIProfiler> profiler(do_GetService("@mozilla.org/tools/profiler;1")); - if (NS_WARN_IF(!profiler)) { - return; - } - nsCOMPtr<nsISupports> gatherer; - profiler->GetProfileGatherer(getter_AddRefs(gatherer)); - mGatherer = static_cast<ProfileGatherer*>(gatherer.get()); -#endif -} - bool ContentParent::RecvNotifyPushObservers(const nsCString& aScope, const IPC::Principal& aPrincipal, @@ -5052,6 +4721,14 @@ ContentParent::RecvGetFilesRequest(const nsID& aUUID, { MOZ_ASSERT(!mGetFilesPendingRequests.GetWeak(aUUID)); + if (!mozilla::Preferences::GetBool("dom.filesystem.pathcheck.disabled", false)) { + RefPtr<FileSystemSecurity> fss = FileSystemSecurity::Get(); + if (NS_WARN_IF(!fss || + !fss->ContentProcessHasAccessTo(ChildID(), aDirectoryPath))) { + return false; + } + } + ErrorResult rv; RefPtr<GetFilesHelper> helper = GetFilesHelperParent::Create(aUUID, aDirectoryPath, aRecursiveFlag, this, |