Skip to content

Commit

Permalink
Stop using CefBrowser::LoadString()
Browse files Browse the repository at this point in the history
This function doesn't exist in the latest CEF versions and apparently
didn't work for a long time before it, see chromiumembedded/cef#2586, so
stop using it and use data: URI instead for loading the fixed text.

This replacement is not quite perfect, notably it doesn't show the
correct URI in the title bar, but better than nothing.
  • Loading branch information
vadz committed Aug 31, 2023
1 parent 8c32af7 commit 50a3569
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/common/webview_chromium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "wx/rtti.h"
#include "wx/stdpaths.h"
#include "wx/app.h"
#include "wx/base64.h"
#include "wx/module.h"

#ifdef __WXMSW__
Expand Down Expand Up @@ -604,13 +605,16 @@ void wxWebViewChromium::SetEditable(bool enable)

void wxWebViewChromium::DoSetPage(const wxString& html, const wxString& baseUrl)
{
wxString pageBaseUrl = baseUrl;
// CEF needs a baseURL that is not empty, set one if not specified
if(pageBaseUrl.empty())
pageBaseUrl = "file://";
wxUnusedVar(baseUrl);

m_clientHandler->GetBrowser()->GetMainFrame()->LoadString(html.ToStdString(),
pageBaseUrl.ToStdString());
// This seems to be the only way to load a string in CEF now, see
// https://github.com/chromiumembedded/cef/issues/2586
const wxScopedCharBuffer& buf = html.utf8_str();
const wxString url{
"data:text/html;base64," + wxBase64Encode(buf.data(), buf.length())
};

m_clientHandler->GetBrowser()->GetMainFrame()->LoadURL(url.ToStdWstring());
}

wxWebViewZoom wxWebViewChromium::GetZoom() const
Expand Down

0 comments on commit 50a3569

Please sign in to comment.