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
|
|
|
|
2016-03-08 22:02:27 +03:00
|
|
|
#if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX)
|
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
2016-02-26 02:26:13 +03:00
|
|
|
#if (defined(XP_WIN) || defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
|
|
|
|
#include "mozilla/Preferences.h"
|
2016-03-08 22:02:27 +03:00
|
|
|
#include "nsAppDirectoryServiceDefs.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
|
2017-01-29 10:27:33 +03:00
|
|
|
// when sandbox pref level >= 1.
|
|
|
|
return Preferences::GetInt("security.sandbox.content.level") >= 1;
|
2016-02-26 02:26:13 +03:00
|
|
|
}
|
|
|
|
|
2016-03-08 22:02:27 +03:00
|
|
|
static void
|
|
|
|
SetTmpEnvironmentVariable(nsIFile* aValue)
|
2016-02-26 02:26:13 +03:00
|
|
|
{
|
2016-03-08 22:02:27 +03:00
|
|
|
// Save the TMP environment variable so that is is picked up by GetTempPath().
|
|
|
|
// Note that we specifically write to the TMP variable, as that is the first
|
|
|
|
// variable that is checked by GetTempPath() to determine its output.
|
|
|
|
nsAutoString fullTmpPath;
|
|
|
|
nsresult rv = aValue->GetPath(fullTmpPath);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(!SetEnvironmentVariableW(L"TMP", fullTmpPath.get()));
|
2016-03-08 22:02:27 +03:00
|
|
|
// We also set TEMP in case there is naughty third-party code that is
|
|
|
|
// referencing the environment variable directly.
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(!SetEnvironmentVariableW(L"TEMP", fullTmpPath.get()));
|
2016-02-26 02:26:13 +03:00
|
|
|
}
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2016-03-08 22:02:27 +03:00
|
|
|
static void
|
|
|
|
SetTmpEnvironmentVariable(nsIFile* aValue)
|
2016-02-26 02:26:13 +03:00
|
|
|
{
|
2016-03-08 22:02:27 +03:00
|
|
|
nsAutoCString fullTmpPath;
|
|
|
|
nsresult rv = aValue->GetNativePath(fullTmpPath);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
2016-09-02 10:12:24 +03:00
|
|
|
Unused << NS_WARN_IF(setenv("TMPDIR", fullTmpPath.get(), 1) != 0);
|
2016-02-26 02:26:13 +03:00
|
|
|
}
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2016-03-08 22:02:27 +03:00
|
|
|
nsCOMPtr<nsIFile> sandboxedContentTemp;
|
|
|
|
nsresult rv =
|
|
|
|
nsDirectoryService::gService->Get(NS_APP_CONTENT_PROCESS_TEMP_DIR,
|
|
|
|
NS_GET_IID(nsIFile),
|
|
|
|
getter_AddRefs(sandboxedContentTemp));
|
2015-05-18 13:51:07 +03:00
|
|
|
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);
|
2016-03-08 22:02:27 +03:00
|
|
|
rv = nsDirectoryService::gService->Set(NS_OS_TEMP_DIR, sandboxedContentTemp);
|
2015-05-18 13:51:07 +03:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
2016-03-08 22:02:27 +03:00
|
|
|
|
|
|
|
SetTmpEnvironmentVariable(sandboxedContentTemp);
|
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);
|
|
|
|
}
|
|
|
|
|
2016-08-30 23:32:21 +03:00
|
|
|
#if defined(XP_MACOSX) && defined(MOZ_CONTENT_SANDBOX)
|
|
|
|
void
|
|
|
|
ContentProcess::SetProfile(const nsACString& aProfile)
|
|
|
|
{
|
|
|
|
bool flag;
|
|
|
|
nsresult rv =
|
|
|
|
XRE_GetFileFromPath(aProfile.BeginReading(), getter_AddRefs(mProfileDir));
|
|
|
|
if (NS_FAILED(rv) ||
|
|
|
|
NS_FAILED(mProfileDir->Exists(&flag)) || !flag) {
|
|
|
|
NS_WARNING("Invalid profile directory passed to content process.");
|
|
|
|
mProfileDir = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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-08-30 23:32:21 +03:00
|
|
|
#if (defined(XP_MACOSX)) && defined(MOZ_CONTENT_SANDBOX)
|
|
|
|
mContent.SetProfileDir(mProfileDir);
|
|
|
|
#endif
|
|
|
|
|
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
|