2017-01-27 16:37:51 +01:00
|
|
|
unit uCEFResourceBundleHandler;
|
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
{$IFDEF FPC}
|
|
|
|
{$MODE OBJFPC}{$H+}
|
|
|
|
{$ENDIF}
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
{$I cef.inc}
|
|
|
|
|
2022-02-19 18:56:41 +01:00
|
|
|
{$IFNDEF TARGET_64BITS}{$ALIGN ON}{$ENDIF}
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2019-11-08 23:15:53 +01:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFApplicationCore;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
type
|
2017-03-16 19:09:42 +01:00
|
|
|
TCefResourceBundleHandlerOwn = class(TCefBaseRefCountedOwn, ICefResourceBundleHandler)
|
2017-01-27 16:37:51 +01:00
|
|
|
protected
|
2017-11-22 17:43:48 +01:00
|
|
|
function GetLocalizedString(stringid: Integer; var stringVal: ustring): Boolean; virtual; abstract;
|
|
|
|
function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; virtual; abstract;
|
|
|
|
function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; virtual; abstract;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
procedure RemoveReferences; virtual; abstract;
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
public
|
|
|
|
constructor Create; virtual;
|
|
|
|
end;
|
|
|
|
|
2017-11-25 19:04:15 +01:00
|
|
|
TCefCustomResourceBundleHandler = class(TCefResourceBundleHandlerOwn)
|
|
|
|
protected
|
2019-11-08 23:15:53 +01:00
|
|
|
FCefApp : TCefApplicationCore;
|
2017-11-25 19:04:15 +01:00
|
|
|
|
|
|
|
function GetLocalizedString(stringid: Integer; var stringVal: ustring): Boolean; override;
|
|
|
|
function GetDataResource(resourceId: Integer; var data: Pointer; var dataSize: NativeUInt): Boolean; override;
|
|
|
|
function GetDataResourceForScale(resourceId: Integer; scaleFactor: TCefScaleFactor; var data: Pointer; var dataSize: NativeUInt): Boolean; override;
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
procedure RemoveReferences; override;
|
|
|
|
|
2017-11-25 19:04:15 +01:00
|
|
|
public
|
2019-11-08 23:15:53 +01:00
|
|
|
constructor Create(const aCefApp : TCefApplicationCore); reintroduce;
|
2017-11-25 19:04:15 +01:00
|
|
|
destructor Destroy; override;
|
|
|
|
end;
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
2018-03-29 20:02:04 +02:00
|
|
|
{$IFDEF DELPHI16_UP}
|
|
|
|
System.SysUtils,
|
|
|
|
{$ELSE}
|
|
|
|
SysUtils,
|
|
|
|
{$ENDIF}
|
2017-11-25 19:04:15 +01:00
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFConstants;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
2017-11-22 17:43:48 +01:00
|
|
|
function cef_resource_bundle_handler_get_localized_string(self : PCefResourceBundleHandler;
|
|
|
|
string_id : Integer;
|
|
|
|
string_val : PCefString): Integer; stdcall;
|
2017-01-27 16:37:51 +01:00
|
|
|
var
|
2017-11-25 19:04:15 +01:00
|
|
|
TempString : ustring;
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(False);
|
2017-11-25 19:04:15 +01:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
if (TempObject <> nil) and
|
|
|
|
(TempObject is TCefResourceBundleHandlerOwn) then
|
2017-11-25 19:04:15 +01:00
|
|
|
begin
|
|
|
|
TempString := '';
|
|
|
|
Result := Ord(TCefResourceBundleHandlerOwn(TempObject).GetLocalizedString(string_id, TempString));
|
2017-11-22 17:43:48 +01:00
|
|
|
|
2019-11-24 18:19:49 +01:00
|
|
|
if (string_val <> nil) then
|
|
|
|
begin
|
|
|
|
CefStringFree(string_val);
|
|
|
|
string_val^ := CefStringAlloc(TempString);
|
|
|
|
end;
|
2018-03-29 20:02:04 +02:00
|
|
|
end;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_resource_bundle_handler_get_data_resource( self : PCefResourceBundleHandler;
|
2017-11-22 17:43:48 +01:00
|
|
|
resource_id : Integer;
|
|
|
|
var data : Pointer;
|
|
|
|
var data_size : NativeUInt): Integer; stdcall;
|
2017-11-25 19:04:15 +01:00
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(False);
|
2017-11-25 19:04:15 +01:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
if (TempObject <> nil) and
|
|
|
|
(TempObject is TCefResourceBundleHandlerOwn) then
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(TCefResourceBundleHandlerOwn(TempObject).GetDataResource(resource_id, data, data_size));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function cef_resource_bundle_handler_get_data_resource_for_scale( self : PCefResourceBundleHandler;
|
2017-11-22 17:43:48 +01:00
|
|
|
resource_id : Integer;
|
|
|
|
scale_factor : TCefScaleFactor;
|
|
|
|
var data : Pointer;
|
|
|
|
var data_size : NativeUInt): Integer; stdcall;
|
2017-11-25 19:04:15 +01:00
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(False);
|
2017-11-25 19:04:15 +01:00
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
if (TempObject <> nil) and
|
|
|
|
(TempObject is TCefResourceBundleHandlerOwn) then
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := Ord(TCefResourceBundleHandlerOwn(TempObject).GetDataResourceForScale(resource_id, scale_factor, data, data_size));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TCefResourceBundleHandlerOwn.Create;
|
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefResourceBundleHandler));
|
|
|
|
|
2017-11-22 17:43:48 +01:00
|
|
|
with PCefResourceBundleHandler(FData)^ do
|
|
|
|
begin
|
2018-05-12 14:50:54 +02:00
|
|
|
get_localized_string := {$IFDEF FPC}@{$ENDIF}cef_resource_bundle_handler_get_localized_string;
|
|
|
|
get_data_resource := {$IFDEF FPC}@{$ENDIF}cef_resource_bundle_handler_get_data_resource;
|
|
|
|
get_data_resource_for_scale := {$IFDEF FPC}@{$ENDIF}cef_resource_bundle_handler_get_data_resource_for_scale;
|
2017-11-22 17:43:48 +01:00
|
|
|
end;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2017-11-25 19:04:15 +01:00
|
|
|
|
|
|
|
// TCefCustomResourceBundleHandler
|
|
|
|
|
|
|
|
|
2019-11-08 23:15:53 +01:00
|
|
|
constructor TCefCustomResourceBundleHandler.Create(const aCefApp : TCefApplicationCore);
|
2017-11-25 19:04:15 +01:00
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FCefApp := aCefApp;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TCefCustomResourceBundleHandler.Destroy;
|
|
|
|
begin
|
2020-11-10 15:02:49 +01:00
|
|
|
RemoveReferences;
|
2017-11-25 19:04:15 +01:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2020-11-10 15:02:49 +01:00
|
|
|
procedure TCefCustomResourceBundleHandler.RemoveReferences;
|
|
|
|
begin
|
|
|
|
FCefApp := nil;
|
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefCustomResourceBundleHandler.GetLocalizedString( stringid : Integer;
|
2017-11-25 19:04:15 +01:00
|
|
|
var stringVal : ustring): Boolean;
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
2023-08-03 15:50:13 +02:00
|
|
|
if (FCefApp <> nil) then
|
2023-08-03 15:58:57 +02:00
|
|
|
Result := IApplicationCoreEvents(FCefApp).doGetLocalizedString(stringid, stringVal);
|
2018-03-29 20:02:04 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCefCustomResourceBundleHandler.GetLocalizedString', e) then raise;
|
|
|
|
end;
|
2017-11-25 19:04:15 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefCustomResourceBundleHandler.GetDataResource( resourceId : Integer;
|
|
|
|
var data : Pointer;
|
|
|
|
var dataSize : NativeUInt): Boolean;
|
2017-11-25 19:04:15 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
2023-08-03 15:50:13 +02:00
|
|
|
if (FCefApp <> nil) then
|
2023-08-03 15:58:57 +02:00
|
|
|
Result := IApplicationCoreEvents(FCefApp).doGetDataResource(resourceId, data, dataSize);
|
2018-03-29 20:02:04 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCefCustomResourceBundleHandler.GetDataResource', e) then raise;
|
|
|
|
end;
|
2017-11-25 19:04:15 +01:00
|
|
|
end;
|
|
|
|
|
2018-03-29 20:02:04 +02:00
|
|
|
function TCefCustomResourceBundleHandler.GetDataResourceForScale( resourceId : Integer;
|
2017-11-25 19:04:15 +01:00
|
|
|
scaleFactor : TCefScaleFactor;
|
|
|
|
var data : Pointer;
|
|
|
|
var dataSize : NativeUInt): Boolean;
|
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := False;
|
|
|
|
|
|
|
|
try
|
2023-08-03 15:50:13 +02:00
|
|
|
if (FCefApp <> nil) then
|
2023-08-03 15:58:57 +02:00
|
|
|
Result := IApplicationCoreEvents(FCefApp).doGetDataResourceForScale(resourceId, scaleFactor, data, dataSize);
|
2018-03-29 20:02:04 +02:00
|
|
|
except
|
|
|
|
on e : exception do
|
|
|
|
if CustomExceptionHandler('TCefCustomResourceBundleHandler.GetDataResourceForScale', e) then raise;
|
|
|
|
end;
|
2017-11-25 19:04:15 +01:00
|
|
|
end;
|
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
end.
|