Default external web browser do not work on Ubuntu 22.04
How to reproduce.
- Start eclipse from terminal to see standard output
- In 'Web Browser" preferences set "external web browser" and enable "Default system web browser"
- Create empty file with html extension
- Double-click html file
Browser will not open and there will be message in terminal:
env: '<html file path>'': Permission denied
Environment
Ubuntu 22.04 with Firefox from snap Eclipse 4.24 (this is not limited to this version)
Problem
When Firefox is installed from Snap (which is default in Ubuntu 22.04) then Exec property in desktop file will have full command line not just executable path:
Snap version (/var/lib/snapd/desktop/applications/firefox_firefox.desktop):
Exec=env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/firefox_firefox.desktop /snap/bin/firefox %u
Deb version (/usr/share/applications/firefox.desktop):
Exec=firefox %u
To get browser command line method Program.gio_getProgram is used.
From bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java:
static Program gio_getProgram (long application) {
Program program = new Program();
// ... cut ...
long applicationCommand = OS.g_app_info_get_executable (application);
if (applicationCommand != 0) {
length = C.strlen (applicationCommand);
if (length > 0) {
buffer = new byte [length];
C.memmove (buffer, applicationCommand, length);
program.command = new String (Converter.mbcsToWcs (buffer));
}
}
Native OS.g_app_info_get_executable method returns executable only, not full command line.
So for Snap Firefox it returns env, which is the used as executable to show html file.
This is consistent with error message in terminal above. For non-snap firefox it would return firefox.
Possible fix could use g_app_info_get_commandline function that return command line instead of just executable.
Simple C program that demonstrates difference:
#include <gio/gio.h>
#include <stdio.h>
int main()
{
GAppInfo* info = g_app_info_get_default_for_type("text/html", 0);
if (info) {
printf("Name: %s\n", g_app_info_get_name(info));
printf("Exec: %s\n", g_app_info_get_executable(info));
printf("Cmdl: %s\n", g_app_info_get_commandline(info));
} else {
printf("error\n");
}
};
and CMakeList.txt:
project(gio_test)
cmake_minimum_required(VERSION 3.19)
find_package(PkgConfig REQUIRED)
pkg_check_modules(deps REQUIRED IMPORTED_TARGET glib-2.0 gio-2.0 gio-unix-2.0)
add_executable(gio_test main.c)
target_link_libraries(gio_test PkgConfig::deps)
Program produces output:
Name: Przeglądarka WWW Firefox
Exec: env
Cmdl: env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/firefox_firefox.desktop /snap/bin/firefox %u
Do you think you can spend the time to provide a PR?
Latest versions are still impacted, any chance that someone make a contribution ?