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 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | #include "nsIdleServiceX.h" |
michael@0 | 6 | #include "nsObjCExceptions.h" |
michael@0 | 7 | #include "nsIServiceManager.h" |
michael@0 | 8 | #import <Foundation/Foundation.h> |
michael@0 | 9 | |
michael@0 | 10 | NS_IMPL_ISUPPORTS_INHERITED0(nsIdleServiceX, nsIdleService) |
michael@0 | 11 | |
michael@0 | 12 | bool |
michael@0 | 13 | nsIdleServiceX::PollIdleTime(uint32_t *aIdleTime) |
michael@0 | 14 | { |
michael@0 | 15 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN; |
michael@0 | 16 | |
michael@0 | 17 | kern_return_t rval; |
michael@0 | 18 | mach_port_t masterPort; |
michael@0 | 19 | |
michael@0 | 20 | rval = IOMasterPort(kIOMasterPortDefault, &masterPort); |
michael@0 | 21 | if (rval != KERN_SUCCESS) |
michael@0 | 22 | return false; |
michael@0 | 23 | |
michael@0 | 24 | io_iterator_t hidItr; |
michael@0 | 25 | rval = IOServiceGetMatchingServices(masterPort, |
michael@0 | 26 | IOServiceMatching("IOHIDSystem"), |
michael@0 | 27 | &hidItr); |
michael@0 | 28 | |
michael@0 | 29 | if (rval != KERN_SUCCESS) |
michael@0 | 30 | return false; |
michael@0 | 31 | NS_ASSERTION(hidItr, "Our iterator is null, but it ought not to be!"); |
michael@0 | 32 | |
michael@0 | 33 | io_registry_entry_t entry = IOIteratorNext(hidItr); |
michael@0 | 34 | NS_ASSERTION(entry, "Our IO Registry Entry is null, but it shouldn't be!"); |
michael@0 | 35 | |
michael@0 | 36 | IOObjectRelease(hidItr); |
michael@0 | 37 | |
michael@0 | 38 | NSMutableDictionary *hidProps; |
michael@0 | 39 | rval = IORegistryEntryCreateCFProperties(entry, |
michael@0 | 40 | (CFMutableDictionaryRef*)&hidProps, |
michael@0 | 41 | kCFAllocatorDefault, 0); |
michael@0 | 42 | if (rval != KERN_SUCCESS) |
michael@0 | 43 | return false; |
michael@0 | 44 | NS_ASSERTION(hidProps, "HIDProperties is null, but no error was returned."); |
michael@0 | 45 | [hidProps autorelease]; |
michael@0 | 46 | |
michael@0 | 47 | id idleObj = [hidProps objectForKey:@"HIDIdleTime"]; |
michael@0 | 48 | NS_ASSERTION([idleObj isKindOfClass: [NSData class]] || |
michael@0 | 49 | [idleObj isKindOfClass: [NSNumber class]], |
michael@0 | 50 | "What we got for the idle object is not what we expect!"); |
michael@0 | 51 | |
michael@0 | 52 | uint64_t time; |
michael@0 | 53 | if ([idleObj isKindOfClass: [NSData class]]) |
michael@0 | 54 | [idleObj getBytes: &time]; |
michael@0 | 55 | else |
michael@0 | 56 | time = [idleObj unsignedLongLongValue]; |
michael@0 | 57 | |
michael@0 | 58 | IOObjectRelease(entry); |
michael@0 | 59 | |
michael@0 | 60 | // convert to ms from ns |
michael@0 | 61 | time /= 1000000; |
michael@0 | 62 | if (time > UINT32_MAX) // Overflow will occur |
michael@0 | 63 | return false; |
michael@0 | 64 | |
michael@0 | 65 | *aIdleTime = static_cast<uint32_t>(time); |
michael@0 | 66 | |
michael@0 | 67 | return true; |
michael@0 | 68 | |
michael@0 | 69 | NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(false); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | bool |
michael@0 | 73 | nsIdleServiceX::UsePollMode() |
michael@0 | 74 | { |
michael@0 | 75 | return true; |
michael@0 | 76 | } |
michael@0 | 77 |