2023-11-27 18:21:07 +01:00
unit uJSExtension;
2017-07-25 22:50:34 +02:00
2019-05-19 16:08:15 +02:00
{$MODE Delphi}
2023-12-23 18:58:40 +01:00
{$I ..\..\..\..\source\cef.inc}
2017-07-25 22:50:34 +02:00
interface
uses
{$IFDEF DELPHI16_UP}
Winapi . Windows, Winapi . Messages, System. SysUtils, System. Variants, System. Classes, Vcl. Graphics,
Vcl. Controls, Vcl. Forms, Vcl. Dialogs, Vcl. StdCtrls, Vcl. ExtCtrls, Vcl. ComCtrls,
{$ELSE}
2019-05-19 16:08:15 +02:00
LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics,
2017-07-25 22:50:34 +02:00
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
{$ENDIF}
2019-03-28 10:40:36 +01:00
uCEFChromium, uCEFWindowParent, uCEFInterfaces, uCEFApplication, uCEFTypes, uCEFConstants,
2023-11-27 18:21:07 +01:00
uCEFWinControl;
2017-07-25 22:50:34 +02:00
const
2017-09-07 10:58:09 +02:00
MINIBROWSER_SHOWTEXTVIEWER = WM_APP + $100 ;
2017-07-25 22:50:34 +02:00
MINIBROWSER_CONTEXTMENU_SETJSEVENT = MENU_ID_USER_FIRST + 1 ;
2019-09-12 11:40:52 +02:00
MINIBROWSER_CONTEXTMENU_JSVISITDOM = MENU_ID_USER_FIRST + 2 ;
2020-06-21 21:27:55 +02:00
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS = MENU_ID_USER_FIRST + 3 ;
MINIBROWSER_CONTEXTMENU_OFFLINE = MENU_ID_USER_FIRST + 4 ;
2017-07-25 22:50:34 +02:00
2017-09-07 10:58:09 +02:00
MOUSEOVER_MESSAGE_NAME = 'mouseover' ;
CUSTOMNAME_MESSAGE_NAME = 'customname' ;
2017-07-25 22:50:34 +02:00
type
2019-05-19 16:08:15 +02:00
{ TJSExtensionFrm }
2017-07-25 22:50:34 +02:00
TJSExtensionFrm = class( TForm)
NavControlPnl: TPanel;
Edit1: TEdit;
GoBtn: TButton;
CEFWindowParent1: TCEFWindowParent;
Chromium1: TChromium;
2019-05-19 16:08:15 +02:00
StatusPnl: TPanel;
2017-11-04 18:32:29 +01:00
Timer1: TTimer;
2024-09-03 17:26:03 +02:00
procedure FormShow( Sender: TObject) ;
2018-03-31 18:08:18 +02:00
procedure FormCreate( Sender: TObject) ;
procedure FormCloseQuery( Sender: TObject; var CanClose: Boolean ) ;
2024-09-03 17:26:03 +02:00
procedure GoBtnClick( Sender: TObject) ;
procedure Timer1Timer( Sender: TObject) ;
procedure Chromium1BeforeContextMenu( Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; const model: ICefMenuModel) ;
procedure Chromium1ContextMenuCommand( Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; const params: ICefContextMenuParams; commandId: Integer ; eventFlags: Cardinal ; out Result : Boolean ) ;
procedure Chromium1ProcessMessageReceived( Sender: TObject; const browser: ICefBrowser; const frame: ICefFrame; sourceProcess: TCefProcessId; const message : ICefProcessMessage; out Result : Boolean ) ;
procedure Chromium1AfterCreated( Sender: TObject; const browser: ICefBrowser) ;
procedure Chromium1BeforePopup( 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 Chromium1BeforeClose( Sender: TObject; const browser: ICefBrowser) ;
2017-07-25 22:50:34 +02:00
protected
FText : string ;
2018-03-31 18:08:18 +02:00
// Variables to control when can we destroy the form safely
FCanClose : boolean ; // Set to True in TChromium.OnBeforeClose
FClosing : boolean ; // Set to True in the CloseQuery event.
2020-06-21 21:27:55 +02:00
FOffline : boolean ;
2017-07-25 22:50:34 +02:00
2017-09-07 10:58:09 +02:00
procedure BrowserCreatedMsg( var aMessage : TMessage) ; message CEF_AFTERCREATED;
2017-07-25 22:50:34 +02:00
procedure ShowTextViewerMsg( var aMessage : TMessage) ; message MINIBROWSER_SHOWTEXTVIEWER;
procedure WMMove( var aMessage : TWMMove) ; message WM_MOVE;
procedure WMMoving( var aMessage : TMessage) ; message WM_MOVING;
2017-12-18 19:38:56 +01:00
procedure WMEnterMenuLoop( var aMessage: TMessage) ; message WM_ENTERMENULOOP;
procedure WMExitMenuLoop( var aMessage: TMessage) ; message WM_EXITMENULOOP;
2020-06-21 21:27:55 +02:00
function SwitchOfflineMode : integer ;
2017-07-25 22:50:34 +02:00
public
{ Public declarations }
end ;
var
JSExtensionFrm: TJSExtensionFrm;
2018-06-17 14:18:11 +02:00
procedure CreateGlobalCEFApp;
2017-11-25 19:04:15 +01:00
2017-07-25 22:50:34 +02:00
implementation
2019-05-19 16:08:15 +02:00
{$R *.lfm}
2017-07-25 22:50:34 +02:00
uses
2020-06-21 21:27:55 +02:00
uSimpleTextViewer, uCEFMiscFunctions, uTestExtensionHandler, uCEFDictionaryValue;
2017-07-25 22:50:34 +02:00
2019-08-31 17:17:55 +02:00
// BASIC CONCEPTS
// ==============
2018-06-25 13:56:23 +02:00
2019-08-31 17:17:55 +02:00
// Chromium uses several processes to carry out all the tasks needed to handle a web page :
// 1. The main application process is called "BROWSER PROCESS" and it runs the UI.
// 2. The layout and interpretation of HTML is done in the "RENDERER PROCESS".
2017-07-25 22:50:34 +02:00
2019-08-31 17:17:55 +02:00
// Read this for more details about Chromium's architecture :
2018-06-27 10:17:34 +02:00
// http://www.chromium.org/developers/design-documents/multi-process-architecture
2019-08-31 17:17:55 +02:00
// Each process is isolated from the rest and you need to use some kind of inter-process
// communication (IPC) to send information between them. This isolation and protection is
// guaranteed by the operating system and it's the main reason Chromium uses several processes.
// In many cases, you need to use JavaScript or visit the DOM to return some results to Pascal.
// The DOM and JavaScript live in the RENDERER PROCESS, while the Pascal code of your application
// lives in the BROWSER PROCESS.
// As commented before, the operating system isolates each process and this means that you
// can't access anything declared in one process like variables, fields, classes, controls, etc.
// from a different process.
// However, CEF has several ways to send information between processes and you can also use your
// own inter-process communication methods.
// If you need to execute some JavaScript code all you need is to call TChromium.ExecuteJavaScript
// from your application's code in the BROWSER PROCESS and CEF will take care of executing that
// code in the RENDERER PROCESS.
// If you need to send a message to the RENDERER PROCESS from the BROWSER PROCESS you can use
// TChromium.SendProcessMessage.
// To send messages to the BROWSER PROCESS from the RENDERER PROCESS you can use
// ICefFrame.SendProcessMessage
2017-07-25 22:50:34 +02:00
2018-06-25 13:56:23 +02:00
2019-08-31 17:17:55 +02:00
// -------------- TChromium.SendProcessMessage --------------
// | | ------------------------------> | |
// | BROWSER | | RENDERER |
// | | | |
// | PROCESS | ICefFrame.SendProcessMessage | PROCESS |
// | | <------------------------------ | |
// -------------- --------------
// To receive the messages sent from the RENDERER PROCESS you need to use the
// TChromium.OnProcessMessageReceived event. This event is executed in a CEF thread that belongs
// to the BROWSER PROCESS.
// To receive the messages sent from the BROWSER PROCESS you need to use the
// TCefApplication.OnProcessMessageReceived event (GlobalCEFApp.OnProcessMessageReceived).
// This event is executed in a CEF thread that belongs to the RENDERER PROCESS.
// JAVASCRIPT EXTENSIONS
// =====================
// CEF exposes a large number of JS features for integration in client applications.
// You can use JS types, arrays, functions, extensions, objects, etc.
// All of those features are described in detail here :
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
// One of the most interesting JS features available in CEF are the JavaScript extensions because they
// can be used to execute custom Pascal code from JavaScript.
2017-07-25 22:50:34 +02:00
2019-08-31 17:17:55 +02:00
// If you put all you know so far together you can get any result or information in Pascal from
// JavaScript following these steps :
// 1. Use TChromium.ExecuteJavaScript to execute your custom JavaScript code.
// 2. That custom JavaScript code is executed in the RENDERER PROCESS and it can call functions in your
// custom JavaScript extension, which executes Pascal code. This Pascal code is also executed in
// the RENDERER PROCESS.
// 3. The Pascal code in the JavaScript extension can use ICefFrame.SendProcessMessage to send
// information back to the BROWSER PROCESS.
// 4. The BROWSER PROCESS receives the information in the TChromium.OnProcessMessageReceived event.
// To create a JavaScript extension in CEF you have to create a new class that inherits from
// TCefv8HandlerOwn and it has to override the "execute" function. Open uTestExtensionHandler.pas
// to see an example and read this for more details about the "execute" parameters :
// https://magpcss.org/ceforum/apidocs3/projects/(default)/CefV8Handler.html
// In order to use that extension, you must register it in the GlobalCEFApp.OnWebKitInitialized event
// as you can see in the GlobalCEFApp_OnWebKitInitialized procedure on this PAS unit.
// You have to call the CefRegisterExtension function with 3 parameters :
// 1. name : The extension name.
// 2. code : Any valid JS code but in this case it includes 2 "native function" forward declarations.
// 3. Handler : An instance of your TCefv8HandlerOwn subclass.
// Notice that the code used with the CefRegisterExtension function in this demo is declaring
// "myextension.mouseover" as a function that calls the "mouseover" native function, and the
// "myextension.sendresulttobrowser" function that calls the "sendresulttobrowser" native function.
// The "execute" function in the custom TCefv8HandlerOwn subclass will compare the "name" parameter
// with the name of the of the native function used in the code that registered this extension.
// As you can see in this demo, TTestExtensionHandler.Execute compares the "name" parameter with
// "mouseover" and "sendresulttobrowser" to execute the code you want for each of those custom functions.
// TTestExtensionHandler.Execute is executed in the RENDERER PROCESS and it uses a process message
// to send some results to he BROWSER PROCESS.
// It uses TCefv8ContextRef.Current.Browser.MainFrame to call the SendProcessMessage procedure for
// the main frame.
// The message is a TCefProcessMessageRef instance and you can set the information you want to send using
// its ArgumentList property.
// You can add several items to ArgumentList using different indexes in the SetString, SetInt, SetBool,
// SetBinary, etc. functions.
// There is a size limit in the binary parameters of only a few kilobytes. Compress the binary data, use
// alternative IPC methods or use a database protected by a mutex if necessary.
// For more information about this, read the following pages :
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md#markdown-header-functions-and-extensions
// https://bitbucket.org/chromiumembedded/cef/src/b6b033a52bb3f7059d169a4c8389966c8fe2531b/include/capi/cef_v8_capi.h#lines-924
// TESTING THIS DEMO :
// ===================
// 1. Run the demo and wait until google.com is loaded
// 2. Right-click and select the "Set the mouseover event" menu option.
// 3. Move the mouse pointer over the web page and see the HTML elements in the status bar.
// When you select the "Set the mouseover event" menu option, the
2018-06-27 10:17:34 +02:00
// TChromium.OnContextMenuCommand event is triggered and it adds an event listener to the
// document's body. That listener calls one of the functions available in the registered
// extension called "myextension.mouseover".
2017-07-25 22:50:34 +02:00
2019-08-31 17:17:55 +02:00
// The TTestExtensionHandler.Execute function in the extension is executed and it
// uses TCefv8ContextRef.Current.Browser.MainFrame.SendProcessMessage(PID_BROWSER, msg)
// to send a process message with the results to the browser process.
2018-06-27 10:17:34 +02:00
2019-08-31 17:17:55 +02:00
// That message is received in the TChromium.OnProcessMessageReceived event and it shows
// the information in the status bar.
2018-06-25 13:56:23 +02:00
2018-06-27 10:17:34 +02:00
// If you have to debug the code executed by the extension you will need to use the
// debugging methods described in
2018-06-25 13:56:23 +02:00
// https://www.briskbard.com/index.php?lang=en&pageid=cef
2019-08-31 17:17:55 +02:00
// DESTRUCTION STEPS
2018-03-31 18:08:18 +02:00
// =================
2024-09-03 17:26:03 +02:00
// 1. FormCloseQuery sets CanClose to FALSE, destroys CEFWindowParent1 and calls TChromium.CloseBrowser which triggers the TChromium.OnBeforeClose event.
// 2. TChromium.OnBeforeClose sets FCanClose := True and sends WM_CLOSE to the form.
2018-03-31 18:08:18 +02:00
2017-11-25 19:04:15 +01:00
procedure GlobalCEFApp_OnWebKitInitialized;
var
TempExtensionCode : string ;
TempHandler : ICefv8Handler;
begin
// This is a JS extension example with 2 functions and several parameters.
// Please, read the "JavaScript Integration" wiki page at
// https://bitbucket.org/chromiumembedded/cef/wiki/JavaScriptIntegration.md
TempExtensionCode : = 'var myextension;' +
'if (!myextension)' +
' myextension = {};' +
'(function() {' +
' myextension.mouseover = function(a) {' +
' native function mouseover();' +
' mouseover(a);' +
' };' +
' myextension.sendresulttobrowser = function(b,c) {' +
' native function sendresulttobrowser();' +
' sendresulttobrowser(b,c);' +
' };' +
'})();' ;
2018-07-24 18:18:54 +02:00
try
TempHandler : = TTestExtensionHandler. Create;
2019-09-12 11:40:52 +02:00
if CefRegisterExtension( 'myextension' , TempExtensionCode, TempHandler) then
{$IFDEF DEBUG} CefDebugLog( 'JavaScript extension registered successfully!' ) {$ENDIF}
else
{$IFDEF DEBUG} CefDebugLog( 'There was an error registering the JavaScript extension!' ) {$ENDIF} ;
2018-07-24 18:18:54 +02:00
finally
TempHandler : = nil ;
end ;
2017-11-25 19:04:15 +01:00
end ;
2018-06-17 14:18:11 +02:00
procedure CreateGlobalCEFApp;
begin
GlobalCEFApp : = TCefApplication. Create;
2023-12-23 18:58:40 +01:00
GlobalCEFApp. OnWebKitInitialized : = GlobalCEFApp_OnWebKitInitialized;
GlobalCEFApp. SetCurrentDir : = True ;
2019-09-12 11:40:52 +02:00
{$IFDEF DEBUG}
2018-07-24 18:18:54 +02:00
GlobalCEFApp. LogFile : = 'debug.log' ;
GlobalCEFApp. LogSeverity : = LOGSEVERITY_INFO;
{$ENDIF}
2018-06-17 14:18:11 +02:00
end ;
2017-07-25 22:50:34 +02:00
procedure TJSExtensionFrm. GoBtnClick( Sender: TObject) ;
begin
Chromium1. LoadURL( Edit1. Text ) ;
end ;
2017-09-07 10:58:09 +02:00
procedure TJSExtensionFrm. Chromium1AfterCreated( Sender: TObject; const browser: ICefBrowser) ;
2017-07-25 22:50:34 +02:00
begin
2017-09-07 10:58:09 +02:00
PostMessage( Handle, CEF_AFTERCREATED, 0 , 0 ) ;
2017-07-25 22:50:34 +02:00
end ;
2018-03-31 18:08:18 +02:00
procedure TJSExtensionFrm. Chromium1BeforeClose( Sender: TObject;
const browser: ICefBrowser) ;
begin
2020-02-26 13:28:29 +01:00
FCanClose : = True ;
PostMessage( Handle, WM_CLOSE, 0 , 0 ) ;
2018-03-31 18:08:18 +02:00
end ;
2017-07-25 22:50:34 +02:00
procedure TJSExtensionFrm. Chromium1BeforeContextMenu( Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; const model: ICefMenuModel) ;
begin
// Adding some custom context menu entries
model. AddSeparator;
2019-09-12 11:40:52 +02:00
model. AddItem( MINIBROWSER_CONTEXTMENU_SETJSEVENT, 'Set mouseover event' ) ;
model. AddItem( MINIBROWSER_CONTEXTMENU_JSVISITDOM, 'Visit DOM in JavaScript' ) ;
2020-06-21 21:27:55 +02:00
model. AddItem( MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS, 'Show DevTools' ) ;
model. AddCheckItem( MINIBROWSER_CONTEXTMENU_OFFLINE, 'Offline' ) ;
model. SetChecked( MINIBROWSER_CONTEXTMENU_OFFLINE, FOffline) ;
2017-07-25 22:50:34 +02:00
end ;
2018-02-16 18:41:13 +01:00
procedure TJSExtensionFrm. Chromium1BeforePopup( Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame; const targetUrl,
targetFrameName: ustring; targetDisposition: TCefWindowOpenDisposition;
2018-03-29 20:02:04 +02:00
userGesture: Boolean ; const popupFeatures: TCefPopupFeatures;
2018-02-16 18:41:13 +01:00
var windowInfo: TCefWindowInfo; var client: ICefClient;
2019-06-16 10:31:13 +02:00
var settings: TCefBrowserSettings;
var extra_info: ICefDictionaryValue;
var noJavascriptAccess: Boolean ;
2018-03-29 20:02:04 +02:00
var Result : Boolean ) ;
2018-02-16 18:41:13 +01:00
begin
// For simplicity, this demo blocks all popup windows and new tabs
2023-12-15 18:06:46 +01:00
Result : = ( targetDisposition in [ CEF_WOD_NEW_FOREGROUND_TAB, CEF_WOD_NEW_BACKGROUND_TAB, CEF_WOD_NEW_POPUP, CEF_WOD_NEW_WINDOW] ) ;
2018-02-16 18:41:13 +01:00
end ;
2017-07-25 22:50:34 +02:00
procedure TJSExtensionFrm. Chromium1ContextMenuCommand( Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const params: ICefContextMenuParams; commandId: Integer ;
2019-09-12 11:40:52 +02:00
eventFlags: Cardinal ; out Result : Boolean ) ;
var
TempPoint : TPoint;
TempJSCode : string ;
2017-07-25 22:50:34 +02:00
begin
Result : = False ;
// Here is the code executed for each custom context menu entry
case commandId of
MINIBROWSER_CONTEXTMENU_SETJSEVENT :
2019-10-13 18:50:23 +02:00
if ( frame < > nil ) and frame. IsValid then
2019-09-12 11:40:52 +02:00
begin
TempJSCode : = 'document.body.addEventListener("mouseover", function(evt){' +
'function getpath(n){' +
'var ret = "<" + n.nodeName + ">";' +
'if (n.parentNode){return getpath(n.parentNode) + ret} else ' +
'return ret' +
'};' +
'myextension.mouseover(getpath(evt.target))}' +
')' ;
2019-10-13 18:50:23 +02:00
frame. ExecuteJavaScript( TempJSCode, 'about:blank' , 0 ) ;
2019-09-12 11:40:52 +02:00
end ;
2017-07-25 22:50:34 +02:00
MINIBROWSER_CONTEXTMENU_JSVISITDOM :
2019-10-13 18:50:23 +02:00
if ( frame < > nil ) and frame. IsValid then
2019-09-12 11:40:52 +02:00
begin
TempJSCode : = 'var testhtml = document.body.innerHTML; ' +
'myextension.sendresulttobrowser(testhtml, ' + quotedstr( CUSTOMNAME_MESSAGE_NAME) + ');' ;
2019-10-13 18:50:23 +02:00
frame. ExecuteJavaScript( TempJSCode, 'about:blank' , 0 ) ;
2019-09-12 11:40:52 +02:00
end ;
MINIBROWSER_CONTEXTMENU_SHOWDEVTOOLS :
begin
TempPoint. x : = params. XCoord;
TempPoint. y : = params. YCoord;
Chromium1. ShowDevTools( TempPoint, nil ) ;
2020-06-21 21:27:55 +02:00
end ;
MINIBROWSER_CONTEXTMENU_OFFLINE :
SwitchOfflineMode;
end ;
end ;
// This is a simple example to set the "offline" mode in the DevTools using the TChromium methods directly.
function TJSExtensionFrm. SwitchOfflineMode : integer ;
var
TempParams : ICefDictionaryValue;
begin
try
FOffline : = not( FOffline) ;
TempParams : = TCefDictionaryValueRef. New;
TempParams. SetBool( 'offline' , FOffline) ;
TempParams. SetDouble( 'latency' , 0 ) ;
TempParams. SetDouble( 'downloadThroughput' , 0 ) ;
TempParams. SetDouble( 'uploadThroughput' , 0 ) ;
Result : = Chromium1. ExecuteDevToolsMethod( 0 , 'Network.emulateNetworkConditions' , TempParams) ;
finally
TempParams : = nil ;
2017-07-25 22:50:34 +02:00
end ;
end ;
procedure TJSExtensionFrm. Chromium1ProcessMessageReceived( Sender: TObject;
2019-06-16 10:31:13 +02:00
const browser: ICefBrowser; const frame: ICefFrame; sourceProcess: TCefProcessId;
2017-07-25 22:50:34 +02:00
const message : ICefProcessMessage; out Result : Boolean ) ;
begin
2017-09-08 17:27:05 +02:00
Result : = False ;
2017-07-25 22:50:34 +02:00
if ( message = nil ) or ( message . ArgumentList = nil ) then exit;
// This function receives the messages with the JavaScript results
2017-08-12 16:22:34 +02:00
// Many of these events are received in different threads and the VCL
2017-07-25 22:50:34 +02:00
// doesn't like to create and destroy components in different threads.
// It's safer to store the results and send a message to the main thread to show them.
// The message names are defined in the extension or in JS code.
2017-09-07 10:58:09 +02:00
if ( message . Name = MOUSEOVER_MESSAGE_NAME) then
2017-07-25 22:50:34 +02:00
begin
2019-05-19 16:08:15 +02:00
StatusPnl. Caption : = message . ArgumentList. GetString( 0 ) ; // this doesn't create/destroy components
2017-07-25 22:50:34 +02:00
Result : = True ;
end
else
2017-09-07 10:58:09 +02:00
if ( message . Name = CUSTOMNAME_MESSAGE_NAME) then
2017-07-25 22:50:34 +02:00
begin
FText : = message . ArgumentList. GetString( 0 ) ;
PostMessage( Handle, MINIBROWSER_SHOWTEXTVIEWER, 0 , 0 ) ;
Result : = True ;
2017-09-08 17:27:05 +02:00
end ;
2017-07-25 22:50:34 +02:00
end ;
2018-03-31 18:08:18 +02:00
procedure TJSExtensionFrm. FormCloseQuery( Sender: TObject;
var CanClose: Boolean ) ;
begin
CanClose : = FCanClose;
if not( FClosing) then
begin
FClosing : = True ;
Visible : = False ;
Chromium1. CloseBrowser( True ) ;
2024-09-03 17:26:03 +02:00
CEFWindowParent1. Free;
2018-03-31 18:08:18 +02:00
end ;
end ;
procedure TJSExtensionFrm. FormCreate( Sender: TObject) ;
begin
FCanClose : = False ;
FClosing : = False ;
end ;
2017-07-25 22:50:34 +02:00
procedure TJSExtensionFrm. FormShow( Sender: TObject) ;
begin
2019-05-19 16:08:15 +02:00
StatusPnl. Caption : = 'Initializing browser. Please wait...' ;
2017-11-04 18:32:29 +01:00
// GlobalCEFApp.GlobalContextInitialized has to be TRUE before creating any browser
// If it's not initialized yet, we use a simple timer to create the browser later.
if not( Chromium1. CreateBrowser( CEFWindowParent1, '' ) ) then Timer1. Enabled : = True ;
2017-07-25 22:50:34 +02:00
end ;
procedure TJSExtensionFrm. WMMove( var aMessage : TWMMove) ;
begin
inherited ;
if ( Chromium1 < > nil ) then Chromium1. NotifyMoveOrResizeStarted;
end ;
procedure TJSExtensionFrm. WMMoving( var aMessage : TMessage) ;
begin
inherited ;
if ( Chromium1 < > nil ) then Chromium1. NotifyMoveOrResizeStarted;
end ;
2017-12-18 19:38:56 +01:00
procedure TJSExtensionFrm. WMEnterMenuLoop( var aMessage: TMessage) ;
begin
inherited ;
if ( aMessage. wParam = 0 ) and ( GlobalCEFApp < > nil ) then GlobalCEFApp. OsmodalLoop : = True ;
end ;
procedure TJSExtensionFrm. WMExitMenuLoop( var aMessage: TMessage) ;
begin
inherited ;
if ( aMessage. wParam = 0 ) and ( GlobalCEFApp < > nil ) then GlobalCEFApp. OsmodalLoop : = False ;
end ;
2017-07-25 22:50:34 +02:00
procedure TJSExtensionFrm. ShowTextViewerMsg( var aMessage : TMessage) ;
begin
// This form will show the HTML received from JavaScript
SimpleTextViewerFrm. Memo1. Lines. Text : = FText;
SimpleTextViewerFrm. ShowModal;
end ;
2017-11-04 18:32:29 +01:00
procedure TJSExtensionFrm. Timer1Timer( Sender: TObject) ;
begin
Timer1. Enabled : = False ;
2017-11-16 12:49:15 +01:00
if not( Chromium1. CreateBrowser( CEFWindowParent1, '' ) ) and not( Chromium1. Initialized) then
Timer1. Enabled : = True ;
2017-11-04 18:32:29 +01:00
end ;
2017-07-25 22:50:34 +02:00
procedure TJSExtensionFrm. BrowserCreatedMsg( var aMessage : TMessage) ;
begin
2019-05-19 16:08:15 +02:00
StatusPnl. Caption : = '' ;
2017-08-23 12:28:45 +02:00
CEFWindowParent1. UpdateSize;
2017-07-25 22:50:34 +02:00
NavControlPnl. Enabled : = True ;
GoBtn. Click;
end ;
end .