15#pragma GCC diagnostic ignored "-Wunused-parameter"
16#pragma GCC diagnostic ignored "-Wshadow"
26#include "include/base/cef_bind.h"
27#include "include/cef_app.h"
28#include "include/cef_version.h"
29#include "include/views/cef_browser_view.h"
30#include "include/views/cef_window.h"
31#include "include/wrapper/cef_closure_task.h"
32#include "include/wrapper/cef_helpers.h"
33#include "include/cef_parser.h"
34#include "include/wrapper/cef_stream_resource_handler.h"
63 CEF_REQUIRE_UI_THREAD();
67 CefRefPtr<CefBrowserView> browser_view = CefBrowserView::GetForBrowser(browser);
69 CefRefPtr<CefWindow> window = browser_view->GetWindow();
70 if (window) window->SetTitle(title);
80 CEF_REQUIRE_UI_THREAD();
88 CEF_REQUIRE_UI_THREAD();
105 CEF_REQUIRE_UI_THREAD();
110 if ((*bit)->IsSame(browser)) {
120 CefQuitMessageLoop();
127 return std::string(
"data:") +
mime_type +
";base64," +
128 CefURIEncode(CefBase64Encode(
data.data(),
data.size()),
false).ToString();
133 const CefString &errorText,
const CefString &failedUrl)
135 CEF_REQUIRE_UI_THREAD();
138 if (errorCode == ERR_ABORTED)
151 printf(
"Fail to load URL %s\n", failedUrl.ToString().substr(0,100).c_str());
156 if (!CefCurrentlyOn(TID_UI)) {
166 br->GetHost()->CloseBrowser(force_close);
170 cef_log_severity_t level,
171 const CefString &message,
const CefString &source,
174 std::string
src = source.ToString().substr(0,100);
177 case LOGSEVERITY_WARNING:
181 case LOGSEVERITY_ERROR:
195 CefRefPtr<CefBrowser> browser,
196 CefRefPtr<CefFrame> frame,
197 CefRefPtr<CefRequest> request,
198 CefRefPtr<CefCallback> callback) {
199 CEF_REQUIRE_IO_THREAD();
215 const char *
GetWSKind()
const override {
return "longpoll"; }
241 std::shared_ptr<TCefHttpCallArg>
fArg;
250 fArg = std::make_shared<TCefHttpCallArg>();
255 void Cancel()
override { CEF_REQUIRE_IO_THREAD(); }
257 bool ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
override
259 CEF_REQUIRE_IO_THREAD();
262 fArg->AssignCallback(callback);
265 callback->Continue();
270#if CEF_VERSION_MAJOR > 114
271 void GetResponseHeaders(CefRefPtr<CefResponse> response, int64_t &response_length, CefString &redirectUrl)
override
273 void GetResponseHeaders(CefRefPtr<CefResponse> response, int64 &response_length, CefString &redirectUrl)
override
276 CEF_REQUIRE_IO_THREAD();
279 response->SetMimeType(
"text/html");
280 response->SetStatus(404);
283 response->SetMimeType(
fArg->GetContentType());
284 response->SetStatus(200);
285 response_length =
fArg->GetContentLength();
287 if (
fArg->NumHeader() > 0) {
288 CefResponse::HeaderMap headers;
292 headers.emplace(CefString(
name.Data()), CefString(
value.Data()));
294 response->SetHeaderMap(headers);
300 bool ReadResponse(
void *data_out,
int bytes_to_read,
int &bytes_read, CefRefPtr<CefCallback> callback)
override
302 CEF_REQUIRE_IO_THREAD();
304 if (!
fArg)
return false;
308 if (fTransferOffset < fArg->GetContentLength()) {
309 char *data_ = (
char *)
fArg->GetContent();
312 if (transfer_size > bytes_to_read)
313 transfer_size = bytes_to_read;
317 bytes_read = transfer_size;
324 return bytes_read > 0;
333 CefRefPtr<CefBrowser> browser,
334 CefRefPtr<CefFrame> frame,
335 CefRefPtr<CefRequest> request) {
336 CEF_REQUIRE_IO_THREAD();
338 std::string addr = request->GetURL().ToString();
339 std::string prefix =
"http://rootserver.local";
341 if (addr.compare(0, prefix.length(), prefix) != 0)
344 int indx = std::stoi(addr.substr(prefix.length(), addr.find(
"/", prefix.length()) - prefix.length()));
358 TUrl url(addr.c_str());
360 const char *inp_path = url.
GetFile();
369 std::ifstream ifs(fname.
Data());
376 CefRefPtr<CefStreamReader> stream = CefStreamReader::CreateForFile(fname.
Data());
380 return new CefStreamResourceHandler(mime, stream);
383 std::string inp_method = request->GetMethod().ToString();
386 handler->
fArg->SetMethod(inp_method.c_str());
387 handler->
fArg->SetPathAndFileName(inp_path);
388 handler->
fArg->SetTopName(
"webgui");
390 if (inp_method ==
"POST") {
392 CefRefPtr< CefPostData > post_data = request->GetPostData();
398 CefPostData::ElementVector elements;
399 post_data->GetElements(elements);
400 size_t sz = 0, off = 0;
401 for (
unsigned n = 0;
n < elements.size(); ++
n)
402 sz += elements[
n]->GetBytesCount();
406 for (
unsigned n = 0;
n < elements.size(); ++
n) {
407 sz = elements[
n]->GetBytes(elements[
n]->GetBytesCount(), (
char *)
data.data() + off);
410 handler->
fArg->SetPostData(std::move(
data));
412 }
else if (inp_query.
Index(
"&post=") !=
kNPOS) {
415 handler->
fArg->SetPostData(std::string(buf.
Data()));
419 handler->
fArg->SetQuery(inp_query.
Data());
432 std::string url =
"file:///batch_page";
436 fResourceManager->AddContentProvider(url, cont,
"text/html", 0, std::string());
454 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.
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
This class represents a WWW compatible URL.
const char * GetFile() const
const char * GetOptions() const
ROOT::Experimental::RLogChannel & CefWebDisplayLog()
ROOT::Experimental::RLogChannel & CefWebDisplayLog()