mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-03 04:27:43 +01:00
cefsimple: Use data URI instead of LoadString for error messages (see issue #2586)
This commit is contained in:
parent
22746985f2
commit
9cdda243a1
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "include/base/cef_bind.h"
|
#include "include/base/cef_bind.h"
|
||||||
#include "include/cef_app.h"
|
#include "include/cef_app.h"
|
||||||
|
#include "include/cef_parser.h"
|
||||||
#include "include/views/cef_browser_view.h"
|
#include "include/views/cef_browser_view.h"
|
||||||
#include "include/views/cef_window.h"
|
#include "include/views/cef_window.h"
|
||||||
#include "include/wrapper/cef_closure_task.h"
|
#include "include/wrapper/cef_closure_task.h"
|
||||||
@ -18,6 +19,13 @@ namespace {
|
|||||||
|
|
||||||
SimpleHandler* g_instance = NULL;
|
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
|
} // namespace
|
||||||
|
|
||||||
SimpleHandler::SimpleHandler(bool use_views)
|
SimpleHandler::SimpleHandler(bool use_views)
|
||||||
@ -106,13 +114,14 @@ void SimpleHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
|||||||
if (errorCode == ERR_ABORTED)
|
if (errorCode == ERR_ABORTED)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Display a load error message.
|
// Display a load error message using a data: URI.
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "<html><body bgcolor=\"white\">"
|
ss << "<html><body bgcolor=\"white\">"
|
||||||
"<h2>Failed to load URL "
|
"<h2>Failed to load URL "
|
||||||
<< std::string(failedUrl) << " with error " << std::string(errorText)
|
<< std::string(failedUrl) << " with error " << std::string(errorText)
|
||||||
<< " (" << errorCode << ").</h2></body></html>";
|
<< " (" << errorCode << ").</h2></body></html>";
|
||||||
frame->LoadString(ss.str(), failedUrl);
|
|
||||||
|
frame->LoadURL(GetDataURI(ss.str(), "text/html"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SimpleHandler::CloseAllBrowsers(bool force_close) {
|
void SimpleHandler::CloseAllBrowsers(bool force_close) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user