Bug 1542316: Allow new instances to be launched if the path to the application bundle is different than currently running instances on macOS. r=spohl

This commit is contained in:
Yuri 2019-04-25 11:46:31 -04:00
Родитель a333a35151
Коммит b1876ebe35
1 изменённых файлов: 26 добавлений и 6 удалений

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

@ -67,7 +67,15 @@ void remoteClientNotificationCallback(CFNotificationCenterRef aCenter, void* aOb
// Autorelease pool to prevent memory leaks, in case there is no outer pool.
mozilla::MacAutoreleasePool pool;
NSDictionary* userInfoDict = (__bridge NSDictionary*)aUserInfo;
if (userInfoDict && [userInfoDict objectForKey:@"commandLineArgs"]) {
if (userInfoDict && [userInfoDict objectForKey:@"commandLineArgs"] &&
[userInfoDict objectForKey:@"senderPath"]) {
NSString* senderPath = [userInfoDict objectForKey:@"senderPath"];
if (![senderPath isEqual:[[NSBundle mainBundle] bundlePath]]) {
// The caller is not the process at the same path as we are at. Skipping.
return;
}
NSArray* args = [userInfoDict objectForKey:@"commandLineArgs"];
nsCOMPtr<nsICommandLineRunner> cmdLine(new nsCommandLine());
@ -201,16 +209,28 @@ NS_IMETHODIMP nsNativeAppSupportCocoa::Start(bool* _retval) {
if (!shallProceedLikeNoRemote) {
// We check for other running instances only if -no-remote was not specified.
// The check is needed so the marAppApplyUpdateSuccess.js test doesn't fail on next call.
runningInstanceFound =
[[NSRunningApplication
runningApplicationsWithBundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]]
count] > 1;
NSArray* appsWithMatchingId = [NSRunningApplication runningApplicationsWithBundleIdentifier:
[[NSBundle mainBundle] bundleIdentifier]];
NSString* currentAppBundlePath = [[NSBundle mainBundle] bundlePath];
NSRunningApplication* currentApp = [NSRunningApplication currentApplication];
for (NSRunningApplication* app in appsWithMatchingId) {
if ([currentAppBundlePath isEqual:[[app bundleURL] path]] &&
![currentApp isEqual:app]) {
runningInstanceFound = YES;
break;
}
}
}
if (!shallProceedLikeNoRemote && !mozillaRestarting && runningInstanceFound) {
// There is another instance of this app already running!
NSArray* arguments = [[NSProcessInfo processInfo] arguments];
CFDictionaryRef userInfoDict = (__bridge CFDictionaryRef) @{@"commandLineArgs" : arguments};
NSString* senderPath = [[NSBundle mainBundle] bundlePath];
CFDictionaryRef userInfoDict = (__bridge CFDictionaryRef) @{@"commandLineArgs" :
arguments,
@"senderPath":
senderPath
};
// This code is shared between Firefox, Thunderbird and other Mozilla products.
// So we need a notification name that is unique to the product, so we