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 #import "base/mac/foundation_util.h" | 13 #import "base/mac/foundation_util.h" |
14 #import "base/mac/mac_util.h" | |
14 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
15 #include "base/sys_string_conversions.h" | 16 #include "base/sys_string_conversions.h" |
16 #include "content/common/sandbox_mac.h" | 17 #include "content/common/sandbox_mac.h" |
17 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
18 #import "content/public/common/injection_test_mac.h" | 19 #import "content/public/common/injection_test_mac.h" |
19 #include "content/common/sandbox_init_mac.h" | 20 #include "content/common/sandbox_init_mac.h" |
20 #include "third_party/mach_override/mach_override.h" | 21 #include "third_party/mach_override/mach_override.h" |
21 | 22 |
22 extern "C" { | 23 extern "C" { |
23 // SPI logging functions for CF that are exported externally. | 24 // SPI logging functions for CF that are exported externally. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 NOTREACHED() << "Failed to load bundle"; | 120 NOTREACHED() << "Failed to load bundle"; |
120 return false; | 121 return false; |
121 } | 122 } |
122 sandbox_tests_bundle_ = [tests_bundle retain]; | 123 sandbox_tests_bundle_ = [tests_bundle retain]; |
123 [objc_getClass("RendererSandboxTestsRunner") setLogFunction:LogTestMessage]; | 124 [objc_getClass("RendererSandboxTestsRunner") setLogFunction:LogTestMessage]; |
124 } | 125 } |
125 return true; | 126 return true; |
126 } | 127 } |
127 | 128 |
128 bool RendererMainPlatformDelegate::EnableSandbox() { | 129 bool RendererMainPlatformDelegate::EnableSandbox() { |
130 // http://openradar.appspot.com/radar?id=1156410 is fixed on OS X 10.9+. | |
129 // See http://crbug.com/31225 and http://crbug.com/152566 | 131 // See http://crbug.com/31225 and http://crbug.com/152566 |
130 // TODO: Don't do this on newer OS X revisions that have a fix for | |
131 // http://openradar.appspot.com/radar?id=1156410 | |
132 // To check if this is broken: | 132 // To check if this is broken: |
133 // 1. Enable Multi language input (simplified chinese) | 133 // 1. Enable Multi language input (simplified chinese) |
134 // 2. Ensure "Show/Hide Trackpad Handwriting" shortcut works. | 134 // 2. Ensure "Show/Hide Trackpad Handwriting" shortcut works. |
135 // (ctrl+shift+space). | 135 // (ctrl+shift+space). |
136 // 3. Now open a new tab in Google Chrome or start Google Chrome | 136 // 3. Now open a new tab in Google Chrome or start Google Chrome |
137 // 4. Try ctrl+shift+space shortcut again. Shortcut will not work, IME will | 137 // 4. Try ctrl+shift+space shortcut again. Shortcut will not work, IME will |
138 // either not appear or (worse) not disappear on ctrl-shift-space. | 138 // either not appear or (worse) not disappear on ctrl-shift-space. |
139 // (Run `ps aux | grep Chinese` (10.6/10.7) or `ps aux | grep Trackpad` | 139 // (Run `ps aux | grep Chinese` (10.6/10.7) or `ps aux | grep Trackpad` |
140 // and then kill that pid to make it go away.) | 140 // and then kill that pid to make it go away.) |
141 // | 141 // |
142 // Chinese Handwriting was introduced in 10.6 and is confirmed broken on | 142 // Chinese Handwriting was introduced in 10.6 and is confirmed broken on |
143 // 10.6, 10.7, and 10.8. | 143 // 10.6, 10.7, and 10.8. It's reportedly fixed on 10.9. |
144 mach_error_t err = mach_override_ptr( | 144 bool needs_ime_hack = !base::mac::IsOSLaterThanMountainLion_DontCallThis(); |
Bernhard Bauer
2013/02/28 13:50:26
Bwahaha
| |
145 (void*)&TISCreateInputSourceList, | |
146 (void*)&CrTISCreateInputSourceList, | |
147 NULL); | |
148 CHECK_EQ(err_none, err); | |
149 | 145 |
150 // Override the private CFLog function so that the console is not spammed | 146 if (needs_ime_hack) { |
151 // by TIS failing to connect to HIServices over XPC. | 147 mach_error_t err = mach_override_ptr( |
152 err = mach_override_ptr((void*)&CFLog, (void*)&CrRendererCFLog, NULL); | 148 (void*)&TISCreateInputSourceList, |
jamesr
2013/02/28 20:25:26
why the c-style casts?
| |
153 CHECK_EQ(err_none, err); | 149 (void*)&CrTISCreateInputSourceList, |
150 NULL); | |
151 CHECK_EQ(err_none, err); | |
152 | |
153 // Override the private CFLog function so that the console is not spammed | |
154 // by TIS failing to connect to HIServices over XPC. | |
155 err = mach_override_ptr((void*)&CFLog, (void*)&CrRendererCFLog, NULL); | |
156 CHECK_EQ(err_none, err); | |
157 } | |
154 | 158 |
155 // Enable the sandbox. | 159 // Enable the sandbox. |
156 bool sandbox_initialized = InitializeSandbox(); | 160 bool sandbox_initialized = InitializeSandbox(); |
157 | 161 |
158 // After the sandbox is initialized, call into TIS. Doing this before | 162 if (needs_ime_hack) { |
159 // the sandbox is in place will open up renderer access to the | 163 // After the sandbox is initialized, call into TIS. Doing this before |
160 // pasteboard and an XPC connection to "com.apple.hiservices-xpcservice". | 164 // the sandbox is in place will open up renderer access to the |
161 base::mac::ScopedCFTypeRef<TISInputSourceRef> layout_source( | 165 // pasteboard and an XPC connection to "com.apple.hiservices-xpcservice". |
162 TISCopyCurrentKeyboardLayoutInputSource()); | 166 base::mac::ScopedCFTypeRef<TISInputSourceRef> layout_source( |
163 base::mac::ScopedCFTypeRef<TISInputSourceRef> input_source( | 167 TISCopyCurrentKeyboardLayoutInputSource()); |
164 TISCopyCurrentKeyboardInputSource()); | 168 base::mac::ScopedCFTypeRef<TISInputSourceRef> input_source( |
169 TISCopyCurrentKeyboardInputSource()); | |
165 | 170 |
166 CFTypeRef source_list[] = { layout_source.get(), input_source.get() }; | 171 CFTypeRef source_list[] = { layout_source.get(), input_source.get() }; |
167 g_text_input_services_source_list_ = CFArrayCreate(kCFAllocatorDefault, | 172 g_text_input_services_source_list_ = CFArrayCreate(kCFAllocatorDefault, |
168 source_list, arraysize(source_list), &kCFTypeArrayCallBacks); | 173 source_list, arraysize(source_list), &kCFTypeArrayCallBacks); |
174 } | |
169 | 175 |
170 return sandbox_initialized; | 176 return sandbox_initialized; |
171 } | 177 } |
172 | 178 |
173 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { | 179 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { |
174 Class tests_runner = objc_getClass("RendererSandboxTestsRunner"); | 180 Class tests_runner = objc_getClass("RendererSandboxTestsRunner"); |
175 if (tests_runner) { | 181 if (tests_runner) { |
176 if (![tests_runner runTests]) | 182 if (![tests_runner runTests]) |
177 LOG(ERROR) << "Running renderer with failing sandbox tests!"; | 183 LOG(ERROR) << "Running renderer with failing sandbox tests!"; |
178 [sandbox_tests_bundle_ unload]; | 184 [sandbox_tests_bundle_ unload]; |
179 [sandbox_tests_bundle_ release]; | 185 [sandbox_tests_bundle_ release]; |
180 sandbox_tests_bundle_ = nil; | 186 sandbox_tests_bundle_ = nil; |
181 } | 187 } |
182 } | 188 } |
183 | 189 |
184 } // namespace content | 190 } // namespace content |
OLD | NEW |