Skip to content

Commit

Permalink
Merge pull request #11 from mobius1qwe/master
Browse files Browse the repository at this point in the history
- Atualização de TBG pra versão 130 do CEF
  • Loading branch information
alepmedeiros authored Nov 21, 2024
2 parents 92cb0bb + d002185 commit d89cc7b
Show file tree
Hide file tree
Showing 5 changed files with 424 additions and 271 deletions.
275 changes: 146 additions & 129 deletions Source/Browser/Browser.Chromium.Events.pas
Original file line number Diff line number Diff line change
@@ -1,70 +1,84 @@
unit Browser.Chromium.Events;

{$I TBGWebCharts.inc}

interface

uses
Interfaces,
uCEFInterfaces,
uCEFTypes,
Generics.Collections,
System.SysUtils;

const
unit Browser.Chromium.Events;

{$I TBGWebCharts.inc}

interface

uses
Interfaces,
uCEFInterfaces,
uCEFTypes,
Generics.Collections,
System.SysUtils;

const
CONSOLE_MSG_PREAMBLE = 'DOMVISITOR';
WEBCHART_PREAMBLE = 'TBGWebCharts_';
type
TChromiumEvents = class
private
FChromiumResources : iModelChromiumResources;
public
constructor Create;
destructor Destroy; override;
procedure Chromium_ConsoleMessage(Sender: TObject; const browser: ICefBrowser; level: Cardinal; const message, source: ustring; line: Integer; out Result: Boolean);
// {$IF RTLVERSION > 22 }
procedure Chromium_BeforeBrowse(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; user_gesture, isRedirect: Boolean; out Result: Boolean);
// {$ENDIF}
procedure Chromium_OnBeforePopup(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean; const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo; var client: ICefClient; var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean; var Result: Boolean);
procedure Chromium_OnGetResourceHandler(Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest; var aResourceHandler : ICefResourceHandler);
function Resources : iModelChromiumResources;

end;

var
vChromiumEvents : TChromiumEvents;

implementation

uses
// {$IF RTLVERSION > 22 }
CallBackJS,
// {$ENDIF}
Browser.Chromium.Resources,
System.Classes;

{ TVCLChromiumEvents }

//{$IF RTLVERSION > 22 }
procedure TChromiumEvents.Chromium_BeforeBrowse(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; user_gesture, isRedirect: Boolean;
out Result: Boolean);
var
Target : String;

WEBCHART_PREAMBLE = 'TBGWebCharts_';

type
TChromiumEvents = class
private
FChromiumResources: iModelChromiumResources;
public
constructor Create;
destructor Destroy; override;
procedure Chromium_ConsoleMessage(Sender: TObject; const Browser: ICefBrowser;
level: TCefLogSeverity; const message, source: ustring; line: Integer;
out Result: Boolean);
// {$IF RTLVERSION > 22 }
procedure Chromium_BeforeBrowse(Sender: TObject; const Browser: ICefBrowser;
const frame: ICefFrame; const request: ICefRequest;
user_gesture, isRedirect: Boolean; out Result: Boolean);
// {$ENDIF}
procedure Chromium_OnBeforePopup(Sender: TObject; const Browser: ICefBrowser;
const frame: ICefFrame; const targetUrl, targetFrameName: ustring;
targetDisposition: TCefWindowOpenDisposition; userGesture: Boolean;
const popupFeatures: TCefPopupFeatures; var windowInfo: TCefWindowInfo;
var client: ICefClient; var settings: TCefBrowserSettings;
var extra_info: ICefDictionaryValue; var noJavascriptAccess: Boolean;
var Result: Boolean);

procedure Chromium_OnGetResourceHandler(Sender: TObject; const Browser: ICefBrowser;
const frame: ICefFrame; const request: ICefRequest;
var aResourceHandler: ICefResourceHandler);

function Resources: iModelChromiumResources;

end;

var
vChromiumEvents: TChromiumEvents;

implementation

uses
// {$IF RTLVERSION > 22 }
CallBackJS,
// {$ENDIF}
Browser.Chromium.Resources,
System.Classes;

{ TVCLChromiumEvents }

// {$IF RTLVERSION > 22 }
procedure TChromiumEvents.Chromium_BeforeBrowse(Sender: TObject;
const Browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest;
user_gesture, isRedirect: Boolean; out Result: Boolean);
var
Target: String;
Aux, Method: string;
Params : TStringList;
begin
Target := request.Url;
if UpperCase(Target).StartsWith('ACTIONCALLBACKJS') then
Params: TStringList;
begin
Target := request.Url;
if UpperCase(Target).StartsWith('ACTIONCALLBACKJS') then
begin
Method := Copy(Target, Pos(':', Target) + 1, Length(Target));
Method := Copy(Target, Pos(':', Target) + 1, Length(Target));
Method := Copy(Method, 1, Pos('(', Method) - 1);
Params := TStringList.Create;
try
Aux := Copy(Target, Pos('(', Target) + 1, Length(Target));
Aux := Copy(Aux, 1, LastDelimiter(')', Aux)-1);
Aux := Copy(Aux, 1, LastDelimiter(')', Aux) - 1);
Params.CommaText := Aux;
if not Method.IsEmpty then
if vCallBackJS.TryGetValue(Method, Params) then
Expand All @@ -74,76 +88,79 @@ procedure TChromiumEvents.Chromium_BeforeBrowse(Sender: TObject;
end;
end;
end;
//{$ENDIF}

procedure TChromiumEvents.Chromium_ConsoleMessage(Sender: TObject;
const browser: ICefBrowser; level: Cardinal; const message, source: ustring;
line: Integer; out Result: Boolean);
var
Key : string;
position : integer;
FMessage : string;
Proc : TProc<String>;
begin
if (length(message) > 0) and
(copy(message, 1, length(CONSOLE_MSG_PREAMBLE)) = CONSOLE_MSG_PREAMBLE) then
begin
position := Pos('|', message) + 1;
Key := Copy(message, Succ(Length(CONSOLE_MSG_PREAMBLE)), position -2 - Length(CONSOLE_MSG_PREAMBLE));
Fmessage := Copy(message, position, Length(message));
Proc := FChromiumResources.JSCallback.Extract(key);
if Assigned (Proc) then
Proc(FMessage);
end;
end;

procedure TChromiumEvents.Chromium_OnBeforePopup(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; const popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue;
var noJavascriptAccess, Result: Boolean);
begin
Result := (targetDisposition in [WOD_NEW_FOREGROUND_TAB, WOD_NEW_BACKGROUND_TAB, WOD_NEW_POPUP, WOD_NEW_WINDOW]);
end;

procedure TChromiumEvents.Chromium_OnGetResourceHandler(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; var aResourceHandler: ICefResourceHandler);
var
Key: String;
position : integer;
begin
if UpperCase(request.Url).StartsWith('HTTP://TBGWEBCHARTS_') then
begin
position := Pos('_', request.Url) + 1;
Key := Copy(request.Url, position, Length(request.Url) - position);
aResourceHandler := FChromiumResources.Pages.extract(Key);
end;
end;

constructor TChromiumEvents.Create;
begin
FChromiumResources := TChromiumResources.New;
end;

destructor TChromiumEvents.Destroy;
begin

inherited;
end;

function TChromiumEvents.Resources: iModelChromiumResources;
begin
Result := FChromiumResources;
end;

initialization
vChromiumEvents := TChromiumEvents.Create;
// {$ENDIF}

procedure TChromiumEvents.Chromium_ConsoleMessage(Sender: TObject;
const Browser: ICefBrowser; level: TCefLogSeverity; const message, source: ustring;
line: Integer; out Result: Boolean);
var
Key: string;
position: Integer;
FMessage: string;
Proc: TProc<String>;
begin
if (Length(message) > 0) and (Copy(message, 1, Length(CONSOLE_MSG_PREAMBLE))
= CONSOLE_MSG_PREAMBLE) then
begin
position := Pos('|', message) + 1;
Key := Copy(message, Succ(Length(CONSOLE_MSG_PREAMBLE)),
position - 2 - Length(CONSOLE_MSG_PREAMBLE));
FMessage := Copy(message, position, Length(message));
Proc := FChromiumResources.JSCallback.Extract(Key);
if Assigned(Proc) then
Proc(FMessage);
end;
end;

procedure TChromiumEvents.Chromium_OnBeforePopup(Sender: TObject;
const Browser: ICefBrowser; const frame: ICefFrame;
const targetUrl, targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
userGesture: Boolean; const popupFeatures: TCefPopupFeatures;
var windowInfo: TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var extra_info: ICefDictionaryValue;
var noJavascriptAccess, Result: Boolean);
begin
Result := (targetDisposition in [CEF_WOD_NEW_FOREGROUND_TAB, CEF_WOD_NEW_BACKGROUND_TAB,
CEF_WOD_NEW_POPUP, CEF_WOD_NEW_WINDOW]);
end;

procedure TChromiumEvents.Chromium_OnGetResourceHandler(Sender: TObject;
const Browser: ICefBrowser; const frame: ICefFrame; const request: ICefRequest;
var aResourceHandler: ICefResourceHandler);
var
Key: String;
position: Integer;
begin
if UpperCase(request.Url).StartsWith('HTTP://TBGWEBCHARTS_') then
begin
position := Pos('_', request.Url) + 1;
Key := Copy(request.Url, position, Length(request.Url) - position);
aResourceHandler := FChromiumResources.Pages.Extract(Key);
end;
end;

constructor TChromiumEvents.Create;
begin
FChromiumResources := TChromiumResources.New;
end;

destructor TChromiumEvents.Destroy;
begin

inherited;
end;

function TChromiumEvents.Resources: iModelChromiumResources;
begin
Result := FChromiumResources;
end;

initialization

vChromiumEvents := TChromiumEvents.Create;

finalization
FreeAndNil(vChromiumEvents);

FreeAndNil(vChromiumEvents);

end.

Loading

0 comments on commit d89cc7b

Please sign in to comment.