1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2024-11-24 08:02:15 +02:00

Add files via upload

This commit is contained in:
Salvador Diaz Fau 2017-01-27 16:25:30 +01:00 committed by GitHub
parent 993d07c00f
commit 40370f6c41
9 changed files with 2113 additions and 0 deletions

524
uCEFClient.pas Normal file
View File

@ -0,0 +1,524 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFClient;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
WinApi.Windows,
uCEFBase, uCEFInterfaces, uCEFTypes;
type
TCefClientOwn = class(TCefBaseOwn, ICefClient)
protected
function GetContextMenuHandler: ICefContextMenuHandler; virtual;
function GetDialogHandler: ICefDialogHandler; virtual;
function GetDisplayHandler: ICefDisplayHandler; virtual;
function GetDownloadHandler: ICefDownloadHandler; virtual;
function GetDragHandler: ICefDragHandler; virtual;
function GetFindHandler: ICefFindHandler; virtual;
function GetFocusHandler: ICefFocusHandler; virtual;
function GetGeolocationHandler: ICefGeolocationHandler; virtual;
function GetJsdialogHandler: ICefJsdialogHandler; virtual;
function GetKeyboardHandler: ICefKeyboardHandler; virtual;
function GetLifeSpanHandler: ICefLifeSpanHandler; virtual;
function GetRenderHandler: ICefRenderHandler; virtual;
function GetLoadHandler: ICefLoadHandler; virtual;
function GetRequestHandler: ICefRequestHandler; virtual;
function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; virtual;
public
constructor Create; virtual;
end;
TCustomClientHandler = class(TCefClientOwn, ICefClientHandler)
protected
FEvents : IChromiumEvents;
FLoadHandler : ICefLoadHandler;
FFocusHandler : ICefFocusHandler;
FContextMenuHandler : ICefContextMenuHandler;
FDialogHandler : ICefDialogHandler;
FKeyboardHandler : ICefKeyboardHandler;
FDisplayHandler : ICefDisplayHandler;
FDownloadHandler : ICefDownloadHandler;
FGeolocationHandler : ICefGeolocationHandler;
FJsDialogHandler : ICefJsDialogHandler;
FLifeSpanHandler : ICefLifeSpanHandler;
FRenderHandler : ICefRenderHandler;
FRequestHandler : ICefRequestHandler;
FDragHandler : ICefDragHandler;
FFindHandler : ICefFindHandler;
function GetContextMenuHandler: ICefContextMenuHandler; override;
function GetDialogHandler: ICefDialogHandler; override;
function GetDisplayHandler: ICefDisplayHandler; override;
function GetDownloadHandler: ICefDownloadHandler; override;
function GetDragHandler: ICefDragHandler; override;
function GetFindHandler: ICefFindHandler; override;
function GetFocusHandler: ICefFocusHandler; override;
function GetGeolocationHandler: ICefGeolocationHandler; override;
function GetJsdialogHandler: ICefJsdialogHandler; override;
function GetKeyboardHandler: ICefKeyboardHandler; override;
function GetLifeSpanHandler: ICefLifeSpanHandler; override;
function GetRenderHandler: ICefRenderHandler; override;
function GetLoadHandler: ICefLoadHandler; override;
function GetRequestHandler: ICefRequestHandler; override;
function OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; override;
public
constructor Create(const events: IChromiumEvents; renderer: Boolean); reintroduce; virtual;
procedure Disconnect;
end;
TVCLClientHandler = class(TCustomClientHandler)
protected
function GetMultithreadApp : boolean;
public
constructor Create(const crm: IChromiumEvents; renderer: Boolean); reintroduce;
destructor Destroy; override;
procedure ReleaseOtherInstances;
property MultithreadApp : boolean read GetMultithreadApp;
end;
implementation
uses
System.SysUtils,
uCEFMiscFunctions, uCEFLibFunctions, uCEFProcessMessage, uCEFBrowser, uCEFLoadHandler,
uCEFFocusHandler, uCEFContextMenuHandler, uCEFDialogHandler, uCEFKeyboardHandler,
uCEFDisplayHandler, uCEFDownloadHandler, uCEFGeolocationHandler, uCEFJsDialogHandler,
uCEFLifeSpanHandler, uCEFRequestHandler, uCEFRenderHandler, uCEFDragHandler,
uCEFFindHandler, uCEFConstants, uCEFApplication;
var
looping : Boolean = False;
CefInstances : Integer = 0;
CefTimer : UINT = 0;
function cef_client_get_context_menu_handler(self: PCefClient): PCefContextMenuHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetContextMenuHandler);
end;
function cef_client_get_dialog_handler(self: PCefClient): PCefDialogHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetDialogHandler);
end;
function cef_client_get_display_handler(self: PCefClient): PCefDisplayHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetDisplayHandler);
end;
function cef_client_get_download_handler(self: PCefClient): PCefDownloadHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetDownloadHandler);
end;
function cef_client_get_drag_handler(self: PCefClient): PCefDragHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetDragHandler);
end;
function cef_client_get_find_handler(self: PCefClient): PCefFindHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetFindHandler);
end;
function cef_client_get_focus_handler(self: PCefClient): PCefFocusHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetFocusHandler);
end;
function cef_client_get_geolocation_handler(self: PCefClient): PCefGeolocationHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetGeolocationHandler);
end;
function cef_client_get_jsdialog_handler(self: PCefClient): PCefJsDialogHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetJsdialogHandler);
end;
function cef_client_get_keyboard_handler(self: PCefClient): PCefKeyboardHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetKeyboardHandler);
end;
function cef_client_get_life_span_handler(self: PCefClient): PCefLifeSpanHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetLifeSpanHandler);
end;
function cef_client_get_load_handler(self: PCefClient): PCefLoadHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetLoadHandler);
end;
function cef_client_get_get_render_handler(self: PCefClient): PCefRenderHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetRenderHandler);
end;
function cef_client_get_request_handler(self: PCefClient): PCefRequestHandler; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := CefGetData(GetRequestHandler);
end;
function cef_client_on_process_message_received(self: PCefClient; browser: PCefBrowser;
source_process: TCefProcessId; message: PCefProcessMessage): Integer; stdcall;
begin
with TCefClientOwn(CefGetObject(self)) do
Result := Ord(OnProcessMessageReceived(TCefBrowserRef.UnWrap(browser), source_process, TCefProcessMessageRef.UnWrap(message)));
end;
constructor TCefClientOwn.Create;
begin
inherited CreateData(SizeOf(TCefClient));
with PCefClient(FData)^ do
begin
get_context_menu_handler := cef_client_get_context_menu_handler;
get_dialog_handler := cef_client_get_dialog_handler;
get_display_handler := cef_client_get_display_handler;
get_download_handler := cef_client_get_download_handler;
get_drag_handler := cef_client_get_drag_handler;
get_find_handler := cef_client_get_find_handler;
get_focus_handler := cef_client_get_focus_handler;
get_geolocation_handler := cef_client_get_geolocation_handler;
get_jsdialog_handler := cef_client_get_jsdialog_handler;
get_keyboard_handler := cef_client_get_keyboard_handler;
get_life_span_handler := cef_client_get_life_span_handler;
get_load_handler := cef_client_get_load_handler;
get_render_handler := cef_client_get_get_render_handler;
get_request_handler := cef_client_get_request_handler;
on_process_message_received := cef_client_on_process_message_received;
end;
end;
function TCefClientOwn.GetContextMenuHandler: ICefContextMenuHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetDialogHandler: ICefDialogHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetDisplayHandler: ICefDisplayHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetDownloadHandler: ICefDownloadHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetDragHandler: ICefDragHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetFindHandler: ICefFindHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetFocusHandler: ICefFocusHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetGeolocationHandler: ICefGeolocationHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetJsdialogHandler: ICefJsDialogHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetKeyboardHandler: ICefKeyboardHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetLifeSpanHandler: ICefLifeSpanHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetLoadHandler: ICefLoadHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetRenderHandler: ICefRenderHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetRequestHandler: ICefRequestHandler;
begin
Result := nil;
end;
function TCefClientOwn.OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean;
begin
Result := False;
end;
// TCustomClientHandler
constructor TCustomClientHandler.Create(const events: IChromiumEvents; renderer: Boolean);
begin
inherited Create;
FEvents := events;
FLoadHandler := TCustomLoadHandler.Create(events);
FFocusHandler := TCustomFocusHandler.Create(events);
FContextMenuHandler := TCustomContextMenuHandler.Create(events);
FDialogHandler := TCustomDialogHandler.Create(events);
FKeyboardHandler := TCustomKeyboardHandler.Create(events);
FDisplayHandler := TCustomDisplayHandler.Create(events);
FDownloadHandler := TCustomDownloadHandler.Create(events);
FGeolocationHandler := TCustomGeolocationHandler.Create(events);
FJsDialogHandler := TCustomJsDialogHandler.Create(events);
FLifeSpanHandler := TCustomLifeSpanHandler.Create(events);
FRequestHandler := TCustomRequestHandler.Create(events);
if renderer then
FRenderHandler := TCustomRenderHandler.Create(events)
else
FRenderHandler := nil;
FDragHandler := TCustomDragHandler.Create(events);
FFindHandler := TCustomFindHandler.Create(events);
end;
procedure TCustomClientHandler.Disconnect;
begin
FEvents := nil;
FLoadHandler := nil;
FFocusHandler := nil;
FContextMenuHandler := nil;
FDialogHandler := nil;
FKeyboardHandler := nil;
FDisplayHandler := nil;
FDownloadHandler := nil;
FGeolocationHandler := nil;
FJsDialogHandler := nil;
FLifeSpanHandler := nil;
FRequestHandler := nil;
FRenderHandler := nil;
FDragHandler := nil;
FFindHandler := nil;
end;
function TCustomClientHandler.GetContextMenuHandler: ICefContextMenuHandler;
begin
Result := FContextMenuHandler;
end;
function TCustomClientHandler.GetDialogHandler: ICefDialogHandler;
begin
Result := FDialogHandler;
end;
function TCustomClientHandler.GetDisplayHandler: ICefDisplayHandler;
begin
Result := FDisplayHandler;
end;
function TCustomClientHandler.GetDownloadHandler: ICefDownloadHandler;
begin
Result := FDownloadHandler;
end;
function TCustomClientHandler.GetDragHandler: ICefDragHandler;
begin
Result := FDragHandler;
end;
function TCustomClientHandler.GetFindHandler: ICefFindHandler;
begin
Result := FFindHandler;
end;
function TCustomClientHandler.GetFocusHandler: ICefFocusHandler;
begin
Result := FFocusHandler;
end;
function TCustomClientHandler.GetGeolocationHandler: ICefGeolocationHandler;
begin
Result := FGeolocationHandler;
end;
function TCustomClientHandler.GetJsdialogHandler: ICefJsDialogHandler;
begin
Result := FJsDialogHandler;
end;
function TCustomClientHandler.GetKeyboardHandler: ICefKeyboardHandler;
begin
Result := FKeyboardHandler;
end;
function TCustomClientHandler.GetLifeSpanHandler: ICefLifeSpanHandler;
begin
Result := FLifeSpanHandler;
end;
function TCustomClientHandler.GetLoadHandler: ICefLoadHandler;
begin
Result := FLoadHandler;
end;
function TCustomClientHandler.GetRenderHandler: ICefRenderHandler;
begin
Result := FRenderHandler;
end;
function TCustomClientHandler.GetRequestHandler: ICefRequestHandler;
begin
Result := FRequestHandler;
end;
function TCustomClientHandler.OnProcessMessageReceived(const browser: ICefBrowser; sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean;
begin
if Assigned(FEvents) then
Result := FEvents.doOnProcessMessageReceived(browser, sourceProcess, message)
else
Result := False;
end;
// TVCLClientHandler
procedure TimerProc(hwnd: HWND; uMsg: UINT; idEvent: Pointer; dwTime: DWORD); stdcall;
begin
if looping then Exit;
if (CefInstances > 0) then
begin
looping := True;
try
cef_do_message_loop_work;
finally
looping := False;
end;
end;
end;
constructor TVCLClientHandler.Create(const crm: IChromiumEvents; renderer : Boolean);
begin
inherited Create(crm, renderer);
if not(MultithreadApp) then
begin
if (CefInstances = 0) then CefTimer := SetTimer(0, 0, USER_TIMER_MINIMUM, @TimerProc);
InterlockedIncrement(CefInstances);
end;
end;
destructor TVCLClientHandler.Destroy;
begin
if not(MultithreadApp) then
begin
InterlockedDecrement(CefInstances);
if (CefInstances = 0) then KillTimer(0, CefTimer);
end;
inherited Destroy;
end;
procedure TVCLClientHandler.ReleaseOtherInstances;
var
i : integer;
begin
i := pred(self.FRefCount);
while (i >= 1) do
begin
self._Release;
dec(i);
end;
end;
function TVCLClientHandler.GetMultithreadApp : boolean;
begin
Result := True;
try
if (GlobalCEFApp <> nil) then Result := GlobalCEFApp.MultiThreadedMessageLoop;
except
on e : exception do
begin
{$IFDEF DEBUG}
OutputDebugString(PWideChar('TVCLClientHandler.GetMultithreadApp error: ' + e.Message + chr(0)));
{$ENDIF}
end;
end;
end;
end.

274
uCEFCommandLine.pas Normal file
View File

@ -0,0 +1,274 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFCommandLine;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
System.Classes,
uCEFBase, uCEFTypes, uCEFInterfaces;
type
TCefCommandLineRef = class(TCefBaseRef, ICefCommandLine)
protected
function IsValid: Boolean;
function IsReadOnly: Boolean;
function Copy: ICefCommandLine;
procedure InitFromArgv(argc: Integer; const argv: PPAnsiChar);
procedure InitFromString(const commandLine: ustring);
procedure Reset;
function GetCommandLineString: ustring;
procedure GetArgv(args: TStrings);
function GetProgram: ustring;
procedure SetProgram(const prog: ustring);
function HasSwitches: Boolean;
function HasSwitch(const name: ustring): Boolean;
function GetSwitchValue(const name: ustring): ustring;
procedure GetSwitches(switches: TStrings);
procedure AppendSwitch(const name: ustring);
procedure AppendSwitchWithValue(const name, value: ustring);
function HasArguments: Boolean;
procedure GetArguments(arguments: TStrings);
procedure AppendArgument(const argument: ustring);
procedure PrependWrapper(const wrapper: ustring);
public
class function UnWrap(data: Pointer): ICefCommandLine;
class function New: ICefCommandLine;
class function Global: ICefCommandLine;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions;
procedure TCefCommandLineRef.AppendArgument(const argument: ustring);
var
a: TCefString;
begin
a := CefString(argument);
PCefCommandLine(FData).append_argument(PCefCommandLine(FData), @a);
end;
procedure TCefCommandLineRef.AppendSwitch(const name: ustring);
var
n: TCefString;
begin
n := CefString(name);
PCefCommandLine(FData).append_switch(PCefCommandLine(FData), @n);
end;
procedure TCefCommandLineRef.AppendSwitchWithValue(const name, value: ustring);
var
n, v: TCefString;
begin
n := CefString(name);
v := CefString(value);
PCefCommandLine(FData).append_switch_with_value(PCefCommandLine(FData), @n, @v);
end;
function TCefCommandLineRef.Copy: ICefCommandLine;
begin
Result := UnWrap(PCefCommandLine(FData).copy(PCefCommandLine(FData)));
end;
procedure TCefCommandLineRef.GetArguments(arguments: TStrings);
var
list: TCefStringList;
i: Integer;
str: TCefString;
begin
list := cef_string_list_alloc;
try
PCefCommandLine(FData).get_arguments(PCefCommandLine(FData), list);
for i := 0 to cef_string_list_size(list) - 1 do
begin
FillChar(str, SizeOf(str), 0);
cef_string_list_value(list, i, @str);
arguments.Add(CefStringClearAndGet(str));
end;
finally
cef_string_list_free(list);
end;
end;
procedure TCefCommandLineRef.GetArgv(args: TStrings);
var
list: TCefStringList;
i: Integer;
str: TCefString;
begin
list := cef_string_list_alloc;
try
PCefCommandLine(FData).get_argv(FData, list);
for i := 0 to cef_string_list_size(list) - 1 do
begin
FillChar(str, SizeOf(str), 0);
cef_string_list_value(list, i, @str);
args.Add(CefStringClearAndGet(str));
end;
finally
cef_string_list_free(list);
end;
end;
function TCefCommandLineRef.GetCommandLineString: ustring;
begin
Result := CefStringFreeAndGet(PCefCommandLine(FData).get_command_line_string(PCefCommandLine(FData)));
end;
function TCefCommandLineRef.GetProgram: ustring;
begin
Result := CefStringFreeAndGet(PCefCommandLine(FData).get_program(PCefCommandLine(FData)));
end;
procedure TCefCommandLineRef.GetSwitches(switches: TStrings);
var
list: TCefStringList;
i: Integer;
str: TCefString;
begin
list := cef_string_list_alloc;
try
PCefCommandLine(FData).get_switches(PCefCommandLine(FData), list);
for i := 0 to cef_string_list_size(list) - 1 do
begin
FillChar(str, SizeOf(str), 0);
cef_string_list_value(list, i, @str);
switches.Add(CefStringClearAndGet(str));
end;
finally
cef_string_list_free(list);
end;
end;
function TCefCommandLineRef.GetSwitchValue(const name: ustring): ustring;
var
n: TCefString;
begin
n := CefString(name);
Result := CefStringFreeAndGet(PCefCommandLine(FData).get_switch_value(PCefCommandLine(FData), @n));
end;
class function TCefCommandLineRef.Global: ICefCommandLine;
begin
Result := UnWrap(cef_command_line_get_global);
end;
function TCefCommandLineRef.HasArguments: Boolean;
begin
Result := PCefCommandLine(FData).has_arguments(PCefCommandLine(FData)) <> 0;
end;
function TCefCommandLineRef.HasSwitch(const name: ustring): Boolean;
var
n: TCefString;
begin
n := CefString(name);
Result := PCefCommandLine(FData).has_switch(PCefCommandLine(FData), @n) <> 0;
end;
function TCefCommandLineRef.HasSwitches: Boolean;
begin
Result := PCefCommandLine(FData).has_switches(PCefCommandLine(FData)) <> 0;
end;
procedure TCefCommandLineRef.InitFromArgv(argc: Integer;
const argv: PPAnsiChar);
begin
PCefCommandLine(FData).init_from_argv(PCefCommandLine(FData), argc, argv);
end;
procedure TCefCommandLineRef.InitFromString(const commandLine: ustring);
var
cl: TCefString;
begin
cl := CefString(commandLine);
PCefCommandLine(FData).init_from_string(PCefCommandLine(FData), @cl);
end;
function TCefCommandLineRef.IsReadOnly: Boolean;
begin
Result := PCefCommandLine(FData).is_read_only(PCefCommandLine(FData)) <> 0;
end;
function TCefCommandLineRef.IsValid: Boolean;
begin
Result := PCefCommandLine(FData).is_valid(PCefCommandLine(FData)) <> 0;
end;
class function TCefCommandLineRef.New: ICefCommandLine;
begin
Result := UnWrap(cef_command_line_create);
end;
procedure TCefCommandLineRef.PrependWrapper(const wrapper: ustring);
var
w: TCefString;
begin
w := CefString(wrapper);
PCefCommandLine(FData).prepend_wrapper(PCefCommandLine(FData), @w);
end;
procedure TCefCommandLineRef.Reset;
begin
PCefCommandLine(FData).reset(PCefCommandLine(FData));
end;
procedure TCefCommandLineRef.SetProgram(const prog: ustring);
var
p: TCefString;
begin
p := CefString(prog);
PCefCommandLine(FData).set_program(PCefCommandLine(FData), @p);
end;
class function TCefCommandLineRef.UnWrap(data: Pointer): ICefCommandLine;
begin
if data <> nil then
Result := Create(data) as ICefCommandLine else
Result := nil;
end;
end.

107
uCEFCompletionCallback.pas Normal file
View File

@ -0,0 +1,107 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFCompletionCallback;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
uCEFBase, uCEFInterfaces;
type
TCefCompletionCallbackOwn = class(TCefBaseOwn, ICefCompletionCallback)
protected
procedure OnComplete; virtual;
public
constructor Create; virtual;
end;
TCefFastCompletionCallback = class(TCefCompletionCallbackOwn)
protected
FProc: TCefCompletionCallbackProc;
procedure OnComplete; override;
public
constructor Create(const proc: TCefCompletionCallbackProc); reintroduce;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions, uCEFTypes;
procedure cef_completion_callback_on_complete(self: PCefCompletionCallback); stdcall;
begin
with TCefCompletionCallbackOwn(CefGetObject(self)) do OnComplete();
end;
// TCefCompletionHandlerOwn
constructor TCefCompletionCallbackOwn.Create;
begin
inherited CreateData(SizeOf(TCefCompletionCallback));
with PCefCompletionCallback(FData)^ do on_complete := cef_completion_callback_on_complete;
end;
procedure TCefCompletionCallbackOwn.OnComplete;
begin
end;
// TCefFastCompletionHandler
constructor TCefFastCompletionCallback.Create(const proc: TCefCompletionCallbackProc);
begin
inherited Create;
FProc := proc;
end;
procedure TCefFastCompletionCallback.OnComplete;
begin
FProc();
end;
end.

270
uCEFConstants.pas Normal file
View File

@ -0,0 +1,270 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFConstants;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
Winapi.Messages;
const
// /include/internal/cef_types.h (cef_errorcode_t)
ERR_NONE = 0;
ERR_FAILED = -2;
ERR_ABORTED = -3;
ERR_INVALID_ARGUMENT = -4;
ERR_INVALID_HANDLE = -5;
ERR_FILE_NOT_FOUND = -6;
ERR_TIMED_OUT = -7;
ERR_FILE_TOO_BIG = -8;
ERR_UNEXPECTED = -9;
ERR_ACCESS_DENIED = -10;
ERR_NOT_IMPLEMENTED = -11;
ERR_CONNECTION_CLOSED = -100;
ERR_CONNECTION_RESET = -101;
ERR_CONNECTION_REFUSED = -102;
ERR_CONNECTION_ABORTED = -103;
ERR_CONNECTION_FAILED = -104;
ERR_NAME_NOT_RESOLVED = -105;
ERR_INTERNET_DISCONNECTED = -106;
ERR_SSL_PROTOCOL_ERROR = -107;
ERR_ADDRESS_INVALID = -108;
ERR_ADDRESS_UNREACHABLE = -109;
ERR_SSL_CLIENT_AUTH_CERT_NEEDED = -110;
ERR_TUNNEL_CONNECTION_FAILED = -111;
ERR_NO_SSL_VERSIONS_ENABLED = -112;
ERR_SSL_VERSION_OR_CIPHER_MISMATCH = -113;
ERR_SSL_RENEGOTIATION_REQUESTED = -114;
ERR_CERT_COMMON_NAME_INVALID = -200;
ERR_CERT_BEGIN = ERR_CERT_COMMON_NAME_INVALID;
ERR_CERT_DATE_INVALID = -201;
ERR_CERT_AUTHORITY_INVALID = -202;
ERR_CERT_CONTAINS_ERRORS = -203;
ERR_CERT_NO_REVOCATION_MECHANISM = -204;
ERR_CERT_UNABLE_TO_CHECK_REVOCATION = -205;
ERR_CERT_REVOKED = -206;
ERR_CERT_INVALID = -207;
ERR_CERT_WEAK_SIGNATURE_ALGORITHM = -208;
ERR_CERT_NON_UNIQUE_NAME = -210;
ERR_CERT_WEAK_KEY = -211;
ERR_CERT_NAME_CONSTRAINT_VIOLATION = -212;
ERR_CERT_VALIDITY_TOO_LONG = -213;
ERR_CERT_END = ERR_CERT_VALIDITY_TOO_LONG;
ERR_INVALID_URL = -300;
ERR_DISALLOWED_URL_SCHEME = -301;
ERR_UNKNOWN_URL_SCHEME = -302;
ERR_TOO_MANY_REDIRECTS = -310;
ERR_UNSAFE_REDIRECT = -311;
ERR_UNSAFE_PORT = -312;
ERR_INVALID_RESPONSE = -320;
ERR_INVALID_CHUNKED_ENCODING = -321;
ERR_METHOD_NOT_SUPPORTED = -322;
ERR_UNEXPECTED_PROXY_AUTH = -323;
ERR_EMPTY_RESPONSE = -324;
ERR_RESPONSE_HEADERS_TOO_BIG = -325;
ERR_CACHE_MISS = -400;
ERR_INSECURE_RESPONSE = -501;
// /include/internal/cef_types.h (cef_cert_status_t)
CERT_STATUS_NONE = 0;
CERT_STATUS_COMMON_NAME_INVALID = 1 shl 0;
CERT_STATUS_DATE_INVALID = 1 shl 1;
CERT_STATUS_AUTHORITY_INVALID = 1 shl 2;
CERT_STATUS_NO_REVOCATION_MECHANISM = 1 shl 4;
CERT_STATUS_UNABLE_TO_CHECK_REVOCATION = 1 shl 5;
CERT_STATUS_REVOKED = 1 shl 6;
CERT_STATUS_INVALID = 1 shl 7;
CERT_STATUS_WEAK_SIGNATURE_ALGORITHM = 1 shl 8;
CERT_STATUS_NON_UNIQUE_NAME = 1 shl 10;
CERT_STATUS_WEAK_KEY = 1 shl 11;
CERT_STATUS_PINNED_KEY_MISSING = 1 shl 13;
CERT_STATUS_NAME_CONSTRAINT_VIOLATION = 1 shl 14;
CERT_STATUS_VALIDITY_TOO_LONG = 1 shl 15;
CERT_STATUS_IS_EV = 1 shl 16;
CERT_STATUS_REV_CHECKING_ENABLED = 1 shl 17;
CERT_STATUS_SHA1_SIGNATURE_PRESENT = 1 shl 19;
CERT_STATUS_CT_COMPLIANCE_FAILED = 1 shl 20;
CERT_STATUS_FIRST_ERROR = CERT_STATUS_COMMON_NAME_INVALID;
CERT_STATUS_LAST_ERROR = CERT_STATUS_VALIDITY_TOO_LONG;
// /include/internal/cef_types.h (cef_v8_propertyattribute_t)
V8_PROPERTY_ATTRIBUTE_NONE = [];
// /include/internal/cef_types.h (cef_transition_type_t)
TT_LINK = 0;
TT_EXPLICIT = 1;
TT_AUTO_SUBFRAME = 3;
TT_MANUAL_SUBFRAME = 4;
TT_FORM_SUBMIT = 7;
TT_RELOAD = 8;
TT_SOURCE_MASK = $FF;
TT_BLOCKED_FLAG = $00800000;
TT_FORWARD_BACK_FLAG = $01000000;
TT_CHAIN_START_FLAG = $10000000;
TT_CHAIN_END_FLAG = $20000000;
TT_CLIENT_REDIRECT_FLAG = $40000000;
TT_SERVER_REDIRECT_FLAG = $80000000;
TT_IS_REDIRECT_MASK = $C0000000;
TT_QUALIFIER_MASK = $FFFFFF00;
// /include/internal/cef_types.h (cef_dom_event_category_t)
DOM_EVENT_CATEGORY_UNKNOWN = $0;
DOM_EVENT_CATEGORY_UI = $1;
DOM_EVENT_CATEGORY_MOUSE = $2;
DOM_EVENT_CATEGORY_MUTATION = $4;
DOM_EVENT_CATEGORY_KEYBOARD = $8;
DOM_EVENT_CATEGORY_TEXT = $10;
DOM_EVENT_CATEGORY_COMPOSITION = $20;
DOM_EVENT_CATEGORY_DRAG = $40;
DOM_EVENT_CATEGORY_CLIPBOARD = $80;
DOM_EVENT_CATEGORY_MESSAGE = $100;
DOM_EVENT_CATEGORY_WHEEL = $200;
DOM_EVENT_CATEGORY_BEFORE_TEXT_INSERTED = $400;
DOM_EVENT_CATEGORY_OVERFLOW = $800;
DOM_EVENT_CATEGORY_PAGE_TRANSITION = $1000;
DOM_EVENT_CATEGORY_POPSTATE = $2000;
DOM_EVENT_CATEGORY_PROGRESS = $4000;
DOM_EVENT_CATEGORY_XMLHTTPREQUEST_PROGRESS = $8000;
// /include/internal/cef_types.h (cef_file_dialog_mode_t)
FILE_DIALOG_TYPE_MASK = $FF;
FILE_DIALOG_OVERWRITEPROMPT_FLAG = $01000000;
FILE_DIALOG_HIDEREADONLY_FLAG = $02000000;
// /include/internal/cef_types.h (cef_uri_unescape_rule_t)
UU_NONE = 0;
UU_NORMAL = 1 shl 0;
UU_SPACES = 1 shl 1;
UU_PATH_SEPARATORS = 1 shl 2;
UU_URL_SPECIAL_CHARS_EXCEPT_PATH_SEPARATORS = 1 shl 3;
UU_SPOOFING_AND_CONTROL_CHARS = 1 shl 4;
UU_REPLACE_PLUS_WITH_SPACE = 1 shl 5;
// /include/internal/cef_types.h (cef_menu_id_t)
MENU_ID_BACK = 100;
MENU_ID_FORWARD = 101;
MENU_ID_RELOAD = 102;
MENU_ID_RELOAD_NOCACHE = 103;
MENU_ID_STOPLOAD = 104;
MENU_ID_UNDO = 110;
MENU_ID_REDO = 111;
MENU_ID_CUT = 112;
MENU_ID_COPY = 113;
MENU_ID_PASTE = 114;
MENU_ID_DELETE = 115;
MENU_ID_SELECT_ALL = 116;
MENU_ID_FIND = 130;
MENU_ID_PRINT = 131;
MENU_ID_VIEW_SOURCE = 132;
MENU_ID_SPELLCHECK_SUGGESTION_0 = 200;
MENU_ID_SPELLCHECK_SUGGESTION_1 = 201;
MENU_ID_SPELLCHECK_SUGGESTION_2 = 202;
MENU_ID_SPELLCHECK_SUGGESTION_3 = 203;
MENU_ID_SPELLCHECK_SUGGESTION_4 = 204;
MENU_ID_SPELLCHECK_SUGGESTION_LAST = 204;
MENU_ID_NO_SPELLING_SUGGESTIONS = 205;
MENU_ID_ADD_TO_DICTIONARY = 206;
MENU_ID_CUSTOM_FIRST = 220;
MENU_ID_CUSTOM_LAST = 250;
MENU_ID_USER_FIRST = 26500;
MENU_ID_USER_LAST = 28500;
// /include/internal/cef_types.h (cef_ssl_version_t)
SSL_CONNECTION_VERSION_UNKNOWN = 0;
SSL_CONNECTION_VERSION_SSL2 = 1;
SSL_CONNECTION_VERSION_SSL3 = 2;
SSL_CONNECTION_VERSION_TLS1 = 3;
SSL_CONNECTION_VERSION_TLS1_1 = 4;
SSL_CONNECTION_VERSION_TLS1_2 = 5;
SSL_CONNECTION_VERSION_QUIC = 7;
//******************************************************
//****************** OTHER CONSTANTS *******************
//******************************************************
DEVTOOLS_WINDOWNAME = 'DevTools';
CEF_PROXYTYPE_DIRECT = 0;
CEF_PROXYTYPE_AUTODETECT = 1;
CEF_PROXYTYPE_SYSTEM = 2;
CEF_PROXYTYPE_FIXED_SERVERS = 3;
CEF_PROXYTYPE_PAC_SCRIPT = 4;
CEF_CONTENT_SETTING_DEFAULT = 0;
CEF_CONTENT_SETTING_ALLOW = 1;
CEF_CONTENT_SETTING_BLOCK = 2;
CEF_CONTENT_SETTING_ASK = 3;
CEF_CONTENT_SETTING_SESSION_ONLY = 4;
CEF_CONTENT_SETTING_NUM_SETTINGS = 5;
ZOOM_STEP_25 = 0;
ZOOM_STEP_33 = 1;
ZOOM_STEP_50 = 2;
ZOOM_STEP_67 = 3;
ZOOM_STEP_75 = 4;
ZOOM_STEP_90 = 5;
ZOOM_STEP_100 = 6;
ZOOM_STEP_110 = 7;
ZOOM_STEP_125 = 8;
ZOOM_STEP_150 = 9;
ZOOM_STEP_175 = 10;
ZOOM_STEP_200 = 11;
ZOOM_STEP_250 = 12;
ZOOM_STEP_300 = 13;
ZOOM_STEP_400 = 14;
ZOOM_STEP_500 = 15;
ZOOM_STEP_MIN = ZOOM_STEP_25;
ZOOM_STEP_MAX = ZOOM_STEP_500;
ZOOM_STEP_DEF = ZOOM_STEP_100;
CEF_PREFERENCES_AVAILABLE = WM_APP + $A00;
CEF_DOONCLOSE = WM_APP + $A01;
USER_TIMER_MINIMUM = $0000000A;
USER_TIMER_MAXIMUM = $7FFFFFFF;
implementation
end.

186
uCEFContextMenuHandler.pas Normal file
View File

@ -0,0 +1,186 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFContextMenuHandler;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
uCEFBase, uCEFInterfaces, uCEFTypes;
type
TCefContextMenuHandlerOwn = class(TCefBaseOwn, ICefContextMenuHandler)
protected
procedure OnBeforeContextMenu(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel); virtual;
function RunContextMenu(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel; const callback: ICefRunContextMenuCallback): Boolean; virtual;
function OnContextMenuCommand(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags): Boolean; virtual;
procedure OnContextMenuDismissed(const browser: ICefBrowser; const frame: ICefFrame); virtual;
public
constructor Create; virtual;
end;
TCustomContextMenuHandler = class(TCefContextMenuHandlerOwn)
protected
FEvent: IChromiumEvents;
procedure OnBeforeContextMenu(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel); override;
function OnContextMenuCommand(const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer; eventFlags: TCefEventFlags): Boolean; override;
procedure OnContextMenuDismissed(const browser: ICefBrowser; const frame: ICefFrame); override;
public
constructor Create(const events: IChromiumEvents); reintroduce; virtual;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFrame, uCEFContextMenuParams,
uCEFMenuModel, uCEFRunContextMenuCallback;
procedure cef_context_menu_handler_on_before_context_menu(self: PCefContextMenuHandler;
browser: PCefBrowser; frame: PCefFrame; params: PCefContextMenuParams;
model: PCefMenuModel); stdcall;
begin
with TCefContextMenuHandlerOwn(CefGetObject(self)) do
OnBeforeContextMenu(TCefBrowserRef.UnWrap(browser), TCefFrameRef.UnWrap(frame),
TCefContextMenuParamsRef.UnWrap(params), TCefMenuModelRef.UnWrap(model));
end;
function cef_context_menu_handler_run_context_menu(self: PCefContextMenuHandler;
browser: PCefBrowser; frame: PCefFrame; params: PCefContextMenuParams;
model: PCefMenuModel; callback: PCefRunContextMenuCallback): Integer; stdcall;
begin
with TCefContextMenuHandlerOwn(CefGetObject(self)) do
Result := Ord(RunContextMenu(TCefBrowserRef.UnWrap(browser), TCefFrameRef.UnWrap(frame),
TCefContextMenuParamsRef.UnWrap(params), TCefMenuModelRef.UnWrap(model),
TCefRunContextMenuCallbackRef.UnWrap(callback)));
end;
function cef_context_menu_handler_on_context_menu_command(self: PCefContextMenuHandler;
browser: PCefBrowser; frame: PCefFrame; params: PCefContextMenuParams;
command_id: Integer; event_flags: Integer): Integer; stdcall;
begin
with TCefContextMenuHandlerOwn(CefGetObject(self)) do
Result := Ord(OnContextMenuCommand(TCefBrowserRef.UnWrap(browser), TCefFrameRef.UnWrap(frame),
TCefContextMenuParamsRef.UnWrap(params), command_id, TCefEventFlags(Pointer(@event_flags)^)));
end;
procedure cef_context_menu_handler_on_context_menu_dismissed(self: PCefContextMenuHandler;
browser: PCefBrowser; frame: PCefFrame); stdcall;
begin
with TCefContextMenuHandlerOwn(CefGetObject(self)) do
OnContextMenuDismissed(TCefBrowserRef.UnWrap(browser), TCefFrameRef.UnWrap(frame));
end;
constructor TCefContextMenuHandlerOwn.Create;
begin
inherited CreateData(SizeOf(TCefContextMenuHandler));
with PCefContextMenuHandler(FData)^ do
begin
on_before_context_menu := cef_context_menu_handler_on_before_context_menu;
run_context_menu := cef_context_menu_handler_run_context_menu;
on_context_menu_command := cef_context_menu_handler_on_context_menu_command;
on_context_menu_dismissed := cef_context_menu_handler_on_context_menu_dismissed;
end;
end;
procedure TCefContextMenuHandlerOwn.OnBeforeContextMenu(
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
end;
function TCefContextMenuHandlerOwn.OnContextMenuCommand(
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: TCefEventFlags): Boolean;
begin
Result := False;
end;
procedure TCefContextMenuHandlerOwn.OnContextMenuDismissed(
const browser: ICefBrowser; const frame: ICefFrame);
begin
end;
function TCefContextMenuHandlerOwn.RunContextMenu(const browser: ICefBrowser;
const frame: ICefFrame; const params: ICefContextMenuParams;
const model: ICefMenuModel;
const callback: ICefRunContextMenuCallback): Boolean;
begin
Result := False;
end;
// TCustomContextMenuHandler
constructor TCustomContextMenuHandler.Create(const events: IChromiumEvents);
begin
inherited Create;
FEvent := events;
end;
procedure TCustomContextMenuHandler.OnBeforeContextMenu(
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel);
begin
FEvent.doOnBeforeContextMenu(browser, frame, params, model);
end;
function TCustomContextMenuHandler.OnContextMenuCommand(
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: TCefEventFlags): Boolean;
begin
Result := FEvent.doOnContextMenuCommand(browser, frame, params, commandId,
eventFlags);
end;
procedure TCustomContextMenuHandler.OnContextMenuDismissed(
const browser: ICefBrowser; const frame: ICefFrame);
begin
FEvent.doOnContextMenuDismissed(browser, frame);
end;
end.

215
uCEFContextMenuParams.pas Normal file
View File

@ -0,0 +1,215 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFContextMenuParams;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
System.Classes,
uCEFBase, uCEFInterfaces, uCEFTypes;
type
TCefContextMenuParamsRef = class(TCefBaseRef, ICefContextMenuParams)
protected
function GetXCoord: Integer;
function GetYCoord: Integer;
function GetTypeFlags: TCefContextMenuTypeFlags;
function GetLinkUrl: ustring;
function GetUnfilteredLinkUrl: ustring;
function GetSourceUrl: ustring;
function HasImageContents: Boolean;
function GetTitleText: ustring;
function GetPageUrl: ustring;
function GetFrameUrl: ustring;
function GetFrameCharset: ustring;
function GetMediaType: TCefContextMenuMediaType;
function GetMediaStateFlags: TCefContextMenuMediaStateFlags;
function GetSelectionText: ustring;
function GetMisspelledWord: ustring;
function GetDictionarySuggestions(const suggestions: TStringList): Boolean;
function IsEditable: Boolean;
function IsSpellCheckEnabled: Boolean;
function GetEditStateFlags: TCefContextMenuEditStateFlags;
function IsCustomMenu: Boolean;
function IsPepperMenu: Boolean;
public
class function UnWrap(data: Pointer): ICefContextMenuParams;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions;
function TCefContextMenuParamsRef.GetDictionarySuggestions(
const suggestions: TStringList): Boolean;
var
list: TCefStringList;
i: Integer;
str: TCefString;
begin
list := cef_string_list_alloc;
try
Result := PCefContextMenuParams(FData).get_dictionary_suggestions(PCefContextMenuParams(FData), list) <> 0;
FillChar(str, SizeOf(str), 0);
for i := 0 to cef_string_list_size(list) - 1 do
begin
FillChar(str, SizeOf(str), 0);
cef_string_list_value(list, i, @str);
suggestions.Add(CefStringClearAndGet(str));
end;
finally
cef_string_list_free(list);
end;
end;
function TCefContextMenuParamsRef.GetEditStateFlags: TCefContextMenuEditStateFlags;
begin
Byte(Result) := PCefContextMenuParams(FData).get_edit_state_flags(PCefContextMenuParams(FData));
end;
function TCefContextMenuParamsRef.GetFrameCharset: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_frame_charset(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetFrameUrl: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_frame_url(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetLinkUrl: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_link_url(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetMediaStateFlags: TCefContextMenuMediaStateFlags;
begin
Word(Result) := PCefContextMenuParams(FData).get_media_state_flags(PCefContextMenuParams(FData));
end;
function TCefContextMenuParamsRef.GetMediaType: TCefContextMenuMediaType;
begin
Result := PCefContextMenuParams(FData).get_media_type(PCefContextMenuParams(FData));
end;
function TCefContextMenuParamsRef.GetMisspelledWord: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_misspelled_word(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetTitleText: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_title_text(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetPageUrl: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_page_url(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetSelectionText: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_selection_text(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetSourceUrl: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_source_url(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetTypeFlags: TCefContextMenuTypeFlags;
begin
Byte(Result) := PCefContextMenuParams(FData).get_type_flags(PCefContextMenuParams(FData));
end;
function TCefContextMenuParamsRef.GetUnfilteredLinkUrl: ustring;
begin
Result := CefStringFreeAndGet(PCefContextMenuParams(FData).get_unfiltered_link_url(PCefContextMenuParams(FData)));
end;
function TCefContextMenuParamsRef.GetXCoord: Integer;
begin
Result := PCefContextMenuParams(FData).get_xcoord(PCefContextMenuParams(FData));
end;
function TCefContextMenuParamsRef.GetYCoord: Integer;
begin
Result := PCefContextMenuParams(FData).get_ycoord(PCefContextMenuParams(FData));
end;
function TCefContextMenuParamsRef.IsCustomMenu: Boolean;
begin
Result := PCefContextMenuParams(FData).is_custom_menu(PCefContextMenuParams(FData)) <> 0;
end;
function TCefContextMenuParamsRef.IsEditable: Boolean;
begin
Result := PCefContextMenuParams(FData).is_editable(PCefContextMenuParams(FData)) <> 0;
end;
function TCefContextMenuParamsRef.IsPepperMenu: Boolean;
begin
Result := PCefContextMenuParams(FData).is_pepper_menu(PCefContextMenuParams(FData)) <> 0;
end;
function TCefContextMenuParamsRef.IsSpellCheckEnabled: Boolean;
begin
Result := PCefContextMenuParams(FData).is_spell_check_enabled(PCefContextMenuParams(FData)) <> 0;
end;
function TCefContextMenuParamsRef.HasImageContents: Boolean;
begin
Result := PCefContextMenuParams(FData).has_image_contents(PCefContextMenuParams(FData)) <> 0;
end;
class function TCefContextMenuParamsRef.UnWrap(
data: Pointer): ICefContextMenuParams;
begin
if data <> nil then
Result := Create(data) as ICefContextMenuParams else
Result := nil;
end;
end.

256
uCEFCookieManager.pas Normal file
View File

@ -0,0 +1,256 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFCookieManager;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
System.Classes,
uCEFBase, uCEFInterfaces, uCEFTypes;
type
TCefCookieManagerRef = class(TCefBaseRef, ICefCookieManager)
protected
procedure SetSupportedSchemes(schemes: TStrings; const callback: ICefCompletionCallback);
procedure SetSupportedSchemesProc(schemes: TStrings; const callback: TCefCompletionCallbackProc);
function VisitAllCookies(const visitor: ICefCookieVisitor): Boolean;
function VisitAllCookiesProc(const visitor: TCefCookieVisitorProc): Boolean;
function VisitUrlCookies(const url: ustring; includeHttpOnly: Boolean; const visitor: ICefCookieVisitor): Boolean;
function VisitUrlCookiesProc(const url: ustring; includeHttpOnly: Boolean; const visitor: TCefCookieVisitorProc): Boolean;
function SetCookie(const url: ustring; const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; const callback: ICefSetCookieCallback): Boolean;
function SetCookieProc(const url: ustring; const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; const callback: TCefSetCookieCallbackProc): Boolean;
function DeleteCookies(const url, cookieName: ustring; const callback: ICefDeleteCookiesCallback): Boolean;
function DeleteCookiesProc(const url, cookieName: ustring; const callback: TCefDeleteCookiesCallbackProc): Boolean;
function SetStoragePath(const path: ustring; persistSessionCookies: Boolean; const callback: ICefCompletionCallback): Boolean;
function SetStoragePathProc(const path: ustring; persistSessionCookies: Boolean; const callback: TCefCompletionCallbackProc): Boolean;
function FlushStore(const handler: ICefCompletionCallback): Boolean;
function FlushStoreProc(const proc: TCefCompletionCallbackProc): Boolean;
public
class function UnWrap(data: Pointer): ICefCookieManager;
class function Global(const callback: ICefCompletionCallback): ICefCookieManager;
class function GlobalProc(const callback: TCefCompletionCallbackProc): ICefCookieManager;
class function New(const path: ustring; persistSessionCookies: Boolean; const callback: ICefCompletionCallback): ICefCookieManager;
class function NewProc(const path: ustring; persistSessionCookies: Boolean; const callback: TCefCompletionCallbackProc): ICefCookieManager;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions, uCEFCompletionCallback, uCEFDeleteCookiesCallback,
uCEFSetCookieCallback, uCEFCookieVisitor;
class function TCefCookieManagerRef.New(const path: ustring; persistSessionCookies: Boolean;
const callback: ICefCompletionCallback): ICefCookieManager;
var
pth: TCefString;
begin
pth := CefString(path);
Result := UnWrap(cef_cookie_manager_create_manager(@pth, Ord(persistSessionCookies), CefGetData(callback)));
end;
class function TCefCookieManagerRef.NewProc(const path: ustring;
persistSessionCookies: Boolean;
const callback: TCefCompletionCallbackProc): ICefCookieManager;
begin
Result := New(path, persistSessionCookies, TCefFastCompletionCallback.Create(callback));
end;
function TCefCookieManagerRef.DeleteCookies(const url,
cookieName: ustring; const callback: ICefDeleteCookiesCallback): Boolean;
var
u, n: TCefString;
begin
u := CefString(url);
n := CefString(cookieName);
Result := PCefCookieManager(FData).delete_cookies(
PCefCookieManager(FData), @u, @n, CefGetData(callback)) <> 0;
end;
function TCefCookieManagerRef.DeleteCookiesProc(const url, cookieName: ustring;
const callback: TCefDeleteCookiesCallbackProc): Boolean;
begin
Result := DeleteCookies(url, cookieName, TCefFastDeleteCookiesCallback.Create(callback));
end;
function TCefCookieManagerRef.FlushStore(
const handler: ICefCompletionCallback): Boolean;
begin
Result := PCefCookieManager(FData).flush_store(PCefCookieManager(FData),
CefGetData(handler)) <> 0;
end;
function TCefCookieManagerRef.FlushStoreProc(
const proc: TCefCompletionCallbackProc): Boolean;
begin
Result := FlushStore(TCefFastCompletionCallback.Create(proc))
end;
class function TCefCookieManagerRef.Global(const callback: ICefCompletionCallback): ICefCookieManager;
begin
Result := UnWrap(cef_cookie_manager_get_global_manager(CefGetData(callback)));
end;
class function TCefCookieManagerRef.GlobalProc(
const callback: TCefCompletionCallbackProc): ICefCookieManager;
begin
Result := Global(TCefFastCompletionCallback.Create(callback));
end;
function TCefCookieManagerRef.SetCookie(const url, name, value, domain,
path: ustring; secure, httponly, hasExpires: Boolean; const creation,
lastAccess, expires: TDateTime; const callback: ICefSetCookieCallback): Boolean;
var
str: TCefString;
cook: TCefCookie;
begin
str := CefString(url);
cook.name := CefString(name);
cook.value := CefString(value);
cook.domain := CefString(domain);
cook.path := CefString(path);
cook.secure := Ord(secure);
cook.httponly := Ord(httponly);
cook.creation := DateTimeToCefTime(creation);
cook.last_access := DateTimeToCefTime(lastAccess);
cook.has_expires := Ord(hasExpires);
if hasExpires then
cook.expires := DateTimeToCefTime(expires) else
FillChar(cook.expires, SizeOf(TCefTime), 0);
Result := PCefCookieManager(FData).set_cookie(
PCefCookieManager(FData), @str, @cook, CefGetData(callback)) <> 0;
end;
function TCefCookieManagerRef.SetCookieProc(const url, name, value, domain,
path: ustring; secure, httponly, hasExpires: Boolean; const creation,
lastAccess, expires: TDateTime;
const callback: TCefSetCookieCallbackProc): Boolean;
begin
Result := SetCookie(url, name, value, domain, path, secure,
httponly, hasExpires, creation, lastAccess, expires,
TCefFastSetCookieCallback.Create(callback));
end;
function TCefCookieManagerRef.SetStoragePath(const path: ustring;
persistSessionCookies: Boolean; const callback: ICefCompletionCallback): Boolean;
var
p: TCefString;
begin
p := CefString(path);
Result := PCefCookieManager(FData)^.set_storage_path(
PCefCookieManager(FData), @p, Ord(persistSessionCookies), CefGetData(callback)) <> 0;
end;
function TCefCookieManagerRef.SetStoragePathProc(const path: ustring;
persistSessionCookies: Boolean;
const callback: TCefCompletionCallbackProc): Boolean;
begin
Result := SetStoragePath(path, persistSessionCookies, TCefFastCompletionCallback.Create(callback));
end;
procedure TCefCookieManagerRef.SetSupportedSchemes(schemes: TStrings; const callback: ICefCompletionCallback);
var
list: TCefStringList;
i: Integer;
item: TCefString;
begin
list := cef_string_list_alloc();
try
if (schemes <> nil) then
for i := 0 to schemes.Count - 1 do
begin
item := CefString(schemes[i]);
cef_string_list_append(list, @item);
end;
PCefCookieManager(FData).set_supported_schemes(
PCefCookieManager(FData), list, CefGetData(callback));
finally
cef_string_list_free(list);
end;
end;
procedure TCefCookieManagerRef.SetSupportedSchemesProc(schemes: TStrings;
const callback: TCefCompletionCallbackProc);
begin
SetSupportedSchemes(schemes, TCefFastCompletionCallback.Create(callback));
end;
class function TCefCookieManagerRef.UnWrap(data: Pointer): ICefCookieManager;
begin
if data <> nil then
Result := Create(data) as ICefCookieManager else
Result := nil;
end;
function TCefCookieManagerRef.VisitAllCookies(
const visitor: ICefCookieVisitor): Boolean;
begin
Result := PCefCookieManager(FData).visit_all_cookies(
PCefCookieManager(FData), CefGetData(visitor)) <> 0;
end;
function TCefCookieManagerRef.VisitAllCookiesProc(
const visitor: TCefCookieVisitorProc): Boolean;
begin
Result := VisitAllCookies(
TCefFastCookieVisitor.Create(visitor) as ICefCookieVisitor);
end;
function TCefCookieManagerRef.VisitUrlCookies(const url: ustring;
includeHttpOnly: Boolean; const visitor: ICefCookieVisitor): Boolean;
var
str: TCefString;
begin
str := CefString(url);
Result := PCefCookieManager(FData).visit_url_cookies(PCefCookieManager(FData), @str, Ord(includeHttpOnly), CefGetData(visitor)) <> 0;
end;
function TCefCookieManagerRef.VisitUrlCookiesProc(const url: ustring;
includeHttpOnly: Boolean; const visitor: TCefCookieVisitorProc): Boolean;
begin
Result := VisitUrlCookies(url, includeHttpOnly,
TCefFastCookieVisitor.Create(visitor) as ICefCookieVisitor);
end;
end.

124
uCEFCookieVisitor.pas Normal file
View File

@ -0,0 +1,124 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFCookieVisitor;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
uCEFBase, uCEFInterfaces, uCEFTypes;
type
TCefCookieVisitorOwn = class(TCefBaseOwn, ICefCookieVisitor)
protected
function visit(const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; count, total: Integer; out deleteCookie: Boolean): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefFastCookieVisitor = class(TCefCookieVisitorOwn)
protected
FVisitor: TCefCookieVisitorProc;
function visit(const name, value, domain, path: ustring; secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime; count, total: Integer; out deleteCookie: Boolean): Boolean; override;
public
constructor Create(const visitor: TCefCookieVisitorProc); reintroduce;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions;
function cef_cookie_visitor_visit(self: PCefCookieVisitor; const cookie: PCefCookie;
count, total: Integer; deleteCookie: PInteger): Integer; stdcall;
var
delete: Boolean;
exp: TDateTime;
begin
delete := False;
if cookie.has_expires <> 0 then
exp := CefTimeToDateTime(cookie.expires) else
exp := 0;
Result := Ord(TCefCookieVisitorOwn(CefGetObject(self)).visit(CefString(@cookie.name),
CefString(@cookie.value), CefString(@cookie.domain), CefString(@cookie.path),
Boolean(cookie.secure), Boolean(cookie.httponly), Boolean(cookie.has_expires), CefTimeToDateTime(cookie.creation),
CefTimeToDateTime(cookie.last_access), exp, count, total, delete));
deleteCookie^ := Ord(delete);
end;
// TCefCookieVisitorOwn
constructor TCefCookieVisitorOwn.Create;
begin
inherited CreateData(SizeOf(TCefCookieVisitor));
PCefCookieVisitor(FData)^.visit := cef_cookie_visitor_visit;
end;
function TCefCookieVisitorOwn.visit(const name, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;
count, total: Integer; out deleteCookie: Boolean): Boolean;
begin
Result := True;
end;
// TCefFastCookieVisitor
constructor TCefFastCookieVisitor.Create(const visitor: TCefCookieVisitorProc);
begin
inherited Create;
FVisitor := visitor;
end;
function TCefFastCookieVisitor.visit(const name, value, domain, path: ustring;
secure, httponly, hasExpires: Boolean; const creation, lastAccess,
expires: TDateTime; count, total: Integer; out deleteCookie: Boolean): Boolean;
begin
Result := FVisitor(name, value, domain, path, secure, httponly, hasExpires,
creation, lastAccess, expires, count, total, deleteCookie);
end;
end.

157
uCEFCustomStreamReader.pas Normal file
View File

@ -0,0 +1,157 @@
// ************************************************************************
// ***************************** CEF4Delphi *******************************
// ************************************************************************
//
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
// browser in Delphi applications.
//
// The original license of DCEF3 still applies to CEF4Delphi.
//
// For more information about CEF4Delphi visit :
// https://www.briskbard.com/index.php?lang=en&pageid=cef
//
// Copyright © 2017 Salvador Díaz Fau. All rights reserved.
//
// ************************************************************************
// ************ vvvv Original license and comments below vvvv *************
// ************************************************************************
(*
* Delphi Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
* Web site : http://www.progdigy.com
* Repository : http://code.google.com/p/delphichromiumembedded/
* Group : http://groups.google.com/group/delphichromiumembedded
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
unit uCEFCustomStreamReader;
{$IFNDEF CPUX64}
{$ALIGN ON}
{$MINENUMSIZE 4}
{$ENDIF}
interface
uses
System.Classes, System.SysUtils,
uCEFBase, uCEFInterfaces, uCEFTypes;
type
TCefCustomStreamReader = class(TCefBaseOwn, ICefCustomStreamReader)
protected
FStream: TStream;
FOwned: Boolean;
function Read(ptr: Pointer; size, n: NativeUInt): NativeUInt; virtual;
function Seek(offset: Int64; whence: Integer): Integer; virtual;
function Tell: Int64; virtual;
function Eof: Boolean; virtual;
function MayBlock: Boolean; virtual;
public
constructor Create(Stream: TStream; Owned: Boolean); overload; virtual;
constructor Create(const filename: string); overload; virtual;
destructor Destroy; override;
end;
implementation
uses
uCEFMiscFunctions, uCEFLibFunctions;
function cef_stream_reader_read(self: PCefReadHandler; ptr: Pointer; size, n: NativeUInt): NativeUInt; stdcall;
begin
with TCefCustomStreamReader(CefGetObject(self)) do
Result := Read(ptr, size, n);
end;
function cef_stream_reader_seek(self: PCefReadHandler; offset: Int64; whence: Integer): Integer; stdcall;
begin
with TCefCustomStreamReader(CefGetObject(self)) do
Result := Seek(offset, whence);
end;
function cef_stream_reader_tell(self: PCefReadHandler): Int64; stdcall;
begin
with TCefCustomStreamReader(CefGetObject(self)) do
Result := Tell;
end;
function cef_stream_reader_eof(self: PCefReadHandler): Integer; stdcall;
begin
with TCefCustomStreamReader(CefGetObject(self)) do
Result := Ord(Eof);
end;
function cef_stream_reader_may_block(self: PCefReadHandler): Integer; stdcall;
begin
with TCefCustomStreamReader(CefGetObject(self)) do
Result := Ord(MayBlock);
end;
constructor TCefCustomStreamReader.Create(Stream: TStream; Owned: Boolean);
begin
inherited CreateData(SizeOf(TCefReadHandler));
FStream := stream;
FOwned := Owned;
with PCefReadHandler(FData)^ do
begin
read := cef_stream_reader_read;
seek := cef_stream_reader_seek;
tell := cef_stream_reader_tell;
eof := cef_stream_reader_eof;
may_block := cef_stream_reader_may_block;
end;
end;
constructor TCefCustomStreamReader.Create(const filename: string);
begin
Create(TFileStream.Create(filename, fmOpenRead or fmShareDenyWrite), True);
end;
destructor TCefCustomStreamReader.Destroy;
begin
if FOwned then
FStream.Free;
inherited;
end;
function TCefCustomStreamReader.Eof: Boolean;
begin
Result := FStream.Position = FStream.size;
end;
function TCefCustomStreamReader.MayBlock: Boolean;
begin
Result := False;
end;
function TCefCustomStreamReader.Read(ptr: Pointer; size, n: NativeUInt): NativeUInt;
begin
result := NativeUInt(FStream.Read(ptr^, n * size)) div size;
end;
function TCefCustomStreamReader.Seek(offset: Int64; whence: Integer): Integer;
begin
Result := FStream.Seek(offset, TSeekOrigin(whence));
end;
function TCefCustomStreamReader.Tell: Int64;
begin
Result := FStream.Position;
end;
end.