Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 | |
michael@0 | 7 | #include "nsUserInfoMac.h" |
michael@0 | 8 | #include "nsObjCExceptions.h" |
michael@0 | 9 | #include "nsString.h" |
michael@0 | 10 | |
michael@0 | 11 | #import <Cocoa/Cocoa.h> |
michael@0 | 12 | #import <AddressBook/AddressBook.h> |
michael@0 | 13 | |
michael@0 | 14 | NS_IMPL_ISUPPORTS(nsUserInfo, nsIUserInfo) |
michael@0 | 15 | |
michael@0 | 16 | nsUserInfo::nsUserInfo() {} |
michael@0 | 17 | |
michael@0 | 18 | NS_IMETHODIMP |
michael@0 | 19 | nsUserInfo::GetFullname(char16_t **aFullname) |
michael@0 | 20 | { |
michael@0 | 21 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT |
michael@0 | 22 | |
michael@0 | 23 | NS_ConvertUTF8toUTF16 fullName([NSFullUserName() UTF8String]); |
michael@0 | 24 | *aFullname = ToNewUnicode(fullName); |
michael@0 | 25 | return NS_OK; |
michael@0 | 26 | |
michael@0 | 27 | NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | NS_IMETHODIMP |
michael@0 | 31 | nsUserInfo::GetUsername(char **aUsername) |
michael@0 | 32 | { |
michael@0 | 33 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT |
michael@0 | 34 | |
michael@0 | 35 | nsAutoCString username([NSUserName() UTF8String]); |
michael@0 | 36 | *aUsername = ToNewCString(username); |
michael@0 | 37 | return NS_OK; |
michael@0 | 38 | |
michael@0 | 39 | NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | nsresult |
michael@0 | 43 | nsUserInfo::GetPrimaryEmailAddress(nsCString &aEmailAddress) |
michael@0 | 44 | { |
michael@0 | 45 | NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT |
michael@0 | 46 | |
michael@0 | 47 | // Try to get this user's primary email from the system addressbook's "me card" |
michael@0 | 48 | // (if they've filled it) |
michael@0 | 49 | ABPerson *me = [[ABAddressBook sharedAddressBook] me]; |
michael@0 | 50 | ABMultiValue *emailAddresses = [me valueForProperty:kABEmailProperty]; |
michael@0 | 51 | if ([emailAddresses count] > 0) { |
michael@0 | 52 | // get the index of the primary email, in case there are more than one |
michael@0 | 53 | int primaryEmailIndex = [emailAddresses indexForIdentifier:[emailAddresses primaryIdentifier]]; |
michael@0 | 54 | aEmailAddress.Assign([[emailAddresses valueAtIndex:primaryEmailIndex] UTF8String]); |
michael@0 | 55 | return NS_OK; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | return NS_ERROR_FAILURE; |
michael@0 | 59 | |
michael@0 | 60 | NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | NS_IMETHODIMP |
michael@0 | 64 | nsUserInfo::GetEmailAddress(char **aEmailAddress) |
michael@0 | 65 | { |
michael@0 | 66 | nsAutoCString email; |
michael@0 | 67 | if (NS_SUCCEEDED(GetPrimaryEmailAddress(email))) |
michael@0 | 68 | *aEmailAddress = ToNewCString(email); |
michael@0 | 69 | return NS_OK; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | NS_IMETHODIMP |
michael@0 | 73 | nsUserInfo::GetDomain(char **aDomain) |
michael@0 | 74 | { |
michael@0 | 75 | nsAutoCString email; |
michael@0 | 76 | if (NS_SUCCEEDED(GetPrimaryEmailAddress(email))) { |
michael@0 | 77 | int32_t index = email.FindChar('@'); |
michael@0 | 78 | if (index != -1) { |
michael@0 | 79 | // chop off everything before, and including the '@' |
michael@0 | 80 | *aDomain = ToNewCString(Substring(email, index + 1)); |
michael@0 | 81 | } |
michael@0 | 82 | } |
michael@0 | 83 | return NS_OK; |
michael@0 | 84 | } |