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/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
16 #include "content/common/sandbox_mac.h" | 16 #include "content/common/sandbox_mac.h" |
17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
18 #import "content/public/common/injection_test_mac.h" | |
19 #include "content/common/sandbox_init_mac.h" | 18 #include "content/common/sandbox_init_mac.h" |
20 | 19 |
21 namespace content { | 20 namespace content { |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 // You are about to read a pretty disgusting hack. In a static initializer, | 24 // You are about to read a pretty disgusting hack. In a static initializer, |
26 // CoreFoundation decides to connect with cfprefsd(8) using Mach IPC. There is | 25 // CoreFoundation decides to connect with cfprefsd(8) using Mach IPC. There is |
27 // no public way to close this Mach port after-the-fact, nor a way to stop it | 26 // no public way to close this Mach port after-the-fact, nor a way to stop it |
28 // from happening since it is done pre-main in dyld. But the address of the | 27 // from happening since it is done pre-main in dyld. But the address of the |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 NSString* string = @""; | 120 NSString* string = @""; |
122 [NSThread detachNewThreadSelector:@selector(length) | 121 [NSThread detachNewThreadSelector:@selector(length) |
123 toTarget:string | 122 toTarget:string |
124 withObject:nil]; | 123 withObject:nil]; |
125 } | 124 } |
126 } | 125 } |
127 | 126 |
128 void RendererMainPlatformDelegate::PlatformUninitialize() { | 127 void RendererMainPlatformDelegate::PlatformUninitialize() { |
129 } | 128 } |
130 | 129 |
131 static void LogTestMessage(std::string message, bool is_error) { | |
132 if (is_error) | |
133 LOG(ERROR) << message; | |
134 else | |
135 VLOG(0) << message; | |
136 } | |
137 | |
138 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { | |
139 const CommandLine& command_line = parameters_.command_line; | |
140 | |
141 if (command_line.HasSwitch(switches::kTestSandbox)) { | |
142 std::string bundle_path = | |
143 command_line.GetSwitchValueNative(switches::kTestSandbox); | |
144 if (bundle_path.empty()) { | |
145 NOTREACHED() << "Bad bundle path"; | |
146 return false; | |
147 } | |
148 NSBundle* tests_bundle = | |
149 [NSBundle bundleWithPath:base::SysUTF8ToNSString(bundle_path)]; | |
150 if (![tests_bundle load]) { | |
151 NOTREACHED() << "Failed to load bundle"; | |
152 return false; | |
153 } | |
154 sandbox_tests_bundle_ = [tests_bundle retain]; | |
155 [objc_getClass("RendererSandboxTestsRunner") setLogFunction:LogTestMessage]; | |
156 } | |
157 return true; | |
158 } | |
159 | |
160 bool RendererMainPlatformDelegate::EnableSandbox() { | 130 bool RendererMainPlatformDelegate::EnableSandbox() { |
161 // Enable the sandbox. | 131 // Enable the sandbox. |
162 bool sandbox_initialized = InitializeSandbox(); | 132 bool sandbox_initialized = InitializeSandbox(); |
163 | 133 |
164 // The sandbox is now engaged. Make sure that the renderer has not connected | 134 // The sandbox is now engaged. Make sure that the renderer has not connected |
165 // itself to Cocoa. | 135 // itself to Cocoa. |
166 CHECK(NSApp == nil); | 136 CHECK(NSApp == nil); |
167 | 137 |
168 DisconnectCFNotificationCenter(); | 138 DisconnectCFNotificationCenter(); |
169 | 139 |
170 return sandbox_initialized; | 140 return sandbox_initialized; |
171 } | 141 } |
172 | 142 |
173 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { | |
174 Class tests_runner = objc_getClass("RendererSandboxTestsRunner"); | |
175 if (tests_runner) { | |
176 if (![tests_runner runTests]) | |
177 LOG(ERROR) << "Running renderer with failing sandbox tests!"; | |
178 [sandbox_tests_bundle_ unload]; | |
179 [sandbox_tests_bundle_ release]; | |
180 sandbox_tests_bundle_ = nil; | |
181 } | |
182 } | |
183 | |
184 } // namespace content | 143 } // namespace content |
OLD | NEW |