Add tracing messages to wxWebViewChromium code

Log calls to some callbacks using "cef" trace mask.

To make these messages actually visible in the sample, use a log target
showing only debug messages and pass messages through to it from
wxLogWindow.
This commit is contained in:
Vadim Zeitlin 2023-09-01 01:23:39 +02:00
parent 05fcc0588d
commit 18456e7de2
2 changed files with 34 additions and 1 deletions

View file

@ -335,6 +335,24 @@ bool WebApp::OnInit()
"<p><a href='memory:page1.htm'>Page 1</a> was better.</p></body>");
wxMemoryFSHandler::AddFile("test.css", "h1 {color: red;}");
// Set log target which only logs debugging messages in the usual way: all
// the rest will be shown in wxLogWindow created by WebFrame.
class DebugOnlyLog : public wxLog
{
public:
DebugOnlyLog() = default;
protected:
void DoLogTextAtLevel(wxLogLevel level, const wxString& msg) override
{
// Ignore all non-debug/trace messages.
if ( level == wxLOG_Debug || level == wxLOG_Trace )
wxLog::DoLogTextAtLevel(level, msg);
}
};
delete wxLog::SetActiveTarget(new DebugOnlyLog);
WebFrame *frame = new WebFrame(m_url);
frame->Show();
@ -412,7 +430,7 @@ WebFrame::WebFrame(const wxString& url, bool isMain, wxWebViewWindowFeatures* wi
// Create a log window
if (m_isMainFrame)
new wxLogWindow(this, _("Logging"), true, false);
new wxLogWindow(this, _("Logging"));
#if wxUSE_WEBVIEW_EDGE
// Check if a fixed version of edge is present in

View file

@ -52,6 +52,15 @@ wxGCC_WARNING_RESTORE(unused-parameter)
#error "Unsupported CEF version"
#endif
namespace
{
constexpr const char* TRACE_CEF = "cef";
#define TRACE_CEF_FUNCTION() wxLogTrace(TRACE_CEF, "%s called", __FUNCTION__)
} // anonymous namespace
extern WXDLLIMPEXP_DATA_WEBVIEW_CHROMIUM(const char) wxWebViewBackendChromium[] = "wxWebViewChromium";
int wxWebViewChromium::ms_activeWebViewCount = 0;
@ -769,6 +778,8 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> WXUNUSED(browser),
void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
{
TRACE_CEF_FUNCTION();
if ( !m_browser.get() )
{
m_browser = browser;
@ -779,11 +790,15 @@ void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser)
}
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> WXUNUSED(browser))
{
TRACE_CEF_FUNCTION();
return false;
}
void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser)
{
TRACE_CEF_FUNCTION();
if ( browser->GetIdentifier() == m_browserId )
{
m_browser = nullptr;