Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(629)

Side by Side Diff: chrome/renderer/renderer_main_platform_delegate_mac.mm

Issue 28214: Add a macutil for the main app bundle and override... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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>
11 #import <Cocoa/Cocoa.h> 11 #import <Cocoa/Cocoa.h>
12 extern "C" { 12 extern "C" {
13 #include <sandbox.h> 13 #include <sandbox.h>
14 } 14 }
15 15
16 #include "base/sys_info.h" 16 #include "base/sys_info.h"
17 #include "base/mac_util.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" 19 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h"
19 20
20 RendererMainPlatformDelegate::RendererMainPlatformDelegate( 21 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
21 const MainFunctionParams& parameters) 22 const MainFunctionParams& parameters)
22 : parameters_(parameters) { 23 : parameters_(parameters) {
23 } 24 }
24 25
25 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { 26 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() {
26 } 27 }
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // This call doesn't work when the sandbox is enabled, the implementation 92 // This call doesn't work when the sandbox is enabled, the implementation
92 // caches it's return value so we call it here and then future calls will 93 // caches it's return value so we call it here and then future calls will
93 // succeed. 94 // succeed.
94 DebugUtil::BeingDebugged(); 95 DebugUtil::BeingDebugged();
95 96
96 // Cache the System info information, since we can't query certain attributes 97 // Cache the System info information, since we can't query certain attributes
97 // with the Sandbox enabled. 98 // with the Sandbox enabled.
98 base::SysInfo::CacheSysInfo(); 99 base::SysInfo::CacheSysInfo();
99 100
100 // For the renderer, we give it a custom sandbox to lock down as tight as 101 // For the renderer, we give it a custom sandbox to lock down as tight as
101 // possible, but still be able to draw. If we're not a renderer process, it 102 // possible, but still be able to draw.
102 // usually means we're a unittest, so we use a pure compute sandbox instead.
103 103
104 const char *sandbox_profile = kSBXProfilePureComputation; 104 NSString* sandbox_profile_path =
105 uint64_t sandbox_flags = SANDBOX_NAMED; 105 [mac_util::MainAppBundle() pathForResource:@"renderer" ofType:@"sb"];
106 106 BOOL is_dir = NO;
107 if (parameters_.sandbox_info_.ProcessType() == switches::kRendererProcess) { 107 if (![[NSFileManager defaultManager] fileExistsAtPath:sandbox_profile_path
108 NSString* sandbox_profile_path = 108 isDirectory:&is_dir] || is_dir) {
109 [[NSBundle mainBundle] pathForResource:@"renderer" ofType:@"sb"]; 109 LOG(ERROR) << "Failed to find the sandbox profile on disk";
110 BOOL is_dir = NO; 110 return false;
111 if (![[NSFileManager defaultManager] fileExistsAtPath:sandbox_profile_path
112 isDirectory:&is_dir] || is_dir) {
113 LOG(ERROR) << "Failed to find the sandbox profile on disk";
114 return false;
115 }
116 sandbox_profile = [sandbox_profile_path fileSystemRepresentation];
117 sandbox_flags = SANDBOX_NAMED_EXTERNAL;
118 } 111 }
119 112
113 const char *sandbox_profile = [sandbox_profile_path fileSystemRepresentation];
120 char* error_buff = NULL; 114 char* error_buff = NULL;
121 int error = sandbox_init(sandbox_profile, sandbox_flags, 115 int error = sandbox_init(sandbox_profile, SANDBOX_NAMED_EXTERNAL,
122 &error_buff); 116 &error_buff);
123 bool success = (error == 0 && error_buff == NULL); 117 bool success = (error == 0 && error_buff == NULL);
124 if (error == -1) { 118 if (error == -1) {
125 LOG(ERROR) << "Failed to Initialize Sandbox: " << error_buff; 119 LOG(ERROR) << "Failed to Initialize Sandbox: " << error_buff;
126 } 120 }
127 sandbox_free_error(error_buff); 121 sandbox_free_error(error_buff);
128 return success; 122 return success;
129 } 123 }
130 124
131 void RendererMainPlatformDelegate::RunSandboxTests() { 125 void RendererMainPlatformDelegate::RunSandboxTests() {
132 // TODO(port): Run sandbox unit test here. 126 // TODO(port): Run sandbox unit test here.
133 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698