Skip to content

Commit

Permalink
add support for OSR
Browse files Browse the repository at this point in the history
other changes:
 - remove cef3api_static
 - add examples: JavaScript, OSRDemo
 - fix DragHandler (thanks to Michl on lazarusforum.de)
  • Loading branch information
dliw committed Aug 16, 2014
1 parent 3d1c5d2 commit a676245
Show file tree
Hide file tree
Showing 27 changed files with 2,367 additions and 825 deletions.
12 changes: 8 additions & 4 deletions Component/cef3.lpk
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,22 @@
<CodeGeneration>
<Checks>
<IOChecks Value="True"/>
<RangeChecks Value="True"/>
<OverflowChecks Value="True"/>
</Checks>
<Optimizations>
<OptimizationLevel Value="2"/>
</Optimizations>
</CodeGeneration>
<Other>
<CompilerMessages>
<IgnoredMessages idx5024="True"/>
<MsgFileName Value=""/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Description Value="Chromium component for Lazarus"/>
<Version Minor="1" Release="1"/>
<Files Count="9">
<Version Minor="1" Release="2"/>
<Files Count="10">
<Item1>
<Filename Value="../cef.inc"/>
<Type Value="Include"/>
Expand Down Expand Up @@ -72,6 +71,11 @@
<HasRegisterProc Value="True"/>
<UnitName Value="cef3lcl"/>
</Item9>
<Item10>
<Filename Value="cef3osr.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="cef3osr"/>
</Item10>
</Files>
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="3">
Expand Down
3 changes: 2 additions & 1 deletion Component/cef3.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ interface

uses
cef3types, cef3api, cef3lib, cef3intf, cef3ref, cef3own, cef3gui, cef3lcl,
LazarusPackageIntf;
cef3osr, LazarusPackageIntf;

implementation

procedure Register;
begin
RegisterUnit('cef3lcl', @cef3lcl.Register);
RegisterUnit('cef3osr', @cef3osr.Register);
end;

initialization
Expand Down
98 changes: 63 additions & 35 deletions Component/cef3lcl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
{$ENDIF}
cef3types, cef3lib, cef3intf, cef3gui;

type
Type

{ TCustomChromium }

Expand Down Expand Up @@ -124,8 +124,9 @@ TCustomChromium = class(TWinControl, IChromiumEvents)
{ RenderHandler }
FOnPopupShow: TOnPopupShow;
FOnPopupSize: TOnPopupSize;
FOnPaint: TOnPaint;
// FOnPaint: TOnPaint; {$NOTE !}
FOnCursorChange: TOnCursorChange;
FOnScrollOffsetChanged: TOnScrollOffsetChanged;
{ RequestHandler }
FOnBeforeBrowse: TOnBeforeBrowse;
FOnBeforeResourceLoad: TOnBeforeResourceLoad;
Expand Down Expand Up @@ -226,12 +227,14 @@ TCustomChromium = class(TWinControl, IChromiumEvents)
function doOnGetViewRect(const Browser: ICefBrowser; rect: PCefRect): Boolean;
function doOnGetScreenPoint(const Browser: ICefBrowser; viewX, viewY: Integer;
screenX, screenY: PInteger): Boolean;
function doOnGetScreenInfo(const browser: ICefBrowser; var screenInfo: TCefScreenInfo): Boolean;
procedure doOnPopupShow(const Browser: ICefBrowser; doshow: Boolean);
procedure doOnPopupSize(const Browser: ICefBrowser; const rect: PCefRect);
procedure doOnPaint(const Browser: ICefBrowser; kind: TCefPaintElementType;
dirtyRectsCount: TSize; const dirtyRects: PCefRectArray;
const buffer: Pointer; awidth, aheight: Integer);
procedure doOnCursorChange(const Browser: ICefBrowser; acursor: TCefCursorHandle);
procedure doOnScrollOffsetChanged(const browser: ICefBrowser);
{ RequestHandler }
function doOnBeforeBrowse(const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; isRedirect: Boolean): Boolean; virtual;
Expand Down Expand Up @@ -302,6 +305,7 @@ TCustomChromium = class(TWinControl, IChromiumEvents)
property OnLoadEnd: TOnLoadEnd read FOnLoadEnd write FOnLoadEnd;
property OnLoadError: TOnLoadError read FOnLoadError write FOnLoadError;
{ RenderHandler }
property OnScrollOffsetChanged: TOnScrollOffsetChanged read FOnScrollOffsetChanged write FOnScrollOffsetChanged;
{ RequestHandler }
property OnBeforeBrowse: TOnBeforeBrowse read FOnBeforeBrowse write FOnBeforeBrowse;
property OnBeforeResourceLoad: TOnBeforeResourceLoad read FOnBeforeResourceLoad write FOnBeforeResourceLoad;
Expand Down Expand Up @@ -345,61 +349,74 @@ TChromium = class(TCustomChromium)
property Visible;

property OnProcessMessageReceived;
property OnLoadStart;
property OnLoadEnd;
property OnLoadError;
property OnRenderProcessTerminated;
property OnPluginCrashed;

property OnTakeFocus;
property OnSetFocus;
property OnGotFocus;
property OnBeforeContextMenu;
property OnContextMenuCommand;
property OnContextMenuDismissed;
property OnPreKeyEvent;
property OnKeyEvent;
property OnLoadingStateChange;

property OnFileDialog;

property OnAddressChange;
property OnTitleChange;
property OnTooltip;
property OnStatusMessage;
property OnConsoleMessage;

property OnBeforeDownload;
property OnDownloadUpdated;

property OnDragEnter;

property OnTakeFocus;
property OnSetFocus;
property OnGotFocus;

property OnRequestGeolocationPermission;
property OnCancelGeolocationPermission;
property OnJsdialog;

property OnJsdialog;
property OnBeforeUnloadDialog;
property OnResetDialogState;

property OnPreKeyEvent;
property OnKeyEvent;

property OnBeforePopup;
property OnAfterCreated;
property OnBeforeClose;
property OnRunModal;
property OnClose;

property OnLoadingStateChange;
property OnLoadStart;
property OnLoadEnd;
property OnLoadError;

property OnScrollOffsetChanged;

property OnBeforeBrowse;
property OnBeforeResourceLoad;
property OnGetResourceHandler;
property OnResourceRedirect;
property OnGetAuthCredentials;
property OnQuotaRequest;
property OnGetCookieManager;
property OnProtocolExecution;

property OnFileDialog;

property OnCertificateError;
property OnBeforePluginLoad;
property OnPluginCrashed;
property OnRenderProcessTerminated;

property Options;
property FontOptions;
property DefaultEncoding;
property UserStyleSheetLocation;

property Handler;
end;

procedure Register;

Implementation

{$IFNDEF CEF_MULTI_THREADED_MESSAGE_LOOP}
Uses ExtCtrls;
Var
Expand Down Expand Up @@ -430,7 +447,7 @@ TWSChromiumControl = class(TWSWinControl)

procedure Register;
begin
RegisterComponents('Chromium',[TChromium]);
RegisterComponents('Chromium', [TChromium]);
end;

{$IFNDEF CEF_MULTI_THREADED_MESSAGE_LOOP}
Expand Down Expand Up @@ -458,7 +475,7 @@ constructor TLCLClientHandler.Create(const crm : IChromiumEvents);
begin
Timer := TTimer.Create(nil);
Timer.Interval := 15;
Timer.Enabled := false;
Timer.Enabled := False;
Timer.OnTimer := @OnTimer;

{$IFDEF DEBUG}
Expand Down Expand Up @@ -486,7 +503,7 @@ procedure TLCLClientHandler.Cleanup;

If CefInstances = 0 then
begin
Timer.Enabled := false;
Timer.Enabled := False;

FreeAndNil(Timer);

Expand Down Expand Up @@ -522,8 +539,8 @@ procedure TCustomChromium.GetSettings(var settings : TCefBrowserSettings);
settings.minimum_font_size := FFontOptions.MinimumFontSize;
settings.minimum_logical_font_size := FFontOptions.MinimumLogicalFontSize;
settings.remote_fonts := FFontOptions.RemoteFonts;
settings.default_encoding := CefString(DefaultEncoding);
settings.user_style_sheet_location := CefString(UserStyleSheetLocation);
settings.default_encoding := CefString(FDefaultEncoding);
settings.user_style_sheet_location := CefString(FUserStyleSheetLocation);

settings.javascript := FOptions.Javascript;
settings.javascript_open_windows := FOptions.JavascriptOpenWindows;
Expand Down Expand Up @@ -663,9 +680,9 @@ procedure TCustomChromium.CreateBrowser;
GetSettings(settings);

{$IFDEF CEF_MULTI_THREADED_MESSAGE_LOOP}
CefBrowserHostCreate(@info, FHandler, FDefaultUrl, @settings, nil);
CefBrowserHostCreateBrowser(@info, FHandler, FDefaultUrl, @settings, nil);
{$ELSE}
FBrowser := CefBrowserHostCreateSync(@info, FHandler, '', @settings, nil);
FBrowser := CefBrowserHostCreateBrowserSync(@info, FHandler, '', @settings, nil);
FBrowserId := FBrowser.Identifier;
{$ENDIF}

Expand Down Expand Up @@ -766,8 +783,7 @@ procedure TCustomChromium.doOnBeforeClose(const Browser: ICefBrowser);
procedure TCustomChromium.doOnBeforeContextMenu(const Browser: ICefBrowser; const Frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
If Assigned(FOnBeforeContextMenu) then
FOnBeforeContextMenu(Self, Browser, Frame, params, model);
If Assigned(FOnBeforeContextMenu) then FOnBeforeContextMenu(Self, Browser, Frame, params, model);
end;

procedure TCustomChromium.doOnBeforeDownload(const Browser: ICefBrowser;
Expand Down Expand Up @@ -843,11 +859,17 @@ procedure TCustomChromium.doOnContextMenuDismissed(const Browser: ICefBrowser; c
If Assigned(FOnContextMenuDismissed) then FOnContextMenuDismissed(Self, Browser, Frame);
end;

procedure TCustomChromium.doOnCursorChange(const Browser: ICefBrowser; aCursor: TCefCursorHandle);
procedure TCustomChromium.doOnCursorChange(const Browser : ICefBrowser;
acursor : TCefCursorHandle);
begin
If Assigned(FOnCursorChange) then FOnCursorChange(Self, Browser, aCursor);
end;

procedure TCustomChromium.doOnScrollOffsetChanged(const browser : ICefBrowser);
begin
If Assigned(FOnScrollOffsetChanged) then FOnScrollOffsetChanged(Self, browser);
end;

function TCustomChromium.doOnBeforeBrowse(const browser : ICefBrowser;
const frame : ICefFrame; const request : ICefRequest; isRedirect : Boolean) : Boolean;
begin
Expand All @@ -866,8 +888,7 @@ function TCustomChromium.doOnDragEnter(const Browser: ICefBrowser; const dragDat
mask: TCefDragOperationsMask): Boolean;
begin
Result := False;
If Assigned(FOnDragEnter) then
FOnDragEnter(Self, Browser, dragData, mask, Result);
If Assigned(FOnDragEnter) then FOnDragEnter(Self, Browser, dragData, mask, Result);
end;

function TCustomChromium.doOnFileDialog(const Browser: ICefBrowser; mode: TCefFileDialogMode;
Expand Down Expand Up @@ -914,6 +935,12 @@ function TCustomChromium.doOnGetScreenPoint(const Browser: ICefBrowser; viewX,
Result := False;
end;

function TCustomChromium.doOnGetScreenInfo(const browser : ICefBrowser;
var screenInfo : TCefScreenInfo) : Boolean;
begin
Result := False;
end;

function TCustomChromium.doOnGetViewRect(const Browser: ICefBrowser; rect: PCefRect): Boolean;
begin
Result := False;
Expand Down Expand Up @@ -1012,10 +1039,11 @@ procedure TCustomChromium.doOnProtocolExecution(const Browser: ICefBrowser;
end;

function TCustomChromium.doOnCertificateError(certError : TCefErrorcode;
const requestUrl : ustring;
callback : ICefAllowCertificateErrorCallback) : Boolean;
const requestUrl : ustring; callback : ICefAllowCertificateErrorCallback) : Boolean;
begin
{ TODO }
Result := False;
If Assigned(FOnCertificateError) then
FOnCertificateError(Self, certError, requestUrl, callback, Result);
end;

function TCustomChromium.doOnQuotaRequest(const Browser: ICefBrowser; const originUrl: ustring;
Expand Down Expand Up @@ -1125,6 +1153,6 @@ class procedure TWSChromiumControl.DestroyHandle(const AWinControl: TWinControl)

Initialization
RegisterWSComponent(TCustomChromium, TWSChromiumControl);
{$I icon.lrs}
{$I icons.lrs}

end.
Loading

0 comments on commit a676245

Please sign in to comment.