Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #define MAC_OS_X_VERSION_MASK 0x0000FFFF |
michael@0 | 7 | #define MAC_OS_X_VERSION_10_6_HEX 0x00001060 |
michael@0 | 8 | #define MAC_OS_X_VERSION_10_7_HEX 0x00001070 |
michael@0 | 9 | #define MAC_OS_X_VERSION_10_8_HEX 0x00001080 |
michael@0 | 10 | #define MAC_OS_X_VERSION_10_9_HEX 0x00001090 |
michael@0 | 11 | #define MAC_OS_X_VERSION_10_10_HEX 0x000010A0 |
michael@0 | 12 | |
michael@0 | 13 | // This API will not work for OS X 10.10, see Gestalt.h. |
michael@0 | 14 | |
michael@0 | 15 | #include "nsCocoaFeatures.h" |
michael@0 | 16 | #include "nsCocoaUtils.h" |
michael@0 | 17 | #include "nsDebug.h" |
michael@0 | 18 | #include "nsObjCExceptions.h" |
michael@0 | 19 | |
michael@0 | 20 | #import <Cocoa/Cocoa.h> |
michael@0 | 21 | |
michael@0 | 22 | int32_t nsCocoaFeatures::mOSXVersion = 0; |
michael@0 | 23 | int32_t nsCocoaFeatures::mOSXVersionMajor = 0; |
michael@0 | 24 | int32_t nsCocoaFeatures::mOSXVersionMinor = 0; |
michael@0 | 25 | int32_t nsCocoaFeatures::mOSXVersionBugFix = 0; |
michael@0 | 26 | |
michael@0 | 27 | static int intAtStringIndex(NSArray *array, int index) |
michael@0 | 28 | { |
michael@0 | 29 | return [(NSString *)[array objectAtIndex:index] integerValue]; |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | static void GetSystemVersion(int &major, int &minor, int &bugfix) |
michael@0 | 33 | { |
michael@0 | 34 | major = minor = bugfix = 0; |
michael@0 | 35 | |
michael@0 | 36 | NSString* versionString = [[NSDictionary dictionaryWithContentsOfFile: |
michael@0 | 37 | @"/System/Library/CoreServices/SystemVersion.plist"] objectForKey:@"ProductVersion"]; |
michael@0 | 38 | NSArray* versions = [versionString componentsSeparatedByString:@"."]; |
michael@0 | 39 | NSUInteger count = [versions count]; |
michael@0 | 40 | if (count > 0) { |
michael@0 | 41 | major = intAtStringIndex(versions, 0); |
michael@0 | 42 | if (count > 1) { |
michael@0 | 43 | minor = intAtStringIndex(versions, 1); |
michael@0 | 44 | if (count > 2) { |
michael@0 | 45 | bugfix = intAtStringIndex(versions, 2); |
michael@0 | 46 | } |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | /*static*/ void |
michael@0 | 52 | nsCocoaFeatures::InitializeVersionNumbers() |
michael@0 | 53 | { |
michael@0 | 54 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK; |
michael@0 | 55 | |
michael@0 | 56 | // Provide an autorelease pool to avoid leaking Cocoa objects, |
michael@0 | 57 | // as this gets called before the main autorelease pool is in place. |
michael@0 | 58 | nsAutoreleasePool localPool; |
michael@0 | 59 | |
michael@0 | 60 | int major, minor, bugfix; |
michael@0 | 61 | GetSystemVersion(major, minor, bugfix); |
michael@0 | 62 | |
michael@0 | 63 | mOSXVersionMajor = major; |
michael@0 | 64 | mOSXVersionMinor = minor; |
michael@0 | 65 | mOSXVersionBugFix = bugfix; |
michael@0 | 66 | |
michael@0 | 67 | if (major < 10) { |
michael@0 | 68 | NS_ERROR("Couldn't determine OS X version, assuming 10.6"); |
michael@0 | 69 | mOSXVersion = MAC_OS_X_VERSION_10_6_HEX; |
michael@0 | 70 | mOSXVersionMajor = 10; |
michael@0 | 71 | mOSXVersionMinor = 6; |
michael@0 | 72 | mOSXVersionBugFix = 0; |
michael@0 | 73 | } else if (minor < 6) { |
michael@0 | 74 | NS_ERROR("OS X version too old, assuming 10.6"); |
michael@0 | 75 | mOSXVersion = MAC_OS_X_VERSION_10_6_HEX; |
michael@0 | 76 | mOSXVersionMinor = 6; |
michael@0 | 77 | mOSXVersionBugFix = 0; |
michael@0 | 78 | } else { |
michael@0 | 79 | mOSXVersion = 0x1000 + (minor << 4); |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | NS_OBJC_END_TRY_ABORT_BLOCK; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | /* static */ int32_t |
michael@0 | 86 | nsCocoaFeatures::OSXVersion() |
michael@0 | 87 | { |
michael@0 | 88 | if (!mOSXVersion) { |
michael@0 | 89 | InitializeVersionNumbers(); |
michael@0 | 90 | } |
michael@0 | 91 | return mOSXVersion; |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | /* static */ int32_t |
michael@0 | 95 | nsCocoaFeatures::OSXVersionMajor() |
michael@0 | 96 | { |
michael@0 | 97 | if (!mOSXVersion) { |
michael@0 | 98 | InitializeVersionNumbers(); |
michael@0 | 99 | } |
michael@0 | 100 | return mOSXVersionMajor; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | /* static */ int32_t |
michael@0 | 104 | nsCocoaFeatures::OSXVersionMinor() |
michael@0 | 105 | { |
michael@0 | 106 | if (!mOSXVersion) { |
michael@0 | 107 | InitializeVersionNumbers(); |
michael@0 | 108 | } |
michael@0 | 109 | return mOSXVersionMinor; |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | /* static */ int32_t |
michael@0 | 113 | nsCocoaFeatures::OSXVersionBugFix() |
michael@0 | 114 | { |
michael@0 | 115 | if (!mOSXVersion) { |
michael@0 | 116 | InitializeVersionNumbers(); |
michael@0 | 117 | } |
michael@0 | 118 | return mOSXVersionBugFix; |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | /* static */ bool |
michael@0 | 122 | nsCocoaFeatures::SupportCoreAnimationPlugins() |
michael@0 | 123 | { |
michael@0 | 124 | // Disallow Core Animation on 10.5 because of crashes. |
michael@0 | 125 | // See Bug 711564. |
michael@0 | 126 | return (OSXVersion() >= MAC_OS_X_VERSION_10_6_HEX); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | /* static */ bool |
michael@0 | 130 | nsCocoaFeatures::OnLionOrLater() |
michael@0 | 131 | { |
michael@0 | 132 | return (OSXVersion() >= MAC_OS_X_VERSION_10_7_HEX); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | /* static */ bool |
michael@0 | 136 | nsCocoaFeatures::OnMountainLionOrLater() |
michael@0 | 137 | { |
michael@0 | 138 | return (OSXVersion() >= MAC_OS_X_VERSION_10_8_HEX); |
michael@0 | 139 | } |
michael@0 | 140 | |
michael@0 | 141 | /* static */ bool |
michael@0 | 142 | nsCocoaFeatures::OnMavericksOrLater() |
michael@0 | 143 | { |
michael@0 | 144 | return (OSXVersion() >= MAC_OS_X_VERSION_10_9_HEX); |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | /* static */ bool |
michael@0 | 148 | nsCocoaFeatures::OnYosemiteOrLater() |
michael@0 | 149 | { |
michael@0 | 150 | return (OSXVersion() >= MAC_OS_X_VERSION_10_10_HEX); |
michael@0 | 151 | } |