Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(966)

Side by Side Diff: content/renderer/renderer_main_platform_delegate_mac.mm

Issue 2944623003: Call SetApplicationIsDaemon() in V2 sandbox. (Closed)
Patch Set: Only execute callback if not-null Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/common/sandbox_mac.mm ('k') | content/renderer/renderer_v2.sb » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/renderer_main_platform_delegate.h" 5 #include "content/renderer/renderer_main_platform_delegate.h"
6 6
7 #include <Carbon/Carbon.h> 7 #include <Carbon/Carbon.h>
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <objc/runtime.h> 9 #include <objc/runtime.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 11
12 #include "base/bind.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/logging.h" 14 #include "base/logging.h"
14 #include "base/mac/mac_util.h" 15 #include "base/mac/mac_util.h"
15 #include "base/mac/scoped_cftyperef.h" 16 #include "base/mac/scoped_cftyperef.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/sys_string_conversions.h" 18 #include "base/strings/sys_string_conversions.h"
18 #include "content/common/sandbox_init_mac.h" 19 #include "content/common/sandbox_init_mac.h"
19 #include "content/common/sandbox_mac.h" 20 #include "content/common/sandbox_mac.h"
20 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
22 #include "sandbox/mac/seatbelt.h"
23
24 extern "C" {
25 void CGSSetDenyWindowServerConnections(bool);
26 void CGSShutdownServerConnections();
27 OSStatus SetApplicationIsDaemon(Boolean isDaemon);
28 };
21 29
22 namespace content { 30 namespace content {
23 31
24 namespace { 32 namespace {
25 33
34 // This disconnects from the window server, and then indicates that Chrome
35 // should continue execution without access to launchservicesd.
36 void DisconnectWindowServer() {
37 // Now disconnect from WindowServer, after all objects have been warmed up.
38 // Shutting down the connection requires connecting to WindowServer,
39 // so do this before actually engaging the sandbox. This may cause two log
40 // messages to be printed to the system logger on certain OS versions.
41 CGSSetDenyWindowServerConnections(true);
42 CGSShutdownServerConnections();
43 // Allow the process to continue without a LaunchServices ASN. The
44 // INIT_Process function in HIServices will abort if it cannot connect to
45 // launchservicesd to get an ASN. By setting this flag, HIServices skips
46 // that.
47 SetApplicationIsDaemon(true);
48 }
49
26 // You are about to read a pretty disgusting hack. In a static initializer, 50 // You are about to read a pretty disgusting hack. In a static initializer,
27 // CoreFoundation decides to connect with cfprefsd(8) using Mach IPC. There is 51 // CoreFoundation decides to connect with cfprefsd(8) using Mach IPC. There is
28 // no public way to close this Mach port after-the-fact, nor a way to stop it 52 // no public way to close this Mach port after-the-fact, nor a way to stop it
29 // from happening since it is done pre-main in dyld. But the address of the 53 // from happening since it is done pre-main in dyld. But the address of the
30 // CFMachPort can be found in the run loop's string description. Below, that 54 // CFMachPort can be found in the run loop's string description. Below, that
31 // address is parsed, cast, and then used to invalidate the Mach port to 55 // address is parsed, cast, and then used to invalidate the Mach port to
32 // disable communication with cfprefsd. 56 // disable communication with cfprefsd.
33 void DisconnectCFNotificationCenter() { 57 void DisconnectCFNotificationCenter() {
34 base::ScopedCFTypeRef<CFStringRef> run_loop_description( 58 base::ScopedCFTypeRef<CFStringRef> run_loop_description(
35 CFCopyDescription(CFRunLoopGetCurrent())); 59 CFCopyDescription(CFRunLoopGetCurrent()));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 [NSThread detachNewThreadSelector:@selector(length) 145 [NSThread detachNewThreadSelector:@selector(length)
122 toTarget:string 146 toTarget:string
123 withObject:nil]; 147 withObject:nil];
124 } 148 }
125 } 149 }
126 150
127 void RendererMainPlatformDelegate::PlatformUninitialize() { 151 void RendererMainPlatformDelegate::PlatformUninitialize() {
128 } 152 }
129 153
130 bool RendererMainPlatformDelegate::EnableSandbox() { 154 bool RendererMainPlatformDelegate::EnableSandbox() {
131 // Enable the sandbox. 155 bool sandbox_initialized = sandbox::Seatbelt::IsSandboxed();
132 bool sandbox_initialized = InitializeSandbox(); 156
157 // If the sandbox is already engaged, just disconnect from the window server.
158 if (sandbox_initialized) {
159 DisconnectWindowServer();
160 } else {
161 sandbox_initialized = InitializeSandboxWithPostWarmupHook(
162 base::BindOnce(&DisconnectWindowServer));
163 }
133 164
134 // The sandbox is now engaged. Make sure that the renderer has not connected 165 // The sandbox is now engaged. Make sure that the renderer has not connected
135 // itself to Cocoa. 166 // itself to Cocoa.
136 CHECK(NSApp == nil); 167 CHECK(NSApp == nil);
137 168
138 DisconnectCFNotificationCenter(); 169 DisconnectCFNotificationCenter();
139 170
140 return sandbox_initialized; 171 return sandbox_initialized;
141 } 172 }
142 173
143 } // namespace content 174 } // namespace content
OLDNEW
« no previous file with comments | « content/common/sandbox_mac.mm ('k') | content/renderer/renderer_v2.sb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698