diff --git a/toolkit/xre/MacRunFromDmgUtils.h b/toolkit/xre/MacRunFromDmgUtils.h index 45b167a0b3ed..d93e6445b1b4 100644 --- a/toolkit/xre/MacRunFromDmgUtils.h +++ b/toolkit/xre/MacRunFromDmgUtils.h @@ -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 diff --git a/toolkit/xre/MacRunFromDmgUtils.mm b/toolkit/xre/MacRunFromDmgUtils.mm index cf96d304e7f2..f25c7a33cb3e 100644 --- a/toolkit/xre/MacRunFromDmgUtils.mm +++ b/toolkit/xre/MacRunFromDmgUtils.mm @@ -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 diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index e239751173f6..b0d3fd3f6ff6 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -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); }