OLD | NEW |
---|---|
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/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/mac/mac_util.h" | 14 #include "base/mac/mac_util.h" |
15 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
18 #include "content/common/sandbox_init_mac.h" | 18 #include "content/common/sandbox_init_mac.h" |
19 #include "content/common/sandbox_mac.h" | 19 #include "content/common/sandbox_mac.h" |
20 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
21 | 21 |
22 extern "C" { | |
23 void CGSSetDenyWindowServerConnections(bool); | |
24 void CGSShutdownServerConnections(); | |
25 OSStatus SetApplicationIsDaemon(Boolean isDaemon); | |
26 }; | |
27 | |
22 namespace content { | 28 namespace content { |
23 | 29 |
24 namespace { | 30 namespace { |
25 | 31 |
26 // You are about to read a pretty disgusting hack. In a static initializer, | 32 // 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 | 33 // 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 | 34 // 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 | 35 // 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 | 36 // 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 | 37 // address is parsed, cast, and then used to invalidate the Mach port to |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 NSString* string = @""; | 126 NSString* string = @""; |
121 [NSThread detachNewThreadSelector:@selector(length) | 127 [NSThread detachNewThreadSelector:@selector(length) |
122 toTarget:string | 128 toTarget:string |
123 withObject:nil]; | 129 withObject:nil]; |
124 } | 130 } |
125 } | 131 } |
126 | 132 |
127 void RendererMainPlatformDelegate::PlatformUninitialize() { | 133 void RendererMainPlatformDelegate::PlatformUninitialize() { |
128 } | 134 } |
129 | 135 |
130 bool RendererMainPlatformDelegate::EnableSandbox() { | 136 bool RendererMainPlatformDelegate::EnableSandbox() { |
Robert Sesek
2017/07/06 21:28:09
(… continuing comment from sandbox_init_mac.h):
T
Greg K
2017/07/07 18:10:21
Done.
| |
137 // Acquire resources before the sandbox is enabled. | |
138 ExplicitlyWarmupSandbox(); | |
139 | |
140 // `ExplicitlyWarmupSandbox` and `ExplicitlyEnableSandbox` are no-ops | |
Greg K
2017/07/03 21:26:08
I know there are a lot of comments here but I kept
Robert Sesek
2017/07/06 21:28:09
I think the comments are very helpful as well.
Greg K
2017/07/07 18:10:21
Acknowledged.
| |
141 // at this stage of execution when the V2 sandbox is enabled. Thus the | |
142 // calls to shut down window server connections and continue with an ASN | |
143 // must be made here, as they must still be executed in the V2 sandbox. | |
144 | |
145 // Now disconnect from WindowServer, after all objects have been warmed up. | |
146 // Shutting down the connection requires connecting to WindowServer, | |
147 // so do this before actually engaging the sandbox. This may cause two log | |
148 // messages to be printed to the system logger on certain OS versions. | |
149 CGSSetDenyWindowServerConnections(true); | |
150 CGSShutdownServerConnections(); | |
151 // Allow the process to continue without a LaunchServices ASN. The | |
152 // INIT_Process function in HIServices will abort if it cannot connect to | |
153 // launchservicesd to get an ASN. By setting this flag, HIServices skips | |
154 // that. | |
155 SetApplicationIsDaemon(true); | |
156 | |
131 // Enable the sandbox. | 157 // Enable the sandbox. |
132 bool sandbox_initialized = InitializeSandbox(); | 158 bool sandbox_initialized = ExplicitlyEnableSandbox(); |
133 | 159 |
134 // The sandbox is now engaged. Make sure that the renderer has not connected | 160 // The sandbox is now engaged. Make sure that the renderer has not connected |
135 // itself to Cocoa. | 161 // itself to Cocoa. |
136 CHECK(NSApp == nil); | 162 CHECK(NSApp == nil); |
137 | 163 |
138 DisconnectCFNotificationCenter(); | 164 DisconnectCFNotificationCenter(); |
139 | 165 |
140 return sandbox_initialized; | 166 return sandbox_initialized; |
141 } | 167 } |
142 | 168 |
143 } // namespace content | 169 } // namespace content |
OLD | NEW |