Bug 1745788: Provide users the ability to install Firefox correctly when App Translocation is in use on macOS. r=mstange,bytesized

Differential Revision: https://phabricator.services.mozilla.com/D141982
This commit is contained in:
Stephen A Pohl 2022-04-04 17:30:10 +00:00
Родитель c4b34fed3b
Коммит 4e3a8b1761
3 изменённых файлов: 23 добавлений и 19 удалений

Просмотреть файл

@ -9,8 +9,7 @@
#ifndef MacRunFromDmgUtils_h_
#define MacRunFromDmgUtils_h_
namespace mozilla {
namespace MacRunFromDmgUtils {
namespace mozilla::MacRunFromDmgUtils {
/**
* Returns true if the app is running from the read-only filesystem of a
@ -20,16 +19,15 @@ namespace MacRunFromDmgUtils {
bool IsAppRunningFromDmg();
/**
* Checks whether the app is running from a read-only .dmg image and, if so,
* asks the user for permission before attempting to install the app and launch
* it.
* Checks whether the app is running from a read-only .dmg image or a read-only
* app translocated location and, if so, asks the user for permission before
* attempting to install the app and launch it.
*
* Returns true if the app has been installed and relaunched, in which case
* this instance of the app should exit.
*/
bool MaybeInstallFromDmgAndRelaunch();
bool MaybeInstallAndRelaunch();
} // namespace MacRunFromDmgUtils
} // namespace mozilla
} // namespace mozilla::MacRunFromDmgUtils
#endif

Просмотреть файл

@ -38,8 +38,7 @@
// https://developer.apple.com/documentation/iokit
// https://developer.apple.com/library/archive/documentation/DeviceDrivers/Conceptual/IOKitFundamentals/
namespace mozilla {
namespace MacRunFromDmgUtils {
namespace mozilla::MacRunFromDmgUtils {
/**
* Opens a dialog to ask the user whether the existing app in the Applications
@ -322,7 +321,7 @@ bool LaunchElevatedDmgInstall(NSString* aBundlePath, NSArray* aArguments) {
// Note: both arguments are expected to contain the app name (to end with
// '.app').
static bool InstallFromDmg(NSString* aBundlePath, NSString* aDestPath) {
static bool InstallFromPath(NSString* aBundlePath, NSString* aDestPath) {
bool installSuccessful = false;
NSFileManager* fileManager = [NSFileManager defaultManager];
if ([fileManager copyItemAtPath:aBundlePath toPath:aDestPath error:nil]) {
@ -456,15 +455,22 @@ bool IsAppRunningFromDmg() {
NS_OBJC_END_TRY_BLOCK_RETURN(false);
}
bool MaybeInstallFromDmgAndRelaunch() {
bool MaybeInstallAndRelaunch() {
NS_OBJC_BEGIN_TRY_BLOCK_RETURN;
@autoreleasepool {
bool isFromDmg = IsAppRunningFromDmg();
bool isTranslocated = false;
if (!isFromDmg) {
NSString* bundlePath = [[NSBundle mainBundle] bundlePath];
if ([bundlePath containsString:@"/AppTranslocation/"]) {
isTranslocated = true;
}
}
Telemetry::ScalarSet(Telemetry::ScalarID::STARTUP_IS_RUN_FROM_DMG, isFromDmg);
if (!isFromDmg) {
if (!isFromDmg && !isTranslocated) {
if (getenv("MOZ_INSTALLED_AND_RELAUNCHED_FROM_DMG")) {
unsetenv("MOZ_INSTALLED_AND_RELAUNCHED_FROM_DMG");
glean::startup::run_from_dmg_install_outcome.Get("installed_and_relaunched"_ns).Set(true);
@ -498,6 +504,7 @@ bool MaybeInstallFromDmgAndRelaunch() {
// a more sophisticated user intentionally running from .dmg.
if ([fileManager fileExistsAtPath:destPath]) {
if (AskUserIfWeShouldLaunchExistingInstall()) {
StripQuarantineBit(destPath);
LaunchInstalledApp(destPath);
glean::startup::run_from_dmg_install_outcome.Get("user_accepted_launch_existing"_ns)
.Set(true);
@ -513,7 +520,7 @@ bool MaybeInstallFromDmgAndRelaunch() {
return false;
}
if (!InstallFromDmg(bundlePath, destPath)) {
if (!InstallFromPath(bundlePath, destPath)) {
ShowInstallFailedDialog();
return false;
}
@ -526,5 +533,4 @@ bool MaybeInstallFromDmgAndRelaunch() {
NS_OBJC_END_TRY_BLOCK_RETURN(false);
}
} // namespace MacRunFromDmgUtils
} // namespace mozilla
} // namespace mozilla::MacRunFromDmgUtils

Просмотреть файл

@ -5615,9 +5615,9 @@ nsresult XREMain::XRE_mainRun() {
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
# ifdef MOZILLA_OFFICIAL
// Check if we're running from a DMG and allow the user to install to the
// Applications directory.
if (MacRunFromDmgUtils::MaybeInstallFromDmgAndRelaunch()) {
// Check if we're running from a DMG or an app translocated location and
// allow the user to install to the Applications directory.
if (MacRunFromDmgUtils::MaybeInstallAndRelaunch()) {
bool userAllowedQuit = true;
appStartup->Quit(nsIAppStartup::eForceQuit, 0, &userAllowedQuit);
}