Patch-Source: https://github.com/wxWidgets/wxWidgets/pull/23633
--
From 1b8664426603376b68f8ca3c54de97ec630e5940 Mon Sep 17 00:00:00 2001
From: Scott Talbert <swt@techie.net>
Date: Mon, 12 Jun 2023 20:28:35 -0400
Subject: [PATCH 1/2] Add support for building WebView with libwebkit2gtk-4.1

libwebkit2gtk-4.1 has the same API as libwebkit2gtk-4.0, except that the
former links with libsoup-3.0 and the latter links with libsoup-2.4.

Fixes #23630.
---
 build/cmake/init.cmake                |    10 +-
 build/cmake/modules/FindLIBSOUP.cmake |    14 +-
 build/cmake/modules/FindWEBKIT2.cmake |     5 +-
 configure                             | 14270 +++++++++++++-----------
 configure.in                          |    16 +-
 src/gtk/webview_webkit2.cpp           |     4 +
 6 files changed, 7892 insertions(+), 6427 deletions(-)

diff --git a/build/cmake/init.cmake b/build/cmake/init.cmake
index 16ffc0f03593..c9604fb48b76 100644
--- a/build/cmake/init.cmake
+++ b/build/cmake/init.cmake
@@ -444,15 +444,21 @@ if(wxUSE_GUI)
     if(wxUSE_WEBVIEW)
         if(WXGTK)
             if(wxUSE_WEBVIEW_WEBKIT)
-                find_package(LIBSOUP)
+                set(WEBKIT_LIBSOUP_VERSION 2.4)
                 if(WXGTK2)
                     find_package(WEBKIT 1.0)
                 elseif(WXGTK3)
-                    find_package(WEBKIT2)
+                    find_package(WEBKIT2 4.1)
+                    if(WEBKIT2_FOUND)
+                        set(WEBKIT_LIBSOUP_VERSION 3.0)
+                    else()
+                        find_package(WEBKIT2 4.0)
+                    endif()
                     if(NOT WEBKIT2_FOUND)
                         find_package(WEBKIT 3.0)
                     endif()
                 endif()
+                find_package(LIBSOUP ${WEBKIT_LIBSOUP_VERSION})
             endif()
             set(wxUSE_WEBVIEW_WEBKIT OFF)
             set(wxUSE_WEBVIEW_WEBKIT2 OFF)
diff --git a/build/cmake/modules/FindLIBSOUP.cmake b/build/cmake/modules/FindLIBSOUP.cmake
index cbfba1cf9366..2433d141eaf7 100644
--- a/build/cmake/modules/FindLIBSOUP.cmake
+++ b/build/cmake/modules/FindLIBSOUP.cmake
@@ -31,19 +31,27 @@
 # LibSoup does not provide an easy way to retrieve its version other than its
 # .pc file, so we need to rely on PC_LIBSOUP_VERSION and REQUIRE the .pc file
 # to be found.
+SET(LIBSOUP_VERSION 2.4)
+if(DEFINED LIBSOUP_FIND_VERSION)
+    SET(LIBSOUP_VERSION ${LIBSOUP_FIND_VERSION})
+endif()
+
+set(LIBSOUP_INCLUDE_DIRS LIBSOUP_INCLUDE_DIRS-NOTFOUND)
+set(LIBSOUP_LIBRARIES LIBSOUP_LIBRARIES-NOTFOUND)
+
 FIND_PACKAGE(PkgConfig)
-PKG_CHECK_MODULES(PC_LIBSOUP QUIET libsoup-2.4)
+PKG_CHECK_MODULES(PC_LIBSOUP QUIET libsoup-${LIBSOUP_VERSION})
 
 if(PC_LIBSOUP_FOUND)
     FIND_PATH(LIBSOUP_INCLUDE_DIRS
         NAMES libsoup/soup.h
         HINTS ${PC_LIBSOUP_INCLUDEDIR}
         ${PC_LIBSOUP_INCLUDE_DIRS}
-        PATH_SUFFIXES libsoup-2.4
+        PATH_SUFFIXES libsoup-${LIBSOUP_VERSION}
         )
 
     FIND_LIBRARY(LIBSOUP_LIBRARIES
-        NAMES soup-2.4
+        NAMES soup-${LIBSOUP_VERSION}
         HINTS ${PC_LIBSOUP_LIBDIR}
         ${PC_LIBSOUP_LIBRARY_DIRS}
         )
diff --git a/build/cmake/modules/FindWEBKIT2.cmake b/build/cmake/modules/FindWEBKIT2.cmake
index 133e7a4563ea..e39077ac4a71 100644
--- a/build/cmake/modules/FindWEBKIT2.cmake
+++ b/build/cmake/modules/FindWEBKIT2.cmake
@@ -5,7 +5,10 @@
 #  WEBKIT2_LIBRARIES   - List of libraries when using Webkit2.
 #  WEBKIT2_FOUND       - True if Webkit2 found.
 
-SET( WEBKIT2_VERSION 4.0)
+SET(WEBKIT2_VERSION 4.0)
+if(DEFINED WEBKIT2_FIND_VERSION)
+    SET(WEBKIT2_VERSION ${WEBKIT2_FIND_VERSION})
+endif()
 
 set(WEBKIT2_INCLUDE_DIR WEBKIT2_INCLUDE_DIR-NOTFOUND)
 set(WEBKIT2_LIBRARY WEBKIT2_LIBRARY-NOTFOUND)
diff --git a/src/gtk/webview_webkit2.cpp b/src/gtk/webview_webkit2.cpp
index 41b4cbe2874b..a50525dedd8c 100644
--- a/src/gtk/webview_webkit2.cpp
+++ b/src/gtk/webview_webkit2.cpp
@@ -252,15 +252,18 @@ wxgtk_webview_webkit_load_failed(WebKitWebView *,
     {
         switch (error->code)
         {
+#if SOUP_MAJOR_VERSION < 3
             case SOUP_STATUS_CANCELLED:
                 type = wxWEBVIEW_NAV_ERR_USER_CANCELLED;
                 break;
 
             case SOUP_STATUS_CANT_RESOLVE:
+#endif
             case SOUP_STATUS_NOT_FOUND:
                 type = wxWEBVIEW_NAV_ERR_NOT_FOUND;
                 break;
 
+#if SOUP_MAJOR_VERSION < 3
             case SOUP_STATUS_CANT_RESOLVE_PROXY:
             case SOUP_STATUS_CANT_CONNECT:
             case SOUP_STATUS_CANT_CONNECT_PROXY:
@@ -272,6 +275,7 @@ wxgtk_webview_webkit_load_failed(WebKitWebView *,
             case SOUP_STATUS_MALFORMED:
                 type = wxWEBVIEW_NAV_ERR_REQUEST;
                 break;
+#endif
 
             case SOUP_STATUS_BAD_REQUEST:
                 type = wxWEBVIEW_NAV_ERR_REQUEST;

