diff --git a/include/wx/gtk/webview_webkit.h b/include/wx/gtk/webview_webkit.h index fccdfcd8d8..38779e3fa1 100644 --- a/include/wx/gtk/webview_webkit.h +++ b/include/wx/gtk/webview_webkit.h @@ -198,6 +198,9 @@ public: long style = 0, const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE { return new wxWebViewWebKit(parent, id, url, pos, size, style, name); } +#if wxUSE_WEBVIEW_WEBKIT2 + virtual wxVersionInfo GetVersionInfo() wxOVERRIDE; +#endif }; diff --git a/include/wx/msw/private/webview_edge.h b/include/wx/msw/private/webview_edge.h index 2fce49a3fa..f5509006e6 100644 --- a/include/wx/msw/private/webview_edge.h +++ b/include/wx/msw/private/webview_edge.h @@ -67,6 +67,7 @@ public: static wxDynamicLibrary ms_loaderDll; static wxString ms_browserExecutableDir; + static wxString ms_version; static bool Initialize(); diff --git a/include/wx/msw/webview_edge.h b/include/wx/msw/webview_edge.h index ab2e65a304..bd25dd5da2 100644 --- a/include/wx/msw/webview_edge.h +++ b/include/wx/msw/webview_edge.h @@ -154,6 +154,7 @@ public: return new wxWebViewEdge(parent, id, url, pos, size, style, name); } virtual bool IsAvailable() wxOVERRIDE; + virtual wxVersionInfo GetVersionInfo() wxOVERRIDE; }; #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_EDGE && defined(__WXMSW__) diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index a7fb5e3171..019ac97dbf 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -192,6 +192,7 @@ public: long style = 0, const wxString& name = wxASCII_STR(wxWebViewNameStr)) wxOVERRIDE { return new wxWebViewIE(parent, id, url, pos, size, style, name); } + virtual wxVersionInfo GetVersionInfo() wxOVERRIDE; }; #endif // wxUSE_WEBVIEW && wxUSE_WEBVIEW_IE && defined(__WXMSW__) diff --git a/include/wx/webview.h b/include/wx/webview.h index 63ca8199a4..e3e2433cea 100644 --- a/include/wx/webview.h +++ b/include/wx/webview.h @@ -18,6 +18,7 @@ #include "wx/sstream.h" #include "wx/sharedptr.h" #include "wx/vector.h" +#include "wx/versioninfo.h" #if defined(__WXOSX__) #include "wx/osx/webviewhistoryitem_webkit.h" @@ -120,6 +121,7 @@ public: long style = 0, const wxString& name = wxASCII_STR(wxWebViewNameStr)) = 0; virtual bool IsAvailable() { return true; } + virtual wxVersionInfo GetVersionInfo() { return wxVersionInfo(); } }; WX_DECLARE_STRING_HASH_MAP(wxSharedPtr, wxStringWebViewFactoryMap); @@ -158,6 +160,7 @@ public: static void RegisterFactory(const wxString& backend, wxSharedPtr factory); static bool IsBackendAvailable(const wxString& backend); + static wxVersionInfo GetBackendVersionInfo(const wxString& backend); // General methods virtual void EnableContextMenu(bool enable = true) diff --git a/interface/wx/webview.h b/interface/wx/webview.h index 4234fc0895..4d4ed87c76 100644 --- a/interface/wx/webview.h +++ b/interface/wx/webview.h @@ -231,6 +231,13 @@ public: @since 3.1.5 */ virtual bool IsAvailable(); + + /** + Retrieve the version information about this backend implementation. + + @since 3.1.5 + */ + virtual wxVersionInfo GetVersionInfo(const wxString& backend); }; /** @@ -492,6 +499,12 @@ public: */ static bool IsBackendAvailable(const wxString& backend); + /** + Retrieve the version information about the backend implementation. + + @since 3.1.5 + */ + static wxVersionInfo GetBackendVersionInfo(const wxString& backend); /** 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 4cc02ab696..9ad0011c2d 100644 --- a/samples/webview/webview.cpp +++ b/samples/webview/webview.cpp @@ -398,6 +398,7 @@ WebFrame::WebFrame(const wxString& url) : } #endif m_browser = wxWebView::New(backend); + wxLogMessage("Backend version: %s", wxWebView::GetBackendVersionInfo(backend).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 348a2ad75e..86c5f53e88 100644 --- a/src/common/webview.cpp +++ b/src/common/webview.cpp @@ -94,6 +94,15 @@ bool wxWebView::IsBackendAvailable(const wxString& backend) return false; } +wxVersionInfo wxWebView::GetBackendVersionInfo(const wxString& backend) +{ + wxStringWebViewFactoryMap::iterator iter = FindFactory(backend); + if (iter != m_factoryMap.end()) + return iter->second->GetVersionInfo(); + else + return wxVersionInfo(); +} + // static wxStringWebViewFactoryMap::iterator wxWebView::FindFactory(const wxString &backend) { diff --git a/src/gtk/webview_webkit2.cpp b/src/gtk/webview_webkit2.cpp index b00840499f..64587bc197 100644 --- a/src/gtk/webview_webkit2.cpp +++ b/src/gtk/webview_webkit2.cpp @@ -507,6 +507,16 @@ wxgtk_authorize_authenticated_peer_cb(GDBusAuthObserver *, } // extern "C" +//----------------------------------------------------------------------------- +// wxWebViewFactoryWebKit +//----------------------------------------------------------------------------- + +wxVersionInfo wxWebViewFactoryWebKit::GetVersionInfo() +{ + return wxVersionInfo("webkit2", webkit_get_major_version(), + webkit_get_minor_version(), webkit_get_micro_version()); +} + //----------------------------------------------------------------------------- // wxWebViewWebKit //----------------------------------------------------------------------------- diff --git a/src/msw/webview_edge.cpp b/src/msw/webview_edge.cpp index 9a7f72cb4b..63a91b94e2 100644 --- a/src/msw/webview_edge.cpp +++ b/src/msw/webview_edge.cpp @@ -19,6 +19,7 @@ #include "wx/log.h" #include "wx/stdpaths.h" #include "wx/thread.h" +#include "wx/tokenzr.h" #include "wx/private/jsscriptwrapper.h" #include "wx/private/json.h" #include "wx/msw/private.h" @@ -53,6 +54,7 @@ GetAvailableCoreWebView2BrowserVersionString_t wxGetAvailableCoreWebView2Browser wxDynamicLibrary wxWebViewEdgeImpl::ms_loaderDll; wxString wxWebViewEdgeImpl::ms_browserExecutableDir; +wxString wxWebViewEdgeImpl::ms_version; wxWebViewEdgeImpl::wxWebViewEdgeImpl(wxWebViewEdge* webview): m_ctrl(webview) @@ -135,6 +137,7 @@ bool wxWebViewEdgeImpl::Initialize() wxLogApiError("GetCoreWebView2BrowserVersionInfo", hr); return false; } + ms_version = versionStr; ms_loaderDll.Attach(loaderDll.Detach()); @@ -876,6 +879,18 @@ bool wxWebViewFactoryEdge::IsAvailable() return wxWebViewEdgeImpl::Initialize(); } +wxVersionInfo wxWebViewFactoryEdge::GetVersionInfo() +{ + IsAvailable(); // Make sure ms_version string is initialized (if available) + long versions[3] = { 0, 0, 0 }; + wxArrayString tokens = wxStringTokenize(wxWebViewEdgeImpl::ms_version, ". "); + for (size_t i = 0; i < 3; i++) + { + if (tokens.size() > i) + tokens[i].ToLong(&versions[i]); + } + return wxVersionInfo("Microsoft Edge WebView2", versions[0], versions[1], versions[2]); +} // ---------------------------------------------------------------------------- // Module ensuring all global/singleton objects are destroyed on shutdown. diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 79b8204776..c584fd32e3 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -19,6 +19,7 @@ #include "wx/filesys.h" #include "wx/dynlib.h" #include "wx/scopeguard.h" +#include "wx/tokenzr.h" #include "wx/msw/missing.h" #include "wx/msw/private.h" @@ -51,6 +52,22 @@ enum //Internal find flags } +// wxWebViewFactoryIE +wxVersionInfo wxWebViewFactoryIE::GetVersionInfo() +{ + wxRegKey key(wxRegKey::HKLM, "Software\\Microsoft\\Internet Explorer"); + wxString value; + key.QueryValue("Version", value); + long versions[3] = { 0, 0, 0 }; + wxArrayString tokens = wxStringTokenize(value, ". "); + for (size_t i = 0; i < 3; i++) + { + if (tokens.size() > i) + tokens[i].ToLong(&versions[i]); + } + return wxVersionInfo("Internet Explorer", versions[0], versions[1], versions[2]); +} + //Convenience function for error conversion #define WX_ERROR_CASE(error, wxerror) \ case error: \