Skip to content

Commit

Permalink
cefsimple: Use data URI instead of LoadString for error messages (see…
Browse files Browse the repository at this point in the history
  • Loading branch information
magreenblatt committed Oct 10, 2019
1 parent 2274698 commit 9cdda24
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tests/cefsimple/simple_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 9cdda24

Please sign in to comment.