eclipse.platform.swt icon indicating copy to clipboard operation
eclipse.platform.swt copied to clipboard

Default external web browser do not work on Ubuntu 22.04

Open jakublabenski opened this issue 3 years ago • 2 comments

How to reproduce.

  1. Start eclipse from terminal to see standard output
  2. In 'Web Browser" preferences set "external web browser" and enable "Default system web browser"
  3. Create empty file with html extension
  4. 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

jakublabenski avatar Jun 22 '22 12:06 jakublabenski

Do you think you can spend the time to provide a PR?

akurtakov avatar Sep 12 '22 14:09 akurtakov

Latest versions are still impacted, any chance that someone make a contribution ?

rbioteau avatar Jan 26 '24 14:01 rbioteau