15#pragma GCC diagnostic ignored "-Wunused-parameter"
16#pragma GCC diagnostic ignored "-Wshadow"
25#include "include/base/cef_bind.h"
26#include "include/cef_app.h"
27#include "include/cef_version.h"
28#include "include/views/cef_browser_view.h"
29#include "include/views/cef_window.h"
30#include "include/wrapper/cef_closure_task.h"
31#include "include/wrapper/cef_helpers.h"
32#include "include/cef_parser.h"
33#include "include/wrapper/cef_stream_resource_handler.h"
62 CEF_REQUIRE_UI_THREAD();
66 CefRefPtr<CefBrowserView> browser_view = CefBrowserView::GetForBrowser(browser);
68 CefRefPtr<CefWindow> window = browser_view->GetWindow();
69 if (window) window->SetTitle(title);
79 CEF_REQUIRE_UI_THREAD();
87 CEF_REQUIRE_UI_THREAD();
104 CEF_REQUIRE_UI_THREAD();
109 if ((*bit)->IsSame(browser)) {
119 CefQuitMessageLoop();
126 return "data:" +
mime_type +
";base64," +
127 CefURIEncode(CefBase64Encode(data.data(), data.size()),
false)
133 const CefString &errorText,
const CefString &failedUrl)
135 CEF_REQUIRE_UI_THREAD();
138 if (errorCode == ERR_ABORTED)
142 std::stringstream ss;
143 ss <<
"<html><body bgcolor=\"white\">"
144 "<h2>Failed to load URL "
145 << failedUrl.ToString().substr(0,100) <<
" with error " << errorText.ToString() <<
" (" << errorCode
146 <<
").</h2></body></html>";
149 printf(
"Fail to load URL %s\n", failedUrl.ToString().substr(0,100).c_str());
154 if (!CefCurrentlyOn(TID_UI)) {
156#if CEF_VERSION_MAJOR < 95
168 br->GetHost()->CloseBrowser(force_close);
172 cef_log_severity_t level,
173 const CefString &message,
const CefString &source,
176 std::string src = source.ToString().substr(0,100);
179 case LOGSEVERITY_WARNING:
183 case LOGSEVERITY_ERROR:
197 CefRefPtr<CefBrowser> browser,
198 CefRefPtr<CefFrame> frame,
199 CefRefPtr<CefRequest> request,
200 CefRefPtr<CefResourceLoadCallBack> callback) {
201 CEF_REQUIRE_IO_THREAD();
221 const char *
GetWSKind()
const override {
return "longpoll"; }
247 std::shared_ptr<TCefHttpCallArg>
fArg;
256 fArg = std::make_shared<TCefHttpCallArg>();
261 void Cancel()
override { CEF_REQUIRE_IO_THREAD(); }
263 bool ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
override
265 CEF_REQUIRE_IO_THREAD();
268 fArg->AssignCallback(callback);
271 callback->Continue();
277 void GetResponseHeaders(CefRefPtr<CefResponse> response, int64 &response_length, CefString &redirectUrl)
override
279 CEF_REQUIRE_IO_THREAD();
282 response->SetMimeType(
"text/html");
283 response->SetStatus(404);
286 response->SetMimeType(
fArg->GetContentType());
287 response->SetStatus(200);
288 response_length =
fArg->GetContentLength();
290 if (
fArg->NumHeader() > 0) {
292 CefResponse::HeaderMap headers;
296 headers.emplace(CefString(
name.Data()), CefString(value.
Data()));
299 response->SetHeaderMap(headers);
308 bool ReadResponse(
void *data_out,
int bytes_to_read,
int &bytes_read, CefRefPtr<CefCallback> callback)
override
310 CEF_REQUIRE_IO_THREAD();
312 if (!
fArg)
return false;
316 if (fTransferOffset < fArg->GetContentLength()) {
317 char *data_ = (
char *)
fArg->GetContent();
320 if (transfer_size > bytes_to_read)
321 transfer_size = bytes_to_read;
325 bytes_read = transfer_size;
332 return bytes_read > 0;
341 CefRefPtr<CefBrowser> browser,
342 CefRefPtr<CefFrame> frame,
343 CefRefPtr<CefRequest> request) {
344 CEF_REQUIRE_IO_THREAD();
346 std::string addr = request->GetURL().ToString();
347 std::string prefix =
"http://rootserver.local";
349 if (addr.compare(0, prefix.length(), prefix) != 0)
352 int indx = std::stoi(addr.substr(prefix.length(), addr.find(
"/", prefix.length()) - prefix.length()));
366 TUrl url(addr.c_str());
368 const char *inp_path = url.
GetFile();
383 CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(fname.
Data());
387 return new CefStreamResourceHandler(mime, stream);
390 std::string inp_method = request->GetMethod().ToString();
395 handler->
fArg->SetMethod(inp_method.c_str());
396 handler->
fArg->SetPathAndFileName(inp_path);
397 handler->
fArg->SetTopName(
"webgui");
399 if (inp_method ==
"POST") {
401 CefRefPtr< CefPostData > post_data = request->GetPostData();
407 CefPostData::ElementVector elements;
408 post_data->GetElements(elements);
409 size_t sz = 0, off = 0;
410 for (
unsigned n = 0;
n < elements.size(); ++
n)
411 sz += elements[
n]->GetBytesCount();
415 for (
unsigned n = 0;
n < elements.size(); ++
n) {
416 sz = elements[
n]->GetBytes(elements[
n]->GetBytesCount(), (
char *)data.data() + off);
419 handler->
fArg->SetPostData(std::move(data));
421 }
else if (inp_query.
Index(
"&post=") !=
kNPOS) {
424 handler->
fArg->SetPostData(std::string(buf.
Data()));
428 handler->
fArg->SetQuery(inp_query.
Data());
441 std::string url =
"file:///batch_page";
445 fResourceManager->AddContentProvider(url, cont,
"text/html", 0, std::string());
463 return std::string(
"http://rootserver.local") + std::to_string(indx) + addr;
#define R__LOG_WARNING(...)
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
char * Form(const char *fmt,...)
R__EXTERN TSystem * gSystem
CefRefPtr< CefResourceManager > fResourceManager
int fConsole
! console parameter, assigned via WebGui.Console rootrc parameter
GuiHandler(bool use_views=false)
std::vector< THttpServer * > fServers
virtual void OnBeforeClose(CefRefPtr< CefBrowser > browser) override
virtual CefRefPtr< CefResourceHandler > GetResourceHandler(CefRefPtr< CefBrowser > browser, CefRefPtr< CefFrame > frame, CefRefPtr< CefRequest > request) override
virtual bool DoClose(CefRefPtr< CefBrowser > browser) override
void CloseAllBrowsers(bool force_close)
void PlatformTitleChange(CefRefPtr< CefBrowser > browser, const CefString &title)
virtual void OnLoadError(CefRefPtr< CefBrowser > browser, CefRefPtr< CefFrame > frame, ErrorCode errorCode, const CefString &errorText, const CefString &failedUrl) override
static std::string GetDataURI(const std::string &data, const std::string &mime_type)
bool fUseViews
! if view framework is used, required for true headless mode
std::string AddBatchPage(const std::string &cont)
Generate URL for batch page Uses file:/// prefix to let access JSROOT scripts placed on file system R...
std::string MakePageUrl(THttpServer *serv, const std::string &addr)
Generate URL for RWebWindow page Register server instance and assign it with the index Produced URL o...
virtual bool OnConsoleMessage(CefRefPtr< CefBrowser > browser, cef_log_severity_t level, const CefString &message, const CefString &source, int line) override
virtual void OnTitleChange(CefRefPtr< CefBrowser > browser, const CefString &title) override
virtual void OnAfterCreated(CefRefPtr< CefBrowser > browser) override
virtual cef_return_value_t OnBeforeResourceLoad(CefRefPtr< CefBrowser > browser, CefRefPtr< CefFrame > frame, CefRefPtr< CefRequest > request, CefRefPtr< CefResourceLoadCallBack > callback) override
A log configuration for a channel, e.g.
static TString Decode(const char *data)
Decode a base64 string date into a generic TString.
void AssignCallback(CefRefPtr< CefCallback > cb)
void HttpReplied() override
virtual method to inform object that http request is processed Normally condition is notified and wai...
const char * GetWSPlatform() const override
provide WS platform
CefRefPtr< CefCallback > fCallBack
const char * GetWSKind() const override
provide WS kind
TCefHttpCallArg()=default
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
bool ProcessRequest(CefRefPtr< CefRequest > request, CefRefPtr< CefCallback > callback) override
DISALLOW_COPY_AND_ASSIGN(TGuiResourceHandler)
std::shared_ptr< TCefHttpCallArg > fArg
IMPLEMENT_REFCOUNTING(TGuiResourceHandler)
bool ReadResponse(void *data_out, int bytes_to_read, int &bytes_read, CefRefPtr< CefCallback > callback) override
virtual ~TGuiResourceHandler()
TGuiResourceHandler(THttpServer *serv, bool dummy=false)
void GetResponseHeaders(CefRefPtr< CefResponse > response, int64 &response_length, CefString &redirectUrl) override
const void * GetContent() const
void SetContent(const char *cont)
Set content as text.
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
Bool_t SubmitHttp(std::shared_ptr< THttpCallArg > arg, Bool_t can_run_immediately=kFALSE)
Submit HTTP request.
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
R__ALWAYS_INLINE Bool_t IsZombie() const
const char * Data() const
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
virtual Bool_t AccessPathName(const char *path, EAccessMode mode=kFileExists)
Returns FALSE if one can access a file using the specified access mode.
This class represents a WWW compatible URL.
const char * GetFile() const
const char * GetOptions() const
ROOT::Experimental::RLogChannel & CefWebDisplayLog()
ROOT::Experimental::RLogChannel & CefWebDisplayLog()