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/cef_browser.h"
30#include "include/cef_version.h"
31#include "include/views/cef_browser_view.h"
32#include "include/views/cef_window.h"
33#include "include/wrapper/cef_helpers.h"
34
35#include "THttpServer.h"
36#include "TTimer.h"
37#include <ROOT/RLogger.hxx>
38
40
41namespace {
42
43// When using the Views framework this object provides the delegate
44// implementation for the CefWindow that hosts the Views-based browser.
45class SimpleWindowDelegate : public CefWindowDelegate {
46 CefRefPtr<CefBrowserView> fBrowserView;
47 int fWidth = 800; ///< preferred window width
48 int fHeight = 600; ///< preferred window height
49 bool fBatch = false;
50public:
51 explicit SimpleWindowDelegate(CefRefPtr<CefBrowserView> browser_view, int width = 800, int height = 600, bool batch = false)
52 : fBrowserView(browser_view), fWidth(width), fHeight(height), fBatch(batch)
53 {
54 }
55
56 void OnWindowCreated(CefRefPtr<CefWindow> window) override
57 {
58 window->AddChildView(fBrowserView);
59
60 if (fBatch) {
61 window->Hide();
62 } else {
63 window->Show();
64 // Give keyboard focus to the browser view.
65 fBrowserView->RequestFocus();
66 }
67 }
68
69 void OnWindowDestroyed(CefRefPtr<CefWindow> window) override { fBrowserView = nullptr; }
70
71 bool CanClose(CefRefPtr<CefWindow> window) override
72 {
73 // Allow the window to close if the browser says it's OK.
74 CefRefPtr<CefBrowser> browser = fBrowserView->GetBrowser();
75 if (browser)
76 return browser->GetHost()->TryCloseBrowser();
77 return true;
78 }
79
81 {
82 return CefSize(fWidth, fHeight);
83 }
84
85
86private:
87
88 IMPLEMENT_REFCOUNTING(SimpleWindowDelegate);
89 DISALLOW_COPY_AND_ASSIGN(SimpleWindowDelegate);
90};
91
92
93class SimpleBrowserViewDelegate : public CefBrowserViewDelegate {
94 public:
95 SimpleBrowserViewDelegate() {}
96
99 bool is_devtools) override {
100 // Create a new top-level Window for the popup. It will show itself after
101 // creation.
102 CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(popup_browser_view));
103
104 // We created the Window.
105 return true;
106 }
107
108 private:
109 IMPLEMENT_REFCOUNTING(SimpleBrowserViewDelegate);
110 DISALLOW_COPY_AND_ASSIGN(SimpleBrowserViewDelegate);
111};
112
113
114} // namespace
115
117 THttpServer *serv, const std::string &url, const std::string &cont,
118 int width, int height, bool headless)
119 : CefApp(), CefBrowserProcessHandler(), fUseViewes(use_viewes), fSupressLog(supress_log), fFirstServer(serv), fFirstUrl(url), fFirstContent(cont), fFirstHeadless(headless)
120{
121 fFirstRect.Set(0, 0, width, height);
122
123#if defined(OS_WIN) || defined(OS_LINUX)
124 // Create the browser using the Views framework if "--use-views" is specified
125 // via the command-line. Otherwise, create the browser using the native
126 // platform framework. The Views framework is currently only supported on
127 // Windows and Linux.
128#else
129// if (fUseViewes) {
130// R__LOG_ERROR(CefWebDisplayLog()) << "view framework does not supported by CEF on the platform, switching off";
131// fUseViewes = false;
132// }
133#endif
134
135}
136
137
143
144
146{
147 // registrar->AddCustomScheme("rootscheme", true, true, true, true, true, true);
148 // registrar->AddCustomScheme("rootscheme", true, false, false, true, false, false);
149}
150
152{
153 if (fSupressLog) {
154 command_line->AppendSwitchWithValue("v", "-1");
155 command_line->AppendSwitch("disable-logging");
156 command_line->AppendSwitchWithValue("enable-logging", "none");
157 }
158}
159
163
165{
167
168 if (!fFirstUrl.empty() || !fFirstContent.empty()) {
170 fFirstUrl.clear();
171 fFirstContent.clear();
172 }
173}
174
175
176void SimpleApp::StartWindow(THttpServer *serv, const std::string &addr, const std::string &cont, CefRect &rect)
177{
179
180 bool is_batch = addr.empty() && !cont.empty();
181
182 if (!fGuiHandler)
184
185 std::string url;
186
187 if(is_batch)
188 url = fGuiHandler->AddBatchPage(cont);
189 else if (serv)
190 url = fGuiHandler->MakePageUrl(serv, addr);
191 else
192 url = addr;
193
194 // Specify CEF browser settings here.
196 if (is_batch)
197 browser_settings.windowless_frame_rate = 30;
198 // browser_settings.plugins = STATE_DISABLED;
199 // browser_settings.file_access_from_file_urls = STATE_ENABLED;
200 // browser_settings.universal_access_from_file_urls = STATE_ENABLED;
201 // browser_settings.web_security = STATE_DISABLED;
202
203 if (fUseViewes) {
204 // Create the BrowserView.
206 CefBrowserView::CreateBrowserView(fGuiHandler, url, browser_settings, nullptr, nullptr, new SimpleBrowserViewDelegate());
207
208 // Create the Window. It will show itself after creation.
209 CefWindow::CreateTopLevelWindow(new SimpleWindowDelegate(browser_view, rect.width, rect.height, is_batch));
210
211 if (fNextHandle) {
212 fNextHandle->SetBrowser(browser_view->GetBrowser());
213 fNextHandle = nullptr; // used only once
214 }
215
216 } else {
217
219
220 // TODO: Seems to be, to configure window_info.SetAsWindowless,
221 // one should implement CefRenderHandler
222
223 #if defined(OS_WIN)
224 if (!rect.IsEmpty())
225 window_info.SetAsChild(0, rect);
226 // On Windows we need to specify certain flags that will be passed to
227 // CreateWindowEx().
228 window_info.SetAsPopup(0, "cefsimple");
229 if (is_batch)
230 // window_info.SetAsWindowless(GetDesktopWindow());
231 window_info.SetAsWindowless(kNullWindowHandle);
232 #else
233 if (!rect.IsEmpty())
234 window_info.SetAsChild(0, rect);
235 if (is_batch)
236 window_info.SetAsWindowless(kNullWindowHandle);
237 #endif
238
239 // Create the first browser window.
240 auto browser = CefBrowserHost::CreateBrowserSync(window_info, fGuiHandler, url, browser_settings, nullptr, nullptr);
241
242 if (fNextHandle) {
244 fNextHandle = nullptr; // used only once
245 }
246
247 }
248
249}
250
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