OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "config.h" | 5 #import "config.h" |
6 #import "platform/mac/VersionUtilMac.h" | 6 #import "platform/mac/VersionUtilMac.h" |
7 | 7 |
8 #import <AppKit/AppKit.h> | 8 #include <sstream> |
| 9 #include <string> |
| 10 #include <sys/utsname.h> |
9 | 11 |
10 #ifndef NSAppKitVersionNumber10_9 | 12 namespace { |
11 #define NSAppKitVersionNumber10_9 1265 | 13 |
12 #endif | 14 // Returns the running system's Darwin major version. Don't call this, it's |
| 15 // an implementation detail and its result is meant to be cached by |
| 16 // MacOSXMinorVersion. |
| 17 int DarwinMajorVersionInternal() |
| 18 { |
| 19 // The implementation of this method was copied from Chromium, with minor |
| 20 // modifications to avoid the use of methods in base/. For further details, |
| 21 // see |
| 22 // https://code.google.com/p/chromium/codesearch#chromium/src/base/mac/mac_u
til.mm |
| 23 struct utsname unameInfo; |
| 24 if (uname(&unameInfo) != 0) |
| 25 return 0; |
| 26 |
| 27 if (strcmp(unameInfo.sysname, "Darwin") != 0) |
| 28 return 0; |
| 29 |
| 30 std::string releaseString(unameInfo.release); |
| 31 size_t pos = releaseString.find_first_of('.'); |
| 32 if (pos == std::string::npos) |
| 33 return 0; |
| 34 |
| 35 std::istringstream convert(releaseString.substr(0, pos)); |
| 36 int majorVersion; |
| 37 if (!(convert >> majorVersion)) |
| 38 return 0; |
| 39 |
| 40 return majorVersion; |
| 41 } |
| 42 |
| 43 // Returns the running system's Mac OS X minor version. This is the |y| value |
| 44 // in 10.y or 10.y.z. Don't call this, it's an implementation detail and the |
| 45 // result is meant to be cached by MacOSXMinorVersion. |
| 46 int MacOSXMinorVersionInternal() |
| 47 { |
| 48 int darwinMajorVersion = DarwinMajorVersionInternal(); |
| 49 return darwinMajorVersion - 4; |
| 50 } |
| 51 |
| 52 // Returns the running system's Mac OS X minor version. This is the |y| value |
| 53 // in 10.y or 10.y.z. |
| 54 int MacOSXMinorVersion() |
| 55 { |
| 56 static int minorVersion = MacOSXMinorVersionInternal(); |
| 57 return minorVersion; |
| 58 } |
| 59 |
| 60 enum { |
| 61 LION_MINOR_VERSION = 7, |
| 62 MAVERICKS_MINOR_VERSION = 9, |
| 63 }; |
| 64 |
| 65 } // namespace |
13 | 66 |
14 namespace blink { | 67 namespace blink { |
15 | 68 |
| 69 bool IsOSLionOrEarlier() |
| 70 { |
| 71 return MacOSXMinorVersion() <= LION_MINOR_VERSION; |
| 72 } |
| 73 |
16 bool IsOSMavericksOrEarlier() | 74 bool IsOSMavericksOrEarlier() |
17 { | 75 { |
18 return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9; | 76 return MacOSXMinorVersion() <= MAVERICKS_MINOR_VERSION; |
19 } | 77 } |
20 | 78 |
21 bool IsOSMavericks() | 79 bool IsOSMavericks() |
22 { | 80 { |
23 return floor(NSAppKitVersionNumber) == NSAppKitVersionNumber10_9; | 81 return MacOSXMinorVersion() == MAVERICKS_MINOR_VERSION; |
24 } | 82 } |
25 | 83 |
26 } // namespace blink | 84 } // namespace blink |
OLD | NEW |