[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / bootstrap_sandbox_manager_mac.cc
blob48d25491429665a76e9edc43e6af364f6fff4965
1 // Copyright 2014 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.
5 #include "content/browser/bootstrap_sandbox_manager_mac.h"
7 #include "base/logging.h"
8 #include "base/mac/mac_util.h"
9 #include "content/browser/browser_io_surface_manager_mac.h"
10 #include "content/browser/mach_broker_mac.h"
11 #include "content/common/sandbox_init_mac.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/child_process_data.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "sandbox/mac/bootstrap_sandbox.h"
17 namespace content {
19 // static
20 bool BootstrapSandboxManager::ShouldEnable() {
21 return false;
24 // static
25 BootstrapSandboxManager* BootstrapSandboxManager::GetInstance() {
26 return base::Singleton<BootstrapSandboxManager>::get();
29 bool BootstrapSandboxManager::EnabledForSandbox(SandboxType sandbox_type) {
30 return sandbox_type == SANDBOX_TYPE_RENDERER;
33 void BootstrapSandboxManager::BrowserChildProcessHostDisconnected(
34 const ChildProcessData& data) {
35 sandbox()->InvalidateClient(data.handle);
38 void BootstrapSandboxManager::BrowserChildProcessCrashed(
39 const ChildProcessData& data,
40 int exit_code) {
41 sandbox()->InvalidateClient(data.handle);
44 void BootstrapSandboxManager::RenderProcessExited(
45 RenderProcessHost* host,
46 base::TerminationStatus status,
47 int exit_code) {
48 sandbox()->InvalidateClient(host->GetHandle());
51 BootstrapSandboxManager::BootstrapSandboxManager()
52 : sandbox_(sandbox::BootstrapSandbox::Create()) {
53 CHECK(sandbox_.get());
54 DCHECK_CURRENTLY_ON(BrowserThread::UI);
55 BrowserChildProcessObserver::Add(this);
56 RegisterSandboxPolicies();
59 BootstrapSandboxManager::~BootstrapSandboxManager() {
60 BrowserChildProcessObserver::Remove(this);
63 void BootstrapSandboxManager::RegisterSandboxPolicies() {
64 RegisterRendererPolicy();
67 void BootstrapSandboxManager::RegisterRendererPolicy() {
68 sandbox::BootstrapSandboxPolicy policy;
69 AddBaselinePolicy(&policy);
71 // Permit font queries.
72 policy.rules["com.apple.FontServer"] = sandbox::Rule(sandbox::POLICY_ALLOW);
73 policy.rules["com.apple.FontObjectsServer"] =
74 sandbox::Rule(sandbox::POLICY_ALLOW);
76 // Allow access to the windowserver. This is needed to get the colorspace
77 // during sandbox warmup. Since NSColorSpace conforms to NSCoding, this
78 // should be plumbed over IPC instead <http://crbug.com/265709>.
79 policy.rules["com.apple.windowserver.active"] =
80 sandbox::Rule(sandbox::POLICY_ALLOW);
82 // Allow renderers to contact the IOSurfaceManager in the browser to share
83 // accelerated surfaces.
84 policy.rules[BrowserIOSurfaceManager::GetMachPortName()] =
85 sandbox::Rule(sandbox::POLICY_ALLOW);
87 // Allow access to launchservicesd on 10.10+ otherwise the renderer will crash
88 // attempting to get its ASN. http://crbug.com/533537
89 if (base::mac::IsOSYosemiteOrLater()) {
90 policy.rules["com.apple.coreservices.launchservicesd"] =
91 sandbox::Rule(sandbox::POLICY_ALLOW);
94 sandbox_->RegisterSandboxPolicy(SANDBOX_TYPE_RENDERER, policy);
97 void BootstrapSandboxManager::AddBaselinePolicy(
98 sandbox::BootstrapSandboxPolicy* policy) {
99 auto& rules = policy->rules;
101 // Allow the child to send its task port to the MachBroker.
102 rules[MachBroker::GetMachPortName()] = sandbox::Rule(sandbox::POLICY_ALLOW);
104 // Allow logging to the syslog.
105 rules["com.apple.system.logger"] = sandbox::Rule(sandbox::POLICY_ALLOW);
108 } // namespace content