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() {
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);
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);
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);