| 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 #include <sstream> | 8 #import <AppKit/AppKit.h> |
| 9 #include <string> | |
| 10 #include <sys/utsname.h> | |
| 11 | 9 |
| 12 namespace { | 10 #ifndef NSAppKitVersionNumber10_9 |
| 13 | 11 #define NSAppKitVersionNumber10_9 1265 |
| 14 // Returns the running system's Darwin major version. Don't call this, it's | 12 #endif |
| 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 | |
| 66 | 13 |
| 67 namespace blink { | 14 namespace blink { |
| 68 | 15 |
| 69 bool IsOSLionOrEarlier() | |
| 70 { | |
| 71 return MacOSXMinorVersion() <= LION_MINOR_VERSION; | |
| 72 } | |
| 73 | |
| 74 bool IsOSMavericksOrEarlier() | 16 bool IsOSMavericksOrEarlier() |
| 75 { | 17 { |
| 76 return MacOSXMinorVersion() <= MAVERICKS_MINOR_VERSION; | 18 return floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9; |
| 77 } | 19 } |
| 78 | 20 |
| 79 bool IsOSMavericks() | 21 bool IsOSMavericks() |
| 80 { | 22 { |
| 81 return MacOSXMinorVersion() == MAVERICKS_MINOR_VERSION; | 23 return floor(NSAppKitVersionNumber) == NSAppKitVersionNumber10_9; |
| 82 } | 24 } |
| 83 | 25 |
| 84 } // namespace blink | 26 } // namespace blink |
| OLD | NEW |