globalcefapplication.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // ************************************************************************
  2. // ***************************** CEF4Delphi *******************************
  3. // ************************************************************************
  4. //
  5. // CEF4Delphi is based on DCEF3 which uses CEF to embed a chromium-based
  6. // browser in Delphi applications.
  7. //
  8. // The original license of DCEF3 still applies to CEF4Delphi.
  9. //
  10. // For more information about CEF4Delphi visit :
  11. // https://www.briskbard.com/index.php?lang=en&pageid=cef
  12. //
  13. // Copyright © 2021 Salvador Diaz Fau. All rights reserved.
  14. //
  15. // ************************************************************************
  16. // ************ vvvv Original license and comments below vvvv *************
  17. // ************************************************************************
  18. (*
  19. * Delphi Chromium Embedded 3
  20. *
  21. * Usage allowed under the restrictions of the Lesser GNU General Public License
  22. * or alternatively the restrictions of the Mozilla Public License 1.1
  23. *
  24. * Software distributed under the License is distributed on an "AS IS" basis,
  25. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  26. * the specific language governing rights and limitations under the License.
  27. *
  28. * Unit owner : Henri Gourvest <[email protected]>
  29. * Web site : http://www.progdigy.com
  30. * Repository : http://code.google.com/p/delphichromiumembedded/
  31. * Group : http://groups.google.com/group/delphichromiumembedded
  32. *
  33. * Embarcadero Technologies, Inc is not permitted to use or redistribute
  34. * this source code without explicit permission.
  35. *
  36. *)
  37. unit GlobalCefApplication;
  38. {$mode ObjFPC}{$H+}
  39. {$DEFINE USE_MULTI_THREAD_LOOP} // Only Windows/Linux
  40. {.$DEFINE USE_APP_HELPER} // Optional on Windows/Linux
  41. {$IFDEF DARWIN}
  42. {$UNDEF USE_MULTI_THREAD_LOOP} // Will fail on Mac
  43. {$DEFINE USE_APP_HELPER} // Required on Mac
  44. {$ENDIF}
  45. interface
  46. uses
  47. uCEFApplication, uCEFWorkScheduler, FileUtil;
  48. procedure CreateGlobalCEFApp;
  49. implementation
  50. procedure GlobalCEFApp_OnScheduleMessagePumpWork(const aDelayMS : int64);
  51. begin
  52. if (GlobalCEFWorkScheduler <> nil) then GlobalCEFWorkScheduler.ScheduleMessagePumpWork(aDelayMS);
  53. end;
  54. procedure CreateGlobalCEFApp;
  55. begin
  56. if GlobalCEFApp <> nil then
  57. exit;
  58. {$IFnDEF USE_MULTI_THREAD_LOOP}
  59. // TCEFWorkScheduler will call cef_do_message_loop_work when
  60. // it's told in the GlobalCEFApp.OnScheduleMessagePumpWork event.
  61. // GlobalCEFWorkScheduler needs to be created before the
  62. // GlobalCEFApp.StartMainProcess call.
  63. GlobalCEFWorkScheduler := TCEFWorkScheduler.Create(nil);
  64. {$ENDIF}
  65. GlobalCEFApp := TCefApplication.Create;
  66. // GlobalCEFApp.CheckCEFFiles := False;
  67. {$IFnDEF DARWIN}
  68. GlobalCEFApp.FrameworkDirPath := 'B:\laz_other\CEF4Delphi\LIB_CEF_BIN\';
  69. {$ENDIF}
  70. {$IFDEF USE_MULTI_THREAD_LOOP}
  71. // On Windows/Linux CEF can use threads for the message-loop
  72. GlobalCEFApp.MultiThreadedMessageLoop := True;
  73. {$ELSE}
  74. // use External Pump for message-loop
  75. GlobalCEFApp.ExternalMessagePump := True;
  76. GlobalCEFApp.MultiThreadedMessageLoop := False;
  77. GlobalCEFApp.OnScheduleMessagePumpWork := @GlobalCEFApp_OnScheduleMessagePumpWork;
  78. {$ENDIF}
  79. {$IFnDEF DARWIN}
  80. {$IFDEF USE_APP_HELPER}
  81. (* Use AppHelper as subprocess, instead of the main exe *)
  82. GlobalCEFApp.BrowserSubprocessPath := 'AppHelper' + GetExeExt;
  83. {$ENDIF}
  84. {$ENDIF}
  85. {$IFDEF DARWIN}
  86. (* Enable the below to prevent being asked for permission to access "Chromium Safe Storage"
  87. If set to true, Cookies will not be encrypted.
  88. *)
  89. GlobalCEFApp.UseMockKeyChain := True;
  90. {$ENDIF}
  91. {$IFDEF LINUX}
  92. // This is a workaround for the 'GPU is not usable error' issue :
  93. // https://bitbucket.org/chromiumembedded/cef/issues/2964/gpu-is-not-usable-error-during-cef
  94. GlobalCEFApp.DisableZygote := True; // this property adds the "--no-zygote" command line switch
  95. {$ENDIF}
  96. {
  97. GlobalCEFApp.LogFile := 'cef.log';
  98. GlobalCEFApp.LogSeverity := LOGSEVERITY_VERBOSE;
  99. }
  100. end;
  101. end.