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

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

Issue 27108: Temporary fix for the Cocoa-in-renderer problem. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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 extern "C" { 12 extern "C" {
12 #include <sandbox.h> 13 #include <sandbox.h>
13 } 14 }
14 15
15 #include "base/sys_info.h" 16 #include "base/sys_info.h"
16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
17 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h" 18 #include "third_party/WebKit/WebKit/mac/WebCoreSupport/WebSystemInterface.h"
18 19
19 RendererMainPlatformDelegate::RendererMainPlatformDelegate( 20 RendererMainPlatformDelegate::RendererMainPlatformDelegate(
20 const MainFunctionParams& parameters) 21 const MainFunctionParams& parameters)
(...skipping 13 matching lines...) Expand all
34 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 35 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
35 36
36 // Allocate a 1 byte image. 37 // Allocate a 1 byte image.
37 char data[8]; 38 char data[8];
38 CGContextRef tmp = CGBitmapContextCreate(data, 1, 1, 8, 1*8, 39 CGContextRef tmp = CGBitmapContextCreate(data, 1, 1, 8, 1*8,
39 rgb_colorspace, 40 rgb_colorspace,
40 kCGImageAlphaPremultipliedFirst | 41 kCGImageAlphaPremultipliedFirst |
41 kCGBitmapByteOrder32Host); 42 kCGBitmapByteOrder32Host);
42 CGColorSpaceRelease(rgb_colorspace); 43 CGColorSpaceRelease(rgb_colorspace);
43 CGContextRelease(tmp); 44 CGContextRelease(tmp);
45
46 #if 0
47
48 // Note: by default, Cocoa is NOT thread safe. Use of NSThreads
49 // tells Cocoa to be MT-aware and create and use locks. The
50 // renderer process only uses Cocoa from the single renderer thread,
51 // so we don't need to tell Cocoa we are using threads (even though,
52 // oddly, we are using Cocoa from the non-main thread.)
53 // The current limit of renderer processes is 20. Brett states that
54 // (despite comments to the contrary) when two tabs are using the
55 // same renderer, we do NOT create a 2nd renderer thread in that
56 // process. Thus, we don't need to MT-aware Cocoa.
57 // (Code and comments left here in case that changes.)
58 if (![NSThread isMultiThreaded]) {
Mark Mentovai 2009/02/25 14:19:39 FYI, base::InitThreading() from platform_thread_ma
59 NSString *string = @"";
60 [NSThread detachNewThreadSelector:@selector(length)
61 toTarget:string
62 withObject:nil];
63 }
64 #endif
65
66 // Initialize Cocoa. Without this call, drawing of native UI
67 // elements (e.g. buttons) in WebKit will explode.
68 [NSApplication sharedApplication];
44 } 69 }
45 70
46 void RendererMainPlatformDelegate::PlatformUninitialize() { 71 void RendererMainPlatformDelegate::PlatformUninitialize() {
47 } 72 }
48 73
49 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) { 74 bool RendererMainPlatformDelegate::InitSandboxTests(bool no_sandbox) {
50 return true; 75 return true;
51 } 76 }
52 77
53 bool RendererMainPlatformDelegate::EnableSandbox() { 78 bool RendererMainPlatformDelegate::EnableSandbox() {
54 79
55 // This call doesn't work when the sandbox is enabled, the implementation 80 // This call doesn't work when the sandbox is enabled, the implementation
56 // caches it's return value so we call it here and then future calls will 81 // caches it's return value so we call it here and then future calls will
57 // succeed. 82 // succeed.
58 DebugUtil::BeingDebugged(); 83 DebugUtil::BeingDebugged();
59 84
60 // Cache the System info information, since we can't query certain attributes 85 // Cache the System info information, since we can't query certain attributes
61 // with the Sandbox enabled. 86 // with the Sandbox enabled.
62 base::SysInfo::CacheSysInfo(); 87 base::SysInfo::CacheSysInfo();
63 88
64 // For the renderer, we give it a custom sandbox to lock down as tight as 89 // For the renderer, we give it a custom sandbox to lock down as tight as
65 // possible, but still be able to draw. If we're not a renderer process, it 90 // possible, but still be able to draw. If we're not a renderer process, it
66 // usually means we're a unittest, so we use a pure compute sandbox instead. 91 // usually means we're a unittest, so we use a pure compute sandbox instead.
67 92
68 const char *sandbox_profile = kSBXProfilePureComputation; 93 const char *sandbox_profile = kSBXProfilePureComputation;
69 uint64_t sandbox_flags = SANDBOX_NAMED; 94 uint64_t sandbox_flags = SANDBOX_NAMED;
70 95
71 if (parameters_.sandbox_info_.ProcessType() == switches::kRendererProcess) { 96 if (parameters_.sandbox_info_.ProcessType() == switches::kRendererProcess) {
72 NSString* sandbox_profile_path = 97 NSString* sandbox_profile_path =
73 [[NSBundle mainBundle] pathForResource:@"renderer" ofType:@"sb"]; 98 [[NSBundle mainBundle] pathForResource:@"renderer" ofType:@"sb"];
74 BOOL is_dir = NO; 99 BOOL is_dir = NO;
75 if (![[NSFileManager defaultManager] fileExistsAtPath:sandbox_profile_path 100 if (![[NSFileManager defaultManager] fileExistsAtPath:sandbox_profile_path
76 isDirectory:&is_dir] || is_dir) { 101 isDirectory:&is_dir] || is_dir) {
77 LOG(ERROR) << "Failed to find the sandbox profile on disk"; 102 LOG(ERROR) << "Failed to find the sandbox profile on disk";
78 return false; 103 return false;
79 } 104 }
80 sandbox_profile = [sandbox_profile_path fileSystemRepresentation]; 105 sandbox_profile = [sandbox_profile_path fileSystemRepresentation];
81 sandbox_flags = SANDBOX_NAMED_EXTERNAL; 106 sandbox_flags = SANDBOX_NAMED_EXTERNAL;
82 } 107 }
83 108
84 char* error_buff = NULL; 109 char* error_buff = NULL;
85 int error = sandbox_init(sandbox_profile, sandbox_flags, 110 int error = sandbox_init(sandbox_profile, sandbox_flags,
86 &error_buff); 111 &error_buff);
87 bool success = (error == 0 && error_buff == NULL); 112 bool success = (error == 0 && error_buff == NULL);
88 if (error == -1) { 113 if (error == -1) {
89 LOG(ERROR) << "Failed to Initialize Sandbox: " << error_buff; 114 LOG(ERROR) << "Failed to Initialize Sandbox: " << error_buff;
90 } 115 }
91 sandbox_free_error(error_buff); 116 sandbox_free_error(error_buff);
92 return success; 117 return success;
93 } 118 }
94 119
95 void RendererMainPlatformDelegate::RunSandboxTests() { 120 void RendererMainPlatformDelegate::RunSandboxTests() {
96 // TODO(port): Run sandbox unit test here. 121 // TODO(port): Run sandbox unit test here.
97 } 122 }
OLDNEW
« chrome/browser/browser_main_mac.mm ('K') | « chrome/common/child_thread.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698