2017-01-27 17:29:37 +01:00
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ***************************** CEF4Delphi *******************************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
//
|
|
|
|
|
// CEF4Delphi is based on DCEF3 which uses CEF3 to embed a chromium-based
|
|
|
|
|
// browser in Delphi applications.
|
|
|
|
|
//
|
|
|
|
|
// The original license of DCEF3 still applies to CEF4Delphi.
|
|
|
|
|
//
|
|
|
|
|
// For more information about CEF4Delphi visit :
|
|
|
|
|
// https://www.briskbard.com/index.php?lang=en&pageid=cef
|
|
|
|
|
//
|
2018-01-06 15:25:32 +01:00
|
|
|
|
// Copyright <20> 2018 Salvador D<>az Fau. All rights reserved.
|
2017-01-27 17:29:37 +01:00
|
|
|
|
//
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
// ************ vvvv Original license and comments below vvvv *************
|
|
|
|
|
// ************************************************************************
|
|
|
|
|
(*
|
|
|
|
|
* Delphi 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.
|
|
|
|
|
*
|
|
|
|
|
* Unit owner : Henri Gourvest <hgourvest@gmail.com>
|
|
|
|
|
* Web site : http://www.progdigy.com
|
|
|
|
|
* Repository : http://code.google.com/p/delphichromiumembedded/
|
|
|
|
|
* Group : http://groups.google.com/group/delphichromiumembedded
|
|
|
|
|
*
|
|
|
|
|
* Embarcadero Technologies, Inc is not permitted to use or redistribute
|
|
|
|
|
* this source code without explicit permission.
|
|
|
|
|
*
|
|
|
|
|
*)
|
|
|
|
|
|
|
|
|
|
unit uCEFChromiumWindow;
|
|
|
|
|
|
|
|
|
|
{$IFNDEF CPUX64}
|
|
|
|
|
{$ALIGN ON}
|
|
|
|
|
{$MINENUMSIZE 4}
|
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$I cef.inc}
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
uses
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2017-01-27 17:29:37 +01:00
|
|
|
|
WinApi.Windows, System.Classes, WinApi.Messages,
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$ELSE}
|
|
|
|
|
Windows, Classes, Messages,
|
|
|
|
|
{$ENDIF}
|
2017-01-27 17:29:37 +01:00
|
|
|
|
uCEFWindowParent, uCEFChromium, uCEFInterfaces, uCEFConstants;
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
TChromiumWindow = class(TCEFWindowParent)
|
|
|
|
|
protected
|
2017-09-07 10:58:09 +02:00
|
|
|
|
FChromium : TChromium;
|
|
|
|
|
FOnClose : TNotifyEvent;
|
2017-12-07 10:49:51 +01:00
|
|
|
|
FOnBeforeClose : TNotifyEvent;
|
2017-09-07 10:58:09 +02:00
|
|
|
|
FOnAfterCreated : TNotifyEvent;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
function GetChildWindowHandle : THandle; override;
|
2017-10-28 18:48:53 +02:00
|
|
|
|
function GetBrowserInitialized : boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
procedure OnCloseMsg(var aMessage : TMessage); message CEF_DOONCLOSE;
|
2017-12-07 10:49:51 +01:00
|
|
|
|
procedure OnBeforeCloseMsg(var aMessage : TMessage); message CEF_DOONBEFORECLOSE;
|
2017-09-07 10:58:09 +02:00
|
|
|
|
procedure OnAfterCreatedMsg(var aMessage : TMessage); message CEF_AFTERCREATED;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
procedure WebBrowser_OnClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
2017-12-07 10:49:51 +01:00
|
|
|
|
procedure WebBrowser_OnBeforeClose(Sender: TObject; const browser: ICefBrowser);
|
2017-09-07 10:58:09 +02:00
|
|
|
|
procedure WebBrowser_OnAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
public
|
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
|
procedure AfterConstruction; override;
|
2017-10-28 18:48:53 +02:00
|
|
|
|
function CreateBrowser : boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
procedure CloseBrowser(aForceClose : boolean);
|
|
|
|
|
procedure LoadURL(const aURL : string);
|
2017-12-07 10:49:51 +01:00
|
|
|
|
procedure NotifyMoveOrResizeStarted;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
2017-11-13 18:32:48 +01:00
|
|
|
|
property ChromiumBrowser : TChromium read FChromium;
|
|
|
|
|
property Initialized : boolean read GetBrowserInitialized;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
published
|
2017-09-07 10:58:09 +02:00
|
|
|
|
property OnClose : TNotifyEvent read FOnClose write FOnClose;
|
2017-12-07 10:49:51 +01:00
|
|
|
|
property OnBeforeClose : TNotifyEvent read FOnBeforeClose write FOnBeforeClose;
|
2017-09-07 10:58:09 +02:00
|
|
|
|
property OnAfterCreated : TNotifyEvent read FOnAfterCreated write FOnAfterCreated;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
uses
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$IFDEF DELPHI16_UP}
|
2017-01-27 17:29:37 +01:00
|
|
|
|
System.SysUtils;
|
2017-02-05 20:56:46 +01:00
|
|
|
|
{$ELSE}
|
|
|
|
|
SysUtils;
|
|
|
|
|
{$ENDIF}
|
2017-01-27 17:29:37 +01:00
|
|
|
|
|
|
|
|
|
constructor TChromiumWindow.Create(AOwner: TComponent);
|
|
|
|
|
begin
|
|
|
|
|
inherited Create(AOwner);
|
|
|
|
|
|
2017-09-07 10:58:09 +02:00
|
|
|
|
FChromium := nil;
|
|
|
|
|
FOnClose := nil;
|
2017-12-07 10:49:51 +01:00
|
|
|
|
FOnBeforeClose := nil;
|
2017-09-07 10:58:09 +02:00
|
|
|
|
FOnAfterCreated := nil;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TChromiumWindow.AfterConstruction;
|
|
|
|
|
begin
|
|
|
|
|
inherited AfterConstruction;
|
|
|
|
|
|
|
|
|
|
if not(csDesigning in ComponentState) then
|
|
|
|
|
begin
|
2017-09-07 10:58:09 +02:00
|
|
|
|
FChromium := TChromium.Create(self);
|
|
|
|
|
FChromium.OnClose := WebBrowser_OnClose;
|
2017-12-07 10:49:51 +01:00
|
|
|
|
FChromium.OnBeforeClose := WebBrowser_OnBeforeClose;
|
2017-09-07 10:58:09 +02:00
|
|
|
|
FChromium.OnAfterCreated := WebBrowser_OnAfterCreated;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
function TChromiumWindow.GetChildWindowHandle : THandle;
|
|
|
|
|
begin
|
|
|
|
|
if (FChromium <> nil) then
|
|
|
|
|
Result := FChromium.WindowHandle
|
|
|
|
|
else
|
|
|
|
|
Result := 0;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-10-28 18:48:53 +02:00
|
|
|
|
function TChromiumWindow.GetBrowserInitialized : boolean;
|
|
|
|
|
begin
|
|
|
|
|
Result := (FChromium <> nil) and FChromium.Initialized;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
procedure TChromiumWindow.WebBrowser_OnClose(Sender: TObject; const browser: ICefBrowser; out Result: Boolean);
|
|
|
|
|
begin
|
2017-03-15 14:53:45 +01:00
|
|
|
|
if assigned(FOnClose) then
|
|
|
|
|
begin
|
2017-09-07 10:58:09 +02:00
|
|
|
|
PostMessage(Handle, CEF_DOONCLOSE, 0, 0);
|
2017-03-15 14:53:45 +01:00
|
|
|
|
Result := True;
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Result := False;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
2017-12-07 10:49:51 +01:00
|
|
|
|
procedure TChromiumWindow.WebBrowser_OnBeforeClose(Sender: TObject; const browser: ICefBrowser);
|
|
|
|
|
begin
|
|
|
|
|
if assigned(FOnBeforeClose) then PostMessage(Handle, CEF_DOONBEFORECLOSE, 0, 0);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-09-07 10:58:09 +02:00
|
|
|
|
procedure TChromiumWindow.WebBrowser_OnAfterCreated(Sender: TObject; const browser: ICefBrowser);
|
|
|
|
|
begin
|
|
|
|
|
PostMessage(Handle, CEF_AFTERCREATED, 0, 0);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
procedure TChromiumWindow.OnCloseMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
if assigned(FOnClose) then FOnClose(self);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-12-07 10:49:51 +01:00
|
|
|
|
procedure TChromiumWindow.OnBeforeCloseMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
|
|
|
|
if assigned(FOnBeforeClose) then FOnBeforeClose(self);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-09-07 10:58:09 +02:00
|
|
|
|
procedure TChromiumWindow.OnAfterCreatedMsg(var aMessage : TMessage);
|
|
|
|
|
begin
|
2017-09-08 17:44:32 +02:00
|
|
|
|
UpdateSize;
|
2017-09-07 10:58:09 +02:00
|
|
|
|
if assigned(FOnAfterCreated) then FOnAfterCreated(self);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-10-28 18:48:53 +02:00
|
|
|
|
function TChromiumWindow.CreateBrowser : boolean;
|
2017-01-27 17:29:37 +01:00
|
|
|
|
begin
|
2017-10-28 18:48:53 +02:00
|
|
|
|
Result := not(csDesigning in ComponentState) and
|
|
|
|
|
(FChromium <> nil) and
|
|
|
|
|
FChromium.CreateBrowser(self, '');
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TChromiumWindow.CloseBrowser(aForceClose : boolean);
|
|
|
|
|
begin
|
|
|
|
|
if (FChromium <> nil) then FChromium.CloseBrowser(aForceClose);
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
procedure TChromiumWindow.LoadURL(const aURL : string);
|
|
|
|
|
begin
|
|
|
|
|
if not(csDesigning in ComponentState) and (FChromium <> nil) then
|
|
|
|
|
FChromium.LoadURL(aURL);
|
|
|
|
|
end;
|
|
|
|
|
|
2017-12-07 10:49:51 +01:00
|
|
|
|
procedure TChromiumWindow.NotifyMoveOrResizeStarted;
|
|
|
|
|
begin
|
|
|
|
|
if (FChromium <> nil) then FChromium.NotifyMoveOrResizeStarted;
|
|
|
|
|
end;
|
|
|
|
|
|
2017-01-27 17:29:37 +01:00
|
|
|
|
end.
|