class ChromiumBrowser : public Ctrl
View in layout designer
|
View in working application
|

|

|
|
ChromiumBrowser is a control that embeds CEF3 (Chromium Embedded Framework) in Upp application. To run CEF you need to download and compile CEF library (it is not included in ChromiumBrowser package due to its size).
Currently two GUI backends are supported: X11 and Windows.
Building CEF application on Linux
|
|
download "Standard Distribution" CEF package for Linux from http://opensource.spotify.com/cefbuilds/index.html
install cmake and gtkglext-1.0:
sudo apt install cmake libgtkglext1-dev
unpack the archive to your "MyApps" directory
go to CEF directory and run following commands:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
make -j4 cefclient cefsimple
if there are any compilation errors install missing libraries.
go to out/Release subdirectory and configure sandbox binary:
sudo chown root:root chrome-sandbox
sudo chmod 4755 chrome-sandbox
check whether sandbox has correct owner and permissions:
-rwsr-xr-x 2 root root 19824 sty 21 15:08 chrome-sandbox
run cefclient application. If you see any errors on console it could mean that the compilation is broken and you have to download different version. Binary packages from cefbuilds.com are built automatically and not every compilation is guaranteed to work
configure library paths in TheIDE, menu Setup / Build methods:
INCLUDE directories - add CEF library directory, for example:
/home/$USER/MyApps/cef_binary_3.2840.1518.gffd843c_linux64
LIB directories - add CEF subdirectories containing libcef.so and libcef_dll_wrapper.a, for example:
/home/$USER/MyApps/cef_binary_3.2840.1518.gffd843c_linux64/libcef_dll
/home/$USER/MyApps/cef_binary_3.2840.1518.gffd843c_linux64/Release
/home/$USER/MyApps/cef_binary_3.2840.1518.gffd843c_linux64/libcef_dll_wrapper
open ChromiumBrowserExample from Bazaar and try to compile it
before you run compiled application, copy asset files and libraries to the output directory. Please check Release and Resources subdirectories from CEF to see the list of required files
if you need Flash plugin, install google chrome browser and copy libpepflashplayer.so and manifest.json from ~/.config/google-chrome/PepperFlash/ to the output directory. Alternatively flash can be downloaded directly from Adobe web page: http://fpdownload.adobe.com/pub/flashplayer/pdc/XX.X.X.XXX/flash_player_ppapi_linux.x86_64.tar.gz, where XX.X.X.XXX is version number. Current version is listed in section PPAPI_linuxchrome in the file: https://fpdownload.macromedia.com/pub/flashplayer/masterversion/masterversion.xml
Building CEF application on Windows
|
|
required software: Visual Studio 2015, CMake (http://www.cmake.org/download/)
download "Standard Distribution" CEF package for Windows from http://opensource.spotify.com/cefbuilds/index.html
unpack the archive to your "MyApps" directory
go to CEF directory and run following command:
cmake -G "Visual Studio 14"
open cef.sln in Visual Studio
change active solution configuration to "Release" (menu Build / Configuration Manager)
right click on "cefclient" in "Solution Explorer" window and select "Build"
run cefclient to check your build
change active solution configuration to "Debug" and rebuild "cefclient"
configure library paths in TheIDE, menu Setup / Build methods:
INCLUDE directories: add CEF library directory, for example:
c:\MyApps\cef_binary_3.3239.1700.g385b2d4_windows32
LIB directories: add directories containing *.lib files, for example:
C:\MyApps\cef_binary_3.3239.1700.g385b2d4_windows32\libcef_dll_wrapper\Release
C:\MyApps\cef_binary_3.3239.1700.g385b2d4_windows32\Release
open ChromiumBrowserExample from Bazaar and try to compile it
before you run compiled application, copy asset files and libraries to the output directory. Please check Resources and Release or Debug subdirectory from CEF to see the list of required files (you can skip *.lib files)
if you need Flash plugin, install google chrome browser and copy pepflashplayer.dll and manifest.json from "C:\Users\USER_NAME\AppData\Local\Google\Chrome\User Data\PepperFlash\XX.X.X.XXX\" to the output directory. Make sure you use file for correct architecture (x86/x64). 64-bit Flash library won't work with 32-bit CEF and vice versa.
CEF is multiprocess and multithreaded library. Your application binary file will be executed at least three times to open single web page. It means that you have to plan your "main" function carefully. Recommended way of starting an application looks like this:
GUI_APP_MAIN
{
SetLanguage(SetLNGCharset(GetSystemLNG(), CHARSET_UTF8));
if (ChromiumBrowser::IsChildProcess()){
ChromiumBrowser::ChildProcess();
}else{
ChromiumBrowserExample().Run();
}
}
This way you avoid initialization of your GUI class each time new process is executed by CEF
CEF uses UTF8 encoding. All URLs, strings containing JavaScript should use this encoding.
ChromiumBrowser()
Initializes ChromiumBrowser.
static const char * const JSFunctions[]
Table containing all names of javascript functions that should be registered as a bridge between javascript engine and native code. Last element must be nullptr. See WhenMessage for more details.
void Browse(const String & url)
Loads the specified url .
static void ChildProcess()
This function should be called from the application's GUI_APP_MAIN function to execute secondary processes. Function will block until secondary process is terminated
Callback1<String> WhenUrlChange
Callback used to update address bar of a browser
Callback3<bool, bool, bool> WhenStatus
Callback used to show browser status. First parameter is true when browser is loading page, second when back button is active and third when forward button is active
Callback2<String, const Vector<Value>&> WhenMessage
Bridge between javascript and native code. Callback is executed when registered JS function is called (see JSFunctions). First parameter is function name, second contains function parameters.
Callback WhenTakeFocus
Called when browser wants to return focus to its parent window. It could be used to return focus to an address bar.
Callback1<bool> WhenKeyboard
Called when a new node in the the browser gets focus. Bool parameter tells application whether node is editable or not. It is usually used to show or hide on-screen keyboard in devices with touch screen
Callback3<String, int, String> WhenConsoleMessage
Called to pass a message from JavaScript functions (console.log, console.debug). First parameter is URL, second - line number, third - message itself
Gate1<String> WhenCertificateError
Called when server certificate is not trusted. Gate should return true if you want to ignore the warning and load the page
static bool IsChildProcess()
This function should be called from the application GUI_APP_MAIN function to check whether process is secondary one. Secondary process is identified by "--type=..." command-line parameter.
ChromiumBrowser & StartPage(const char * url)
Sets url of a page that is loaded right after browser is started.
void ShowHTML(const String& html)
Loads the contents of html string (UTF-8 encoded).
String GetLocation()
Returns the URL of currently loaded page
void GoBack()
Navigates backwards
void GoForward()
Navigates forwards
void Stop()
Stops loading the page
void RefreshPage()
Reloads the current page
String GetVersion()
Returns version of Chromium Embedded Framework and Chromium itself
void ExecuteJavaScript(const char * js)
Executes a string of JavaScript code. String must be UTF-8 encoded.
|