Allow usage of static loader with wxWebViewEdge

Add a new build option wxUSE_WEBVIEW_EDGE_STATIC.
If it is set to 1 the WebView2 loader is static linked into the binary
and removes the runtime dependency on WebView2Loader.dll.
This commit is contained in:
Tobias Taschner
2022-02-02 22:39:28 +01:00
committed by Tobias Taschner
parent f0c6b42ad0
commit 57ebad4f7d
15 changed files with 95 additions and 5 deletions

View File

@@ -184,6 +184,22 @@
<if cond="TOOLKIT=='MSW' and IS_MSVC=='0'">$(TOP_SRCDIR)include/wx/msw/wrl</if> <if cond="TOOLKIT=='MSW' and IS_MSVC=='0'">$(TOP_SRCDIR)include/wx/msw/wrl</if>
</set> </set>
<set var="webview_additional_libdirs_arch">
<if cond="TARGET_CPU=='amd64'">x64</if>
<if cond="TARGET_CPU=='AMD64'">x64</if>
<if cond="TARGET_CPU=='arm64'">arm64</if>
<if cond="TARGET_CPU=='ARM64'">arm64</if>
<if cond="TARGET_CPU=='x64'">x64</if>
<if cond="TARGET_CPU=='X64'">x64</if>
<if cond="TARGET_CPU=='x86'">x86</if>
<if cond="TARGET_CPU=='X86'">x86</if>
<if cond="TARGET_CPU==''">x86</if>
</set>
<set var="webview_additional_libdirs">
<if cond="IS_MSVC=='1' and TOOLKIT=='MSW'">$(TOP_SRCDIR)3rdparty/webview2/build/native/$(webview_additional_libdirs_arch)</if>
</set>
<set var="webview_edge_pragma_warning"> <set var="webview_edge_pragma_warning">
<if cond="TOOLKIT=='MSW' and IS_MSVC=='0'">-Wno-unknown-pragmas</if> <if cond="TOOLKIT=='MSW' and IS_MSVC=='0'">-Wno-unknown-pragmas</if>
</set> </set>
@@ -195,6 +211,7 @@
<sources>$(WEBVIEW_SRC)</sources> <sources>$(WEBVIEW_SRC)</sources>
<library>coredll</library> <library>coredll</library>
<library>basedll</library> <library>basedll</library>
<lib-path>$(webview_additional_libdirs)</lib-path>
<ldlibs>$(EXTRALIBS_WEBVIEW)</ldlibs> <ldlibs>$(EXTRALIBS_WEBVIEW)</ldlibs>
<msvc-headers>$(WEBVIEW_HDR)</msvc-headers> <msvc-headers>$(WEBVIEW_HDR)</msvc-headers>
<include>$(webview_additional_include_wrl)</include> <include>$(webview_additional_include_wrl)</include>
@@ -208,6 +225,7 @@
<msvc-headers>$(WEBVIEW_HDR)</msvc-headers> <msvc-headers>$(WEBVIEW_HDR)</msvc-headers>
<include>$(webview_additional_include_wrl)</include> <include>$(webview_additional_include_wrl)</include>
<include>$(webview_additional_include)</include> <include>$(webview_additional_include)</include>
<lib-path>$(webview_additional_libdirs)</lib-path>
<cxxflags-mingw>$(webview_edge_pragma_warning)</cxxflags-mingw> <cxxflags-mingw>$(webview_edge_pragma_warning)</cxxflags-mingw>
</lib> </lib>

View File

@@ -87,7 +87,12 @@ elseif(WXMSW)
endif() endif()
endif() endif()
wx_webview_copy_webview2_loader(wxwebview) if (wxUSE_WEBVIEW_EDGE_STATIC)
target_link_directories(wxwebview PUBLIC "${WEBVIEW2_PACKAGE_DIR}/build/native/$(LibrariesArchitecture)/")
else()
wx_webview_copy_webview2_loader(wxwebview)
endif()
endif() endif()
elseif(WXGTK) elseif(WXGTK)
if(LIBSOUP_FOUND) if(LIBSOUP_FOUND)

View File

@@ -477,6 +477,7 @@ if(WIN32)
wx_option(wxUSE_TASKBARICON_BALLOONS "enable wxTaskBarIcon::ShowBalloon() method (Win32 only)") wx_option(wxUSE_TASKBARICON_BALLOONS "enable wxTaskBarIcon::ShowBalloon() method (Win32 only)")
wx_option(wxUSE_UXTHEME "enable support for Windows XP themed look (Win32 only)") wx_option(wxUSE_UXTHEME "enable support for Windows XP themed look (Win32 only)")
wx_option(wxUSE_WEBVIEW_EDGE "use wxWebView Edge (Chromium) backend (Windows 7+ only)" ${wxUSE_WEBVIEW_EDGE_DEFAULT}) wx_option(wxUSE_WEBVIEW_EDGE "use wxWebView Edge (Chromium) backend (Windows 7+ only)" ${wxUSE_WEBVIEW_EDGE_DEFAULT})
wx_option(wxUSE_WEBVIEW_EDGE_STATIC "use wxWebView Edge with static loader" OFF)
wx_option(wxUSE_WEBVIEW_IE "use wxWebView IE backend (Win32 only)") wx_option(wxUSE_WEBVIEW_IE "use wxWebView IE backend (Win32 only)")
wx_option(wxUSE_WINRT "enable WinRT support" ${wxUSE_WINRT_DEFAULT}) wx_option(wxUSE_WINRT "enable WinRT support" ${wxUSE_WINRT_DEFAULT})
wx_option(wxUSE_WXDIB "use wxDIB class (Win32 only)") wx_option(wxUSE_WXDIB "use wxDIB class (Win32 only)")

View File

@@ -332,6 +332,8 @@
#cmakedefine01 wxUSE_WEBVIEW_EDGE #cmakedefine01 wxUSE_WEBVIEW_EDGE
#cmakedefine01 wxUSE_WEBVIEW_EDGE_STATIC
#if (defined(__WXGTK__) && !defined(__WXGTK3__)) || defined(__WXOSX__) #if (defined(__WXGTK__) && !defined(__WXGTK3__)) || defined(__WXOSX__)
#cmakedefine01 wxUSE_WEBVIEW_WEBKIT #cmakedefine01 wxUSE_WEBVIEW_WEBKIT
#else #else

View File

@@ -350,7 +350,7 @@
<AdditionalDependencies>wxtiff$(wxSuffixDebug).lib;wxjpeg$(wxSuffixDebug).lib;wxpng$(wxSuffixDebug).lib;wxzlib$(wxSuffixDebug).lib;wxregex$(wxSuffix).lib;wxexpat$(wxSuffixDebug).lib;$(wxToolkitLibNamePrefix)core.lib;$(wxBaseLibNamePrefix).lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>wxtiff$(wxSuffixDebug).lib;wxjpeg$(wxSuffixDebug).lib;wxpng$(wxSuffixDebug).lib;wxzlib$(wxSuffixDebug).lib;wxregex$(wxSuffix).lib;wxexpat$(wxSuffixDebug).lib;$(wxToolkitLibNamePrefix)core.lib;$(wxBaseLibNamePrefix).lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImportLibrary>$(OutDir)$(wxToolkitLibNamePrefix)$(ProjectName).lib</ImportLibrary> <ImportLibrary>$(OutDir)$(wxToolkitLibNamePrefix)$(ProjectName).lib</ImportLibrary>
<SuppressStartupBanner>true</SuppressStartupBanner> <SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(OutDir);..\..\3rdparty\webview2\build\native\$(LibrariesArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>true</GenerateDebugInformation> <GenerateDebugInformation>true</GenerateDebugInformation>
</Link> </Link>
<Bscmake> <Bscmake>
@@ -435,7 +435,7 @@
<AdditionalDependencies>wxtiff$(wxSuffixDebug).lib;wxjpeg$(wxSuffixDebug).lib;wxpng$(wxSuffixDebug).lib;wxzlib$(wxSuffixDebug).lib;wxregex$(wxSuffix).lib;wxexpat$(wxSuffixDebug).lib;$(wxToolkitLibNamePrefix)core.lib;$(wxBaseLibNamePrefix).lib;%(AdditionalDependencies)</AdditionalDependencies> <AdditionalDependencies>wxtiff$(wxSuffixDebug).lib;wxjpeg$(wxSuffixDebug).lib;wxpng$(wxSuffixDebug).lib;wxzlib$(wxSuffixDebug).lib;wxregex$(wxSuffix).lib;wxexpat$(wxSuffixDebug).lib;$(wxToolkitLibNamePrefix)core.lib;$(wxBaseLibNamePrefix).lib;%(AdditionalDependencies)</AdditionalDependencies>
<ImportLibrary>$(OutDir)$(wxToolkitLibNamePrefix)$(ProjectName).lib</ImportLibrary> <ImportLibrary>$(OutDir)$(wxToolkitLibNamePrefix)$(ProjectName).lib</ImportLibrary>
<SuppressStartupBanner>true</SuppressStartupBanner> <SuppressStartupBanner>true</SuppressStartupBanner>
<AdditionalLibraryDirectories>$(OutDir);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> <AdditionalLibraryDirectories>$(OutDir);..\..\3rdparty\webview2\build\native\$(LibrariesArchitecture);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<GenerateDebugInformation>false</GenerateDebugInformation> <GenerateDebugInformation>false</GenerateDebugInformation>
<OptimizeReferences>true</OptimizeReferences> <OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding> <EnableCOMDATFolding>true</EnableCOMDATFolding>

View File

@@ -802,6 +802,13 @@
// Recommended setting: 1 when building for Windows with WebView2 SDK // Recommended setting: 1 when building for Windows with WebView2 SDK
#define wxUSE_WEBVIEW_EDGE 0 #define wxUSE_WEBVIEW_EDGE 0
// Use the Edge (Chromium) wxWebView backend without loader DLL
//
// Default is 0, set it to 1 if you don't want to depend on WebView2Loader.dll.
//
// Recommended setting: 0
#define wxUSE_WEBVIEW_EDGE_STATIC 0
// Use the WebKit wxWebView backend // Use the WebKit wxWebView backend
// //
// Default is 1 on GTK and OSX // Default is 1 on GTK and OSX

View File

@@ -803,6 +803,13 @@
// Recommended setting: 1 when building for Windows with WebView2 SDK // Recommended setting: 1 when building for Windows with WebView2 SDK
#define wxUSE_WEBVIEW_EDGE 0 #define wxUSE_WEBVIEW_EDGE 0
// Use the Edge (Chromium) wxWebView backend without loader DLL
//
// Default is 0, set it to 1 if you don't want to depend on WebView2Loader.dll.
//
// Recommended setting: 0
#define wxUSE_WEBVIEW_EDGE_STATIC 0
// Use the WebKit wxWebView backend // Use the WebKit wxWebView backend
// //
// Default is 1 on GTK and OSX // Default is 1 on GTK and OSX

View File

@@ -803,6 +803,13 @@
// Recommended setting: 1 when building for Windows with WebView2 SDK // Recommended setting: 1 when building for Windows with WebView2 SDK
#define wxUSE_WEBVIEW_EDGE 0 #define wxUSE_WEBVIEW_EDGE 0
// Use the Edge (Chromium) wxWebView backend without loader DLL
//
// Default is 0, set it to 1 if you don't want to depend on WebView2Loader.dll.
//
// Recommended setting: 0
#define wxUSE_WEBVIEW_EDGE_STATIC 0
// Use the WebKit wxWebView backend // Use the WebKit wxWebView backend
// //
// Default is 1 on GTK and OSX // Default is 1 on GTK and OSX

View File

@@ -10,7 +10,9 @@
#ifndef wxWebViewEdge_PRIVATE_H #ifndef wxWebViewEdge_PRIVATE_H
#define wxWebViewEdge_PRIVATE_H #define wxWebViewEdge_PRIVATE_H
#if !wxUSE_WEBVIEW_EDGE_STATIC
#include "wx/dynlib.h" #include "wx/dynlib.h"
#endif
#include "wx/msw/private/comptr.h" #include "wx/msw/private/comptr.h"
#include <WebView2.h> #include <WebView2.h>
@@ -98,7 +100,9 @@ public:
void UpdateWebMessageHandler(); void UpdateWebMessageHandler();
#if !wxUSE_WEBVIEW_EDGE_STATIC
static wxDynamicLibrary ms_loaderDll; static wxDynamicLibrary ms_loaderDll;
#endif
static wxString ms_browserExecutableDir; static wxString ms_browserExecutableDir;
static bool Initialize(); static bool Initialize();

View File

@@ -809,6 +809,13 @@
// Recommended setting: 1 when building for Windows with WebView2 SDK // Recommended setting: 1 when building for Windows with WebView2 SDK
#define wxUSE_WEBVIEW_EDGE 0 #define wxUSE_WEBVIEW_EDGE 0
// Use the Edge (Chromium) wxWebView backend without loader DLL
//
// Default is 0, set it to 1 if you don't want to depend on WebView2Loader.dll.
//
// Recommended setting: 0
#define wxUSE_WEBVIEW_EDGE_STATIC 0
// Use the WebKit wxWebView backend // Use the WebKit wxWebView backend
// //
// Default is 1 on GTK and OSX // Default is 1 on GTK and OSX

View File

@@ -799,6 +799,13 @@
// Recommended setting: 1 when building for Windows with WebView2 SDK // Recommended setting: 1 when building for Windows with WebView2 SDK
#define wxUSE_WEBVIEW_EDGE 0 #define wxUSE_WEBVIEW_EDGE 0
// Use the Edge (Chromium) wxWebView backend without loader DLL
//
// Default is 0, set it to 1 if you don't want to depend on WebView2Loader.dll.
//
// Recommended setting: 0
#define wxUSE_WEBVIEW_EDGE_STATIC 0
// Use the WebKit wxWebView backend // Use the WebKit wxWebView backend
// //
// Default is 1 on GTK and OSX // Default is 1 on GTK and OSX

View File

@@ -802,6 +802,13 @@
// Recommended setting: 1 when building for Windows with WebView2 SDK // Recommended setting: 1 when building for Windows with WebView2 SDK
#define wxUSE_WEBVIEW_EDGE 0 #define wxUSE_WEBVIEW_EDGE 0
// Use the Edge (Chromium) wxWebView backend without loader DLL
//
// Default is 0, set it to 1 if you don't want to depend on WebView2Loader.dll.
//
// Recommended setting: 0
#define wxUSE_WEBVIEW_EDGE_STATIC 0
// Use the WebKit wxWebView backend // Use the WebKit wxWebView backend
// //
// Default is 1 on GTK and OSX // Default is 1 on GTK and OSX

View File

@@ -362,6 +362,9 @@ public:
loaded and Edge (Chromium) is installed) loaded and Edge (Chromium) is installed)
- Make sure to add a note about using the WebView2 SDK to your application - Make sure to add a note about using the WebView2 SDK to your application
documentation, as required by its licence documentation, as required by its licence
- With Visual Studio 2019 or newer @c wxUSE_WEBVIEW_EDGE_STATIC can be used
to static link the loader and remove the dependency on @c WebView2Loader.dll
at runtime.
If enabled and available at runtime Edge will be selected as the default If enabled and available at runtime Edge will be selected as the default
backend. If you require the IE backend use @c wxWebViewBackendIE when backend. If you require the IE backend use @c wxWebViewBackendIE when

View File

@@ -332,6 +332,8 @@
#define wxUSE_WEBVIEW_EDGE 0 #define wxUSE_WEBVIEW_EDGE 0
#define wxUSE_WEBVIEW_EDGE_STATIC 0
#if (defined(__WXGTK__) && !defined(__WXGTK3__)) || defined(__WXOSX__) #if (defined(__WXGTK__) && !defined(__WXGTK3__)) || defined(__WXOSX__)
#define wxUSE_WEBVIEW_WEBKIT 0 #define wxUSE_WEBVIEW_WEBKIT 0
#else #else

View File

@@ -42,6 +42,13 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxWebViewEdge, wxWebView);
event.SetInt(wxerror); \ event.SetInt(wxerror); \
break; break;
#if wxUSE_WEBVIEW_EDGE_STATIC
#define wxCreateCoreWebView2EnvironmentWithOptions ::CreateCoreWebView2EnvironmentWithOptions
#define wxGetAvailableCoreWebView2BrowserVersionString ::GetAvailableCoreWebView2BrowserVersionString
// Automatically link the static loader lib with MSVC
#pragma comment(lib, "WebView2LoaderStatic")
#else
// WebView2Loader typedefs // WebView2Loader typedefs
typedef HRESULT (__stdcall *CreateCoreWebView2EnvironmentWithOptions_t)( typedef HRESULT (__stdcall *CreateCoreWebView2EnvironmentWithOptions_t)(
PCWSTR browserExecutableFolder, PCWSTR browserExecutableFolder,
@@ -54,8 +61,9 @@ typedef HRESULT(__stdcall *GetAvailableCoreWebView2BrowserVersionString_t)(
CreateCoreWebView2EnvironmentWithOptions_t wxCreateCoreWebView2EnvironmentWithOptions = NULL; CreateCoreWebView2EnvironmentWithOptions_t wxCreateCoreWebView2EnvironmentWithOptions = NULL;
GetAvailableCoreWebView2BrowserVersionString_t wxGetAvailableCoreWebView2BrowserVersionString = NULL; GetAvailableCoreWebView2BrowserVersionString_t wxGetAvailableCoreWebView2BrowserVersionString = NULL;
wxDynamicLibrary wxWebViewEdgeImpl::ms_loaderDll; wxDynamicLibrary wxWebViewEdgeImpl::ms_loaderDll;
#endif // wxUSE_WEBVIEW_EDGE_STATIC
wxString wxWebViewEdgeImpl::ms_browserExecutableDir; wxString wxWebViewEdgeImpl::ms_browserExecutableDir;
wxWebViewEdgeImpl::wxWebViewEdgeImpl(wxWebViewEdge* webview): wxWebViewEdgeImpl::wxWebViewEdgeImpl(wxWebViewEdge* webview):
@@ -132,6 +140,7 @@ HRESULT wxWebViewEdgeImpl::OnEnvironmentCreated(
bool wxWebViewEdgeImpl::Initialize() bool wxWebViewEdgeImpl::Initialize()
{ {
#if !wxUSE_WEBVIEW_EDGE_STATIC
if (ms_loaderDll.IsLoaded()) if (ms_loaderDll.IsLoaded())
return true; return true;
@@ -144,7 +153,7 @@ bool wxWebViewEdgeImpl::Initialize()
wxDL_INIT_FUNC(wx, GetAvailableCoreWebView2BrowserVersionString, loaderDll); wxDL_INIT_FUNC(wx, GetAvailableCoreWebView2BrowserVersionString, loaderDll);
if (!wxGetAvailableCoreWebView2BrowserVersionString || !wxCreateCoreWebView2EnvironmentWithOptions) if (!wxGetAvailableCoreWebView2BrowserVersionString || !wxCreateCoreWebView2EnvironmentWithOptions)
return false; return false;
#endif
// Check if a Edge browser can be found by the loader DLL // Check if a Edge browser can be found by the loader DLL
wxCoTaskMemPtr<wchar_t> versionStr; wxCoTaskMemPtr<wchar_t> versionStr;
HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString( HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString(
@@ -155,14 +164,18 @@ bool wxWebViewEdgeImpl::Initialize()
return false; return false;
} }
#if !wxUSE_WEBVIEW_EDGE_STATIC
ms_loaderDll.Attach(loaderDll.Detach()); ms_loaderDll.Attach(loaderDll.Detach());
#endif
return true; return true;
} }
void wxWebViewEdgeImpl::Uninitialize() void wxWebViewEdgeImpl::Uninitialize()
{ {
#if !wxUSE_WEBVIEW_EDGE_STATIC
ms_loaderDll.Unload(); ms_loaderDll.Unload();
#endif
} }
void wxWebViewEdgeImpl::UpdateBounds() void wxWebViewEdgeImpl::UpdateBounds()