Skip to content

Commit 9cdda24

Browse files
committed
cefsimple: Use data URI instead of LoadString for error messages (see issue #2586)
1 parent 2274698 commit 9cdda24

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

tests/cefsimple/simple_handler.cc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "include/base/cef_bind.h"
1111
#include "include/cef_app.h"
12+
#include "include/cef_parser.h"
1213
#include "include/views/cef_browser_view.h"
1314
#include "include/views/cef_window.h"
1415
#include "include/wrapper/cef_closure_task.h"
@@ -18,6 +19,13 @@ namespace {
1819

1920
SimpleHandler* g_instance = NULL;
2021

22+
// Returns a data: URI with the specified contents.
23+
std::string GetDataURI(const std::string& data, const std::string& mime_type) {
24+
return "data:" + mime_type + ";base64," +
25+
CefURIEncode(CefBase64Encode(data.data(), data.size()), false)
26+
.ToString();
27+
}
28+
2129
} // namespace
2230

2331
SimpleHandler::SimpleHandler(bool use_views)
@@ -106,13 +114,14 @@ void SimpleHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
106114
if (errorCode == ERR_ABORTED)
107115
return;
108116

109-
// Display a load error message.
117+
// Display a load error message using a data: URI.
110118
std::stringstream ss;
111119
ss << "<html><body bgcolor=\"white\">"
112120
"<h2>Failed to load URL "
113121
<< std::string(failedUrl) << " with error " << std::string(errorText)
114122
<< " (" << errorCode << ").</h2></body></html>";
115-
frame->LoadString(ss.str(), failedUrl);
123+
124+
frame->LoadURL(GetDataURI(ss.str(), "text/html"));
116125
}
117126

118127
void SimpleHandler::CloseAllBrowsers(bool force_close) {

0 commit comments

Comments
 (0)