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
3 // found in the LICENSE file.
5 #include "base/mac/mac_util.h"
7 #import <Cocoa/Cocoa.h>
8 #import <IOKit/IOKitLib.h>
12 #include <sys/utsname.h>
13 #include <sys/xattr.h>
15 #include "base/files/file_path.h"
16 #include "base/logging.h"
17 #include "base/mac/bundle_locations.h"
18 #include "base/mac/foundation_util.h"
19 #include "base/mac/mac_logging.h"
20 #include "base/mac/scoped_cftyperef.h"
21 #include "base/mac/scoped_ioobject.h"
22 #include "base/mac/scoped_nsobject.h"
23 #include "base/strings/string_number_conversions.h"
24 #include "base/strings/string_piece.h"
25 #include "base/strings/sys_string_conversions.h"
30 // Replicate specific 10.7 SDK declarations for building with prior SDKs.
31 #if !defined(MAC_OS_X_VERSION_10_7) || \
32 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
35 NSApplicationPresentationFullScreen = 1 << 10
38 #endif // MAC_OS_X_VERSION_10_7
42 // The current count of outstanding requests for full screen mode from browser
43 // windows, plugins, etc.
44 int g_full_screen_requests[kNumFullScreenModes] = { 0 };
46 // Sets the appropriate application presentation option based on the current
47 // full screen requests. Since only one presentation option can be active at a
48 // given time, full screen requests are ordered by priority. If there are no
49 // outstanding full screen requests, reverts to normal mode. If the correct
50 // presentation option is already set, does nothing.
52 NSApplicationPresentationOptions current_options =
53 [NSApp presentationOptions];
55 // Determine which mode should be active, based on which requests are
56 // currently outstanding. More permissive requests take precedence. For
57 // example, plugins request |kFullScreenModeAutoHideAll|, while browser
58 // windows request |kFullScreenModeHideDock| when the fullscreen overlay is
59 // down. Precedence goes to plugins in this case, so AutoHideAll wins over
61 NSApplicationPresentationOptions desired_options =
62 NSApplicationPresentationDefault;
63 if (g_full_screen_requests[kFullScreenModeAutoHideAll] > 0) {
64 desired_options = NSApplicationPresentationHideDock |
65 NSApplicationPresentationAutoHideMenuBar;
66 } else if (g_full_screen_requests[kFullScreenModeHideDock] > 0) {
67 desired_options = NSApplicationPresentationHideDock;
68 } else if (g_full_screen_requests[kFullScreenModeHideAll] > 0) {
69 desired_options = NSApplicationPresentationHideDock |
70 NSApplicationPresentationHideMenuBar;
73 // Mac OS X bug: if the window is fullscreened (Lion-style) and
74 // NSApplicationPresentationDefault is requested, the result is that the menu
75 // bar doesn't auto-hide. rdar://13576498 http://www.openradar.me/13576498
77 // As a workaround, in that case, explicitly set the presentation options to
78 // the ones that are set by the system as it fullscreens a window.
79 if (desired_options == NSApplicationPresentationDefault &&
80 current_options & NSApplicationPresentationFullScreen) {
81 desired_options |= NSApplicationPresentationFullScreen |
82 NSApplicationPresentationAutoHideMenuBar |
83 NSApplicationPresentationAutoHideDock;
86 if (current_options != desired_options)
87 [NSApp setPresentationOptions:desired_options];
90 // Looks into Shared File Lists corresponding to Login Items for the item
91 // representing the current application. If such an item is found, returns a
92 // retained reference to it. Caller is responsible for releasing the reference.
93 LSSharedFileListItemRef GetLoginItemForApp() {
94 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate(
95 NULL, kLSSharedFileListSessionLoginItems, NULL));
97 if (!login_items.get()) {
98 DLOG(ERROR) << "Couldn't get a Login Items list.";
102 base::scoped_nsobject<NSArray> login_items_array(
103 CFToNSCast(LSSharedFileListCopySnapshot(login_items, NULL)));
105 NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]];
107 for(NSUInteger i = 0; i < [login_items_array count]; ++i) {
108 LSSharedFileListItemRef item = reinterpret_cast<LSSharedFileListItemRef>(
109 [login_items_array objectAtIndex:i]);
110 CFURLRef item_url_ref = NULL;
112 if (LSSharedFileListItemResolve(item, 0, &item_url_ref, NULL) == noErr) {
113 ScopedCFTypeRef<CFURLRef> item_url(item_url_ref);
114 if (CFEqual(item_url, url)) {
124 bool IsHiddenLoginItem(LSSharedFileListItemRef item) {
125 ScopedCFTypeRef<CFBooleanRef> hidden(reinterpret_cast<CFBooleanRef>(
126 LSSharedFileListItemCopyProperty(item,
127 reinterpret_cast<CFStringRef>(kLSSharedFileListLoginItemHidden))));
129 return hidden && hidden == kCFBooleanTrue;
134 std::string PathFromFSRef(const FSRef& ref) {
135 ScopedCFTypeRef<CFURLRef> url(
136 CFURLCreateFromFSRef(kCFAllocatorDefault, &ref));
137 NSString *path_string = [(NSURL *)url.get() path];
138 return [path_string fileSystemRepresentation];
141 bool FSRefFromPath(const std::string& path, FSRef* ref) {
142 OSStatus status = FSPathMakeRef((const UInt8*)path.c_str(),
144 return status == noErr;
147 CGColorSpaceRef GetGenericRGBColorSpace() {
148 // Leaked. That's OK, it's scoped to the lifetime of the application.
149 static CGColorSpaceRef g_color_space_generic_rgb(
150 CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB));
151 DLOG_IF(ERROR, !g_color_space_generic_rgb) <<
152 "Couldn't get the generic RGB color space";
153 return g_color_space_generic_rgb;
156 CGColorSpaceRef GetSRGBColorSpace() {
157 // Leaked. That's OK, it's scoped to the lifetime of the application.
158 static CGColorSpaceRef g_color_space_sRGB =
159 CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
160 DLOG_IF(ERROR, !g_color_space_sRGB) << "Couldn't get the sRGB color space";
161 return g_color_space_sRGB;
164 CGColorSpaceRef GetSystemColorSpace() {
165 // Leaked. That's OK, it's scoped to the lifetime of the application.
166 // Try to get the main display's color space.
167 static CGColorSpaceRef g_system_color_space =
168 CGDisplayCopyColorSpace(CGMainDisplayID());
170 if (!g_system_color_space) {
171 // Use a generic RGB color space. This is better than nothing.
172 g_system_color_space = CGColorSpaceCreateDeviceRGB();
174 if (g_system_color_space) {
176 "Couldn't get the main display's color space, using generic";
178 DLOG(ERROR) << "Couldn't get any color space";
182 return g_system_color_space;
185 // Add a request for full screen mode. Must be called on the main thread.
186 void RequestFullScreen(FullScreenMode mode) {
187 DCHECK_LT(mode, kNumFullScreenModes);
188 if (mode >= kNumFullScreenModes)
191 DCHECK_GE(g_full_screen_requests[mode], 0);
195 g_full_screen_requests[mode] = std::max(g_full_screen_requests[mode] + 1, 1);
199 // Release a request for full screen mode. Must be called on the main thread.
200 void ReleaseFullScreen(FullScreenMode mode) {
201 DCHECK_LT(mode, kNumFullScreenModes);
202 if (mode >= kNumFullScreenModes)
205 DCHECK_GE(g_full_screen_requests[mode], 0);
209 g_full_screen_requests[mode] = std::max(g_full_screen_requests[mode] - 1, 0);
213 // Switches full screen modes. Releases a request for |from_mode| and adds a
214 // new request for |to_mode|. Must be called on the main thread.
215 void SwitchFullScreenModes(FullScreenMode from_mode, FullScreenMode to_mode) {
216 DCHECK_LT(from_mode, kNumFullScreenModes);
217 DCHECK_LT(to_mode, kNumFullScreenModes);
218 if (from_mode >= kNumFullScreenModes || to_mode >= kNumFullScreenModes)
221 DCHECK_GT(g_full_screen_requests[from_mode], 0);
222 DCHECK_GE(g_full_screen_requests[to_mode], 0);
223 g_full_screen_requests[from_mode] =
224 std::max(g_full_screen_requests[from_mode] - 1, 0);
225 g_full_screen_requests[to_mode] =
226 std::max(g_full_screen_requests[to_mode] + 1, 1);
230 void SetCursorVisibility(bool visible) {
237 bool ShouldWindowsMiniaturizeOnDoubleClick() {
238 // We use an undocumented method in Cocoa; if it doesn't exist, default to
239 // |true|. If it ever goes away, we can do (using an undocumented pref key):
240 // NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
241 // return ![defaults objectForKey:@"AppleMiniaturizeOnDoubleClick"] ||
242 // [defaults boolForKey:@"AppleMiniaturizeOnDoubleClick"];
243 BOOL methodImplemented =
244 [NSWindow respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)];
245 DCHECK(methodImplemented);
246 return !methodImplemented ||
247 [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)];
250 void ActivateProcess(pid_t pid) {
251 ProcessSerialNumber process;
252 OSStatus status = GetProcessForPID(pid, &process);
253 if (status == noErr) {
254 SetFrontProcess(&process);
256 OSSTATUS_DLOG(WARNING, status) << "Unable to get process for pid " << pid;
260 bool AmIForeground() {
261 ProcessSerialNumber foreground_psn = { 0 };
262 OSErr err = GetFrontProcess(&foreground_psn);
264 OSSTATUS_DLOG(WARNING, err) << "GetFrontProcess";
268 ProcessSerialNumber my_psn = { 0, kCurrentProcess };
270 Boolean result = FALSE;
271 err = SameProcess(&foreground_psn, &my_psn, &result);
273 OSSTATUS_DLOG(WARNING, err) << "SameProcess";
280 bool SetFileBackupExclusion(const FilePath& file_path) {
281 NSString* file_path_ns =
282 [NSString stringWithUTF8String:file_path.value().c_str()];
283 NSURL* file_url = [NSURL fileURLWithPath:file_path_ns];
285 // When excludeByPath is true the application must be running with root
286 // privileges (admin for 10.6 and earlier) but the URL does not have to
287 // already exist. When excludeByPath is false the URL must already exist but
288 // can be used in non-root (or admin as above) mode. We use false so that
289 // non-root (or admin) users don't get their TimeMachine drive filled up with
290 // unnecessary backups.
292 CSBackupSetItemExcluded(base::mac::NSToCFCast(file_url), TRUE, FALSE);
293 if (os_err != noErr) {
294 OSSTATUS_DLOG(WARNING, os_err)
295 << "Failed to set backup exclusion for file '"
296 << file_path.value().c_str() << "'";
298 return os_err == noErr;
301 void SetProcessName(CFStringRef process_name) {
302 if (!process_name || CFStringGetLength(process_name) == 0) {
303 NOTREACHED() << "SetProcessName given bad name.";
307 if (![NSThread isMainThread]) {
308 NOTREACHED() << "Should only set process name from main thread.";
312 // Warning: here be dragons! This is SPI reverse-engineered from WebKit's
313 // plugin host, and could break at any time (although realistically it's only
314 // likely to break in a new major release).
315 // When 10.7 is available, check that this still works, and update this
318 // Private CFType used in these LaunchServices calls.
319 typedef CFTypeRef PrivateLSASN;
320 typedef PrivateLSASN (*LSGetCurrentApplicationASNType)();
321 typedef OSStatus (*LSSetApplicationInformationItemType)(int, PrivateLSASN,
326 static LSGetCurrentApplicationASNType ls_get_current_application_asn_func =
328 static LSSetApplicationInformationItemType
329 ls_set_application_information_item_func = NULL;
330 static CFStringRef ls_display_name_key = NULL;
332 static bool did_symbol_lookup = false;
333 if (!did_symbol_lookup) {
334 did_symbol_lookup = true;
335 CFBundleRef launch_services_bundle =
336 CFBundleGetBundleWithIdentifier(CFSTR("com.apple.LaunchServices"));
337 if (!launch_services_bundle) {
338 DLOG(ERROR) << "Failed to look up LaunchServices bundle";
342 ls_get_current_application_asn_func =
343 reinterpret_cast<LSGetCurrentApplicationASNType>(
344 CFBundleGetFunctionPointerForName(
345 launch_services_bundle, CFSTR("_LSGetCurrentApplicationASN")));
346 if (!ls_get_current_application_asn_func)
347 DLOG(ERROR) << "Could not find _LSGetCurrentApplicationASN";
349 ls_set_application_information_item_func =
350 reinterpret_cast<LSSetApplicationInformationItemType>(
351 CFBundleGetFunctionPointerForName(
352 launch_services_bundle,
353 CFSTR("_LSSetApplicationInformationItem")));
354 if (!ls_set_application_information_item_func)
355 DLOG(ERROR) << "Could not find _LSSetApplicationInformationItem";
357 CFStringRef* key_pointer = reinterpret_cast<CFStringRef*>(
358 CFBundleGetDataPointerForName(launch_services_bundle,
359 CFSTR("_kLSDisplayNameKey")));
360 ls_display_name_key = key_pointer ? *key_pointer : NULL;
361 if (!ls_display_name_key)
362 DLOG(ERROR) << "Could not find _kLSDisplayNameKey";
364 // Internally, this call relies on the Mach ports that are started up by the
365 // Carbon Process Manager. In debug builds this usually happens due to how
366 // the logging layers are started up; but in release, it isn't started in as
367 // much of a defined order. So if the symbols had to be loaded, go ahead
368 // and force a call to make sure the manager has been initialized and hence
369 // the ports are opened.
370 ProcessSerialNumber psn;
371 GetCurrentProcess(&psn);
373 if (!ls_get_current_application_asn_func ||
374 !ls_set_application_information_item_func ||
375 !ls_display_name_key) {
379 PrivateLSASN asn = ls_get_current_application_asn_func();
380 // Constant used by WebKit; what exactly it means is unknown.
381 const int magic_session_constant = -2;
383 ls_set_application_information_item_func(magic_session_constant, asn,
386 NULL /* optional out param */);
387 OSSTATUS_DLOG_IF(ERROR, err != noErr, err)
388 << "Call to set process name failed";
391 // Converts a NSImage to a CGImageRef. Normally, the system frameworks can do
392 // this fine, especially on 10.6. On 10.5, however, CGImage cannot handle
393 // converting a PDF-backed NSImage into a CGImageRef. This function will
394 // rasterize the PDF into a bitmap CGImage. The caller is responsible for
395 // releasing the return value.
396 CGImageRef CopyNSImageToCGImage(NSImage* image) {
397 // This is based loosely on http://www.cocoadev.com/index.pl?CGImageRef .
398 NSSize size = [image size];
399 ScopedCFTypeRef<CGContextRef> context(
400 CGBitmapContextCreate(NULL, // Allow CG to allocate memory.
403 8, // bitsPerComponent
404 0, // bytesPerRow - CG will calculate by default.
405 [[NSColorSpace genericRGBColorSpace] CGColorSpace],
406 kCGBitmapByteOrder32Host |
407 kCGImageAlphaPremultipliedFirst));
411 [NSGraphicsContext saveGraphicsState];
412 [NSGraphicsContext setCurrentContext:
413 [NSGraphicsContext graphicsContextWithGraphicsPort:context.get()
415 [image drawInRect:NSMakeRect(0,0, size.width, size.height)
417 operation:NSCompositeCopy
419 [NSGraphicsContext restoreGraphicsState];
421 return CGBitmapContextCreateImage(context);
424 bool CheckLoginItemStatus(bool* is_hidden) {
425 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp());
430 *is_hidden = IsHiddenLoginItem(item);
435 void AddToLoginItems(bool hide_on_startup) {
436 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp());
437 if (item.get() && (IsHiddenLoginItem(item) == hide_on_startup)) {
438 return; // Already is a login item with required hide flag.
441 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate(
442 NULL, kLSSharedFileListSessionLoginItems, NULL));
444 if (!login_items.get()) {
445 DLOG(ERROR) << "Couldn't get a Login Items list.";
449 // Remove the old item, it has wrong hide flag, we'll create a new one.
451 LSSharedFileListItemRemove(login_items, item);
454 NSURL* url = [NSURL fileURLWithPath:[base::mac::MainBundle() bundlePath]];
456 BOOL hide = hide_on_startup ? YES : NO;
457 NSDictionary* properties =
459 dictionaryWithObject:[NSNumber numberWithBool:hide]
460 forKey:(NSString*)kLSSharedFileListLoginItemHidden];
462 ScopedCFTypeRef<LSSharedFileListItemRef> new_item;
463 new_item.reset(LSSharedFileListInsertItemURL(
464 login_items, kLSSharedFileListItemLast, NULL, NULL,
465 reinterpret_cast<CFURLRef>(url),
466 reinterpret_cast<CFDictionaryRef>(properties), NULL));
468 if (!new_item.get()) {
469 DLOG(ERROR) << "Couldn't insert current app into Login Items list.";
473 void RemoveFromLoginItems() {
474 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp());
478 ScopedCFTypeRef<LSSharedFileListRef> login_items(LSSharedFileListCreate(
479 NULL, kLSSharedFileListSessionLoginItems, NULL));
481 if (!login_items.get()) {
482 DLOG(ERROR) << "Couldn't get a Login Items list.";
486 LSSharedFileListItemRemove(login_items, item);
489 bool WasLaunchedAsLoginOrResumeItem() {
490 ProcessSerialNumber psn = { 0, kCurrentProcess };
492 base::scoped_nsobject<NSDictionary> process_info(
493 CFToNSCast(ProcessInformationCopyDictionary(
494 &psn, kProcessDictionaryIncludeAllInformationMask)));
496 long long temp = [[process_info objectForKey:@"ParentPSN"] longLongValue];
497 ProcessSerialNumber parent_psn =
498 { (temp >> 32) & 0x00000000FFFFFFFFLL, temp & 0x00000000FFFFFFFFLL };
500 base::scoped_nsobject<NSDictionary> parent_info(
501 CFToNSCast(ProcessInformationCopyDictionary(
502 &parent_psn, kProcessDictionaryIncludeAllInformationMask)));
504 // Check that creator process code is that of loginwindow.
506 [[parent_info objectForKey:@"FileCreator"] isEqualToString:@"lgnw"];
508 return result == YES;
511 bool WasLaunchedAsHiddenLoginItem() {
512 if (!WasLaunchedAsLoginOrResumeItem())
515 ScopedCFTypeRef<LSSharedFileListItemRef> item(GetLoginItemForApp());
517 // Lion can launch items for the resume feature. So log an error only for
518 // Snow Leopard or earlier.
519 if (IsOSSnowLeopard())
521 "Process launched at Login but can't access Login Item List.";
525 return IsHiddenLoginItem(item);
528 bool RemoveQuarantineAttribute(const FilePath& file_path) {
529 const char kQuarantineAttrName[] = "com.apple.quarantine";
530 int status = removexattr(file_path.value().c_str(), kQuarantineAttrName, 0);
531 return status == 0 || errno == ENOATTR;
536 // Returns the running system's Darwin major version. Don't call this, it's
537 // an implementation detail and its result is meant to be cached by
538 // MacOSXMinorVersion.
539 int DarwinMajorVersionInternal() {
540 // base::OperatingSystemVersionNumbers calls Gestalt, which is a
541 // higher-level operation than is needed. It might perform unnecessary
542 // operations. On 10.6, it was observed to be able to spawn threads (see
543 // http://crbug.com/53200). It might also read files or perform other
544 // blocking operations. Actually, nobody really knows for sure just what
545 // Gestalt might do, or what it might be taught to do in the future.
547 // uname, on the other hand, is implemented as a simple series of sysctl
548 // system calls to obtain the relevant data from the kernel. The data is
549 // compiled right into the kernel, so no threads or blocking or other
550 // funny business is necessary.
552 struct utsname uname_info;
553 if (uname(&uname_info) != 0) {
554 DPLOG(ERROR) << "uname";
558 if (strcmp(uname_info.sysname, "Darwin") != 0) {
559 DLOG(ERROR) << "unexpected uname sysname " << uname_info.sysname;
563 int darwin_major_version = 0;
564 char* dot = strchr(uname_info.release, '.');
566 if (!base::StringToInt(base::StringPiece(uname_info.release,
567 dot - uname_info.release),
568 &darwin_major_version)) {
574 DLOG(ERROR) << "could not parse uname release " << uname_info.release;
578 return darwin_major_version;
581 // Returns the running system's Mac OS X minor version. This is the |y| value
582 // in 10.y or 10.y.z. Don't call this, it's an implementation detail and the
583 // result is meant to be cached by MacOSXMinorVersion.
584 int MacOSXMinorVersionInternal() {
585 int darwin_major_version = DarwinMajorVersionInternal();
587 // The Darwin major version is always 4 greater than the Mac OS X minor
588 // version for Darwin versions beginning with 6, corresponding to Mac OS X
589 // 10.2. Since this correspondence may change in the future, warn when
590 // encountering a version higher than anything seen before. Older Darwin
591 // versions, or versions that can't be determined, result in
593 CHECK(darwin_major_version >= 6);
594 int mac_os_x_minor_version = darwin_major_version - 4;
595 DLOG_IF(WARNING, darwin_major_version > 12) << "Assuming Darwin "
596 << base::IntToString(darwin_major_version) << " is Mac OS X 10."
597 << base::IntToString(mac_os_x_minor_version);
599 return mac_os_x_minor_version;
602 // Returns the running system's Mac OS X minor version. This is the |y| value
603 // in 10.y or 10.y.z.
604 int MacOSXMinorVersion() {
605 static int mac_os_x_minor_version = MacOSXMinorVersionInternal();
606 return mac_os_x_minor_version;
610 SNOW_LEOPARD_MINOR_VERSION = 6,
611 LION_MINOR_VERSION = 7,
612 MOUNTAIN_LION_MINOR_VERSION = 8,
617 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_7)
618 bool IsOSSnowLeopard() {
619 return MacOSXMinorVersion() == SNOW_LEOPARD_MINOR_VERSION;
623 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7)
625 return MacOSXMinorVersion() == LION_MINOR_VERSION;
629 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7)
630 bool IsOSLionOrEarlier() {
631 return MacOSXMinorVersion() <= LION_MINOR_VERSION;
635 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_7)
636 bool IsOSLionOrLater() {
637 return MacOSXMinorVersion() >= LION_MINOR_VERSION;
641 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_8)
642 bool IsOSMountainLion() {
643 return MacOSXMinorVersion() == MOUNTAIN_LION_MINOR_VERSION;
647 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GE_10_8)
648 bool IsOSMountainLionOrLater() {
649 return MacOSXMinorVersion() >= MOUNTAIN_LION_MINOR_VERSION;
653 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_8)
654 bool IsOSLaterThanMountainLion_DontCallThis() {
655 return MacOSXMinorVersion() > MOUNTAIN_LION_MINOR_VERSION;
659 std::string GetModelIdentifier() {
660 std::string return_string;
661 ScopedIOObject<io_service_t> platform_expert(
662 IOServiceGetMatchingService(kIOMasterPortDefault,
663 IOServiceMatching("IOPlatformExpertDevice")));
664 if (platform_expert) {
665 ScopedCFTypeRef<CFDataRef> model_data(
666 static_cast<CFDataRef>(IORegistryEntryCreateCFProperty(
673 reinterpret_cast<const char*>(CFDataGetBytePtr(model_data));
676 return return_string;
679 bool ParseModelIdentifier(const std::string& ident,
683 size_t number_loc = ident.find_first_of("0123456789");
684 if (number_loc == std::string::npos)
686 size_t comma_loc = ident.find(',', number_loc);
687 if (comma_loc == std::string::npos)
689 int32 major_tmp, minor_tmp;
690 std::string::const_iterator begin = ident.begin();
692 StringPiece(begin + number_loc, begin + comma_loc), &major_tmp) ||
694 StringPiece(begin + comma_loc + 1, ident.end()), &minor_tmp))
696 *type = ident.substr(0, number_loc);