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 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
14 #include "base/mac/scoped_cftyperef.h" | 14 #include "base/mac/scoped_cftyperef.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
17 #include "content/common/sandbox_mac.h" | 17 #include "content/common/sandbox_mac.h" |
18 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
19 #include "content/common/sandbox_init_mac.h" | 19 #include "content/common/sandbox_init_mac.h" |
20 | 20 |
21 extern "C" { | |
22 void CGSSetDenyWindowServerConnections(bool); | |
23 void CGSShutdownServerConnections(); | |
24 }; | |
25 | |
26 namespace content { | 21 namespace content { |
27 | 22 |
28 namespace { | 23 namespace { |
29 | 24 |
30 // You are about to read a pretty disgusting hack. In a static initializer, | 25 // You are about to read a pretty disgusting hack. In a static initializer, |
31 // CoreFoundation decides to connect with cfprefsd(8) using Mach IPC. There is | 26 // CoreFoundation decides to connect with cfprefsd(8) using Mach IPC. There is |
32 // no public way to close this Mach port after-the-fact, nor a way to stop it | 27 // no public way to close this Mach port after-the-fact, nor a way to stop it |
33 // from happening since it is done pre-main in dyld. But the address of the | 28 // from happening since it is done pre-main in dyld. But the address of the |
34 // CFMachPort can be found in the run loop's string description. Below, that | 29 // CFMachPort can be found in the run loop's string description. Below, that |
35 // address is parsed, cast, and then used to invalidate the Mach port to | 30 // address is parsed, cast, and then used to invalidate the Mach port to |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 [NSThread detachNewThreadSelector:@selector(length) | 129 [NSThread detachNewThreadSelector:@selector(length) |
135 toTarget:string | 130 toTarget:string |
136 withObject:nil]; | 131 withObject:nil]; |
137 } | 132 } |
138 } | 133 } |
139 | 134 |
140 void RendererMainPlatformDelegate::PlatformUninitialize() { | 135 void RendererMainPlatformDelegate::PlatformUninitialize() { |
141 } | 136 } |
142 | 137 |
143 bool RendererMainPlatformDelegate::EnableSandbox() { | 138 bool RendererMainPlatformDelegate::EnableSandbox() { |
144 // Disconnect from WindowServer before entering the sandbox, after all | |
145 // objects have been warmed up. Shutting down the connection requires | |
146 // connecting to WindowServer, so do this before engaging the sandbox. | |
147 CGSSetDenyWindowServerConnections(true); | |
148 CGSShutdownServerConnections(); | |
149 | |
150 // Enable the sandbox. | 139 // Enable the sandbox. |
151 bool sandbox_initialized = InitializeSandbox(); | 140 bool sandbox_initialized = InitializeSandbox(); |
152 | 141 |
153 // The sandbox is now engaged. Make sure that the renderer has not connected | 142 // The sandbox is now engaged. Make sure that the renderer has not connected |
154 // itself to Cocoa. | 143 // itself to Cocoa. |
155 CHECK(NSApp == nil); | 144 CHECK(NSApp == nil); |
156 | 145 |
157 DisconnectCFNotificationCenter(); | 146 DisconnectCFNotificationCenter(); |
158 | 147 |
159 return sandbox_initialized; | 148 return sandbox_initialized; |
160 } | 149 } |
161 | 150 |
162 } // namespace content | 151 } // namespace content |
OLD | NEW |