Chromium Code Reviews| 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 #import "base/mac/mac_util.h" |
| 15 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
| 16 #include "base/strings/string_number_conversions.h" | |
| 16 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 17 #include "content/common/sandbox_mac.h" | 18 #include "content/common/sandbox_mac.h" |
| 18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 19 #import "content/public/common/injection_test_mac.h" | 20 #import "content/public/common/injection_test_mac.h" |
| 20 #include "content/common/sandbox_init_mac.h" | 21 #include "content/common/sandbox_init_mac.h" |
| 21 #include "third_party/mach_override/mach_override.h" | 22 #include "third_party/mach_override/mach_override.h" |
| 22 | 23 |
| 23 extern "C" { | 24 extern "C" { |
| 24 // SPI logging functions for CF that are exported externally. | 25 // SPI logging functions for CF that are exported externally. |
| 25 void CFLog(int32_t level, CFStringRef format, ...); | 26 void CFLog(int32_t level, CFStringRef format, ...); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 61 return; | 62 return; |
| 62 } | 63 } |
| 63 } | 64 } |
| 64 | 65 |
| 65 va_list args; | 66 va_list args; |
| 66 va_start(args, format); | 67 va_start(args, format); |
| 67 _CFLogvEx(NULL, NULL, NULL, level, format, args); | 68 _CFLogvEx(NULL, NULL, NULL, level, format, args); |
| 68 va_end(args); | 69 va_end(args); |
| 69 } | 70 } |
| 70 | 71 |
| 72 // You are about to read a pretty disgusting hack. In a static initializer, | |
| 73 // CoreFoundation decides to connect with cfprefsd(8) using Mach IPC. There is | |
| 74 // no public way to close this Mach port after-the-fact, nor a way to stop it | |
| 75 // from happening since it is done pre-main in dyld. But the address of the | |
| 76 // CFMachPort can be found in the run loop's string description. Below, that | |
| 77 // address is parsed, cast, and then used to invalidate the Mach port to | |
| 78 // disable communication with cfprefsd. | |
| 79 void DisconnectCFNotificationCenter() { | |
| 80 base::ScopedCFTypeRef<CFStringRef> description( | |
|
Mark Mentovai
2014/02/25 17:08:41
You also have port_description in this function. T
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 81 CFCopyDescription(CFRunLoopGetCurrent())); | |
|
Mark Mentovai
2014/02/25 17:08:41
A comment with the full contents of what this stri
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 82 const CFIndex length = CFStringGetLength(description); | |
| 83 for (CFIndex i = 0; i < length; ) { | |
| 84 // Find the start of a CFMachPort run loop source. | |
| 85 CFRange start_range; | |
|
Mark Mentovai
2014/02/25 17:08:41
There are a few different ranges in here. This one
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 86 if (!CFStringFindWithOptions(description, CFSTR("context = <CFMachPort "), | |
| 87 CFRangeMake(i, length - i), 0, &start_range)) { | |
| 88 break; | |
| 89 } | |
| 90 i = start_range.location + start_range.length; | |
| 91 | |
| 92 // The address of the CFMachPort is the first hexadecimal address after the | |
| 93 // CF type name. | |
| 94 CFRange address_range = CFRangeMake(i, 0); | |
| 95 for (CFIndex j = start_range.location; i < length - j; ++j) { | |
|
Mark Mentovai
2014/02/25 17:08:41
“i is less than length minus j”
Do you think that
Robert Sesek
2014/02/25 17:56:30
Wow that was doltish of me. This is the problem wi
| |
| 96 UniChar c = CFStringGetCharacterAtIndex(description, j); | |
| 97 ++address_range.length; | |
|
Mark Mentovai
2014/02/25 17:08:41
Don’t you want to do this after breaking on ' '?
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 98 if (c == ' ') | |
|
Mark Mentovai
2014/02/25 17:08:41
If you never found the space, you might have a tru
Robert Sesek
2014/02/25 17:56:30
I don't think this condition is likely at all, and
| |
| 99 break; | |
| 100 } | |
| 101 | |
| 102 // The address is a hexadecimal string. | |
| 103 if (address_range.length < 1) | |
|
Mark Mentovai
2014/02/25 17:08:41
If you passed through the loop above at all, even
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 104 continue; | |
| 105 | |
| 106 base::ScopedCFTypeRef<CFStringRef> address_string( | |
| 107 CFStringCreateWithSubstring(NULL, description, address_range)); | |
| 108 if (!address_string) | |
| 109 continue; | |
| 110 | |
| 111 // Convert the string to an address. | |
| 112 std::string address_std_string = base::SysCFStringRefToUTF8(address_string); | |
| 113 uint64 address = 0; | |
|
Mark Mentovai
2014/02/25 17:08:41
Marginal preference for
#if __LP64__
// this th
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 114 if (!base::HexStringToUInt64(address_std_string, &address)) | |
| 115 continue; | |
| 116 | |
| 117 // Cast the address to an object. | |
| 118 CFMachPortRef mach_port = reinterpret_cast<CFMachPortRef>(address); | |
|
Mark Mentovai
2014/02/25 17:08:41
if (CFGetTypeID(mach_port) != CFMachPortGetTypeID(
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 119 | |
| 120 // Verify that this is the Mach port that needs to be disconnected by the | |
| 121 // name of its callout function. | |
| 122 base::ScopedCFTypeRef<CFStringRef> port_description( | |
| 123 CFCopyDescription(mach_port)); | |
|
Mark Mentovai
2014/02/25 17:08:41
Contents comment for this one too?
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 124 if (CFStringFindWithOptions(port_description, | |
| 125 CFSTR("callout = __CFXNotificationReceiveFromServer"), | |
|
Mark Mentovai
2014/02/25 17:08:41
Anchor this string with a trailing space.
Maybe e
Robert Sesek
2014/02/25 17:56:30
Done.
| |
| 126 CFRangeMake(0, CFStringGetLength(port_description)), | |
| 127 0, | |
| 128 NULL)) { | |
| 129 CFMachPortInvalidate(mach_port); | |
| 130 return; | |
| 131 } | |
| 132 } | |
| 133 } | |
| 134 | |
| 71 } // namespace | 135 } // namespace |
| 72 | 136 |
| 73 RendererMainPlatformDelegate::RendererMainPlatformDelegate( | 137 RendererMainPlatformDelegate::RendererMainPlatformDelegate( |
| 74 const MainFunctionParams& parameters) | 138 const MainFunctionParams& parameters) |
| 75 : parameters_(parameters) { | 139 : parameters_(parameters) { |
| 76 } | 140 } |
| 77 | 141 |
| 78 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { | 142 RendererMainPlatformDelegate::~RendererMainPlatformDelegate() { |
| 79 } | 143 } |
| 80 | 144 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 base::ScopedCFTypeRef<TISInputSourceRef> layout_source( | 230 base::ScopedCFTypeRef<TISInputSourceRef> layout_source( |
| 167 TISCopyCurrentKeyboardLayoutInputSource()); | 231 TISCopyCurrentKeyboardLayoutInputSource()); |
| 168 base::ScopedCFTypeRef<TISInputSourceRef> input_source( | 232 base::ScopedCFTypeRef<TISInputSourceRef> input_source( |
| 169 TISCopyCurrentKeyboardInputSource()); | 233 TISCopyCurrentKeyboardInputSource()); |
| 170 | 234 |
| 171 CFTypeRef source_list[] = { layout_source.get(), input_source.get() }; | 235 CFTypeRef source_list[] = { layout_source.get(), input_source.get() }; |
| 172 g_text_input_services_source_list_ = CFArrayCreate(kCFAllocatorDefault, | 236 g_text_input_services_source_list_ = CFArrayCreate(kCFAllocatorDefault, |
| 173 source_list, arraysize(source_list), &kCFTypeArrayCallBacks); | 237 source_list, arraysize(source_list), &kCFTypeArrayCallBacks); |
| 174 } | 238 } |
| 175 | 239 |
| 240 DisconnectCFNotificationCenter(); | |
| 241 | |
| 176 return sandbox_initialized; | 242 return sandbox_initialized; |
| 177 } | 243 } |
| 178 | 244 |
| 179 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { | 245 void RendererMainPlatformDelegate::RunSandboxTests(bool no_sandbox) { |
| 180 Class tests_runner = objc_getClass("RendererSandboxTestsRunner"); | 246 Class tests_runner = objc_getClass("RendererSandboxTestsRunner"); |
| 181 if (tests_runner) { | 247 if (tests_runner) { |
| 182 if (![tests_runner runTests]) | 248 if (![tests_runner runTests]) |
| 183 LOG(ERROR) << "Running renderer with failing sandbox tests!"; | 249 LOG(ERROR) << "Running renderer with failing sandbox tests!"; |
| 184 [sandbox_tests_bundle_ unload]; | 250 [sandbox_tests_bundle_ unload]; |
| 185 [sandbox_tests_bundle_ release]; | 251 [sandbox_tests_bundle_ release]; |
| 186 sandbox_tests_bundle_ = nil; | 252 sandbox_tests_bundle_ = nil; |
| 187 } | 253 } |
| 188 } | 254 } |
| 189 | 255 |
| 190 } // namespace content | 256 } // namespace content |
| OLD | NEW |