From dd3279a03bf2d8ff04f89bc8d3b7c65f485c3e92 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 9 Mar 2022 11:22:42 +0000 Subject: [PATCH] Bug 1494436 - Unset MOZ_APP_LAUNCHER for external MIME handlers If Thunderbird sets this in its startup script (as it does in Debian and Fedora), Firefox does not set this in its startup script (it doesn't in Debian), and Firefox is the handler for clicking a link in Thunderbird, then Firefox will think it is part of Thunderbird and offer to make Thunderbird (not Firefox!) the default browser. If the user accepts this, it will break the ability to open normal HTTP links and HTML files from other applications. The same would be true for any other pair of Mozilla-based applications. To avoid this, unset MOZ_APP_LAUNCHER for the Firefox child process. Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1494436 Bug-Debian: https://bugs.debian.org/948691 Gbp-Pq: Topic fixes Gbp-Pq: Name Bug-1494436-Unset-MOZ_APP_LAUNCHER-for-external-MIME-hand.patch --- toolkit/system/gnome/nsGIOService.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/toolkit/system/gnome/nsGIOService.cpp b/toolkit/system/gnome/nsGIOService.cpp index 3f0a53bc51..93b695fa47 100644 --- a/toolkit/system/gnome/nsGIOService.cpp +++ b/toolkit/system/gnome/nsGIOService.cpp @@ -23,6 +23,17 @@ using namespace mozilla; +static GAppLaunchContext* GetAppLaunchContext() { + GAppLaunchContext* context = g_app_launch_context_new(); + // Unset this before launching third-party MIME handlers. Otherwise, + // if Thunderbird sets this in its startup script (as it does in Debian + // and Fedora), and Firefox does not set this in its startup script + // (it doesn't in Debian), then Firefox will think it is part of + // Thunderbird and try to make Thunderbird the default browser. + g_app_launch_context_unsetenv(context, "MOZ_APP_LAUNCHER"); + return context; +} + // s. a. the code gtk_should_use_portal() uses to detect if in flatpak env // https://gitlab.gnome.org/GNOME/gtk/-/blob/4300a5c609306ce77cbc8a3580c19201dccd8d13/gdk/gdk.c#L472 static bool GetFlatpakPortalEnv() { @@ -240,7 +251,9 @@ nsGIOMimeApp::LaunchWithURI(nsIURI* aUri, uris.data = const_cast(spec.get()); GError* error = nullptr; - gboolean result = g_app_info_launch_uris(mApp, &uris, nullptr, &error); + GAppLaunchContext* context = GetAppLaunchContext(); + gboolean result = g_app_info_launch_uris(mApp, &uris, context, &error); + g_object_unref(context); if (!result) { g_warning("Cannot launch application: %s", error->message); @@ -546,7 +559,10 @@ nsGIOService::ShowURI(nsIURI* aURI) { nsresult rv = aURI->GetSpec(spec); NS_ENSURE_SUCCESS(rv, rv); GError* error = nullptr; - if (!g_app_info_launch_default_for_uri(spec.get(), nullptr, &error)) { + GAppLaunchContext* context = GetAppLaunchContext(); + g_app_info_launch_default_for_uri(spec.get(), context, &error); + g_object_unref(context); + if (error) { g_warning("Could not launch default application for URI: %s", error->message); g_error_free(error); @@ -562,7 +578,9 @@ nsGIOService::ShowURIForInput(const nsACString& aUri) { nsresult rv = NS_ERROR_FAILURE; GError* error = nullptr; - g_app_info_launch_default_for_uri(spec, nullptr, &error); + GAppLaunchContext* context = GetAppLaunchContext(); + g_app_info_launch_default_for_uri(spec, context, &error); + g_object_unref(context); if (error) { g_warning("Cannot launch default application: %s", error->message); g_error_free(error); -- 2.30.2