blob: 7af85444ada6a9fa5520d8b99ef4070e54a4b068 [file] [log] [blame]
[email protected]aebcd0dd2012-10-05 17:48:581// Copyright 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.
4
5#include "base/ios/ios_util.h"
6
marqf51b0032015-08-10 08:55:177#import <Foundation/Foundation.h>
avi9b6f42932015-12-26 22:15:148#include <stddef.h>
marqf51b0032015-08-10 08:55:179
avi9b6f42932015-12-26 22:15:1410#include "base/macros.h"
[email protected]aebcd0dd2012-10-05 17:48:5811#include "base/sys_info.h"
12
13namespace {
justincohenb83910d2016-01-08 23:49:4314
[email protected]aebcd0dd2012-10-05 17:48:5815// Return a 3 elements array containing the major, minor and bug fix version of
16// the OS.
avi9b6f42932015-12-26 22:15:1417const int32_t* OSVersionAsArray() {
18 int32_t* digits = new int32_t[3];
[email protected]aebcd0dd2012-10-05 17:48:5819 base::SysInfo::OperatingSystemVersionNumbers(
20 &digits[0], &digits[1], &digits[2]);
21 return digits;
22}
justincohenb83910d2016-01-08 23:49:4323
24std::string* g_icudtl_path_override = nullptr;
25
[email protected]aebcd0dd2012-10-05 17:48:5826} // namespace
27
28namespace base {
29namespace ios {
30
jif367f1092015-06-22 09:45:2231// When dropping iOS7 support, also address issues listed in crbug.com/502968.
sdefresne2f3869f92014-09-25 15:31:3432bool IsRunningOnIOS8OrLater() {
33 return IsRunningOnOrLater(8, 0, 0);
34}
35
pklded303e92015-07-06 16:14:5836bool IsRunningOnIOS9OrLater() {
37 return IsRunningOnOrLater(9, 0, 0);
38}
39
michaeldo19e74eb2016-06-16 23:58:1040bool IsRunningOnIOS10OrLater() {
41 return IsRunningOnOrLater(10, 0, 0);
42}
43
avi9b6f42932015-12-26 22:15:1444bool IsRunningOnOrLater(int32_t major, int32_t minor, int32_t bug_fix) {
45 static const int32_t* current_version = OSVersionAsArray();
46 int32_t version[] = {major, minor, bug_fix};
[email protected]aebcd0dd2012-10-05 17:48:5847 for (size_t i = 0; i < arraysize(version); i++) {
48 if (current_version[i] != version[i])
49 return current_version[i] > version[i];
50 }
51 return true;
52}
53
marqf51b0032015-08-10 08:55:1754bool IsInForcedRTL() {
55 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
marqb2238de2015-09-21 17:06:2156 return [defaults boolForKey:@"NSForceRightToLeftWritingDirection"];
marqf51b0032015-08-10 08:55:1757}
58
justincohenb83910d2016-01-08 23:49:4359void OverridePathOfEmbeddedICU(const char* path) {
60 DCHECK(!g_icudtl_path_override);
61 g_icudtl_path_override = new std::string(path);
62}
63
64FilePath FilePathOfEmbeddedICU() {
65 if (g_icudtl_path_override) {
66 return FilePath(*g_icudtl_path_override);
67 }
68 return FilePath();
69}
70
[email protected]aebcd0dd2012-10-05 17:48:5871} // namespace ios
72} // namespace base