Skip to content

Commit 121741a

Browse files
committed
Fix Browser.setCookie on WebkitGtk/Soup3
Soup 3.x switched away from its own SoupURI to Glib's GUri (see https://libsoup.gnome.org/libsoup-3.0/migrating-from-libsoup-2.html#uri-type-changed ). Thus g_uri_parse have to be used instead of soup_uri_new.
1 parent d53701b commit 121741a

File tree

8 files changed

+83
-6
lines changed

8 files changed

+83
-6
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12648,6 +12648,33 @@ JNIEXPORT void JNICALL OS_NATIVE(g_1unsetenv)
1264812648
}
1264912649
#endif
1265012650

12651+
#ifndef NO_g_1uri_1parse
12652+
JNIEXPORT jlong JNICALL OS_NATIVE(g_1uri_1parse)
12653+
(JNIEnv *env, jclass that, jbyteArray arg0, jlong arg1, jlongArray arg2)
12654+
{
12655+
jbyte *lparg0=NULL;
12656+
jlong *lparg2=NULL;
12657+
jlong rc = 0;
12658+
OS_NATIVE_ENTER(env, that, g_1uri_1parse_FUNC);
12659+
if (arg0) if ((lparg0 = (*env)->GetByteArrayElements(env, arg0, NULL)) == NULL) goto fail;
12660+
if (arg2) if ((lparg2 = (*env)->GetLongArrayElements(env, arg2, NULL)) == NULL) goto fail;
12661+
/*
12662+
rc = (jlong)g_uri_parse((const gchar *)lparg0, arg1, (GError **)lparg2);
12663+
*/
12664+
{
12665+
OS_LOAD_FUNCTION(fp, g_uri_parse)
12666+
if (fp) {
12667+
rc = (jlong)((jlong (CALLING_CONVENTION*)(const gchar *, jlong, GError **))fp)((const gchar *)lparg0, arg1, (GError **)lparg2);
12668+
}
12669+
}
12670+
fail:
12671+
if (arg2 && lparg2) (*env)->ReleaseLongArrayElements(env, arg2, lparg2, 0);
12672+
if (arg0 && lparg0) (*env)->ReleaseByteArrayElements(env, arg0, lparg0, 0);
12673+
OS_NATIVE_EXIT(env, that, g_1uri_1parse_FUNC);
12674+
return rc;
12675+
}
12676+
#endif
12677+
1265112678
#ifndef NO_g_1utf16_1offset_1to_1pointer
1265212679
JNIEXPORT jlong JNICALL OS_NATIVE(g_1utf16_1offset_1to_1pointer)
1265312680
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#define ubuntu_menu_proxy_get_LIB LIB_GTK
6060
#define FcConfigAppFontAddFile_LIB LIB_FONTCONFIG
6161
#define pango_attr_insert_hyphens_new_LIB LIB_PANGO
62+
#define g_uri_parse_LIB LIB_GLIB
6263

6364
/* Field accessors */
6465
#define G_OBJECT_CLASS_CONSTRUCTOR(arg0) (arg0)->constructor

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ typedef enum {
10211021
g_1type_1parent_FUNC,
10221022
g_1type_1register_1static_FUNC,
10231023
g_1unsetenv_FUNC,
1024+
g_1uri_1parse_FUNC,
10241025
g_1utf16_1offset_1to_1pointer_FUNC,
10251026
g_1utf16_1offset_1to_1utf8_1offset_FUNC,
10261027
g_1utf16_1pointer_1to_1offset_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,14 @@ public static boolean isX11 () {
14101410
* @param variable cast=(const gchar *),flags=no_out
14111411
*/
14121412
public static final native void g_unsetenv(byte [] variable);
1413+
1414+
/**
1415+
* @method flags=dynamic
1416+
* @param uri_string cast=(const gchar *)
1417+
* @param flags
1418+
* @param error cast=(GError **)
1419+
*/
1420+
public static final native long g_uri_parse (byte[] uri_string, long flags, long[] error);
14131421
/** @method flags=const */
14141422
public static final native int glib_major_version();
14151423
/** @method flags=const */

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2022 IBM Corporation and others. All rights reserved.
2+
* Copyright (c) 2009, 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
@@ -307,6 +307,26 @@ JNIEXPORT jlong JNICALL WebKitGTK_NATIVE(soup_1cookie_1parse)
307307
}
308308
#endif
309309

310+
#ifndef NO_soup_1get_1major_1version
311+
JNIEXPORT jint JNICALL WebKitGTK_NATIVE(soup_1get_1major_1version)
312+
(JNIEnv *env, jclass that)
313+
{
314+
jint rc = 0;
315+
WebKitGTK_NATIVE_ENTER(env, that, soup_1get_1major_1version_FUNC);
316+
/*
317+
rc = (jint)soup_get_major_version();
318+
*/
319+
{
320+
WebKitGTK_LOAD_FUNCTION(fp, soup_get_major_version)
321+
if (fp) {
322+
rc = (jint)((jint (CALLING_CONVENTION*)())fp)();
323+
}
324+
}
325+
WebKitGTK_NATIVE_EXIT(env, that, soup_1get_1major_1version_FUNC);
326+
return rc;
327+
}
328+
#endif
329+
310330
#ifndef NO_soup_1message_1headers_1append
311331
JNIEXPORT void JNICALL WebKitGTK_NATIVE(soup_1message_1headers_1append)
312332
(JNIEnv *env, jclass that, jlong arg0, jbyteArray 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, 2023 IBM Corporation and others. All rights reserved.
2+
* Copyright (c) 2009, 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
@@ -37,6 +37,7 @@ typedef enum {
3737
soup_1cookie_1get_1name_FUNC,
3838
soup_1cookie_1get_1value_FUNC,
3939
soup_1cookie_1parse_FUNC,
40+
soup_1get_1major_1version_FUNC,
4041
soup_1message_1headers_1append_FUNC,
4142
soup_1uri_1free_FUNC,
4243
soup_1uri_1new_FUNC,

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,10 +1127,26 @@ static boolean setCookie(String cookieUrl, String cookieValue) {
11271127
long context = WebKitGTK.webkit_web_context_get_default();
11281128
long cookieManager = WebKitGTK.webkit_web_context_get_cookie_manager(context);
11291129
byte[] bytes = Converter.wcsToMbcs (cookieUrl, true);
1130-
long uri = WebKitGTK.soup_uri_new (bytes);
1131-
if (uri == 0) {
1132-
System.err.println("SWT WebKit: SoupURI == 0 when setting cookie");
1133-
return false;
1130+
long uri;
1131+
if (WebKitGTK.soup_get_major_version()==2) {
1132+
uri = WebKitGTK.soup_uri_new (bytes);
1133+
if (uri == 0) {
1134+
System.err.println("SWT WebKit: SoupURI == 0 when setting cookie");
1135+
return false;
1136+
}
1137+
} else {
1138+
long [] error = new long [1];
1139+
uri = OS.g_uri_parse(bytes, 0, error);
1140+
if (uri == 0) {
1141+
long errorMessageC = OS.g_error_get_message(error[0]);
1142+
String errorMessageStr = Converter.cCharPtrToJavaString(errorMessageC, false);
1143+
OS.g_error_free(error[0]);
1144+
System.err.format(
1145+
"SWT WebKit: Failed to parse cookie URI: %s%n",
1146+
errorMessageStr);
1147+
return false;
1148+
}
1149+
11341150
}
11351151
bytes = Converter.wcsToMbcs (cookieValue, true);
11361152
long soupCookie = WebKitGTK.soup_cookie_parse (bytes, uri);

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
@@ -226,6 +226,9 @@ public class WebKitGTK extends C {
226226
/** @method flags=dynamic */
227227
public static final native long soup_uri_new(byte[] uri_string);
228228

229+
/** @method flags=dynamic */
230+
public static final native int soup_get_major_version();
231+
229232
/* --------------------- start WebKitGTK natives --------------------- */
230233

231234
/** @method flags=dynamic */

0 commit comments

Comments
 (0)