toolkit/components/startup/nsUserInfoMac.mm

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "nsUserInfoMac.h"
     8 #include "nsObjCExceptions.h"
     9 #include "nsString.h"
    11 #import <Cocoa/Cocoa.h>
    12 #import <AddressBook/AddressBook.h>
    14 NS_IMPL_ISUPPORTS(nsUserInfo, nsIUserInfo)
    16 nsUserInfo::nsUserInfo() {}
    18 NS_IMETHODIMP
    19 nsUserInfo::GetFullname(char16_t **aFullname)
    20 {
    21   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
    23   NS_ConvertUTF8toUTF16 fullName([NSFullUserName() UTF8String]);
    24   *aFullname = ToNewUnicode(fullName);
    25   return NS_OK;
    27   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
    28 }
    30 NS_IMETHODIMP 
    31 nsUserInfo::GetUsername(char **aUsername)
    32 {
    33   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
    35   nsAutoCString username([NSUserName() UTF8String]);
    36   *aUsername = ToNewCString(username);
    37   return NS_OK;
    39   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
    40 }
    42 nsresult 
    43 nsUserInfo::GetPrimaryEmailAddress(nsCString &aEmailAddress)
    44 {
    45   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
    47   // Try to get this user's primary email from the system addressbook's "me card" 
    48   // (if they've filled it)
    49   ABPerson *me = [[ABAddressBook sharedAddressBook] me];
    50   ABMultiValue *emailAddresses = [me valueForProperty:kABEmailProperty];
    51   if ([emailAddresses count] > 0) {
    52     // get the index of the primary email, in case there are more than one
    53     int primaryEmailIndex = [emailAddresses indexForIdentifier:[emailAddresses primaryIdentifier]];
    54     aEmailAddress.Assign([[emailAddresses valueAtIndex:primaryEmailIndex] UTF8String]);
    55     return NS_OK;
    56   }
    58   return NS_ERROR_FAILURE;
    60   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
    61 }
    63 NS_IMETHODIMP 
    64 nsUserInfo::GetEmailAddress(char **aEmailAddress)
    65 {
    66   nsAutoCString email;
    67   if (NS_SUCCEEDED(GetPrimaryEmailAddress(email))) 
    68     *aEmailAddress = ToNewCString(email);
    69   return NS_OK;
    70 }
    72 NS_IMETHODIMP 
    73 nsUserInfo::GetDomain(char **aDomain)
    74 {
    75   nsAutoCString email;
    76   if (NS_SUCCEEDED(GetPrimaryEmailAddress(email))) {
    77     int32_t index = email.FindChar('@');
    78     if (index != -1) {
    79       // chop off everything before, and including the '@'
    80       *aDomain = ToNewCString(Substring(email, index + 1));
    81     }
    82   }
    83   return NS_OK;
    84 }

mercurial