fpCEF3

From Lazarus wiki
Revision as of 21:37, 14 June 2015 by Michl (talk | contribs) (German-> English translation)
Jump to navigationJump to search

Deutsch (de) | English (en)

Description

SimpleChromium.png

Chromium is a open source project (from Google), to create a own browser for different platforms. Among other things the browser chrome is based on this source data.

The Chromium Embedded Framework (CEF) is an open source framework for embedding a browser control based on Chromium. It can be used on Linux, Mac OS X and Windows in 32 and 64 bit versions. CEF is there in the versions CEF1 and CEF3 where CEF1 is no longer maintained.

There is a framework for Delphi (Delphi Chromium Embedded Framework - DCEF3) and two branches, which can be used for Lazarus/FreePascal (fpCEF3 and WACEF).

Installation

In addition to Lazarus package even the framework itself must be downloaded and made available to the project. It is important that the framework for the package fits. Which it is and some more helpful installation instructions can be found at Github: https://github.com/dliw/fpCEF3

At the time of writing this description (June 2015), CEF 3.1750 is the required framework.

Download Package

fpCEF3 with Git

git://github.com/dliw/fpCEF3.git

You can also download a zipped package:

master.zip

Package Installation

Chromium.png

After downloading of package fpCEF3, it can be installed in Lazarus:

  • Start Lazarus and open main menu Package -> Open package file (.lpk)...
  • Select the in the fpCEF3 subdirectory Component the file cef3.lpk
  • The package editing window will open
  • Click on Compile, the package will be compiled
  • Click on Use...-> Install and confirm the dialog window with Yes
  • Lazarus is now compiling and create a new tab Chromium in the component palette

Download Framework CEF3

You can now download the framework from here (or an older version from here) and made the libraries available for a particular project

Light bulb  Note: You'll be sure which framework version with the current fpCEF3 can be used! See Installation

Usage

A minimal example with a simple browser is created.

Windows

The CEF libraries are needed for loading, so it makes sense to create a new project folder, to save the project and the libraries in it together.

  • Create a new directory for the project to a location of your choice such as C:\SimpleBrowser
  • Copy the complete CEF3 directory Resources to C:\SimpleBrowser\Resources
  • Copy the contents of the CEF3 directory Release in the directory C:\SimpleBrowser (the DLLs are thus in the same directory as the project)

Now build the project with Lazarus

Save the project in the directory you specify for Windows (under C:\SimpleBrowser)

  • Drop a TEditButton on the form
  • With Object Inspector set the Name to edtURL, Align on alTop and ButtonCaption to go
  • Put a TChromium on the form and set the Name to Chromium and its Align to alClient
  • Create the OnButtonClick event handler for the TEditButton edtURL. Select the OnButtonClick in the Object Inspector tab events and click on the button [...]
  • Write following code (chromium should open at each click the URL in the text box):
procedure TForm1.edtURLClick(Sender: TObject);
begin
  Chromium.Load(UTF8Decode(edtURL.Text));
end;
  • Create the OnLoadEnd event handler for Chromium
  • Write following code (URL should be updated after any browsing):
procedure TForm1.ChromiumLoadEnd(Sender: TObject; const Browser: ICefBrowser;
  const Frame: ICefFrame; httpStatusCode: Integer);
begin
  edtURL.Text:=UTF8Encode(Browser.MainFrame.Url);
end;
  • Chromium must be initialized at the start of the program, you can do this with the OnCreate event handler of the form:
procedure TForm1.FormCreate(Sender: TObject);
begin
  CefResourcesDirPath:='Resources';
  CefLocalesDirPath:='Resources\locales';
  CefInitDefault;
  edtURL.Text:='http://www.lazarus-ide.org/';
end;
  • Run your program, if all goes well it might look like:

SimpleChromium.png

Further Informations

Thread in the German Lazarusforum


--Michl 22:58, 1 June 2015 (CEST)