Add sandbox support (issue #524).

- The sandbox is now enabled by default on all platforms. Use the CefSettings.no_sandbox option or the "no-sandbox" command-line flag to disable sandbox support.
- Windows: See cef_sandbox_win.h for requirements to enable sandbox support.
- Windows: If Visual Studio isn't installed in the standard location set the CEF_VCVARS environment variable before running make_distrib.py or automate.py (see msvs_env.bat).
- Linux: For binary distributions a new chrome-sandbox executable with SUID permissions must be placed next to the CEF executable. See https://code.google.com/p/chromium/wiki/LinuxSUIDSandboxDevelopment for details on setting up the development environment when building CEF from source code.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1518 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2013-11-15 18:47:02 +00:00
parent 395f443215
commit f5bc72b234
24 changed files with 485 additions and 52 deletions

View File

@@ -60,7 +60,8 @@ class CefForceShutdown {
} // namespace
int CefExecuteProcess(const CefMainArgs& args,
CefRefPtr<CefApp> application) {
CefRefPtr<CefApp> application,
void* windows_sandbox_info) {
CommandLine command_line(CommandLine::NO_PROGRAM);
#if defined(OS_WIN)
command_line.ParseFromString(::GetCommandLineW());
@@ -89,9 +90,14 @@ int CefExecuteProcess(const CefMainArgs& args,
// Execute the secondary process.
#if defined(OS_WIN)
sandbox::SandboxInterfaceInfo sandbox_info = {0};
content::InitializeSandboxInfo(&sandbox_info);
if (windows_sandbox_info == NULL) {
content::InitializeSandboxInfo(&sandbox_info);
windows_sandbox_info = &sandbox_info;
}
return content::ContentMain(args.instance, &sandbox_info, &main_delegate);
return content::ContentMain(args.instance,
static_cast<sandbox::SandboxInterfaceInfo*>(windows_sandbox_info),
&main_delegate);
#else
return content::ContentMain(args.argc, const_cast<const char**>(args.argv),
&main_delegate);
@@ -100,7 +106,8 @@ int CefExecuteProcess(const CefMainArgs& args,
bool CefInitialize(const CefMainArgs& args,
const CefSettings& settings,
CefRefPtr<CefApp> application) {
CefRefPtr<CefApp> application,
void* windows_sandbox_info) {
// Return true if the global context already exists.
if (g_context)
return true;
@@ -116,7 +123,8 @@ bool CefInitialize(const CefMainArgs& args,
g_context = new CefContext();
// Initialize the global context.
return g_context->Initialize(args, settings, application);
return g_context->Initialize(args, settings, application,
windows_sandbox_info);
}
void CefShutdown() {
@@ -222,7 +230,8 @@ CefContext* CefContext::Get() {
bool CefContext::Initialize(const CefMainArgs& args,
const CefSettings& settings,
CefRefPtr<CefApp> application) {
CefRefPtr<CefApp> application,
void* windows_sandbox_info) {
init_thread_id_ = base::PlatformThread::CurrentId();
settings_ = settings;
@@ -257,10 +266,15 @@ bool CefContext::Initialize(const CefMainArgs& args,
// Initialize the content runner.
#if defined(OS_WIN)
sandbox::SandboxInterfaceInfo sandbox_info = {0};
content::InitializeSandboxInfo(&sandbox_info);
if (windows_sandbox_info == NULL) {
content::InitializeSandboxInfo(&sandbox_info);
windows_sandbox_info = &sandbox_info;
settings_.no_sandbox = true;
}
exit_code = main_runner_->Initialize(args.instance, &sandbox_info,
main_delegate_.get());
exit_code = main_runner_->Initialize(args.instance,
static_cast<sandbox::SandboxInterfaceInfo*>(windows_sandbox_info),
main_delegate_.get());
#else
exit_code = main_runner_->Initialize(args.argc,
const_cast<const char**>(args.argv),

View File

@@ -48,7 +48,8 @@ class CefContext : public content::NotificationObserver {
// These methods will be called on the main application thread.
bool Initialize(const CefMainArgs& args,
const CefSettings& settings,
CefRefPtr<CefApp> application);
CefRefPtr<CefApp> application,
void* windows_sandbox_info);
void Shutdown();
// Returns true if the current thread is the initialization thread.

View File

@@ -166,15 +166,26 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
if (settings.single_process)
command_line->AppendSwitch(switches::kSingleProcess);
bool no_sandbox = settings.no_sandbox;
if (settings.browser_subprocess_path.length > 0) {
base::FilePath file_path =
base::FilePath(CefString(&settings.browser_subprocess_path));
if (!file_path.empty()) {
command_line->AppendSwitchPath(switches::kBrowserSubprocessPath,
file_path);
#if defined(OS_WIN)
// The sandbox is not supported when using a separate subprocess
// executable on Windows.
no_sandbox = true;
#endif
}
}
if (no_sandbox)
command_line->AppendSwitch(switches::kNoSandbox);
if (settings.user_agent.length > 0) {
command_line->AppendSwitchASCII(switches::kUserAgent,
CefString(&settings.user_agent));
@@ -267,10 +278,6 @@ bool CefMainDelegate::BasicStartupComplete(int* exit_code) {
command_line->AppendSwitchASCII(switches::kContextSafetyImplementation,
base::IntToString(settings.context_safety_implementation));
}
// TODO(cef): Figure out how to support the sandbox.
if (!command_line->HasSwitch(switches::kNoSandbox))
command_line->AppendSwitch(switches::kNoSandbox);
}
if (content_client_.application().get()) {