cefsimple: Use data URI instead of LoadString for error messages (see issue #2586)

This commit is contained in:
Marshall Greenblatt 2019-10-10 11:10:28 +03:00
parent 22746985f2
commit 9cdda243a1

View File

@ -9,6 +9,7 @@
#include "include/base/cef_bind.h"
#include "include/cef_app.h"
#include "include/cef_parser.h"
#include "include/views/cef_browser_view.h"
#include "include/views/cef_window.h"
#include "include/wrapper/cef_closure_task.h"
@ -18,6 +19,13 @@ namespace {
SimpleHandler* g_instance = NULL;
// Returns a data: URI with the specified contents.
std::string GetDataURI(const std::string& data, const std::string& mime_type) {
return "data:" + mime_type + ";base64," +
CefURIEncode(CefBase64Encode(data.data(), data.size()), false)
.ToString();
}
} // namespace
SimpleHandler::SimpleHandler(bool use_views)
@ -106,13 +114,14 @@ void SimpleHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
if (errorCode == ERR_ABORTED)
return;
// Display a load error message.
// Display a load error message using a data: URI.
std::stringstream ss;
ss << "<html><body bgcolor=\"white\">"
"<h2>Failed to load URL "
<< std::string(failedUrl) << " with error " << std::string(errorText)
<< " (" << errorCode << ").</h2></body></html>";
frame->LoadString(ss.str(), failedUrl);
frame->LoadURL(GetDataURI(ss.str(), "text/html"));
}
void SimpleHandler::CloseAllBrowsers(bool force_close) {