OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/mac/mac_util.h" | 5 #include "base/mac/mac_util.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <sys/sysctl.h> // sysctlbyname() | |
9 #include <sys/utsname.h> | 10 #include <sys/utsname.h> |
10 | 11 |
11 #include "base/file_path.h" | 12 #include "base/file_path.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
14 #include "base/mac/scoped_cftyperef.h" | 15 #include "base/mac/scoped_cftyperef.h" |
15 #include "base/memory/scoped_nsobject.h" | 16 #include "base/memory/scoped_nsobject.h" |
16 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
18 #include "base/string_util.h" | |
19 #include "base/sys_info.h" | |
17 #include "base/sys_string_conversions.h" | 20 #include "base/sys_string_conversions.h" |
18 | 21 |
19 namespace base { | 22 namespace base { |
20 namespace mac { | 23 namespace mac { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 // The current count of outstanding requests for full screen mode from browser | 27 // The current count of outstanding requests for full screen mode from browser |
25 // windows, plugins, etc. | 28 // windows, plugins, etc. |
26 int g_full_screen_requests[kNumFullScreenModes] = { 0, 0, 0}; | 29 int g_full_screen_requests[kNumFullScreenModes] = { 0, 0, 0}; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 // Constant used by WebKit; what exactly it means is unknown. | 348 // Constant used by WebKit; what exactly it means is unknown. |
346 const int magic_session_constant = -2; | 349 const int magic_session_constant = -2; |
347 OSErr err = | 350 OSErr err = |
348 ls_set_application_information_item_func(magic_session_constant, asn, | 351 ls_set_application_information_item_func(magic_session_constant, asn, |
349 ls_display_name_key, | 352 ls_display_name_key, |
350 process_name, | 353 process_name, |
351 NULL /* optional out param */); | 354 NULL /* optional out param */); |
352 LOG_IF(ERROR, err) << "Call to set process name failed, err " << err; | 355 LOG_IF(ERROR, err) << "Call to set process name failed, err " << err; |
353 } | 356 } |
354 | 357 |
358 std::string GetHardwareModelName() { | |
359 char modelBuffer[256]; | |
360 size_t length = sizeof(modelBuffer); | |
361 if (!sysctlbyname("hw.model", modelBuffer, &length, NULL, 0)) { | |
362 for (size_t i = 0; i < length; i++) { | |
363 if (IsAsciiDigit(modelBuffer[i])) { | |
364 return std::string(modelBuffer, 0, i); | |
365 } | |
366 } | |
367 return std::string(modelBuffer, 0, length); | |
368 } else { | |
369 return "Unknown"; | |
370 } | |
Nico
2011/08/31 03:55:50
Don't you want [[NSHost currentHost] localizedName
Nico
2011/08/31 03:58:22
(If so, you'll probably need some kind of fallback
Yaron
2011/08/31 23:23:22
No the thinking was that people identify their com
Nico
2011/08/31 23:27:13
That string usually looks like "Nico Weber's MacBo
Yaron
2011/09/01 20:16:17
Ah, ok, fair enough. Added that for 10.6 and left
| |
371 } | |
372 | |
355 // Converts a NSImage to a CGImageRef. Normally, the system frameworks can do | 373 // Converts a NSImage to a CGImageRef. Normally, the system frameworks can do |
356 // this fine, especially on 10.6. On 10.5, however, CGImage cannot handle | 374 // this fine, especially on 10.6. On 10.5, however, CGImage cannot handle |
357 // converting a PDF-backed NSImage into a CGImageRef. This function will | 375 // converting a PDF-backed NSImage into a CGImageRef. This function will |
358 // rasterize the PDF into a bitmap CGImage. The caller is responsible for | 376 // rasterize the PDF into a bitmap CGImage. The caller is responsible for |
359 // releasing the return value. | 377 // releasing the return value. |
360 CGImageRef CopyNSImageToCGImage(NSImage* image) { | 378 CGImageRef CopyNSImageToCGImage(NSImage* image) { |
361 // This is based loosely on http://www.cocoadev.com/index.pl?CGImageRef . | 379 // This is based loosely on http://www.cocoadev.com/index.pl?CGImageRef . |
362 NSSize size = [image size]; | 380 NSSize size = [image size]; |
363 ScopedCFTypeRef<CGContextRef> context( | 381 ScopedCFTypeRef<CGContextRef> context( |
364 CGBitmapContextCreate(NULL, // Allow CG to allocate memory. | 382 CGBitmapContextCreate(NULL, // Allow CG to allocate memory. |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 #endif | 631 #endif |
614 | 632 |
615 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7) | 633 #if !defined(BASE_MAC_MAC_UTIL_H_INLINED_GT_10_7) |
616 bool IsOSLaterThanLion() { | 634 bool IsOSLaterThanLion() { |
617 return MacOSXMinorVersion() > LION_MINOR_VERSION; | 635 return MacOSXMinorVersion() > LION_MINOR_VERSION; |
618 } | 636 } |
619 #endif | 637 #endif |
620 | 638 |
621 } // namespace mac | 639 } // namespace mac |
622 } // namespace base | 640 } // namespace base |
OLD | NEW |