Skip to content

Commit e605e79

Browse files
committed
[GTK] Fix webkit download on GTK 4
Webkitgtk on GTK 4 changed the component which handles the download-started signal. This PR adjusts SWT accordingly.
1 parent 142dc7a commit e605e79

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,26 @@ JNIEXPORT jlong JNICALL WebKitGTK_NATIVE(webkit_1navigation_1policy_1decision_1g
11631163
}
11641164
#endif
11651165

1166+
#ifndef NO_webkit_1network_1session_1get_1default
1167+
JNIEXPORT jlong JNICALL WebKitGTK_NATIVE(webkit_1network_1session_1get_1default)
1168+
(JNIEnv *env, jclass that)
1169+
{
1170+
jlong rc = 0;
1171+
WebKitGTK_NATIVE_ENTER(env, that, webkit_1network_1session_1get_1default_FUNC);
1172+
/*
1173+
rc = (jlong)webkit_network_session_get_default();
1174+
*/
1175+
{
1176+
WebKitGTK_LOAD_FUNCTION(fp, webkit_network_session_get_default)
1177+
if (fp) {
1178+
rc = (jlong)((jlong (CALLING_CONVENTION*)())fp)();
1179+
}
1180+
}
1181+
WebKitGTK_NATIVE_EXIT(env, that, webkit_1network_1session_1get_1default_FUNC);
1182+
return rc;
1183+
}
1184+
#endif
1185+
11661186
#ifndef NO_webkit_1policy_1decision_1download
11671187
JNIEXPORT void JNICALL WebKitGTK_NATIVE(webkit_1policy_1decision_1download)
11681188
(JNIEnv *env, jclass that, jlong arg0)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ typedef enum {
7979
webkit_1javascript_1result_1get_1value_FUNC,
8080
webkit_1javascript_1result_1unref_FUNC,
8181
webkit_1navigation_1policy_1decision_1get_1request_FUNC,
82+
webkit_1network_1session_1get_1default_FUNC,
8283
webkit_1policy_1decision_1download_FUNC,
8384
webkit_1policy_1decision_1ignore_FUNC,
8485
webkit_1response_1policy_1decision_1get_1request_FUNC,

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,11 @@ public void create (Composite parent, int style) {
703703

704704
// (!) Note this one's a 'webContext' signal, not webview. See:
705705
// https://webkitgtk.org/reference/webkit2gtk/stable/WebKitWebContext.html#WebKitWebContext-download-started
706-
OS.g_signal_connect (WebKitGTK.webkit_web_context_get_default(), WebKitGTK.download_started, Proc3.getAddress (), DOWNLOAD_STARTED);
706+
if (GTK.GTK4) {
707+
OS.g_signal_connect (WebKitGTK.webkit_network_session_get_default(), WebKitGTK.download_started, Proc3.getAddress (), DOWNLOAD_STARTED);
708+
} else {
709+
OS.g_signal_connect (WebKitGTK.webkit_web_context_get_default(), WebKitGTK.download_started, Proc3.getAddress (), DOWNLOAD_STARTED);
710+
}
707711

708712
GTK.gtk_widget_show (webView);
709713
GTK.gtk_widget_show (browser.handle);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2021 IBM Corporation and others. All rights reserved.
2+
* Copyright (c) 2000, 2025 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
@@ -359,6 +359,9 @@ public class WebKitGTK extends C {
359359
/** @method flags=dynamic */
360360
public static final native long webkit_web_context_get_default();
361361

362+
/** @method flags=dynamic */
363+
public static final native long webkit_network_session_get_default();
364+
362365
/** @method flags=dynamic */
363366
public static final native long webkit_web_context_get_cookie_manager(long context);
364367

0 commit comments

Comments
 (0)