Avoid crash on startup in webvew sample under Wayland

The workaround for wxWebViewChromium added in f5e2af9a28 (Make
wxWebViewChromium work with wxGTK3 and X11, 2023-09-02) broke
wxWebViewWebKit under Wayland as calling wxYield() inside
wxEVT_WEBVIEW_CREATED handler results in

Error flushing display: Resource temporarily unavailable

error from GTK and immediate application exit.

This is almost certainly a GTK bug and should be fixed there, see
https://gitlab.gnome.org/GNOME/gtk/-/issues/124, but for now make the
workaround even uglier to avoid it.
This commit is contained in:
Vadim Zeitlin
2024-04-22 17:47:02 +02:00
parent 9278e0b7c3
commit dce09c9b2a
+20 -4
View File
@@ -555,8 +555,11 @@ WebFrame::WebFrame(const wxString& url, int flags, wxWebViewWindowFeatures* wind
wxWebView::GetBackendVersionInfo(backend).ToString());
// Chromium backend can't be used immediately after creation, so wait
// until the browser is created before calling GetUserAgent().
m_browser->Bind(wxEVT_WEBVIEW_CREATED, [this](wxWebViewEvent& event) {
// until the browser is created before calling GetUserAgent(), but we
// can't do it unconditionally neither as doing it with WebViewGTK
// triggers https://gitlab.gnome.org/GNOME/gtk/-/issues/124 and just
// kills the sample.
const auto initShow = [this](){
wxLogMessage("Web view created, user agent is \"%s\"", m_browser->GetUserAgent());
// We need to synchronize this call with GetUserAgent() one, as
@@ -565,9 +568,22 @@ WebFrame::WebFrame(const wxString& url, int flags, wxWebViewWindowFeatures* wind
// order and we'd get the wrong user agent string back.
if (!m_browser->AddScriptMessageHandler("wx"))
wxLogError("Could not add script message handler");
};
event.Skip();
});
#if wxUSE_WEBVIEW_CHROMIUM
if ( backend == wxWebViewBackendChromium )
{
m_browser->Bind(wxEVT_WEBVIEW_CREATED, [&initShow](wxWebViewEvent& event) {
initShow();
event.Skip();
});
}
else
#endif // wxUSE_WEBVIEW_CHROMIUM
{
initShow();
}
#ifndef __WXMAC__
//We register the wxfs:// protocol for testing purposes