diff --git a/include/wx/msw/private/webview_edge.h b/include/wx/msw/private/webview_edge.h index 3fb204309c..2fce49a3fa 100644 --- a/include/wx/msw/private/webview_edge.h +++ b/include/wx/msw/private/webview_edge.h @@ -66,6 +66,7 @@ public: ICoreWebView2Settings* GetSettings(); static wxDynamicLibrary ms_loaderDll; + static wxString ms_browserExecutableDir; static bool Initialize(); diff --git a/include/wx/msw/webview_edge.h b/include/wx/msw/webview_edge.h index dbdbfc5678..ab2e65a304 100644 --- a/include/wx/msw/webview_edge.h +++ b/include/wx/msw/webview_edge.h @@ -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; diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 4d01990faf..4234fc0895 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -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 + + fixed version 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 diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index b6902965b3..4cc02ab696 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -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"); diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp index 74694fa8d9..9a7f72cb4b 100644 --- a/src/msw/webview_edge.cpp +++ b/src/msw/webview_edge.cpp @@ -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(this, @@ -127,7 +128,8 @@ bool wxWebViewEdgeImpl::Initialize() // Check if a Edge browser can be found by the loader DLL wxCoTaskMemPtr versionStr; - HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString(NULL, &versionStr); + HRESULT hr = wxGetAvailableCoreWebView2BrowserVersionString( + ms_browserExecutableDir.wc_str(), &versionStr); if (FAILED(hr) || !versionStr) { wxLogApiError("GetCoreWebView2BrowserVersionInfo", hr); @@ -780,6 +782,11 @@ bool wxWebViewEdge::QueryCommandEnabled(const wxString& command) const 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)