Skip to content
Snippets Groups Projects
Commit 0588b7de authored by Sergey Linev's avatar Sergey Linev
Browse files

webui: ensure that CEF works with local communication

Special handling of file responses required.
When file not exists, 404 reqply shoould be returned
parent 1acce37e
Branches
Tags
No related merge requests found
...@@ -84,9 +84,10 @@ public: ...@@ -84,9 +84,10 @@ public:
int fTransferOffset{0}; int fTransferOffset{0};
explicit TGuiResourceHandler() explicit TGuiResourceHandler(bool dummy = false)
{ {
fArg = std::make_shared<TCefHttpCallArg>(); if (!dummy)
fArg = std::make_shared<TCefHttpCallArg>();
} }
virtual ~TGuiResourceHandler() {} virtual ~TGuiResourceHandler() {}
...@@ -97,9 +98,12 @@ public: ...@@ -97,9 +98,12 @@ public:
{ {
CEF_REQUIRE_IO_THREAD(); CEF_REQUIRE_IO_THREAD();
fArg->AssignCallback(callback); if (fArg) {
fArg->AssignCallback(callback);
gHandlingServer->SubmitHttp(fArg); gHandlingServer->SubmitHttp(fArg);
} else {
callback->Continue();
}
return true; return true;
} }
...@@ -108,7 +112,7 @@ public: ...@@ -108,7 +112,7 @@ public:
{ {
CEF_REQUIRE_IO_THREAD(); CEF_REQUIRE_IO_THREAD();
if (fArg->Is404()) { if (!fArg || fArg->Is404()) {
response->SetMimeType("text/html"); response->SetMimeType("text/html");
response->SetStatus(404); response->SetStatus(404);
response_length = 0; response_length = 0;
...@@ -117,16 +121,14 @@ public: ...@@ -117,16 +121,14 @@ public:
response->SetStatus(200); response->SetStatus(200);
response_length = fArg->GetContentLength(); response_length = fArg->GetContentLength();
printf("SET RESPONSE len %d type %s\n", (int) response_length, fArg->GetContentType());
if (fArg->NumHeader() > 0) { if (fArg->NumHeader() > 0) {
printf("******* Response with extra headers\n"); // printf("******* Response with extra headers\n");
CefResponse::HeaderMap headers; CefResponse::HeaderMap headers;
for (Int_t n = 0; n < fArg->NumHeader(); ++n) { for (Int_t n = 0; n < fArg->NumHeader(); ++n) {
TString name = fArg->GetHeaderName(n); TString name = fArg->GetHeaderName(n);
TString value = fArg->GetHeader(name.Data()); TString value = fArg->GetHeader(name.Data());
headers.emplace(CefString(name.Data()), CefString(value.Data())); headers.emplace(CefString(name.Data()), CefString(value.Data()));
printf(" header %s %s\n", name.Data(), value.Data()); // printf(" header %s %s\n", name.Data(), value.Data());
} }
response->SetHeaderMap(headers); response->SetHeaderMap(headers);
} }
...@@ -216,8 +218,6 @@ public: ...@@ -216,8 +218,6 @@ public:
{ {
std::string addr = request->GetURL().ToString(); std::string addr = request->GetURL().ToString();
printf("REQUEST %s\n", addr.c_str());
TUrl url(addr.c_str()); TUrl url(addr.c_str());
const char *inp_path = url.GetFile(); const char *inp_path = url.GetFile();
...@@ -229,15 +229,11 @@ public: ...@@ -229,15 +229,11 @@ public:
if (gHandlingServer->IsFileRequested(inp_path, fname)) { if (gHandlingServer->IsFileRequested(inp_path, fname)) {
// process file - no need for special requests handling // process file - no need for special requests handling
const char *mime = THttpServer::GetMimeType(fname.Data()); // when file not exists - return nullptr
if (gSystem->AccessPathName(fname.Data()))
// static std::string str_content = THttpServer::ReadFileContent(fname.Data()); return new TGuiResourceHandler(true);
printf("Sending file %s mime %s\n", fname.Data(), mime);
// Create a stream reader for |html_content|. const char *mime = THttpServer::GetMimeType(fname.Data());
//CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForData(
// static_cast<void *>(const_cast<char *>(str_content.c_str())), str_content.size());
CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(fname.Data()); CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(fname.Data());
...@@ -248,7 +244,7 @@ public: ...@@ -248,7 +244,7 @@ public:
std::string inp_method = request->GetMethod().ToString(); std::string inp_method = request->GetMethod().ToString();
printf("REQUEST METHOD %s\n", inp_method.c_str()); // printf("REQUEST METHOD %s\n", inp_method.c_str());
TGuiResourceHandler *handler = new TGuiResourceHandler(); TGuiResourceHandler *handler = new TGuiResourceHandler();
handler->fArg->SetMethod(inp_method.c_str()); handler->fArg->SetMethod(inp_method.c_str());
...@@ -311,7 +307,7 @@ void SimpleApp::OnBeforeCommandLineProcessing(const CefString &process_type, Cef ...@@ -311,7 +307,7 @@ void SimpleApp::OnBeforeCommandLineProcessing(const CefString &process_type, Cef
{ {
std::string name = process_type.ToString(); std::string name = process_type.ToString();
std::string prog = command_line->GetProgram().ToString(); std::string prog = command_line->GetProgram().ToString();
printf("OnBeforeCommandLineProcessing %s %s\n", name.c_str(), prog.c_str()); // printf("OnBeforeCommandLineProcessing %s %s\n", name.c_str(), prog.c_str());
// if (fBatch) { // if (fBatch) {
// command_line->AppendSwitch("disable-gpu"); // command_line->AppendSwitch("disable-gpu");
// command_line->AppendSwitch("disable-gpu-compositing"); // command_line->AppendSwitch("disable-gpu-compositing");
...@@ -324,8 +320,7 @@ void SimpleApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_lin ...@@ -324,8 +320,7 @@ void SimpleApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_lin
std::string newprog = fCefMain; std::string newprog = fCefMain;
command_line->SetProgram(newprog); command_line->SetProgram(newprog);
printf("OnBeforeChildProcessLaunch %s LastBatch %s\n", command_line->GetProgram().ToString().c_str(), fLastBatch ? "true" : "false"); // printf("OnBeforeChildProcessLaunch %s LastBatch %s\n", command_line->GetProgram().ToString().c_str(), fLastBatch ? "true" : "false");
if (fLastBatch) { if (fLastBatch) {
command_line->AppendSwitch("disable-webgl"); command_line->AppendSwitch("disable-webgl");
...@@ -334,17 +329,15 @@ void SimpleApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_lin ...@@ -334,17 +329,15 @@ void SimpleApp::OnBeforeChildProcessLaunch(CefRefPtr<CefCommandLine> command_lin
// command_line->AppendSwitch("disable-gpu-sandbox"); // command_line->AppendSwitch("disable-gpu-sandbox");
} }
auto str = command_line->GetCommandLineString().ToString(); // auto str = command_line->GetCommandLineString().ToString();
printf("RUNNING %s\n", str.c_str()); // printf("RUN %s\n", str.c_str());
} }
void SimpleApp::OnContextInitialized() void SimpleApp::OnContextInitialized()
{ {
CEF_REQUIRE_UI_THREAD(); CEF_REQUIRE_UI_THREAD();
// CefRegisterSchemeHandlerFactory("http", "rootserver.local", new ROOTSchemeHandlerFactory()); CefRegisterSchemeHandlerFactory("http", "rootserver.local", new ROOTSchemeHandlerFactory());
if (!fFirstUrl.empty()) if (!fFirstUrl.empty())
StartWindow(fFirstUrl, fFirstBatch, fFirstRect); StartWindow(fFirstUrl, fFirstBatch, fFirstRect);
...@@ -527,19 +520,19 @@ protected: ...@@ -527,19 +520,19 @@ protected:
// cef_string_ascii_to_utf16(path2.Data(), path2.Length(), &settings.locales_dir_path); // cef_string_ascii_to_utf16(path2.Data(), path2.Length(), &settings.locales_dir_path);
// settings.no_sandbox = 1; settings.no_sandbox = 1;
// if (gROOT->IsWebDisplayBatch()) settings.single_process = true; // if (gROOT->IsWebDisplayBatch()) settings.single_process = true;
// if (batch_mode) // if (batch_mode)
// settings.windowless_rendering_enabled = true; // settings.windowless_rendering_enabled = true;
settings.external_message_pump = true; // settings.external_message_pump = true;
settings.multi_threaded_message_loop = false; // settings.multi_threaded_message_loop = false;
std::string plog = "cef.log"; std::string plog = "cef.log";
cef_string_ascii_to_utf16(plog.c_str(), plog.length(), &settings.log_file); cef_string_ascii_to_utf16(plog.c_str(), plog.length(), &settings.log_file);
settings.log_severity = LOGSEVERITY_VERBOSE; // LOGSEVERITY_INFO, LOGSEVERITY_WARNING, LOGSEVERITY_ERROR, LOGSEVERITY_DISABLE settings.log_severity = LOGSEVERITY_VERBOSE; // LOGSEVERITY_VERBOSE, LOGSEVERITY_INFO, LOGSEVERITY_WARNING, LOGSEVERITY_ERROR, LOGSEVERITY_DISABLE
// settings.uncaught_exception_stack_size = 100; // settings.uncaught_exception_stack_size = 100;
// settings.ignore_certificate_errors = true; // settings.ignore_certificate_errors = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment