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

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

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

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

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