Allow using a fixed version with wxWebViewEdge

A fixed version may be distributed with the application
and wxWebViewEdge::MSWSetBrowserExecutableDir() allows
it's usage with wxWebViewEdge.
This commit is contained in:
Tobias Taschner
2021-02-03 16:12:25 +01:00
parent 49fcd34335
commit 489afb3336
5 changed files with 32 additions and 2 deletions

View File

@@ -66,6 +66,7 @@ public:
ICoreWebView2Settings* GetSettings();
static wxDynamicLibrary ms_loaderDll;
static wxString ms_browserExecutableDir;
static bool Initialize();

View File

@@ -122,6 +122,8 @@ public:
virtual void* GetNativeBackend() const wxOVERRIDE;
static void MSWSetBrowserExecutableDir(const wxString& path);
protected:
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) wxOVERRIDE;

View File

@@ -330,6 +330,12 @@ public:
- Make sure to add a note about using the WebView2 SDK to your application
documentation, as required by its licence
If your application should use a
<a href="https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/distribution#fixed-version-distribution-mode">
fixed version</a> of the WebView2 runtime you must use
wxWebViewEdge::MSWSetBrowserExecutableDir() to specify its usage before
using the edge backend.
@par wxWEBVIEW_WEBKIT (GTK)
Under GTK the WebKit backend uses

View File

@@ -30,6 +30,9 @@
#if wxUSE_WEBVIEW_IE
#include "wx/msw/webview_ie.h"
#endif
#if wxUSE_WEBVIEW_EDGE
#include "wx/msw/webview_edge.h"
#endif
#include "wx/webviewarchivehandler.h"
#include "wx/webviewfshandler.h"
#include "wx/numdlg.h"
@@ -37,6 +40,7 @@
#include "wx/filesys.h"
#include "wx/fs_arc.h"
#include "wx/fs_mem.h"
#include "wx/stdpaths.h"
#ifndef wxHAS_IMAGES_IN_RESOURCES
#include "../sample.xpm"
@@ -373,6 +377,16 @@ WebFrame::WebFrame(const wxString& url) :
// Create the webview
wxString backend = wxWebViewBackendDefault;
#ifdef __WXMSW__
// Check if a fixed version of edge is present in
// $executable_path/edge_fixed and use it
wxFileName edgeFixedDir(wxStandardPaths::Get().GetExecutablePath());
edgeFixedDir.SetFullName("");
edgeFixedDir.AppendDir("edge_fixed");
if (edgeFixedDir.DirExists())
{
wxWebViewEdge::MSWSetBrowserExecutableDir(edgeFixedDir.GetFullPath());
wxLogMessage("Using fixed edge version");
}
if (wxWebView::IsBackendAvailable(wxWebViewBackendEdge))
{
wxLogMessage("Using Edge backend");

View File

@@ -52,6 +52,7 @@ CreateCoreWebView2EnvironmentWithOptions_t wxCreateCoreWebView2EnvironmentWithOp
GetAvailableCoreWebView2BrowserVersionString_t wxGetAvailableCoreWebView2BrowserVersionString = NULL;
wxDynamicLibrary wxWebViewEdgeImpl::ms_loaderDll;
wxString wxWebViewEdgeImpl::ms_browserExecutableDir;
wxWebViewEdgeImpl::wxWebViewEdgeImpl(wxWebViewEdge* webview):
m_ctrl(webview)
@@ -85,7 +86,7 @@ bool wxWebViewEdgeImpl::Create()
wxString userDataPath = wxStandardPaths::Get().GetUserLocalDataDir();
HRESULT hr = wxCreateCoreWebView2EnvironmentWithOptions(
nullptr,
ms_browserExecutableDir.wc_str(),
userDataPath.wc_str(),
nullptr,
Callback<ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler>(this,
@@ -127,7 +128,8 @@ bool wxWebViewEdgeImpl::Initialize()
// Check if a Edge browser can be found by the loader DLL
wxCoTaskMemPtr<wchar_t> versionStr;
HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString(NULL, &versionStr);
HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString(
ms_browserExecutableDir.wc_str(), &versionStr);
if (FAILED(hr) || !versionStr)
{
wxLogApiError("GetCoreWebView2BrowserVersionInfo", hr);
@@ -782,6 +784,11 @@ void wxWebViewEdge::ExecCommand(const wxString& command)
RunScript(wxString::Format("document.execCommand('%s');", command));
}
void wxWebViewEdge::MSWSetBrowserExecutableDir(const wxString & path)
{
wxWebViewEdgeImpl::ms_browserExecutableDir = path;
}
bool wxWebViewEdge::RunScriptSync(const wxString& javascript, wxString* output)
{
bool scriptExecuted = false;