Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/root/ROOT/RWebDisplayHandle.hxx was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 IsSnapBrowser() 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 IsSnapBrowser() 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       bool IsSnapBrowser() const override { return fProg == "/snap/bin/firefox"; }
0084       void ProcessGeometry(std::string &, const RWebDisplayArgs &) override;
0085       std::string MakeProfile(std::string &exec, bool batch) override;
0086    };
0087 
0088    static std::map<std::string, std::unique_ptr<Creator>> &GetMap();
0089 
0090    static std::unique_ptr<Creator> &FindCreator(const std::string &name, const std::string &libname = "");
0091 
0092    static bool CheckIfCanProduceImages(RWebDisplayArgs &args);
0093 
0094 public:
0095 
0096    /// constructor
0097    RWebDisplayHandle(const std::string &url) : fUrl(url) {}
0098 
0099    /// required virtual destructor for correct cleanup at the end
0100    virtual ~RWebDisplayHandle() = default;
0101 
0102    /// returns url of start web display
0103    const std::string &GetUrl() const { return fUrl; }
0104 
0105    /// set content
0106    void SetContent(const std::string &cont) { fContent = cont; }
0107    /// get content
0108    const std::string &GetContent() const { return fContent; }
0109 
0110    /// resize web window - if possible
0111    virtual bool Resize(int, int) { return false; }
0112 
0113    /// remove file which was used to startup widget - if possible
0114    virtual void RemoveStartupFiles() {}
0115 
0116    static bool NeedHttpServer(const RWebDisplayArgs &args);
0117 
0118    static std::unique_ptr<RWebDisplayHandle> Display(const RWebDisplayArgs &args);
0119 
0120    static bool DisplayUrl(const std::string &url);
0121 
0122    static bool CanProduceImages(const std::string &browser = "");
0123 
0124    static std::string GetImageFormat(const std::string &fname);
0125 
0126    static bool ProduceImage(const std::string &fname, const std::string &json, int width = 800, int height = 600, const char *batch_file = nullptr);
0127 
0128    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);
0129 
0130    static std::vector<std::string> ProduceImagesNames(const std::string &fname, unsigned nfiles = 1);
0131 
0132    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);
0133 
0134 };
0135 
0136 } // namespace ROOT
0137 
0138 #endif