diff --git a/include/wx/webview.h b/include/wx/webview.h index 4f6c96b868..740991a7bc 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -160,7 +160,7 @@ public: static void RegisterFactory(const wxString& backend, wxSharedPtr factory); static bool IsBackendAvailable(const wxString& backend); - static wxVersionInfo GetBackendVersionInfo(const wxString& backend); + static wxVersionInfo GetBackendVersionInfo(const wxString& backend = wxASCII_STR(wxWebViewBackendDefault)); // General methods virtual void EnableContextMenu(bool enable = true) diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 0f2a2ca7b3..1e46ebad43 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -337,6 +337,10 @@ public: - Make sure to add a note about using the WebView2 SDK to your application documentation, as required by its licence + If enabled and available at runtime edge will be selected as the default + backend. If you require the IE backend use @c wxWEBVIEW_BACKEND_IE when + using wxWebView::New(). + If your application should use a fixed version of the WebView2 runtime you must use @@ -504,7 +508,7 @@ public: @since 3.1.5 */ - static wxVersionInfo GetBackendVersionInfo(const wxString& backend); + static wxVersionInfo GetBackendVersionInfo(const wxString& backend = wxWebViewBackendDefault); /** Get the title of the current web page, or its URL/path if title is not diff --git a/samples/webview/webview.cpp b/samples/webview/webview.cpp index 9ad0011c2d..368628d88d 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -374,9 +374,7 @@ WebFrame::WebFrame(const wxString& url) : // Create a log window new wxLogWindow(this, _("Logging"), true, false); - // Create the webview - wxString backend = wxWebViewBackendDefault; -#ifdef __WXMSW__ +#if wxUSE_WEBVIEW_EDGE // Check if a fixed version of edge is present in // $executable_path/edge_fixed and use it wxFileName edgeFixedDir(wxStandardPaths::Get().GetExecutablePath()); @@ -387,18 +385,12 @@ WebFrame::WebFrame(const wxString& url) : wxWebViewEdge::MSWSetBrowserExecutableDir(edgeFixedDir.GetFullPath()); wxLogMessage("Using fixed edge version"); } - if (wxWebView::IsBackendAvailable(wxWebViewBackendEdge)) - { - wxLogMessage("Using Edge backend"); - backend = wxWebViewBackendEdge; - } - else - { - wxLogMessage("Edge backend not available"); - } #endif - m_browser = wxWebView::New(backend); - wxLogMessage("Backend version: %s", wxWebView::GetBackendVersionInfo(backend).ToString()); + // Create the webview + m_browser = wxWebView::New(); + // Log backend information + wxLogMessage("Backend: %s Version: %s", m_browser->GetClassInfo()->GetClassName(), + wxWebView::GetBackendVersionInfo().ToString()); #ifdef __WXMAC__ // With WKWebView handlers need to be registered before creation m_browser->RegisterHandler(wxSharedPtr(new wxWebViewArchiveHandler("wxfs"))); diff --git a/src/common/webview.cpp b/src/common/webview.cpp index cab737ae24..21ab75f5ea 100644 --- a/src/common/webview.cpp +++ b/src/common/webview.cpp @@ -34,7 +34,7 @@ extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendEdge[] = "wxWebViewE extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendWebKit[] = "wxWebViewWebKit"; #ifdef __WXMSW__ -extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewIE"; +extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = ""; #else extern WXDLLIMPEXP_DATA_WEBVIEW(const char) wxWebViewBackendDefault[] = "wxWebViewWebKit"; #endif @@ -269,7 +269,22 @@ wxStringWebViewFactoryMap::iterator wxWebView::FindFactory(const wxString &backe // Initialise the map, it checks internally for existing factories InitFactoryMap(); - return m_factoryMap.find(backend); +#ifdef __WXMSW__ + // Use edge as default backend on MSW if available + if (backend.empty()) + { + wxStringWebViewFactoryMap::iterator defaultBackend = + m_factoryMap.find(wxWebViewBackendIE); +#if wxUSE_WEBVIEW_EDGE + wxStringWebViewFactoryMap::iterator edgeFactory = m_factoryMap.find(wxWebViewBackendEdge); + if (edgeFactory->second->IsAvailable()) + return edgeFactory; +#endif + return defaultBackend; + } + else +#endif + return m_factoryMap.find(backend); } // static