Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/renderer_main_platform_delegate.h" | 5 #include "chrome/renderer/renderer_main_platform_delegate.h" |
| 6 | 6 |
| 7 #include "base/debug_util.h" | 7 #include "base/debug_util.h" |
| 8 | 8 |
| 9 #import <Foundation/Foundation.h> | 9 #import <Foundation/Foundation.h> |
| 10 #import <ApplicationServices/ApplicationServices.h> | 10 #import <ApplicationServices/ApplicationServices.h> |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 { // [-NSColor colorUsingColorSpaceName] - 10.5.6 | 56 { // [-NSColor colorUsingColorSpaceName] - 10.5.6 |
| 57 NSColor *color = [NSColor controlTextColor]; | 57 NSColor *color = [NSColor controlTextColor]; |
| 58 [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; | 58 [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace]; |
| 59 } | 59 } |
| 60 | 60 |
| 61 { // localtime() - 10.5.6 | 61 { // localtime() - 10.5.6 |
| 62 time_t tv = {0}; | 62 time_t tv = {0}; |
| 63 localtime(&tv); | 63 localtime(&tv); |
| 64 } | 64 } |
| 65 | 65 |
| 66 { // Gestalt() tries to read /System/Library/CoreServices/SystemVersion.plist | |
| 67 // on 10.5.6 | |
| 68 int32 tmp; | |
| 69 base::SysInfo::OperatingSystemVersionNumbers(&tmp, &tmp, &tmp); | |
| 70 } | |
| 71 | |
| 66 { // CGImageSourceGetStatus() - 10.6 seed release. | 72 { // CGImageSourceGetStatus() - 10.6 seed release. |
| 67 // Create a png with just enough data to get everything warmed up... | 73 // Create a png with just enough data to get everything warmed up... |
| 68 char png_header[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; | 74 char png_header[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; |
| 69 NSData *data = [NSData dataWithBytes:png_header | 75 NSData *data = [NSData dataWithBytes:png_header |
| 70 length:arraysize(png_header)]; | 76 length:arraysize(png_header)]; |
| 71 scoped_cftyperef<CGImageSourceRef> img( | 77 scoped_cftyperef<CGImageSourceRef> img( |
| 72 CGImageSourceCreateWithData((CFDataRef)data, | 78 CGImageSourceCreateWithData((CFDataRef)data, |
| 73 NULL)); | 79 NULL)); |
| 74 CGImageSourceGetStatus(img); | 80 CGImageSourceGetStatus(img); |
| 75 } | 81 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 98 } | 104 } |
| 99 | 105 |
| 100 void RendererMainPlatformDelegate::PlatformUninitialize() { | 106 void RendererMainPlatformDelegate::PlatformUninitialize() { |
| 101 } | 107 } |
| 102 | 108 |
| 103 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { | 109 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { |
| 104 return true; | 110 return true; |
| 105 } | 111 } |
| 106 | 112 |
| 107 bool RendererMainPlatformDelegate::EnableSandbox() { | 113 bool RendererMainPlatformDelegate::EnableSandbox() { |
| 108 | 114 // For the renderer, we give it a custom sandbox to lock things down as |
| 109 // TODO(jeremy): Remove BeingDebugged() and CacheSysInfo() calls. They are | 115 // tightly as possible, while still enabling drawing. |
| 110 // no longer required since the sandbox now allows sysctl() reads. | |
| 111 | |
| 112 // This call doesn't work when the sandbox is enabled, the implementation | |
| 113 // caches it's return value so we call it here and then future calls will | |
| 114 // succeed. | |
| 115 DebugUtil::BeingDebugged(); | |
| 116 | |
| 117 // For the renderer, we give it a custom sandbox to lock down as tight as | |
| 118 // possible, but still be able to draw. | |
| 119 | |
| 120 NSString* sandbox_profile_path = | 116 NSString* sandbox_profile_path = |
| 121 [mac_util::MainAppBundle() pathForResource:@"renderer" ofType:@"sb"]; | 117 [mac_util::MainAppBundle() pathForResource:@"renderer" ofType:@"sb"]; |
| 122 BOOL is_dir = NO; | 118 NSString *sandbox_data = [NSString |
|
Paul Godavari
2009/08/21 21:26:12
nit: * should be placed consistently.
| |
| 123 if (![[NSFileManager defaultManager] fileExistsAtPath:sandbox_profile_path | 119 stringWithContentsOfFile:sandbox_profile_path |
| 124 isDirectory:&is_dir] || is_dir) { | 120 encoding:NSUTF8StringEncoding |
| 121 error:nil]; | |
| 122 | |
| 123 if (!sandbox_data) { | |
| 125 LOG(ERROR) << "Failed to find the sandbox profile on disk"; | 124 LOG(ERROR) << "Failed to find the sandbox profile on disk"; |
| 126 return false; | 125 return false; |
| 127 } | 126 } |
| 128 | 127 |
| 129 const char *sandbox_profile = [sandbox_profile_path fileSystemRepresentation]; | 128 // Splice the path of the user's home directory into the sandbox profile |
| 129 // (see renderer.sb for details). | |
| 130 sandbox_data = [sandbox_data | |
| 131 stringByReplacingOccurrencesOfString:@"USER_HOMEDIR" | |
| 132 withString:NSHomeDirectory()]; | |
| 133 | |
| 130 char* error_buff = NULL; | 134 char* error_buff = NULL; |
| 131 int error = sandbox_init(sandbox_profile, SANDBOX_NAMED_EXTERNAL, | 135 int error = sandbox_init([sandbox_data UTF8String], 0, &error_buff); |
| 132 &error_buff); | |
| 133 bool success = (error == 0 && error_buff == NULL); | 136 bool success = (error == 0 && error_buff == NULL); |
| 134 if (error == -1) { | 137 if (error == -1) { |
| 135 LOG(ERROR) << "Failed to Initialize Sandbox: " << error_buff; | 138 LOG(ERROR) << "Failed to Initialize Sandbox: " << error_buff; |
| 136 } | 139 } |
| 137 sandbox_free_error(error_buff); | 140 sandbox_free_error(error_buff); |
| 138 return success; | 141 return success; |
| 139 } | 142 } |
| 140 | 143 |
| 141 void RendererMainPlatformDelegate::RunSandboxTests() { | 144 void RendererMainPlatformDelegate::RunSandboxTests() { |
| 142 // TODO(port): Run sandbox unit test here. | 145 // TODO(port): Run sandbox unit test here. |
| 143 } | 146 } |
| OLD | NEW |