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/common/sandbox_mac.h" | 5 #include "content/common/sandbox_mac.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 extern "C" { | 9 extern "C" { |
10 #include <sandbox.h> | 10 #include <sandbox.h> |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // that needs to be warmed up. The OS version on which we found the need to | 245 // that needs to be warmed up. The OS version on which we found the need to |
246 // enable the function is also noted. | 246 // enable the function is also noted. |
247 // This function is tested on the following OS versions: | 247 // This function is tested on the following OS versions: |
248 // 10.5.6, 10.6.0 | 248 // 10.5.6, 10.6.0 |
249 | 249 |
250 // static | 250 // static |
251 void Sandbox::SandboxWarmup(int sandbox_type) { | 251 void Sandbox::SandboxWarmup(int sandbox_type) { |
252 base::mac::ScopedNSAutoreleasePool scoped_pool; | 252 base::mac::ScopedNSAutoreleasePool scoped_pool; |
253 | 253 |
254 { // CGColorSpaceCreateWithName(), CGBitmapContextCreate() - 10.5.6 | 254 { // CGColorSpaceCreateWithName(), CGBitmapContextCreate() - 10.5.6 |
255 base::mac::ScopedCFTypeRef<CGColorSpaceRef> rgb_colorspace( | 255 base::ScopedCFTypeRef<CGColorSpaceRef> rgb_colorspace( |
256 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); | 256 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB)); |
257 | 257 |
258 // Allocate a 1x1 image. | 258 // Allocate a 1x1 image. |
259 char data[4]; | 259 char data[4]; |
260 base::mac::ScopedCFTypeRef<CGContextRef> context( | 260 base::ScopedCFTypeRef<CGContextRef> context(CGBitmapContextCreate( |
261 CGBitmapContextCreate(data, 1, 1, 8, 1 * 4, | 261 data, |
262 rgb_colorspace, | 262 1, |
263 kCGImageAlphaPremultipliedFirst | | 263 1, |
264 kCGBitmapByteOrder32Host)); | 264 8, |
| 265 1 * 4, |
| 266 rgb_colorspace, |
| 267 kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); |
265 | 268 |
266 // Load in the color profiles we'll need (as a side effect). | 269 // Load in the color profiles we'll need (as a side effect). |
267 (void) base::mac::GetSRGBColorSpace(); | 270 (void) base::mac::GetSRGBColorSpace(); |
268 (void) base::mac::GetSystemColorSpace(); | 271 (void) base::mac::GetSystemColorSpace(); |
269 | 272 |
270 // CGColorSpaceCreateSystemDefaultCMYK - 10.6 | 273 // CGColorSpaceCreateSystemDefaultCMYK - 10.6 |
271 base::mac::ScopedCFTypeRef<CGColorSpaceRef> cmyk_colorspace( | 274 base::ScopedCFTypeRef<CGColorSpaceRef> cmyk_colorspace( |
272 CGColorSpaceCreateWithName(kCGColorSpaceGenericCMYK)); | 275 CGColorSpaceCreateWithName(kCGColorSpaceGenericCMYK)); |
273 } | 276 } |
274 | 277 |
275 { // [-NSColor colorUsingColorSpaceName] - 10.5.6 | 278 { // [-NSColor colorUsingColorSpaceName] - 10.5.6 |
276 NSColor* color = [NSColor controlTextColor]; | 279 NSColor* color = [NSColor controlTextColor]; |
277 [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; | 280 [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; |
278 } | 281 } |
279 | 282 |
280 { // localtime() - 10.5.6 | 283 { // localtime() - 10.5.6 |
281 time_t tv = {0}; | 284 time_t tv = {0}; |
282 localtime(&tv); | 285 localtime(&tv); |
283 } | 286 } |
284 | 287 |
285 { // Gestalt() tries to read /System/Library/CoreServices/SystemVersion.plist | 288 { // Gestalt() tries to read /System/Library/CoreServices/SystemVersion.plist |
286 // on 10.5.6 | 289 // on 10.5.6 |
287 int32 tmp; | 290 int32 tmp; |
288 base::SysInfo::OperatingSystemVersionNumbers(&tmp, &tmp, &tmp); | 291 base::SysInfo::OperatingSystemVersionNumbers(&tmp, &tmp, &tmp); |
289 } | 292 } |
290 | 293 |
291 { // CGImageSourceGetStatus() - 10.6 | 294 { // CGImageSourceGetStatus() - 10.6 |
292 // Create a png with just enough data to get everything warmed up... | 295 // Create a png with just enough data to get everything warmed up... |
293 char png_header[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; | 296 char png_header[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; |
294 NSData* data = [NSData dataWithBytes:png_header | 297 NSData* data = [NSData dataWithBytes:png_header |
295 length:arraysize(png_header)]; | 298 length:arraysize(png_header)]; |
296 base::mac::ScopedCFTypeRef<CGImageSourceRef> img( | 299 base::ScopedCFTypeRef<CGImageSourceRef> img( |
297 CGImageSourceCreateWithData((CFDataRef)data, | 300 CGImageSourceCreateWithData((CFDataRef)data, NULL)); |
298 NULL)); | |
299 CGImageSourceGetStatus(img); | 301 CGImageSourceGetStatus(img); |
300 } | 302 } |
301 | 303 |
302 { | 304 { |
303 // Allow access to /dev/urandom. | 305 // Allow access to /dev/urandom. |
304 base::GetUrandomFD(); | 306 base::GetUrandomFD(); |
305 } | 307 } |
306 | 308 |
307 // Process-type dependent warm-up. | 309 // Process-type dependent warm-up. |
308 if (sandbox_type == SANDBOX_TYPE_GPU) { | 310 if (sandbox_type == SANDBOX_TYPE_GPU) { |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 if (HANDLE_EINTR(fcntl(fd, F_GETPATH, canonical_path)) != 0) { | 601 if (HANDLE_EINTR(fcntl(fd, F_GETPATH, canonical_path)) != 0) { |
600 DPLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " | 602 DPLOG(FATAL) << "GetCanonicalSandboxPath() failed for: " |
601 << path.value(); | 603 << path.value(); |
602 return path; | 604 return path; |
603 } | 605 } |
604 | 606 |
605 return base::FilePath(canonical_path); | 607 return base::FilePath(canonical_path); |
606 } | 608 } |
607 | 609 |
608 } // namespace content | 610 } // namespace content |
OLD | NEW |