Make wxWebViewChromium work with wxGTK3 and X11

Make browser creation actually work by postponing it until the host
window is realized and so has a valid X11 Window.

Remove unnecessary code manually creating GTK widget and just use the
standard wxGTK wxWindow instead.

Add code for setting the visual compatible with CEF to avoid X11 errors,
see https://github.com/chromiumembedded/cef/issues/3564, with many
thanks to Jiří Janoušek for finding and solving this problem originally.

Adjust the sample to handle wxWebView::Create() failure (not very
gracefully, but still better than just crashing) and to avoid using it
until it is fully created.

Update documentation to mention GTK limitations.
This commit is contained in:
Vadim Zeitlin
2023-09-06 03:50:05 +02:00
parent d3cc4678d5
commit f5e2af9a28
4 changed files with 158 additions and 60 deletions
+12
View File
@@ -118,10 +118,18 @@ public:
//Virtual Filesystem Support
virtual void RegisterHandler(wxSharedPtr<wxWebViewHandler> handler) override;
#ifdef __WXGTK__
virtual void GTKHandleRealized() override;
#endif
protected:
virtual void DoSetPage(const wxString& html, const wxString& baseUrl) override;
private:
// Actually create the browser: this can only be done once the window is
// created in wxGTK.
bool DoCreateBrowser(const wxString& url);
//History related variables, we currently use our own implementation
wxVector<wxSharedPtr<wxWebViewHistoryItem> > m_historyList;
int m_historyPosition;
@@ -142,6 +150,10 @@ private:
friend class ClientHandler;
ClientHandler* m_clientHandler;
#ifdef __WXGTK__
wxString m_url;
#endif
friend class wxWebViewChromiumModule;
static bool ms_cefInitialized;
+17
View File
@@ -64,6 +64,23 @@
Only Microsoft Visual C++ 2015 or newer can be used to build wxWebViewChromium.
__Linux with GTK__
wxWebviewChromium currently only supports X11 and not Wayland, i.e. you
need to either ensure that `GDK_BACKEND` environment variable is set to
"x11" before running your program using it or call
@code
gdk_set_allowed_backends("x11")
@endcode
in your application code.
Moreover, the actual browser is only created once the window is shown, and
can't be used until then. You can bind an event handler for wxEVT_CREATE to
know when it is usable.
__Mac OS X Platform__
OS X 10.9 or above is required.
+13 -3
View File
@@ -460,14 +460,17 @@ WebFrame::WebFrame(const wxString& url, bool isMain, wxWebViewWindowFeatures* wi
m_browser->RegisterHandler(wxSharedPtr<wxWebViewHandler>(new AdvancedWebViewHandler()));
}
#endif
m_browser->Create(this, wxID_ANY, url, wxDefaultPosition,
if ( !m_browser->Create(this, wxID_ANY, url, wxDefaultPosition,
#if defined(wxWEBVIEW_SAMPLE_CHROMIUM) && defined(__WXOSX__)
// OSX implementation currently cannot handle the default size
wxSize(800, 600)
#else
wxDefaultSize
#endif
);
) )
{
wxLogFatalError("Failed to create wxWebView");
}
topsizer->Add(m_browser, wxSizerFlags().Expand().Proportion(1));
@@ -476,7 +479,14 @@ WebFrame::WebFrame(const wxString& url, bool isMain, wxWebViewWindowFeatures* wi
// Log backend information
wxLogMessage("Backend: %s Version: %s", m_browser->GetClassInfo()->GetClassName(),
wxWebView::GetBackendVersionInfo().ToString());
wxLogMessage("User Agent: %s", m_browser->GetUserAgent());
// Chromium backend can't be used immediately after creation, so wait
// until the browser is created before calling GetUserAgent().
m_browser->Bind(wxEVT_CREATE, [this](wxWindowCreateEvent& event) {
wxLogMessage("User Agent: %s", m_browser->GetUserAgent());
event.Skip();
});
#ifndef __WXMAC__
//We register the wxfs:// protocol for testing purposes
File diff suppressed because it is too large Load Diff