Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
simple_app.cxx
Go to the documentation of this file.
1// Author: Sergey Linev <S.Linev@gsi.de>
2// Date: 2017-06-29
3// Warning: This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback is welcome!
4
5// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
6// reserved. Use of this source code is governed by a BSD-style license that
7// can be found in the LICENSE file.
8
9/*************************************************************************
10 * Copyright (C) 1995-2023, Rene Brun and Fons Rademakers. *
11 * All rights reserved. *
12 * *
13 * For the licensing terms see $ROOTSYS/LICENSE. *
14 * For the list of contributors see $ROOTSYS/README/CREDITS. *
15 *************************************************************************/
16
17
18#if !defined(_MSC_VER)
19#pragma GCC diagnostic ignored "-Wunused-parameter"
20#pragma GCC diagnostic ignored "-Wshadow"
21#endif
22
23#include "simple_app.h"
24
25#include <string>
26#include <cstdio>
27#include <memory>
28
29#include "include/base/cef_build.h"
30#include "include/cef_browser.h"
31#include "include/cef_version.h"
32#include "include/views/cef_browser_view.h"
33#include "include/views/cef_window.h"
34#include "include/wrapper/cef_helpers.h"
35
36#include "THttpServer.h"
37#include "TTimer.h"
38#include <ROOT/RLogger.hxx>
39
41
42namespace {
43
44// When using the Views framework this object provides the delegate
45// implementation for the CefWindow that hosts the Views-based browser.
46class SimpleWindowDelegate : public CefWindowDelegate {
47 CefRefPtr<CefBrowserView> fBrowserView;
48 int fWidth = 800; ///< preferred window width
49 int fHeight = 600; ///< preferred window height
50 bool fBatch = false;
51public:
52 explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browser_view, int width = 800, int height = 600, bool batch = false)
53 : fBrowserView(browser_view), fWidth(width), fHeight(height), fBatch(batch)
54 {
55 }
56
57 void OnWindowCreated(CefRefPtr<CefWindow> window) override
58 {
59 window->AddChildView(fBrowserView);
60
61 if (fBatch) {
62 window->Hide();
63 } else {
64 window->Show();
65 // Give keyboard focus to the browser view.
66 fBrowserView->RequestFocus();
67 }
68 }
69
70 void OnWindowDestroyed(CefRefPtr<CefWindow> window) override { fBrowserView = nullptr; }
71
72 bool CanClose(CefRefPtr<CefWindow> window) override
73 {
74 // Allow the window to close if the browser says it's OK.
75 CefRefPtr<CefBrowser> browser = fBrowserView->GetBrowser();
76 if (browser)
77 return browser->GetHost()->TryCloseBrowser();
78 return true;
79 }
80
82 {
83 return CefSize(fWidth, fHeight);
84 }
85
86
87private:
88
89 IMPLEMENT_REFCOUNTING(SimpleWindowDelegate);
90 DISALLOW_COPY_AND_ASSIGN(SimpleWindowDelegate);
91};
92
93
94class SimpleBrowserViewDelegate : public CefBrowserViewDelegate {
95 public:
96 SimpleBrowserViewDelegate() {}
97
100 bool is_devtools) override {
101 // Create a new top-level Window for the popup. It will show itself after
102 // creation.
103 CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(popup_browser_view));
104
105 // We created the Window.
106 return true;
107 }
108
109 private:
110 IMPLEMENT_REFCOUNTING(SimpleBrowserViewDelegate);
111 DISALLOW_COPY_AND_ASSIGN(SimpleBrowserViewDelegate);
112};
113
114
115} // namespace
116
118 THttpServer *serv, const std::string &url, const std::string &cont,
119 int width, int height, bool headless)
120 : CefApp(), CefBrowserProcessHandler(), fUseViewes(use_viewes), fSupressLog(supress_log), fFirstServer(serv), fFirstUrl(url), fFirstContent(cont), fFirstHeadless(headless)
121{
122 fFirstRect.Set(0, 0, width, height);
123
124#if defined(OS_WIN) || defined(OS_LINUX)
125 // Create the browser using the Views framework if "--use-views" is specified
126 // via the command-line. Otherwise, create the browser using the native
127 // platform framework. The Views framework is currently only supported on
128 // Windows and Linux.
129#else
130// if (fUseViewes) {
131// R__LOG_ERROR(CefWebDisplayLog()) << "view framework does not supported by CEF on the platform, switching off";
132// fUseViewes = false;
133// }
134#endif
135
136}
137
138
144
145
147{
148 // registrar->AddCustomScheme("rootscheme", true, true, true, true, true, true);
149 // registrar->AddCustomScheme("rootscheme", true, false, false, true, false, false);
150}
151
153{
154 if (fSupressLog) {
155 command_line->AppendSwitchWithValue("v", "-1");
156 command_line->AppendSwitch("disable-logging");
157 command_line->AppendSwitchWithValue("enable-logging", "none");
158 }
159
160#ifdef OS_MACOSX
161
162 if (fNextHeadless) {
163 command_line->AppendSwitchWithValue("use-angle", "swiftshader");
164 command_line->AppendSwitch("enable-unsafe-swiftshader");
165 command_line->AppendSwitch("disable-gpu");
166 } else {
167 command_line->AppendSwitchWithValue("use-angle", "metal");
168 command_line->AppendSwitch("ignore-gpu-blocklist");
169 command_line->AppendSwitch("enable-webgl");
170 }
171#endif
172}
173
177
179{
181
182 if (!fFirstUrl.empty() || !fFirstContent.empty()) {
184 fFirstUrl.clear();
185 fFirstContent.clear();
186 }
187}
188
189
190void SimpleApp::StartWindow(THttpServer *serv, const std::string &addr, const std::string &cont, CefRect &rect)
191{
193
194 bool is_batch = addr.empty() && !cont.empty();
195
196 if (!fGuiHandler)
198
199 std::string url;
200
201 if(is_batch)
202 url = fGuiHandler->AddBatchPage(cont);
203 else if (serv)
204 url = fGuiHandler->MakePageUrl(serv, addr);
205 else
206 url = addr;
207
208 // Specify CEF browser settings here.
210 if (is_batch)
211 browser_settings.windowless_frame_rate = 30;
212 // browser_settings.plugins = STATE_DISABLED;
213 // browser_settings.file_access_from_file_urls = STATE_ENABLED;
214 // browser_settings.universal_access_from_file_urls = STATE_ENABLED;
215 // browser_settings.web_security = STATE_DISABLED;
216
217 if (fUseViewes) {
218 // Create the BrowserView.
220 CefBrowserView::CreateBrowserView(fGuiHandler, url, browser_settings, nullptr, nullptr, new SimpleBrowserViewDelegate());
221
222 // Create the Window. It will show itself after creation.
223 CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view, rect.width, rect.height, is_batch));
224
225 if (fNextHandle) {
226 fNextHandle->SetBrowser(browser_view->GetBrowser());
227 fNextHandle = nullptr; // used only once
228 }
229
230 } else {
231
233
234 // TODO: Seems to be, to configure window_info.SetAsWindowless,
235 // one should implement CefRenderHandler
236
237 #if defined(OS_WIN)
238 if (!rect.IsEmpty())
239 window_info.SetAsChild(0, rect);
240 // On Windows we need to specify certain flags that will be passed to
241 // CreateWindowEx().
242 window_info.SetAsPopup(0, "cefsimple");
243 if (is_batch)
244 // window_info.SetAsWindowless(GetDesktopWindow());
245 window_info.SetAsWindowless(kNullWindowHandle);
246 #else
247 if (!rect.IsEmpty())
248 window_info.SetAsChild(0, rect);
249 if (is_batch)
250 window_info.SetAsWindowless(kNullWindowHandle);
251 #endif
252
253 // Create the first browser window.
254 auto browser = CefBrowserHost::CreateBrowserSync(window_info, fGuiHandler, url, browser_settings, nullptr, nullptr);
255
256 if (fNextHandle) {
258 fNextHandle = nullptr; // used only once
259 }
260
261 }
262
263}
264
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t rect
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
void SetBrowser(CefRefPtr< CefBrowser > br)
RCefWebDisplayHandle * fNextHandle
next handle where browser will be created
Definition simple_app.h:45
bool fNextHeadless
if next handle display is headless
Definition simple_app.h:46
std::string fFirstUrl
! first URL to open
Definition simple_app.h:41
void SetNextHandle(RCefWebDisplayHandle *handle, bool headless)
bool fUseViewes
! is views framework used
Definition simple_app.h:38
void OnContextInitialized() override
THttpServer * fFirstServer
! first server
Definition simple_app.h:40
void StartWindow(THttpServer *serv, const std::string &url, const std::string &cont, CefRect &rect)
bool fSupressLog
! supress log output when possible
Definition simple_app.h:39
void OnBeforeChildProcessLaunch(CefRefPtr< CefCommandLine > command_line) override
CefRect fFirstRect
! original width
Definition simple_app.h:43
void OnRegisterCustomSchemes(CefRawPtr< CefSchemeRegistrar > registrar) override
CefRefPtr< GuiHandler > fGuiHandler
! normal handler
Definition simple_app.h:48
std::string fFirstContent
! first page content open
Definition simple_app.h:42
SimpleApp(bool use_viewes, bool supress_log, THttpServer *serv=nullptr, const std::string &url="", const std::string &cont="", int width=0, int height=0, bool headless=false)
void OnBeforeCommandLineProcessing(const CefString &process_type, CefRefPtr< CefCommandLine > command_line) override
Online http server for arbitrary ROOT application.
Definition THttpServer.h:31