Skip to content

Commit 214c622

Browse files
committed
[GTK4] Browser crash when started from inside Eclipse
WebKitGtk 6 enforces sandbox web process but for it to work properly one has to configure the sandbox to have access to XDG_RUNTIME_DIR (contains Wayland/X11 display sockets) and /tmp (temporary files). Fixes a crash when opening Welcome/Internal Web Browser views or Help system with ``` (process:2): Gtk-WARNING **: 14:56:39.676: Failed to open display ** (Eclipse:1773443): ERROR **: 14:56:39.750: readPIDFromPeer: Unexpected short read from PID socket. (This usually means the auxiliary process crashed immediately. Investigate that instead!) ```
1 parent b4e5320 commit 214c622

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/library/webkitgtk.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2025 IBM Corporation and others. All rights reserved.
2+
* Copyright (c) 2009, 2026 IBM Corporation and others. All rights reserved.
33
* The contents of this file are made available under the terms
44
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
55
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -1953,6 +1953,28 @@ JNIEXPORT void JNICALL WebKitGTK_NATIVE(webkit_1user_1script_1unref)
19531953
}
19541954
#endif
19551955

1956+
#ifndef NO_webkit_1web_1context_1add_1path_1to_1sandbox
1957+
JNIEXPORT void JNICALL WebKitGTK_NATIVE(webkit_1web_1context_1add_1path_1to_1sandbox)
1958+
(JNIEnv *env, jclass that, jlong arg0, jbyteArray arg1, jboolean arg2)
1959+
{
1960+
jbyte *lparg1=NULL;
1961+
WebKitGTK_NATIVE_ENTER(env, that, webkit_1web_1context_1add_1path_1to_1sandbox_FUNC);
1962+
if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail;
1963+
/*
1964+
webkit_web_context_add_path_to_sandbox(arg0, lparg1, arg2);
1965+
*/
1966+
{
1967+
WebKitGTK_LOAD_FUNCTION(fp, webkit_web_context_add_path_to_sandbox)
1968+
if (fp) {
1969+
((void (CALLING_CONVENTION*)(jlong, jbyte *, jboolean))fp)(arg0, lparg1, arg2);
1970+
}
1971+
}
1972+
fail:
1973+
if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0);
1974+
WebKitGTK_NATIVE_EXIT(env, that, webkit_1web_1context_1add_1path_1to_1sandbox_FUNC);
1975+
}
1976+
#endif
1977+
19561978
#ifndef NO_webkit_1web_1context_1allow_1tls_1certificate_1for_1host
19571979
JNIEXPORT jlong JNICALL WebKitGTK_NATIVE(webkit_1web_1context_1allow_1tls_1certificate_1for_1host)
19581980
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jbyteArray arg2)

bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/library/webkitgtk_stats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2025 IBM Corporation and others. All rights reserved.
2+
* Copyright (c) 2009, 2026 IBM Corporation and others. All rights reserved.
33
* The contents of this file are made available under the terms
44
* of the GNU Lesser General Public License (LGPL) Version 2.1 that
55
* accompanies this distribution (lgpl-v21.txt). The LGPL is also
@@ -118,6 +118,7 @@ typedef enum {
118118
webkit_1user_1content_1manager_1remove_1all_1scripts_FUNC,
119119
webkit_1user_1script_1new_FUNC,
120120
webkit_1user_1script_1unref_FUNC,
121+
webkit_1web_1context_1add_1path_1to_1sandbox_FUNC,
121122
webkit_1web_1context_1allow_1tls_1certificate_1for_1host_FUNC,
122123
webkit_1web_1context_1get_1cookie_1manager_FUNC,
123124
webkit_1web_1context_1get_1default_FUNC,

bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/browser/WebKit.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,19 @@ public void create (Composite parent, int style) {
661661

662662
if (FirstCreate) {
663663
FirstCreate = false;
664+
664665
// Register the swt:// custom protocol for BrowserFunction calls via XMLHttpRequest
665666
long context = WebKitGTK.webkit_web_context_get_default();
667+
if (GTK.GTK4) {
668+
String xdgRuntimeDir = System.getenv("XDG_RUNTIME_DIR");
669+
if (xdgRuntimeDir != null && !xdgRuntimeDir.isEmpty()) {
670+
byte[] path = Converter.wcsToMbcs(xdgRuntimeDir, true);
671+
WebKitGTK.webkit_web_context_add_path_to_sandbox(context, path, false);
672+
}
673+
// Add /tmp to sandbox for temporary files
674+
byte[] tmpPath = Converter.wcsToMbcs("/tmp", true);
675+
WebKitGTK.webkit_web_context_add_path_to_sandbox(context, tmpPath, false);
676+
}
666677
WebKitGTK.webkit_web_context_register_uri_scheme(context, SWT_PROTOCOL, RequestProc.getAddress(), 0, 0);
667678
long security = WebKitGTK.webkit_web_context_get_security_manager(context);
668679
WebKitGTK.webkit_security_manager_register_uri_scheme_as_secure(security, SWT_PROTOCOL);

bundles/org.eclipse.swt/Eclipse SWT WebKit/gtk/org/eclipse/swt/internal/webkit/WebKitGTK.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ public class WebKitGTK extends C {
394394
/** @method flags=dynamic */
395395
public static final native void webkit_web_context_register_uri_scheme(long context, byte[] scheme, long callback, long user_data, long user_data_destroy_func);
396396

397+
/** @method flags=dynamic */
398+
public static final native void webkit_web_context_add_path_to_sandbox(long context, byte[] path, boolean read_only);
399+
397400
/** @method flags=dynamic */
398401
public static final native int webkit_web_view_can_go_back(long web_view);
399402

0 commit comments

Comments
 (0)