Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / content / browser / child_process_launcher.cc
index 3869c68..152cd5c 100644 (file)
@@ -28,7 +28,9 @@
 #include "content/common/sandbox_win.h"
 #include "content/public/common/sandbox_init.h"
 #elif defined(OS_MACOSX)
+#include "content/browser/bootstrap_sandbox_mac.h"
 #include "content/browser/mach_broker_mac.h"
+#include "sandbox/mac/bootstrap_sandbox.h"
 #elif defined(OS_ANDROID)
 #include "base/android/jni_android.h"
 #include "content/browser/android/child_process_launcher_android.h"
@@ -74,7 +76,7 @@ class ChildProcessLauncher::Context
 
   void Launch(
       SandboxedProcessLauncherDelegate* delegate,
-      CommandLine* cmd_line,
+      base::CommandLine* cmd_line,
       int child_process_id,
       Client* client) {
     client_ = client;
@@ -170,7 +172,7 @@ class ChildProcessLauncher::Context
       BrowserThread::ID client_thread_id,
       int child_process_id,
       SandboxedProcessLauncherDelegate* delegate,
-      CommandLine* cmd_line) {
+      base::CommandLine* cmd_line) {
     scoped_ptr<SandboxedProcessLauncherDelegate> delegate_deleter(delegate);
 #if defined(OS_WIN)
     bool launch_elevated = delegate->ShouldLaunchElevated();
@@ -184,7 +186,7 @@ class ChildProcessLauncher::Context
     base::EnvironmentMap env = delegate->GetEnvironment();
     int ipcfd = delegate->GetIpcFd();
 #endif
-    scoped_ptr<CommandLine> cmd_line_deleter(cmd_line);
+    scoped_ptr<base::CommandLine> cmd_line_deleter(cmd_line);
     base::TimeTicks begin_launch_time = base::TimeTicks::Now();
 
 #if defined(OS_WIN)
@@ -282,11 +284,27 @@ class ChildProcessLauncher::Context
       // Make sure the MachBroker is running, and inform it to expect a
       // check-in from the new process.
       broker->EnsureRunning();
+
+      const int bootstrap_sandbox_policy = delegate->GetSandboxType();
+      if (ShouldEnableBootstrapSandbox() &&
+          bootstrap_sandbox_policy != SANDBOX_TYPE_INVALID) {
+        options.replacement_bootstrap_name =
+            GetBootstrapSandbox()->server_bootstrap_name();
+        GetBootstrapSandbox()->PrepareToForkWithPolicy(
+            bootstrap_sandbox_policy);
+      }
 #endif  // defined(OS_MACOSX)
 
       bool launched = base::LaunchProcess(*cmd_line, options, &handle);
+      if (!launched)
+        handle = base::kNullProcessHandle;
 
 #if defined(OS_MACOSX)
+      if (ShouldEnableBootstrapSandbox() &&
+          bootstrap_sandbox_policy != SANDBOX_TYPE_INVALID) {
+        GetBootstrapSandbox()->FinishedFork(handle);
+      }
+
       if (launched)
         broker->AddPlaceholderForPid(handle);
 
@@ -294,9 +312,6 @@ class ChildProcessLauncher::Context
       // messasge be processed on the broker's thread.
       broker->GetLock().Release();
 #endif  // defined(OS_MACOSX)
-
-      if (!launched)
-        handle = base::kNullProcessHandle;
     }
 #endif  // else defined(OS_POSIX)
 #if !defined(OS_ANDROID)
@@ -421,7 +436,7 @@ class ChildProcessLauncher::Context
 
 ChildProcessLauncher::ChildProcessLauncher(
     SandboxedProcessLauncherDelegate* delegate,
-    CommandLine* cmd_line,
+    base::CommandLine* cmd_line,
     int child_process_id,
     Client* client) {
   context_ = new Context();
@@ -496,10 +511,10 @@ base::TerminationStatus ChildProcessLauncher::GetChildTerminationStatus(
 
 void ChildProcessLauncher::SetProcessBackgrounded(bool background) {
   BrowserThread::PostTask(
-      BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
-      base::Bind(
-          &ChildProcessLauncher::Context::SetProcessBackgrounded,
-          GetHandle(), background));
+     BrowserThread::PROCESS_LAUNCHER, FROM_HERE,
+     base::Bind(
+         &ChildProcessLauncher::Context::SetProcessBackgrounded,
+         GetHandle(), background));
 }
 
 void ChildProcessLauncher::SetTerminateChildOnShutdown(