forked from academiadocodigo/TBGWebCharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Browser.VCL.Chromium.pas
103 lines (85 loc) · 2.86 KB
/
Browser.VCL.Chromium.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
unit Browser.VCL.Chromium;
{$I TBGWebCharts.inc}
interface
uses
Interfaces,
uCEFChromium,
uCEFWindowParent,
uCEFInterfaces;
Type
TModelBrowserVCLChromium = class(TInterfacedObject, iModelBrowser)
private
FChromium : TChromium;
FWindowParent : TCEFWindowParent;
public
constructor Create(Chromium : TChromium; WindowParent : TCEFWindowParent);
destructor Destroy; override;
class function New(Chromium : TChromium; WindowParent : TCEFWindowParent) : iModelBrowser;
procedure ExecuteScript(Value : iModelJSCommand);
function ExecuteScriptResult(Value : iModelJSCommand) : string;
procedure ExecuteScriptCallback(Value: iModelJSCommand);
function Generated(FHTML : string) : iModelBrowser;
end;
implementation
uses
{$IF RTLVERSION > 22 }
CallBackJS,
{$ENDIF}
System.SysUtils,
System.Classes,
VCL.Forms,
Browser.Chromium.Events;
{ TModelBrowserVCLChromium }
constructor TModelBrowserVCLChromium.Create(Chromium : TChromium; WindowParent : TCEFWindowParent);
begin
FChromium := Chromium;
FWindowParent := WindowParent;
FChromium.OnBeforePopup := vChromiumEvents.Chromium_OnBeforePopup;
FChromium.OnGetResourceHandler := vChromiumEvents.Chromium_OnGetResourceHandler;
{$IF RTLVERSION > 22 }
FChromium.OnBeforeBrowse := vChromiumEvents.Chromium_BeforeBrowse;
{$ENDIF}
FChromium.OnConsoleMessage := vChromiumEvents.Chromium_ConsoleMessage;
end;
destructor TModelBrowserVCLChromium.Destroy;
begin
inherited;
end;
procedure TModelBrowserVCLChromium.ExecuteScript(Value: iModelJSCommand);
begin
FChromium.ExecuteJavaScript(value.ResultCommand , 'about:blank', 0);
end;
procedure TModelBrowserVCLChromium.ExecuteScriptCallback(
Value: iModelJSCommand);
var
key : String;
begin
if not Assigned(Value.CallBack) then
raise Exception.Create('Procedure para Callback inválida');
key := vChromiumEvents.Resources.JSCallback.Add(Value.Callback);
FChromium.ExecuteJavaScript(
Value.ResultCommand + ';' +
'console.log(''' + CONSOLE_MSG_PREAMBLE + Key + '|'' + document.getElementById(''' + Value.TagID + ''').' + Value.TagAttribute + ');'
,'about:blank', 0);
end;
function TModelBrowserVCLChromium.ExecuteScriptResult(
Value: iModelJSCommand): string;
begin
Result := 'Use ExecuteScriptCallback';
end;
function TModelBrowserVCLChromium.Generated(FHTML: string): iModelBrowser;
var
Key : string;
begin
Result := Self;
Key := vChromiumEvents.Resources.Pages.add(FHTML);
FChromium.CreateBrowser(FWindowParent, '');
while not FChromium.Initialized do
Application.ProcessMessages;
FChromium.loadURL(WEBCHART_PREAMBLE + Key);
end;
class function TModelBrowserVCLChromium.New(Chromium : TChromium; WindowParent : TCEFWindowParent): iModelBrowser;
begin
Result := Self.Create(Chromium, WindowParent);
end;
end.