1
0
mirror of https://github.com/salvadordf/CEF4Delphi.git synced 2025-11-23 21:34:53 +02:00

Fixed the CustomResourceHandler demo

- Added TCEFSentinel to more demos
This commit is contained in:
Salvador Díaz Fau
2019-10-14 15:39:27 +02:00
parent 77121dc510
commit 4d994de2e9
99 changed files with 1179 additions and 512 deletions

View File

@@ -22,15 +22,15 @@
<ResourceBaseClass Value="Form"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="1"/>
<TopLine Value="103"/>
<CursorPos X="58" Y="123"/>
<TopLine Value="235"/>
<CursorPos X="51" Y="233"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
<LoadedDesigner Value="True"/>
<DefaultSyntaxHighlighter Value="Delphi"/>
</Unit1>
</Units>
<JumpHistory Count="5" HistoryIndex="4">
<JumpHistory Count="11" HistoryIndex="10">
<Position1>
<Filename Value="JSDialogBrowser.lpr"/>
</Position1>
@@ -50,6 +50,30 @@
<Filename Value="uJSDialogBrowser.pas"/>
<Caret Line="72" Column="32" TopLine="64"/>
</Position5>
<Position6>
<Filename Value="uJSDialogBrowser.pas"/>
<Caret Line="117" Column="82" TopLine="103"/>
</Position6>
<Position7>
<Filename Value="uJSDialogBrowser.pas"/>
<Caret Line="123" Column="82" TopLine="109"/>
</Position7>
<Position8>
<Filename Value="uJSDialogBrowser.pas"/>
<Caret Line="263" Column="40" TopLine="235"/>
</Position8>
<Position9>
<Filename Value="uJSDialogBrowser.pas"/>
<Caret Line="77" Column="15" TopLine="60"/>
</Position9>
<Position10>
<Filename Value="uJSDialogBrowser.pas"/>
<Caret Line="279" TopLine="275"/>
</Position10>
<Position11>
<Filename Value="uJSDialogBrowser.pas"/>
<Caret Line="93" Column="59" TopLine="82"/>
</Position11>
</JumpHistory>
<RunParams>
<FormatVersion Value="2"/>

View File

@@ -65,4 +65,9 @@ object JSDialogBrowserFrm: TJSDialogBrowserFrm
left = 56
top = 88
end
object CEFSentinel1: TCEFSentinel
OnClose = CEFSentinel1Close
left = 128
top = 88
end
end

View File

@@ -49,18 +49,24 @@ uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, ExtCtrls, SyncObjs,
{$ENDIF}
uCEFChromium, uCEFWindowParent, uCEFChromiumWindow, uCEFInterfaces, uCEFTypes, uCEFConstants;
uCEFChromium, uCEFWindowParent, uCEFChromiumWindow, uCEFInterfaces, uCEFTypes,
uCEFConstants, uCEFSentinel;
const
CEFBROWSER_SHOWJSDIALOG = WM_APP + $101;
type
{ TJSDialogBrowserFrm }
TJSDialogBrowserFrm = class(TForm)
CEFSentinel1: TCEFSentinel;
ChromiumWindow1: TChromiumWindow;
AddressPnl: TPanel;
AddressEdt: TEdit;
GoBtn: TButton;
Timer1: TTimer;
procedure CEFSentinel1Close(Sender: TObject);
procedure GoBtnClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ChromiumWindow1AfterCreated(Sender: TObject);
@@ -113,8 +119,8 @@ uses
// =================
// 1. The FormCloseQuery event sets CanClose to False and calls TChromiumWindow.CloseBrowser, which triggers the TChromiumWindow.OnClose event.
// 2. The TChromiumWindow.OnClose event calls TChromiumWindow.DestroyChildWindow which triggers the TChromiumWindow.OnBeforeClose event.
// 3. TChromiumWindow.OnBeforeClose sets FCanClose to True and closes the form.
// 3. TChromiumWindow.OnBeforeClose calls TCEFSentinel.Start, which will trigger TCEFSentinel.OnClose when the renderer processes are closed.
// 4. TCEFSentinel.OnClose sets FCanClose := True and sends WM_CLOSE to the form.
procedure CreateGlobalCEFApp;
begin
@@ -176,6 +182,12 @@ begin
ChromiumWindow1.LoadURL(AddressEdt.Text);
end;
procedure TJSDialogBrowserFrm.CEFSentinel1Close(Sender: TObject);
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
end;
procedure TJSDialogBrowserFrm.Timer1Timer(Sender: TObject);
begin
Timer1.Enabled := False;
@@ -211,15 +223,14 @@ begin
if (aMessage.wParam = 0) and (GlobalCEFApp <> nil) then GlobalCEFApp.OsmodalLoop := False;
end;
procedure TJSDialogBrowserFrm.Chromium_OnJsdialog(Sender : TObject;
const browser : ICefBrowser;
const originUrl : ustring;
dialogType : TCefJsDialogType;
const messageText : ustring;
const defaultPromptText : ustring;
const callback : ICefJsDialogCallback;
out suppressMessage : Boolean;
out Result : Boolean);
procedure TJSDialogBrowserFrm.Chromium_OnJsdialog(Sender: TObject;
const browser: ICefBrowser;
const originUrl: ustring;
dialogType: TCefJsDialogType;
const messageText, defaultPromptText: ustring;
const callback: ICefJsDialogCallback;
out suppressMessage: Boolean;
out Result: Boolean);
begin
// In this event we must store the dialog information and post a message to the main form to show the dialog
FJSDialogInfoCS.Acquire;
@@ -248,18 +259,13 @@ end;
procedure TJSDialogBrowserFrm.ChromiumWindow1BeforeClose(Sender: TObject);
begin
FCanClose := True;
PostMessage(Handle, WM_CLOSE, 0, 0);
CEFSentinel1.Start;
end;
procedure TJSDialogBrowserFrm.ChromiumWindow1Close(Sender: TObject);
begin
// DestroyChildWindow will destroy the child window created by CEF at the top of the Z order.
if not(ChromiumWindow1.DestroyChildWindow) then
begin
FCanClose := True;
Close;
end;
if not(ChromiumWindow1.DestroyChildWindow) then CEFSentinel1.Start;
end;
procedure TJSDialogBrowserFrm.Chromium_OnBeforePopup(Sender: TObject;