From 9cdda243a154f27a2a36641fd20d5d6e3641f84e Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 10 Oct 2019 11:10:28 +0300 Subject: [PATCH] cefsimple: Use data URI instead of LoadString for error messages (see issue #2586) --- tests/cefsimple/simple_handler.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/cefsimple/simple_handler.cc b/tests/cefsimple/simple_handler.cc index 1029904ae..352622a5d 100644 --- a/tests/cefsimple/simple_handler.cc +++ b/tests/cefsimple/simple_handler.cc @@ -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 browser, if (errorCode == ERR_ABORTED) return; - // Display a load error message. + // Display a load error message using a data: URI. std::stringstream ss; ss << "" "

Failed to load URL " << std::string(failedUrl) << " with error " << std::string(errorText) << " (" << errorCode << ").

"; - frame->LoadString(ss.str(), failedUrl); + + frame->LoadURL(GetDataURI(ss.str(), "text/html")); } void SimpleHandler::CloseAllBrowsers(bool force_close) {