Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-13 09:10:22

0001 // Author: Sergey Linev <s.linev@gsi.de>
0002 // Date: 2018-10-17
0003 // Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
0004 
0005 /*************************************************************************
0006  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers.               *
0007  * All rights reserved.                                                  *
0008  *                                                                       *
0009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
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 #include "TString.h"
0023 
0024 namespace ROOT {
0025 
0026 class RWebDisplayHandle {
0027 
0028    std::string fUrl; ///!< URL used to launch display
0029 
0030    std::string fContent; ///!< page content
0031 
0032 protected:
0033 
0034    class Creator {
0035    public:
0036       virtual std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args) = 0;
0037       virtual bool IsActive() const { return true; }
0038       virtual ~Creator() = default;
0039       virtual bool IsSnapChromium() const { return false; }
0040    };
0041 
0042    class BrowserCreator : public Creator {
0043    protected:
0044       std::string fProg;  ///< browser executable
0045       std::string fExec;  ///< standard execute line
0046       std::string fHeadlessExec; ///< headless execute line
0047       std::string fBatchExec; ///< batch execute line
0048       void TestProg(const std::string &nexttry, bool check_std_paths = false);
0049       virtual void ProcessGeometry(std::string &, const RWebDisplayArgs &) {}
0050       virtual std::string MakeProfile(std::string &, bool) { return ""; }
0051    public:
0052       BrowserCreator(bool custom = true, const std::string &exec = "");
0053       std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args) override;
0054       ~BrowserCreator() override = default;
0055       static FILE *TemporaryFile(TString &name, int use_home_dir = 0, const char *suffix = nullptr);
0056    };
0057 
0058    class SafariCreator : public BrowserCreator {
0059    public:
0060       SafariCreator();
0061       ~SafariCreator() override = default;
0062       bool IsActive() const override;
0063    };
0064 
0065    class ChromeCreator : public BrowserCreator {
0066       bool fEdge{false};
0067       std::string fEnvPrefix; // rc parameters prefix
0068       int fChromeVersion{-1}; // major version in chrome browser
0069    public:
0070       ChromeCreator(bool is_edge = false);
0071       ~ChromeCreator() override = default;
0072       bool IsActive() const override { return !fProg.empty(); }
0073       bool IsSnapChromium() const override { return fProg == "/snap/bin/chromium"; }
0074       void ProcessGeometry(std::string &, const RWebDisplayArgs &) override;
0075       std::string MakeProfile(std::string &exec, bool) override;
0076    };
0077 
0078    class FirefoxCreator : public BrowserCreator {
0079    public:
0080       FirefoxCreator();
0081       ~FirefoxCreator() override = default;
0082       bool IsActive() const override { return !fProg.empty(); }
0083       void ProcessGeometry(std::string &, const RWebDisplayArgs &) override;
0084       std::string MakeProfile(std::string &exec, bool batch) override;
0085    };
0086 
0087    static std::map<std::string, std::unique_ptr<Creator>> &GetMap();
0088 
0089    static std::unique_ptr<Creator> &FindCreator(const std::string &name, const std::string &libname = "");
0090 
0091    static bool CheckIfCanProduceImages(RWebDisplayArgs &args);
0092 
0093 public:
0094 
0095    /// constructor
0096    RWebDisplayHandle(const std::string &url) : fUrl(url) {}
0097 
0098    /// required virtual destructor for correct cleanup at the end
0099    virtual ~RWebDisplayHandle() = default;
0100 
0101    /// returns url of start web display
0102    const std::string &GetUrl() const { return fUrl; }
0103 
0104    /// set content
0105    void SetContent(const std::string &cont) { fContent = cont; }
0106    /// get content
0107    const std::string &GetContent() const { return fContent; }
0108 
0109    /// resize web window - if possible
0110    virtual bool Resize(int, int) { return false; }
0111 
0112    /// remove file which was used to startup widget - if possible
0113    virtual void RemoveStartupFiles() {}
0114 
0115    static bool NeedHttpServer(const RWebDisplayArgs &args);
0116 
0117    static std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args);
0118 
0119    static bool DisplayUrl(const std::string &url);
0120 
0121    static bool CanProduceImages(const std::string &browser = "");
0122 
0123    static std::string GetImageFormat(const std::string &fname);
0124 
0125    static bool ProduceImage(const std::string &fname, const std::string &json, int width = 800, int height = 600, const char *batch_file = nullptr);
0126 
0127    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);
0128 
0129    static std::vector<std::string> ProduceImagesNames(const std::string &fname, unsigned nfiles = 1);
0130 
0131    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);
0132 
0133 };
0134 
0135 } // namespace ROOT
0136 
0137 #endif