forked from dliw/fpCEF3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cef3own.pas
3109 lines (2659 loc) · 101 KB
/
cef3own.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*
* Free Pascal Chromium Embedded 3
*
* Usage allowed under the restrictions of the Lesser GNU General Public License
* or alternatively the restrictions of the Mozilla Public License 1.1
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* Author: d.l.i.w <[email protected]>
* Repository: http://github.com/dliw/fpCEF3
*
*
* Based on 'Delphi Chromium Embedded' by: Henri Gourvest <[email protected]>
* Repository : http://code.google.com/p/delphichromiumembedded/
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
Unit cef3own;
{$MODE objfpc}{$H+}
{$I cef.inc}
Interface
Uses
Classes, SysUtils, Math,
{$IFDEF DEBUG}LCLProc,{$ENDIF}
cef3api, cef3types, cef3intf;
Type
TCefBaseOwn = class(TInterfacedObject, ICefBase)
private
FData: Pointer;
public
function Wrap: Pointer;
constructor CreateData(size: TSize; owned: Boolean = False); virtual;
destructor Destroy; override;
end;
TCefAppOwn = class(TCefBaseOwn, ICefApp)
protected
procedure OnBeforeCommandLineProcessing(const processType: ustring;
const commandLine: ICefCommandLine); virtual; abstract;
procedure OnRegisterCustomSchemes(const registrar: ICefSchemeRegistrar); virtual; abstract;
function GetResourceBundleHandler: ICefResourceBundleHandler; virtual; abstract;
function GetBrowserProcessHandler: ICefBrowserProcessHandler; virtual; abstract;
function GetRenderProcessHandler: ICefRenderProcessHandler; virtual; abstract;
public
constructor Create; virtual;
end;
TInternalApp = class(TCefAppOwn)
protected
procedure OnBeforeCommandLineProcessing(const processType: ustring;
const commandLine: ICefCommandLine); override;
procedure OnRegisterCustomSchemes(const registrar: ICefSchemeRegistrar); override;
function GetResourceBundleHandler: ICefResourceBundleHandler; override;
function GetBrowserProcessHandler: ICefBrowserProcessHandler; override;
function GetRenderProcessHandler: ICefRenderProcessHandler; override;
end;
TCefRunFileDialogCallbackOwn = class(TCefBaseOwn, ICefRunFileDialogCallback)
protected
procedure Cont(const browserHost: ICefBrowserHost; filePaths: TStrings); virtual;
public
constructor Create;
end;
TCefFastRunFileDialogCallback = class(TCefRunFileDialogCallbackOwn)
private
FCallback: TCefRunFileDialogCallbackProc;
protected
procedure Cont(const browserHost: ICefBrowserHost; filePaths: TStrings); override;
public
constructor Create(callback: TCefRunFileDialogCallbackProc); reintroduce; virtual;
end;
TCefBrowserProcessHandlerOwn = class(TCefBaseOwn, ICefBrowserProcessHandler)
protected
procedure OnContextInitialized; virtual;
procedure OnBeforeChildProcessLaunch(const commandLine: ICefCommandLine); virtual;
procedure OnRenderProcessThreadCreated(extra_info: ICefListValue); virtual;
public
constructor Create; virtual;
end;
TCefClientOwn = class(TCefBaseOwn, ICefClient)
protected
function GetContextMenuHandler: ICefContextMenuHandler; virtual;
function GetDialogHandler:ICefDialogHandler; virtual;
function GetDisplayHandler: ICefDisplayHandler; virtual;
function GetDownloadHandler: ICefDownloadHandler; virtual;
function GetDragHandler: ICefDragHandler; virtual;
function GetFocusHandler: ICefFocusHandler; virtual;
function GetGeolocationHandler: ICefGeolocationHandler; virtual;
function GetJsdialogHandler: ICefJsdialogHandler; virtual;
function GetKeyboardHandler: ICefKeyboardHandler; virtual;
function GetLifeSpanHandler: ICefLifeSpanHandler; virtual;
function GetLoadHandler: ICefLoadHandler; virtual;
function GetRenderHandler: ICefRenderHandler; virtual;
function GetRequestHandler: ICefRequestHandler; virtual;
function OnProcessMessageReceived(const browser: ICefBrowser;
sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefContextMenuHandlerOwn = class(TCefBaseOwn, ICefContextMenuHandler)
protected
procedure OnBeforeContextMenu(const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel); virtual;
function OnContextMenuCommand(const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer;
eventFlags: TCefEventFlags): Boolean; virtual;
procedure OnContextMenuDismissed(const browser: ICefBrowser; const frame: ICefFrame); virtual;
public
constructor Create; virtual;
end;
TCefCookieVisitorOwn = class(TCefBaseOwn, ICefCookieVisitor)
protected
function Visit(const name, value, domain, path: ustring; secure, httponly,
hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;
count, total: Integer; out deleteCookie: Boolean): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefFastCookieVisitor = class(TCefCookieVisitorOwn)
private
FVisitor: TCefCookieVisitorProc;
protected
function Visit(const name, value, domain, path: ustring; secure, httponly,
hasExpires: Boolean; const creation, lastAccess, expires: TDateTime;
count, total: Integer; out deleteCookie: Boolean): Boolean; override;
public
constructor Create(const visitor: TCefCookieVisitorProc); reintroduce;
end;
TCefDialogHandlerOwn = class(TCefBaseOwn, ICefDialogHandler)
protected
function OnFileDialog(const browser:ICefBrowser; mode: TCefFileDialogMode;
const title, default_file_name: ustring;
accept_types: TStrings; callback: ICefFileDialogCallback): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefDisplayHandlerOwn = class(TCefBaseOwn, ICefDisplayHandler)
protected
procedure OnAddressChange(const browser: ICefBrowser; const frame: ICefFrame; const url: ustring); virtual;
procedure OnTitleChange(const browser: ICefBrowser; const title: ustring); virtual;
function OnTooltip(const browser: ICefBrowser; var text: ustring): Boolean; virtual;
procedure OnStatusMessage(const browser: ICefBrowser; const value: ustring); virtual;
function OnConsoleMessage(const browser: ICefBrowser; const message, source: ustring; line: Integer): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefDomVisitorOwn = class(TCefBaseOwn, ICefDomVisitor)
protected
procedure Visit(const document: ICefDomDocument); virtual;
public
constructor Create; virtual;
end;
TCefFastDomVisitor = class(TCefDomVisitorOwn)
private
FProc: TCefDomVisitorProc;
protected
procedure Visit(const document: ICefDomDocument); override;
public
constructor Create(const proc: TCefDomVisitorProc); reintroduce; virtual;
end;
TCefDomEventListenerOwn = class(TCefBaseOwn, ICefDomEventListener)
protected
procedure HandleEvent(const event: ICefDomEvent); virtual;
public
constructor Create; virtual;
end;
TCefFastDomEventListener = class(TCefDomEventListenerOwn)
private
FProc: TCefDomEventListenerProc;
protected
procedure HandleEvent(const event: ICefDomEvent); override;
public
constructor Create(const proc: TCefDomEventListenerProc); reintroduce; virtual;
end;
TCefDownloadHandlerOwn = class(TCefBaseOwn, ICefDownloadHandler)
protected
procedure OnBeforeDownload(const browser: ICefBrowser; const downloadItem: ICefDownloadItem;
const suggestedName: ustring; const callback: ICefBeforeDownloadCallback); virtual;
procedure OnDownloadUpdated(const browser: ICefBrowser; const downloadItem: ICefDownloadItem;
const callback: ICefDownloadItemCallback); virtual;
public
constructor Create; virtual;
end;
TCefDragHandlerOwn = class(TCefBaseOwn, ICefDragHandler)
protected
function OnDragEnter(const browser: ICefBrowser; const dragData: ICefDragData; mask: TCefDragOperationsMask): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefFocusHandlerOwn = class(TCefBaseOwn, ICefFocusHandler)
protected
procedure OnTakeFocus(const browser: ICefBrowser; next: Boolean); virtual;
function OnSetFocus(const browser: ICefBrowser; source: TCefFocusSource): Boolean; virtual;
procedure OnGotFocus(const browser: ICefBrowser); virtual;
public
constructor Create; virtual;
end;
TCefGeolocationHandlerOwn = class(TCefBaseOwn, ICefGeolocationHandler)
protected
procedure OnRequestGeolocationPermission(const browser: ICefBrowser;
const requestingUrl: ustring; requestId: Integer;
const callback: ICefGeolocationCallback); virtual;
procedure OnCancelGeolocationPermission(const browser: ICefBrowser;
const requestingUrl: ustring; requestId: Integer); virtual;
public
constructor Create; virtual;
end;
TCefJsDialogHandlerOwn = class(TCefBaseOwn, ICefJsDialogHandler)
protected
function OnJsDialog(const browser: ICefBrowser; const originUrl, acceptLang: ustring;
dialogType: TCefJsDialogType; const messageText, defaultPromptText: ustring;
callback: ICefJsDialogCallback; out suppressMessage: Boolean): Boolean; virtual;
function OnBeforeUnloadDialog(const browser: ICefBrowser;
const messageText: ustring; isReload: Boolean;
const callback: ICefJsDialogCallback): Boolean; virtual;
procedure OnResetDialogState(const browser: ICefBrowser); virtual;
procedure OnDialogClosed(const browser: ICefBrowser); virtual;
public
constructor Create; virtual;
end;
TCefKeyboardHandlerOwn = class(TCefBaseOwn, ICefKeyboardHandler)
protected
function OnPreKeyEvent(const browser: ICefBrowser; const event: PCefKeyEvent;
osEvent: TCefEventHandle; out isKeyboardShortcut: Boolean): Boolean; virtual;
function OnKeyEvent(const browser: ICefBrowser; const event: PCefKeyEvent;
osEvent: TCefEventHandle): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefLifeSpanHandlerOwn = class(TCefBaseOwn, ICefLifeSpanHandler)
protected
function OnBeforePopup(const parentBrowser: ICefBrowser; const frame: ICefFrame;
var target_url: ustring; const targetFrameName: ustring;
var popupFeatures: TCefPopupFeatures; var windowInfo:TCefWindowInfo; var client: ICefClient;
var settings: TCefBrowserSettings; var no_javascript_access: Boolean): Boolean; virtual;
procedure OnAfterCreated(const browser: ICefBrowser); virtual;
function RunModal(const browser: ICefBrowser): Boolean; virtual;
function DoClose(const browser: ICefBrowser): Boolean; virtual;
procedure OnBeforeClose(const browser: ICefBrowser); virtual;
public
constructor Create; virtual;
end;
TCefLoadHandlerOwn = class(TCefBaseOwn, ICefLoadHandler)
protected
procedure OnLoadingStateChange(const browser: ICefBrowser; isLoading, canGoBack, canGoForward: Boolean); virtual;
procedure OnLoadStart(const browser: ICefBrowser; const frame: ICefFrame); virtual;
procedure OnLoadEnd(const browser: ICefBrowser; const frame: ICefFrame; httpStatusCode: Integer); virtual;
procedure OnLoadError(const browser: ICefBrowser; const frame: ICefFrame; errorCode: TCefErrorCode;
const errorText, failedUrl: ustring); virtual;
public
constructor Create; virtual;
end;
TCefRenderHandlerOwn = class(TCefBaseOwn, ICefRenderHandler)
protected
function GetRootScreenRect(const browser: ICefBrowser; rect: PCefRect): Boolean; virtual;
function GetViewRect(const browser: ICefBrowser; rect: PCefRect): Boolean; virtual;
function GetScreenPoint(const browser: ICefBrowser; viewX, viewY: Integer;
screenX, screenY: PInteger): Boolean; virtual;
function GetScreenInfo(const browser: ICefBrowser; screenInfo: PCefScreenInfo): Boolean; virtual;
procedure OnPopupShow(const browser: ICefBrowser; show: Boolean); virtual;
procedure OnPopupSize(const browser: ICefBrowser; const rect: PCefRect); virtual;
procedure OnPaint(const browser: ICefBrowser; kind: TCefPaintElementType;
dirtyRectsCount: TSize; const dirtyRects: PCefRectArray;
const buffer: Pointer; width, height: Integer); virtual;
procedure OnCursorChange(const browser: ICefBrowser; cursor: TCefCursorHandle); virtual;
procedure OnScrollOffsetChanged(const browser: ICefBrowser); virtual;
public
constructor Create; virtual;
end;
TCefRenderProcessHandlerOwn = class(TCefBaseOwn, ICefRenderProcessHandler)
protected
procedure OnRenderThreadCreated(const ExtraInfo:ICefListValue); virtual;
procedure OnWebKitInitialized; virtual;
procedure OnBrowserCreated(const browser: ICefBrowser); virtual;
procedure OnBrowserDestroyed(const browser: ICefBrowser); virtual;
function GetLoadHandler: ICefLoadHandler; virtual;
function OnBeforeNavigation(const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const navigationType: TCefNavigationType;
const isRedirect: Boolean): Boolean; virtual;
procedure OnContextCreated(const browser: ICefBrowser;
const frame: ICefFrame; const context: ICefv8Context); virtual;
procedure OnContextReleased(const browser: ICefBrowser;
const frame: ICefFrame; const context: ICefv8Context); virtual;
procedure OnUncaughtException(const browser:ICefBrowser;
const frame:ICefFrame; const context:ICefV8Context;
const exception:ICefV8Exception; const stackTrace:ICefV8StackTrace); virtual;
procedure OnFocusedNodeChanged(const browser: ICefBrowser;
const frame: ICefFrame; const node: ICefDomNode); virtual;
function OnProcessMessageReceived(const browser: ICefBrowser;
sourceProcess: TCefProcessId; const message: ICefProcessMessage): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefPostDataElementOwn = class(TCefBaseOwn, ICefPostDataElement)
private
FDataType: TCefPostDataElementType;
FValueByte: Pointer;
FValueStr: TCefString;
FSize: Cardinal;
FReadOnly: Boolean;
procedure Clear;
protected
function IsReadOnly: Boolean; virtual;
procedure SetToEmpty; virtual;
procedure SetToFile(const fileName: ustring); virtual;
procedure SetToBytes(size: TSize; const bytes: Pointer); virtual;
function GetType: TCefPostDataElementType; virtual;
function GetFile: ustring; virtual;
function GetBytesCount: TSize; virtual;
function GetBytes(size: TSize; bytes: Pointer): TSize; virtual;
public
constructor Create(readonly: Boolean); virtual;
end;
TCefRequestHandlerOwn = class(TCefBaseOwn, ICefRequestHandler)
protected
function OnBeforeBrowse(const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; isRedirect: Boolean): Boolean;
function OnBeforeResourceLoad(const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest): Boolean; virtual;
function GetResourceHandler(const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest): ICefResourceHandler; virtual;
procedure OnResourceRedirect(const browser: ICefBrowser; const frame: ICefFrame;
const oldUrl: ustring; var newUrl: ustring); virtual;
function GetAuthCredentials(const browser: ICefBrowser; const frame: ICefFrame;
isProxy: Boolean; const host: ustring; port: Integer; const realm, scheme: ustring;
const callback: ICefAuthCallback): Boolean; virtual;
function OnQuotaRequest(const browser: ICefBrowser; const originUrl: ustring;
newSize: Int64; const callback: ICefQuotaCallback): Boolean; virtual;
function GetCookieManager(const browser: ICefBrowser; const mainUrl: ustring): ICefCookieManager; virtual;
procedure OnProtocolExecution(const browser: ICefBrowser; const url: ustring; out allowOsExecution: Boolean); virtual;
function OnBeforePluginLoad(const browser: ICefBrowser; const url, policyUrl: ustring;
const info: ICefWebPluginInfo): Boolean; virtual;
function OnCertificateError(certError: TCefErrorcode; const requestUrl: ustring;
callback: ICefAllowCertificateErrorCallback): Boolean;
procedure OnPluginCrashed(const browser: ICefBrowser; const plugin_path: ustring);
procedure OnRenderProcessTerminated(const browser: ICefBrowser; status: TCefTerminationStatus);
public
constructor Create; virtual;
end;
TCefResourceBundleHandlerOwn = class(TCefBaseOwn, ICefResourceBundleHandler)
protected
function GetLocalizedString(messageId: Integer;
out stringVal: ustring): Boolean; virtual; abstract;
function GetDataResource(resourceId: Integer; out data: Pointer;
out dataSize: TSize): Boolean; virtual; abstract;
public
constructor Create; virtual;
end;
TCefFastResourceBundle = class(TCefResourceBundleHandlerOwn)
private
FGetDataResource: TGetDataResource;
FGetLocalizedString: TGetLocalizedString;
protected
function GetDataResource(resourceId: Integer; out data: Pointer;
out dataSize: TSize): Boolean; override;
function GetLocalizedString(messageId: Integer; out stringVal: ustring): Boolean; override;
public
constructor Create(AGetDataResource: TGetDataResource;
AGetLocalizedString: TGetLocalizedString); reintroduce;
end;
TCefResourceHandlerOwn = class(TCefBaseOwn, ICefResourceHandler)
protected
function ProcessRequest(const request: ICefRequest; const callback: ICefCallback): Boolean; virtual;
procedure GetResponseHeaders(const response: ICefResponse;
out responseLength: Int64; out redirectUrl: ustring); virtual;
function ReadResponse(const dataOut: Pointer; bytesToRead: Integer;
var bytesRead: Integer; const callback: ICefCallback): Boolean; virtual;
function CanGetCookie(const cookie: PCefCookie): Boolean; virtual;
function CanSetCookie(const cookie: PCefCookie): Boolean; virtual;
procedure Cancel; virtual;
public
constructor Create(const browser: ICefBrowser; const frame: ICefFrame;
const schemeName: ustring; const request: ICefRequest); virtual;
end;
TCefResourceHandlerClass = class of TCefResourceHandlerOwn;
TCefSchemeHandlerFactoryOwn = class(TCefBaseOwn, ICefSchemeHandlerFactory)
private
FClass: TCefResourceHandlerClass;
protected
function New(const browser: ICefBrowser; const frame: ICefFrame;
const schemeName: ustring; const request: ICefRequest): ICefResourceHandler; virtual;
public
constructor Create(const AClass: TCefResourceHandlerClass; SyncMainThread: Boolean); virtual;
end;
TCefCustomStreamReader = class(TCefBaseOwn, ICefCustomStreamReader)
private
FStream: TStream;
FOwned: Boolean;
protected
function Read(ptr: Pointer; size, n: TSize): TSize; virtual;
function Seek(offset: Int64; whence: Integer): Integer; virtual;
function Tell: Int64; virtual;
function Eof: Boolean; virtual;
function MayBlock: Boolean; virtual;
public
constructor Create(Stream: TStream; Owned: Boolean); overload; virtual;
constructor Create(const filename: string); overload; virtual;
destructor Destroy; override;
end;
TCefStringVisitorOwn = class(TCefBaseOwn, ICefStringVisitor)
protected
procedure Visit(const str: ustring); virtual;
public
constructor Create; virtual;
end;
TCefFastStringVisitor = class(TCefStringVisitorOwn, ICefStringVisitor)
private
FVisit: TCefStringVisitorProc;
protected
procedure Visit(const str: ustring); override;
public
constructor Create(const callback: TCefStringVisitorProc); reintroduce;
end;
TCefTaskOwn = class(TCefBaseOwn, ICefTask)
protected
procedure Execute; virtual;
public
constructor Create; virtual;
end;
TCefUrlrequestClientOwn = class(TCefBaseOwn, ICefUrlrequestClient)
protected
procedure OnRequestComplete(const request: ICefUrlRequest);
procedure OnUploadProgress(const request: ICefUrlRequest; current, total: UInt64);
procedure OnDownloadProgress(const request: ICefUrlRequest; current, total: UInt64);
procedure OnDownloadData(const request: ICefUrlRequest; data: Pointer; dataLength: TSize);
function GetAuthCredentials(isProxy: Boolean; const host: ustring; port: Integer;
const realm, scheme: ustring; callback: ICefAuthCallback): Boolean;
public
constructor Create; virtual;
end;
TCefv8HandlerOwn = class(TCefBaseOwn, ICefv8Handler)
protected
function Execute(const name: ustring; const obj: ICefv8Value;
const arguments: TCefv8ValueArray; var retval: ICefv8Value;
var exception: ustring): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefV8AccessorOwn = class(TCefBaseOwn, ICefV8Accessor)
protected
function Get(const name: ustring; const obj: ICefv8Value;
out value: ICefv8Value; const exception: string): Boolean; virtual;
function Put(const name: ustring; const obj, value: ICefv8Value;
const exception: string): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefWebPluginInfoVisitorOwn = class(TCefBaseOwn, ICefWebPluginInfoVisitor)
protected
function Visit(const info: ICefWebPluginInfo; count, total: Integer): Boolean; virtual;
public
constructor Create; virtual;
end;
TCefFastWebPluginInfoVisitor = class(TCefWebPluginInfoVisitorOwn)
private
FProc: TCefWebPluginInfoVisitorProc;
protected
function Visit(const info: ICefWebPluginInfo; count, total: Integer): Boolean; override;
public
constructor Create(const proc: TCefWebPluginInfoVisitorProc); reintroduce;
end;
TCefWebPluginUnstableCallbackOwn = class(TCefBaseOwn, ICefWebPluginUnstableCallback)
protected
procedure IsUnstable(const path: ustring; unstable: Boolean); virtual;
public
constructor Create; virtual;
end;
TCefFastWebPluginUnstableCallback = class(TCefWebPluginUnstableCallbackOwn)
private
FCallback: TCefWebPluginIsUnstableProc;
protected
procedure IsUnstable(const path: ustring; unstable: Boolean); override;
public
constructor Create(const callback: TCefWebPluginIsUnstableProc); reintroduce;
end;
TCefStringMapOwn = class(TInterfacedObject, ICefStringMap)
private
FStringMap: TCefStringMap;
protected
function GetHandle: TCefStringMap; virtual;
function GetSize: Integer; virtual;
function Find(const key: ustring): ustring; virtual;
function GetKey(index: Integer): ustring; virtual;
function GetValue(index: Integer): ustring; virtual;
procedure Append(const key, value: ustring); virtual;
procedure Clear; virtual;
public
constructor Create; virtual;
destructor Destroy; override;
end;
TCefStringMultimapOwn = class(TInterfacedObject, ICefStringMultimap)
private
FStringMap: TCefStringMultimap;
protected
function GetHandle: TCefStringMultimap; virtual;
function GetSize: Integer; virtual;
function FindCount(const Key: ustring): Integer; virtual;
function GetEnumerate(const Key: ustring; ValueIndex: Integer): ustring; virtual;
function GetKey(Index: Integer): ustring; virtual;
function GetValue(Index: Integer): ustring; virtual;
procedure Append(const Key, Value: ustring); virtual;
procedure Clear; virtual;
public
constructor Create; virtual;
destructor Destroy; override;
end;
(*
TCefRTTIExtension = class(TCefv8HandlerOwn)
private
FValue: TValue;
FCtx: TRttiContext;
{$IFDEF CEF_MULTI_THREADED_MESSAGE_LOOP}
FSyncMainThread: Boolean;
{$ENDIF}
function GetValue(pi: PTypeInfo; const v: ICefv8Value; var ret: TValue): Boolean;
function SetValue(const v: TValue; var ret: ICefv8Value): Boolean;
protected
function Execute(const name: ustring; const obj: ICefv8Value;
const arguments: TCefv8ValueArray; var retval: ICefv8Value;
var exception: ustring): Boolean; override;
public
constructor Create(const value: TValue{$IFDEF CEF_MULTI_THREADED_MESSAGE_LOOP}; SyncMainThread: Boolean{$ENDIF}); reintroduce;
destructor Destroy; override;
class procedure Register(const name: string; const value: TValue{$IFDEF CEF_MULTI_THREADED_MESSAGE_LOOP}; SyncMainThread: Boolean{$ENDIF});
end;
*)
ECefException = class(Exception)
end;
Implementation
Uses cef3lib, cef3ref;
{ TCefBaseOwn }
function cef_base_add_ref(self : PCefBase) : Integer; cconv;
begin
Result := TCefBaseOwn(CefGetObject(self))._AddRef;
end;
function cef_base_release(self : PCefBase) : Integer; cconv;
begin
Result := TCefBaseOwn(CefGetObject(self))._Release;
end;
function cef_base_get_refct(self : PCefBase) : Integer; cconv;
begin
Result := TCefBaseOwn(CefGetObject(self)).RefCount;
end;
function cef_base_add_ref_owned(self : PCefBase): Integer; cconv;
begin
Result := 1;
end;
function cef_base_release_owned(self : PCefBase): Integer; cconv;
begin
Result := 1;
end;
function cef_base_get_refct_owned(self : PCefBase): Integer; cconv;
begin
Result := 1;
end;
{ TCefDragHandlerOwn }
function cef_drag_handler_on_drag_enter(self: PCefDragHandler; browser: PCefBrowser;
dragData: PCefDragData; mask: TCefDragOperationsMask): Integer; cconv;
begin
Result := Ord(TCefDragHandlerOwn(CefGetObject(self)).OnDragEnter(
TCefBrowserRef.UnWrap(browser), TCefDragDataRef.UnWrap(dragData), mask));
end;
function TCefDragHandlerOwn.OnDragEnter(const browser : ICefBrowser; const dragData : ICefDragData;
mask : TCefDragOperationsMask) : Boolean;
begin
Result := False;
end;
constructor TCefDragHandlerOwn.Create;
begin
inherited CreateData(SizeOf(TCefDragHandler));
With PCefDragHandler(FData)^ do
begin
on_drag_enter := @cef_drag_handler_on_drag_enter;
end;
end;
function TCefBaseOwn.Wrap : Pointer;
begin
Result := FData;
If Assigned(PCefBase(FData)^.add_ref) then PCefBase(FData)^.add_ref(FData);
end;
constructor TCefBaseOwn.CreateData(size : TSize; owned : Boolean);
begin
GetMem(FData, size + SizeOf(Pointer));
PPointer(FData)^ := Self;
Inc(FData, SizeOf(Pointer));
FillChar(FData^, size, 0);
PCefBase(FData)^.size := size;
If owned then
begin
PCefBase(FData)^.add_ref := @cef_base_add_ref_owned;
PCefBase(FData)^.release := @cef_base_release_owned;
PCefBase(FData)^.get_refct := @cef_base_get_refct_owned;
end
Else
begin
PCefBase(FData)^.add_ref := @cef_base_add_ref;
PCefBase(FData)^.release := @cef_base_release;
PCefBase(FData)^.get_refct := @cef_base_get_refct;
end;
end;
destructor TCefBaseOwn.Destroy;
begin
{$IFDEF DEBUG}
DebugLn(Self.ClassName + '.Destroy; RefCount: ' + IntToStr(Self.RefCount));
{$ENDIF}
Dec(FData, SizeOf(Pointer));
FreeMem(FData);
inherited;
end;
{ TCefAppOwn }
procedure cef_app_on_before_command_line_processing(self : PCefApp;
const process_type : PCefString; command_line : PCefCommandLine); cconv;
begin
With TCefAppOwn(CefGetObject(self)) do
OnBeforeCommandLineProcessing(CefString(process_type), TCefCommandLineRef.UnWrap(command_line));
end;
procedure cef_app_on_register_custom_schemes(self : PCefApp; registrar : PCefSchemeRegistrar); cconv;
begin
With TCefAppOwn(CefGetObject(self)) do OnRegisterCustomSchemes(TCefSchemeRegistrarRef.UnWrap(registrar));
end;
function cef_app_get_resource_bundle_handler(self : PCefApp) : PCefResourceBundleHandler; cconv;
begin
Result := CefGetData(TCefAppOwn(CefGetObject(self)).GetResourceBundleHandler());
end;
function cef_app_get_browser_process_handler(self : PCefApp) : PCefBrowserProcessHandler; cconv;
begin
Result := CefGetData(TCefAppOwn(CefGetObject(self)).GetBrowserProcessHandler());
end;
function cef_app_get_render_process_handler(self : PCefApp) : PCefRenderProcessHandler; cconv;
begin
Result := CefGetData(TCefAppOwn(CefGetObject(self)).GetRenderProcessHandler());
end;
constructor TCefAppOwn.Create;
begin
inherited CreateData(SizeOf(TCefApp));
With PCefApp(FData)^ do
begin
on_before_command_line_processing := @cef_app_on_before_command_line_processing;
on_register_custom_schemes := @cef_app_on_register_custom_schemes;
get_resource_bundle_handler := @cef_app_get_resource_bundle_handler;
get_browser_process_handler := @cef_app_get_browser_process_handler;
get_render_process_handler := @cef_app_get_render_process_handler;
end;
end;
{ TInternalApp }
procedure TInternalApp.OnBeforeCommandLineProcessing(const processType : ustring; const commandLine : ICefCommandLine);
begin
If Assigned(CefOnBeforeCommandLineProcessing) then CefOnBeforeCommandLineProcessing(processType, commandLine);
end;
procedure TInternalApp.OnRegisterCustomSchemes(const registrar : ICefSchemeRegistrar);
begin
If Assigned(CefOnRegisterCustomSchemes) then CefOnRegisterCustomSchemes(registrar);
end;
function TInternalApp.GetResourceBundleHandler : ICefResourceBundleHandler;
begin
Result := CefResourceBundleHandler;
end;
function TInternalApp.GetBrowserProcessHandler : ICefBrowserProcessHandler;
begin
Result := CefBrowserProcessHandler;
end;
function TInternalApp.GetRenderProcessHandler : ICefRenderProcessHandler;
begin
Result := CefRenderProcessHandler;
end;
{ TCefRunFileDialogCallbackOwn }
procedure cef_run_file_dialog_callback_cont(self : PCefRunFileDialogCallback;
browser_host : PCefBrowserHost; file_paths : TCefStringList); cconv;
var
list : TStringList;
i : Integer;
item : TCefString;
begin
list := TStringList.Create;
try
For i := 0 to cef_string_list_size(file_paths) - 1 do
begin
FillChar(item, SizeOf(item), 0);
cef_string_list_value(file_paths, i, @item);
list.Add(CefStringClearAndGet(item));
end;
With TCefRunFileDialogCallbackOwn(CefGetObject(self)) do
cont(TCefBrowserHostRef.UnWrap(browser_host), list);
finally
list.Free;
end;
end;
procedure TCefRunFileDialogCallbackOwn.Cont(const browserHost : ICefBrowserHost; filePaths : TStrings);
begin
{ empty }
end;
constructor TCefRunFileDialogCallbackOwn.Create;
begin
inherited CreateData(SizeOf(TCefRunFileDialogCallback));
With PCefRunFileDialogCallback(FData)^ do
begin
cont := @cef_run_file_dialog_callback_cont;
end;
end;
{ TCefFastRunFileDialogCallback }
procedure TCefFastRunFileDialogCallback.Cont(const browserHost : ICefBrowserHost; filePaths : TStrings);
begin
FCallback(browserHost, filePaths);
end;
constructor TCefFastRunFileDialogCallback.Create(callback : TCefRunFileDialogCallbackProc);
begin
inherited Create;
FCallback := callback;
end;
{ TCefBrowserProcessHandlerOwn }
procedure cef_browser_process_handler_on_context_initialized(self : PCefBrowserProcessHandler); cconv;
begin
With TCefBrowserProcessHandlerOwn(CefGetObject(self)) do
OnContextInitialized;
end;
procedure cef_browser_process_handler_on_before_child_process_launch(
self : PCefBrowserProcessHandler; command_line : PCefCommandLine); cconv;
begin
With TCefBrowserProcessHandlerOwn(CefGetObject(self)) do
OnBeforeChildProcessLaunch(TCefCommandLineRef.UnWrap(command_line));
end;
procedure cef_browser_render_process_thread_created(self : PCefBrowserProcessHandler; extra_info : PCefListValue); cconv;
begin
With TCefBrowserProcessHandlerOwn(CefGetObject(self)) do
OnRenderProcessThreadCreated(TCefListValueRef.UnWrap(extra_info));
end;
procedure TCefBrowserProcessHandlerOwn.OnContextInitialized;
begin
{ empty }
end;
procedure TCefBrowserProcessHandlerOwn.OnBeforeChildProcessLaunch(const commandLine : ICefCommandLine);
begin
{ empty }
end;
procedure TCefBrowserProcessHandlerOwn.OnRenderProcessThreadCreated(extra_info : ICefListValue);
begin
{ empty }
end;
constructor TCefBrowserProcessHandlerOwn.Create;
begin
inherited CreateData(SizeOf(TCefBrowserProcessHandler));
With PCefBrowserProcessHandler(FData)^ do
begin
on_context_initialized := @cef_browser_process_handler_on_context_initialized;
on_before_child_process_launch := @cef_browser_process_handler_on_before_child_process_launch;
on_render_process_thread_created := @cef_browser_render_process_thread_created;
end;
end;
{ TCefClientOwn }
function cef_client_get_context_menu_handler(self : PCefClient) : PCefContextMenuHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetContextMenuHandler);
end;
function cef_client_get_dialog_handler(self : PCefClient) : PCefDialogHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetDialogHandler);
end;
function cef_client_get_display_handler(self : PCefClient) : PCefDisplayHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetDisplayHandler);
end;
function cef_client_get_download_handler(self : PCefClient) : PCefDownloadHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetDownloadHandler);
end;
function cef_client_get_drag_handler(self : PCefClient) : PCefDragHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetDragHandler);
end;
function cef_client_get_focus_handler(self : PCefClient) : PCefFocusHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetFocusHandler);
end;
function cef_client_get_geolocation_handler(self : PCefClient) : PCefGeolocationHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetGeolocationHandler);
end;
function cef_client_get_jsdialog_handler(self : PCefClient) : PCefJsDialogHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetJsdialogHandler);
end;
function cef_client_get_keyboard_handler(self : PCefClient) : PCefKeyboardHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetKeyboardHandler);
end;
function cef_client_get_life_span_handler(self : PCefClient) : PCefLifeSpanHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetLifeSpanHandler);
end;
function cef_client_get_load_handler(self : PCefClient) : PCefLoadHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetLoadHandler);
end;
function cef_client_get_render_handler(self: PCefClient) : PCefRenderHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetRenderHandler);
end;
function cef_client_get_request_handler(self : PCefClient) : PCefRequestHandler; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do Result := CefGetData(GetRequestHandler);
end;
function cef_client_on_process_message_received(self : PCefClient; browser : PCefBrowser;
source_process : TCefProcessId; message : PCefProcessMessage) : Integer; cconv;
begin
With TCefClientOwn(CefGetObject(self)) do
Result := Ord(OnProcessMessageReceived(TCefBrowserRef.UnWrap(browser), source_process, TCefProcessMessageRef.UnWrap(message)));
end;
function TCefClientOwn.GetContextMenuHandler : ICefContextMenuHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetDialogHandler : ICefDialogHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetDisplayHandler : ICefDisplayHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetDownloadHandler : ICefDownloadHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetDragHandler : ICefDragHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetFocusHandler : ICefFocusHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetGeolocationHandler : ICefGeolocationHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetJsdialogHandler : ICefJsdialogHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetKeyboardHandler : ICefKeyboardHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetLifeSpanHandler : ICefLifeSpanHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetLoadHandler : ICefLoadHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetRenderHandler : ICefRenderHandler;
begin
Result := nil;
end;
function TCefClientOwn.GetRequestHandler : ICefRequestHandler;
begin
Result := nil;
end;
function TCefClientOwn.OnProcessMessageReceived(const browser : ICefBrowser;
sourceProcess : TCefProcessId; const message : ICefProcessMessage) : Boolean;
begin
Result := False;
end;
constructor TCefClientOwn.Create;
begin
inherited CreateData(SizeOf(TCefClient));