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)
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
#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)
|
|
|
|
static already_AddRefed<nsIFile>
|
|
|
|
GetLowIntegrityTemp()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsDirectoryService::gService,
|
|
|
|
"GetLowIntegrityTemp relies on nsDirectoryService being initialized");
|
|
|
|
|
|
|
|
// A low integrity temp only currently makes sense for sandbox pref level 1.
|
|
|
|
if (Preferences::GetInt("security.sandbox.content.level") != 1) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> lowIntegrityTemp;
|
|
|
|
nsresult rv = nsDirectoryService::gService->Get(NS_WIN_LOW_INTEGRITY_TEMP,
|
|
|
|
NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(lowIntegrityTemp));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return lowIntegrityTemp.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
SetUpSandboxEnvironment()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(nsDirectoryService::gService,
|
|
|
|
"SetUpSandboxEnvironment relies on nsDirectoryService being initialized");
|
|
|
|
|
|
|
|
// Setup to use a low integrity temp if available.
|
|
|
|
nsCOMPtr<nsIFile> lowIntegrityTemp = GetLowIntegrityTemp();
|
|
|
|
if (!lowIntegrityTemp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Undefine returns a failure if the property is not already set.
|
|
|
|
unused << nsDirectoryService::gService->Undefine(NS_OS_TEMP_DIR);
|
|
|
|
nsresult rv = nsDirectoryService::gService->Set(NS_OS_TEMP_DIR, lowIntegrityTemp);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set TEMP and TMP environment variables.
|
|
|
|
nsAutoString lowIntegrityTempPath;
|
|
|
|
rv = lowIntegrityTemp->GetPath(lowIntegrityTempPath);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool setOK = SetEnvironmentVariableW(L"TEMP", lowIntegrityTempPath.get());
|
|
|
|
NS_WARN_IF_FALSE(setOK, "Failed to set TEMP to low integrity temp path");
|
|
|
|
setOK = SetEnvironmentVariableW(L"TMP", lowIntegrityTempPath.get());
|
|
|
|
NS_WARN_IF_FALSE(setOK, "Failed to set TMP to low integrity temp path");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CleanUpSandboxEnvironment()
|
|
|
|
{
|
|
|
|
// Remove low integrity temp if it exists.
|
|
|
|
nsCOMPtr<nsIFile> lowIntegrityTemp = GetLowIntegrityTemp();
|
|
|
|
if (!lowIntegrityTemp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't check the return value as the directory will only have been created
|
|
|
|
// if it has been used.
|
|
|
|
unused << lowIntegrityTemp->Remove(/* aRecursive */ true);
|
|
|
|
}
|
|
|
|
#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-04-01 11:40:35 +03:00
|
|
|
ParentPid(),
|
2010-05-14 03:44:53 +04:00
|
|
|
IOThreadChild::channel());
|
2010-05-26 04:13:47 +04:00
|
|
|
mXREEmbed.Start();
|
2010-09-24 05:39:32 +04:00
|
|
|
mContent.InitXPCOM();
|
2015-04-05 16:01:38 +03:00
|
|
|
|
|
|
|
#if defined(XP_WIN) && defined(MOZ_CONTENT_SANDBOX)
|
|
|
|
SetUpSandboxEnvironment();
|
|
|
|
#endif
|
2010-05-26 04:13:47 +04:00
|
|
|
|
2010-05-14 03:44:53 +04:00
|
|
|
return true;
|
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
|
|
|
{
|
2014-09-10 15:36:17 +04:00
|
|
|
#if defined(XP_WIN) && defined(MOZ_CONTENT_SANDBOX)
|
2015-04-05 16:01:38 +03:00
|
|
|
CleanUpSandboxEnvironment();
|
2014-09-10 15:36:17 +04:00
|
|
|
#endif
|
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
|