-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathcef3lib.pas
1189 lines (993 loc) · 37.3 KB
/
cef3lib.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
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Author: [email protected]
* Repository: https://github.com/dliw/fpCEF3
*
*
* Originally based on 'Delphi Chromium Embedded 3' by Henri Gourvest
*
* Embarcadero Technologies, Inc is not permitted to use or redistribute
* this source code without explicit permission.
*
*)
Unit cef3lib;
{$MODE objfpc}{$H+}
{$I cef.inc}
Interface
Uses
{$IFDEF CEF_MULTI_THREADED_MESSAGE_LOOP}Messages,{$ENDIF}
{$IFDEF WINDOWS}Windows,{$ENDIF}
{$IFNDEF WINDOWS}cwstring,{$ENDIF}
{$IFDEF LINUX}xlib, x,{$ENDIF}
SysUtils, Classes, LCLProc, Graphics, FPimage,
cef3api, cef3types, cef3intf, cef3ref, cef3own;
function CefGetObject(ptr: Pointer): TObject; {$IFDEF SUPPORTS_INLINE}inline;{$ENDIF}
function CefGetData(const i: ICefBaseRefCounted): Pointer; {$IFDEF SUPPORTS_INLINE}inline; {$ENDIF}
function CefTimeToDateTime(const dt: TCefTime): TDateTime;
function DateTimeToCefTime(dt: TDateTime): TCefTime;
{$IFDEF WINDOWS}
function TzSpecificLocalTimeToSystemTime(
lpTimeZoneInformation: PTimeZoneInformation;
lpLocalTime, lpUniversalTime: PSystemTime): BOOL; stdcall; external 'kernel32.dll';
function SystemTimeToTzSpecificLocalTime(
lpTimeZoneInformation: PTimeZoneInformation;
lpUniversalTime, lpLocalTime: PSystemTime): BOOL; stdcall; external 'kernel32.dll';
function CefTimeToSystemTime(const dt: TCefTime): TSystemTime;
{$ENDIF}
function TColorToCefColor(const aColor: TColor): TCefColor;
function FPColorToCefColor(const aColor: TFPColor): TCefColor;
function CefString(const str: ustring): TCefString; overload;
function CefString(const str: PCefString): ustring; overload;
function CefStringClearAndGet(var str: TCefString): ustring;
function CefStringFreeAndGet(const str: PCefStringUserFree): ustring;
function CefStringAlloc(const str: ustring): TCefString;
procedure CefStringFree(const str: PCefString);
function CefUserFreeString(const str: ustring): PCefStringUserFree;
procedure CefStringSet(const str: PCefString; const value: ustring);
{ *** API *** }
function CefInitialize: Boolean;
procedure CefShutDown;
{$IFNDEF CEF_MULTI_THREADED_MESSAGE_LOOP}
procedure CefDoMessageLoopWork;
procedure CefRunMessageLoop;
procedure CefQuitMessageLoop;
{$ENDIF}
procedure CefSetOsmodalLoop(osModalLoop: Boolean);
procedure CefEnableHighDPISupport;
function CefBrowserHostCreateBrowser(windowInfo: PCefWindowInfo; const client: ICefClient;
const url: ustring; const settings: PCefBrowserSettings; const requestContext: ICefRequestContext): Boolean;
function CefBrowserHostCreateBrowserSync(windowInfo: PCefWindowInfo; const client: ICefClient;
const url: ustring; const settings: PCefBrowserSettings; const requestContext: ICefRequestContext): ICefBrowser;
function CefCrashReportingEnabled: Boolean;
procedure CefSetCrashKeyValue(const key, value: ustring);
function CefCreateDirectory(const fullPath: ustring): Boolean;
function CefGetTempDirectory(out tempDir: ustring): Boolean;
function CefCreateNewTempDirectory(const prefix: ustring; out newTempPath: ustring): Boolean;
function CefCreateTempDirectoryInDirectory(const baseDir, prefix: ustring; out newDir: ustring): Boolean;
function CefDirectoryExists(const path: ustring): Boolean;
function CefDeleteFile(const path: ustring; recursive: Boolean): Boolean;
function CefZipDirectory(const srcDir, destFile: ustring; includeHiddenFiles: Boolean): Boolean;
function CefGetGeolocation(const callback: ICefGetGeolocationCallback): Boolean;
function CefGetGeolocationProc(const callback: TCefGetGeolocationCallbackProc): Boolean;
function CefAddCrossOriginWhitelistEntry(const SourceOrigin, TargetProtocol, TargetDomain: ustring; AllowTargetSubdomains: Boolean): Boolean;
function CefRemoveCrossOriginWhitelistEntry(const SourceOrigin, TargetProtocol, TargetDomain: ustring; AllowTargetSubdomains: Boolean): Boolean;
function CefClearCrossOriginWhitelist: Boolean;
function CefParseUrl(const url: ustring; var parts: TUrlParts): Boolean;
function CefCreateUrl(var parts: TUrlParts): ustring;
function CefFormatUrlForSecurityDisplay(const originUrl: ustring): ustring;
function CefGetMimeType(const extension: ustring): ustring;
procedure CefGetExtensionsForMimeType(const mimeType: ustring; extensions: TStrings);
function CefBase64Encode(const data: Pointer; dataSize: TSize): ustring;
function CefBase64Decode(const data: ustring): ICefBinaryValue;
function CefUriEncode(const text: ustring; usePlus: Boolean): ustring;
function CefUriDecode(const text: ustring; convertToUtf8: Boolean; unescapeRules: TCefUriUnescapeRule): ustring;
function CefParseJson(const jsonString: ustring; options: TCefJsonParserOptions): ICefValue;
function CefParseJsonAndReturnError(const jsonString: ustring; options: TCefJsonParserOptions; out errorCode: TCefJsonParserError; out errorMsg: ustring): ICefValue;
function CefWriteJson(node: ICefValue; options: TCefJsonWriterOptions): ustring;
function CefGetPath(key: TCefPathKey; out path: ustring): Boolean;
function CefLaunchProcess(commandLine: ICefCommandLine): Boolean;
function CefRegisterSchemeHandlerFactory(const SchemeName, HostName: ustring;
const handler: TCefResourceHandlerClass): Boolean;
function CefClearSchemeHandlerFactories: Boolean;
function CefIsCertStatusError(status: TCefCertStatus): Boolean;
function CefIsCertStatusMinorError(status: TCefCertStatus): Boolean;
function CefCurrentlyOn(ThreadId: TCefThreadId): Boolean;
procedure CefPostTask(ThreadId: TCefThreadId; const task: ICefTask);
procedure CefPostDelayedTask(ThreadId: TCefThreadId; const task: ICefTask; delayMs: Int64);
function CefBeginTracing(const categories: ustring; const callback: ICefCompletionCallback): Boolean;
function CefBeginTracingProc(const categories: ustring; const proc: TCefCompletionCallbackProc): Boolean;
function CefEndTracing(const tracingFile: ustring; const callback: ICefEndTracingCallback): Boolean;
function CefEndTracingProc(const tracingFile: ustring; const proc: TCefEndTracingCallbackProc): Boolean;
function CefNowFromSystemTraceTime: Int64;
function CefRegisterExtension(const name, code: ustring; const Handler: ICefv8Handler): Boolean;
function Cefv8ContextInContext: Boolean;
procedure CefVisitWebPluginInfo(const visitor: ICefWebPluginInfoVisitor);
procedure CefVisitWebPluginInfoProc(const visitor: TCefWebPluginInfoVisitorProc);
procedure CefRefreshWebPlugins;
procedure CefUnregisterInternalWebPlugin(const path: ustring);
procedure CefRegisterWebPluginCrash(const path: ustring);
procedure CefIsWebPluginUnstable(const path: ustring; const callback: ICefWebPluginUnstableCallback);
procedure CefIsWebPluginUnstableProc(const path: ustring; const callback: TCefWebPluginIsUnstableProc);
procedure CefRegisterWidevineCdm(const path: ustring; const callback: ICefRegisterCdmCallback);
procedure CefRegisterWidevineCdmProc(const path: ustring; const proc: TCefRegisterCdmCallbackProc);
function CefGetMinLogLevel: Integer;
function CefGetVlogLevel(const fileStart: String; n: TSize): Integer;
procedure CefLog(const file_: String; line, severity: Integer; const message: String);
function CefGetCurrentPlatformThreadId: TCefPlatformThreadId;
function CefGetCurrentPlatformThreadHandle: TCefPlatformThreadHandle;
function CefTimeNow(out cefTime: TDateTime): Boolean;
procedure CefTraceEventInstant(const category, name, arg1_name: String; arg1_val: UInt64; const arg2_name: String; arg2_val: UInt64; copy: Integer);
procedure CefTraceEventBegin(const category, name, arg1_name: String; arg1_val: UInt64; const arg2_name: String; arg2_val: UInt64; copy: Integer);
procedure CefTraceEventEnd(const category, name, arg1_name: String; arg1_val: UInt64; const arg2_name: String; arg2_val: UInt64; copy: Integer);
procedure CefTraceCounter(const category, name, arg1_name: String; arg1_val: UInt64; const arg2_name: String; arg2_val: UInt64; copy: Integer);
procedure CefTraceCounterId(const category, name: String; id: UInt64; const value1_name: String; value1_val: UInt64; const value2_name: String; value2_val: UInt64; copy: Integer);
procedure CefTraceEventAsyncBegin(const category, name: String; id: UInt64; const arg1_name: String; arg1_val: UInt64; const arg2_name: String; arg2_val: UInt64; copy: Integer);
procedure CefTraceEventAsyncStepInto(const category, name: String; id, step: UInt64; const arg1_name: String; arg1_val: UInt64; copy: Integer);
procedure CefTraceEventAsyncStepPast(const category, name: String; id, step: UInt64; const arg1_name: String; arg1_val: UInt64; copy: Integer);
procedure CefTraceEventAsyncEnd(const category, name: String; id: UInt64; const arg1_name: String; arg1_val: UInt64; const arg2_name: String; arg2_val: UInt64; copy: Integer);
function CefVersionInfo(entry: Integer): Integer;
function CefApiHash(entry: Integer): String;
{$IFDEF LINUX}
procedure CefXWindowResize(const ABrowser: ICefBrowser; const Top, Left, Width, Height: Integer);
procedure CefXLooseFocus(const ABrowser: ICefBrowser);
procedure CefXSetVisibility(const ABrowser: ICefBrowser; const Value: Boolean);
procedure CefXDestroyWindow(const Handle: TXID);
function XErrorHandler(display: PDisplay; event: PXErrorEvent): Integer; cdecl;
function XIOErrorHandler(display: PDisplay): Integer; cdecl;
{$ENDIF}
Var
CefSingleProcess: Boolean = False;
CefNoSandbox: Boolean = True;
CefBrowserSubprocessPath: ustring = '';
CefFrameworkDirPath: ustring = '';
CefExternalMessagePump: Boolean = False;
CefWindowlessRenderingEnabled: Boolean = False;
CefCachePath: ustring = '';
CefCommandLineArgsDisabled: Boolean = False;
CefUserDataPath: ustring = '';
CefPersistSessionCookies: Boolean = False;
CefPersistUserPreferences: Boolean = False;
CefUserAgent: ustring = '';
CefProductVersion: ustring = '';
CefLocale: ustring = '';
CefLogFile: ustring = '';
CefLogSeverity: TCefLogSeverity = LOGSEVERITY_DEFAULT;
CefJavaScriptFlags: ustring = '';
CefResourcesDirPath: ustring = '';
CefLocalesDirPath: ustring = '';
CefPackLoadingDisabled: Boolean = False;
CefRemoteDebuggingPort: Integer = 0;
CefUncaughtExceptionStackSize: Integer = 10;
CefContextSafetyImplementation: Integer = 0;
CefIgnoreCertificateError: Boolean = False;
CefEnableNetSecurityExpiration: Boolean = False;
CefBackgroundColor: TFPColor = (red: 255; green: 255; blue: 255; alpha: 0);
CefAcceptLanguageList: ustring = '';
CefGetDataResource: TGetDataResource = nil;
CefGetLocalizedString: TGetLocalizedString = nil;
CefResourceBundleHandler: ICefResourceBundleHandler = nil;
CefBrowserProcessHandler: ICefBrowserProcessHandler = nil;
CefRenderProcessHandler: ICefRenderProcessHandler = nil;
CefOnBeforeCommandLineProcessing: TOnBeforeCommandLineProcessing = nil;
CefOnRegisterCustomSchemes: TOnRegisterCustomSchemes = nil;
// allow custom library location, can be relative
CefLibraryDirPath: String = '';
Implementation
Type
TC = class(TThread)
procedure Execute; override;
end;
(*
{$IFDEF WINDOWS}
{ TODO : Where are these types defined? }
{
function TzSpecificLocalTimeToSystemTime(
lpTimeZoneInformation: PTimeZoneInformation;
lpLocalTime, lpUniversalTime: PSystemTime): BOOL; cdecl; external 'kernel32.dll';
function SystemTimeToTzSpecificLocalTime(
lpTimeZoneInformation: PTimeZoneInformation;
lpUniversalTime, lpLocalTime: PSystemTime): BOOL; cdecl; external 'kernel32.dll';
}
{$ENDIF}
*)
Var
CefIsMainProcess: Boolean = False;
function CefGetObject(ptr: Pointer): TObject; {$IFDEF SUPPORTS_INLINE}inline; {$ENDIF}
begin
Dec(ptr, SizeOf(Pointer));
Result := TObject(ptr^);
end;
function CefGetData(const i: ICefBaseRefCounted): Pointer; {$IFDEF SUPPORTS_INLINE}inline; {$ENDIF}
begin
If i <> nil then Result := i.Wrap
Else Result := nil;
end;
{ TODO : Time functions }
{$IFDEF WINDOWS}
function CefTimeToSystemTime(const dt: TCefTime): TSystemTime;
begin
With Result do
begin
wYear := dt.year;
wMonth := dt.month;
wDayOfWeek := dt.day_of_week;
wDay := dt.day_of_month;
wHour := dt.hour;
wMinute := dt.minute;
wSecond := dt.second;
wMilliseconds := dt.millisecond;
end;
end;
function SystemTimeToCefTime(const dt: TSystemTime): TCefTime;
begin
With Result do
begin
year := dt.wYear;
month := dt.wMonth;
day_of_week := dt.wDayOfWeek;
day_of_month := dt.wDay;
hour := dt.wHour;
minute := dt.wMinute;
second := dt.wSecond;
millisecond := dt.wMilliseconds;
end;
end;
function CefTimeToDateTime(const dt: TCefTime): TDateTime;
Var
st: TSystemTime;
begin
st := CefTimeToSystemTime(dt);
SystemTimeToTzSpecificLocalTime(nil, @st, @st);
Result := SystemTimeToDateTime(st);
end;
function DateTimeToCefTime(dt: TDateTime): TCefTime;
Var
st: TSystemTime;
begin
DateTimeToSystemTime(dt, st);
TzSpecificLocalTimeToSystemTime(nil, @st, @st);
Result := SystemTimeToCefTime(st);
end;
{$ELSE}
function CefTimeToDateTime(const dt: TCefTime): TDateTime;
begin
Result := EncodeDate(dt.year, dt.month, dt.day_of_month) + EncodeTime(dt.hour, dt.minute, dt.second, dt.millisecond);
end;
function DateTimeToCefTime(dt: TDateTime): TCefTime;
Var
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
DecodeDate(dt, Year, Month, Day);
DecodeTime(dt, Hour, Min, Sec, MSec);
With Result do
begin
year := Year;
month := Month;
day_of_week := DayOfWeek(dt);
day_of_month := Month;
hour := Hour;
minute := Min;
second := Sec;
millisecond := MSec;
end;
end;
{$ENDIF}
function TColorToCefColor(const aColor: TColor): TCefColor;
Var
red, green, blue: Byte;
begin
RedGreenBlue(ColorToRGB(aColor), red, green, blue);
Result := CefColorSetARGB(255, red, green, blue);
end;
function FPColorToCefColor(const aColor: TFPColor): TCefColor;
Const
F = 1 / high(Word) * 255;
begin
With aColor do
Result := CefColorSetARGB(Round(alpha * F), Round(red * F), Round(green * F), Round(blue * F));
end;
function CefString(const str: ustring): TCefString;
begin
Result.length := Length(str);
If Result.length > 0 then Result.str := PCefChar(str)
Else Result.str := nil;
Result.dtor := nil;
end;
function CefString(const str: PCefString): ustring;
begin
If str <> nil then SetString(Result, str^.str, str^.length)
Else Result := '';
end;
function CefStringClearAndGet(var str: TCefString): ustring;
begin
Result := CefString(@str);
cef_string_clear(@str);
end;
function CefStringFreeAndGet(const str: PCefStringUserFree): ustring;
begin
If str <> nil then
begin
Result := CefString(PCefString(str));
cef_string_userfree_free(str);
end
Else Result := '';
end;
function CefStringAlloc(const str: ustring): TCefString;
begin
FillChar(Result, SizeOf(Result), 0);
CefStringSet(@Result, str);
end;
procedure CefStringFree(const str: PCefString);
begin
If str <> nil then cef_string_clear(str);
end;
procedure _free_string(str: PCefChar); cconv;
begin
If str <> nil then FreeMem(str);
end;
function CefUserFreeString(const str: ustring): PCefStringUserFree;
begin
Result := cef_string_userfree_alloc();
Result^.length := Length(str);
Result^.dtor := @_free_string;
GetMem(Result^.str, Result^.length * SizeOf(TCefChar));
Move(PCefChar(str)^, Result^.str^, Result^.length * SizeOf(TCefChar));
end;
procedure CefStringSet(const str: PCefString; const value: ustring); inline;
begin
If str <> nil then cef_string_set(PCefChar(value), Length(value), str, 1);
end;
{ *** API *** }
function CefInitialize: Boolean;
Var
Settings: TCefSettings;
App: ICefApp;
ErrCode: Integer;
Args : TCefMainArgs;
begin
{$IFDEF DEBUG}
Debugln('CefInitialize');
{$ENDIF}
If not CefLoadLibrary(CefLibraryDirPath) then
begin
Result := True;
Exit;
end;
FillChar(Settings, SizeOf(settings), 0);
Settings.size := SizeOf(Settings);
Settings.single_process := Ord(CefSingleProcess);
Settings.no_sandbox := Ord(CefNoSandbox);
Settings.browser_subprocess_path := CefString(CefBrowserSubprocessPath);
Settings.framework_dir_path := CefString(CefFrameworkDirPath);
{$IFDEF CEF_MULTI_THREADED_MESSAGE_LOOP}
Settings.multi_threaded_message_loop := Ord(True);
{$ELSE}
Settings.multi_threaded_message_loop := Ord(False);
{$ENDIF}
Settings.external_message_pump := Ord(CefExternalMessagePump);
Settings.windowless_rendering_enabled := Ord(CefWindowlessRenderingEnabled);
Settings.cache_path := CefString(CefCachePath);
Settings.command_line_args_disabled := Ord(CefCommandLineArgsDisabled);
Settings.cache_path := CefString(CefCachePath);
Settings.user_data_path := CefString(CefUserDataPath);
Settings.persist_session_cookies := Ord(CefPersistSessionCookies);
Settings.persist_user_preferences := Ord(CefPersistUserPreferences);
Settings.user_agent := CefString(CefUserAgent);
Settings.product_version := CefString(CefProductVersion);
Settings.locale := CefString(CefLocale);
Settings.log_file := CefString(CefLogFile);
Settings.log_severity := CefLogSeverity;
Settings.javascript_flags := CefString(CefJavaScriptFlags);
Settings.resources_dir_path := CefString(CefResourcesDirPath);
Settings.locales_dir_path := CefString(CefLocalesDirPath);
Settings.pack_loading_disabled := Ord(CefPackLoadingDisabled);
Settings.remote_debugging_port := CefRemoteDebuggingPort;
Settings.uncaught_exception_stack_size := CefUncaughtExceptionStackSize;
Settings.context_safety_implementation := CefContextSafetyImplementation;
Settings.ignore_certificate_error := Ord(CefIgnoreCertificateError);
Settings.enable_net_security_expiration := Ord(CefEnableNetSecurityExpiration);
Settings.background_color := FPColorToCefColor(CefBackgroundColor);
Settings.accept_language_list := CefString(CefAcceptLanguageList);
app := TInternalApp.Create;
{$IFDEF WINDOWS}
Args.instance := HINSTANCE();
ErrCode := cef_execute_process(@Args, CefGetData(app), nil);
{$ELSE}
Args.argc := argc;
Args.argv := argv;
ErrCode := cef_execute_process(@Args, CefGetData(app), nil);
{$ENDIF}
If ErrCode >= 0 then Halt(ErrCode);
ErrCode := cef_initialize(@Args, @settings, CefGetData(app), nil);
If ErrCode <> 1 then
begin
Result := False;
Exit;
end;
CefIsMainProcess := True;
Result := True;
{$IFDEF LINUX}
// Install xlib error handlers so that the application won't be terminated
// on non-fatal errors.
XSetErrorHandler(@XErrorHandler);
XSetIOErrorHandler(@XIOErrorHandler);
{$ENDIF}
end;
procedure CefShutDown;
begin
{$IFDEF DEBUG}
Debugln('CefShutDown');
{$ENDIF}
If CefIsMainProcess then
begin
cef_shutdown();
CefIsMainProcess := False;
end;
end;
{$IFNDEF CEF_MULTI_THREADED_MESSAGE_LOOP}
procedure CefDoMessageLoopWork;
begin
cef_do_message_loop_work();
end;
procedure CefRunMessageLoop;
begin
cef_run_message_loop();
end;
procedure CefQuitMessageLoop;
begin
cef_quit_message_loop();
end;
{$ENDIF}
procedure CefSetOsmodalLoop(osModalLoop: Boolean);
begin
cef_set_osmodal_loop(Ord(osModalLoop));
end;
procedure CefEnableHighDPISupport;
begin
cef_enable_highdpi_support();
end;
function CefBrowserHostCreateBrowser(windowInfo: PCefWindowInfo; const client: ICefClient;
const url: ustring; const settings: PCefBrowserSettings; const requestContext: ICefRequestContext): Boolean;
Var
u : TCefString;
begin
CefInitialize;
u := CefString(url);
Result := cef_browser_host_create_browser(windowInfo, CefGetData(client), @u, settings, CefGetData(requestContext)) <> 0;
end;
function CefBrowserHostCreateBrowserSync(windowInfo: PCefWindowInfo; const client: ICefClient;
const url: ustring; const settings: PCefBrowserSettings; const requestContext: ICefRequestContext): ICefBrowser;
Var
u: TCefString;
begin
CefInitialize;
u := CefString(url);
Result := TCefBrowserRef.UnWrap(cef_browser_host_create_browser_sync(windowInfo, CefGetData(client), @u, settings, CefGetData(requestContext)));
end;
function CefCrashReportingEnabled: Boolean;
begin
Result := cef_crash_reporting_enabled() <> 0;
end;
procedure CefSetCrashKeyValue(const key, value: ustring);
Var
k, v: TCefString;
begin
k := CefString(key);
v := CefString(value);
cef_set_crash_key_value(@k, @v);
end;
function CefCreateDirectory(const fullPath: ustring): Boolean;
Var
f: TCefString;
begin
f := CefString(fullPath);
Result := cef_create_directory(@f) <> 0;
end;
function CefGetTempDirectory(out tempDir: ustring): Boolean;
Var
t: TCefString;
begin
FillChar(t, SizeOf(t), 0);
Result := cef_get_temp_directory(@t) <> 0;
tempDir := CefString(@t);
end;
function CefCreateNewTempDirectory(const prefix: ustring; out newTempPath: ustring): Boolean;
Var
p, n: TCefString;
begin
p := CefString(prefix);
FillChar(n, SizeOf(n), 0);
Result := cef_create_new_temp_directory(@p, @n) <> 0;
newTempPath := CefString(@n);
end;
function CefCreateTempDirectoryInDirectory(const baseDir, prefix: ustring;
out newDir: ustring): Boolean;
Var
b, p, n: TCefString;
begin
b := CefString(baseDir);
p := CefString(prefix);
FillChar(n, SizeOf(n), 0);
Result := cef_create_temp_directory_in_directory(@b, @p, @n) <> 0;
newDir := CefString(@n);
end;
function CefDirectoryExists(const path: ustring): Boolean;
Var
p: TCefString;
begin
p := CefString(path);
Result := cef_directory_exists(@p) <> 0;
end;
function CefDeleteFile(const path: ustring; recursive: Boolean): Boolean;
Var
p: TCefString;
begin
p := CefString(path);
Result := cef_delete_file(@p, Ord(recursive)) <> 0;
end;
function CefZipDirectory(const srcDir, destFile: ustring; includeHiddenFiles: Boolean): Boolean;
Var
s, d: TCefString;
begin
s := CefString(srcDir);
d := CefString(destFile);
Result := cef_zip_directory(@s, @d, Ord(includeHiddenFiles)) <> 0;
end;
function CefGetGeolocation(const callback: ICefGetGeolocationCallback): Boolean;
begin
Result := cef_get_geolocation(CefGetData(callback)) <> 0;
end;
function CefGetGeolocationProc(const callback: TCefGetGeolocationCallbackProc): Boolean;
begin
Result := CefGetGeolocation(TCefFastGetGeolocationCallback.Create(callback));
end;
function CefAddCrossOriginWhitelistEntry(const SourceOrigin, TargetProtocol, TargetDomain: ustring;
AllowTargetSubdomains: Boolean): Boolean;
Var
so, tp, td: TCefString;
begin
CefInitialize;
so := CefString(SourceOrigin);
tp := CefString(TargetProtocol);
td := CefString(TargetDomain);
If TargetDomain <> '' then
Result := cef_add_cross_origin_whitelist_entry(@so, @tp, @td, Ord(AllowTargetSubdomains)) <> 0
Else
Result := cef_add_cross_origin_whitelist_entry(@so, @tp, nil, Ord(AllowTargetSubdomains)) <> 0;
end;
function CefRemoveCrossOriginWhitelistEntry(const SourceOrigin, TargetProtocol, TargetDomain: ustring;
AllowTargetSubdomains: Boolean): Boolean;
Var
so, tp, td: TCefString;
begin
CefInitialize;
so := CefString(SourceOrigin);
tp := CefString(TargetProtocol);
td := CefString(TargetDomain);
Result := cef_remove_cross_origin_whitelist_entry(@so, @tp, @td, Ord(AllowTargetSubdomains)) <> 0;
end;
function CefClearCrossOriginWhitelist: Boolean;
begin
CefInitialize;
Result := cef_clear_cross_origin_whitelist() <> 0;
end;
function CefParseUrl(const url: ustring; var parts: TUrlParts): Boolean;
Var
u: TCefString;
p: TCefUrlParts;
begin
FillChar(p, sizeof(p), 0);
u := CefString(url);
Result := cef_parse_url(@u, @p) <> 0;
If Result then
begin
parts.spec := CefString(@p.spec);
parts.scheme := CefString(@p.scheme);
parts.username := CefString(@p.username);
parts.password := CefString(@p.password);
parts.host := CefString(@p.host);
parts.port := CefString(@p.port);
parts.origin := CefString(@p.origin);
parts.path := CefString(@p.path);
parts.query := CefString(@p.query);
end;
end;
function CefCreateUrl(var parts: TUrlParts): ustring;
Var
p: TCefUrlParts;
u: TCefString;
begin
FillChar(p, sizeof(p), 0);
p.spec := CefString(parts.spec);
p.scheme := CefString(parts.scheme);
p.username := CefString(parts.username);
p.password := CefString(parts.password);
p.host := CefString(parts.host);
p.port := CefString(parts.port);
p.origin := CefString(parts.origin);
p.path := CefString(parts.path);
p.query := CefString(parts.query);
FillChar(u, SizeOf(u), 0);
If cef_create_url(@p, @u) <> 0 then Result := CefString(@u)
Else Result := '';
end;
function CefFormatUrlForSecurityDisplay(const originUrl: ustring): ustring;
Var
o: TCefString;
begin
o := CefString(originUrl);
Result := CefStringFreeAndGet(cef_format_url_for_security_display(@o));
end;
function CefGetMimeType(const extension: ustring): ustring;
Var
e: TCefString;
begin
e := CefString(extension);
Result := CefStringFreeAndGet(cef_get_mime_type(@e));
end;
procedure CefGetExtensionsForMimeType(const mimeType: ustring; extensions: TStrings);
Var
m, str: TCefString;
i: Integer;
list: TCefStringList;
begin
m := CefString(mimeType);
list := cef_string_list_alloc();
try
cef_get_extensions_for_mime_type(@m, list);
FillChar(str, SizeOf(str), 0);
For i := 0 to cef_string_list_size(list) - 1 do
begin
cef_string_list_value(list, i, @str);
extensions.Add(CefStringClearAndGet(str));
end;
finally
cef_string_list_free(list);
end;
end;
function CefBase64Encode(const data: Pointer; dataSize: TSize): ustring;
begin
Result := CefStringFreeAndGet(cef_base64encode(data, dataSize));
end;
function CefBase64Decode(const data: ustring): ICefBinaryValue;
Var
u: TCefString;
begin
u := CefString(data);
Result := TCefBinaryValueRef.UnWrap(cef_base64decode(@u));
end;
function CefUriEncode(const text: ustring; usePlus: Boolean): ustring;
Var
t: TCefString;
begin
t := CefString(text);
Result := CefStringFreeAndGet(cef_uriencode(@t, Ord(usePlus)));
end;
function CefUriDecode(const text: ustring; convertToUtf8: Boolean;
unescapeRules: TCefUriUnescapeRule): ustring;
Var
t: TCefString;
begin
t := CefString(text);
Result := CefStringFreeAndGet(cef_uridecode(@t, Ord(convertToUtf8), unescapeRules));
end;
function CefParseJson(const jsonString: ustring; options: TCefJsonParserOptions): ICefValue;
Var
j: TCefString;
begin
j := CefString(jsonString);
Result := TCefValueRef.UnWrap(cef_parse_json(@j, options));
end;
function CefParseJsonAndReturnError(const jsonString: ustring; options: TCefJsonParserOptions;
out errorCode: TCefJsonParserError; out errorMsg: ustring): ICefValue;
Var
j: TCefString;
e: TCefString;
begin
j := CefString(jsonString);
Result := TCefValueRef.UnWrap(cef_parse_jsonand_return_error(@j, options, @errorCode, @e));
errorMsg := CefStringClearAndGet(e);
end;
function CefWriteJson(node: ICefValue; options: TCefJsonWriterOptions): ustring;
begin
Result := CefStringFreeAndGet(cef_write_json(CefGetData(node), options));
end;
function CefGetPath(key: TCefPathKey; out path: ustring): Boolean;
Var
p: TCefString;
begin
p := CefString('');
Result := cef_get_path(key, @p) <> 0;
path := CefStringClearAndGet(p);
end;
function CefLaunchProcess(commandLine: ICefCommandLine): Boolean;
begin
Result := cef_launch_process(CefGetData(commandLine)) <> 0;
end;
function CefRegisterSchemeHandlerFactory(const SchemeName, HostName: ustring;
const handler: TCefResourceHandlerClass): Boolean;
Var
s, h: TCefString;
begin
CefInitialize;
s := CefString(SchemeName);
h := CefString(HostName);
Result := cef_register_scheme_handler_factory(
@s, @h, CefGetData(TCefSchemeHandlerFactoryOwn.Create(handler) as ICefBaseRefCounted)) <> 0;
end;
function CefClearSchemeHandlerFactories: Boolean;
begin
CefInitialize;
Result := cef_clear_scheme_handler_factories() <> 0;
end;
function CefIsCertStatusError(status: TCefCertStatus): Boolean;
begin
Result := cef_is_cert_status_error(status) <> 0;
end;
function CefIsCertStatusMinorError(status: TCefCertStatus): Boolean;
begin
Result := cef_is_cert_status_minor_error(status) <> 0;
end;
function CefCurrentlyOn(ThreadId: TCefThreadId): Boolean;
begin
Result := cef_currently_on(ThreadId) <> 0;
end;
procedure CefPostTask(ThreadId: TCefThreadId; const task: ICefTask);
begin
cef_post_task(ThreadId, CefGetData(task));
end;
procedure CefPostDelayedTask(ThreadId: TCefThreadId; const task: ICefTask; delayMs: Int64);
begin
cef_post_delayed_task(ThreadId, CefGetData(task), delayMs);
end;
function CefBeginTracing(const categories: ustring;
const callback: ICefCompletionCallback): Boolean;
Var
c: TCefString;
begin
c := CefString(categories);
Result := cef_begin_tracing(@c, CefGetData(callback)) <> 0;
end;
function CefBeginTracingProc(const categories: ustring;
const proc: TCefCompletionCallbackProc): Boolean;
begin
Result := CefBeginTracing(categories, TCefFastCompletionCallback.Create(proc));
end;
function CefEndTracing(const tracingFile: ustring; const callback: ICefEndTracingCallback): Boolean;
Var
t: TCefString;
begin
t := CefString(tracingFile);
Result := cef_end_tracing(@t, CefGetData(callback)) <> 0;
end;
function CefEndTracingProc(const tracingFile: ustring;
const proc: TCefEndTracingCallbackProc): Boolean;
begin
Result := CefEndTracing(tracingFile, TCefFastEndTracingCallback.Create(proc));
end;
function CefNowFromSystemTraceTime: Int64;
begin
Result := cef_now_from_system_trace_time();
end;
function CefRegisterExtension(const name, code: ustring; const Handler: ICefv8Handler): Boolean;
Var
n, c: TCefString;
begin
n := CefString(name);
c := CefString(code);
Result := cef_register_extension(@n, @c, CefGetData(handler)) <> 0;
end;
function Cefv8ContextInContext: Boolean;
begin
Result := cef_v8context_in_context() <> 0;
end;
procedure CefVisitWebPluginInfo(const visitor: ICefWebPluginInfoVisitor);
begin
cef_visit_web_plugin_info(CefGetData(visitor));
end;
procedure CefVisitWebPluginInfoProc(const visitor: TCefWebPluginInfoVisitorProc);
begin
CefVisitWebPluginInfo(TCefFastWebPluginInfoVisitor.Create(visitor));
end;
procedure CefRefreshWebPlugins;
begin
cef_refresh_web_plugins();
end;
procedure CefUnregisterInternalWebPlugin(const path: ustring);
Var
p: TCefString;
begin
p := CefString(path);
cef_unregister_internal_web_plugin(@p);
end;
procedure CefRegisterWebPluginCrash(const path: ustring);
Var
p: TCefString;
begin
p := CefString(path);
cef_register_web_plugin_crash(@p);
end;
procedure CefIsWebPluginUnstable(const path: ustring; const callback: ICefWebPluginUnstableCallback);
Var
p: TCefString;
begin
p := CefString(path);
cef_is_web_plugin_unstable(@p, CefGetData(callback));
end;
procedure CefIsWebPluginUnstableProc(const path: ustring; const callback: TCefWebPluginIsUnstableProc);
begin
CefIsWebPluginUnstable(path, TCefFastWebPluginUnstableCallback.Create(callback));
end;
procedure CefRegisterWidevineCdm(const path: ustring; const callback: ICefRegisterCdmCallback);
Var
p: TCefString;
begin
p := CefString(path);
cef_register_widevine_cdm(@p, CefGetData(callback));
end;
procedure CefRegisterWidevineCdmProc(const path: ustring; const proc: TCefRegisterCdmCallbackProc);
begin
CefRegisterWidevineCdm(path, TCefFastRegisterCdmCallback.Create(proc));
end;
function CefGetMinLogLevel: Integer;
begin