2017-01-27 16:37:51 +01:00
|
|
|
unit uCEFSchemeHandlerFactory;
|
|
|
|
|
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
|
2017-03-16 19:09:42 +01:00
|
|
|
uCEFBaseRefCounted, uCEFInterfaces, uCEFTypes, uCEFResourceHandler;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
|
|
|
type
|
2023-11-05 16:53:22 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Class that creates ICefResourceHandler instances for handling scheme
|
|
|
|
/// requests.
|
|
|
|
/// </summary>
|
|
|
|
/// <remarks>
|
|
|
|
/// <para><see href="https://bitbucket.org/chromiumembedded/cef/src/master/include/capi/cef_scheme_capi.h">CEF source file: /include/capi/cef_scheme_capi.h (cef_scheme_handler_factory_t)</see></para>
|
|
|
|
/// </remarks>
|
2017-03-16 19:09:42 +01:00
|
|
|
TCefSchemeHandlerFactoryOwn = class(TCefBaseRefCountedOwn, ICefSchemeHandlerFactory)
|
2017-01-27 16:37:51 +01:00
|
|
|
protected
|
2017-03-16 19:09:42 +01:00
|
|
|
FClass : TCefResourceHandlerClass;
|
2017-01-27 16:37:51 +01:00
|
|
|
|
2023-11-05 16:53:22 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Return a new resource handler instance to handle the request or an NULL
|
|
|
|
/// reference to allow default handling of the request. |browser| and |frame|
|
|
|
|
/// will be the browser window and frame respectively that originated the
|
|
|
|
/// request or NULL if the request did not originate from a browser window
|
|
|
|
/// (for example, if the request came from ICefUrlRequest). The |request|
|
|
|
|
/// object passed to this function cannot be modified.
|
|
|
|
/// </summary>
|
2017-01-27 16:37:51 +01:00
|
|
|
function New(const browser: ICefBrowser; const frame: ICefFrame; const schemeName: ustring; const request: ICefRequest): ICefResourceHandler; virtual;
|
|
|
|
|
|
|
|
public
|
2023-11-05 16:53:22 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Constructor of the scheme handler factory.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="AClass">Class of the custom resource handler used to handle custom scheme requests.</param>
|
2017-01-27 16:37:51 +01:00
|
|
|
constructor Create(const AClass: TCefResourceHandlerClass); virtual;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
uses
|
|
|
|
uCEFMiscFunctions, uCEFLibFunctions, uCEFBrowser, uCEFFrame, uCEFRequest;
|
|
|
|
|
2017-03-16 19:09:42 +01:00
|
|
|
function cef_scheme_handler_factory_create( self : PCefSchemeHandlerFactory;
|
|
|
|
browser : PCefBrowser;
|
|
|
|
frame : PCefFrame;
|
|
|
|
const scheme_name : PCefString;
|
|
|
|
request : PCefRequest): PCefResourceHandler; stdcall;
|
2018-03-29 20:02:04 +02:00
|
|
|
var
|
|
|
|
TempObject : TObject;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-03-29 20:02:04 +02:00
|
|
|
Result := nil;
|
|
|
|
TempObject := CefGetObject(self);
|
|
|
|
|
|
|
|
if (TempObject <> nil) and (TempObject is TCefSchemeHandlerFactoryOwn) then
|
|
|
|
Result := CefGetData(TCefSchemeHandlerFactoryOwn(TempObject).New(TCefBrowserRef.UnWrap(browser),
|
|
|
|
TCefFrameRef.UnWrap(frame),
|
|
|
|
CefString(scheme_name),
|
|
|
|
TCefRequestRef.UnWrap(request)));
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2017-03-16 19:09:42 +01:00
|
|
|
constructor TCefSchemeHandlerFactoryOwn.Create(const AClass: TCefResourceHandlerClass);
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
|
|
|
inherited CreateData(SizeOf(TCefSchemeHandlerFactory));
|
2017-03-16 19:09:42 +01:00
|
|
|
|
2017-01-27 16:37:51 +01:00
|
|
|
FClass := AClass;
|
2017-03-16 19:09:42 +01:00
|
|
|
|
2018-05-12 14:50:54 +02:00
|
|
|
PCefSchemeHandlerFactory(FData)^.create := {$IFDEF FPC}@{$ENDIF}cef_scheme_handler_factory_create;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
2017-03-16 19:09:42 +01:00
|
|
|
function TCefSchemeHandlerFactoryOwn.New(const browser : ICefBrowser;
|
|
|
|
const frame : ICefFrame;
|
|
|
|
const schemeName : ustring;
|
|
|
|
const request : ICefRequest): ICefResourceHandler;
|
2017-01-27 16:37:51 +01:00
|
|
|
begin
|
2018-06-11 18:38:51 +02:00
|
|
|
if (FClass <> nil) then
|
|
|
|
Result := FClass.Create(browser, frame, schemeName, request)
|
|
|
|
else
|
|
|
|
Result := nil;
|
2017-01-27 16:37:51 +01:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|