Issue #1829 - Revert "Issue #1751"

This commit is contained in:
Brian Smith 2022-04-26 11:34:08 -05:00 • committed by roytam1
commit 13fcc4a046
949 changed files with 95662 additions and 444 deletions

View file

@ -7,7 +7,7 @@ DIRS += ['public']
EXPORTS.mozilla += ['StartupTimeline.h']
SOURCES += [
UNIFIED_SOURCES += [
'nsAppStartup.cpp',
'StartupTimeline.cpp',
]
@ -16,7 +16,9 @@ if CONFIG['MOZ_USERINFO']:
if CONFIG['OS_ARCH'] == 'WINNT':
# This file cannot be built in unified mode because of name clashes with Windows headers.
SOURCES += ['nsUserInfoWin.cpp']
elif CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
UNIFIED_SOURCES += ['nsUserInfoMac.mm']
else:
SOURCES += ['nsUserInfoUnix.cpp']
UNIFIED_SOURCES += ['nsUserInfoUnix.cpp']
FINAL_LIBRARY = 'xul'

View file

@ -273,6 +273,10 @@ nsAppStartup::Run(void)
// with a zombie process.
if (!mShuttingDown && mConsiderQuitStopper != 0) {
#ifdef XP_MACOSX
EnterLastWindowClosingSurvivalArea();
#endif
mRunning = true;
nsresult rv = mAppShell->Run();
@ -308,10 +312,45 @@ nsAppStartup::Quit(uint32_t aMode)
// If we're considering quitting, we will only do so if:
if (ferocity == eConsiderQuit) {
#ifdef XP_MACOSX
nsCOMPtr<nsIAppShellService> appShell
(do_GetService(NS_APPSHELLSERVICE_CONTRACTID));
bool hasHiddenPrivateWindow = false;
if (appShell) {
appShell->GetHasHiddenPrivateWindow(&hasHiddenPrivateWindow);
}
int32_t suspiciousCount = hasHiddenPrivateWindow ? 2 : 1;
#endif
if (mConsiderQuitStopper == 0) {
// there are no windows...
ferocity = eAttemptQuit;
}
#ifdef XP_MACOSX
else if (mConsiderQuitStopper == suspiciousCount) {
// ... or there is only a hiddenWindow left, and it's useless:
// Failure shouldn't be fatal, but will abort quit attempt:
if (!appShell)
return NS_OK;
bool usefulHiddenWindow;
appShell->GetApplicationProvidedHiddenWindow(&usefulHiddenWindow);
nsCOMPtr<nsIXULWindow> hiddenWindow;
appShell->GetHiddenWindow(getter_AddRefs(hiddenWindow));
// If the remaining windows are useful, we won't quit:
nsCOMPtr<nsIXULWindow> hiddenPrivateWindow;
if (hasHiddenPrivateWindow) {
appShell->GetHiddenPrivateWindow(getter_AddRefs(hiddenPrivateWindow));
if ((!hiddenWindow && !hiddenPrivateWindow) || usefulHiddenWindow)
return NS_OK;
} else if (!hiddenWindow || usefulHiddenWindow) {
return NS_OK;
}
ferocity = eAttemptQuit;
}
#endif
}
nsCOMPtr<nsIObserverService> obsService;
@ -365,6 +404,10 @@ nsAppStartup::Quit(uint32_t aMode)
if (!mAttemptingQuit) {
mAttemptingQuit = true;
#ifdef XP_MACOSX
// now even the Mac wants to quit when the last window is closed
ExitLastWindowClosingSurvivalArea();
#endif
if (obsService)
obsService->NotifyObservers(nullptr, "quit-application-granted", nullptr);
}

View file

@ -0,0 +1,25 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef __nsUserInfoMac_h
#define __nsUserInfoMac_h
#include "nsIUserInfo.h"
#include "nsReadableUtils.h"
class nsUserInfo: public nsIUserInfo
{
public:
nsUserInfo();
NS_DECL_ISUPPORTS
NS_DECL_NSIUSERINFO
nsresult GetPrimaryEmailAddress(nsCString &aEmailAddress);
protected:
virtual ~nsUserInfo() {}
};
#endif /* __nsUserInfo_h */

View file

@ -0,0 +1,84 @@
/* -*- Mode: Objective-C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsUserInfoMac.h"
#include "nsObjCExceptions.h"
#include "nsString.h"
#import <Cocoa/Cocoa.h>
#import <AddressBook/AddressBook.h>
NS_IMPL_ISUPPORTS(nsUserInfo, nsIUserInfo)
nsUserInfo::nsUserInfo() {}
NS_IMETHODIMP
nsUserInfo::GetFullname(char16_t **aFullname)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
NS_ConvertUTF8toUTF16 fullName([NSFullUserName() UTF8String]);
*aFullname = ToNewUnicode(fullName);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
}
NS_IMETHODIMP
nsUserInfo::GetUsername(char **aUsername)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
nsAutoCString username([NSUserName() UTF8String]);
*aUsername = ToNewCString(username);
return NS_OK;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
}
nsresult
nsUserInfo::GetPrimaryEmailAddress(nsCString &aEmailAddress)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NSRESULT
// Try to get this user's primary email from the system addressbook's "me card"
// (if they've filled it)
ABPerson *me = [[ABAddressBook sharedAddressBook] me];
ABMultiValue *emailAddresses = [me valueForProperty:kABEmailProperty];
if ([emailAddresses count] > 0) {
// get the index of the primary email, in case there are more than one
int primaryEmailIndex = [emailAddresses indexForIdentifier:[emailAddresses primaryIdentifier]];
aEmailAddress.Assign([[emailAddresses valueAtIndex:primaryEmailIndex] UTF8String]);
return NS_OK;
}
return NS_ERROR_FAILURE;
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT
}
NS_IMETHODIMP
nsUserInfo::GetEmailAddress(char **aEmailAddress)
{
nsAutoCString email;
if (NS_SUCCEEDED(GetPrimaryEmailAddress(email)))
*aEmailAddress = ToNewCString(email);
return NS_OK;
}
NS_IMETHODIMP
nsUserInfo::GetDomain(char **aDomain)
{
nsAutoCString email;
if (NS_SUCCEEDED(GetPrimaryEmailAddress(email))) {
int32_t index = email.FindChar('@');
if (index != -1) {
// chop off everything before, and including the '@'
*aDomain = ToNewCString(Substring(email, index + 1));
}
}
return NS_OK;
}