Add wxEVT_WEBVIEW_CREATED for wxWebViewChromium async creation

wxWebViewChromium creation is asynchronous and the object can't be
really used until OnAfterCreated() is called, so expose this in the
public API via a new event sent when the object becomes actually usable.

As a side effect, add a convenient wxWebViewEvent ctor taking wxWebView
as argument and calling SetEventObject() itself, instead of forcing all
code creating wxWebViewEvents to do it.
This commit is contained in:
Vadim Zeitlin
2023-09-06 03:50:34 +02:00
parent f1734a29b6
commit 92f6f164b3
10 changed files with 58 additions and 3 deletions
+3 -3
View File
@@ -475,8 +475,8 @@ WebFrame::WebFrame(const wxString& url, bool isMain, wxWebViewWindowFeatures* wi
// 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());
m_browser->Bind(wxEVT_WEBVIEW_CREATED, [this](wxWebViewEvent& event) {
wxLogMessage("Web view created, user agent is \"%s\"", m_browser->GetUserAgent());
event.Skip();
});
@@ -1398,7 +1398,7 @@ void WebFrame::OnAddUserScript(wxCommandEvent & WXUNUSED(evt))
void WebFrame::OnSetCustomUserAgent(wxCommandEvent& WXUNUSED(evt))
{
wxString customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.1 Mobile/15E148 Safari/604.1";
wxString customUserAgent = m_browser->GetUserAgent();
wxTextEntryDialog dialog
(
this,