2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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-07-01 00:39:22 +04:00
|
|
|
|
2010-05-14 03:44:53 +04:00
|
|
|
#include "mozilla/ipc/IOThreadChild.h"
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2010-07-19 22:33:33 +04:00
|
|
|
#include "ContentProcess.h"
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2015-04-05 16:01:38 +03:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_CONTENT_SANDBOX)
|
2015-05-18 13:51:07 +03:00
|
|
|
#include "mozilla/WindowsVersion.h"
|
2016-02-26 02:26:13 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
|
|
|
|
#include "mozilla/Preferences.h"
|
2015-04-05 16:01:38 +03:00
|
|
|
#include "nsDirectoryService.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-14 03:44:53 +04:00
|
|
|
using mozilla::ipc::IOThreadChild;
|
2009-07-01 00:39:22 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2009-08-12 20:18:08 +04:00
|
|
|
namespace dom {
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2015-04-05 16:01:38 +03:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_CONTENT_SANDBOX)
|
2016-02-26 02:26:13 +03:00
|
|
|
static bool
|
|
|
|
IsSandboxTempDirRequired()
|
|
|
|
{
|
|
|
|
// On Windows, a sandbox-writable temp directory is only used
|
|
|
|
// for Vista or later with sandbox pref level >= 1.
|
|
|
|
return (IsVistaOrLater() &&
|
|
|
|
(Preferences::GetInt("security.sandbox.content.level") >= 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
SandboxTempDirParent()
|
|
|
|
{
|
|
|
|
// On Windows, the sandbox-writable temp directory resides in the
|
|
|
|
// low integrity sandbox base directory.
|
|
|
|
return NS_WIN_LOW_INTEGRITY_TEMP_BASE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX)
|
|
|
|
static bool
|
|
|
|
IsSandboxTempDirRequired()
|
|
|
|
{
|
|
|
|
// On OSX, use the sandbox-writable temp when the pref level >= 1.
|
|
|
|
return (Preferences::GetInt("security.sandbox.content.level") >= 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char*
|
|
|
|
SandboxTempDirParent()
|
|
|
|
{
|
|
|
|
return NS_OS_TEMP_DIR;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
|
2015-04-05 16:01:38 +03:00
|
|
|
static void
|
|
|
|
SetUpSandboxEnvironment()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsDirectoryService::gService,
|
|
|
|
"SetUpSandboxEnvironment relies on nsDirectoryService being initialized");
|
|
|
|
|
2016-02-26 02:26:13 +03:00
|
|
|
if (!IsSandboxTempDirRequired()) {
|
2015-04-05 16:01:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-18 13:51:07 +03:00
|
|
|
nsAdoptingString tempDirSuffix =
|
|
|
|
Preferences::GetString("security.sandbox.content.tempDirSuffix");
|
|
|
|
if (tempDirSuffix.IsEmpty()) {
|
2016-02-26 02:26:13 +03:00
|
|
|
NS_WARNING("Sandbox-writable temp directory suffix pref not set.");
|
2015-04-05 16:01:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-26 02:26:13 +03:00
|
|
|
// Get the parent of our sandbox writable temp directory.
|
2015-05-18 13:51:07 +03:00
|
|
|
nsCOMPtr<nsIFile> lowIntegrityTemp;
|
2016-02-26 02:26:13 +03:00
|
|
|
nsresult rv = nsDirectoryService::gService->Get(SandboxTempDirParent(),
|
2015-05-18 13:51:07 +03:00
|
|
|
NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(lowIntegrityTemp));
|
2015-04-05 16:01:38 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-18 13:51:07 +03:00
|
|
|
// Append our profile specific temp name.
|
|
|
|
rv = lowIntegrityTemp->Append(NS_LITERAL_STRING("Temp-") + tempDirSuffix);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2015-04-05 16:01:38 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-02-26 02:26:13 +03:00
|
|
|
// Change the gecko defined temp directory to our sandbox-writable one.
|
2015-05-18 13:51:07 +03:00
|
|
|
// Undefine returns a failure if the property is not already set.
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << nsDirectoryService::gService->Undefine(NS_OS_TEMP_DIR);
|
2015-05-18 13:51:07 +03:00
|
|
|
rv = nsDirectoryService::gService->Set(NS_OS_TEMP_DIR, lowIntegrityTemp);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
2015-04-05 16:01:38 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-18 20:24:42 +04:00
|
|
|
void
|
|
|
|
ContentProcess::SetAppDir(const nsACString& aPath)
|
|
|
|
{
|
|
|
|
mXREEmbed.SetAppDir(aPath);
|
|
|
|
}
|
|
|
|
|
2010-05-14 03:44:53 +04:00
|
|
|
bool
|
2010-07-19 22:33:33 +04:00
|
|
|
ContentProcess::Init()
|
2009-07-01 00:39:22 +04:00
|
|
|
{
|
2010-07-19 22:33:33 +04:00
|
|
|
mContent.Init(IOThreadChild::message_loop(),
|
2015-08-02 23:59:33 +03:00
|
|
|
ParentPid(),
|
|
|
|
IOThreadChild::channel());
|
2010-05-26 04:13:47 +04:00
|
|
|
mXREEmbed.Start();
|
2010-09-24 05:39:32 +04:00
|
|
|
mContent.InitXPCOM();
|
2015-08-02 23:59:33 +03:00
|
|
|
mContent.InitGraphicsDeviceData();
|
2015-04-05 16:01:38 +03:00
|
|
|
|
2016-02-26 02:26:13 +03:00
|
|
|
#if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
|
2015-04-05 16:01:38 +03:00
|
|
|
SetUpSandboxEnvironment();
|
|
|
|
#endif
|
2016-02-26 02:26:13 +03:00
|
|
|
|
2010-05-14 03:44:53 +04:00
|
|
|
return true;
|
2009-07-01 00:39:22 +04:00
|
|
|
}
|
|
|
|
|
2015-05-20 11:58:32 +03:00
|
|
|
// Note: CleanUp() never gets called in non-debug builds because we exit early
|
|
|
|
// in ContentChild::ActorDestroy().
|
2009-07-01 00:39:22 +04:00
|
|
|
void
|
2010-07-19 22:33:33 +04:00
|
|
|
ContentProcess::CleanUp()
|
2009-07-01 00:39:22 +04:00
|
|
|
{
|
2010-02-01 06:19:21 +03:00
|
|
|
mXREEmbed.Stop();
|
2009-07-01 00:39:22 +04:00
|
|
|
}
|
|
|
|
|
2013-06-03 14:14:40 +04:00
|
|
|
} // namespace dom
|
2009-07-01 00:39:22 +04:00
|
|
|
} // namespace mozilla
|