Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

ChromiumBrowser

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 three GUI backends are supported: X11, GTK/X11 and Windows.

 

 

Building CEF application on Linux

 

download "Standard Distribution" CEF package for Linux from http://opensource.spotify.com/cefbuilds/index.html

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. It should look like this:

 

        ChromiumBrowserExample

        ├── cef_100_percent.pak

        ├── cef_200_percent.pak

        ├── cef.pak

        ├── cef_extensions.pak

        ├── chrome-sandbox

        ├── ChromiumBrowserExample

        ├── devtools_resources.pak

        ├── icudtl.dat

        ├── libcef.so

        ├── natives_blob.bin

        ├── snapshot_blob.bin

        └── locales

            ├── am.pak

            ├── ar.pak

            ├── bg.pak

            ├── bn.pak

            ├── ca.pak

            ├── cs.pak

            ├── da.pak

            ├── de.pak

            ├── el.pak

            ├── en-GB.pak

            ├── en-US.pak

            ├── es-419.pak

            ├── es.pak

            ├── et.pak

            ├── fa.pak

            ├── fil.pak

            ├── fi.pak

            ├── fr.pak

            ├── gu.pak

            ├── he.pak

            ├── hi.pak

            ├── hr.pak

            ├── hu.pak

            ├── id.pak

            ├── it.pak

            ├── ja.pak

            ├── kn.pak

            ├── ko.pak

            ├── lt.pak

            ├── lv.pak

            ├── ml.pak

            ├── mr.pak

            ├── ms.pak

            ├── nb.pak

            ├── nl.pak

            ├── pl.pak

            ├── pt-BR.pak

            ├── pt-PT.pak

            ├── ro.pak

            ├── ru.pak

            ├── sk.pak

            ├── sl.pak

            ├── sr.pak

            ├── sv.pak

            ├── sw.pak

            ├── ta.pak

            ├── te.pak

            ├── th.pak

            ├── tr.pak

            ├── uk.pak

            ├── vi.pak

            ├── zh-CN.pak

            └── zh-TW.pak

 

if you need Flash plugin, install google chrome browser and copy libpepflashplayer.so from /opt/google/chrome/PepperFlash to the output directory

 

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.2454.1328.gc45b7de_windows32

    LIB directories: the same path as above, for example

    C:\MyApps\cef_binary_3.2454.1328.gc45b7de_windows32

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. Your application directory should look like this:

 

        ChromiumBrowserExample

        │   cef.pak

        │   cef_100_percent.pak

        │   cef_200_percent.pak

        │   ChromiumBrowserExample.exe

        │   d3dcompiler_43.dll

        │   d3dcompiler_47.dll

        │   devtools_resources.pak

        │   icudtl.dat

        │   libcef.dll

        │   libEGL.dll

        │   libGLESv2.dll

        │   natives_blob.bin

        │   snapshot_blob.bin

        └───locales

                am.pak

                ar.pak

                bg.pak

                bn.pak

                ca.pak

                cs.pak

                da.pak

                de.pak

                el.pak

                en-GB.pak

                en-US.pak

                es-419.pak

                es.pak

                et.pak

                fa.pak

                fi.pak

                fil.pak

                fr.pak

                gu.pak

                he.pak

                hi.pak

                hr.pak

                hu.pak

                id.pak

                it.pak

                ja.pak

                kn.pak

                ko.pak

                lt.pak

                lv.pak

                ml.pak

                mr.pak

                ms.pak

                nb.pak

                nl.pak

                pl.pak

                pt-BR.pak

                pt-PT.pak

                ro.pak

                ru.pak

                sk.pak

                sl.pak

                sr.pak

                sv.pak

                sw.pak

                ta.pak

                te.pak

                th.pak

                tr.pak

                uk.pak

                vi.pak

                zh-CN.pak

                zh-TW.pak

 

if you need Flash plugin, install google chrome browser and copy pepflashplayer.dll from "c:\Program Files (x86)\Google\Chrome\Application\xxx\PepperFlash" to the output directory

 

Final remarks

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.

 

 

Constructor detail

 

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.

 


 

 

Public Method List

 

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<StringWhenUrlChange

Callback used to update address bar of a browser

 

 


 

Callback3<bool, bool, boolWhenStatus

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<boolWhenKeyboard

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, StringWhenConsoleMessage

Called to pass a message from JavaScript functions (console.log, console.debug). First parameter is URL, second - line number, third - message itself

 

 


 

Gate1<StringWhenCertificateError

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.

 


 

 

Do you want to contribute?