CEF4Delphi

Description

CEF4Delphi is an open source project created by Salvador Díaz Fau to embed Chromium-based browsers in applications made with Delphi.

Introduction

CEF4Delphi is based on DCEF3, made by Henri Gourvest, which is adapted to the 2623 branch of CEF3. In order to have Chromium-based web browser tabs in BriskBard it's necessary to use the latest stable branch of CEF3 and have frequent updates. DCEF3 hasn't been updated in the last months so it was decided to create a new project.

The main goal of CEF4Delphi is to simplify, whenever is possible, the work necessary to upgrade it to the latest version of CEF3. To achieve this goal it was necessary to take the following measures :

  • Some redundancies were removed. Now there's only one TChromium component.
  • The code comments copied from CEF3 were removed. The comments in CEF3 are updated as frequently as the code and they can be replaced by a reference to the CEF3 file where you can find them.
  • The code is now spread over many more smaller units.
  • There are new comments with the equivalencies between classes and types of CEF4Delphi and CEF3.

The latest version of CEF4Delphi uses the branch 2987 of CEF3. More precisely, it uses CEF 3.2987.1601.gf035232 which includes Chromium 57.0.2987.133 and as a result of that, you need Windows 7 or newer to make it work.

CEF4Delphi was developed and tested on Delphi 10 Seattle and it has been tested in Delphi 7, Delphi XE and Delphi 10.1.

Installation

To build and install CEF4Delphi in the latest version of Delphi you need to follow these steps :

  1. Download the latest version of CEF4Delphi from GitHub.
  2. Decompress CEF4Delphi into a directory. Make sure your user has write privileges in that directory.
  3. Run Delphi.
  4. Add the CEF4Delphi's source directory to the Library path in Delphi inside the Tools->Options menu. The Options window will show up and there you have to click on Environment Options->Delphi Options->Library, select the right platform (32 or 64 bits) and add directory in Library path.
  5. Open the file CEF4Delphi.dproj from Delphi.
  6. Right-click on the CEF4Delphi.bpl icon inside the Project manager and select the Build option.
  7. Right-click on the CEF4Delphi.bpl icon inside the Project manager and select the Install option.

To compile and install CEF4Delphi in Delphi 7 you need to follow these steps :

  1. Download the latest version of CEF4Delphi from GitHub.
  2. Decompress CEF4Delphi into a directory. Make sure your user has write privileges in that directory and create a subdirectory called CEF4Delphi\source\dcu.
  3. Run Delphi.
  4. Add the CEF4Delphi's source directory to the Library path in Delphi inside the Tools->Environment options menu. The Environment Options window will show up and there you have to select the Library tab to modify the Library path.
  5. Open the file CEF4Delphi_D7.dpk from Delphi.
  6. Click on the Compile button.
  7. Click on the Install button.

Usage

Before you use CEF4Delphi for the first time it's highly recommended to read all the information about CEF3 and the design documents of Chromium.

The CEF3 API documents are available at magpcss.org and there is extensive information about the CEF3 usage in its source code comments.

As you can see in the documentation, It's necessary to configure CEF3 before TApplication runs. In CEF4Delphi this initialization is easier thanks to the TCEFApplication class

Delphi applications use to have this code in the DPR file :

program Project1; uses Vcl.Forms, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TForm1, Form1); Application.Run; end.

To include CEF4Delphi you only have to add WinApi.Windows and uCEFApplication to the uses clause, crete the GlobalCEFApp global variable, call the GlobalCEFApp.StartMainProcess function and free GlobalCEFApp in the last step. You also have to add the SetPEFlags directive.

program Project1; uses WinApi.Windows, Vcl.Forms, uCEFApplication, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} begin GlobalCEFApp := TCefApplication.Create; if GlobalCEFApp.StartMainProcess then begin Application.Initialize; Application.MainFormOnTaskbar := True; Application.CreateForm(TForm1, Form1); Application.Run; end; GlobalCEFApp.Free; end.

If you wish a different CEF3 configuration you only have to modify the properties of GlobalCEFApp before the GlobalCEFApp.StartMainProcess function call. Almost all properties have the same meaning as the fields of cef_settings_t.

Other properties in TCefApplication :

  • Cookies : Directory where the web browser cookies are stored.
  • DeleteCache : Set to True if you wish to delete the cache during initialization.
  • DeleteCookies : Set to True if you wish to delete the cookies during initialization.
  • FlashEnabled : Set to True if you wish to use the version of Adobe Flash Player (PPAPI) installed in the operating system.
  • CheckCEFFiles : Set to True if you wish to check the integrity of the CEF3 files during the initialization.
  • EnableSpellingService : Set to True if you wish to use Google's spelling service.
  • EnableMediaStream : Set to True if you wish to enable media (WebRTC audio/video) streaming.
  • EnableSpeechInput : Set to True if you wish to enable speech input (x-webkit-speech).
  • SmoothScrolling : Set to True to enable smooth scroll animation.
  • FastUnload : Set to True to speed up the tab/window close.
  • DisableSafeBrowsing : Set to True to disable several anti phishing functions.
  • EnableHighDPISupport : Set to True to support high DPI.
  • MuteAudio : Set to True to mute all audio.

To add command line arguments use the AddCustomCommandLine procedure with any of the switches in these lists : peter.sh, cef_switches.cc.

If you need to use another executable for subprocesses check the SubProcess demo, configure the BrowserSubprocessPath property of TCefApplication with the name of the executable and create a crash_reporter.cfg file as described here.

After that, you must add different components depending on the type of application that you want :

  • Regular browser UI window : Add a TChromium and a TCEFWindowParent to the Form where you want to have a web browser and then call the CreateBrowser function with the TCEFWindowParent instance as the first parameter. Alternatively you can add a TChromiumWindow, which is a class that inherits from TCEFWindowParent and has a TChromium child control. Take a look at the MiniBrowser and SimpleBrowser demos for more details.
  • Off-Screen Rendering : Add a TChromium to the Form and call the CreateBrowser without parameters. Be sure to set GlobalCEFApp.WindowlessRenderingEnabled to True. Check the SimpleOSRBrowser demo for more details.

As you can see in the source code, TChromium groups the functions, procedures and events of :

Other properties and functions in TChromium that you may find interesting :

  • IncZoomStep, DecZoomStep, ResetZoomStep : Used to zoom in or out.
  • CustomHeaderName, CustomHeaderValue : Used to send customized headers on every request.
  • DoNotTrack : Set to True if you want to send the DNT header.
  • SendReferrer : Set to True if you want to send the 'referer' header.
  • ProxyType, ProxyServer, ProxyPort, ProxyUsername, ProxyPassword, ProxyScriptURL, ProxyByPassList : Proxy configuration as described here.

As all other CEF3 applications, you must copy the CEF3 binary distribution files to the directory where your CEF4Delphi application is located. Those files are part of a package called Standard Distribution and it's available at the CEF3 downloads page.

Once you've downloaded and decompressed the Standard Distribution package for the windows platform of your choice, you must copy the contents of the Release and Resources directories to the directory of your application's exe. Here's an screenshot of the final layout :

Final layout of the CEF3 binary distribution files with the application.
Final layout of the CEF3 binary distribution files with the application.
Notice how cef_sandbox.lib and libcef.lib can be omitted.

It's extremely important to only use the version of the CEF3 binary distribution files specified in the introduction. CEF3 evolves very rapidly and changes are introduced in every version. Your application could crash if you try to use an unsupported version of CEF3 with CEF4Delphi.

About the name

CEF4Delphi is just a numeronym and it should be interpreted as CEF for Delphi. It doesn't mean that it's based in CEF4.

How to help

If you wish to help in this project you can make a donation by clicking this button :

You can also help by telling your friends about this project, sharing the messages of this project on the social networks, writing articles about this project on your website, making suggestions, reporting issues, etc.

If you shop online you can also help by using these links for your purchases :





Copyright © 2017  All rights reserved.
Cookie usage

By browsing our site you agree to our use of cookies. You will only see this message once.
Find out more
Ok