1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2026-04-23 01:13:01 +02:00
Files
CEF4Delphi/source/uCEFJsDialogHandler.pas
T

237 lines
9.4 KiB
ObjectPascal
Raw Permalink Normal View History

2017-01-27 16:37:51 +01:00
unit uCEFJsDialogHandler;
{$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;
2017-01-27 16:37:51 +01:00
type
2017-03-16 19:09:42 +01:00
TCefJsDialogHandlerOwn = class(TCefBaseRefCountedOwn, ICefJsDialogHandler)
2017-01-27 16:37:51 +01:00
protected
2017-12-18 19:38:56 +01:00
function OnJsdialog(const browser: ICefBrowser; const originUrl: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring; const callback: ICefJsDialogCallback; out suppressMessage: Boolean): Boolean; virtual;
function OnBeforeUnloadDialog(const browser: ICefBrowser; const messageText: ustring; isReload: Boolean; const callback: ICefJsDialogCallback): Boolean; virtual;
2017-01-27 16:37:51 +01:00
procedure OnResetDialogState(const browser: ICefBrowser); virtual;
procedure OnDialogClosed(const browser: ICefBrowser); virtual;
2018-02-03 17:52:48 +01:00
procedure RemoveReferences; virtual;
2017-01-27 16:37:51 +01:00
public
constructor Create; virtual;
end;
TCustomJsDialogHandler = class(TCefJsDialogHandlerOwn)
protected
2018-02-03 17:52:48 +01:00
FEvents : Pointer;
2017-01-27 16:37:51 +01:00
function OnJsdialog(const browser: ICefBrowser; const originUrl: ustring; dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring; const callback: ICefJsDialogCallback; out suppressMessage: Boolean): Boolean; override;
function OnBeforeUnloadDialog(const browser: ICefBrowser; const messageText: ustring; isReload: Boolean; const callback: ICefJsDialogCallback): Boolean; override;
procedure OnResetDialogState(const browser: ICefBrowser); override;
procedure OnDialogClosed(const browser: ICefBrowser); override;
2018-02-03 17:52:48 +01:00
procedure RemoveReferences; override;
2017-01-27 16:37:51 +01:00
public
2019-06-19 16:53:26 +02:00
constructor Create(const events : IChromiumEvents); reintroduce; virtual;
2017-06-11 17:48:20 +02:00
destructor Destroy; override;
2017-01-27 16:37:51 +01:00
end;
implementation
uses
2018-02-03 17:52:48 +01:00
{$IFDEF DELPHI16_UP}
System.SysUtils,
{$ELSE}
SysUtils,
{$ENDIF}
2025-12-29 19:05:51 +01:00
uCEFMiscFunctions, uCEFBrowser, uCEFJsDialogCallback;
2017-01-27 16:37:51 +01:00
2018-03-29 20:02:04 +02:00
function cef_jsdialog_handler_on_jsdialog( self : PCefJsDialogHandler;
2017-12-18 19:38:56 +01:00
browser : PCefBrowser;
const origin_url : PCefString;
dialog_type : TCefJsDialogType;
const message_text : PCefString;
const default_prompt_text : PCefString;
callback : PCefJsDialogCallback;
suppress_message : PInteger): Integer; stdcall;
2017-01-27 16:37:51 +01:00
var
TempSuppress : boolean;
2018-03-29 20:02:04 +02:00
TempObject : TObject;
TempResult : boolean;
2017-01-27 16:37:51 +01:00
begin
TempResult := False;
2018-03-29 20:02:04 +02:00
TempSuppress := suppress_message^ <> 0;
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefJsDialogHandlerOwn) then
TempResult := TCefJsDialogHandlerOwn(TempObject).OnJsdialog(TCefBrowserRef.UnWrap(browser),
2018-03-29 20:02:04 +02:00
CefString(origin_url),
dialog_type,
CefString(message_text),
CefString(default_prompt_text),
TCefJsDialogCallbackRef.UnWrap(callback),
TempSuppress);
2018-03-29 20:02:04 +02:00
suppress_message^ := Ord(TempSuppress);
Result := Ord(TempResult);
2017-01-27 16:37:51 +01:00
end;
2018-03-29 20:02:04 +02:00
function cef_jsdialog_handler_on_before_unload_dialog( self : PCefJsDialogHandler;
browser : PCefBrowser;
const message_text : PCefString;
is_reload : Integer;
callback : PCefJsDialogCallback): Integer; stdcall;
var
TempObject : TObject;
TempResult : boolean;
2017-01-27 16:37:51 +01:00
begin
TempResult := False;
2018-03-29 20:02:04 +02:00
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefJsDialogHandlerOwn) then
TempResult := TCefJsDialogHandlerOwn(TempObject).OnBeforeUnloadDialog(TCefBrowserRef.UnWrap(browser),
2018-03-29 20:02:04 +02:00
CefString(message_text),
is_reload <> 0,
TCefJsDialogCallbackRef.UnWrap(callback));
Result := Ord(TempResult);
2017-01-27 16:37:51 +01:00
end;
2018-03-29 20:02:04 +02:00
procedure cef_jsdialog_handler_on_reset_dialog_state(self : PCefJsDialogHandler;
browser : PCefBrowser); stdcall;
var
TempObject : TObject;
2017-01-27 16:37:51 +01:00
begin
2018-03-29 20:02:04 +02:00
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefJsDialogHandlerOwn) then
TCefJsDialogHandlerOwn(TempObject).OnResetDialogState(TCefBrowserRef.UnWrap(browser));
2017-01-27 16:37:51 +01:00
end;
2018-03-29 20:02:04 +02:00
procedure cef_jsdialog_handler_on_dialog_closed(self : PCefJsDialogHandler;
browser : PCefBrowser); stdcall;
var
TempObject : TObject;
2017-01-27 16:37:51 +01:00
begin
2018-03-29 20:02:04 +02:00
TempObject := CefGetObject(self);
if (TempObject <> nil) and (TempObject is TCefJsDialogHandlerOwn) then
TCefJsDialogHandlerOwn(TempObject).OnDialogClosed(TCefBrowserRef.UnWrap(browser));
2017-01-27 16:37:51 +01:00
end;
constructor TCefJsDialogHandlerOwn.Create;
begin
inherited CreateData(SizeOf(TCefJsDialogHandler));
2018-03-29 20:02:04 +02:00
2017-01-27 16:37:51 +01:00
with PCefJsDialogHandler(FData)^ do
2018-03-29 20:02:04 +02:00
begin
on_jsdialog := {$IFDEF FPC}@{$ENDIF}cef_jsdialog_handler_on_jsdialog;
on_before_unload_dialog := {$IFDEF FPC}@{$ENDIF}cef_jsdialog_handler_on_before_unload_dialog;
on_reset_dialog_state := {$IFDEF FPC}@{$ENDIF}cef_jsdialog_handler_on_reset_dialog_state;
on_dialog_closed := {$IFDEF FPC}@{$ENDIF}cef_jsdialog_handler_on_dialog_closed;
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 TCefJsDialogHandlerOwn.OnJsdialog(const browser : ICefBrowser;
const originUrl : ustring;
dialogType : TCefJsDialogType;
const messageText : ustring;
const defaultPromptText : ustring;
const callback : ICefJsDialogCallback;
out suppressMessage : Boolean): Boolean;
2017-01-27 16:37:51 +01:00
begin
2017-12-18 19:38:56 +01:00
Result := False;
suppressMessage := False;
2017-01-27 16:37:51 +01:00
end;
2018-03-29 20:02:04 +02:00
function TCefJsDialogHandlerOwn.OnBeforeUnloadDialog(const browser : ICefBrowser;
const messageText : ustring;
isReload : Boolean;
const callback : ICefJsDialogCallback): Boolean;
2017-01-27 16:37:51 +01:00
begin
Result := False;
end;
procedure TCefJsDialogHandlerOwn.OnDialogClosed(const browser: ICefBrowser);
begin
2018-03-29 20:02:04 +02:00
//
2017-01-27 16:37:51 +01:00
end;
procedure TCefJsDialogHandlerOwn.OnResetDialogState(const browser: ICefBrowser);
begin
2018-03-29 20:02:04 +02:00
//
2017-01-27 16:37:51 +01:00
end;
2018-02-03 17:52:48 +01:00
procedure TCefJsDialogHandlerOwn.RemoveReferences;
begin
//
end;
2017-01-27 16:37:51 +01:00
// TCustomJsDialogHandler
2019-06-19 16:53:26 +02:00
constructor TCustomJsDialogHandler.Create(const events : IChromiumEvents);
2017-01-27 16:37:51 +01:00
begin
inherited Create;
2017-06-11 17:48:20 +02:00
2019-06-19 16:53:26 +02:00
FEvents := Pointer(events);
2017-01-27 16:37:51 +01:00
end;
2017-06-11 17:48:20 +02:00
destructor TCustomJsDialogHandler.Destroy;
begin
2018-02-03 17:52:48 +01:00
RemoveReferences;
2017-06-11 17:48:20 +02:00
inherited Destroy;
end;
2018-02-03 17:52:48 +01:00
procedure TCustomJsDialogHandler.RemoveReferences;
begin
FEvents := nil;
end;
function TCustomJsDialogHandler.OnBeforeUnloadDialog(const browser : ICefBrowser;
const messageText : ustring;
isReload : Boolean;
const callback : ICefJsDialogCallback): Boolean;
2017-01-27 16:37:51 +01:00
begin
2018-02-03 17:52:48 +01:00
if (FEvents <> nil) then
Result := IChromiumEvents(FEvents).doOnBeforeUnloadDialog(browser, messageText, isReload, callback)
2017-06-11 17:48:20 +02:00
else
Result := inherited OnBeforeUnloadDialog(browser, messageText, isReload, callback);
2017-01-27 16:37:51 +01:00
end;
procedure TCustomJsDialogHandler.OnDialogClosed(const browser: ICefBrowser);
begin
2018-02-03 17:52:48 +01:00
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnDialogClosed(browser);
2017-01-27 16:37:51 +01:00
end;
function TCustomJsDialogHandler.OnJsdialog(const browser : ICefBrowser;
const originUrl : ustring;
dialogType : TCefJsDialogType;
const messageText : ustring;
const defaultPromptText : ustring;
const callback : ICefJsDialogCallback;
out suppressMessage : Boolean): Boolean;
2017-01-27 16:37:51 +01:00
begin
2017-12-18 19:38:56 +01:00
suppressMessage := False;
2018-02-03 17:52:48 +01:00
if (FEvents <> nil) then
Result := IChromiumEvents(FEvents).doOnJsdialog(browser, originUrl, dialogType, messageText, defaultPromptText, callback, suppressMessage)
2017-06-11 17:48:20 +02:00
else
Result := inherited OnJsdialog(browser, originUrl, dialogType, messageText, defaultPromptText, callback, suppressMessage);
2017-01-27 16:37:51 +01:00
end;
procedure TCustomJsDialogHandler.OnResetDialogState(const browser: ICefBrowser);
begin
2018-02-03 17:52:48 +01:00
if (FEvents <> nil) then IChromiumEvents(FEvents).doOnResetDialogState(browser);
2017-01-27 16:37:51 +01:00
end;
end.