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 std::string(
"data:") +
mime_type +
";base64," +
127 CefURIEncode(CefBase64Encode(
data.data(),
data.size()),
false).ToString();
132 const CefString &errorText,
const CefString &failedUrl)
134 CEF_REQUIRE_UI_THREAD();
137 if (errorCode == ERR_ABORTED)
150 printf(
"Fail to load URL %s\n", failedUrl.ToString().substr(0,100).c_str());
155 if (!CefCurrentlyOn(TID_UI)) {
165 br->GetHost()->CloseBrowser(force_close);
169 cef_log_severity_t level,
170 const CefString &message,
const CefString &source,
173 std::string
src = source.ToString().substr(0,100);
176 case LOGSEVERITY_WARNING:
180 case LOGSEVERITY_ERROR:
194 CefRefPtr<CefBrowser> browser,
195 CefRefPtr<CefFrame> frame,
196 CefRefPtr<CefRequest> request,
197 CefRefPtr<CefCallback> callback) {
198 CEF_REQUIRE_IO_THREAD();
214 const char *
GetWSKind()
const override {
return "longpoll"; }
240 std::shared_ptr<TCefHttpCallArg>
fArg;
249 fArg = std::make_shared<TCefHttpCallArg>();
254 void Cancel()
override { CEF_REQUIRE_IO_THREAD(); }
256 bool ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
override
258 CEF_REQUIRE_IO_THREAD();
261 fArg->AssignCallback(callback);
264 callback->Continue();
269#if CEF_VERSION_MAJOR > 114
270 void GetResponseHeaders(CefRefPtr<CefResponse> response, int64_t &response_length, CefString &redirectUrl)
override
272 void GetResponseHeaders(CefRefPtr<CefResponse> response, int64 &response_length, CefString &redirectUrl)
override
275 CEF_REQUIRE_IO_THREAD();
278 response->SetMimeType(
"text/html");
279 response->SetStatus(404);
282 response->SetMimeType(
fArg->GetContentType());
283 response->SetStatus(200);
284 response_length =
fArg->GetContentLength();
286 if (
fArg->NumHeader() > 0) {
287 CefResponse::HeaderMap headers;
291 headers.emplace(CefString(
name.Data()), CefString(
value.Data()));
293 response->SetHeaderMap(headers);
299 bool ReadResponse(
void *data_out,
int bytes_to_read,
int &bytes_read, CefRefPtr<CefCallback> callback)
override
301 CEF_REQUIRE_IO_THREAD();
303 if (!
fArg)
return false;
307 if (fTransferOffset < fArg->GetContentLength()) {
308 char *data_ = (
char *)
fArg->GetContent();
311 if (transfer_size > bytes_to_read)
312 transfer_size = bytes_to_read;
316 bytes_read = transfer_size;
323 return bytes_read > 0;
332 CefRefPtr<CefBrowser> browser,
333 CefRefPtr<CefFrame> frame,
334 CefRefPtr<CefRequest> request) {
335 CEF_REQUIRE_IO_THREAD();
337 std::string addr = request->GetURL().ToString();
338 std::string prefix =
"http://rootserver.local";
340 if (addr.compare(0, prefix.length(), prefix) != 0)
343 int indx = std::stoi(addr.substr(prefix.length(), addr.find(
"/", prefix.length()) - prefix.length()));
357 TUrl url(addr.c_str());
359 const char *inp_path = url.
GetFile();
374 CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(fname.
Data());
378 return new CefStreamResourceHandler(mime, stream);
381 std::string inp_method = request->GetMethod().ToString();
384 handler->
fArg->SetMethod(inp_method.c_str());
385 handler->
fArg->SetPathAndFileName(inp_path);
386 handler->
fArg->SetTopName(
"webgui");
388 if (inp_method ==
"POST") {
390 CefRefPtr< CefPostData > post_data = request->GetPostData();
396 CefPostData::ElementVector elements;
397 post_data->GetElements(elements);
398 size_t sz = 0, off = 0;
399 for (
unsigned n = 0;
n < elements.size(); ++
n)
400 sz += elements[
n]->GetBytesCount();
404 for (
unsigned n = 0;
n < elements.size(); ++
n) {
405 sz = elements[
n]->GetBytes(elements[
n]->GetBytesCount(), (
char *)
data.data() + off);
408 handler->
fArg->SetPostData(std::move(
data));
410 }
else if (inp_query.
Index(
"&post=") !=
kNPOS) {
413 handler->
fArg->SetPostData(std::string(buf.
Data()));
417 handler->
fArg->SetQuery(inp_query.
Data());
430 std::string url =
"file:///batch_page";
434 fResourceManager->AddContentProvider(url, cont,
"text/html", 0, std::string());
452 return std::string(
"http://rootserver.local") + std::to_string(indx) + addr;
#define R__LOG_WARNING(...)
#define R__LOG_ERROR(...)
#define R__LOG_DEBUG(DEBUGLEVEL,...)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t src
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
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
void OnBeforeClose(CefRefPtr< CefBrowser > browser) override
CefRefPtr< CefResourceHandler > GetResourceHandler(CefRefPtr< CefBrowser > browser, CefRefPtr< CefFrame > frame, CefRefPtr< CefRequest > request) override
bool DoClose(CefRefPtr< CefBrowser > browser) override
void CloseAllBrowsers(bool force_close)
void PlatformTitleChange(CefRefPtr< CefBrowser > browser, const CefString &title)
cef_return_value_t OnBeforeResourceLoad(CefRefPtr< CefBrowser > browser, CefRefPtr< CefFrame > frame, CefRefPtr< CefRequest > request, CefRefPtr< CefCallback > callback) override
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...
bool OnConsoleMessage(CefRefPtr< CefBrowser > browser, cef_log_severity_t level, const CefString &message, const CefString &source, int line) override
void OnTitleChange(CefRefPtr< CefBrowser > browser, const CefString &title) override
void OnAfterCreated(CefRefPtr< CefBrowser > browser) 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
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.
~TGuiResourceHandler() override
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
TGuiResourceHandler(THttpServer *serv, bool dummy=false)
void GetResponseHeaders(CefRefPtr< CefResponse > response, int64 &response_length, CefString &redirectUrl) override
Contains arguments for single HTTP call.
const void * GetContent() const
void SetContent(const char *cont)
Set content as text.
Online http server for arbitrary ROOT application.
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()