Control: tags -1 + patch Steps to reproduce in a test account:
* testing/unstable system (I used a GNOME virtual machine) * firefox-esr as default web browser (this is the default in GNOME anyway) * use an expendable uid or a VM, these test steps are destructive * rm -f ~/.config/mimeapps.list * Completely exit from both Firefox and Thunderbird * strace -eexecve -ff thunderbird * no need to set up an actual email account * press Alt, Help -> About Thunderbird, click on Privacy Policy - It launches firefox as a subprocess (you'll see this in the strace) * If Firefox asks to be made the default browser: - Click "Make Firefox my default browser" * Completely exit from both Firefox and Thunderbird again * cat ~/.config/mimeapps.list * xdg-open http://example.com Expected result: mimeapps.list doesn't exist, is empty, or lists firefox-esr as default web browser. example.com opens in Firefox. Actual result: mimeapps.list has thunderbird.desktop as default for HTML, HTTP etc., and Thunderbird opens instead of Firefox. Mitigation: If Firefox is already running before you click the link in Thunderbird, then the firefox-esr subprocess of Thunderbird just sends an IPC request to the existing Firefox instance and then exits, so people who habitually have a web browser open at all times will often not experience this bug (which is presumably why the Thunderbird maintainers didn't). On Wed, 09 Mar 2022 at 01:23:08 +0000, Simon McVittie wrote: > https://bugs.debian.org/980461 seems to be basically the same bug, > and points to upstream bug report > https://bugzilla.mozilla.org/show_bug.cgi?id=1494436 where the > other suggestion was to remove MOZ_APP_LAUNCHER from the environment > before launching any external URL or MIME-type handler. I'll try to > put together a patch for that. The attached patch for Thunderbird works, and gives me the expected result: Firefox doesn't ask to be made the default browser, and doesn't write itself into mimeapps.list as though it was Thunderbird. Please consider applying this in both unstable and stable: this bug is really confusing when it happens to a non-technical user. smcv
From: Simon McVittie <s...@debian.org> Date: Wed, 9 Mar 2022 11:22:42 +0000 Subject: 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 --- 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 3f0a53b..b2479d2 100644 --- a/toolkit/system/gnome/nsGIOService.cpp +++ b/toolkit/system/gnome/nsGIOService.cpp @@ -23,6 +23,17 @@ using namespace mozilla; +static bool 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<char*>(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);