Home | History | Annotate | Download | only in common
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CONTENT_PUBLIC_COMMON_SANDBOXED_PROCESS_LAUNCHER_DELEGATE_H_
      6 #define CONTENT_PUBLIC_COMMON_SANDBOXED_PROCESS_LAUNCHER_DELEGATE_H_
      7 
      8 #include "base/environment.h"
      9 #include "base/process/process.h"
     10 
     11 #include "content/common/content_export.h"
     12 
     13 #if defined(OS_MACOSX)
     14 #include "content/public/common/sandbox_type_mac.h"
     15 #endif
     16 
     17 namespace base {
     18 class FilePath;
     19 }
     20 
     21 namespace sandbox {
     22 class TargetPolicy;
     23 }
     24 
     25 namespace content {
     26 
     27 // Allows a caller of StartSandboxedProcess or
     28 // BrowserChildProcessHost/ChildProcessLauncher to control the sandbox policy,
     29 // i.e. to loosen it if needed.
     30 // The methods below will be called on the PROCESS_LAUNCHER thread.
     31 class CONTENT_EXPORT SandboxedProcessLauncherDelegate {
     32  public:
     33   virtual ~SandboxedProcessLauncherDelegate() {}
     34 
     35 #if defined(OS_WIN)
     36   // Override to return true if the process should be launched as an elevated
     37   // process (which implies no sandbox).
     38   virtual bool ShouldLaunchElevated();
     39 
     40   // By default, the process is launched sandboxed. Override this method to
     41   // return false if the process should be launched without a sandbox
     42   // (i.e. through base::LaunchProcess directly).
     43   virtual bool ShouldSandbox();
     44 
     45   // Called before the default sandbox is applied. If the default policy is too
     46   // restrictive, the caller should set |disable_default_policy| to true and
     47   // apply their policy in PreSpawnTarget. |exposed_dir| is used to allow a
     48   //directory through the sandbox.
     49   virtual void PreSandbox(bool* disable_default_policy,
     50                           base::FilePath* exposed_dir) {}
     51 
     52   // Called right before spawning the process.
     53   virtual void PreSpawnTarget(sandbox::TargetPolicy* policy,
     54                               bool* success) {}
     55 
     56   // Called right after the process is launched, but before its thread is run.
     57   virtual void PostSpawnTarget(base::ProcessHandle process) {}
     58 
     59 #elif defined(OS_POSIX)
     60   // Override this to return true to use the setuid sandbox.
     61   virtual bool ShouldUseZygote();
     62 
     63   // Override this if the process needs a non-empty environment map.
     64   virtual base::EnvironmentMap GetEnvironment();
     65 
     66   // Return the file descriptor for the IPC channel.
     67   virtual int GetIpcFd() = 0;
     68 
     69 #if defined(OS_MACOSX)
     70   // Gets the Mac SandboxType to enforce on the process. Return
     71   // SANDBOX_TYPE_INVALID for no sandbox policy.
     72   virtual SandboxType GetSandboxType();
     73 #endif
     74 
     75 #endif
     76 };
     77 
     78 }  // namespace content
     79 
     80 #endif  // CONTENT_PUBLIC_COMMON_SANDBOXED_PROCESS_LAUNCHER_DELEGATE_H_
     81