Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
RWebDisplayHandle.hxx
Go to the documentation of this file.
1// Author: Sergey Linev <s.linev@gsi.de>
2// Date: 2018-10-17
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5/*************************************************************************
6 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
7 * All rights reserved. *
8 * *
9 * For the licensing terms see $ROOTSYS/LICENSE. *
10 * For the list of contributors see $ROOTSYS/README/CREDITS. *
11 *************************************************************************/
12
13#ifndef ROOT7_RWebDisplayHandle
14#define ROOT7_RWebDisplayHandle
15
17
18#include <string>
19#include <map>
20#include <memory>
21#include <vector>
22#include "TString.h"
23
24namespace ROOT {
25
27
28 std::string fUrl; ///!< URL used to launch display
29
30 std::string fContent; ///!< page content
31
32protected:
33
34 class Creator {
35 public:
36 virtual std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args) = 0;
37 virtual bool IsActive() const { return true; }
38 virtual ~Creator() = default;
39 virtual bool IsSnapChromium() const { return false; }
40 };
41
42 class BrowserCreator : public Creator {
43 protected:
44 std::string fProg; ///< browser executable
45 std::string fExec; ///< standard execute line
46 std::string fHeadlessExec; ///< headless execute line
47 std::string fBatchExec; ///< batch execute line
48 void TestProg(const std::string &nexttry, bool check_std_paths = false);
49 virtual void ProcessGeometry(std::string &, const RWebDisplayArgs &) {}
50 virtual std::string MakeProfile(std::string &, bool) { return ""; }
51 public:
52 BrowserCreator(bool custom = true, const std::string &exec = "");
53 std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args) override;
54 ~BrowserCreator() override = default;
55 static FILE *TemporaryFile(TString &name, int use_home_dir = 0, const char *suffix = nullptr);
56 };
57
59 public:
61 ~SafariCreator() override = default;
62 bool IsActive() const override;
63 };
64
66 bool fEdge{false};
67 std::string fEnvPrefix; // rc parameters prefix
68 int fChromeVersion{-1}; // major version in chrome browser
69 public:
70 ChromeCreator(bool is_edge = false);
71 ~ChromeCreator() override = default;
72 bool IsActive() const override { return !fProg.empty(); }
73 bool IsSnapChromium() const override { return fProg == "/snap/bin/chromium"; }
74 void ProcessGeometry(std::string &, const RWebDisplayArgs &) override;
75 std::string MakeProfile(std::string &exec, bool) override;
76 };
77
79 public:
81 ~FirefoxCreator() override = default;
82 bool IsActive() const override { return !fProg.empty(); }
83 void ProcessGeometry(std::string &, const RWebDisplayArgs &) override;
84 std::string MakeProfile(std::string &exec, bool batch) override;
85 };
86
87 static std::map<std::string, std::unique_ptr<Creator>> &GetMap();
88
89 static std::unique_ptr<Creator> &FindCreator(const std::string &name, const std::string &libname = "");
90
92
93public:
94
95 /// constructor
96 RWebDisplayHandle(const std::string &url) : fUrl(url) {}
97
98 /// required virtual destructor for correct cleanup at the end
99 virtual ~RWebDisplayHandle() = default;
100
101 /// returns url of start web display
102 const std::string &GetUrl() const { return fUrl; }
103
104 /// set content
105 void SetContent(const std::string &cont) { fContent = cont; }
106 /// get content
107 const std::string &GetContent() const { return fContent; }
108
109 /// resize web window - if possible
110 virtual bool Resize(int, int) { return false; }
111
112 /// remove file which was used to startup widget - if possible
113 virtual void RemoveStartupFiles() {}
114
115 static bool NeedHttpServer(const RWebDisplayArgs &args);
116
117 static std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args);
118
119 static bool DisplayUrl(const std::string &url);
120
121 static bool CanProduceImages(const std::string &browser = "");
122
123 static std::string GetImageFormat(const std::string &fname);
124
125 static bool ProduceImage(const std::string &fname, const std::string &json, int width = 800, int height = 600, const char *batch_file = nullptr);
126
127 static bool ProduceImages(const std::string &fname, const std::vector<std::string> &jsons, const std::vector<int> &widths, const std::vector<int> &heights, const char *batch_file = nullptr);
128
129 static std::vector<std::string> ProduceImagesNames(const std::string &fname, unsigned nfiles = 1);
130
131 static bool ProduceImages(const std::vector<std::string> &fnames, const std::vector<std::string> &jsons, const std::vector<int> &widths, const std::vector<int> &heights, const char *batch_file = nullptr);
132
133};
134
135} // namespace ROOT
136
137#endif
nlohmann::json json
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t width
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t height
char name[80]
Definition TGX11.cxx:110
Holds different arguments for starting browser with RWebDisplayHandle::Display() method.
std::string fBatchExec
batch execute line
std::string fHeadlessExec
headless execute line
static FILE * TemporaryFile(TString &name, int use_home_dir=0, const char *suffix=nullptr)
Create temporary file for web display Normally gSystem->TempFileName() method used to create file in ...
std::unique_ptr< RWebDisplayHandle > Display(const RWebDisplayArgs &args) override
Display given URL in web browser.
virtual void ProcessGeometry(std::string &, const RWebDisplayArgs &)
std::string fExec
standard execute line
void TestProg(const std::string &nexttry, bool check_std_paths=false)
Check if browser executable exists and can be used.
BrowserCreator(bool custom=true, const std::string &exec="")
Class to handle starting of web-browsers like Chrome or Firefox.
virtual std::string MakeProfile(std::string &, bool)
ChromeCreator(bool is_edge=false)
Constructor.
void ProcessGeometry(std::string &, const RWebDisplayArgs &) override
Replace $geometry placeholder with geometry settings Also RWebDisplayArgs::GetExtraArgs() are appende...
std::string MakeProfile(std::string &exec, bool) override
Handle profile argument.
virtual std::unique_ptr< RWebDisplayHandle > Display(const RWebDisplayArgs &args)=0
std::string MakeProfile(std::string &exec, bool batch) override
Create Firefox profile to run independent browser window.
void ProcessGeometry(std::string &, const RWebDisplayArgs &) override
Process window geometry for Firefox.
bool IsActive() const override
Returns true if it can be used.
Handle of created web-based display Depending from type of web display, holds handle of started brows...
const std::string & GetContent() const
get content
static std::map< std::string, std::unique_ptr< Creator > > & GetMap()
Static holder of registered creators of web displays.
static bool CheckIfCanProduceImages(RWebDisplayArgs &args)
Checks if configured browser can be used for image production.
static bool ProduceImages(const std::string &fname, const std::vector< std::string > &jsons, const std::vector< int > &widths, const std::vector< int > &heights, const char *batch_file=nullptr)
Produce image file(s) using JSON data as source Invokes JSROOT drawing functionality in headless brow...
static std::vector< std::string > ProduceImagesNames(const std::string &fname, unsigned nfiles=1)
Produce vector of file names for specified file pattern Depending from supported file forma.
static std::string GetImageFormat(const std::string &fname)
Detect image format There is special handling of ".screenshot.pdf" and ".screenshot....
virtual ~RWebDisplayHandle()=default
required virtual destructor for correct cleanup at the end
void SetContent(const std::string &cont)
set content
const std::string & GetUrl() const
returns url of start web display
RWebDisplayHandle(const std::string &url)
constructor
static bool ProduceImage(const std::string &fname, const std::string &json, int width=800, int height=600, const char *batch_file=nullptr)
Produce image file using JSON data as source Invokes JSROOT drawing functionality in headless browser...
static bool CanProduceImages(const std::string &browser="")
Returns true if image production for specified browser kind is supported If browser not specified - u...
static bool NeedHttpServer(const RWebDisplayArgs &args)
Check if http server required for display.
virtual bool Resize(int, int)
resize web window - if possible
static bool DisplayUrl(const std::string &url)
Display provided url in configured web browser.
std::string fContent
!< URL used to launch display
static std::unique_ptr< RWebDisplayHandle > Display(const RWebDisplayArgs &args)
Create web display.
static std::unique_ptr< Creator > & FindCreator(const std::string &name, const std::string &libname="")
Search for specific browser creator If not found, try to add one.
virtual void RemoveStartupFiles()
remove file which was used to startup widget - if possible
Basic string class.
Definition TString.h:139
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...