File indexing completed on 2025-01-18 10:10:50
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef ROOT7_RWebDisplayHandle
0014 #define ROOT7_RWebDisplayHandle
0015
0016 #include <ROOT/RWebDisplayArgs.hxx>
0017
0018 #include <string>
0019 #include <map>
0020 #include <memory>
0021 #include <vector>
0022
0023 namespace ROOT {
0024
0025 class RWebDisplayHandle {
0026
0027 std::string fUrl;
0028
0029 std::string fContent;
0030
0031 protected:
0032
0033 class Creator {
0034 public:
0035 virtual std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args) = 0;
0036 virtual bool IsActive() const { return true; }
0037 virtual ~Creator() = default;
0038 };
0039
0040 class BrowserCreator : public Creator {
0041 protected:
0042 std::string fProg;
0043 std::string fExec;
0044 std::string fHeadlessExec;
0045 std::string fBatchExec;
0046
0047 void TestProg(const std::string &nexttry, bool check_std_paths = false);
0048
0049 virtual void ProcessGeometry(std::string &, const RWebDisplayArgs &) {}
0050 virtual std::string MakeProfile(std::string &, bool) { return ""; }
0051
0052 public:
0053
0054 BrowserCreator(bool custom = true, const std::string &exec = "");
0055
0056 std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args) override;
0057
0058 ~BrowserCreator() override = default;
0059 };
0060
0061 class ChromeCreator : public BrowserCreator {
0062 bool fEdge{false};
0063 std::string fEnvPrefix;
0064 int fChromeVersion{-1};
0065 public:
0066 ChromeCreator(bool is_edge = false);
0067 ~ChromeCreator() override = default;
0068 bool IsActive() const override { return !fProg.empty(); }
0069 void ProcessGeometry(std::string &, const RWebDisplayArgs &) override;
0070 std::string MakeProfile(std::string &exec, bool) override;
0071 };
0072
0073 class FirefoxCreator : public BrowserCreator {
0074 public:
0075 FirefoxCreator();
0076 ~FirefoxCreator() override = default;
0077 bool IsActive() const override { return !fProg.empty(); }
0078 void ProcessGeometry(std::string &, const RWebDisplayArgs &) override;
0079 std::string MakeProfile(std::string &exec, bool batch) override;
0080 };
0081
0082 static std::map<std::string, std::unique_ptr<Creator>> &GetMap();
0083
0084 static std::unique_ptr<Creator> &FindCreator(const std::string &name, const std::string &libname = "");
0085
0086 static bool CheckIfCanProduceImages(RWebDisplayArgs &args);
0087
0088 public:
0089
0090
0091 RWebDisplayHandle(const std::string &url) : fUrl(url) {}
0092
0093
0094 virtual ~RWebDisplayHandle() = default;
0095
0096
0097 const std::string &GetUrl() const { return fUrl; }
0098
0099
0100 void SetContent(const std::string &cont) { fContent = cont; }
0101
0102 const std::string &GetContent() const { return fContent; }
0103
0104
0105 virtual bool Resize(int, int) { return false; }
0106
0107 static bool NeedHttpServer(const RWebDisplayArgs &args);
0108
0109 static std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args);
0110
0111 static bool DisplayUrl(const std::string &url);
0112
0113 static bool CanProduceImages(const std::string &browser = "");
0114
0115 static bool ProduceImage(const std::string &fname, const std::string &json, int width = 800, int height = 600, const char *batch_file = nullptr);
0116
0117 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);
0118 };
0119
0120 }
0121
0122 #endif